Skip to content

Conversation

@CECILIA-MULANDI
Copy link
Contributor

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

  • I have added an entry to CHANGELOG.md

  • I 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

assert!(contract.deposit(U256::from(50)).is_ok());
}
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thank you for the PR! Can you add some E2E tests here? They should check for the error codes/messages as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi, i've added them.

@CECILIA-MULANDI CECILIA-MULANDI force-pushed the cecilia-implement-ensure-macro branch from 7f311f3 to 2b04709 Compare December 14, 2025 14: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.

Implement ensure! of frame support in ink!

2 participants