Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/lotus_json/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::shim::actors::cron::Entry;
use crate::shim::address::Address;
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "PascalCase")]
pub struct EntryLotusJson {
#[schemars(with = "LotusJson<Address>")]
Expand Down Expand Up @@ -49,3 +49,4 @@ impl HasLotusJson for Entry {
Entry::default_latest_version(lotus_json.receiver.into(), lotus_json.method_num)
}
}
crate::test_snapshots!(Entry);
52 changes: 30 additions & 22 deletions src/lotus_json/filter_estimate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::*;
use num::BigInt;
use pastey::paste;

#[derive(Debug, Serialize, Deserialize, JsonSchema)]
#[derive(Debug, Eq, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "PascalCase")]
pub struct FilterEstimateLotusJson {
#[schemars(with = "LotusJson<BigInt>")]
Expand All @@ -21,31 +21,39 @@ macro_rules! impl_filter_estimate_lotus_json {
($($version:literal),+) => {
$(
paste! {
impl HasLotusJson for fil_actors_shared::[<v $version>]::reward::FilterEstimate {
type LotusJson = FilterEstimateLotusJson;

#[cfg(test)]
fn snapshots() -> Vec<(serde_json::Value, Self)> {
vec![(
json!({
"PositionEstimate": "0",
"VelocityEstimate": "0",
}),
Self::default(),
)]
mod [<impl_filter_estimate_lotus_json_ $version>] {
use super::*;
type T = fil_actors_shared::[<v $version>]::reward::FilterEstimate;
#[test]
fn snapshots() {
crate::lotus_json::assert_all_snapshots::<T>();
}
impl HasLotusJson for T {
type LotusJson = FilterEstimateLotusJson;

fn into_lotus_json(self) -> Self::LotusJson {
FilterEstimateLotusJson {
position_estimate: self.position,
velocity_estimate: self.velocity,
#[cfg(test)]
fn snapshots() -> Vec<(serde_json::Value, Self)> {
vec![(
json!({
"PositionEstimate": "0",
"VelocityEstimate": "0",
}),
Self::default(),
)]
}

fn into_lotus_json(self) -> Self::LotusJson {
FilterEstimateLotusJson {
position_estimate: self.position,
velocity_estimate: self.velocity,
}
}
}

fn from_lotus_json(lotus_json: Self::LotusJson) -> Self {
Self {
position: lotus_json.position_estimate,
velocity: lotus_json.velocity_estimate,
fn from_lotus_json(lotus_json: Self::LotusJson) -> Self {
Self {
position: lotus_json.position_estimate,
velocity: lotus_json.velocity_estimate,
}
}
}
}
Expand Down
32 changes: 25 additions & 7 deletions src/lotus_json/miner_power.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,30 @@ impl HasLotusJson for MinerPower {
type LotusJson = MinerPowerLotusJson;
#[cfg(test)]
fn snapshots() -> Vec<(serde_json::Value, Self)> {
unimplemented!("see commented-out test, below")
vec![(
json!({
"MinerPower": {
"RawBytePower": "1",
"QualityAdjPower": "2",
},
"TotalPower": {
"RawBytePower": "3",
"QualityAdjPower": "4",
},
"HasMinPower": true,
}),
Self {
miner_power: Claim {
raw_byte_power: 1.into(),
quality_adj_power: 2.into(),
},
total_power: Claim {
raw_byte_power: 3.into(),
quality_adj_power: 4.into(),
},
has_min_power: true,
},
)]
}
fn into_lotus_json(self) -> Self::LotusJson {
MinerPowerLotusJson {
Expand All @@ -39,9 +62,4 @@ impl HasLotusJson for MinerPower {
}
}
}

// MinerPower: !Debug
// #[test]
// fn snapshots() {
// assert_all_snapshots::<MinerPower>();
// }
crate::test_snapshots!(MinerPower);
2 changes: 1 addition & 1 deletion src/lotus_json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ pub use vec::*;

#[macro_export]
macro_rules! test_snapshots {
($ty:ident) => {
($ty:ty) => {
pastey::paste! {
#[test]
fn [<snapshots_ $ty:snake>]() {
Expand Down
150 changes: 83 additions & 67 deletions src/lotus_json/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,90 +82,106 @@ impl HasLotusJson for Signature {
}
}
}
crate::test_snapshots!(Signature);

mod signature2 {
use super::*;
use fvm_shared2::crypto::signature::Signature;
impl HasLotusJson for Signature {
type LotusJson = SignatureV2LotusJson;

#[cfg(test)]
fn snapshots() -> Vec<(serde_json::Value, Self)> {
vec![(
json!({"Type": 2, "Data": "aGVsbG8gd29ybGQh"}),
Self {
sig_type: fvm_shared2::crypto::signature::SignatureType::BLS,
bytes: Vec::from_iter(*b"hello world!"),
},
)]
}

impl HasLotusJson for fvm_shared2::crypto::signature::Signature {
type LotusJson = SignatureV2LotusJson;

#[cfg(test)]
fn snapshots() -> Vec<(serde_json::Value, Self)> {
vec![(
json!({"Type": 2, "Data": "aGVsbG8gd29ybGQh"}),
Self {
sig_type: fvm_shared2::crypto::signature::SignatureType::BLS,
bytes: Vec::from_iter(*b"hello world!"),
},
)]
}

fn into_lotus_json(self) -> Self::LotusJson {
SignatureV2LotusJson {
r#type: self.sig_type,
data: self.bytes,
fn into_lotus_json(self) -> Self::LotusJson {
SignatureV2LotusJson {
r#type: self.sig_type,
data: self.bytes,
}
}
}

fn from_lotus_json(lotus_json: Self::LotusJson) -> Self {
Self {
sig_type: lotus_json.r#type,
bytes: lotus_json.data,
fn from_lotus_json(lotus_json: Self::LotusJson) -> Self {
Self {
sig_type: lotus_json.r#type,
bytes: lotus_json.data,
}
}
}
crate::test_snapshots!(Signature);
}

impl HasLotusJson for fvm_shared3::crypto::signature::Signature {
type LotusJson = SignatureV3LotusJson;

#[cfg(test)]
fn snapshots() -> Vec<(serde_json::Value, Self)> {
vec![(
json!({"Type": 1, "Data": "aGVsbG8gd29ybGQh"}),
Self {
sig_type: fvm_shared3::crypto::signature::SignatureType::Secp256k1,
bytes: Vec::from_iter(*b"hello world!"),
},
)]
}
mod signature3 {
use super::*;
use fvm_shared3::crypto::signature::Signature;
impl HasLotusJson for Signature {
type LotusJson = SignatureV3LotusJson;

#[cfg(test)]
fn snapshots() -> Vec<(serde_json::Value, Self)> {
vec![(
json!({"Type": 1, "Data": "aGVsbG8gd29ybGQh"}),
Self {
sig_type: fvm_shared3::crypto::signature::SignatureType::Secp256k1,
bytes: Vec::from_iter(*b"hello world!"),
},
)]
}

fn into_lotus_json(self) -> Self::LotusJson {
SignatureV3LotusJson {
r#type: self.sig_type,
data: self.bytes,
fn into_lotus_json(self) -> Self::LotusJson {
SignatureV3LotusJson {
r#type: self.sig_type,
data: self.bytes,
}
}
}

fn from_lotus_json(lotus_json: Self::LotusJson) -> Self {
Self {
sig_type: lotus_json.r#type,
bytes: lotus_json.data,
fn from_lotus_json(lotus_json: Self::LotusJson) -> Self {
Self {
sig_type: lotus_json.r#type,
bytes: lotus_json.data,
}
}
}
crate::test_snapshots!(Signature);
}

impl HasLotusJson for fvm_shared4::crypto::signature::Signature {
type LotusJson = SignatureV4LotusJson;

#[cfg(test)]
fn snapshots() -> Vec<(serde_json::Value, Self)> {
vec![(
json!({"Type": 1, "Data": "aGVsbG8gd29ybGQh"}),
Self {
sig_type: fvm_shared4::crypto::signature::SignatureType::Secp256k1,
bytes: Vec::from_iter(*b"hello world!"),
},
)]
}
mod signature4 {
use super::*;
use fvm_shared4::crypto::signature::Signature;
impl HasLotusJson for Signature {
type LotusJson = SignatureV4LotusJson;

#[cfg(test)]
fn snapshots() -> Vec<(serde_json::Value, Self)> {
vec![(
json!({"Type": 1, "Data": "aGVsbG8gd29ybGQh"}),
Self {
sig_type: fvm_shared4::crypto::signature::SignatureType::Secp256k1,
bytes: Vec::from_iter(*b"hello world!"),
},
)]
}

fn into_lotus_json(self) -> Self::LotusJson {
SignatureV4LotusJson {
r#type: self.sig_type,
data: self.bytes,
fn into_lotus_json(self) -> Self::LotusJson {
SignatureV4LotusJson {
r#type: self.sig_type,
data: self.bytes,
}
}
}

fn from_lotus_json(lotus_json: Self::LotusJson) -> Self {
Self {
sig_type: lotus_json.r#type,
bytes: lotus_json.data,
fn from_lotus_json(lotus_json: Self::LotusJson) -> Self {
Self {
sig_type: lotus_json.r#type,
bytes: lotus_json.data,
}
}
}
crate::test_snapshots!(Signature);
}
Loading
Loading