Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(miner): add BatchReturn serialization tests #1564

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
}
Loading