Add ensure! macro to ink! and replace manual error checks in integration test contracts #2753
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