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

BatchReturn tests #753

Merged
merged 3 commits into from
Oct 14, 2022
Merged
Changes from 2 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
81 changes: 81 additions & 0 deletions runtime/tests/batch_return_test.rs
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"]);
}