From 832d59af815c2bbeb12125bc440a7cea3c39371f Mon Sep 17 00:00:00 2001 From: Omar Inuwa Date: Wed, 26 Nov 2025 18:04:14 +0100 Subject: [PATCH] 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. --- contracts/util/PropertiesAsserts.sol | 57 ++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/contracts/util/PropertiesAsserts.sol b/contracts/util/PropertiesAsserts.sol index d753d54..d4e026e 100644 --- a/contracts/util/PropertiesAsserts.sol +++ b/contracts/util/PropertiesAsserts.sol @@ -439,6 +439,63 @@ abstract contract PropertiesAsserts { } return a; } + + /* ================================================================ + FORGE-STD COMPATIBLE ASSERTION ALIASES + + The following functions provide compatibility with forge-std/Test.sol + naming conventions, enabling seamless integration with existing Foundry + codebases. These are aliases that delegate to the existing assertion + implementations above. + ================================================================ */ + + /// @notice Forge-std compatible alias for assertWithMsg + /// @dev Asserts that condition is true. Reverts with reason if false. + function assertTrue(bool condition, string memory reason) internal { + assertWithMsg(condition, reason); + } + + /// @notice Forge-std compatible assertion for false conditions + /// @dev Asserts that condition is false. Reverts with reason if true. + function assertFalse(bool condition, string memory reason) internal { + assertWithMsg(!condition, reason); + } + + /// @notice Forge-std compatible alias for assertNeq (uint256) + /// @dev Asserts that a is not equal to b. Violations are logged using reason. + function assertNotEq(uint256 a, uint256 b, string memory reason) internal { + assertNeq(a, b, reason); + } + + /// @notice Forge-std compatible alias for assertNeq (int256) + /// @dev Asserts that a is not equal to b. Violations are logged using reason. + function assertNotEq(int256 a, int256 b, string memory reason) internal { + assertNeq(a, b, reason); + } + + /// @notice Forge-std compatible alias for assertGte (uint256) + /// @dev Asserts that a is greater than or equal to b. Violations are logged using reason. + function assertGe(uint256 a, uint256 b, string memory reason) internal { + assertGte(a, b, reason); + } + + /// @notice Forge-std compatible alias for assertGte (int256) + /// @dev Asserts that a is greater than or equal to b. Violations are logged using reason. + function assertGe(int256 a, int256 b, string memory reason) internal { + assertGte(a, b, reason); + } + + /// @notice Forge-std compatible alias for assertLte (uint256) + /// @dev Asserts that a is less than or equal to b. Violations are logged using reason. + function assertLe(uint256 a, uint256 b, string memory reason) internal { + assertLte(a, b, reason); + } + + /// @notice Forge-std compatible alias for assertLte (int256) + /// @dev Asserts that a is less than or equal to b. Violations are logged using reason. + function assertLe(int256 a, int256 b, string memory reason) internal { + assertLte(a, b, reason); + } } /// @notice Efficient library for creating string representations of integers.