Skip to content

Commit

Permalink
chore(miner): add BatchReturn serialization tests (#1564)
Browse files Browse the repository at this point in the history
* chore(miner): add BatchReturn serialization tests

* fix(deps): const-hex as a dev depenedency everywhere
  • Loading branch information
rvagg committed Sep 12, 2024
1 parent 92a7559 commit a45fb87
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion actors/miner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand All @@ -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"]
2 changes: 1 addition & 1 deletion actors/verifreg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
1 change: 1 addition & 0 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,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"] }

Expand Down
54 changes: 54 additions & 0 deletions runtime/tests/types_test.rs
Original file line number Diff line number Diff line change
@@ -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(&params).unwrap().unwrap();
assert_eq!(const_hex::encode(&encoded.data), expected_hex);
let decoded: BatchReturn = IpldBlock::deserialize(&encoded).unwrap();
assert_eq!(params, decoded);
}
}
}

0 comments on commit a45fb87

Please sign in to comment.