Skip to content

Commit

Permalink
chore(miner): add BatchReturn serialization tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed Sep 11, 2024
1 parent 92a7559 commit b520243
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 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.

1 change: 1 addition & 0 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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 b520243

Please sign in to comment.