diff --git a/crates/cheatcodes/src/test/assert.rs b/crates/cheatcodes/src/test/assert.rs index d727626ca48c..3c1ab22f3c85 100644 --- a/crates/cheatcodes/src/test/assert.rs +++ b/crates/cheatcodes/src/test/assert.rs @@ -1122,13 +1122,17 @@ fn uint_assert_approx_eq_rel( right: U256, max_delta: U256, ) -> Result, EqRelAssertionError> { - if right.is_zero() && !left.is_zero() { - return Err(EqRelAssertionError::Failure(Box::new(EqRelAssertionFailure { - left, - right, - max_delta, - real_delta: EqRelDelta::Undefined, - }))) + if right.is_zero() { + if left.is_zero() { + return Ok(Default::default()) + } else { + return Err(EqRelAssertionError::Failure(Box::new(EqRelAssertionFailure { + left, + right, + max_delta, + real_delta: EqRelDelta::Undefined, + }))) + }; } let delta = get_delta_uint(left, right) @@ -1153,13 +1157,17 @@ fn int_assert_approx_eq_rel( right: I256, max_delta: U256, ) -> Result, EqRelAssertionError> { - if right.is_zero() && !left.is_zero() { - return Err(EqRelAssertionError::Failure(Box::new(EqRelAssertionFailure { - left, - right, - max_delta, - real_delta: EqRelDelta::Undefined, - }))) + if right.is_zero() { + if left.is_zero() { + return Ok(Default::default()) + } else { + return Err(EqRelAssertionError::Failure(Box::new(EqRelAssertionFailure { + left, + right, + max_delta, + real_delta: EqRelDelta::Undefined, + }))) + } } let (_, abs_right) = right.into_sign_and_abs(); diff --git a/testdata/default/cheats/Assert.t.sol b/testdata/default/cheats/Assert.t.sol index d2b0dcb3589a..b33af6292ce3 100644 --- a/testdata/default/cheats/Assert.t.sol +++ b/testdata/default/cheats/Assert.t.sol @@ -823,5 +823,7 @@ contract AssertionsTest is DSTest { bytes("assertion failed: 1 !~= 0 (max delta: 0.0000000000000000%, real delta: undefined)") ); vm.assertApproxEqRel(uint256(1), uint256(0), uint256(0)); + + vm.assertApproxEqRel(uint256(0), uint256(0), uint256(0)); } }