forked from filecoin-project/builtin-actors
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BatchReturn tests (filecoin-project#753)
Co-authored-by: zenground0 <[email protected]> Co-authored-by: Aayush Rajasekaran <[email protected]>
- Loading branch information
Showing
1 changed file
with
81 additions
and
0 deletions.
There are no files selected for viewing
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,81 @@ | ||
use fil_actors_runtime::{BatchReturn, BatchReturnGen}; | ||
use fvm_shared::error::ExitCode; | ||
|
||
#[test] | ||
fn batch_generation() { | ||
let mut 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); | ||
|
||
let br = gen.gen(); | ||
assert_eq!(5, br.size()); | ||
assert!(!br.all_ok()); | ||
assert_eq!( | ||
vec![ | ||
ExitCode::OK, | ||
ExitCode::SYS_OUT_OF_GAS, | ||
ExitCode::USR_ILLEGAL_STATE, | ||
ExitCode::OK, | ||
ExitCode::USR_ILLEGAL_ARGUMENT | ||
], | ||
br.codes() | ||
); | ||
|
||
let ret_vals = vec!["first", "second", "third", "fourth", "fifth"]; | ||
assert_eq!(vec!["first", "fourth"], br.successes(&ret_vals)); | ||
} | ||
|
||
#[test] | ||
fn batch_generation_constants() { | ||
let br = BatchReturn::ok(3); | ||
assert_eq!(3, br.size()); | ||
assert!(br.all_ok()); | ||
assert_eq!(vec![ExitCode::OK, ExitCode::OK, ExitCode::OK], br.codes()); | ||
let ret_vals = vec!["first", "second", "third"]; | ||
assert_eq!(ret_vals, br.successes(&ret_vals)); | ||
|
||
let br = BatchReturn::empty(); | ||
assert_eq!(0, br.size()); | ||
assert!(br.all_ok()); | ||
assert_eq!(Vec::<ExitCode>::new(), br.codes()); | ||
let empty_successes = Vec::<u64>::new(); | ||
assert_eq!(empty_successes, br.successes(&empty_successes)); | ||
} | ||
|
||
#[test] | ||
#[should_panic( | ||
expected = "programmer error, mismatched batch size 3 and processed count 4 batch return must include success/fail for all inputs" | ||
)] | ||
fn batch_generation_programmer_error_too_many() { | ||
let mut gen = BatchReturnGen::new(3); | ||
gen.add_success(); | ||
gen.add_success(); | ||
gen.add_success(); | ||
gen.add_success(); | ||
|
||
// this will panic | ||
gen.gen(); | ||
} | ||
|
||
#[test] | ||
#[should_panic( | ||
expected = "programmer error, mismatched batch size 3 and processed count 2 batch return must include success/fail for all inputs" | ||
)] | ||
fn batch_generation_programmer_error_too_few() { | ||
let mut gen = BatchReturnGen::new(3); | ||
gen.add_success(); | ||
gen.add_fail(ExitCode::USR_NOT_FOUND); | ||
|
||
// this will panic | ||
gen.gen(); | ||
} | ||
|
||
#[test] | ||
#[should_panic(expected = "items length 1 does not match batch size 300")] | ||
fn misaligned_success_panics() { | ||
let br = BatchReturn::ok(300); | ||
br.successes(&["first"]); | ||
} |