Skip to content

Commit

Permalink
Add Golden files for FvmStateParams
Browse files Browse the repository at this point in the history
  • Loading branch information
fridrik01 committed Feb 28, 2024
1 parent 41d1255 commit caa912a
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 2 deletions.
5 changes: 5 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions fendermint/vm/genesis/tests/golden.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Copyright 2022-2024 Protocol Labs
// SPDX-License-Identifier: Apache-2.0, MIT

/// JSON based test in case we want to configure the Genesis by hand.
/// JSON based test so we can parse data from the disk where it's nice to be human readable.
mod json {
use fendermint_testing::golden_json;
use fendermint_vm_genesis::Genesis;
use quickcheck::Arbitrary;
golden_json! { "genesis/json", genesis, Genesis::arbitrary }
}

/// CBOR based tests in case we have to grab Genesis from on-chain storage.
/// CBOR based tests to make sure we can parse data in network format.
mod cbor {
use fendermint_testing::golden_cbor;
use fendermint_vm_genesis::Genesis;
Expand Down
15 changes: 15 additions & 0 deletions fendermint/vm/interpreter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ fendermint_rpc = { path = "../../rpc" }
fendermint_actors = { path = "../../actors" }
fendermint_actor_chainmetadata = { path = "../../actors/chainmetadata" }
fendermint_actor_eam = { workspace = true }
fendermint_testing = { path = "../../testing", optional = true }
ipc_actors_abis = { workspace = true }

ipc-api = { workspace = true }
Expand Down Expand Up @@ -56,14 +57,28 @@ pin-project = { workspace = true }
tokio-stream = { workspace = true }
tokio-util = { workspace = true }

arbitrary = { workspace = true, optional = true }
quickcheck = { workspace = true, optional = true }
rand = { workspace = true, optional = true }

[dev-dependencies]
quickcheck = { workspace = true }
quickcheck_macros = { workspace = true }
tempfile = { workspace = true }

fendermint_vm_interpreter = { path = ".", features = ["arb"] }
fendermint_testing = { path = "../../testing", features = ["golden"] }
fvm = { workspace = true, features = ["arb", "testing"] }
fendermint_vm_genesis = { path = "../genesis", features = ["arb"] }
multihash = { workspace = true }

[features]
default = []
bundle = []
arb = [
"arbitrary",
"quickcheck",
"fvm_shared/arb",
"fendermint_testing/arb",
"rand",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a86a73746174655f726f6f74d82a58250001bd3ffa3d1e11163d5fa40a156e3caef9cf45f736ce99b42abede4c32ccf9d50f9018966974696d657374616d701b146ef18ccc9e55bb6f6e6574776f726b5f76657273696f6e1568626173655f6665655100c167b71a6b28cec166ff4ca208fbb3446b636972635f737570706c795100fc8ea419cbcbc401a12180e388e68f5d68636861696e5f69641b000b6b07b4af45db6b706f7765725f7363616c65006b6170705f76657273696f6e01
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FvmStateParams { state_root: Cid(bag6t76r5dyirmpk7uqfbk3r4v3446rpxg3hjtnbkx3peymwm7hkq7eaysy), timestamp: Timestamp(1472379715227375035), network_version: NetworkVersion(21), base_fee: TokenAmount(257079523536971773801.541083398290518852), circ_supply: TokenAmount(335706089450661601774.571585084053688157), chain_id: 3213905584145883, power_scale: 0, app_version: 1 }
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"state_root": "QmQysvBaHAk7sygxwxzTN2mdvA5jqXMhXzSqTDSNDDJBnF",
"timestamp": 4888195286957380285,
"network_version": 21,
"base_fee": "19429382762560951179258988865468432764",
"circ_supply": "250860824295515106050023062062359002052",
"chain_id": 0,
"power_scale": 3,
"app_version": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FvmStateParams { state_root: Cid(QmQysvBaHAk7sygxwxzTN2mdvA5jqXMhXzSqTDSNDDJBnF), timestamp: Timestamp(4888195286957380285), network_version: NetworkVersion(21), base_fee: TokenAmount(19429382762560951179.258988865468432764), circ_supply: TokenAmount(250860824295515106050.023062062359002052), chain_id: 0, power_scale: 3, app_version: 1 }
26 changes: 26 additions & 0 deletions fendermint/vm/interpreter/src/arb.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2022-2024 Protocol Labs
// SPDX-License-Identifier: Apache-2.0, MIT

use fendermint_testing::arb::{ArbCid, ArbTokenAmount};
use fendermint_vm_core::{chainid, Timestamp};
use fvm_shared::version::NetworkVersion;
use quickcheck::{Arbitrary, Gen};

use crate::fvm::state::FvmStateParams;

impl Arbitrary for FvmStateParams {
fn arbitrary(g: &mut Gen) -> Self {
Self {
state_root: ArbCid::arbitrary(g).0,
timestamp: Timestamp(u64::arbitrary(g)),
network_version: NetworkVersion::new(*g.choose(&[21]).unwrap()),
base_fee: ArbTokenAmount::arbitrary(g).0,
circ_supply: ArbTokenAmount::arbitrary(g).0,
chain_id: chainid::from_str_hashed(String::arbitrary(g).as_str())
.unwrap()
.into(),
power_scale: *g.choose(&[-1, 0, 3]).unwrap(),
app_version: *g.choose(&[0, 1, 2]).unwrap(),
}
}
}
3 changes: 3 additions & 0 deletions fendermint/vm/interpreter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ pub mod chain;
pub mod fvm;
pub mod signed;

#[cfg(feature = "arb")]
mod arb;

/// Initialize the chain state.
///
/// This could be from the original genesis file, or perhaps a checkpointed snapshot.
Expand Down
18 changes: 18 additions & 0 deletions fendermint/vm/interpreter/tests/golden.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2022-2024 Protocol Labs
// SPDX-License-Identifier: Apache-2.0, MIT

/// JSON based test in case we want to configure the FvmStateParams by hand.
mod json {
use fendermint_testing::golden_json;
use fendermint_vm_interpreter::fvm::state::FvmStateParams;
use quickcheck::Arbitrary;
golden_json! { "fvmstateparams/json", fvmstateparams, FvmStateParams::arbitrary }
}

/// CBOR based tests in case we have to grab FvmStateParams from on-chain storage.
mod cbor {
use fendermint_testing::golden_cbor;
use fendermint_vm_interpreter::fvm::state::FvmStateParams;
use quickcheck::Arbitrary;
golden_cbor! { "fvmstateparams/cbor", fvmstateparams, FvmStateParams::arbitrary }
}

0 comments on commit caa912a

Please sign in to comment.