Add ensure! macro to ink! and replace manual error checks in integration test contracts#2753
Open
CECILIA-MULANDI wants to merge 5 commits intouse-ink:masterfrom
Open
Conversation
cmichi
reviewed
Dec 13, 2025
| assert!(contract.deposit(U256::from(50)).is_ok()); | ||
| } | ||
| } | ||
| } |
Collaborator
There was a problem hiding this comment.
Thank you for the PR! Can you add some E2E tests here? They should check for the error codes/messages as well.
Contributor
Author
There was a problem hiding this comment.
Hi, i've added them.
7f311f3 to
2b04709
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #2747
cargo-contractorpallet-revive? No - It's a standard Rust macroImplements the
ensure!macro similar toframe_support::ensure!and applies it to all integration test contracts. This provides a convenient way to check conditions and return errors in ink! contracts.Description
ensure!macro incrates/ink/src/ensure.rswith comprehensive documentation and unit testscrates/ink/src/lib.rsensure!to replace manual error checks in the following integration test contracts:integration-tests/public/erc20/lib.rs(2 places)integration-tests/public/payment-channel/lib.rs(8 places)integration-tests/public/trait-erc20/lib.rs(2 places)integration-tests/public/erc1155/lib.rs(replaced local macro withuse ink::ensure;)integration-tests/public/fallible-setter/lib.rs(3 places)integration-tests/public/ensure-test/as a dedicated test contract to verify the macro functionalityThe macro follows the same pattern as
frame_support::ensure!and isno_stdcompatible.Checklist before requesting a review
I have added an entry to
CHANGELOG.mdI have commented on my code, particularly in hard-to-understand areas
I have added tests that prove my fix is effective or that my feature works
Any dependent changes have been merged and published in downstream modules