From b52024329028213fbf557270e5170653e2aa19a5 Mon Sep 17 00:00:00 2001 From: Rod Vagg Date: Wed, 3 Jul 2024 21:59:31 +1000 Subject: [PATCH 1/2] chore(miner): add BatchReturn serialization tests --- Cargo.lock | 1 + runtime/Cargo.toml | 1 + runtime/tests/types_test.rs | 54 +++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 runtime/tests/types_test.rs diff --git a/Cargo.lock b/Cargo.lock index 5865774e2..7d5121f43 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1777,6 +1777,7 @@ dependencies = [ "byteorder", "castaway", "cid 0.10.1", + "const-hex", "derive_builder", "fil_actors_runtime", "fvm_ipld_amt", diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 8056e463d..7b1c1bd0e 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -34,6 +34,7 @@ serde_repr = { workspace = true } thiserror = { workspace = true } unsigned-varint = { workspace = true } vm_api = { workspace = true } +const-hex = { workspace = true } # A fake-proofs dependency but... we can't select on that feature here because we enable it from # build.rs. diff --git a/runtime/tests/types_test.rs b/runtime/tests/types_test.rs new file mode 100644 index 000000000..47fe77d94 --- /dev/null +++ b/runtime/tests/types_test.rs @@ -0,0 +1,54 @@ +// Tests to match with Go github.com/filecoin-project/go-state-types/*/BatchReturn +mod serialization { + use fil_actors_runtime::{BatchReturn, BatchReturnGen}; + use fvm_ipld_encoding::ipld_block::IpldBlock; + use fvm_shared::error::ExitCode; + + #[test] + fn batch_return() { + let mut test_cases = vec![]; + + let mut gen = BatchReturnGen::new(0); + test_cases.push(( + gen.gen(), + // [0,[]] + "820080", + )); + + gen = BatchReturnGen::new(1); + gen.add_success(); + test_cases.push(( + gen.gen(), + // [1,[]] + "820180", + )); + + gen = BatchReturnGen::new(1); + gen.add_fail(ExitCode::USR_ILLEGAL_ARGUMENT); + test_cases.push(( + gen.gen(), + // [0,[[0,16]]] + "820081820010", + )); + + gen = BatchReturnGen::new(5); + gen.add_success(); + gen.add_fail(ExitCode::SYS_OUT_OF_GAS); + gen.add_fail(ExitCode::USR_ILLEGAL_STATE); + gen.add_success(); + gen.add_fail(ExitCode::USR_ILLEGAL_ARGUMENT); + + test_cases.push(( + gen.gen(), + // [2,[[1,7],[2,20],[4,16]]] + "820283820107820214820410", + )); + + for (params, expected_hex) in test_cases { + let encoded = IpldBlock::serialize_cbor(¶ms).unwrap().unwrap(); + assert_eq!(const_hex::encode(&encoded.data), expected_hex); + let decoded: BatchReturn = IpldBlock::deserialize(&encoded).unwrap(); + assert_eq!(params, decoded); + } + } +} From 4d290b19d9fc4985d44133dda11f8d68b5d55b07 Mon Sep 17 00:00:00 2001 From: Rod Vagg Date: Thu, 12 Sep 2024 10:45:08 +1000 Subject: [PATCH 2/2] fix(deps): const-hex as a dev depenedency everywhere --- actors/miner/Cargo.toml | 2 +- actors/verifreg/Cargo.toml | 2 +- runtime/Cargo.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/actors/miner/Cargo.toml b/actors/miner/Cargo.toml index 047231f30..bc03e1ae9 100644 --- a/actors/miner/Cargo.toml +++ b/actors/miner/Cargo.toml @@ -33,7 +33,6 @@ lazy_static = { workspace = true } log = { workspace = true } byteorder = { workspace = true } itertools = { workspace = true } -const-hex = { workspace = true } [dev-dependencies] fil_actors_runtime = { workspace = true, features = ["test_utils", "sector-default"] } @@ -43,6 +42,7 @@ fil_actor_power = { workspace = true } fil_actor_market = { workspace = true } rand = { workspace = true } test-case = { workspace = true } +const-hex = { workspace = true } [features] fil-actor = ["fil_actors_runtime/fil-actor"] diff --git a/actors/verifreg/Cargo.toml b/actors/verifreg/Cargo.toml index 66bd676b5..2e003e5a8 100644 --- a/actors/verifreg/Cargo.toml +++ b/actors/verifreg/Cargo.toml @@ -30,9 +30,9 @@ log = { workspace = true } num-derive = { workspace = true } num-traits = { workspace = true } serde = { workspace = true } -const-hex = { workspace = true } [dev-dependencies] +const-hex = { workspace = true } fil_actors_runtime = { workspace = true, features = ["test_utils", "sector-default"] } [features] diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 7b1c1bd0e..3379ac93b 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -34,7 +34,6 @@ serde_repr = { workspace = true } thiserror = { workspace = true } unsigned-varint = { workspace = true } vm_api = { workspace = true } -const-hex = { workspace = true } # A fake-proofs dependency but... we can't select on that feature here because we enable it from # build.rs. @@ -56,6 +55,7 @@ optional = true derive_builder = { workspace = true } hex = { workspace = true } rand = { workspace = true } +const-hex = { workspace = true } # Enable the test_utils feature when testing. fil_actors_runtime = { workspace = true, features = ["test_utils"] }