Skip to content

Commit 4af52ed

Browse files
Omar InuwaOmar Inuwa
authored andcommitted
Add forge-std compatible assertion aliases for easier integration
This PR adds assertion function aliases that match forge-std/Test.sol naming conventions, resolving naming conflicts and enabling seamless integration with existing Foundry codebases. Problem: When integrating crytic/properties with existing Foundry projects, many assertion helpers collided with forge-std/Test.sol, making it difficult to use both libraries together. Specific conflicts: - assertWithMsg (crytic) vs assertTrue (forge-std) - assertGte (crytic) vs assertGe (forge-std) - assertLte (crytic) vs assertLe (forge-std) - assertNeq (crytic) vs assertNotEq (forge-std) Solution: Added 8 new assertion function aliases in PropertiesHelper.sol that delegate to existing implementations: - assertTrue() - alias for assertWithMsg() - assertFalse() - new function for asserting false conditions - assertNotEq() - alias for assertNeq() (uint256 and int256) - assertGe() - alias for assertGte() (uint256 and int256) - assertLe() - alias for assertLte() (uint256 and int256) Benefits: - Users can now inherit from both PropertiesAsserts and forge-std Test without naming conflicts - Both naming conventions work side-by-side - 100% backward compatible - existing code continues to work - No breaking changes to existing properties - Easier onboarding for Foundry developers Example usage: ```solidity contract MyTest is MyToken, CryticERC20BasicProperties, Test { function test_example() public { // Both styles work! assertTrue(balance > 0, "Has balance"); // forge-std style assertWithMsg(balance > 0, "Has balance"); // crytic style assertGe(balance, 100, "At least 100"); // forge-std style assertGte(balance, 100, "At least 100"); // crytic style } } ``` This change makes crytic/properties fully compatible with Foundry's standard testing patterns, lowering the barrier to adoption.
1 parent d346d8e commit 4af52ed

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

contracts/util/PropertiesHelper.sol

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,63 @@ abstract contract PropertiesAsserts {
439439
}
440440
return a;
441441
}
442+
443+
/* ================================================================
444+
FORGE-STD COMPATIBLE ASSERTION ALIASES
445+
446+
The following functions provide compatibility with forge-std/Test.sol
447+
naming conventions, enabling seamless integration with existing Foundry
448+
codebases. These are aliases that delegate to the existing assertion
449+
implementations above.
450+
================================================================ */
451+
452+
/// @notice Forge-std compatible alias for assertWithMsg
453+
/// @dev Asserts that condition is true. Reverts with reason if false.
454+
function assertTrue(bool condition, string memory reason) internal {
455+
assertWithMsg(condition, reason);
456+
}
457+
458+
/// @notice Forge-std compatible assertion for false conditions
459+
/// @dev Asserts that condition is false. Reverts with reason if true.
460+
function assertFalse(bool condition, string memory reason) internal {
461+
assertWithMsg(!condition, reason);
462+
}
463+
464+
/// @notice Forge-std compatible alias for assertNeq (uint256)
465+
/// @dev Asserts that a is not equal to b. Violations are logged using reason.
466+
function assertNotEq(uint256 a, uint256 b, string memory reason) internal {
467+
assertNeq(a, b, reason);
468+
}
469+
470+
/// @notice Forge-std compatible alias for assertNeq (int256)
471+
/// @dev Asserts that a is not equal to b. Violations are logged using reason.
472+
function assertNotEq(int256 a, int256 b, string memory reason) internal {
473+
assertNeq(a, b, reason);
474+
}
475+
476+
/// @notice Forge-std compatible alias for assertGte (uint256)
477+
/// @dev Asserts that a is greater than or equal to b. Violations are logged using reason.
478+
function assertGe(uint256 a, uint256 b, string memory reason) internal {
479+
assertGte(a, b, reason);
480+
}
481+
482+
/// @notice Forge-std compatible alias for assertGte (int256)
483+
/// @dev Asserts that a is greater than or equal to b. Violations are logged using reason.
484+
function assertGe(int256 a, int256 b, string memory reason) internal {
485+
assertGte(a, b, reason);
486+
}
487+
488+
/// @notice Forge-std compatible alias for assertLte (uint256)
489+
/// @dev Asserts that a is less than or equal to b. Violations are logged using reason.
490+
function assertLe(uint256 a, uint256 b, string memory reason) internal {
491+
assertLte(a, b, reason);
492+
}
493+
494+
/// @notice Forge-std compatible alias for assertLte (int256)
495+
/// @dev Asserts that a is less than or equal to b. Violations are logged using reason.
496+
function assertLe(int256 a, int256 b, string memory reason) internal {
497+
assertLte(a, b, reason);
498+
}
442499
}
443500

444501
/// @notice Efficient library for creating string representations of integers.

0 commit comments

Comments
 (0)