diff --git a/src/lotus_json/actors/states/account_state.rs b/src/lotus_json/actors/states/account_state.rs index 099b95c9d22b..8f6408dd2bc6 100644 --- a/src/lotus_json/actors/states/account_state.rs +++ b/src/lotus_json/actors/states/account_state.rs @@ -2,10 +2,10 @@ // SPDX-License-Identifier: Apache-2.0, MIT use super::*; -use crate::shim::{actors::account, address::Address}; +use crate::shim::{actors::account::State, address::Address}; use serde::{Deserialize, Serialize}; -#[derive(Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Debug, Eq, PartialEq, Serialize, Deserialize, JsonSchema)] #[serde(rename_all = "PascalCase")] pub struct AccountStateLotusJson { #[schemars(with = "LotusJson
")] @@ -13,7 +13,7 @@ pub struct AccountStateLotusJson { address: Address, } -impl HasLotusJson for account::State { +impl HasLotusJson for State { type LotusJson = AccountStateLotusJson; #[cfg(test)] @@ -38,3 +38,4 @@ impl HasLotusJson for account::State { Self::default_latest_version(lotus_json.address.into()) } } +crate::test_snapshots!(State); diff --git a/src/lotus_json/actors/states/cron_state.rs b/src/lotus_json/actors/states/cron_state.rs index 71ada9fb45ae..fa092d51fdad 100644 --- a/src/lotus_json/actors/states/cron_state.rs +++ b/src/lotus_json/actors/states/cron_state.rs @@ -5,7 +5,7 @@ use super::*; use crate::shim::actors::cron::{Entry, State}; use serde::{Deserialize, Serialize}; -#[derive(Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Debug, PartialEq, Serialize, Deserialize, JsonSchema)] #[serde(rename_all = "PascalCase")] pub struct CronStateLotusJson { #[schemars(with = "LotusJson>")] @@ -75,3 +75,4 @@ impl HasLotusJson for State { State::default_latest_version_from_entries(entries) } } +crate::test_snapshots!(State); diff --git a/src/lotus_json/actors/states/datacap_state.rs b/src/lotus_json/actors/states/datacap_state.rs index a1e7887e7244..ec138f364675 100644 --- a/src/lotus_json/actors/states/datacap_state.rs +++ b/src/lotus_json/actors/states/datacap_state.rs @@ -6,7 +6,7 @@ use crate::shim::actors::datacap::State; use crate::shim::address::Address; use fil_actors_shared::frc46_token::token::state::TokenState; -#[derive(Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Debug, Eq, PartialEq, Serialize, Deserialize, JsonSchema)] #[serde(rename_all = "PascalCase")] #[schemars(rename = "DatacapState")] pub struct DatacapStateLotusJson { @@ -26,12 +26,12 @@ impl HasLotusJson for State { fn snapshots() -> Vec<(serde_json::Value, Self)> { vec![( json!({ - "governor": "t00", - "token": { - "supply": "0", - "balances": {"/":"baeaaaaa"}, - "allowances": {"/":"baeaaaaa"}, - "hamt_bit_width": 0 + "Governor": "f00", + "Token": { + "Supply": "0", + "Balances": {"/":"baeaaaaa"}, + "Allowances": {"/":"baeaaaaa"}, + "HamtBitWidth": 0 } }), State::default_latest_version( @@ -70,3 +70,4 @@ impl HasLotusJson for State { State::default_latest_version(lotus_json.governor.into(), lotus_json.token) } } +crate::test_snapshots!(State); diff --git a/src/lotus_json/actors/states/evm_state.rs b/src/lotus_json/actors/states/evm_state.rs index df0e97406542..cc95ac9dfd5f 100644 --- a/src/lotus_json/actors/states/evm_state.rs +++ b/src/lotus_json/actors/states/evm_state.rs @@ -6,7 +6,7 @@ use crate::shim::actors::evm::{State, TombstoneState}; use ::cid::Cid; use pastey::paste; -#[derive(Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Debug, Eq, PartialEq, Serialize, Deserialize, JsonSchema)] #[serde(rename_all = "PascalCase")] #[schemars(rename = "EVMState")] pub struct EVMStateLotusJson { @@ -35,60 +35,67 @@ macro_rules! impl_evm_state_lotus_json { (no_transient_data: $($version:literal),+) => { $( paste! { - impl HasLotusJson for fil_actor_evm_state::[]::State { - type LotusJson = EVMStateLotusJson; - - #[cfg(test)] - fn snapshots() -> Vec<(serde_json::Value, Self)> { - vec![( - json!({ - "Bytecode": {"/":"baeaaaaa"}, - "BytecodeHash": "0x0000000000000000000000000000000000000000000000000000000000000000", - "ContractState": {"/":"baeaaaaa"}, - "Nonce": 0, - "Tombstone": null, - "TransientData": null - }), - Self { - bytecode: Cid::default(), - bytecode_hash: fil_actor_evm_state::[]::BytecodeHash::from([0; 32]), - contract_state: Cid::default(), - nonce: 0, - tombstone: None, - }, - )] + mod [] { + use super::*; + type T = fil_actor_evm_state::[]::State; + #[test] + fn snapshots() { + crate::lotus_json::assert_all_snapshots::(); } + impl HasLotusJson for T { + type LotusJson = EVMStateLotusJson; + #[cfg(test)] + fn snapshots() -> Vec<(serde_json::Value, Self)> { + vec![( + json!({ + "Bytecode": {"/":"baeaaaaa"}, + "BytecodeHash": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], + "ContractState": {"/":"baeaaaaa"}, + "Nonce": 0, + "Tombstone": null, + "TransientData": null + }), + Self { + bytecode: Cid::default(), + bytecode_hash: fil_actor_evm_state::[]::BytecodeHash::from([0; 32]), + contract_state: Cid::default(), + nonce: 0, + tombstone: None, + }, + )] + } - fn into_lotus_json(self) -> Self::LotusJson { - let bytecode_hash_data: [u8; 32] = self.bytecode_hash.into(); - - EVMStateLotusJson { - bytecode: self.bytecode, - bytecode_hash: bytecode_hash_data, - contract_state: self.contract_state, - nonce: self.nonce, - tombstone: self.tombstone.map(|t| { - let tombstone_state = TombstoneState::[](t); - tombstone_state.into_lotus_json() - }), - transient_data: None, + fn into_lotus_json(self) -> Self::LotusJson { + let bytecode_hash_data: [u8; 32] = self.bytecode_hash.into(); + + EVMStateLotusJson { + bytecode: self.bytecode, + bytecode_hash: bytecode_hash_data, + contract_state: self.contract_state, + nonce: self.nonce, + tombstone: self.tombstone.map(|t| { + let tombstone_state = TombstoneState::[](t); + tombstone_state.into_lotus_json() + }), + transient_data: None, + } } - } - fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { - let tombstone = lotus_json.tombstone.map(|tombstone_lotus| { - fil_actor_evm_state::[]::Tombstone { - origin: tombstone_lotus.origin.into(), - nonce: tombstone_lotus.nonce, + fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { + let tombstone = lotus_json.tombstone.map(|tombstone_lotus| { + fil_actor_evm_state::[]::Tombstone { + origin: tombstone_lotus.origin.into(), + nonce: tombstone_lotus.nonce, + } + }); + + Self { + bytecode: lotus_json.bytecode, + bytecode_hash: fil_actor_evm_state::[]::BytecodeHash::from(lotus_json.bytecode_hash), + contract_state: lotus_json.contract_state, + nonce: lotus_json.nonce, + tombstone, } - }); - - Self { - bytecode: lotus_json.bytecode, - bytecode_hash: fil_actor_evm_state::[]::BytecodeHash::from(lotus_json.bytecode_hash), - contract_state: lotus_json.contract_state, - nonce: lotus_json.nonce, - tombstone, } } } @@ -99,70 +106,78 @@ macro_rules! impl_evm_state_lotus_json { (with_transient_data: $($version:literal),+) => { $( paste! { - impl HasLotusJson for fil_actor_evm_state::[]::State { - type LotusJson = EVMStateLotusJson; - - #[cfg(test)] - fn snapshots() -> Vec<(serde_json::Value, Self)> { - vec![( - json!({ - "Bytecode": {"/":"baeaaaaa"}, - "BytecodeHash": "0x0000000000000000000000000000000000000000000000000000000000000000", - "ContractState": {"/":"baeaaaaa"}, - "Nonce": 0, - "Tombstone": null, - "TransientData": null - }), - Self { - bytecode: Cid::default(), - bytecode_hash: fil_actor_evm_state::[]::BytecodeHash::from([0; 32]), - contract_state: Cid::default(), - nonce: 0, - tombstone: None, - transient_data: None, - }, - )] + mod [] { + use super::*; + type T = fil_actor_evm_state::[]::State; + #[test] + fn snapshots() { + crate::lotus_json::assert_all_snapshots::(); } - - fn into_lotus_json(self) -> Self::LotusJson { - let bytecode_hash_data: [u8; 32] = self.bytecode_hash.into(); - - EVMStateLotusJson { - bytecode: self.bytecode, - bytecode_hash: bytecode_hash_data, - contract_state: self.contract_state, - nonce: self.nonce, - tombstone: self.tombstone.map(|t| { - let tombstone_state = TombstoneState::[](t); - tombstone_state.into_lotus_json() - }), - transient_data: Some(self.transient_data.map(|td| { - td.into_lotus_json() - })), + impl HasLotusJson for T { + type LotusJson = EVMStateLotusJson; + + #[cfg(test)] + fn snapshots() -> Vec<(serde_json::Value, Self)> { + vec![( + json!({ + "Bytecode": {"/":"baeaaaaa"}, + "BytecodeHash": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], + "ContractState": {"/":"baeaaaaa"}, + "Nonce": 0, + "Tombstone": null, + "TransientData": null + }), + Self { + bytecode: Cid::default(), + bytecode_hash: fil_actor_evm_state::[]::BytecodeHash::from([0; 32]), + contract_state: Cid::default(), + nonce: 0, + tombstone: None, + transient_data: None, + }, + )] } - } - fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { - let tombstone = lotus_json.tombstone.map(|tombstone_lotus| { - fil_actor_evm_state::[]::Tombstone { - origin: tombstone_lotus.origin.into(), - nonce: tombstone_lotus.nonce, + fn into_lotus_json(self) -> Self::LotusJson { + let bytecode_hash_data: [u8; 32] = self.bytecode_hash.into(); + + EVMStateLotusJson { + bytecode: self.bytecode, + bytecode_hash: bytecode_hash_data, + contract_state: self.contract_state, + nonce: self.nonce, + tombstone: self.tombstone.map(|t| { + let tombstone_state = TombstoneState::[](t); + tombstone_state.into_lotus_json() + }), + transient_data: Some(self.transient_data.map(|td| { + td.into_lotus_json() + })), } - }); + } - let transient_data = lotus_json.transient_data - .and_then(|outer_option| outer_option) - .map(|transient_data_lotus| { - fil_actor_evm_state::[]::TransientData::from_lotus_json(transient_data_lotus) + fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { + let tombstone = lotus_json.tombstone.map(|tombstone_lotus| { + fil_actor_evm_state::[]::Tombstone { + origin: tombstone_lotus.origin.into(), + nonce: tombstone_lotus.nonce, + } }); - Self { - bytecode: lotus_json.bytecode, - bytecode_hash: fil_actor_evm_state::[]::BytecodeHash::from(lotus_json.bytecode_hash), - contract_state: lotus_json.contract_state, - nonce: lotus_json.nonce, - tombstone, - transient_data, + let transient_data = lotus_json.transient_data + .and_then(|outer_option| outer_option) + .map(|transient_data_lotus| { + fil_actor_evm_state::[]::TransientData::from_lotus_json(transient_data_lotus) + }); + + Self { + bytecode: lotus_json.bytecode, + bytecode_hash: fil_actor_evm_state::[]::BytecodeHash::from(lotus_json.bytecode_hash), + contract_state: lotus_json.contract_state, + nonce: lotus_json.nonce, + tombstone, + transient_data, + } } } } @@ -179,7 +194,7 @@ impl HasLotusJson for State { vec![( json!({ "Bytecode": {"/":"baeaaaaa"}, - "BytecodeHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "BytecodeHash": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], "ContractState": {"/":"baeaaaaa"}, "Nonce": 0, "Tombstone": null, @@ -216,6 +231,7 @@ impl HasLotusJson for State { ) } } +crate::test_snapshots!(State); // Implement for versions without transient_data (v10-v15) impl_evm_state_lotus_json!(no_transient_data: 10, 11, 12, 13, 14, 15); diff --git a/src/lotus_json/actors/states/init_state.rs b/src/lotus_json/actors/states/init_state.rs index 437f916f10b0..f30e1bf422da 100644 --- a/src/lotus_json/actors/states/init_state.rs +++ b/src/lotus_json/actors/states/init_state.rs @@ -5,7 +5,7 @@ use super::*; use crate::shim::actors::init::State; use ::cid::Cid; -#[derive(Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Debug, Eq, PartialEq, Serialize, Deserialize, JsonSchema)] #[serde(rename_all = "PascalCase")] #[schemars(rename = "InitState")] pub struct InitStateLotusJson { @@ -59,3 +59,4 @@ impl HasLotusJson for State { ) } } +crate::test_snapshots!(State); diff --git a/src/lotus_json/actors/states/market_state.rs b/src/lotus_json/actors/states/market_state.rs index d4ca4e0bc701..83989cf1dd26 100644 --- a/src/lotus_json/actors/states/market_state.rs +++ b/src/lotus_json/actors/states/market_state.rs @@ -7,7 +7,7 @@ use crate::shim::{clock::ChainEpoch, econ::TokenAmount}; use ::cid::Cid; use fvm_shared4::deal::DealID; -#[derive(Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Debug, Eq, PartialEq, Serialize, Deserialize, JsonSchema)] #[serde(rename_all = "PascalCase")] #[schemars(rename = "MarketState")] pub struct MarketStateLotusJson { @@ -131,7 +131,7 @@ impl HasLotusJson for State { "TotalClientLockedCollateral": "0", "TotalProviderLockedCollateral": "0", "TotalClientStorageFee": "0", - "PendingDealAllocationIDs": {"/":"baeaaaaa"}, + "PendingDealAllocationIds": {"/":"baeaaaaa"}, "ProviderSectors": {"/":"baeaaaaa"} }), State::default_latest_version( @@ -195,3 +195,4 @@ impl HasLotusJson for State { ) } } +crate::test_snapshots!(State); diff --git a/src/lotus_json/actors/states/miner_state.rs b/src/lotus_json/actors/states/miner_state.rs index 55341ef9db87..4678af6475ca 100644 --- a/src/lotus_json/actors/states/miner_state.rs +++ b/src/lotus_json/actors/states/miner_state.rs @@ -10,7 +10,7 @@ use fvm_shared4::clock::ChainEpoch; use super::vesting_funds::{VestingFundLotusJson, VestingFundsLotusJson}; -#[derive(Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Debug, Eq, PartialEq, Serialize, Deserialize, JsonSchema)] #[serde(rename_all = "PascalCase")] #[schemars(rename = "MinerState")] pub struct MinerStateLotusJson { @@ -69,7 +69,7 @@ pub struct MinerStateLotusJson { } // VestingFunds can be either embedded (V16+) or referenced via Cid (V8-V15). -#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)] +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize, JsonSchema)] #[serde(untagged)] pub enum VestingFundsValue { Embedded(VestingFundsLotusJson), @@ -136,13 +136,13 @@ impl HasLotusJson for State { vec![( json!({ "Info": {"/":"baeaaaaa"}, - "PreCommitDeposits": "1000000000000000000", - "LockedFunds": "2000000000000000000", + "PreCommitDeposits": "0", + "LockedFunds": "0", "VestingFunds": null, - "FeeDebt": "400000000000000000", - "InitialPledge": "5000000000000000000", + "FeeDebt": "0", + "InitialPledge": "0", "PreCommittedSectors": {"/":"baeaaaaa"}, - "PreCommittedSectorsCleanup": {"/":"baeaaaaa"}, + "PreCommittedSectorsCleanUp": {"/":"baeaaaaa"}, "AllocatedSectors": {"/":"baeaaaaa"}, "Sectors": {"/":"baeaaaaa"}, "ProvingPeriodStart": 0, @@ -236,3 +236,4 @@ impl HasLotusJson for State { ) } } +crate::test_snapshots!(State); diff --git a/src/lotus_json/actors/states/multisig_state.rs b/src/lotus_json/actors/states/multisig_state.rs index 250414bb69c8..f280e58ec7fe 100644 --- a/src/lotus_json/actors/states/multisig_state.rs +++ b/src/lotus_json/actors/states/multisig_state.rs @@ -8,7 +8,7 @@ use crate::shim::clock::ChainEpoch; use crate::shim::econ::TokenAmount; use ::cid::Cid; -#[derive(Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Debug, Eq, PartialEq, Serialize, Deserialize, JsonSchema)] #[serde(rename_all = "PascalCase")] #[schemars(rename = "MultisigState")] pub struct MultisigStateLotusJson { @@ -45,7 +45,7 @@ impl HasLotusJson for State { fn snapshots() -> Vec<(serde_json::Value, Self)> { vec![( json!({ - "Signers": [], + "Signers": null, "NumApprovalsThreshold": 0, "NextTxnID": 0, "InitialBalance": "0", @@ -104,3 +104,4 @@ impl HasLotusJson for State { ) } } +crate::test_snapshots!(State); diff --git a/src/lotus_json/actors/states/payment_channel_state.rs b/src/lotus_json/actors/states/payment_channel_state.rs index 39068893491d..5d27ee1dbc66 100644 --- a/src/lotus_json/actors/states/payment_channel_state.rs +++ b/src/lotus_json/actors/states/payment_channel_state.rs @@ -8,7 +8,7 @@ use crate::shim::clock::ChainEpoch; use crate::shim::econ::TokenAmount; use ::cid::Cid; -#[derive(Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Debug, Eq, PartialEq, Serialize, Deserialize, JsonSchema)] #[serde(rename_all = "PascalCase")] #[schemars(rename = "PaymentChannelState")] pub struct PaymentChannelStateLotusJson { @@ -96,3 +96,4 @@ impl HasLotusJson for State { ) } } +crate::test_snapshots!(State); diff --git a/src/lotus_json/actors/states/power_states.rs b/src/lotus_json/actors/states/power_states.rs index 4738a7eb8a5a..526d0c8a5be6 100644 --- a/src/lotus_json/actors/states/power_states.rs +++ b/src/lotus_json/actors/states/power_states.rs @@ -8,7 +8,7 @@ use ::cid::Cid; use fil_actors_shared::v16::reward::FilterEstimate; use num::BigInt; -#[derive(Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Debug, Eq, PartialEq, Serialize, Deserialize, JsonSchema)] #[serde(rename_all = "PascalCase")] #[schemars(rename = "PowerState")] pub struct PowerStateLotusJson { @@ -134,8 +134,8 @@ impl HasLotusJson for State { "ThisEpochQualityAdjPower": "0", "ThisEpochPledgeCollateral": "0", "ThisEpochQAPowerSmoothed": { - "Position": "0", - "Velocity": "0" + "PositionEstimate": "0", + "VelocityEstimate": "0" }, "MinerCount": 0, "MinerAboveMinPowerCount": 0, @@ -217,3 +217,4 @@ impl HasLotusJson for State { ) } } +crate::test_snapshots!(State); diff --git a/src/lotus_json/actors/states/reward_state.rs b/src/lotus_json/actors/states/reward_state.rs index fee24e84fed2..74b25d5c4306 100644 --- a/src/lotus_json/actors/states/reward_state.rs +++ b/src/lotus_json/actors/states/reward_state.rs @@ -8,7 +8,7 @@ use crate::shim::econ::TokenAmount; use fil_actors_shared::v16::reward::FilterEstimate; use num_bigint::BigInt; -#[derive(Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Debug, Eq, PartialEq, Serialize, Deserialize, JsonSchema)] #[serde(rename_all = "PascalCase")] #[schemars(rename = "RewardState")] pub struct RewardStateLotusJson { @@ -70,8 +70,8 @@ impl HasLotusJson for State { "EffectiveBaselinePower": "1", "ThisEpochReward": "1", "ThisEpochRewardSmoothed": { - "Position": "1", - "Velocity": "1", + "PositionEstimate": "1", + "VelocityEstimate": "1", }, "ThisEpochBaselinePower": "1", "Epoch": 1, @@ -147,3 +147,4 @@ impl HasLotusJson for State { ) } } +crate::test_snapshots!(State); diff --git a/src/lotus_json/actors/states/system_state.rs b/src/lotus_json/actors/states/system_state.rs index 979a1e846ebd..c6e6fbee59ca 100644 --- a/src/lotus_json/actors/states/system_state.rs +++ b/src/lotus_json/actors/states/system_state.rs @@ -5,7 +5,7 @@ use super::*; use crate::shim::actors::system::State; use ::cid::Cid; -#[derive(Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Debug, Eq, PartialEq, Serialize, Deserialize, JsonSchema)] #[serde(rename_all = "PascalCase")] #[schemars(rename = "SystemState")] pub struct SystemStateLotusJson { @@ -50,3 +50,4 @@ impl HasLotusJson for State { State::default_latest_version(lotus_json.builtin_actors) } } +crate::test_snapshots!(State); diff --git a/src/lotus_json/actors/states/verified_reg_state.rs b/src/lotus_json/actors/states/verified_reg_state.rs index 7e3f8167703e..07fe208f86f1 100644 --- a/src/lotus_json/actors/states/verified_reg_state.rs +++ b/src/lotus_json/actors/states/verified_reg_state.rs @@ -6,7 +6,7 @@ use crate::shim::actors::verifreg::State; use crate::shim::address::Address; use ::cid::Cid; -#[derive(Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Debug, Eq, PartialEq, Serialize, Deserialize, JsonSchema)] #[serde(rename_all = "PascalCase")] #[schemars(rename = "VerifiedRegistryState")] pub struct VerifiedRegistryStateLotusJson { @@ -23,18 +23,30 @@ pub struct VerifiedRegistryStateLotusJson { pub remove_data_cap_proposal_ids: Cid, #[schemars(with = "LotusJson>")] - #[serde(with = "crate::lotus_json", skip_serializing_if = "Option::is_none")] + #[serde( + with = "crate::lotus_json", + default, + skip_serializing_if = "Option::is_none" + )] pub verified_clients: Option, // only available in verified reg state version 8 #[schemars(with = "LotusJson>")] - #[serde(with = "crate::lotus_json", skip_serializing_if = "Option::is_none")] + #[serde( + with = "crate::lotus_json", + default, + skip_serializing_if = "Option::is_none" + )] pub allocations: Option, // not available in verified reg state version 8 #[serde(skip_serializing_if = "Option::is_none")] pub next_allocation_id: Option, // not available in verified reg state version 8 #[schemars(with = "LotusJson>")] - #[serde(with = "crate::lotus_json", skip_serializing_if = "Option::is_none")] + #[serde( + with = "crate::lotus_json", + default, + skip_serializing_if = "Option::is_none" + )] pub claims: Option, // not available in verified reg state version 8 } @@ -78,7 +90,7 @@ impl HasLotusJson for State { "RemoveDataCapProposalIDs": {"/":"baeaaaaa"}, "Allocations": {"/":"baeaaaaa"}, "NextAllocationId": 0, - "Claims": {"/":"baeaaaaa"} + "Claims": {"/":"baeaaaaa"}, }), State::default_latest_version( Address::new_id(0).into(), @@ -126,3 +138,4 @@ impl HasLotusJson for State { ) } } +crate::test_snapshots!(State); diff --git a/src/lotus_json/actors/states/vesting_funds.rs b/src/lotus_json/actors/states/vesting_funds.rs index 28bd9d7dcb87..199399f28656 100644 --- a/src/lotus_json/actors/states/vesting_funds.rs +++ b/src/lotus_json/actors/states/vesting_funds.rs @@ -7,7 +7,7 @@ use ::cid::Cid; use pastey::paste; // Single LotusJson struct for VestingFund (used by all versions) -#[derive(Debug, Serialize, Deserialize, JsonSchema, Clone)] +#[derive(Debug, Eq, PartialEq, Serialize, Deserialize, JsonSchema, Clone)] #[serde(rename_all = "PascalCase")] #[schemars(rename = "VestingFund")] pub struct VestingFundLotusJson { @@ -18,7 +18,7 @@ pub struct VestingFundLotusJson { } // Single LotusJson struct for VestingFunds (used by all versions) -#[derive(Debug, Serialize, Deserialize, JsonSchema, Clone)] +#[derive(Debug, Eq, PartialEq, Serialize, Deserialize, JsonSchema, Clone)] #[serde(rename_all = "PascalCase")] #[schemars(rename = "VestingFunds")] pub struct VestingFundsLotusJson { @@ -34,104 +34,122 @@ macro_rules! impl_vesting_funds_lotus_json { ($($version_num:literal),+) => { $( paste! { - // Implement HasLotusJson for VestingFund - impl HasLotusJson for fil_actor_miner_state::[]::VestingFund { - type LotusJson = VestingFundLotusJson; + mod [] { + use super::*; + type T = fil_actor_miner_state::[]::VestingFund; + #[test] + fn snapshots() { + crate::lotus_json::assert_all_snapshots::(); + } + // Implement HasLotusJson for VestingFund + impl HasLotusJson for T { + type LotusJson = VestingFundLotusJson; - #[cfg(test)] - fn snapshots() -> Vec<(serde_json::Value, Self)> { - use fvm_shared4::bigint::BigInt; + #[cfg(test)] + fn snapshots() -> Vec<(serde_json::Value, Self)> { + use fvm_shared4::bigint::BigInt; - vec![ - ( - json!({ - "Epoch": 1000, - "Amount": "0" - }), - Self { - epoch: 1000, - amount: Default::default(), - }, - ), - ( - json!({ - "Epoch": 2000, - "Amount": "1000000000000000000" - }), - Self { - epoch: 2000, - amount: TokenAmount::from_atto(BigInt::from(10u64.pow(18))).into(), - }, - ), - ] - } + vec![ + ( + json!({ + "Epoch": 1000, + "Amount": "0" + }), + Self { + epoch: 1000, + amount: Default::default(), + }, + ), + ( + json!({ + "Epoch": 2000, + "Amount": "1000000000000000000" + }), + Self { + epoch: 2000, + amount: TokenAmount::from_atto(BigInt::from(10u64.pow(18))).into(), + }, + ), + ] + } - fn into_lotus_json(self) -> Self::LotusJson { - VestingFundLotusJson { - epoch: self.epoch, - amount: self.amount.into(), + fn into_lotus_json(self) -> Self::LotusJson { + VestingFundLotusJson { + epoch: self.epoch, + amount: self.amount.into(), + } } - } - fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { - Self { - epoch: lotus_json.epoch, - amount: lotus_json.amount.into(), + fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { + Self { + epoch: lotus_json.epoch, + amount: lotus_json.amount.into(), + } } } } - // Implement HasLotusJson for VestingFunds - impl HasLotusJson for fil_actor_miner_state::[]::VestingFunds { - type LotusJson = Option; - - #[cfg(test)] - fn snapshots() -> Vec<(serde_json::Value, Self)> { - vec![ - (json!(null), Self(None)), - ( - json!({ - "Head": { - "Epoch": 1000, - "Amount": "1000000000000000000" - }, - "Tail": "bafy2bzaceaa43t4wykyk57ibfghjkvcbartledtcflp25htn56svwkrtp6ddy" - }), - Self(Some(fil_actor_miner_state::[]::VestingFundsInner { - head: fil_actor_miner_state::[]::VestingFund { - epoch: 1000, - amount: TokenAmount::from_atto(num_bigint::BigInt::from(10u64.pow(18))) - .into(), - }, - tail: Cid::try_from( - "bafy2bzaceaa43t4wykyk57ibfghjkvcbartledtcflp25htn56svwkrtp6ddy", - ) - .unwrap(), - })), - ), - ] + mod [] { + use super::*; + type T = fil_actor_miner_state::[]::VestingFunds; + #[test] + fn snapshots() { + crate::lotus_json::assert_all_snapshots::(); } + // Implement HasLotusJson for VestingFunds + impl HasLotusJson for T { + type LotusJson = Option; - fn into_lotus_json(self) -> Self::LotusJson { - self.0.map(|v| VestingFundsLotusJson { - head: VestingFundLotusJson { - epoch: v.head.epoch, - amount: v.head.amount.into(), - }, - tail: v.tail, - }) - } + #[cfg(test)] + fn snapshots() -> Vec<(serde_json::Value, Self)> { + vec![ + (json!(null), Self(None)), + ( + json!({ + "Head": { + "Epoch": 1000, + "Amount": "1000000000000000000" + }, + "Tail": { + "/": "bafy2bzaceaa43t4wykyk57ibfghjkvcbartledtcflp25htn56svwkrtp6ddy" + } + }), + Self(Some(fil_actor_miner_state::[]::VestingFundsInner { + head: fil_actor_miner_state::[]::VestingFund { + epoch: 1000, + amount: TokenAmount::from_atto(num_bigint::BigInt::from(10u64.pow(18))) + .into(), + }, + tail: Cid::try_from( + "bafy2bzaceaa43t4wykyk57ibfghjkvcbartledtcflp25htn56svwkrtp6ddy", + ) + .unwrap(), + })), + ), + ] + } - fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { - match lotus_json { - None => Self(None), - Some(json) => Self(Some(fil_actor_miner_state::[]::VestingFundsInner { - head: fil_actor_miner_state::[]::VestingFund { - epoch: json.head.epoch, - amount: json.head.amount.into(), + fn into_lotus_json(self) -> Self::LotusJson { + self.0.map(|v| VestingFundsLotusJson { + head: VestingFundLotusJson { + epoch: v.head.epoch, + amount: v.head.amount.into(), }, - tail: json.tail, - })), + tail: v.tail, + }) + } + + fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { + match lotus_json { + None => Self(None), + Some(json) => Self(Some(fil_actor_miner_state::[]::VestingFundsInner { + head: fil_actor_miner_state::[]::VestingFund { + epoch: json.head.epoch, + amount: json.head.amount.into(), + }, + tail: json.tail, + })), + } } } } diff --git a/src/lotus_json/tombstone.rs b/src/lotus_json/tombstone.rs index 6149d399fa83..816c4a247c66 100644 --- a/src/lotus_json/tombstone.rs +++ b/src/lotus_json/tombstone.rs @@ -5,7 +5,7 @@ use super::*; use crate::shim::actors::evm::TombstoneState; use fvm_shared4::ActorID; -#[derive(Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Debug, Eq, PartialEq, Serialize, Deserialize, JsonSchema)] #[serde(rename_all = "PascalCase")] #[schemars(rename = "Tombstone")] pub struct TombstoneLotusJson { @@ -49,3 +49,4 @@ impl HasLotusJson for TombstoneState { TombstoneState::default_latest_version(lotus_json.origin, lotus_json.nonce) } } +crate::test_snapshots!(TombstoneState); diff --git a/src/lotus_json/transient_data.rs b/src/lotus_json/transient_data.rs index 5e40674c0229..7a762a3f8ab0 100644 --- a/src/lotus_json/transient_data.rs +++ b/src/lotus_json/transient_data.rs @@ -6,7 +6,7 @@ use ::cid::Cid; use fvm_shared4::ActorID; use pastey::paste; -#[derive(Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Debug, Eq, PartialEq, Serialize, Deserialize, JsonSchema)] #[serde(rename_all = "PascalCase")] #[schemars(rename = "TransientData")] pub struct TransientDataLotusJson { @@ -16,7 +16,7 @@ pub struct TransientDataLotusJson { pub transient_data_lifespan: TransientDataLifespanLotusJson, } -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)] +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize, JsonSchema)] #[serde(rename_all = "PascalCase")] #[schemars(rename = "TransientDataLifespan")] pub struct TransientDataLifespanLotusJson { diff --git a/src/shim/actors/builtin/cron/mod.rs b/src/shim/actors/builtin/cron/mod.rs index 88e2f4eba27b..6f81d8166c64 100644 --- a/src/shim/actors/builtin/cron/mod.rs +++ b/src/shim/actors/builtin/cron/mod.rs @@ -44,7 +44,7 @@ impl State { } } -#[derive(Clone, Serialize, Debug)] +#[derive(Clone, PartialEq, Serialize, Debug)] #[serde(untagged)] pub enum Entry { V8(fil_actor_cron_state::v8::Entry),