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 comprehensive tests to adapter_tests #260

Merged
merged 1 commit into from
Jan 25, 2022
Merged

Add comprehensive tests to adapter_tests #260

merged 1 commit into from
Jan 25, 2022

Conversation

lxfind
Copy link
Contributor

@lxfind lxfind commented Jan 24, 2022

This PR adds more tests to adapter_tests.
In doing so, also found a few issues and fixed them:

  1. In adapter::publish, we were returning Err for some user errors. We should return ExecutionStatus::Failure instead.
  2. In adapter_tests, we were passing MAX_GAS as budget. This is problematic as it equals the the balance of the object, and can fail on the second use (once we add the same check from handle_order to confirm_order).
  3. A few nits on error messages.

Comment on lines +203 to +206
let package_id = match generate_package_id(&mut modules, ctx) {
Ok(ok) => ok,
Err(err) => exec_failure!(gas::MIN_MOVE_PUBLISH_GAS, err),
};
Copy link
Contributor

Choose a reason for hiding this comment

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

So, if you change the exec_failure! macro to not return something but instead just construct the result, this can become:

let package_id = match generate_package_id(&mut modules, ctx).unwrap_or_else(|e| exec_failure!(..., e))?;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not really, note that exec_failure! actually returns Ok instead of Err.

Copy link
Contributor

@huitseeker huitseeker Jan 25, 2022

Choose a reason for hiding this comment

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

Fair enough.

let package_id = generate_package_id(&mut modules, ctx).or_else(|e| exec_failure!(..., e))?;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's not going to work either. What I want here is when a user error occurred, the entire function still returns an Ok, but inside that Ok there is an ExecutionStatus::Failure. So any mechanism that chains into ? will not work.
Also exec_failure! needs to be in the outer function scope, not in lambda scope, otherwise it just returns from within the lambda instead of returns the outer function.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, understood, finally. You're right, there's nothing relevant to do from within the lambda scope.

Comment on lines +415 to 417
.unwrap()
.unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm thinking we may want to provide a convenience method (perhaps an impl TryFrom?) to unpack results wrapping execution statuses.

@lxfind lxfind merged commit 95ed19d into MystenLabs:main Jan 25, 2022
@lxfind lxfind deleted the add-adapter-tests branch January 25, 2022 21:48
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.

2 participants