-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(miner): add BatchReturn serialization tests (#1564)
* chore(miner): add BatchReturn serialization tests * fix(deps): const-hex as a dev depenedency everywhere
- Loading branch information
Showing
5 changed files
with
58 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(¶ms).unwrap().unwrap(); | ||
assert_eq!(const_hex::encode(&encoded.data), expected_hex); | ||
let decoded: BatchReturn = IpldBlock::deserialize(&encoded).unwrap(); | ||
assert_eq!(params, decoded); | ||
} | ||
} | ||
} |