Skip to content

Add assert_approx_eq! macro with configurable tolerance#672

Open
wheval wants to merge 1 commit into
benelabs:mainfrom
wheval:fix/issue-631-assert-approx-eq
Open

Add assert_approx_eq! macro with configurable tolerance#672
wheval wants to merge 1 commit into
benelabs:mainfrom
wheval:fix/issue-631-assert-approx-eq

Conversation

@wheval

@wheval wheval commented Jul 5, 2026

Copy link
Copy Markdown

Summary

  • Adds assert_approx_eq! to the assertion-macros module (contracts/crucible/src/macros.rs), alongside the existing assert_reverts!/assert_emitted!/assert_not_emitted!. Supports a 3-arg form (left, right, tolerance) and a 4-arg form with a custom failure message, and works with any numeric type supporting subtraction/ordering/Debug (i128, u128, i64, u64, ...).
  • While getting the crate to build to test this, found and fixed two pre-existing compile errors that were blocking crucible entirely: an unterminated string literal in AccountBuilder::build() (account.rs), and a Display-vs-Debug formatting bug in assert_emitted! (soroban_sdk::Address doesn't implement Display).

Closes #631

Test plan

  • cargo test -p crucible — all macro tests pass, including 3 new tests for assert_approx_eq! (within tolerance, outside tolerance panics, custom message included in panic)

Adds an assert_approx_eq! assertion macro to the crucible testing
toolkit for comparing numeric values (e.g. i128 amounts) within a
tolerance, with an optional custom context message on failure.

Also fixes an unterminated string literal in AccountBuilder::build()
and a Display/Debug formatting bug in assert_emitted! (Address does
not implement Display) - both were pre-existing compile errors that
blocked the crucible crate from building at all.
@drips-wave

drips-wave Bot commented Jul 5, 2026

Copy link
Copy Markdown

@wheval Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

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.

Add assert_approx_eq! macro with configurable tolerance

1 participant