diff --git a/src/lotus_json/actors/params/account_params.rs b/src/lotus_json/actors/params/account_params.rs index 5023f3a007be..448f8265cad9 100644 --- a/src/lotus_json/actors/params/account_params.rs +++ b/src/lotus_json/actors/params/account_params.rs @@ -27,40 +27,48 @@ pub struct AuthenticateParamsLotusJson { pub message: Vec, } -macro_rules! impl_account_authenticate_params { +macro_rules! impl_account_authenticate_params { ($type_suffix:path: $($version:literal),+) => { $( paste! { - impl HasLotusJson for fil_actor_account_state::[]::$type_suffix { - type LotusJson = AuthenticateParamsLotusJson; + mod [] { + use super::*; + type T = fil_actor_account_state::[]::$type_suffix; + #[test] + fn snapshots() { + crate::lotus_json::assert_all_snapshots::(); + } + impl HasLotusJson for T { + type LotusJson = AuthenticateParamsLotusJson; - #[cfg(test)] - fn snapshots() -> Vec<(serde_json::Value, Self)> { - vec![ - ( - json!({ - "Signature": null, - "Message": null, - }), - Self { - signature: vec![], - message: vec![], - }, - ), - ] - } + #[cfg(test)] + fn snapshots() -> Vec<(serde_json::Value, Self)> { + vec![ + ( + json!({ + "Signature": null, + "Message": null, + }), + Self { + signature: vec![], + message: vec![], + }, + ), + ] + } - fn into_lotus_json(self) -> Self::LotusJson { - AuthenticateParamsLotusJson { - signature: self.signature, - message: self.message, + fn into_lotus_json(self) -> Self::LotusJson { + AuthenticateParamsLotusJson { + signature: self.signature, + message: self.message, + } } - } - fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { - Self { - signature: lotus_json.signature, - message: lotus_json.message, + fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { + Self { + signature: lotus_json.signature, + message: lotus_json.message, + } } } } @@ -72,28 +80,36 @@ macro_rules! impl_account_authenticate_params { macro_rules! impl_account_constructor_params { ($type_suffix:path: $($version:literal),+) => { $( - paste! { - impl HasLotusJson for fil_actor_account_state::[]::$type_suffix { - type LotusJson = AccountConstructorParamsLotusJson; - - #[cfg(test)] - fn snapshots() -> Vec<(serde_json::Value, Self)> { - vec![ - ( - json!("f01234"), - Self { - address: Address::new_id(1234).into(), - }, - ), - ] + paste! { + mod [] { + use super::*; + type T = fil_actor_account_state::[]::$type_suffix; + #[test] + fn snapshots() { + crate::lotus_json::assert_all_snapshots::(); } + impl HasLotusJson for T { + type LotusJson = AccountConstructorParamsLotusJson; - fn into_lotus_json(self) -> Self::LotusJson { - AccountConstructorParamsLotusJson { address: self.address.into() } - } + #[cfg(test)] + fn snapshots() -> Vec<(serde_json::Value, Self)> { + vec![ + ( + json!("f01234"), + Self { + address: Address::new_id(1234).into(), + }, + ), + ] + } - fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { - Self { address: lotus_json.address.into() } + fn into_lotus_json(self) -> Self::LotusJson { + AccountConstructorParamsLotusJson { address: self.address.into() } + } + + fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { + Self { address: lotus_json.address.into() } + } } } } @@ -101,7 +117,7 @@ macro_rules! impl_account_constructor_params { }; } -impl_account_constructor_params!(types::ConstructorParams: 15, 16, 17); impl_account_constructor_params!(ConstructorParams: 11, 12, 13, 14); -impl_account_authenticate_params!(types::AuthenticateMessageParams: 15, 16, 17); +impl_account_constructor_params!(types::ConstructorParams: 15, 16, 17); impl_account_authenticate_params!(AuthenticateMessageParams: 9, 10, 11, 12, 13, 14); +impl_account_authenticate_params!(types::AuthenticateMessageParams: 15, 16, 17); diff --git a/src/lotus_json/actors/params/datacap_params.rs b/src/lotus_json/actors/params/datacap_params.rs index cc9ad1a6109b..37d4ea69ca50 100644 --- a/src/lotus_json/actors/params/datacap_params.rs +++ b/src/lotus_json/actors/params/datacap_params.rs @@ -10,6 +10,7 @@ use fil_actors_shared::frc46_token::token::types::{ IncreaseAllowanceParams, RevokeAllowanceParams, TransferFromParams, TransferParams, }; use fvm_ipld_encoding::RawBytes; +use pastey::paste; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; @@ -24,24 +25,34 @@ pub struct DatacapBalanceParamsLotusJson { macro_rules! impl_datacap_balance_params_lotus_json { ($($version:ident),*) => { $( - impl HasLotusJson for datacap::$version::BalanceParams { - type LotusJson = DatacapBalanceParamsLotusJson; - - #[cfg(test)] - fn snapshots() -> Vec<(serde_json::Value, Self)> { - vec![( - serde_json::json!("f01234"), - datacap::$version::BalanceParams { - address: Address::new_id(1234).into(), - }, - )] - } - - fn into_lotus_json(self) -> Self::LotusJson { - DatacapBalanceParamsLotusJson { address: self.address.into() } - } - fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { - datacap::$version::BalanceParams { address: lotus_json.address.into() } + paste! { + mod [] { + use super::*; + type T = datacap::$version::BalanceParams; + #[test] + fn snapshots() { + crate::lotus_json::assert_all_snapshots::(); + } + impl HasLotusJson for T { + type LotusJson = DatacapBalanceParamsLotusJson; + + #[cfg(test)] + fn snapshots() -> Vec<(serde_json::Value, Self)> { + vec![( + serde_json::json!("f01234"), + Self { + address: Address::new_id(1234).into(), + }, + )] + } + + fn into_lotus_json(self) -> Self::LotusJson { + DatacapBalanceParamsLotusJson { address: self.address.into() } + } + fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { + Self { address: lotus_json.address.into() } + } + } } } )* @@ -61,24 +72,34 @@ pub struct DatacapConstructorParamsLotusJson { macro_rules! impl_datacap_constructor_params_lotus_json { ($($version:ident),*) => { $( - impl HasLotusJson for datacap::$version::ConstructorParams { - type LotusJson = DatacapConstructorParamsLotusJson; - - #[cfg(test)] - fn snapshots() -> Vec<(serde_json::Value, Self)> { - vec![( - serde_json::json!("f01234"), - datacap::$version::ConstructorParams { - governor: Address::new_id(1234).into(), - }, - )] - } - - fn into_lotus_json(self) -> Self::LotusJson { - DatacapConstructorParamsLotusJson { governor: self.governor.into() } - } - fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { - datacap::$version::ConstructorParams { governor: lotus_json.governor.into() } + paste! { + mod [] { + use super::*; + type T = datacap::$version::ConstructorParams; + #[test] + fn snapshots() { + crate::lotus_json::assert_all_snapshots::(); + } + impl HasLotusJson for T { + type LotusJson = DatacapConstructorParamsLotusJson; + + #[cfg(test)] + fn snapshots() -> Vec<(serde_json::Value, Self)> { + vec![( + serde_json::json!("f01234"), + Self { + governor: Address::new_id(1234).into(), + }, + )] + } + + fn into_lotus_json(self) -> Self::LotusJson { + DatacapConstructorParamsLotusJson { governor: self.governor.into() } + } + fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { + Self { governor: lotus_json.governor.into() } + } + } } } )* @@ -101,33 +122,43 @@ pub struct DatacapDestroyParamsLotusJson { macro_rules! impl_datacap_destroy_params_lotus_json { ($($version:ident),*) => { $( - impl HasLotusJson for datacap::$version::DestroyParams { - type LotusJson = DatacapDestroyParamsLotusJson; - - #[cfg(test)] - fn snapshots() -> Vec<(serde_json::Value, Self)> { - vec![( - serde_json::json!({ - "owner": "f01234", - "amount": "1000000000000000000" - }), - datacap::$version::DestroyParams { - owner: Address::new_id(1234).into(), - amount: TokenAmount::from_atto(1_000_000_000_000_000_000_i64).into(), - }, - )] - } - - fn into_lotus_json(self) -> Self::LotusJson { - DatacapDestroyParamsLotusJson { - owner: self.owner.into(), - amount: self.amount.into(), + paste! { + mod [] { + use super::*; + type T = datacap::$version::DestroyParams; + #[test] + fn snapshots() { + crate::lotus_json::assert_all_snapshots::(); } - } - fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { - datacap::$version::DestroyParams { - owner: lotus_json.owner.into(), - amount: lotus_json.amount.into(), + impl HasLotusJson for T { + type LotusJson = DatacapDestroyParamsLotusJson; + + #[cfg(test)] + fn snapshots() -> Vec<(serde_json::Value, Self)> { + vec![( + serde_json::json!({ + "Owner": "f01234", + "Amount": "1000000000000000000" + }), + Self { + owner: Address::new_id(1234).into(), + amount: TokenAmount::from_atto(1_000_000_000_000_000_000_i64).into(), + }, + )] + } + + fn into_lotus_json(self) -> Self::LotusJson { + DatacapDestroyParamsLotusJson { + owner: self.owner.into(), + amount: self.amount.into(), + } + } + fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { + Self { + owner: lotus_json.owner.into(), + amount: lotus_json.amount.into(), + } + } } } } @@ -154,40 +185,50 @@ pub struct DatacapMintParamsLotusJson { macro_rules! impl_datacap_mint_params_lotus_json { ($($version:ident),*) => { $( - impl HasLotusJson for datacap::$version::MintParams { - type LotusJson = DatacapMintParamsLotusJson; - - #[cfg(test)] - fn snapshots() -> Vec<(serde_json::Value, Self)> { - vec![( - serde_json::json!({ - "to": "f01234", - "amount": "1000000000000000000", - "operators": ["f01235", "f01236"] - }), - datacap::$version::MintParams { - to: Address::new_id(1234).into(), - amount: TokenAmount::from_atto(1_000_000_000_000_000_000_i64).into(), - operators: vec![ - Address::new_id(1235).into(), - Address::new_id(1236).into(), - ], - }, - )] - } - - fn into_lotus_json(self) -> Self::LotusJson { - DatacapMintParamsLotusJson { - to: self.to.into(), - amount: self.amount.into(), - operators: self.operators.into_iter().map(|a| a.into()).collect(), + paste! { + mod [] { + use super::*; + type T = datacap::$version::MintParams; + #[test] + fn snapshots() { + crate::lotus_json::assert_all_snapshots::(); } - } - fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { - datacap::$version::MintParams { - to: lotus_json.to.into(), - amount: lotus_json.amount.into(), - operators: lotus_json.operators.into_iter().map(|a| a.into()).collect(), + impl HasLotusJson for T { + type LotusJson = DatacapMintParamsLotusJson; + + #[cfg(test)] + fn snapshots() -> Vec<(serde_json::Value, Self)> { + vec![( + serde_json::json!({ + "To": "f01234", + "Amount": "1000000000000000000", + "Operators": ["f01235", "f01236"] + }), + Self { + to: Address::new_id(1234).into(), + amount: TokenAmount::from_atto(1_000_000_000_000_000_000_i64).into(), + operators: vec![ + Address::new_id(1235).into(), + Address::new_id(1236).into(), + ], + }, + )] + } + + fn into_lotus_json(self) -> Self::LotusJson { + DatacapMintParamsLotusJson { + to: self.to.into(), + amount: self.amount.into(), + operators: self.operators.into_iter().map(|a| a.into()).collect(), + } + } + fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { + Self { + to: lotus_json.to.into(), + amount: lotus_json.amount.into(), + operators: lotus_json.operators.into_iter().map(|a| a.into()).collect(), + } + } } } } @@ -218,9 +259,9 @@ impl HasLotusJson for TransferParams { fn snapshots() -> Vec<(serde_json::Value, Self)> { vec![( serde_json::json!({ - "to": "f01234", - "amount": "1000000000000000000", - "operator_data": "dGVzdCBkYXRh" + "To": "f01234", + "Amount": "1000000000000000000", + "OperatorData": "dGVzdCBkYXRh" }), TransferParams { to: Address::new_id(1234).into(), @@ -246,6 +287,7 @@ impl HasLotusJson for TransferParams { } } } +crate::test_snapshots!(TransferParams); #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema)] #[serde(rename_all = "PascalCase")] @@ -271,10 +313,10 @@ impl HasLotusJson for TransferFromParams { fn snapshots() -> Vec<(serde_json::Value, Self)> { vec![( serde_json::json!({ - "from": "f01234", - "to": "f01235", - "amount": "1000000000000000000", - "operator_data": "dGVzdCBkYXRh" + "From": "f01234", + "To": "f01235", + "Amount": "1000000000000000000", + "OperatorData": "dGVzdCBkYXRh" }), TransferFromParams { from: Address::new_id(1234).into(), @@ -303,6 +345,7 @@ impl HasLotusJson for TransferFromParams { } } } +crate::test_snapshots!(TransferFromParams); #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema)] #[serde(rename_all = "PascalCase")] @@ -322,8 +365,8 @@ impl HasLotusJson for IncreaseAllowanceParams { fn snapshots() -> Vec<(serde_json::Value, Self)> { vec![( serde_json::json!({ - "operator": "f01234", - "increase": "1000000000000000000" + "Operator": "f01234", + "Increase": "1000000000000000000" }), IncreaseAllowanceParams { operator: Address::new_id(1234).into(), @@ -346,6 +389,7 @@ impl HasLotusJson for IncreaseAllowanceParams { } } } +crate::test_snapshots!(IncreaseAllowanceParams); #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema)] #[serde(rename_all = "PascalCase")] @@ -365,8 +409,8 @@ impl HasLotusJson for DecreaseAllowanceParams { fn snapshots() -> Vec<(serde_json::Value, Self)> { vec![( serde_json::json!({ - "operator": "f01234", - "decrease": "1000000000000000000" + "Operator": "f01234", + "Decrease": "1000000000000000000" }), DecreaseAllowanceParams { operator: Address::new_id(1234).into(), @@ -389,6 +433,7 @@ impl HasLotusJson for DecreaseAllowanceParams { } } } +crate::test_snapshots!(DecreaseAllowanceParams); #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema)] #[serde(rename_all = "PascalCase")] @@ -405,7 +450,7 @@ impl HasLotusJson for RevokeAllowanceParams { fn snapshots() -> Vec<(serde_json::Value, Self)> { vec![( serde_json::json!({ - "operator": "f01234" + "Operator": "f01234" }), RevokeAllowanceParams { operator: Address::new_id(1234).into(), @@ -425,6 +470,7 @@ impl HasLotusJson for RevokeAllowanceParams { } } } +crate::test_snapshots!(RevokeAllowanceParams); #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema)] #[serde(rename_all = "PascalCase")] @@ -441,7 +487,7 @@ impl HasLotusJson for BurnParams { fn snapshots() -> Vec<(serde_json::Value, Self)> { vec![( serde_json::json!({ - "amount": "1000000000000000000" + "Amount": "1000000000000000000" }), BurnParams { amount: TokenAmount::from_atto(1_000_000_000_000_000_000_i64).into(), @@ -461,6 +507,7 @@ impl HasLotusJson for BurnParams { } } } +crate::test_snapshots!(BurnParams); #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema)] #[serde(rename_all = "PascalCase")] @@ -480,8 +527,8 @@ impl HasLotusJson for BurnFromParams { fn snapshots() -> Vec<(serde_json::Value, Self)> { vec![( serde_json::json!({ - "owner": "f01234", - "amount": "1000000000000000000" + "Owner": "f01234", + "Amount": "1000000000000000000" }), BurnFromParams { owner: Address::new_id(1234).into(), @@ -504,6 +551,7 @@ impl HasLotusJson for BurnFromParams { } } } +crate::test_snapshots!(BurnFromParams); #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema)] #[serde(rename_all = "PascalCase")] @@ -523,8 +571,8 @@ impl HasLotusJson for GetAllowanceParams { fn snapshots() -> Vec<(serde_json::Value, Self)> { vec![( serde_json::json!({ - "owner": "f01234", - "operator": "f01235" + "Owner": "f01234", + "Operator": "f01235" }), GetAllowanceParams { owner: Address::new_id(1234).into(), @@ -547,3 +595,4 @@ impl HasLotusJson for GetAllowanceParams { } } } +crate::test_snapshots!(GetAllowanceParams); diff --git a/src/lotus_json/actors/params/miner_params.rs b/src/lotus_json/actors/params/miner_params.rs index 495bf120eaa3..11670c06f4cc 100644 --- a/src/lotus_json/actors/params/miner_params.rs +++ b/src/lotus_json/actors/params/miner_params.rs @@ -601,46 +601,54 @@ pub struct ProveCommitSectorsNIParamsLotusJson { pub require_activation_success: bool, } -macro_rules! impl_lotus_json_for_miner_change_worker_param { +macro_rules! impl_lotus_json_for_miner_change_worker_param { ($($version:literal),+) => { $( - paste! { - impl HasLotusJson for fil_actor_miner_state::[]::ChangeWorkerAddressParams { - type LotusJson = ChangeWorkerAddressParamsLotusJson; - - #[cfg(test)] - fn snapshots() -> Vec<(serde_json::Value, Self)> { - vec![ - ( - json!({ - "NewWorker": "f01234", - "NewControlAddrs": ["f01236", "f01237"], - }), - Self { - new_worker: Address::new_id(1234).into(), - new_control_addresses: vec![Address::new_id(1236).into(), Address::new_id(1237).into()], - }, - ), - ] - } + paste! { + mod [] { + use super::*; + type T = fil_actor_miner_state::[]::ChangeWorkerAddressParams; + #[test] + fn snapshots() { + crate::lotus_json::assert_all_snapshots::(); + } + impl HasLotusJson for T { + type LotusJson = ChangeWorkerAddressParamsLotusJson; + + #[cfg(test)] + fn snapshots() -> Vec<(serde_json::Value, Self)> { + vec![ + ( + json!({ + "NewWorker": "f01234", + "NewControlAddrs": ["f01236", "f01237"], + }), + Self { + new_worker: Address::new_id(1234).into(), + new_control_addresses: vec![Address::new_id(1236).into(), Address::new_id(1237).into()], + }, + ), + ] + } - fn into_lotus_json(self) -> Self::LotusJson { - ChangeWorkerAddressParamsLotusJson { - new_worker: self.new_worker.into(), - new_control_addresses: self.new_control_addresses - .into_iter() - .map(|a| a.into()) - .collect(), + fn into_lotus_json(self) -> Self::LotusJson { + ChangeWorkerAddressParamsLotusJson { + new_worker: self.new_worker.into(), + new_control_addresses: self.new_control_addresses + .into_iter() + .map(|a| a.into()) + .collect(), + } } - } - fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { - Self { - new_worker: lotus_json.new_worker.into(), - new_control_addresses: lotus_json.new_control_addresses - .into_iter() - .map(|a| a.into()) - .collect(), + fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { + Self { + new_worker: lotus_json.new_worker.into(), + new_control_addresses: lotus_json.new_control_addresses + .into_iter() + .map(|a| a.into()) + .collect(), + } } } } @@ -652,56 +660,65 @@ macro_rules! impl_lotus_json_for_miner_change_worker_param { macro_rules! impl_lotus_json_for_miner_constructor_params { ($($version:literal),+) => { $( - paste! { - impl HasLotusJson for fil_actor_miner_state::[]::MinerConstructorParams { - type LotusJson = ConstructorParamsLotusJson; - - #[cfg(test)] - fn snapshots() -> Vec<(serde_json::Value, Self)> { - vec![ - ( - json!({ - "Owner": "f01234", - "Worker": "f01235", - "ControlAddrs": ["f01236", "f01237"], - "WindowPoStProofType": 1, - "PeerId": "AQ==", - "Multiaddrs": ["Ag==", "Aw=="], - }), - Self { - owner: Address::new_id(1234).into(), - worker: Address::new_id(1235).into(), - control_addresses: vec![Address::new_id(1236).into(), Address::new_id(1237).into()], - window_post_proof_type: RegisteredPoStProof::from(fvm_shared4::sector::RegisteredPoStProof::StackedDRGWindow2KiBV1P1).into(), - peer_id: vec![1], - multi_addresses: vec![], - }, - ), - ] - } + paste! { + mod [] { + use super::*; + type T = fil_actor_miner_state::[]::MinerConstructorParams; + #[test] + #[ignore = "https://github.com/ChainSafe/forest/issues/6369"] + fn snapshots() { + crate::lotus_json::assert_all_snapshots::(); + } + impl HasLotusJson for T { + type LotusJson = ConstructorParamsLotusJson; + + #[cfg(test)] + fn snapshots() -> Vec<(serde_json::Value, Self)> { + vec![ + ( + json!({ + "OwnerAddr": "f01234", + "WorkerAddr": "f01235", + "ControlAddrs": ["f01236", "f01237"], + "WindowPoStProofType": 1, + "PeerId": "AQ==", + "Multiaddrs": ["Ag==", "Aw=="], + }), + Self { + owner: Address::new_id(1234).into(), + worker: Address::new_id(1235).into(), + control_addresses: vec![Address::new_id(1236).into(), Address::new_id(1237).into()], + window_post_proof_type: RegisteredPoStProof::from(fvm_shared4::sector::RegisteredPoStProof::StackedDRGWindow2KiBV1P1).into(), + peer_id: vec![1], + multi_addresses: vec![], + }, + ), + ] + } - fn into_lotus_json(self) -> Self::LotusJson { - ConstructorParamsLotusJson { - owner_addr: self.owner.into(), - worker_addr: self.worker.into(), - control_addrs: self.control_addresses.into_iter().map(|a| a.into()).collect(), - window_po_st_proof_type: self.window_post_proof_type.into(), - peer_id: self.peer_id, - multiaddrs: self.multi_addresses.into_iter().map(|addr| addr.0).collect(), + fn into_lotus_json(self) -> Self::LotusJson { + ConstructorParamsLotusJson { + owner_addr: self.owner.into(), + worker_addr: self.worker.into(), + control_addrs: self.control_addresses.into_iter().map(|a| a.into()).collect(), + window_po_st_proof_type: self.window_post_proof_type.into(), + peer_id: self.peer_id, + multiaddrs: self.multi_addresses.into_iter().map(|addr| addr.0).collect(), + } } - } - fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { - Self { - owner: lotus_json.owner_addr.into(), - worker: lotus_json.worker_addr.into(), - control_addresses: lotus_json.control_addrs - .into_iter() - .map(|a| a.into()) - .collect(), - window_post_proof_type: lotus_json.window_po_st_proof_type.into(), - peer_id: lotus_json.peer_id, - multi_addresses: lotus_json.multiaddrs.into_iter().map(BytesDe).collect(), + fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { + Self { + owner: lotus_json.owner_addr.into(), + worker: lotus_json.worker_addr.into(), + control_addresses: lotus_json.control_addrs + .into_iter() + .map(|a| a.into()) + .collect(), + window_post_proof_type: lotus_json.window_po_st_proof_type.into(), + peer_id: lotus_json.peer_id, + multi_addresses: lotus_json.multiaddrs.into_iter().map(BytesDe).collect(), + } } } } @@ -713,28 +730,28 @@ macro_rules! impl_lotus_json_for_miner_constructor_params { macro_rules! impl_lotus_json_for_miner_declare_faults_recovered_params { ($($version:literal),+) => { $( - paste! { - impl HasLotusJson for fil_actor_miner_state::[]::DeclareFaultsRecoveredParams { - type LotusJson = DeclareFaultsRecoveredParamsLotusJson; + paste! { + impl HasLotusJson for fil_actor_miner_state::[]::DeclareFaultsRecoveredParams { + type LotusJson = DeclareFaultsRecoveredParamsLotusJson; - #[cfg(test)] - fn snapshots() -> Vec<(serde_json::Value, Self)> { - vec![] - } + #[cfg(test)] + fn snapshots() -> Vec<(serde_json::Value, Self)> { + vec![] + } - fn into_lotus_json(self) -> Self::LotusJson { - DeclareFaultsRecoveredParamsLotusJson { - recoveries: self.recoveries.into_iter().map(|r| r.into_lotus_json()).collect(), + fn into_lotus_json(self) -> Self::LotusJson { + DeclareFaultsRecoveredParamsLotusJson { + recoveries: self.recoveries.into_iter().map(|r| r.into_lotus_json()).collect(), + } } - } - fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { - Self { - recoveries: lotus_json.recoveries.into_iter().map(|r| fil_actor_miner_state::[]::RecoveryDeclaration::from_lotus_json(r)).collect(), + fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { + Self { + recoveries: lotus_json.recoveries.into_iter().map(|r| fil_actor_miner_state::[]::RecoveryDeclaration::from_lotus_json(r)).collect(), + } } } } - } )+ }; } @@ -742,44 +759,53 @@ macro_rules! impl_lotus_json_for_miner_declare_faults_recovered_params { macro_rules! impl_lotus_json_for_recover_declaration_params_v9_and_above { ($($version:literal),+) => { $( - paste! { - impl HasLotusJson for fil_actor_miner_state::[]::RecoveryDeclaration { - type LotusJson = RecoveryDeclarationLotusJson; - - #[cfg(test)] - fn snapshots() -> Vec<(serde_json::Value, Self)> { - let sectors = BitField::new(); - vec![( - json!({ - "Deadline": 1, - "Partition": 2, - "Sectors": "gCI=" - }), - Self { - deadline: 1, - partition: 2, - sectors, - }, - )] - } + paste! { + mod [] { + use super::*; + type T = fil_actor_miner_state::[]::RecoveryDeclaration; + #[test] + #[ignore = "https://github.com/ChainSafe/forest/issues/6370"] + fn snapshots() { + crate::lotus_json::assert_all_snapshots::(); + } + impl HasLotusJson for T { + type LotusJson = RecoveryDeclarationLotusJson; + + #[cfg(test)] + fn snapshots() -> Vec<(serde_json::Value, Self)> { + let sectors = BitField::new(); + vec![( + json!({ + "Deadline": 1, + "Partition": 2, + "Sectors": "gCI=" + }), + Self { + deadline: 1, + partition: 2, + sectors, + }, + )] + } - fn into_lotus_json(self) -> Self::LotusJson { - RecoveryDeclarationLotusJson { - deadline: self.deadline, - partition: self.partition, - sectors: self.sectors, - } - } + fn into_lotus_json(self) -> Self::LotusJson { + RecoveryDeclarationLotusJson { + deadline: self.deadline, + partition: self.partition, + sectors: self.sectors, + } + } - fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { - Self { - deadline: lotus_json.deadline, - partition: lotus_json.partition, - sectors: lotus_json.sectors, + fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { + Self { + deadline: lotus_json.deadline, + partition: lotus_json.partition, + sectors: lotus_json.sectors, + } + } } } } - } )+ }; } diff --git a/src/lotus_json/beneficiary_term.rs b/src/lotus_json/beneficiary_term.rs index c9d35495a2f5..f825d2437075 100644 --- a/src/lotus_json/beneficiary_term.rs +++ b/src/lotus_json/beneficiary_term.rs @@ -5,7 +5,7 @@ use super::*; use crate::shim::{clock::ChainEpoch, econ::TokenAmount}; use fil_actor_miner_state::v12::BeneficiaryTerm; -#[derive(Clone, Serialize, Deserialize, JsonSchema)] +#[derive(Debug, Eq, PartialEq, Clone, Serialize, Deserialize, JsonSchema)] #[serde(rename_all = "PascalCase")] #[schemars(rename = "BeneficiaryTerm")] pub struct BeneficiaryTermLotusJson { diff --git a/src/lotus_json/election_proof.rs b/src/lotus_json/election_proof.rs index 9e1d12c26ce4..98dba1123569 100644 --- a/src/lotus_json/election_proof.rs +++ b/src/lotus_json/election_proof.rs @@ -5,7 +5,7 @@ use crate::blocks::{ElectionProof, VRFProof}; use super::*; -#[derive(Serialize, Deserialize, JsonSchema)] +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize, JsonSchema)] #[serde(rename_all = "PascalCase")] #[schemars(rename = "ElectionProof")] pub struct ElectionProofLotusJson { diff --git a/src/lotus_json/extended_sector_info.rs b/src/lotus_json/extended_sector_info.rs index f0e8aa1cdeed..500d2a43ebbb 100644 --- a/src/lotus_json/extended_sector_info.rs +++ b/src/lotus_json/extended_sector_info.rs @@ -5,7 +5,7 @@ use super::*; use crate::shim::sector::{ExtendedSectorInfo, RegisteredSealProof}; use ::cid::Cid; -#[derive(Serialize, Deserialize, JsonSchema)] +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize, JsonSchema)] #[serde(rename_all = "PascalCase")] #[schemars(rename = "ExtendedSectorInfo")] pub struct ExtendedSectorInfoLotusJson { diff --git a/src/lotus_json/gossip_block.rs b/src/lotus_json/gossip_block.rs index c535b5a58450..318a2ba7483e 100644 --- a/src/lotus_json/gossip_block.rs +++ b/src/lotus_json/gossip_block.rs @@ -6,7 +6,7 @@ use super::*; use crate::blocks::{CachingBlockHeader, GossipBlock}; use ::cid::Cid; -#[derive(Serialize, Deserialize, JsonSchema)] +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize, JsonSchema)] #[serde(rename_all = "PascalCase")] #[schemars(rename = "GossipBlock")] pub struct GossipBlockLotusJson { diff --git a/src/lotus_json/ipld.rs b/src/lotus_json/ipld.rs index 91a6c68c6ab9..2f94cbd8fd6b 100644 --- a/src/lotus_json/ipld.rs +++ b/src/lotus_json/ipld.rs @@ -30,7 +30,7 @@ use ::cid::multibase; use ipld_core::{ipld, ipld::Ipld}; use serde::de; -#[derive(Serialize, Deserialize, JsonSchema)] +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize, JsonSchema)] #[schemars(rename = "Ipld")] pub struct IpldLotusJson( #[serde(with = "self")] diff --git a/src/lotus_json/mod.rs b/src/lotus_json/mod.rs index 6735a6e653f0..906f25a87369 100644 --- a/src/lotus_json/mod.rs +++ b/src/lotus_json/mod.rs @@ -247,6 +247,16 @@ pub use vec::*; #[macro_export] macro_rules! test_snapshots { + ($ty:ident) => { + pastey::paste! { + #[test] + fn []() { + use super::*; + assert_all_snapshots::<$ty>(); + } + } + }; + ($module:path: $ty:ident: $($version:literal),+ $(,)?) => { $( pastey::paste! { @@ -275,7 +285,8 @@ macro_rules! test_snapshots { #[cfg(any(test, doc))] pub fn assert_all_snapshots() where - T: HasLotusJson + PartialEq + std::fmt::Debug + Clone, + T: HasLotusJson, + ::LotusJson: PartialEq + std::fmt::Debug, { let snapshots = T::snapshots(); assert!(!snapshots.is_empty()); @@ -287,10 +298,12 @@ where #[cfg(test)] pub fn assert_one_snapshot(lotus_json: serde_json::Value, val: T) where - T: HasLotusJson + PartialEq + std::fmt::Debug + Clone, + T: HasLotusJson, + ::LotusJson: PartialEq + std::fmt::Debug, { - // T -> T::LotusJson -> lotus_json - let serialized = val.clone().into_lotus_json_value().unwrap(); + // T -> T::LotusJson -> lotus_json (Do not clone T as some external types do not implement Clone) + let val_lotus_json = val.into_lotus_json(); + let serialized = serde_json::to_value(&val_lotus_json).unwrap(); assert_eq!( serialized.to_string(), lotus_json.to_string(), @@ -298,16 +311,17 @@ where std::any::type_name::() ); - // lotus_json -> T::LotusJson -> T + // lotus_json -> T::LotusJson -> T -> T::LotusJson + //( Not comparing T because external types may not implement `Eq` and `PartialEq`) let deserialized = match serde_json::from_value::(lotus_json.clone()) { - Ok(lotus_json) => T::from_lotus_json(lotus_json), + Ok(lotus_json) => T::from_lotus_json(lotus_json).into_lotus_json(), Err(e) => panic!( "couldn't deserialize a {} from {}: {e}", std::any::type_name::(), lotus_json ), }; - assert_eq!(deserialized, val); + assert_eq!(deserialized, val_lotus_json); } #[cfg(any(test, doc))] diff --git a/src/lotus_json/pending_beneficiary_change.rs b/src/lotus_json/pending_beneficiary_change.rs index 3049ab5cee63..d9b77e905f6a 100644 --- a/src/lotus_json/pending_beneficiary_change.rs +++ b/src/lotus_json/pending_beneficiary_change.rs @@ -6,7 +6,7 @@ use super::*; use crate::shim::{address::Address, clock::ChainEpoch, econ::TokenAmount}; use fil_actor_miner_state::v12::PendingBeneficiaryChange; -#[derive(Clone, Serialize, Deserialize, JsonSchema)] +#[derive(Debug, Eq, PartialEq, Clone, Serialize, Deserialize, JsonSchema)] #[serde(rename_all = "PascalCase")] #[schemars(rename = "PendingBeneficiaryChange")] pub struct PendingBeneficiaryChangeLotusJson { diff --git a/src/lotus_json/po_st_proof.rs b/src/lotus_json/po_st_proof.rs index 78eaaa6c4558..d79116d28256 100644 --- a/src/lotus_json/po_st_proof.rs +++ b/src/lotus_json/po_st_proof.rs @@ -6,7 +6,7 @@ use fvm_shared4::sector::PoStProof as PoStProofV4; use super::*; -#[derive(Serialize, Deserialize, JsonSchema)] +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize, JsonSchema)] #[serde(rename_all = "PascalCase")] #[schemars(rename = "PoStProof")] pub struct PoStProofLotusJson { diff --git a/src/lotus_json/power_claim.rs b/src/lotus_json/power_claim.rs index f496512c3bd9..12da8697d9ed 100644 --- a/src/lotus_json/power_claim.rs +++ b/src/lotus_json/power_claim.rs @@ -5,7 +5,7 @@ use crate::shim::actors::power::Claim; use super::*; -#[derive(Default, Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Default, Debug, Eq, PartialEq, Serialize, Deserialize, JsonSchema)] #[serde(rename_all = "PascalCase")] #[schemars(rename = "Claim")] pub struct ClaimLotusJson { diff --git a/src/lotus_json/sector_info.rs b/src/lotus_json/sector_info.rs index 2624986f6210..874603e054ed 100644 --- a/src/lotus_json/sector_info.rs +++ b/src/lotus_json/sector_info.rs @@ -5,7 +5,7 @@ use super::*; use crate::shim::sector::{RegisteredSealProof, SectorInfo}; use ::cid::Cid; -#[derive(Serialize, Deserialize, JsonSchema)] +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize, JsonSchema)] #[serde(rename_all = "PascalCase")] #[schemars(rename = "SectorInfo")] pub struct SectorInfoLotusJson { diff --git a/src/lotus_json/sector_size.rs b/src/lotus_json/sector_size.rs index 74ad8f5a40a3..43303179cfe1 100644 --- a/src/lotus_json/sector_size.rs +++ b/src/lotus_json/sector_size.rs @@ -4,7 +4,7 @@ use super::*; use crate::shim::sector::SectorSize; -#[derive(Serialize, Deserialize, JsonSchema)] +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize, JsonSchema)] #[schemars(rename = "SectorSize")] // This should probably be a JSON Schema `enum` pub struct SectorSizeLotusJson(#[schemars(with = "u64")] SectorSize); diff --git a/src/lotus_json/signature_type.rs b/src/lotus_json/signature_type.rs index 07aad5ac2cfe..562770d858a5 100644 --- a/src/lotus_json/signature_type.rs +++ b/src/lotus_json/signature_type.rs @@ -11,7 +11,7 @@ use crate::shim::crypto::SignatureType; // and // https://github.com/filecoin-project/lotus/blob/7bb1f98ac6f5a6da2cc79afc26d8cd9fe323eb30/chain/types/keystore.go#L47 -#[derive(Deserialize, Serialize, JsonSchema)] +#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize, JsonSchema)] #[serde(untagged)] // try an int, then a string pub enum SignatureTypeLotusJson { Integer(#[schemars(with = "u8")] SignatureType), diff --git a/src/lotus_json/ticket.rs b/src/lotus_json/ticket.rs index 32eac0d2c228..1ba174286801 100644 --- a/src/lotus_json/ticket.rs +++ b/src/lotus_json/ticket.rs @@ -5,7 +5,7 @@ use crate::blocks::{Ticket, VRFProof}; use super::*; -#[derive(Serialize, Deserialize, JsonSchema)] +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize, JsonSchema)] #[serde(rename_all = "PascalCase")] #[schemars(rename = "Ticket")] pub struct TicketLotusJson { diff --git a/src/shim/sector.rs b/src/shim/sector.rs index e3056d1670d2..3243602d25bb 100644 --- a/src/shim/sector.rs +++ b/src/shim/sector.rs @@ -226,7 +226,7 @@ impl quickcheck::Arbitrary for ExtendedSectorInfo { } } -#[derive(serde::Serialize, serde::Deserialize, Clone, Debug, PartialEq, derive_more::Into)] +#[derive(serde::Serialize, serde::Deserialize, Clone, Debug, Eq, PartialEq, derive_more::Into)] pub struct RegisteredPoStProof(RegisteredPoStProofV4); #[cfg(test)]