Skip to content

Commit

Permalink
Support expected_failure with parameters (MystenLabs#23)
Browse files Browse the repository at this point in the history
* 041924-expected_failure-with-params: ini

* 041924-expected_failure-with-params: clean-up
  • Loading branch information
jcivlin authored Apr 24, 2024
1 parent f923b0b commit 0d32838
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
10 changes: 7 additions & 3 deletions external-crates/move/crates/move-stdlib/tests/vector_tests.move
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ module std::vector_tests {
struct Droppable has drop {}
struct NotDroppable {}

// defined in vm_status.rs
const MEMORY_LIMIT_EXCEEDED: u64 = 4028;
const UNKNOWN_STATUS: u64 = 18446744073709551615;

#[test]
fun test_singleton_contains() {
assert!(*V::borrow(&V::singleton(0), 0) == 0, 0);
Expand Down Expand Up @@ -566,12 +570,12 @@ module std::vector_tests {
}

#[test]
#[expected_failure]
#[expected_failure(major_status = MEMORY_LIMIT_EXCEEDED, minor_status = UNKNOWN_STATUS, location=Self)]
fun size_limit_fail() {
let v = V::empty();
let i = 0;
// Limit is currently 1024 * 1024
let max_len = 1024 * 1024 + 1;
// Solana default limit is 1024 * 2
let max_len = 1024 * 2 + 1;

while (i < max_len) {
V::push_back(&mut v, i);
Expand Down
23 changes: 23 additions & 0 deletions external-crates/move/crates/move-unit-test/src/test_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,29 @@ impl SharedTestingConfig {
output.pass(function_name);
stats.test_success(test_run_info(), test_plan);
}
// Support expected failures with known error codes
(Some(ExpectedFailure::ExpectedWithError(error)), move_to_solana::runner::ExitReason::Failure) => {
// Processing
// #[expected_failure(major_status = MEMORY_LIMIT_EXCEEDED, minor_status = UNKNOWN_STATUS, location=Self)]
if error.0 == StatusCode::MEMORY_LIMIT_EXCEEDED {
if let (Some(minor_status), return_value) = (error.1, result.return_value) {
if minor_status == return_value {
output.pass(function_name);
stats.test_success(test_run_info(), test_plan);
}
}
} else {
output.fail(function_name);
stats.test_failure(
TestFailure::new(
FailureReason::solana_vm_error(result.log),
test_run_info(),
None,
),
test_plan,
)
}
}
// Support tests with naked expected_failure, for example size_limit_fail in vector_tests.move
(Some(
ExpectedFailure::Expected), move_to_solana::runner::ExitReason::Failure) => {
Expand Down

0 comments on commit 0d32838

Please sign in to comment.