use super::*;
use crate::shim::crypto::SignatureType;
#[derive(Deserialize, Serialize, JsonSchema)]
#[serde(untagged)] pub enum SignatureTypeLotusJson {
Integer(#[schemars(with = "u8")] SignatureType),
String(
#[serde(with = "crate::lotus_json::stringify")]
#[schemars(with = "SignatureType")]
SignatureType,
),
}
impl HasLotusJson for SignatureType {
type LotusJson = SignatureTypeLotusJson;
#[cfg(test)]
fn snapshots() -> Vec<(serde_json::Value, Self)> {
vec![(json!(2), SignatureType::Bls)]
}
fn into_lotus_json(self) -> Self::LotusJson {
SignatureTypeLotusJson::Integer(self)
}
fn from_lotus_json(lotus_json: Self::LotusJson) -> Self {
match lotus_json {
SignatureTypeLotusJson::Integer(inner) | SignatureTypeLotusJson::String(inner) => inner,
}
}
}
#[test]
fn deserialize_integer() {
pretty_assertions::assert_eq!(
SignatureType::Bls,
serde_json::from_value(json!(2)).unwrap()
);
}