ink icon indicating copy to clipboard operation
ink copied to clipboard

Add ensure! macro to ink! and replace manual error checks in integration test contracts

Open CECILIA-MULANDI opened this issue 4 months ago • 0 comments

Summary

Closes #2747

  • [ ] n | Does it introduce breaking changes? No - This is a purely additive feature
  • [ ] n | Is it dependent on a specific version of cargo-contract or pallet-revive? No - It's a standard Rust macro

Implements the ensure! macro similar to frame_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

  • Added ensure! macro in crates/ink/src/ensure.rs with comprehensive documentation and unit tests
  • Exported the macro from crates/ink/src/lib.rs
  • Applied ensure! 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 with use ink::ensure;)
    • integration-tests/public/fallible-setter/lib.rs (3 places)
  • Added integration-tests/public/ensure-test/ as a dedicated test contract to verify the macro functionality

The macro follows the same pattern as frame_support::ensure! and is no_std compatible.

Checklist before requesting a review

  • [x] I have added an entry to CHANGELOG.md

  • [x] I have commented on my code, particularly in hard-to-understand areas

  • [x] 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

CECILIA-MULANDI avatar Dec 12 '25 22:12 CECILIA-MULANDI