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

Add exhaustive tests for fvm sdk api #1681

Merged
merged 12 commits into from
Mar 10, 2023
Merged

Add exhaustive tests for fvm sdk api #1681

merged 12 commits into from
Mar 10, 2023

Conversation

fridrik01
Copy link
Contributor

@fridrik01 fridrik01 commented Feb 23, 2023

This PR adds multiple tests for our fvm sdk api to confirm they behave according to fvm sdk docs.

Fixes: #585

Note that there are still tests to be written for actor::next_actor_address and crypto::verify_consensus_fault.

@fridrik01 fridrik01 force-pushed the fvmsdk-syscall-testing branch 3 times, most recently from feb3e46 to 177776d Compare February 23, 2023 19:01
Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is exactly what I'm looking for.

assert_eq!(res, Err(ErrorNumber::IllegalArgument));

// Test for invalid Cid pointer
let res = sdk::sys::ipld::block_open("invalid ptr".as_ptr());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still a valid pointer (i.e., valid memory). I'd cast a large integer to a pointer.

(also, now that you've checked this, I wouldn't bother checking for "out of bounds" pointers on every syscall as that could get tedious and we use the same code-paths)

let res = sdk::sys::ipld::block_open("invalid ptr".as_ptr());
assert_eq!(res, Err(ErrorNumber::IllegalArgument));

// TODO (fridrik): Test for very large cid
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this'll be a bit annoying as you'll have to manually construct it. Also not something that's super critical to test.

sdk::sys::ipld::block_create(DAG_CBOR, test_bytes.as_ptr(), test_bytes.len() as u32);
assert_eq!(res, Err(ErrorNumber::LimitExceeded));

// TODO (fridrik): Test for TooManyBlock error requires INT32_MAX blocks
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't bother with this one, honestly. Given the current gas model, there's no way to hit this limit at the moment.

@fridrik01 fridrik01 force-pushed the fvmsdk-syscall-testing branch 2 times, most recently from f84aaba to d76fff3 Compare February 24, 2023 10:00
@codecov-commenter
Copy link

codecov-commenter commented Mar 2, 2023

Codecov Report

Merging #1681 (f9a2087) into master (251db77) will not change coverage.
The diff coverage is 0.00%.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1681   +/-   ##
=======================================
  Coverage   55.44%   55.44%           
=======================================
  Files         146      146           
  Lines       14031    14031           
=======================================
  Hits         7779     7779           
  Misses       6252     6252           
Impacted Files Coverage Δ
sdk/src/error.rs 0.00% <0.00%> (ø)
sdk/src/sself.rs 0.00% <ø> (ø)
shared/src/sys/mod.rs 0.00% <0.00%> (ø)
shared/src/sys/out.rs 0.00% <0.00%> (ø)

@fridrik01 fridrik01 force-pushed the fvmsdk-syscall-testing branch from 3484ca1 to 7955d21 Compare March 2, 2023 16:50
@fridrik01 fridrik01 changed the title [WIP] Add exhaustive tests for verifying fvm sdk behaves according to specs Add exhaustive tests for fvm sdk api Mar 7, 2023
@fridrik01 fridrik01 requested review from maciejwitowski and vyzo March 7, 2023 15:07
@fridrik01 fridrik01 marked this pull request as ready for review March 7, 2023 15:07
Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

Comment on lines 10 to 15
std::panic::set_hook(Box::new(|info| {
sdk::vm::abort(
ExitCode::USR_ASSERTION_FAILED.value(),
Some(&format!("{}", info)),
)
}));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I recommend just calling sdk::initialize().

panic!("non-zero exit code {}", res.msg_receipt.exit_code)
}
}

assert_eq!(res.msg_receipt.exit_code, ExitCode::OK);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now redundant.

@Stebalien
Copy link
Member

Feel free to merge when ready.

…FVM and SDK

This allows us to more easily assert on certain error conditions:

Example (this failed before):

   let res = sdk::sys::ipld::block_open(buf.as_mut_ptr());
   assert_eq!(res, Err(ErrorNumber::IllegalArgument));
This commit refactors the fil-create-actor actor, main differences are:
- If test failed with user asserts, they are now printed in the test output (before they were ignored)
- Tests now verify result for specific error numbers
- Added more tests for resolve_address and get_actor_code_cid
When deleting an actor with 0 balance, then this sself::self_destruct
will always return Ok() regardless of whether the actor has already
been deleted, or the beneficiary address does not exist or is itself
@fridrik01 fridrik01 force-pushed the fvmsdk-syscall-testing branch from c3c1e6b to cb0fa3b Compare March 10, 2023 09:37
@Stebalien Stebalien merged commit d9fd645 into master Mar 10, 2023
@Stebalien Stebalien deleted the fvmsdk-syscall-testing branch March 10, 2023 20:12
@Stebalien
Copy link
Member

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Syscall Testing Epic
3 participants