Add assert_approx_eq! macro with configurable tolerance#672
Open
wheval wants to merge 1 commit into
Open
Conversation
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.
|
@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! 🚀 |
1 task
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
assert_approx_eq!to the assertion-macros module (contracts/crucible/src/macros.rs), alongside the existingassert_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, ...).crucibleentirely: an unterminated string literal inAccountBuilder::build()(account.rs), and aDisplay-vs-Debugformatting bug inassert_emitted!(soroban_sdk::Addressdoesn't implementDisplay).Closes #631
Test plan
cargo test -p crucible— all macro tests pass, including 3 new tests forassert_approx_eq!(within tolerance, outside tolerance panics, custom message included in panic)