From 8d91a32531440a16a8b57a99abf5e88d0816497e Mon Sep 17 00:00:00 2001 From: Arsenii Kulikov Date: Mon, 15 Jan 2024 17:44:44 +0400 Subject: [PATCH 01/19] Add assertEq, assertNotEq, assertGt, assertGe, assertLt, assertLe cheatcodes --- crates/cheatcodes/assets/cheatcodes.json | 1480 ++++++++++++++++++++++ crates/cheatcodes/spec/src/vm.rs | 304 +++++ crates/cheatcodes/src/test.rs | 1 + crates/cheatcodes/src/test/assert.rs | 620 +++++++++ testdata/cheats/Vm.sol | 74 ++ 5 files changed, 2479 insertions(+) create mode 100644 crates/cheatcodes/src/test/assert.rs diff --git a/crates/cheatcodes/assets/cheatcodes.json b/crates/cheatcodes/assets/cheatcodes.json index 3225893d14c3..61c90aa3653c 100644 --- a/crates/cheatcodes/assets/cheatcodes.json +++ b/crates/cheatcodes/assets/cheatcodes.json @@ -553,6 +553,1486 @@ "status": "stable", "safety": "unsafe" }, + { + "func": { + "id": "assertEq_0", + "description": "Asserts that two `bool` values are equal.", + "declaration": "function assertEq(bool a, bool b) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertEq(bool,bool)", + "selector": "0xf7fe3477", + "selectorBytes": [ + 247, + 254, + 52, + 119 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertEq_1", + "description": "Asserts that two `bool` values are equal and includes error message into revert string on failure.", + "declaration": "function assertEq(bool a, bool b, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertEq(bool,bool,string)", + "selector": "0x4db19e7e", + "selectorBytes": [ + 77, + 177, + 158, + 126 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertEq_10", + "description": "Asserts that two `string` values are equal.", + "declaration": "function assertEq(string calldata a, string calldata b) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertEq(string,string)", + "selector": "0xf320d963", + "selectorBytes": [ + 243, + 32, + 217, + 99 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertEq_11", + "description": "Asserts that two `string` values are equal and includes error message into revert string on failure.", + "declaration": "function assertEq(string calldata a, string calldata b, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertEq(string,string,string)", + "selector": "0x36f656d8", + "selectorBytes": [ + 54, + 246, + 86, + 216 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertEq_12", + "description": "Asserts that two `bytes` values are equal.", + "declaration": "function assertEq(bytes calldata a, bytes calldata b) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertEq(bytes,bytes)", + "selector": "0x97624631", + "selectorBytes": [ + 151, + 98, + 70, + 49 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertEq_13", + "description": "Asserts that two `bytes` values are equal and includes error message into revert string on failure.", + "declaration": "function assertEq(bytes calldata a, bytes calldata b, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertEq(bytes,bytes,string)", + "selector": "0xe24fed00", + "selectorBytes": [ + 226, + 79, + 237, + 0 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertEq_14", + "description": "Asserts that two arrays of `bool` values are equal.", + "declaration": "function assertEq(bool[] calldata a, bool[] calldata b) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertEq(bool[],bool[])", + "selector": "0x707df785", + "selectorBytes": [ + 112, + 125, + 247, + 133 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertEq_15", + "description": "Asserts that two arrays of `bool` values are equal and includes error message into revert string on failure.", + "declaration": "function assertEq(bool[] calldata a, bool[] calldata b, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertEq(bool[],bool[],string)", + "selector": "0xe48a8f8d", + "selectorBytes": [ + 228, + 138, + 143, + 141 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertEq_16", + "description": "Asserts that two arrays of `uint256 values are equal.", + "declaration": "function assertEq(uint256[] calldata a, uint256[] calldata b) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertEq(uint256[],uint256[])", + "selector": "0x975d5a12", + "selectorBytes": [ + 151, + 93, + 90, + 18 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertEq_17", + "description": "Asserts that two arrays of `uint256` values are equal and includes error message into revert string on failure.", + "declaration": "function assertEq(uint256[] calldata a, uint256[] calldata b, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertEq(uint256[],uint256[],string)", + "selector": "0x5d18c73a", + "selectorBytes": [ + 93, + 24, + 199, + 58 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertEq_18", + "description": "Asserts that two arrays of `int256` values are equal.", + "declaration": "function assertEq(int256[] calldata a, int256[] calldata b) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertEq(int256[],int256[])", + "selector": "0x711043ac", + "selectorBytes": [ + 113, + 16, + 67, + 172 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertEq_19", + "description": "Asserts that two arrays of `int256` values are equal and includes error message into revert string on failure.", + "declaration": "function assertEq(int256[] calldata a, int256[] calldata b, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertEq(int256[],int256[],string)", + "selector": "0x191f1b30", + "selectorBytes": [ + 25, + 31, + 27, + 48 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertEq_2", + "description": "Asserts that two `uint256` values are equal.", + "declaration": "function assertEq(uint256 a, uint256 b) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertEq(uint256,uint256)", + "selector": "0x98296c54", + "selectorBytes": [ + 152, + 41, + 108, + 84 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertEq_20", + "description": "Asserts that two arrays of `address` values are equal.", + "declaration": "function assertEq(address[] calldata a, address[] calldata b) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertEq(address[],address[])", + "selector": "0x3868ac34", + "selectorBytes": [ + 56, + 104, + 172, + 52 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertEq_21", + "description": "Asserts that two arrays of `address` values are equal and includes error message into revert string on failure.", + "declaration": "function assertEq(address[] calldata a, address[] calldata b, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertEq(address[],address[],string)", + "selector": "0x3e9173c5", + "selectorBytes": [ + 62, + 145, + 115, + 197 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertEq_22", + "description": "Asserts that two arrays of `bytes32` values are equal.", + "declaration": "function assertEq(bytes32[] calldata a, bytes32[] calldata b) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertEq(bytes32[],bytes32[])", + "selector": "0x0cc9ee84", + "selectorBytes": [ + 12, + 201, + 238, + 132 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertEq_23", + "description": "Asserts that two arrays of `bytes32` values are equal and includes error message into revert string on failure.", + "declaration": "function assertEq(bytes32[] calldata a, bytes32[] calldata b, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertEq(bytes32[],bytes32[],string)", + "selector": "0xe03e9177", + "selectorBytes": [ + 224, + 62, + 145, + 119 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertEq_24", + "description": "Asserts that two arrays of `string` values are equal.", + "declaration": "function assertEq(string[] calldata a, string[] calldata b) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertEq(string[],string[])", + "selector": "0xcf1c049c", + "selectorBytes": [ + 207, + 28, + 4, + 156 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertEq_25", + "description": "Asserts that two arrays of `string` values are equal and includes error message into revert string on failure.", + "declaration": "function assertEq(string[] calldata a, string[] calldata b, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertEq(string[],string[],string)", + "selector": "0xeff6b27d", + "selectorBytes": [ + 239, + 246, + 178, + 125 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertEq_26", + "description": "Asserts that two arrays of `bytes` values are equal.", + "declaration": "function assertEq(bytes[] calldata a, bytes[] calldata b) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertEq(bytes[],bytes[])", + "selector": "0xe5fb9b4a", + "selectorBytes": [ + 229, + 251, + 155, + 74 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertEq_27", + "description": "Asserts that two arrays of `bytes` values are equal and includes error message into revert string on failure.", + "declaration": "function assertEq(bytes[] calldata a, bytes[] calldata b, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertEq(bytes[],bytes[],string)", + "selector": "0xf413f0b6", + "selectorBytes": [ + 244, + 19, + 240, + 182 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertEq_3", + "description": "Asserts that two `uint256` values are equal and includes error message into revert string on failure.", + "declaration": "function assertEq(uint256 a, uint256 b, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertEq(uint256,uint256,string)", + "selector": "0x88b44c85", + "selectorBytes": [ + 136, + 180, + 76, + 133 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertEq_4", + "description": "Asserts that two `int256` values are equal.", + "declaration": "function assertEq(int256 a, int256 b) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertEq(int256,int256)", + "selector": "0xfe74f05b", + "selectorBytes": [ + 254, + 116, + 240, + 91 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertEq_5", + "description": "Asserts that two `int256` values are equal and includes error message into revert string on failure.", + "declaration": "function assertEq(int256 a, int256 b, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertEq(int256,int256,string)", + "selector": "0x714a2f13", + "selectorBytes": [ + 113, + 74, + 47, + 19 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertEq_6", + "description": "Asserts that two `address` values are equal.", + "declaration": "function assertEq(address a, address b) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertEq(address,address)", + "selector": "0x515361f6", + "selectorBytes": [ + 81, + 83, + 97, + 246 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertEq_7", + "description": "Asserts that two `address` values are equal and includes error message into revert string on failure.", + "declaration": "function assertEq(address a, address b, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertEq(address,address,string)", + "selector": "0x2f2769d1", + "selectorBytes": [ + 47, + 39, + 105, + 209 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertEq_8", + "description": "Asserts that two `bytes32` values are equal.", + "declaration": "function assertEq(bytes32 a, bytes32 b) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertEq(bytes32,bytes32)", + "selector": "0x7c84c69b", + "selectorBytes": [ + 124, + 132, + 198, + 155 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertEq_9", + "description": "Asserts that two `bytes32` values are equal and includes error message into revert string on failure.", + "declaration": "function assertEq(bytes32 a, bytes32 b, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertEq(bytes32,bytes32,string)", + "selector": "0xc1fa1ed0", + "selectorBytes": [ + 193, + 250, + 30, + 208 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertGe_0", + "description": "Compares two `uint256` values. Expects first value to be greater than or equal to second.", + "declaration": "function assertGe(uint256 a, uint256 b) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertGe(uint256,uint256)", + "selector": "0xa8d4d1d9", + "selectorBytes": [ + 168, + 212, + 209, + 217 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertGe_1", + "description": "Compares two `uint256` values. Expects first value to be greater than or equal to second.\nIncludes error message into revert string on failure.", + "declaration": "function assertGe(uint256 a, uint256 b, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertGe(uint256,uint256,string)", + "selector": "0xe25242c0", + "selectorBytes": [ + 226, + 82, + 66, + 192 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertGe_2", + "description": "Compares two `int256` values. Expects first value to be greater than or equal to second.", + "declaration": "function assertGe(int256 a, int256 b) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertGe(int256,int256)", + "selector": "0x0a30b771", + "selectorBytes": [ + 10, + 48, + 183, + 113 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertGe_3", + "description": "Compares two `int256` values. Expects first value to be greater than or equal to second.\nIncludes error message into revert string on failure.", + "declaration": "function assertGe(int256 a, int256 b, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertGe(int256,int256,string)", + "selector": "0xa84328dd", + "selectorBytes": [ + 168, + 67, + 40, + 221 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertGt_0", + "description": "Compares two `uint256` values. Expects first value to be greater than second.", + "declaration": "function assertGt(uint256 a, uint256 b) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertGt(uint256,uint256)", + "selector": "0xdb07fcd2", + "selectorBytes": [ + 219, + 7, + 252, + 210 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertGt_1", + "description": "Compares two `uint256` values. Expects first value to be greater than second.\nIncludes error message into revert string on failure.", + "declaration": "function assertGt(uint256 a, uint256 b, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertGt(uint256,uint256,string)", + "selector": "0xd9a3c4d2", + "selectorBytes": [ + 217, + 163, + 196, + 210 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertGt_2", + "description": "Compares two `int256` values. Expects first value to be greater than second.", + "declaration": "function assertGt(int256 a, int256 b) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertGt(int256,int256)", + "selector": "0x5a362d45", + "selectorBytes": [ + 90, + 54, + 45, + 69 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertGt_3", + "description": "Compares two `int256` values. Expects first value to be greater than second.\nIncludes error message into revert string on failure.", + "declaration": "function assertGt(int256 a, int256 b, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertGt(int256,int256,string)", + "selector": "0xf8d33b9b", + "selectorBytes": [ + 248, + 211, + 59, + 155 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertLe_0", + "description": "Compares two `uint256` values. Expects first value to be less than or equal to second.", + "declaration": "function assertLe(uint256 a, uint256 b) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertLe(uint256,uint256)", + "selector": "0x8466f415", + "selectorBytes": [ + 132, + 102, + 244, + 21 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertLe_1", + "description": "Compares two `uint256` values. Expects first value to be less than or equal to second.\nIncludes error message into revert string on failure.", + "declaration": "function assertLe(uint256 a, uint256 b, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertLe(uint256,uint256,string)", + "selector": "0xd17d4b0d", + "selectorBytes": [ + 209, + 125, + 75, + 13 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertLe_2", + "description": "Compares two `int256` values. Expects first value to be less than or equal to second.", + "declaration": "function assertLe(int256 a, int256 b) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertLe(int256,int256)", + "selector": "0x95fd154e", + "selectorBytes": [ + 149, + 253, + 21, + 78 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertLe_3", + "description": "Compares two `int256` values. Expects first value to be less than or equal to second.\nIncludes error message into revert string on failure.", + "declaration": "function assertLe(int256 a, int256 b, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertLe(int256,int256,string)", + "selector": "0x4dfe692c", + "selectorBytes": [ + 77, + 254, + 105, + 44 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertLt_0", + "description": "Compares two `uint256` values. Expects first value to be less than second.", + "declaration": "function assertLt(uint256 a, uint256 b) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertLt(uint256,uint256)", + "selector": "0xb12fc005", + "selectorBytes": [ + 177, + 47, + 192, + 5 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertLt_1", + "description": "Compares two `uint256` values. Expects first value to be less than second.\nIncludes error message into revert string on failure.", + "declaration": "function assertLt(uint256 a, uint256 b, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertLt(uint256,uint256,string)", + "selector": "0x65d5c135", + "selectorBytes": [ + 101, + 213, + 193, + 53 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertLt_2", + "description": "Compares two `int256` values. Expects first value to be less than second.", + "declaration": "function assertLt(int256 a, int256 b) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertLt(int256,int256)", + "selector": "0x3e914080", + "selectorBytes": [ + 62, + 145, + 64, + 128 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertLt_3", + "description": "Compares two `int256` values. Expects first value to be less than second.\nIncludes error message into revert string on failure.", + "declaration": "function assertLt(int256 a, int256 b, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertLt(int256,int256,string)", + "selector": "0x9ff531e3", + "selectorBytes": [ + 159, + 245, + 49, + 227 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertNotEq_0", + "description": "Asserts that two `bool` values are not equal.", + "declaration": "function assertNotEq(bool a, bool b) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertNotEq(bool,bool)", + "selector": "0x236e4d66", + "selectorBytes": [ + 35, + 110, + 77, + 102 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertNotEq_1", + "description": "Asserts that two `bool` values are not equal and includes error message into revert string on failure.", + "declaration": "function assertNotEq(bool a, bool b, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertNotEq(bool,bool,string)", + "selector": "0x1091a261", + "selectorBytes": [ + 16, + 145, + 162, + 97 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertNotEq_10", + "description": "Asserts that two `string` values are not equal.", + "declaration": "function assertNotEq(string calldata a, string calldata b) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertNotEq(string,string)", + "selector": "0x6a8237b3", + "selectorBytes": [ + 106, + 130, + 55, + 179 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertNotEq_11", + "description": "Asserts that two `string` values are not equal and includes error message into revert string on failure.", + "declaration": "function assertNotEq(string calldata a, string calldata b, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertNotEq(string,string,string)", + "selector": "0x78bdcea7", + "selectorBytes": [ + 120, + 189, + 206, + 167 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertNotEq_12", + "description": "Asserts that two `bytes` values are not equal.", + "declaration": "function assertNotEq(bytes calldata a, bytes calldata b) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertNotEq(bytes,bytes)", + "selector": "0x3cf78e28", + "selectorBytes": [ + 60, + 247, + 142, + 40 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertNotEq_13", + "description": "Asserts that two `bytes` values are not equal and includes error message into revert string on failure.", + "declaration": "function assertNotEq(bytes calldata a, bytes calldata b, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertNotEq(bytes,bytes,string)", + "selector": "0x9507540e", + "selectorBytes": [ + 149, + 7, + 84, + 14 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertNotEq_14", + "description": "Asserts that two arrays of `bool` values are not equal.", + "declaration": "function assertNotEq(bool[] calldata a, bool[] calldata b) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertNotEq(bool[],bool[])", + "selector": "0x286fafea", + "selectorBytes": [ + 40, + 111, + 175, + 234 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertNotEq_15", + "description": "Asserts that two arrays of `bool` values are not equal and includes error message into revert string on failure.", + "declaration": "function assertNotEq(bool[] calldata a, bool[] calldata b, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertNotEq(bool[],bool[],string)", + "selector": "0x62c6f9fb", + "selectorBytes": [ + 98, + 198, + 249, + 251 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertNotEq_16", + "description": "Asserts that two arrays of `uint256` values are not equal.", + "declaration": "function assertNotEq(uint256[] calldata a, uint256[] calldata b) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertNotEq(uint256[],uint256[])", + "selector": "0x56f29cba", + "selectorBytes": [ + 86, + 242, + 156, + 186 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertNotEq_17", + "description": "Asserts that two arrays of `uint256` values are not equal and includes error message into revert string on failure.", + "declaration": "function assertNotEq(uint256[] calldata a, uint256[] calldata b, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertNotEq(uint256[],uint256[],string)", + "selector": "0x9a7fbd8f", + "selectorBytes": [ + 154, + 127, + 189, + 143 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertNotEq_18", + "description": "Asserts that two arrays of `int256` values are not equal.", + "declaration": "function assertNotEq(int256[] calldata a, int256[] calldata b) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertNotEq(int256[],int256[])", + "selector": "0x0b72f4ef", + "selectorBytes": [ + 11, + 114, + 244, + 239 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertNotEq_19", + "description": "Asserts that two arrays of `int256` values are not equal and includes error message into revert string on failure.", + "declaration": "function assertNotEq(int256[] calldata a, int256[] calldata b, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertNotEq(int256[],int256[],string)", + "selector": "0xd3977322", + "selectorBytes": [ + 211, + 151, + 115, + 34 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertNotEq_2", + "description": "Asserts that two `uint256` values are not equal.", + "declaration": "function assertNotEq(uint256 a, uint256 b) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertNotEq(uint256,uint256)", + "selector": "0xb7909320", + "selectorBytes": [ + 183, + 144, + 147, + 32 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertNotEq_20", + "description": "Asserts that two arrays of `address` values are not equal.", + "declaration": "function assertNotEq(address[] calldata a, address[] calldata b) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertNotEq(address[],address[])", + "selector": "0x46d0b252", + "selectorBytes": [ + 70, + 208, + 178, + 82 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertNotEq_21", + "description": "Asserts that two arrays of `address` values are not equal and includes error message into revert string on failure.", + "declaration": "function assertNotEq(address[] calldata a, address[] calldata b, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertNotEq(address[],address[],string)", + "selector": "0x72c7e0b5", + "selectorBytes": [ + 114, + 199, + 224, + 181 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertNotEq_22", + "description": "Asserts that two arrays of `bytes32` values are not equal.", + "declaration": "function assertNotEq(bytes32[] calldata a, bytes32[] calldata b) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertNotEq(bytes32[],bytes32[])", + "selector": "0x0603ea68", + "selectorBytes": [ + 6, + 3, + 234, + 104 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertNotEq_23", + "description": "Asserts that two arrays of `bytes32` values are not equal and includes error message into revert string on failure.", + "declaration": "function assertNotEq(bytes32[] calldata a, bytes32[] calldata b, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertNotEq(bytes32[],bytes32[],string)", + "selector": "0xb873634c", + "selectorBytes": [ + 184, + 115, + 99, + 76 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertNotEq_24", + "description": "Asserts that two arrays of `string` values are not equal.", + "declaration": "function assertNotEq(string[] calldata a, string[] calldata b) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertNotEq(string[],string[])", + "selector": "0xbdfacbe8", + "selectorBytes": [ + 189, + 250, + 203, + 232 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertNotEq_25", + "description": "Asserts that two arrays of `string` values are not equal and includes error message into revert string on failure.", + "declaration": "function assertNotEq(string[] calldata a, string[] calldata b, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertNotEq(string[],string[],string)", + "selector": "0xb67187f3", + "selectorBytes": [ + 182, + 113, + 135, + 243 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertNotEq_26", + "description": "Asserts that two arrays of `bytes` values are not equal.", + "declaration": "function assertNotEq(bytes[] calldata a, bytes[] calldata b) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertNotEq(bytes[],bytes[])", + "selector": "0xedecd035", + "selectorBytes": [ + 237, + 236, + 208, + 53 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertNotEq_27", + "description": "Asserts that two arrays of `bytes` values are not equal and includes error message into revert string on failure.", + "declaration": "function assertNotEq(bytes[] calldata a, bytes[] calldata b, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertNotEq(bytes[],bytes[],string)", + "selector": "0x1dcd1f68", + "selectorBytes": [ + 29, + 205, + 31, + 104 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertNotEq_3", + "description": "Asserts that two `uint256` values are not equal and includes error message into revert string on failure.", + "declaration": "function assertNotEq(uint256 a, uint256 b, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertNotEq(uint256,uint256,string)", + "selector": "0x98f9bdbd", + "selectorBytes": [ + 152, + 249, + 189, + 189 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertNotEq_4", + "description": "Asserts that two `int256` values are not equal.", + "declaration": "function assertNotEq(int256 a, int256 b) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertNotEq(int256,int256)", + "selector": "0xf4c004e3", + "selectorBytes": [ + 244, + 192, + 4, + 227 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertNotEq_5", + "description": "Asserts that two `int256` values are not equal and includes error message into revert string on failure.", + "declaration": "function assertNotEq(int256 a, int256 b, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertNotEq(int256,int256,string)", + "selector": "0x4724c5b9", + "selectorBytes": [ + 71, + 36, + 197, + 185 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertNotEq_6", + "description": "Asserts that two `address` values are not equal.", + "declaration": "function assertNotEq(address a, address b) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertNotEq(address,address)", + "selector": "0xb12e1694", + "selectorBytes": [ + 177, + 46, + 22, + 148 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertNotEq_7", + "description": "Asserts that two `address` values are not equal and includes error message into revert string on failure.", + "declaration": "function assertNotEq(address a, address b, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertNotEq(address,address,string)", + "selector": "0x8775a591", + "selectorBytes": [ + 135, + 117, + 165, + 145 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertNotEq_8", + "description": "Asserts that two `bytes32` values are not equal.", + "declaration": "function assertNotEq(bytes32 a, bytes32 b) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertNotEq(bytes32,bytes32)", + "selector": "0x898e83fc", + "selectorBytes": [ + 137, + 142, + 131, + 252 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertNotEq_9", + "description": "Asserts that two `bytes32` values are not equal and includes error message into revert string on failure.", + "declaration": "function assertNotEq(bytes32 a, bytes32 b, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertNotEq(bytes32,bytes32,string)", + "selector": "0xb2332f51", + "selectorBytes": [ + 178, + 51, + 47, + 81 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertTrue_0", + "description": "Asserts that the given condition is true.", + "declaration": "function assertTrue(bool condition) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertTrue(bool)", + "selector": "0x0c9fd581", + "selectorBytes": [ + 12, + 159, + 213, + 129 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertTrue_1", + "description": "Asserts that the given condition is true and includes error message into revert string on failure.", + "declaration": "function assertTrue(bool condition, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertTrue(bool,string)", + "selector": "0xa34edc03", + "selectorBytes": [ + 163, + 78, + 220, + 3 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, { "func": { "id": "assume", diff --git a/crates/cheatcodes/spec/src/vm.rs b/crates/cheatcodes/spec/src/vm.rs index 8daca4ef31d2..62d134e4bf65 100644 --- a/crates/cheatcodes/spec/src/vm.rs +++ b/crates/cheatcodes/spec/src/vm.rs @@ -711,6 +711,310 @@ interface Vm { #[cheatcode(group = Testing, safety = Unsafe)] function skip(bool skipTest) external; + /// Asserts that the given condition is true. + #[cheatcode(group = Testing, safety = Safe)] + function assertTrue(bool condition) external pure; + + /// Asserts that the given condition is true and includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertTrue(bool condition, string calldata error) external pure; + + /// Asserts that two `bool` values are equal. + #[cheatcode(group = Testing, safety = Safe)] + function assertEq(bool a, bool b) external pure; + + /// Asserts that two `bool` values are equal and includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertEq(bool a, bool b, string calldata error) external pure; + + /// Asserts that two `uint256` values are equal. + #[cheatcode(group = Testing, safety = Safe)] + function assertEq(uint256 a, uint256 b) external pure; + + /// Asserts that two `uint256` values are equal and includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertEq(uint256 a, uint256 b, string calldata error) external pure; + + /// Asserts that two `int256` values are equal. + #[cheatcode(group = Testing, safety = Safe)] + function assertEq(int256 a, int256 b) external pure; + + /// Asserts that two `int256` values are equal and includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertEq(int256 a, int256 b, string calldata error) external pure; + + /// Asserts that two `address` values are equal. + #[cheatcode(group = Testing, safety = Safe)] + function assertEq(address a, address b) external pure; + + /// Asserts that two `address` values are equal and includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertEq(address a, address b, string calldata error) external pure; + + /// Asserts that two `bytes32` values are equal. + #[cheatcode(group = Testing, safety = Safe)] + function assertEq(bytes32 a, bytes32 b) external pure; + + /// Asserts that two `bytes32` values are equal and includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertEq(bytes32 a, bytes32 b, string calldata error) external pure; + + /// Asserts that two `string` values are equal. + #[cheatcode(group = Testing, safety = Safe)] + function assertEq(string calldata a, string calldata b) external pure; + + /// Asserts that two `string` values are equal and includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertEq(string calldata a, string calldata b, string calldata error) external pure; + + /// Asserts that two `bytes` values are equal. + #[cheatcode(group = Testing, safety = Safe)] + function assertEq(bytes calldata a, bytes calldata b) external pure; + + /// Asserts that two `bytes` values are equal and includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertEq(bytes calldata a, bytes calldata b, string calldata error) external pure; + + /// Asserts that two arrays of `bool` values are equal. + #[cheatcode(group = Testing, safety = Safe)] + function assertEq(bool[] calldata a, bool[] calldata b) external pure; + + /// Asserts that two arrays of `bool` values are equal and includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertEq(bool[] calldata a, bool[] calldata b, string calldata error) external pure; + + /// Asserts that two arrays of `uint256 values are equal. + #[cheatcode(group = Testing, safety = Safe)] + function assertEq(uint256[] calldata a, uint256[] calldata b) external pure; + + /// Asserts that two arrays of `uint256` values are equal and includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertEq(uint256[] calldata a, uint256[] calldata b, string calldata error) external pure; + + /// Asserts that two arrays of `int256` values are equal. + #[cheatcode(group = Testing, safety = Safe)] + function assertEq(int256[] calldata a, int256[] calldata b) external pure; + + /// Asserts that two arrays of `int256` values are equal and includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertEq(int256[] calldata a, int256[] calldata b, string calldata error) external pure; + + /// Asserts that two arrays of `address` values are equal. + #[cheatcode(group = Testing, safety = Safe)] + function assertEq(address[] calldata a, address[] calldata b) external pure; + + /// Asserts that two arrays of `address` values are equal and includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertEq(address[] calldata a, address[] calldata b, string calldata error) external pure; + + /// Asserts that two arrays of `bytes32` values are equal. + #[cheatcode(group = Testing, safety = Safe)] + function assertEq(bytes32[] calldata a, bytes32[] calldata b) external pure; + + /// Asserts that two arrays of `bytes32` values are equal and includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertEq(bytes32[] calldata a, bytes32[] calldata b, string calldata error) external pure; + + /// Asserts that two arrays of `string` values are equal. + #[cheatcode(group = Testing, safety = Safe)] + function assertEq(string[] calldata a, string[] calldata b) external pure; + + /// Asserts that two arrays of `string` values are equal and includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertEq(string[] calldata a, string[] calldata b, string calldata error) external pure; + + /// Asserts that two arrays of `bytes` values are equal. + #[cheatcode(group = Testing, safety = Safe)] + function assertEq(bytes[] calldata a, bytes[] calldata b) external pure; + + /// Asserts that two arrays of `bytes` values are equal and includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertEq(bytes[] calldata a, bytes[] calldata b, string calldata error) external pure; + + /// Asserts that two `bool` values are not equal. + #[cheatcode(group = Testing, safety = Safe)] + function assertNotEq(bool a, bool b) external pure; + + /// Asserts that two `bool` values are not equal and includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertNotEq(bool a, bool b, string calldata error) external pure; + + /// Asserts that two `uint256` values are not equal. + #[cheatcode(group = Testing, safety = Safe)] + function assertNotEq(uint256 a, uint256 b) external pure; + + /// Asserts that two `uint256` values are not equal and includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertNotEq(uint256 a, uint256 b, string calldata error) external pure; + + /// Asserts that two `int256` values are not equal. + #[cheatcode(group = Testing, safety = Safe)] + function assertNotEq(int256 a, int256 b) external pure; + + /// Asserts that two `int256` values are not equal and includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertNotEq(int256 a, int256 b, string calldata error) external pure; + + /// Asserts that two `address` values are not equal. + #[cheatcode(group = Testing, safety = Safe)] + function assertNotEq(address a, address b) external pure; + + /// Asserts that two `address` values are not equal and includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertNotEq(address a, address b, string calldata error) external pure; + + /// Asserts that two `bytes32` values are not equal. + #[cheatcode(group = Testing, safety = Safe)] + function assertNotEq(bytes32 a, bytes32 b) external pure; + + /// Asserts that two `bytes32` values are not equal and includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertNotEq(bytes32 a, bytes32 b, string calldata error) external pure; + + /// Asserts that two `string` values are not equal. + #[cheatcode(group = Testing, safety = Safe)] + function assertNotEq(string calldata a, string calldata b) external pure; + + /// Asserts that two `string` values are not equal and includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertNotEq(string calldata a, string calldata b, string calldata error) external pure; + + /// Asserts that two `bytes` values are not equal. + #[cheatcode(group = Testing, safety = Safe)] + function assertNotEq(bytes calldata a, bytes calldata b) external pure; + + /// Asserts that two `bytes` values are not equal and includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertNotEq(bytes calldata a, bytes calldata b, string calldata error) external pure; + + /// Asserts that two arrays of `bool` values are not equal. + #[cheatcode(group = Testing, safety = Safe)] + function assertNotEq(bool[] calldata a, bool[] calldata b) external pure; + + /// Asserts that two arrays of `bool` values are not equal and includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertNotEq(bool[] calldata a, bool[] calldata b, string calldata error) external pure; + + /// Asserts that two arrays of `uint256` values are not equal. + #[cheatcode(group = Testing, safety = Safe)] + function assertNotEq(uint256[] calldata a, uint256[] calldata b) external pure; + + /// Asserts that two arrays of `uint256` values are not equal and includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertNotEq(uint256[] calldata a, uint256[] calldata b, string calldata error) external pure; + + /// Asserts that two arrays of `int256` values are not equal. + #[cheatcode(group = Testing, safety = Safe)] + function assertNotEq(int256[] calldata a, int256[] calldata b) external pure; + + /// Asserts that two arrays of `int256` values are not equal and includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertNotEq(int256[] calldata a, int256[] calldata b, string calldata error) external pure; + + /// Asserts that two arrays of `address` values are not equal. + #[cheatcode(group = Testing, safety = Safe)] + function assertNotEq(address[] calldata a, address[] calldata b) external pure; + + /// Asserts that two arrays of `address` values are not equal and includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertNotEq(address[] calldata a, address[] calldata b, string calldata error) external pure; + + /// Asserts that two arrays of `bytes32` values are not equal. + #[cheatcode(group = Testing, safety = Safe)] + function assertNotEq(bytes32[] calldata a, bytes32[] calldata b) external pure; + + /// Asserts that two arrays of `bytes32` values are not equal and includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertNotEq(bytes32[] calldata a, bytes32[] calldata b, string calldata error) external pure; + + /// Asserts that two arrays of `string` values are not equal. + #[cheatcode(group = Testing, safety = Safe)] + function assertNotEq(string[] calldata a, string[] calldata b) external pure; + + /// Asserts that two arrays of `string` values are not equal and includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertNotEq(string[] calldata a, string[] calldata b, string calldata error) external pure; + + /// Asserts that two arrays of `bytes` values are not equal. + #[cheatcode(group = Testing, safety = Safe)] + function assertNotEq(bytes[] calldata a, bytes[] calldata b) external pure; + + /// Asserts that two arrays of `bytes` values are not equal and includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertNotEq(bytes[] calldata a, bytes[] calldata b, string calldata error) external pure; + + /// Compares two `uint256` values. Expects first value to be greater than second. + #[cheatcode(group = Testing, safety = Safe)] + function assertGt(uint256 a, uint256 b) external pure; + + /// Compares two `uint256` values. Expects first value to be greater than second. + /// Includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertGt(uint256 a, uint256 b, string calldata error) external pure; + + /// Compares two `int256` values. Expects first value to be greater than second. + #[cheatcode(group = Testing, safety = Safe)] + function assertGt(int256 a, int256 b) external pure; + + /// Compares two `int256` values. Expects first value to be greater than second. + /// Includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertGt(int256 a, int256 b, string calldata error) external pure; + + /// Compares two `uint256` values. Expects first value to be greater than or equal to second. + #[cheatcode(group = Testing, safety = Safe)] + function assertGe(uint256 a, uint256 b) external pure; + + /// Compares two `uint256` values. Expects first value to be greater than or equal to second. + /// Includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertGe(uint256 a, uint256 b, string calldata error) external pure; + + /// Compares two `int256` values. Expects first value to be greater than or equal to second. + #[cheatcode(group = Testing, safety = Safe)] + function assertGe(int256 a, int256 b) external pure; + + /// Compares two `int256` values. Expects first value to be greater than or equal to second. + /// Includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertGe(int256 a, int256 b, string calldata error) external pure; + + /// Compares two `uint256` values. Expects first value to be less than second. + #[cheatcode(group = Testing, safety = Safe)] + function assertLt(uint256 a, uint256 b) external pure; + + /// Compares two `uint256` values. Expects first value to be less than second. + /// Includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertLt(uint256 a, uint256 b, string calldata error) external pure; + + /// Compares two `int256` values. Expects first value to be less than second. + #[cheatcode(group = Testing, safety = Safe)] + function assertLt(int256 a, int256 b) external pure; + + /// Compares two `int256` values. Expects first value to be less than second. + /// Includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertLt(int256 a, int256 b, string calldata error) external pure; + + /// Compares two `uint256` values. Expects first value to be less than or equal to second. + #[cheatcode(group = Testing, safety = Safe)] + function assertLe(uint256 a, uint256 b) external pure; + + /// Compares two `uint256` values. Expects first value to be less than or equal to second. + /// Includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertLe(uint256 a, uint256 b, string calldata error) external pure; + + /// Compares two `int256` values. Expects first value to be less than or equal to second. + #[cheatcode(group = Testing, safety = Safe)] + function assertLe(int256 a, int256 b) external pure; + + /// Compares two `int256` values. Expects first value to be less than or equal to second. + /// Includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertLe(int256 a, int256 b, string calldata error) external pure; + // ======== OS and Filesystem ======== // -------- Metadata -------- diff --git a/crates/cheatcodes/src/test.rs b/crates/cheatcodes/src/test.rs index 740d4687e181..0d557db22329 100644 --- a/crates/cheatcodes/src/test.rs +++ b/crates/cheatcodes/src/test.rs @@ -5,6 +5,7 @@ use alloy_primitives::Address; use alloy_sol_types::SolValue; use foundry_evm_core::constants::{MAGIC_ASSUME, MAGIC_SKIP}; +pub(crate) mod assert; pub(crate) mod expect; impl Cheatcode for assumeCall { diff --git a/crates/cheatcodes/src/test/assert.rs b/crates/cheatcodes/src/test/assert.rs new file mode 100644 index 000000000000..54d2a9c6fe6c --- /dev/null +++ b/crates/cheatcodes/src/test/assert.rs @@ -0,0 +1,620 @@ +use std::fmt::Display; + +use itertools::Itertools; + +use crate::{Cheatcode, Cheatcodes, Result, Vm::*}; + +impl Cheatcode for assertTrue_0Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + assert_true(self.condition, None) + } +} + +impl Cheatcode for assertTrue_1Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + assert_true(self.condition, Some(&self.error)) + } +} + +impl Cheatcode for assertEq_0Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b } = self; + assert_eq(a, b, None) + } +} + +impl Cheatcode for assertEq_1Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b, error } = self; + assert_eq(a, b, Some(error)) + } +} + +impl Cheatcode for assertEq_2Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b } = self; + assert_eq(a, b, None) + } +} + +impl Cheatcode for assertEq_3Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b, error } = self; + assert_eq(a, b, Some(error)) + } +} + +impl Cheatcode for assertEq_4Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b } = self; + assert_eq(a, b, None) + } +} + +impl Cheatcode for assertEq_5Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b, error } = self; + assert_eq(a, b, Some(error)) + } +} + +impl Cheatcode for assertEq_6Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b } = self; + assert_eq(a, b, None) + } +} + +impl Cheatcode for assertEq_7Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b, error } = self; + assert_eq(a, b, Some(error)) + } +} + +impl Cheatcode for assertEq_8Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b } = self; + assert_eq(a, b, None) + } +} + +impl Cheatcode for assertEq_9Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b, error } = self; + assert_eq(a, b, Some(error)) + } +} + +impl Cheatcode for assertEq_10Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b } = self; + assert_eq(a, b, None) + } +} + +impl Cheatcode for assertEq_11Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b, error } = self; + assert_eq(a, b, Some(error)) + } +} + +impl Cheatcode for assertEq_12Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b } = self; + assert_eq(&hex::encode_prefixed(a), &hex::encode_prefixed(b), None) + } +} + +impl Cheatcode for assertEq_13Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b, error } = self; + assert_eq(&hex::encode_prefixed(a), &hex::encode_prefixed(b), Some(error)) + } +} + +impl Cheatcode for assertEq_14Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b } = self; + assert_eq_array(a, b, None) + } +} + +impl Cheatcode for assertEq_15Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b, error } = self; + assert_eq_array(a, b, Some(error)) + } +} + +impl Cheatcode for assertEq_16Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b } = self; + assert_eq_array(a, b, None) + } +} + +impl Cheatcode for assertEq_17Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b, error } = self; + assert_eq_array(a, b, Some(error)) + } +} + +impl Cheatcode for assertEq_18Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b } = self; + assert_eq_array(a, b, None) + } +} + +impl Cheatcode for assertEq_19Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b, error } = self; + assert_eq_array(a, b, Some(error)) + } +} + +impl Cheatcode for assertEq_20Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b } = self; + assert_eq_array(a, b, None) + } +} + +impl Cheatcode for assertEq_21Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b, error } = self; + assert_eq_array(a, b, Some(error)) + } +} + +impl Cheatcode for assertEq_22Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b } = self; + assert_eq_array(a, b, None) + } +} + +impl Cheatcode for assertEq_23Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b, error } = self; + assert_eq_array(a, b, Some(error)) + } +} + +impl Cheatcode for assertEq_24Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b } = self; + assert_eq_array(a, b, None) + } +} + +impl Cheatcode for assertEq_25Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b, error } = self; + assert_eq_array(a, b, Some(error)) + } +} + +impl Cheatcode for assertEq_26Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b } = self; + let a = a.iter().map(|x| hex::encode_prefixed(x)).collect::>(); + let b = b.iter().map(|x| hex::encode_prefixed(x)).collect::>(); + assert_eq_array(&a, &b, None) + } +} + +impl Cheatcode for assertEq_27Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b, error } = self; + let a = a.iter().map(|x| hex::encode_prefixed(x)).collect::>(); + let b = b.iter().map(|x| hex::encode_prefixed(x)).collect::>(); + assert_eq_array(&a, &b, Some(error)) + } +} + +impl Cheatcode for assertNotEq_0Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b } = self; + assert_not_eq(a, b, None) + } +} + +impl Cheatcode for assertNotEq_1Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b, error } = self; + assert_not_eq(a, b, Some(error)) + } +} + +impl Cheatcode for assertNotEq_2Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b } = self; + assert_not_eq(a, b, None) + } +} + +impl Cheatcode for assertNotEq_3Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b, error } = self; + assert_not_eq(a, b, Some(error)) + } +} + +impl Cheatcode for assertNotEq_4Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b } = self; + assert_not_eq(a, b, None) + } +} + +impl Cheatcode for assertNotEq_5Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b, error } = self; + assert_not_eq(a, b, Some(error)) + } +} + +impl Cheatcode for assertNotEq_6Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b } = self; + assert_not_eq(a, b, None) + } +} + +impl Cheatcode for assertNotEq_7Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b, error } = self; + assert_not_eq(a, b, Some(error)) + } +} + +impl Cheatcode for assertNotEq_8Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b } = self; + assert_not_eq(a, b, None) + } +} + +impl Cheatcode for assertNotEq_9Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b, error } = self; + assert_not_eq(a, b, Some(error)) + } +} + +impl Cheatcode for assertNotEq_10Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b } = self; + assert_not_eq(a, b, None) + } +} + +impl Cheatcode for assertNotEq_11Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b, error } = self; + assert_not_eq(a, b, Some(error)) + } +} + +impl Cheatcode for assertNotEq_12Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b } = self; + assert_not_eq(&hex::encode_prefixed(a), &hex::encode_prefixed(b), None) + } +} + +impl Cheatcode for assertNotEq_13Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b, error } = self; + assert_not_eq(&hex::encode_prefixed(a), &hex::encode_prefixed(b), Some(error)) + } +} + +impl Cheatcode for assertNotEq_14Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b } = self; + assert_not_eq_array(a, b, None) + } +} + +impl Cheatcode for assertNotEq_15Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b, error } = self; + assert_not_eq_array(a, b, Some(error)) + } +} + +impl Cheatcode for assertNotEq_16Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b } = self; + assert_not_eq_array(a, b, None) + } +} + +impl Cheatcode for assertNotEq_17Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b, error } = self; + assert_not_eq_array(a, b, Some(error)) + } +} + +impl Cheatcode for assertNotEq_18Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b } = self; + assert_not_eq_array(a, b, None) + } +} + +impl Cheatcode for assertNotEq_19Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b, error } = self; + assert_not_eq_array(a, b, Some(error)) + } +} + +impl Cheatcode for assertNotEq_20Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b } = self; + assert_not_eq_array(a, b, None) + } +} + +impl Cheatcode for assertNotEq_21Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b, error } = self; + assert_not_eq_array(a, b, Some(error)) + } +} + +impl Cheatcode for assertNotEq_22Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b } = self; + assert_not_eq_array(a, b, None) + } +} + +impl Cheatcode for assertNotEq_23Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b, error } = self; + assert_not_eq_array(a, b, Some(error)) + } +} + +impl Cheatcode for assertNotEq_24Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b } = self; + assert_not_eq_array(a, b, None) + } +} + +impl Cheatcode for assertNotEq_25Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b, error } = self; + assert_not_eq_array(a, b, Some(error)) + } +} + +impl Cheatcode for assertNotEq_26Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b } = self; + let a = a.iter().map(|x| hex::encode_prefixed(x)).collect::>(); + let b = b.iter().map(|x| hex::encode_prefixed(x)).collect::>(); + assert_not_eq_array(&a, &b, None) + } +} + +impl Cheatcode for assertNotEq_27Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b, error } = self; + let a = a.iter().map(|x| hex::encode_prefixed(x)).collect::>(); + let b = b.iter().map(|x| hex::encode_prefixed(x)).collect::>(); + assert_not_eq_array(&a, &b, Some(error)) + } +} + +impl Cheatcode for assertGt_0Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b } = self; + assert_gt(a, b, None) + } +} + +impl Cheatcode for assertGt_1Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b, error } = self; + assert_gt(a, b, Some(error)) + } +} + +impl Cheatcode for assertGt_2Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b } = self; + assert_gt(a, b, None) + } +} + +impl Cheatcode for assertGt_3Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b, error } = self; + assert_gt(a, b, Some(error)) + } +} + +impl Cheatcode for assertGe_0Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b } = self; + assert_ge(a, b, None) + } +} + +impl Cheatcode for assertGe_1Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b, error } = self; + assert_ge(a, b, Some(error)) + } +} + +impl Cheatcode for assertGe_2Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b } = self; + assert_ge(a, b, None) + } +} + +impl Cheatcode for assertGe_3Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b, error } = self; + assert_ge(a, b, Some(error)) + } +} + +impl Cheatcode for assertLt_0Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b } = self; + assert_lt(a, b, None) + } +} + +impl Cheatcode for assertLt_1Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b, error } = self; + assert_lt(a, b, Some(error)) + } +} + +impl Cheatcode for assertLt_2Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b } = self; + assert_lt(a, b, None) + } +} + +impl Cheatcode for assertLt_3Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b, error } = self; + assert_lt(a, b, Some(error)) + } +} + +impl Cheatcode for assertLe_0Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b } = self; + assert_le(a, b, None) + } +} + +impl Cheatcode for assertLe_1Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b, error } = self; + assert_le(a, b, Some(error)) + } +} + +impl Cheatcode for assertLe_2Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b } = self; + assert_le(a, b, None) + } +} + +impl Cheatcode for assertLe_3Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { a, b, error } = self; + assert_le(a, b, Some(error)) + } +} + +fn get_revert_string(error_message: Option<&str>, failed_assertion_info: String) -> String { + let mut error = String::new(); + if let Some(message) = error_message { + error.push_str(&format!("{message}. ")); + } + error.push_str(&format!("Assertion failed: {}", failed_assertion_info)); + error +} + +fn assert_true(condition: bool, error_message: Option<&str>) -> Result { + if condition { + Ok(Default::default()) + } else { + bail!(get_revert_string(error_message, "condition is false".to_string())) + } +} + +fn assert_eq(a: &T, b: &T, error_message: Option<&str>) -> Result { + if a == b { + Ok(Default::default()) + } else { + bail!(get_revert_string(error_message, format!("{} != {}", a, b))) + } +} + +fn assert_not_eq(a: &T, b: &T, error_message: Option<&str>) -> Result { + if a != b { + Ok(Default::default()) + } else { + bail!(get_revert_string(error_message, format!("{} == {}", a, b))) + } +} + +fn assert_eq_array(a: &Vec, b: &Vec, error_message: Option<&str>) -> Result { + if a == b { + Ok(Default::default()) + } else { + bail!(get_revert_string( + error_message, + format!("[{}] != [{}]", a.into_iter().join(", "), b.into_iter().join(", ")) + )) + } +} + +fn assert_not_eq_array( + a: &Vec, + b: &Vec, + error_message: Option<&str>, +) -> Result { + if a != b { + Ok(Default::default()) + } else { + bail!(get_revert_string( + error_message, + format!("[{}] == [{}]", a.into_iter().join(", "), b.into_iter().join(", ")) + )) + } +} + +fn assert_gt(a: &T, b: &T, error_message: Option<&str>) -> Result { + if a > b { + Ok(Default::default()) + } else { + bail!(get_revert_string(error_message, format!("{} <= {}", a, b))) + } +} + +fn assert_ge(a: &T, b: &T, error_message: Option<&str>) -> Result { + if a >= b { + Ok(Default::default()) + } else { + bail!(get_revert_string(error_message, format!("{} < {}", a, b))) + } +} + +fn assert_lt(a: &T, b: &T, error_message: Option<&str>) -> Result { + if a < b { + Ok(Default::default()) + } else { + bail!(get_revert_string(error_message, format!("{} >= {}", a, b))) + } +} + +fn assert_le(a: &T, b: &T, error_message: Option<&str>) -> Result { + if a <= b { + Ok(Default::default()) + } else { + bail!(get_revert_string(error_message, format!("{} > {}", a, b))) + } +} \ No newline at end of file diff --git a/testdata/cheats/Vm.sol b/testdata/cheats/Vm.sol index 08c8f570bd3e..7e02bdb69076 100644 --- a/testdata/cheats/Vm.sol +++ b/testdata/cheats/Vm.sol @@ -25,6 +25,80 @@ interface Vm { function activeFork() external view returns (uint256 forkId); function addr(uint256 privateKey) external pure returns (address keyAddr); function allowCheatcodes(address account) external; + function assertEq(bool a, bool b) external pure; + function assertEq(bool a, bool b, string calldata error) external pure; + function assertEq(string calldata a, string calldata b) external pure; + function assertEq(string calldata a, string calldata b, string calldata error) external pure; + function assertEq(bytes calldata a, bytes calldata b) external pure; + function assertEq(bytes calldata a, bytes calldata b, string calldata error) external pure; + function assertEq(bool[] calldata a, bool[] calldata b) external pure; + function assertEq(bool[] calldata a, bool[] calldata b, string calldata error) external pure; + function assertEq(uint256[] calldata a, uint256[] calldata b) external pure; + function assertEq(uint256[] calldata a, uint256[] calldata b, string calldata error) external pure; + function assertEq(int256[] calldata a, int256[] calldata b) external pure; + function assertEq(int256[] calldata a, int256[] calldata b, string calldata error) external pure; + function assertEq(uint256 a, uint256 b) external pure; + function assertEq(address[] calldata a, address[] calldata b) external pure; + function assertEq(address[] calldata a, address[] calldata b, string calldata error) external pure; + function assertEq(bytes32[] calldata a, bytes32[] calldata b) external pure; + function assertEq(bytes32[] calldata a, bytes32[] calldata b, string calldata error) external pure; + function assertEq(string[] calldata a, string[] calldata b) external pure; + function assertEq(string[] calldata a, string[] calldata b, string calldata error) external pure; + function assertEq(bytes[] calldata a, bytes[] calldata b) external pure; + function assertEq(bytes[] calldata a, bytes[] calldata b, string calldata error) external pure; + function assertEq(uint256 a, uint256 b, string calldata error) external pure; + function assertEq(int256 a, int256 b) external pure; + function assertEq(int256 a, int256 b, string calldata error) external pure; + function assertEq(address a, address b) external pure; + function assertEq(address a, address b, string calldata error) external pure; + function assertEq(bytes32 a, bytes32 b) external pure; + function assertEq(bytes32 a, bytes32 b, string calldata error) external pure; + function assertGe(uint256 a, uint256 b) external pure; + function assertGe(uint256 a, uint256 b, string calldata error) external pure; + function assertGe(int256 a, int256 b) external pure; + function assertGe(int256 a, int256 b, string calldata error) external pure; + function assertGt(uint256 a, uint256 b) external pure; + function assertGt(uint256 a, uint256 b, string calldata error) external pure; + function assertGt(int256 a, int256 b) external pure; + function assertGt(int256 a, int256 b, string calldata error) external pure; + function assertLe(uint256 a, uint256 b) external pure; + function assertLe(uint256 a, uint256 b, string calldata error) external pure; + function assertLe(int256 a, int256 b) external pure; + function assertLe(int256 a, int256 b, string calldata error) external pure; + function assertLt(uint256 a, uint256 b) external pure; + function assertLt(uint256 a, uint256 b, string calldata error) external pure; + function assertLt(int256 a, int256 b) external pure; + function assertLt(int256 a, int256 b, string calldata error) external pure; + function assertNotEq(bool a, bool b) external pure; + function assertNotEq(bool a, bool b, string calldata error) external pure; + function assertNotEq(string calldata a, string calldata b) external pure; + function assertNotEq(string calldata a, string calldata b, string calldata error) external pure; + function assertNotEq(bytes calldata a, bytes calldata b) external pure; + function assertNotEq(bytes calldata a, bytes calldata b, string calldata error) external pure; + function assertNotEq(bool[] calldata a, bool[] calldata b) external pure; + function assertNotEq(bool[] calldata a, bool[] calldata b, string calldata error) external pure; + function assertNotEq(uint256[] calldata a, uint256[] calldata b) external pure; + function assertNotEq(uint256[] calldata a, uint256[] calldata b, string calldata error) external pure; + function assertNotEq(int256[] calldata a, int256[] calldata b) external pure; + function assertNotEq(int256[] calldata a, int256[] calldata b, string calldata error) external pure; + function assertNotEq(uint256 a, uint256 b) external pure; + function assertNotEq(address[] calldata a, address[] calldata b) external pure; + function assertNotEq(address[] calldata a, address[] calldata b, string calldata error) external pure; + function assertNotEq(bytes32[] calldata a, bytes32[] calldata b) external pure; + function assertNotEq(bytes32[] calldata a, bytes32[] calldata b, string calldata error) external pure; + function assertNotEq(string[] calldata a, string[] calldata b) external pure; + function assertNotEq(string[] calldata a, string[] calldata b, string calldata error) external pure; + function assertNotEq(bytes[] calldata a, bytes[] calldata b) external pure; + function assertNotEq(bytes[] calldata a, bytes[] calldata b, string calldata error) external pure; + function assertNotEq(uint256 a, uint256 b, string calldata error) external pure; + function assertNotEq(int256 a, int256 b) external pure; + function assertNotEq(int256 a, int256 b, string calldata error) external pure; + function assertNotEq(address a, address b) external pure; + function assertNotEq(address a, address b, string calldata error) external pure; + function assertNotEq(bytes32 a, bytes32 b) external pure; + function assertNotEq(bytes32 a, bytes32 b, string calldata error) external pure; + function assertTrue(bool condition) external pure; + function assertTrue(bool condition, string calldata error) external pure; function assume(bool condition) external pure; function breakpoint(string calldata char) external; function breakpoint(string calldata char, bool value) external; From 09239d158ecbc819935bf3dd000859c73cf8f481 Mon Sep 17 00:00:00 2001 From: Arsenii Kulikov Date: Mon, 15 Jan 2024 18:26:33 +0400 Subject: [PATCH 02/19] rustfmt --- crates/cheatcodes/spec/src/vm.rs | 2 +- crates/cheatcodes/src/test/assert.rs | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/crates/cheatcodes/spec/src/vm.rs b/crates/cheatcodes/spec/src/vm.rs index 62d134e4bf65..2a159efb5da0 100644 --- a/crates/cheatcodes/spec/src/vm.rs +++ b/crates/cheatcodes/spec/src/vm.rs @@ -946,7 +946,7 @@ interface Vm { /// Compares two `uint256` values. Expects first value to be greater than second. #[cheatcode(group = Testing, safety = Safe)] function assertGt(uint256 a, uint256 b) external pure; - + /// Compares two `uint256` values. Expects first value to be greater than second. /// Includes error message into revert string on failure. #[cheatcode(group = Testing, safety = Safe)] diff --git a/crates/cheatcodes/src/test/assert.rs b/crates/cheatcodes/src/test/assert.rs index 54d2a9c6fe6c..c9020c569c76 100644 --- a/crates/cheatcodes/src/test/assert.rs +++ b/crates/cheatcodes/src/test/assert.rs @@ -561,7 +561,11 @@ fn assert_not_eq(a: &T, b: &T, error_message: Option<&st } } -fn assert_eq_array(a: &Vec, b: &Vec, error_message: Option<&str>) -> Result { +fn assert_eq_array( + a: &Vec, + b: &Vec, + error_message: Option<&str>, +) -> Result { if a == b { Ok(Default::default()) } else { @@ -617,4 +621,4 @@ fn assert_le(a: &T, b: &T, error_message: Option<&str>) } else { bail!(get_revert_string(error_message, format!("{} > {}", a, b))) } -} \ No newline at end of file +} From 3a7ba91b4c7872b292b953ba663db84c4de4bbb9 Mon Sep 17 00:00:00 2001 From: Arsenii Kulikov Date: Mon, 15 Jan 2024 18:30:31 +0400 Subject: [PATCH 03/19] fix clippy warning --- crates/cheatcodes/src/test/assert.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/crates/cheatcodes/src/test/assert.rs b/crates/cheatcodes/src/test/assert.rs index c9020c569c76..5253a078f5d0 100644 --- a/crates/cheatcodes/src/test/assert.rs +++ b/crates/cheatcodes/src/test/assert.rs @@ -201,8 +201,8 @@ impl Cheatcode for assertEq_25Call { impl Cheatcode for assertEq_26Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b } = self; - let a = a.iter().map(|x| hex::encode_prefixed(x)).collect::>(); - let b = b.iter().map(|x| hex::encode_prefixed(x)).collect::>(); + let a = a.iter().map(hex::encode_prefixed).collect::>(); + let b = b.iter().map(hex::encode_prefixed).collect::>(); assert_eq_array(&a, &b, None) } } @@ -210,8 +210,8 @@ impl Cheatcode for assertEq_26Call { impl Cheatcode for assertEq_27Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b, error } = self; - let a = a.iter().map(|x| hex::encode_prefixed(x)).collect::>(); - let b = b.iter().map(|x| hex::encode_prefixed(x)).collect::>(); + let a = a.iter().map(hex::encode_prefixed).collect::>(); + let b = b.iter().map(hex::encode_prefixed).collect::>(); assert_eq_array(&a, &b, Some(error)) } } @@ -401,8 +401,8 @@ impl Cheatcode for assertNotEq_25Call { impl Cheatcode for assertNotEq_26Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b } = self; - let a = a.iter().map(|x| hex::encode_prefixed(x)).collect::>(); - let b = b.iter().map(|x| hex::encode_prefixed(x)).collect::>(); + let a = a.iter().map(hex::encode_prefixed).collect::>(); + let b = b.iter().map(hex::encode_prefixed).collect::>(); assert_not_eq_array(&a, &b, None) } } @@ -410,8 +410,8 @@ impl Cheatcode for assertNotEq_26Call { impl Cheatcode for assertNotEq_27Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b, error } = self; - let a = a.iter().map(|x| hex::encode_prefixed(x)).collect::>(); - let b = b.iter().map(|x| hex::encode_prefixed(x)).collect::>(); + let a = a.iter().map(hex::encode_prefixed).collect::>(); + let b = b.iter().map(hex::encode_prefixed).collect::>(); assert_not_eq_array(&a, &b, Some(error)) } } @@ -571,7 +571,7 @@ fn assert_eq_array( } else { bail!(get_revert_string( error_message, - format!("[{}] != [{}]", a.into_iter().join(", "), b.into_iter().join(", ")) + format!("[{}] != [{}]", a.iter().join(", "), b.iter().join(", ")) )) } } @@ -586,7 +586,7 @@ fn assert_not_eq_array( } else { bail!(get_revert_string( error_message, - format!("[{}] == [{}]", a.into_iter().join(", "), b.into_iter().join(", ")) + format!("[{}] == [{}]", a.iter().join(", "), b.iter().join(", ")) )) } } From 93b6d5acb42523d48135f202b3c9423869e1dd6c Mon Sep 17 00:00:00 2001 From: Arsenii Kulikov Date: Tue, 16 Jan 2024 03:57:50 +0400 Subject: [PATCH 04/19] dedicated errors --- Cargo.lock | 1 + crates/cheatcodes/Cargo.toml | 1 + crates/cheatcodes/src/test/assert.rs | 290 +++++++++++++++------------ 3 files changed, 164 insertions(+), 128 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index db3c1f8aa359..a4b42b17b980 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2960,6 +2960,7 @@ dependencies = [ "p256", "revm", "serde_json", + "thiserror", "tracing", "walkdir", ] diff --git a/crates/cheatcodes/Cargo.toml b/crates/cheatcodes/Cargo.toml index 7c3d2db0a4cc..d670d26daa60 100644 --- a/crates/cheatcodes/Cargo.toml +++ b/crates/cheatcodes/Cargo.toml @@ -38,3 +38,4 @@ base64.workspace = true tracing.workspace = true walkdir = "2" p256 = "0.13.2" +thiserror = "1" diff --git a/crates/cheatcodes/src/test/assert.rs b/crates/cheatcodes/src/test/assert.rs index 5253a078f5d0..2211ed2bb0cd 100644 --- a/crates/cheatcodes/src/test/assert.rs +++ b/crates/cheatcodes/src/test/assert.rs @@ -2,199 +2,257 @@ use std::fmt::Display; use itertools::Itertools; -use crate::{Cheatcode, Cheatcodes, Result, Vm::*}; +use crate::{Cheatcode, Cheatcodes, Error, Result, Vm::*}; + +#[derive(Debug, thiserror::Error)] +#[error("Assertion failed")] +struct SimpleAssertionError; + +#[derive(thiserror::Error, Debug)] +enum ComparisonAssertionError<'a, T> { + NotEq(&'a T, &'a T), + Eq(&'a T, &'a T), + Ge(&'a T, &'a T), + Gt(&'a T, &'a T), + Le(&'a T, &'a T), + Lt(&'a T, &'a T), +} + +impl<'a, T: Display> ComparisonAssertionError<'a, T> { + fn format_for_values(&self) -> String { + match self { + Self::NotEq(a, b) => format!("{} == {}", a, b), + Self::Eq(a, b) => format!("{} != {}", a, b), + Self::Ge(a, b) => format!("{} < {}", a, b), + Self::Gt(a, b) => format!("{} <= {}", a, b), + Self::Le(a, b) => format!("{} > {}", a, b), + Self::Lt(a, b) => format!("{} >= {}", a, b), + } + } +} + +impl<'a, T: Display> ComparisonAssertionError<'a, Vec> { + fn format_for_arrays(&self) -> String { + match self { + Self::NotEq(a, b) => { + format!("[{}] == [{}]", a.iter().join(", "), b.iter().join(", ")) + } + Self::Eq(a, b) => { + format!("[{}] != [{}]", a.iter().join(", "), b.iter().join(", ")) + } + Self::Ge(a, b) => { + format!("[{}] < [{}]", a.iter().join(", "), b.iter().join(", ")) + } + Self::Gt(a, b) => { + format!("[{}] <= [{}]", a.iter().join(", "), b.iter().join(", ")) + } + Self::Le(a, b) => { + format!("[{}] > [{}]", a.iter().join(", "), b.iter().join(", ")) + } + Self::Lt(a, b) => { + format!("[{}] >= [{}]", a.iter().join(", "), b.iter().join(", ")) + } + } + } +} + +type ComparisonResult<'a, T> = Result, ComparisonAssertionError<'a, T>>; impl Cheatcode for assertTrue_0Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - assert_true(self.condition, None) + Ok(assert_true(self.condition).map_err(|_| "Assertion failed")?) } } impl Cheatcode for assertTrue_1Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - assert_true(self.condition, Some(&self.error)) + Ok(assert_true(self.condition).map_err(|_| self.error.to_string())?) } } impl Cheatcode for assertEq_0Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b } = self; - assert_eq(a, b, None) + Ok(assert_eq(a, b).map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) } } impl Cheatcode for assertEq_1Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b, error } = self; - assert_eq(a, b, Some(error)) + Ok(assert_eq(a, b).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) } } impl Cheatcode for assertEq_2Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b } = self; - assert_eq(a, b, None) + Ok(assert_eq(a, b).map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) } } impl Cheatcode for assertEq_3Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b, error } = self; - assert_eq(a, b, Some(error)) + Ok(assert_eq(a, b).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) } } impl Cheatcode for assertEq_4Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b } = self; - assert_eq(a, b, None) + Ok(assert_eq(a, b).map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) } } impl Cheatcode for assertEq_5Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b, error } = self; - assert_eq(a, b, Some(error)) + Ok(assert_eq(a, b).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) } } impl Cheatcode for assertEq_6Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b } = self; - assert_eq(a, b, None) + Ok(assert_eq(a, b).map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) } } impl Cheatcode for assertEq_7Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b, error } = self; - assert_eq(a, b, Some(error)) + Ok(assert_eq(a, b).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) } } impl Cheatcode for assertEq_8Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b } = self; - assert_eq(a, b, None) + Ok(assert_eq(a, b).map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) } } impl Cheatcode for assertEq_9Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b, error } = self; - assert_eq(a, b, Some(error)) + Ok(assert_eq(a, b).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) } } impl Cheatcode for assertEq_10Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b } = self; - assert_eq(a, b, None) + Ok(assert_eq(&hex::encode_prefixed(a), &hex::encode_prefixed(b)) + .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) } } impl Cheatcode for assertEq_11Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b, error } = self; - assert_eq(a, b, Some(error)) + Ok(assert_eq(&hex::encode_prefixed(a), &hex::encode_prefixed(b)) + .map_err(|e| format!("{}: {}", error, e.format_for_values()))?) } } impl Cheatcode for assertEq_12Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b } = self; - assert_eq(&hex::encode_prefixed(a), &hex::encode_prefixed(b), None) + Ok(assert_eq(&hex::encode_prefixed(a), &hex::encode_prefixed(b)) + .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) } } impl Cheatcode for assertEq_13Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b, error } = self; - assert_eq(&hex::encode_prefixed(a), &hex::encode_prefixed(b), Some(error)) + Ok(assert_eq(&hex::encode_prefixed(a), &hex::encode_prefixed(b)) + .map_err(|e| format!("{}: {}", error, e.format_for_values()))?) } } impl Cheatcode for assertEq_14Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b } = self; - assert_eq_array(a, b, None) + Ok(assert_eq(a, b).map_err(|e| format!("Assertion failed: {}", e.format_for_arrays()))?) } } impl Cheatcode for assertEq_15Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b, error } = self; - assert_eq_array(a, b, Some(error)) + Ok(assert_eq(a, b).map_err(|e| format!("{}: {}", error, e.format_for_arrays()))?) } } impl Cheatcode for assertEq_16Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b } = self; - assert_eq_array(a, b, None) + Ok(assert_eq(a, b).map_err(|e| format!("Assertion failed: {}", e.format_for_arrays()))?) } } impl Cheatcode for assertEq_17Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b, error } = self; - assert_eq_array(a, b, Some(error)) + Ok(assert_eq(a, b).map_err(|e| format!("{}: {}", error, e.format_for_arrays()))?) } } impl Cheatcode for assertEq_18Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b } = self; - assert_eq_array(a, b, None) + Ok(assert_eq(a, b).map_err(|e| format!("Assertion failed: {}", e.format_for_arrays()))?) } } impl Cheatcode for assertEq_19Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b, error } = self; - assert_eq_array(a, b, Some(error)) + Ok(assert_eq(a, b).map_err(|e| format!("{}: {}", error, e.format_for_arrays()))?) } } impl Cheatcode for assertEq_20Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b } = self; - assert_eq_array(a, b, None) + Ok(assert_eq(a, b).map_err(|e| format!("Assertion failed: {}", e.format_for_arrays()))?) } } impl Cheatcode for assertEq_21Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b, error } = self; - assert_eq_array(a, b, Some(error)) + Ok(assert_eq(a, b).map_err(|e| format!("{}: {}", error, e.format_for_arrays()))?) } } impl Cheatcode for assertEq_22Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b } = self; - assert_eq_array(a, b, None) + Ok(assert_eq(a, b).map_err(|e| format!("Assertion failed: {}", e.format_for_arrays()))?) } } impl Cheatcode for assertEq_23Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b, error } = self; - assert_eq_array(a, b, Some(error)) + Ok(assert_eq(a, b).map_err(|e| format!("{}: {}", error, e.format_for_arrays()))?) } } impl Cheatcode for assertEq_24Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b } = self; - assert_eq_array(a, b, None) + Ok(assert_eq(a, b).map_err(|e| format!("Assertion failed: {}", e.format_for_arrays()))?) } } impl Cheatcode for assertEq_25Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b, error } = self; - assert_eq_array(a, b, Some(error)) + Ok(assert_eq(a, b).map_err(|e| format!("{}: {}", error, e.format_for_arrays()))?) } } @@ -203,7 +261,7 @@ impl Cheatcode for assertEq_26Call { let Self { a, b } = self; let a = a.iter().map(hex::encode_prefixed).collect::>(); let b = b.iter().map(hex::encode_prefixed).collect::>(); - assert_eq_array(&a, &b, None) + Ok(assert_eq(&a, &b).map_err(|e| format!("Assertion failed: {}", e.format_for_arrays()))?) } } @@ -212,189 +270,203 @@ impl Cheatcode for assertEq_27Call { let Self { a, b, error } = self; let a = a.iter().map(hex::encode_prefixed).collect::>(); let b = b.iter().map(hex::encode_prefixed).collect::>(); - assert_eq_array(&a, &b, Some(error)) + Ok(assert_eq(&a, &b).map_err(|e| format!("{}: {}", error, e.format_for_arrays()))?) } } impl Cheatcode for assertNotEq_0Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b } = self; - assert_not_eq(a, b, None) + Ok(assert_not_eq(a, b) + .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) } } impl Cheatcode for assertNotEq_1Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b, error } = self; - assert_not_eq(a, b, Some(error)) + Ok(assert_not_eq(a, b).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) } } impl Cheatcode for assertNotEq_2Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b } = self; - assert_not_eq(a, b, None) + Ok(assert_not_eq(a, b) + .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) } } impl Cheatcode for assertNotEq_3Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b, error } = self; - assert_not_eq(a, b, Some(error)) + Ok(assert_not_eq(a, b).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) } } impl Cheatcode for assertNotEq_4Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b } = self; - assert_not_eq(a, b, None) + Ok(assert_not_eq(a, b) + .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) } } impl Cheatcode for assertNotEq_5Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b, error } = self; - assert_not_eq(a, b, Some(error)) + Ok(assert_not_eq(a, b).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) } } impl Cheatcode for assertNotEq_6Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b } = self; - assert_not_eq(a, b, None) + Ok(assert_not_eq(a, b) + .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) } } impl Cheatcode for assertNotEq_7Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b, error } = self; - assert_not_eq(a, b, Some(error)) + Ok(assert_not_eq(a, b).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) } } impl Cheatcode for assertNotEq_8Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b } = self; - assert_not_eq(a, b, None) + Ok(assert_not_eq(a, b) + .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) } } impl Cheatcode for assertNotEq_9Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b, error } = self; - assert_not_eq(a, b, Some(error)) + Ok(assert_not_eq(a, b).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) } } impl Cheatcode for assertNotEq_10Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b } = self; - assert_not_eq(a, b, None) + Ok(assert_not_eq(a, b) + .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) } } impl Cheatcode for assertNotEq_11Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b, error } = self; - assert_not_eq(a, b, Some(error)) + Ok(assert_not_eq(a, b).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) } } impl Cheatcode for assertNotEq_12Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b } = self; - assert_not_eq(&hex::encode_prefixed(a), &hex::encode_prefixed(b), None) + Ok(assert_not_eq(&hex::encode_prefixed(a), &hex::encode_prefixed(b)) + .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) } } impl Cheatcode for assertNotEq_13Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b, error } = self; - assert_not_eq(&hex::encode_prefixed(a), &hex::encode_prefixed(b), Some(error)) + Ok(assert_not_eq(&hex::encode_prefixed(a), &hex::encode_prefixed(b)) + .map_err(|e| format!("{}: {}", error, e.format_for_values()))?) } } impl Cheatcode for assertNotEq_14Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b } = self; - assert_not_eq_array(a, b, None) + Ok(assert_not_eq(a, b) + .map_err(|e| format!("Assertion failed: {}", e.format_for_arrays()))?) } } impl Cheatcode for assertNotEq_15Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b, error } = self; - assert_not_eq_array(a, b, Some(error)) + Ok(assert_not_eq(a, b).map_err(|e| format!("{}: {}", error, e.format_for_arrays()))?) } } impl Cheatcode for assertNotEq_16Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b } = self; - assert_not_eq_array(a, b, None) + Ok(assert_not_eq(a, b) + .map_err(|e| format!("Assertion failed: {}", e.format_for_arrays()))?) } } impl Cheatcode for assertNotEq_17Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b, error } = self; - assert_not_eq_array(a, b, Some(error)) + Ok(assert_not_eq(a, b).map_err(|e| format!("{}: {}", error, e.format_for_arrays()))?) } } impl Cheatcode for assertNotEq_18Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b } = self; - assert_not_eq_array(a, b, None) + Ok(assert_not_eq(a, b) + .map_err(|e| format!("Assertion failed: {}", e.format_for_arrays()))?) } } impl Cheatcode for assertNotEq_19Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b, error } = self; - assert_not_eq_array(a, b, Some(error)) + Ok(assert_not_eq(a, b).map_err(|e| format!("{}: {}", error, e.format_for_arrays()))?) } } impl Cheatcode for assertNotEq_20Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b } = self; - assert_not_eq_array(a, b, None) + Ok(assert_not_eq(a, b) + .map_err(|e| format!("Assertion failed: {}", e.format_for_arrays()))?) } } impl Cheatcode for assertNotEq_21Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b, error } = self; - assert_not_eq_array(a, b, Some(error)) + Ok(assert_not_eq(a, b).map_err(|e| format!("{}: {}", error, e.format_for_arrays()))?) } } impl Cheatcode for assertNotEq_22Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b } = self; - assert_not_eq_array(a, b, None) + Ok(assert_not_eq(a, b) + .map_err(|e| format!("Assertion failed: {}", e.format_for_arrays()))?) } } impl Cheatcode for assertNotEq_23Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b, error } = self; - assert_not_eq_array(a, b, Some(error)) + Ok(assert_not_eq(a, b).map_err(|e| format!("{}: {}", error, e.format_for_arrays()))?) } } impl Cheatcode for assertNotEq_24Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b } = self; - assert_not_eq_array(a, b, None) + Ok(assert_not_eq(a, b) + .map_err(|e| format!("Assertion failed: {}", e.format_for_arrays()))?) } } impl Cheatcode for assertNotEq_25Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b, error } = self; - assert_not_eq_array(a, b, Some(error)) + Ok(assert_not_eq(a, b).map_err(|e| format!("{}: {}", error, e.format_for_arrays()))?) } } @@ -403,7 +475,8 @@ impl Cheatcode for assertNotEq_26Call { let Self { a, b } = self; let a = a.iter().map(hex::encode_prefixed).collect::>(); let b = b.iter().map(hex::encode_prefixed).collect::>(); - assert_not_eq_array(&a, &b, None) + Ok(assert_not_eq(&a, &b) + .map_err(|e| format!("Assertion failed: {}", e.format_for_arrays()))?) } } @@ -412,213 +485,174 @@ impl Cheatcode for assertNotEq_27Call { let Self { a, b, error } = self; let a = a.iter().map(hex::encode_prefixed).collect::>(); let b = b.iter().map(hex::encode_prefixed).collect::>(); - assert_not_eq_array(&a, &b, Some(error)) + Ok(assert_not_eq(&a, &b).map_err(|e| format!("{}: {}", error, e.format_for_arrays()))?) } } impl Cheatcode for assertGt_0Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b } = self; - assert_gt(a, b, None) + Ok(assert_gt(a, b).map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) } } impl Cheatcode for assertGt_1Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b, error } = self; - assert_gt(a, b, Some(error)) + Ok(assert_gt(a, b).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) } } impl Cheatcode for assertGt_2Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b } = self; - assert_gt(a, b, None) + Ok(assert_gt(a, b).map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) } } impl Cheatcode for assertGt_3Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b, error } = self; - assert_gt(a, b, Some(error)) + Ok(assert_gt(a, b).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) } } impl Cheatcode for assertGe_0Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b } = self; - assert_ge(a, b, None) + Ok(assert_ge(a, b).map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) } } impl Cheatcode for assertGe_1Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b, error } = self; - assert_ge(a, b, Some(error)) + Ok(assert_ge(a, b).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) } } impl Cheatcode for assertGe_2Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b } = self; - assert_ge(a, b, None) + Ok(assert_ge(a, b).map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) } } impl Cheatcode for assertGe_3Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b, error } = self; - assert_ge(a, b, Some(error)) + Ok(assert_ge(a, b).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) } } impl Cheatcode for assertLt_0Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b } = self; - assert_lt(a, b, None) + Ok(assert_lt(a, b).map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) } } impl Cheatcode for assertLt_1Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b, error } = self; - assert_lt(a, b, Some(error)) + Ok(assert_lt(a, b).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) } } impl Cheatcode for assertLt_2Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b } = self; - assert_lt(a, b, None) + Ok(assert_lt(a, b).map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) } } impl Cheatcode for assertLt_3Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b, error } = self; - assert_lt(a, b, Some(error)) + Ok(assert_lt(a, b).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) } } impl Cheatcode for assertLe_0Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b } = self; - assert_le(a, b, None) + Ok(assert_le(a, b).map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) } } impl Cheatcode for assertLe_1Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b, error } = self; - assert_le(a, b, Some(error)) + Ok(assert_le(a, b).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) } } impl Cheatcode for assertLe_2Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b } = self; - assert_le(a, b, None) + Ok(assert_le(a, b).map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) } } impl Cheatcode for assertLe_3Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b, error } = self; - assert_le(a, b, Some(error)) + Ok(assert_le(a, b).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) } } -fn get_revert_string(error_message: Option<&str>, failed_assertion_info: String) -> String { - let mut error = String::new(); - if let Some(message) = error_message { - error.push_str(&format!("{message}. ")); - } - error.push_str(&format!("Assertion failed: {}", failed_assertion_info)); - error -} - -fn assert_true(condition: bool, error_message: Option<&str>) -> Result { +fn assert_true(condition: bool) -> Result, SimpleAssertionError> { if condition { Ok(Default::default()) } else { - bail!(get_revert_string(error_message, "condition is false".to_string())) - } -} - -fn assert_eq(a: &T, b: &T, error_message: Option<&str>) -> Result { - if a == b { - Ok(Default::default()) - } else { - bail!(get_revert_string(error_message, format!("{} != {}", a, b))) - } -} - -fn assert_not_eq(a: &T, b: &T, error_message: Option<&str>) -> Result { - if a != b { - Ok(Default::default()) - } else { - bail!(get_revert_string(error_message, format!("{} == {}", a, b))) + Err(SimpleAssertionError) } } -fn assert_eq_array( - a: &Vec, - b: &Vec, - error_message: Option<&str>, -) -> Result { +fn assert_eq<'a, T: PartialEq>(a: &'a T, b: &'a T) -> ComparisonResult<'a, T> { if a == b { Ok(Default::default()) } else { - bail!(get_revert_string( - error_message, - format!("[{}] != [{}]", a.iter().join(", "), b.iter().join(", ")) - )) + Err(ComparisonAssertionError::Eq(a, b)) } } -fn assert_not_eq_array( - a: &Vec, - b: &Vec, - error_message: Option<&str>, -) -> Result { +fn assert_not_eq<'a, T: PartialEq>(a: &'a T, b: &'a T) -> ComparisonResult<'a, T> { if a != b { Ok(Default::default()) } else { - bail!(get_revert_string( - error_message, - format!("[{}] == [{}]", a.iter().join(", "), b.iter().join(", ")) - )) + Err(ComparisonAssertionError::NotEq(a, b)) } } -fn assert_gt(a: &T, b: &T, error_message: Option<&str>) -> Result { +fn assert_gt<'a, T: PartialOrd>(a: &'a T, b: &'a T) -> ComparisonResult<'a, T> { if a > b { Ok(Default::default()) } else { - bail!(get_revert_string(error_message, format!("{} <= {}", a, b))) + Err(ComparisonAssertionError::Gt(a, b)) } } -fn assert_ge(a: &T, b: &T, error_message: Option<&str>) -> Result { +fn assert_ge<'a, T: PartialOrd>(a: &'a T, b: &'a T) -> ComparisonResult<'a, T> { if a >= b { Ok(Default::default()) } else { - bail!(get_revert_string(error_message, format!("{} < {}", a, b))) + Err(ComparisonAssertionError::Ge(a, b)) } } -fn assert_lt(a: &T, b: &T, error_message: Option<&str>) -> Result { +fn assert_lt<'a, T: PartialOrd>(a: &'a T, b: &'a T) -> ComparisonResult<'a, T> { if a < b { Ok(Default::default()) } else { - bail!(get_revert_string(error_message, format!("{} >= {}", a, b))) + Err(ComparisonAssertionError::Lt(a, b)) } } -fn assert_le(a: &T, b: &T, error_message: Option<&str>) -> Result { +fn assert_le<'a, T: PartialOrd>(a: &'a T, b: &'a T) -> ComparisonResult<'a, T> { if a <= b { Ok(Default::default()) } else { - bail!(get_revert_string(error_message, format!("{} > {}", a, b))) + Err(ComparisonAssertionError::Le(a, b)) } } From 9932d2f0da69e70f497b2c8fa6e82f568240948a Mon Sep 17 00:00:00 2001 From: Arsenii Kulikov Date: Tue, 16 Jan 2024 04:13:48 +0400 Subject: [PATCH 05/19] fix clippy warning --- crates/cheatcodes/src/test/assert.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/cheatcodes/src/test/assert.rs b/crates/cheatcodes/src/test/assert.rs index 2211ed2bb0cd..ba8c37cc25f3 100644 --- a/crates/cheatcodes/src/test/assert.rs +++ b/crates/cheatcodes/src/test/assert.rs @@ -2,7 +2,7 @@ use std::fmt::Display; use itertools::Itertools; -use crate::{Cheatcode, Cheatcodes, Error, Result, Vm::*}; +use crate::{Cheatcode, Cheatcodes, Result, Vm::*}; #[derive(Debug, thiserror::Error)] #[error("Assertion failed")] From b18e2f267edff019a0928c8b04d1382eeac1cb7b Mon Sep 17 00:00:00 2001 From: Arsenii Kulikov Date: Tue, 16 Jan 2024 13:35:55 +0400 Subject: [PATCH 06/19] assertFalse --- crates/cheatcodes/assets/cheatcodes.json | 40 ++++++++++++++++++++++++ crates/cheatcodes/spec/src/vm.rs | 8 +++++ crates/cheatcodes/src/test/assert.rs | 20 ++++++++++++ testdata/cheats/Vm.sol | 2 ++ 4 files changed, 70 insertions(+) diff --git a/crates/cheatcodes/assets/cheatcodes.json b/crates/cheatcodes/assets/cheatcodes.json index 61c90aa3653c..ea280bc22ef0 100644 --- a/crates/cheatcodes/assets/cheatcodes.json +++ b/crates/cheatcodes/assets/cheatcodes.json @@ -1113,6 +1113,46 @@ "status": "stable", "safety": "safe" }, + { + "func": { + "id": "assertFalse_0", + "description": "Asserts that the given condition is false.", + "declaration": "function assertFalse(bool condition) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertFalse(bool)", + "selector": "0xa5982885", + "selectorBytes": [ + 165, + 152, + 40, + 133 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertFalse_1", + "description": "Asserts that the given condition is false and includes error message into revert string on failure.", + "declaration": "function assertFalse(bool condition, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertFalse(bool,string)", + "selector": "0x7ba04809", + "selectorBytes": [ + 123, + 160, + 72, + 9 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, { "func": { "id": "assertGe_0", diff --git a/crates/cheatcodes/spec/src/vm.rs b/crates/cheatcodes/spec/src/vm.rs index 2a159efb5da0..1dad0ba2c6a8 100644 --- a/crates/cheatcodes/spec/src/vm.rs +++ b/crates/cheatcodes/spec/src/vm.rs @@ -719,6 +719,14 @@ interface Vm { #[cheatcode(group = Testing, safety = Safe)] function assertTrue(bool condition, string calldata error) external pure; + /// Asserts that the given condition is false. + #[cheatcode(group = Testing, safety = Safe)] + function assertFalse(bool condition) external pure; + + /// Asserts that the given condition is false and includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertFalse(bool condition, string calldata error) external pure; + /// Asserts that two `bool` values are equal. #[cheatcode(group = Testing, safety = Safe)] function assertEq(bool a, bool b) external pure; diff --git a/crates/cheatcodes/src/test/assert.rs b/crates/cheatcodes/src/test/assert.rs index ba8c37cc25f3..5e6838a14923 100644 --- a/crates/cheatcodes/src/test/assert.rs +++ b/crates/cheatcodes/src/test/assert.rs @@ -70,6 +70,18 @@ impl Cheatcode for assertTrue_1Call { } } +impl Cheatcode for assertFalse_0Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + Ok(assert_false(self.condition).map_err(|_| "Assertion failed")?) + } +} + +impl Cheatcode for assertFalse_1Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + Ok(assert_false(self.condition).map_err(|_| self.error.to_string())?) + } +} + impl Cheatcode for assertEq_0Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { a, b } = self; @@ -609,6 +621,14 @@ fn assert_true(condition: bool) -> Result, SimpleAssertionError> { } } +fn assert_false(condition: bool) -> Result, SimpleAssertionError> { + if !condition { + Ok(Default::default()) + } else { + Err(SimpleAssertionError) + } +} + fn assert_eq<'a, T: PartialEq>(a: &'a T, b: &'a T) -> ComparisonResult<'a, T> { if a == b { Ok(Default::default()) diff --git a/testdata/cheats/Vm.sol b/testdata/cheats/Vm.sol index 7e02bdb69076..d6a3f9657338 100644 --- a/testdata/cheats/Vm.sol +++ b/testdata/cheats/Vm.sol @@ -53,6 +53,8 @@ interface Vm { function assertEq(address a, address b, string calldata error) external pure; function assertEq(bytes32 a, bytes32 b) external pure; function assertEq(bytes32 a, bytes32 b, string calldata error) external pure; + function assertFalse(bool condition) external pure; + function assertFalse(bool condition, string calldata error) external pure; function assertGe(uint256 a, uint256 b) external pure; function assertGe(uint256 a, uint256 b, string calldata error) external pure; function assertGe(int256 a, int256 b) external pure; From d12fea9a983c59994a7506d2288ee147cfb17c2a Mon Sep 17 00:00:00 2001 From: Arsenii Kulikov Date: Tue, 16 Jan 2024 16:05:38 +0400 Subject: [PATCH 07/19] assertEqAbs --- crates/cheatcodes/assets/cheatcodes.json | 80 ++++++++++++++++++++++++ crates/cheatcodes/spec/src/vm.rs | 18 ++++++ crates/cheatcodes/src/test/assert.rs | 76 +++++++++++++++++++++- testdata/cheats/Vm.sol | 4 ++ 4 files changed, 177 insertions(+), 1 deletion(-) diff --git a/crates/cheatcodes/assets/cheatcodes.json b/crates/cheatcodes/assets/cheatcodes.json index ea280bc22ef0..07f4c25e47d8 100644 --- a/crates/cheatcodes/assets/cheatcodes.json +++ b/crates/cheatcodes/assets/cheatcodes.json @@ -553,6 +553,86 @@ "status": "stable", "safety": "unsafe" }, + { + "func": { + "id": "assertApproxEqAbs_0", + "description": "Compares two `uint256` values. Expects difference to be less than or equal to `maxDelta`.", + "declaration": "function assertApproxEqAbs(uint256 a, uint256 b, uint256 maxDelta) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertApproxEqAbs(uint256,uint256,uint256)", + "selector": "0x16d207c6", + "selectorBytes": [ + 22, + 210, + 7, + 198 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertApproxEqAbs_1", + "description": "Compares two `uint256` values. Expects difference to be less than or equal to `maxDelta`.\nIncludes error message into revert string on failure.", + "declaration": "function assertApproxEqAbs(uint256 a, uint256 b, uint256 maxDelta, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertApproxEqAbs(uint256,uint256,uint256,string)", + "selector": "0xf710b062", + "selectorBytes": [ + 247, + 16, + 176, + 98 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertApproxEqAbs_2", + "description": "Compares two `int256` values. Expects difference to be less than or equal to `maxDelta`.", + "declaration": "function assertApproxEqAbs(int256 a, int256 b, uint256 maxDelta) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertApproxEqAbs(int256,int256,uint256)", + "selector": "0x240f839d", + "selectorBytes": [ + 36, + 15, + 131, + 157 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertApproxEqAbs_3", + "description": "Compares two `int256` values. Expects difference to be less than or equal to `maxDelta`.\nIncludes error message into revert string on failure.", + "declaration": "function assertApproxEqAbs(int256 a, int256 b, uint256 maxDelta, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertApproxEqAbs(int256,int256,uint256,string)", + "selector": "0x8289e621", + "selectorBytes": [ + 130, + 137, + 230, + 33 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, { "func": { "id": "assertEq_0", diff --git a/crates/cheatcodes/spec/src/vm.rs b/crates/cheatcodes/spec/src/vm.rs index 1dad0ba2c6a8..9850ef01baaa 100644 --- a/crates/cheatcodes/spec/src/vm.rs +++ b/crates/cheatcodes/spec/src/vm.rs @@ -1023,6 +1023,24 @@ interface Vm { #[cheatcode(group = Testing, safety = Safe)] function assertLe(int256 a, int256 b, string calldata error) external pure; + /// Compares two `uint256` values. Expects difference to be less than or equal to `maxDelta`. + #[cheatcode(group = Testing, safety = Safe)] + function assertApproxEqAbs(uint256 a, uint256 b, uint256 maxDelta) external pure; + + /// Compares two `uint256` values. Expects difference to be less than or equal to `maxDelta`. + /// Includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertApproxEqAbs(uint256 a, uint256 b, uint256 maxDelta, string calldata error) external pure; + + /// Compares two `int256` values. Expects difference to be less than or equal to `maxDelta`. + #[cheatcode(group = Testing, safety = Safe)] + function assertApproxEqAbs(int256 a, int256 b, uint256 maxDelta) external pure; + + /// Compares two `int256` values. Expects difference to be less than or equal to `maxDelta`. + /// Includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertApproxEqAbs(int256 a, int256 b, uint256 maxDelta, string calldata error) external pure; + // ======== OS and Filesystem ======== // -------- Metadata -------- diff --git a/crates/cheatcodes/src/test/assert.rs b/crates/cheatcodes/src/test/assert.rs index 5e6838a14923..99b64a9f5577 100644 --- a/crates/cheatcodes/src/test/assert.rs +++ b/crates/cheatcodes/src/test/assert.rs @@ -1,5 +1,6 @@ -use std::fmt::Display; +use std::fmt::{Debug, Display}; +use alloy_primitives::{I256, U256}; use itertools::Itertools; use crate::{Cheatcode, Cheatcodes, Result, Vm::*}; @@ -18,6 +19,12 @@ enum ComparisonAssertionError<'a, T> { Lt(&'a T, &'a T), } +#[derive(thiserror::Error, Debug)] +enum ApproxAssertionError { + #[error("{a} !~= {b} (max delta: {expected_delta}, real delta: {delta})")] + EqAbs { a: T, b: T, expected_delta: D, delta: D }, +} + impl<'a, T: Display> ComparisonAssertionError<'a, T> { fn format_for_values(&self) -> String { match self { @@ -613,6 +620,34 @@ impl Cheatcode for assertLe_3Call { } } +impl Cheatcode for assertApproxEqAbs_0Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + Ok(uint_assert_approx_eq_abs(self.a, self.b, self.maxDelta) + .map_err(|e| format!("Assertion failed: {}", e.to_string()))?) + } +} + +impl Cheatcode for assertApproxEqAbs_1Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + Ok(uint_assert_approx_eq_abs(self.a, self.b, self.maxDelta) + .map_err(|e| format!("{}: {}", self.error, e.to_string()))?) + } +} + +impl Cheatcode for assertApproxEqAbs_2Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + Ok(int_assert_approx_eq_abs(self.a, self.b, self.maxDelta) + .map_err(|e| format!("Assertion failed: {}", e.to_string()))?) + } +} + +impl Cheatcode for assertApproxEqAbs_3Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + Ok(int_assert_approx_eq_abs(self.a, self.b, self.maxDelta) + .map_err(|e| format!("{}: {}", self.error, e.to_string()))?) + } +} + fn assert_true(condition: bool) -> Result, SimpleAssertionError> { if condition { Ok(Default::default()) @@ -645,6 +680,45 @@ fn assert_not_eq<'a, T: PartialEq>(a: &'a T, b: &'a T) -> ComparisonResult<'a, T } } +fn uint_assert_approx_eq_abs( + a: U256, + b: U256, + max_delta: U256, +) -> Result, ApproxAssertionError> { + let delta = if a > b { a - b } else { b - a }; + + if delta <= max_delta { + Ok(Default::default()) + } else { + Err(ApproxAssertionError::EqAbs { a, b, expected_delta: max_delta, delta }) + } +} + +fn int_assert_approx_eq_abs( + a: I256, + b: I256, + max_delta: U256, +) -> Result, ApproxAssertionError> { + let (a_sign, a_abs) = a.into_sign_and_abs(); + let (b_sign, b_abs) = b.into_sign_and_abs(); + + let delta = if a_sign == b_sign { + if a_abs > b_abs { + a_abs - b_abs + } else { + b_abs - a_abs + } + } else { + a_abs + b_abs + }; + + if delta <= max_delta { + Ok(Default::default()) + } else { + Err(ApproxAssertionError::EqAbs { a, b, expected_delta: max_delta, delta }) + } +} + fn assert_gt<'a, T: PartialOrd>(a: &'a T, b: &'a T) -> ComparisonResult<'a, T> { if a > b { Ok(Default::default()) diff --git a/testdata/cheats/Vm.sol b/testdata/cheats/Vm.sol index d6a3f9657338..1c9fbbdf12da 100644 --- a/testdata/cheats/Vm.sol +++ b/testdata/cheats/Vm.sol @@ -25,6 +25,10 @@ interface Vm { function activeFork() external view returns (uint256 forkId); function addr(uint256 privateKey) external pure returns (address keyAddr); function allowCheatcodes(address account) external; + function assertApproxEqAbs(uint256 a, uint256 b, uint256 maxDelta) external pure; + function assertApproxEqAbs(uint256 a, uint256 b, uint256 maxDelta, string calldata error) external pure; + function assertApproxEqAbs(int256 a, int256 b, uint256 maxDelta) external pure; + function assertApproxEqAbs(int256 a, int256 b, uint256 maxDelta, string calldata error) external pure; function assertEq(bool a, bool b) external pure; function assertEq(bool a, bool b, string calldata error) external pure; function assertEq(string calldata a, string calldata b) external pure; From 05828abd664dc4131104a884424be482c7f703f1 Mon Sep 17 00:00:00 2001 From: Arsenii Kulikov Date: Tue, 16 Jan 2024 16:15:48 +0400 Subject: [PATCH 08/19] Prettify format_for_arrays --- crates/cheatcodes/src/test/assert.rs | 32 +++++++++++----------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/crates/cheatcodes/src/test/assert.rs b/crates/cheatcodes/src/test/assert.rs index 99b64a9f5577..befc063e7922 100644 --- a/crates/cheatcodes/src/test/assert.rs +++ b/crates/cheatcodes/src/test/assert.rs @@ -29,7 +29,7 @@ impl<'a, T: Display> ComparisonAssertionError<'a, T> { fn format_for_values(&self) -> String { match self { Self::NotEq(a, b) => format!("{} == {}", a, b), - Self::Eq(a, b) => format!("{} != {}", a, b), + Self::Eq(a, b) => format!("{} != {}", a, b), Self::Ge(a, b) => format!("{} < {}", a, b), Self::Gt(a, b) => format!("{} <= {}", a, b), Self::Le(a, b) => format!("{} > {}", a, b), @@ -38,27 +38,21 @@ impl<'a, T: Display> ComparisonAssertionError<'a, T> { } } +macro_rules! format_arrays { + ($a:expr, $b:expr, $c:literal) => { + format!("[{}] {} [{}]", $a.iter().join(", "), $c, $b.iter().join(", ")) + }; +} + impl<'a, T: Display> ComparisonAssertionError<'a, Vec> { fn format_for_arrays(&self) -> String { match self { - Self::NotEq(a, b) => { - format!("[{}] == [{}]", a.iter().join(", "), b.iter().join(", ")) - } - Self::Eq(a, b) => { - format!("[{}] != [{}]", a.iter().join(", "), b.iter().join(", ")) - } - Self::Ge(a, b) => { - format!("[{}] < [{}]", a.iter().join(", "), b.iter().join(", ")) - } - Self::Gt(a, b) => { - format!("[{}] <= [{}]", a.iter().join(", "), b.iter().join(", ")) - } - Self::Le(a, b) => { - format!("[{}] > [{}]", a.iter().join(", "), b.iter().join(", ")) - } - Self::Lt(a, b) => { - format!("[{}] >= [{}]", a.iter().join(", "), b.iter().join(", ")) - } + Self::NotEq(a, b) => format_arrays!(a, b, "=="), + Self::Eq(a, b) => format_arrays!(a, b, "!="), + Self::Ge(a, b) => format_arrays!(a, b, "<"), + Self::Gt(a, b) => format_arrays!(a, b, "<="), + Self::Le(a, b) => format_arrays!(a, b, ">"), + Self::Lt(a, b) => format_arrays!(a, b, ">="), } } } From 254e0290dc56a7335fc9e81e6c98e7716097d774 Mon Sep 17 00:00:00 2001 From: Arsenii Kulikov Date: Tue, 16 Jan 2024 16:24:29 +0400 Subject: [PATCH 09/19] (a, b) -> (left, right) --- crates/cheatcodes/assets/cheatcodes.json | 152 ++++---- crates/cheatcodes/spec/src/vm.rs | 152 ++++---- crates/cheatcodes/src/test/assert.rs | 441 ++++++++++++----------- testdata/cheats/Vm.sol | 152 ++++---- 4 files changed, 465 insertions(+), 432 deletions(-) diff --git a/crates/cheatcodes/assets/cheatcodes.json b/crates/cheatcodes/assets/cheatcodes.json index 07f4c25e47d8..97a102183431 100644 --- a/crates/cheatcodes/assets/cheatcodes.json +++ b/crates/cheatcodes/assets/cheatcodes.json @@ -557,7 +557,7 @@ "func": { "id": "assertApproxEqAbs_0", "description": "Compares two `uint256` values. Expects difference to be less than or equal to `maxDelta`.", - "declaration": "function assertApproxEqAbs(uint256 a, uint256 b, uint256 maxDelta) external pure;", + "declaration": "function assertApproxEqAbs(uint256 left, uint256 right, uint256 maxDelta) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertApproxEqAbs(uint256,uint256,uint256)", @@ -577,7 +577,7 @@ "func": { "id": "assertApproxEqAbs_1", "description": "Compares two `uint256` values. Expects difference to be less than or equal to `maxDelta`.\nIncludes error message into revert string on failure.", - "declaration": "function assertApproxEqAbs(uint256 a, uint256 b, uint256 maxDelta, string calldata error) external pure;", + "declaration": "function assertApproxEqAbs(uint256 left, uint256 right, uint256 maxDelta, string calldata error) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertApproxEqAbs(uint256,uint256,uint256,string)", @@ -597,7 +597,7 @@ "func": { "id": "assertApproxEqAbs_2", "description": "Compares two `int256` values. Expects difference to be less than or equal to `maxDelta`.", - "declaration": "function assertApproxEqAbs(int256 a, int256 b, uint256 maxDelta) external pure;", + "declaration": "function assertApproxEqAbs(int256 left, int256 right, uint256 maxDelta) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertApproxEqAbs(int256,int256,uint256)", @@ -617,7 +617,7 @@ "func": { "id": "assertApproxEqAbs_3", "description": "Compares two `int256` values. Expects difference to be less than or equal to `maxDelta`.\nIncludes error message into revert string on failure.", - "declaration": "function assertApproxEqAbs(int256 a, int256 b, uint256 maxDelta, string calldata error) external pure;", + "declaration": "function assertApproxEqAbs(int256 left, int256 right, uint256 maxDelta, string calldata error) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertApproxEqAbs(int256,int256,uint256,string)", @@ -637,7 +637,7 @@ "func": { "id": "assertEq_0", "description": "Asserts that two `bool` values are equal.", - "declaration": "function assertEq(bool a, bool b) external pure;", + "declaration": "function assertEq(bool left, bool right) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertEq(bool,bool)", @@ -657,7 +657,7 @@ "func": { "id": "assertEq_1", "description": "Asserts that two `bool` values are equal and includes error message into revert string on failure.", - "declaration": "function assertEq(bool a, bool b, string calldata error) external pure;", + "declaration": "function assertEq(bool left, bool right, string calldata error) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertEq(bool,bool,string)", @@ -677,7 +677,7 @@ "func": { "id": "assertEq_10", "description": "Asserts that two `string` values are equal.", - "declaration": "function assertEq(string calldata a, string calldata b) external pure;", + "declaration": "function assertEq(string calldata left, string calldata right) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertEq(string,string)", @@ -697,7 +697,7 @@ "func": { "id": "assertEq_11", "description": "Asserts that two `string` values are equal and includes error message into revert string on failure.", - "declaration": "function assertEq(string calldata a, string calldata b, string calldata error) external pure;", + "declaration": "function assertEq(string calldata left, string calldata right, string calldata error) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertEq(string,string,string)", @@ -717,7 +717,7 @@ "func": { "id": "assertEq_12", "description": "Asserts that two `bytes` values are equal.", - "declaration": "function assertEq(bytes calldata a, bytes calldata b) external pure;", + "declaration": "function assertEq(bytes calldata left, bytes calldata right) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertEq(bytes,bytes)", @@ -737,7 +737,7 @@ "func": { "id": "assertEq_13", "description": "Asserts that two `bytes` values are equal and includes error message into revert string on failure.", - "declaration": "function assertEq(bytes calldata a, bytes calldata b, string calldata error) external pure;", + "declaration": "function assertEq(bytes calldata left, bytes calldata right, string calldata error) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertEq(bytes,bytes,string)", @@ -757,7 +757,7 @@ "func": { "id": "assertEq_14", "description": "Asserts that two arrays of `bool` values are equal.", - "declaration": "function assertEq(bool[] calldata a, bool[] calldata b) external pure;", + "declaration": "function assertEq(bool[] calldata left, bool[] calldata right) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertEq(bool[],bool[])", @@ -777,7 +777,7 @@ "func": { "id": "assertEq_15", "description": "Asserts that two arrays of `bool` values are equal and includes error message into revert string on failure.", - "declaration": "function assertEq(bool[] calldata a, bool[] calldata b, string calldata error) external pure;", + "declaration": "function assertEq(bool[] calldata left, bool[] calldata right, string calldata error) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertEq(bool[],bool[],string)", @@ -797,7 +797,7 @@ "func": { "id": "assertEq_16", "description": "Asserts that two arrays of `uint256 values are equal.", - "declaration": "function assertEq(uint256[] calldata a, uint256[] calldata b) external pure;", + "declaration": "function assertEq(uint256[] calldata left, uint256[] calldata right) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertEq(uint256[],uint256[])", @@ -817,7 +817,7 @@ "func": { "id": "assertEq_17", "description": "Asserts that two arrays of `uint256` values are equal and includes error message into revert string on failure.", - "declaration": "function assertEq(uint256[] calldata a, uint256[] calldata b, string calldata error) external pure;", + "declaration": "function assertEq(uint256[] calldata left, uint256[] calldata right, string calldata error) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertEq(uint256[],uint256[],string)", @@ -837,7 +837,7 @@ "func": { "id": "assertEq_18", "description": "Asserts that two arrays of `int256` values are equal.", - "declaration": "function assertEq(int256[] calldata a, int256[] calldata b) external pure;", + "declaration": "function assertEq(int256[] calldata left, int256[] calldata right) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertEq(int256[],int256[])", @@ -857,7 +857,7 @@ "func": { "id": "assertEq_19", "description": "Asserts that two arrays of `int256` values are equal and includes error message into revert string on failure.", - "declaration": "function assertEq(int256[] calldata a, int256[] calldata b, string calldata error) external pure;", + "declaration": "function assertEq(int256[] calldata left, int256[] calldata right, string calldata error) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertEq(int256[],int256[],string)", @@ -877,7 +877,7 @@ "func": { "id": "assertEq_2", "description": "Asserts that two `uint256` values are equal.", - "declaration": "function assertEq(uint256 a, uint256 b) external pure;", + "declaration": "function assertEq(uint256 left, uint256 right) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertEq(uint256,uint256)", @@ -897,7 +897,7 @@ "func": { "id": "assertEq_20", "description": "Asserts that two arrays of `address` values are equal.", - "declaration": "function assertEq(address[] calldata a, address[] calldata b) external pure;", + "declaration": "function assertEq(address[] calldata left, address[] calldata right) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertEq(address[],address[])", @@ -917,7 +917,7 @@ "func": { "id": "assertEq_21", "description": "Asserts that two arrays of `address` values are equal and includes error message into revert string on failure.", - "declaration": "function assertEq(address[] calldata a, address[] calldata b, string calldata error) external pure;", + "declaration": "function assertEq(address[] calldata left, address[] calldata right, string calldata error) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertEq(address[],address[],string)", @@ -937,7 +937,7 @@ "func": { "id": "assertEq_22", "description": "Asserts that two arrays of `bytes32` values are equal.", - "declaration": "function assertEq(bytes32[] calldata a, bytes32[] calldata b) external pure;", + "declaration": "function assertEq(bytes32[] calldata left, bytes32[] calldata right) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertEq(bytes32[],bytes32[])", @@ -957,7 +957,7 @@ "func": { "id": "assertEq_23", "description": "Asserts that two arrays of `bytes32` values are equal and includes error message into revert string on failure.", - "declaration": "function assertEq(bytes32[] calldata a, bytes32[] calldata b, string calldata error) external pure;", + "declaration": "function assertEq(bytes32[] calldata left, bytes32[] calldata right, string calldata error) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertEq(bytes32[],bytes32[],string)", @@ -977,7 +977,7 @@ "func": { "id": "assertEq_24", "description": "Asserts that two arrays of `string` values are equal.", - "declaration": "function assertEq(string[] calldata a, string[] calldata b) external pure;", + "declaration": "function assertEq(string[] calldata left, string[] calldata right) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertEq(string[],string[])", @@ -997,7 +997,7 @@ "func": { "id": "assertEq_25", "description": "Asserts that two arrays of `string` values are equal and includes error message into revert string on failure.", - "declaration": "function assertEq(string[] calldata a, string[] calldata b, string calldata error) external pure;", + "declaration": "function assertEq(string[] calldata left, string[] calldata right, string calldata error) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertEq(string[],string[],string)", @@ -1017,7 +1017,7 @@ "func": { "id": "assertEq_26", "description": "Asserts that two arrays of `bytes` values are equal.", - "declaration": "function assertEq(bytes[] calldata a, bytes[] calldata b) external pure;", + "declaration": "function assertEq(bytes[] calldata left, bytes[] calldata right) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertEq(bytes[],bytes[])", @@ -1037,7 +1037,7 @@ "func": { "id": "assertEq_27", "description": "Asserts that two arrays of `bytes` values are equal and includes error message into revert string on failure.", - "declaration": "function assertEq(bytes[] calldata a, bytes[] calldata b, string calldata error) external pure;", + "declaration": "function assertEq(bytes[] calldata left, bytes[] calldata right, string calldata error) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertEq(bytes[],bytes[],string)", @@ -1057,7 +1057,7 @@ "func": { "id": "assertEq_3", "description": "Asserts that two `uint256` values are equal and includes error message into revert string on failure.", - "declaration": "function assertEq(uint256 a, uint256 b, string calldata error) external pure;", + "declaration": "function assertEq(uint256 left, uint256 right, string calldata error) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertEq(uint256,uint256,string)", @@ -1077,7 +1077,7 @@ "func": { "id": "assertEq_4", "description": "Asserts that two `int256` values are equal.", - "declaration": "function assertEq(int256 a, int256 b) external pure;", + "declaration": "function assertEq(int256 left, int256 right) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertEq(int256,int256)", @@ -1097,7 +1097,7 @@ "func": { "id": "assertEq_5", "description": "Asserts that two `int256` values are equal and includes error message into revert string on failure.", - "declaration": "function assertEq(int256 a, int256 b, string calldata error) external pure;", + "declaration": "function assertEq(int256 left, int256 right, string calldata error) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertEq(int256,int256,string)", @@ -1117,7 +1117,7 @@ "func": { "id": "assertEq_6", "description": "Asserts that two `address` values are equal.", - "declaration": "function assertEq(address a, address b) external pure;", + "declaration": "function assertEq(address left, address right) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertEq(address,address)", @@ -1137,7 +1137,7 @@ "func": { "id": "assertEq_7", "description": "Asserts that two `address` values are equal and includes error message into revert string on failure.", - "declaration": "function assertEq(address a, address b, string calldata error) external pure;", + "declaration": "function assertEq(address left, address right, string calldata error) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertEq(address,address,string)", @@ -1157,7 +1157,7 @@ "func": { "id": "assertEq_8", "description": "Asserts that two `bytes32` values are equal.", - "declaration": "function assertEq(bytes32 a, bytes32 b) external pure;", + "declaration": "function assertEq(bytes32 left, bytes32 right) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertEq(bytes32,bytes32)", @@ -1177,7 +1177,7 @@ "func": { "id": "assertEq_9", "description": "Asserts that two `bytes32` values are equal and includes error message into revert string on failure.", - "declaration": "function assertEq(bytes32 a, bytes32 b, string calldata error) external pure;", + "declaration": "function assertEq(bytes32 left, bytes32 right, string calldata error) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertEq(bytes32,bytes32,string)", @@ -1237,7 +1237,7 @@ "func": { "id": "assertGe_0", "description": "Compares two `uint256` values. Expects first value to be greater than or equal to second.", - "declaration": "function assertGe(uint256 a, uint256 b) external pure;", + "declaration": "function assertGe(uint256 left, uint256 right) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertGe(uint256,uint256)", @@ -1257,7 +1257,7 @@ "func": { "id": "assertGe_1", "description": "Compares two `uint256` values. Expects first value to be greater than or equal to second.\nIncludes error message into revert string on failure.", - "declaration": "function assertGe(uint256 a, uint256 b, string calldata error) external pure;", + "declaration": "function assertGe(uint256 left, uint256 right, string calldata error) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertGe(uint256,uint256,string)", @@ -1277,7 +1277,7 @@ "func": { "id": "assertGe_2", "description": "Compares two `int256` values. Expects first value to be greater than or equal to second.", - "declaration": "function assertGe(int256 a, int256 b) external pure;", + "declaration": "function assertGe(int256 left, int256 right) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertGe(int256,int256)", @@ -1297,7 +1297,7 @@ "func": { "id": "assertGe_3", "description": "Compares two `int256` values. Expects first value to be greater than or equal to second.\nIncludes error message into revert string on failure.", - "declaration": "function assertGe(int256 a, int256 b, string calldata error) external pure;", + "declaration": "function assertGe(int256 left, int256 right, string calldata error) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertGe(int256,int256,string)", @@ -1317,7 +1317,7 @@ "func": { "id": "assertGt_0", "description": "Compares two `uint256` values. Expects first value to be greater than second.", - "declaration": "function assertGt(uint256 a, uint256 b) external pure;", + "declaration": "function assertGt(uint256 left, uint256 right) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertGt(uint256,uint256)", @@ -1337,7 +1337,7 @@ "func": { "id": "assertGt_1", "description": "Compares two `uint256` values. Expects first value to be greater than second.\nIncludes error message into revert string on failure.", - "declaration": "function assertGt(uint256 a, uint256 b, string calldata error) external pure;", + "declaration": "function assertGt(uint256 left, uint256 right, string calldata error) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertGt(uint256,uint256,string)", @@ -1357,7 +1357,7 @@ "func": { "id": "assertGt_2", "description": "Compares two `int256` values. Expects first value to be greater than second.", - "declaration": "function assertGt(int256 a, int256 b) external pure;", + "declaration": "function assertGt(int256 left, int256 right) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertGt(int256,int256)", @@ -1377,7 +1377,7 @@ "func": { "id": "assertGt_3", "description": "Compares two `int256` values. Expects first value to be greater than second.\nIncludes error message into revert string on failure.", - "declaration": "function assertGt(int256 a, int256 b, string calldata error) external pure;", + "declaration": "function assertGt(int256 left, int256 right, string calldata error) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertGt(int256,int256,string)", @@ -1397,7 +1397,7 @@ "func": { "id": "assertLe_0", "description": "Compares two `uint256` values. Expects first value to be less than or equal to second.", - "declaration": "function assertLe(uint256 a, uint256 b) external pure;", + "declaration": "function assertLe(uint256 left, uint256 right) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertLe(uint256,uint256)", @@ -1417,7 +1417,7 @@ "func": { "id": "assertLe_1", "description": "Compares two `uint256` values. Expects first value to be less than or equal to second.\nIncludes error message into revert string on failure.", - "declaration": "function assertLe(uint256 a, uint256 b, string calldata error) external pure;", + "declaration": "function assertLe(uint256 left, uint256 right, string calldata error) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertLe(uint256,uint256,string)", @@ -1437,7 +1437,7 @@ "func": { "id": "assertLe_2", "description": "Compares two `int256` values. Expects first value to be less than or equal to second.", - "declaration": "function assertLe(int256 a, int256 b) external pure;", + "declaration": "function assertLe(int256 left, int256 right) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertLe(int256,int256)", @@ -1457,7 +1457,7 @@ "func": { "id": "assertLe_3", "description": "Compares two `int256` values. Expects first value to be less than or equal to second.\nIncludes error message into revert string on failure.", - "declaration": "function assertLe(int256 a, int256 b, string calldata error) external pure;", + "declaration": "function assertLe(int256 left, int256 right, string calldata error) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertLe(int256,int256,string)", @@ -1477,7 +1477,7 @@ "func": { "id": "assertLt_0", "description": "Compares two `uint256` values. Expects first value to be less than second.", - "declaration": "function assertLt(uint256 a, uint256 b) external pure;", + "declaration": "function assertLt(uint256 left, uint256 right) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertLt(uint256,uint256)", @@ -1497,7 +1497,7 @@ "func": { "id": "assertLt_1", "description": "Compares two `uint256` values. Expects first value to be less than second.\nIncludes error message into revert string on failure.", - "declaration": "function assertLt(uint256 a, uint256 b, string calldata error) external pure;", + "declaration": "function assertLt(uint256 left, uint256 right, string calldata error) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertLt(uint256,uint256,string)", @@ -1517,7 +1517,7 @@ "func": { "id": "assertLt_2", "description": "Compares two `int256` values. Expects first value to be less than second.", - "declaration": "function assertLt(int256 a, int256 b) external pure;", + "declaration": "function assertLt(int256 left, int256 right) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertLt(int256,int256)", @@ -1537,7 +1537,7 @@ "func": { "id": "assertLt_3", "description": "Compares two `int256` values. Expects first value to be less than second.\nIncludes error message into revert string on failure.", - "declaration": "function assertLt(int256 a, int256 b, string calldata error) external pure;", + "declaration": "function assertLt(int256 left, int256 right, string calldata error) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertLt(int256,int256,string)", @@ -1557,7 +1557,7 @@ "func": { "id": "assertNotEq_0", "description": "Asserts that two `bool` values are not equal.", - "declaration": "function assertNotEq(bool a, bool b) external pure;", + "declaration": "function assertNotEq(bool left, bool right) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertNotEq(bool,bool)", @@ -1577,7 +1577,7 @@ "func": { "id": "assertNotEq_1", "description": "Asserts that two `bool` values are not equal and includes error message into revert string on failure.", - "declaration": "function assertNotEq(bool a, bool b, string calldata error) external pure;", + "declaration": "function assertNotEq(bool left, bool right, string calldata error) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertNotEq(bool,bool,string)", @@ -1597,7 +1597,7 @@ "func": { "id": "assertNotEq_10", "description": "Asserts that two `string` values are not equal.", - "declaration": "function assertNotEq(string calldata a, string calldata b) external pure;", + "declaration": "function assertNotEq(string calldata left, string calldata right) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertNotEq(string,string)", @@ -1617,7 +1617,7 @@ "func": { "id": "assertNotEq_11", "description": "Asserts that two `string` values are not equal and includes error message into revert string on failure.", - "declaration": "function assertNotEq(string calldata a, string calldata b, string calldata error) external pure;", + "declaration": "function assertNotEq(string calldata left, string calldata right, string calldata error) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertNotEq(string,string,string)", @@ -1637,7 +1637,7 @@ "func": { "id": "assertNotEq_12", "description": "Asserts that two `bytes` values are not equal.", - "declaration": "function assertNotEq(bytes calldata a, bytes calldata b) external pure;", + "declaration": "function assertNotEq(bytes calldata left, bytes calldata right) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertNotEq(bytes,bytes)", @@ -1657,7 +1657,7 @@ "func": { "id": "assertNotEq_13", "description": "Asserts that two `bytes` values are not equal and includes error message into revert string on failure.", - "declaration": "function assertNotEq(bytes calldata a, bytes calldata b, string calldata error) external pure;", + "declaration": "function assertNotEq(bytes calldata left, bytes calldata right, string calldata error) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertNotEq(bytes,bytes,string)", @@ -1677,7 +1677,7 @@ "func": { "id": "assertNotEq_14", "description": "Asserts that two arrays of `bool` values are not equal.", - "declaration": "function assertNotEq(bool[] calldata a, bool[] calldata b) external pure;", + "declaration": "function assertNotEq(bool[] calldata left, bool[] calldata right) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertNotEq(bool[],bool[])", @@ -1697,7 +1697,7 @@ "func": { "id": "assertNotEq_15", "description": "Asserts that two arrays of `bool` values are not equal and includes error message into revert string on failure.", - "declaration": "function assertNotEq(bool[] calldata a, bool[] calldata b, string calldata error) external pure;", + "declaration": "function assertNotEq(bool[] calldata left, bool[] calldata right, string calldata error) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertNotEq(bool[],bool[],string)", @@ -1717,7 +1717,7 @@ "func": { "id": "assertNotEq_16", "description": "Asserts that two arrays of `uint256` values are not equal.", - "declaration": "function assertNotEq(uint256[] calldata a, uint256[] calldata b) external pure;", + "declaration": "function assertNotEq(uint256[] calldata left, uint256[] calldata right) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertNotEq(uint256[],uint256[])", @@ -1737,7 +1737,7 @@ "func": { "id": "assertNotEq_17", "description": "Asserts that two arrays of `uint256` values are not equal and includes error message into revert string on failure.", - "declaration": "function assertNotEq(uint256[] calldata a, uint256[] calldata b, string calldata error) external pure;", + "declaration": "function assertNotEq(uint256[] calldata left, uint256[] calldata right, string calldata error) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertNotEq(uint256[],uint256[],string)", @@ -1757,7 +1757,7 @@ "func": { "id": "assertNotEq_18", "description": "Asserts that two arrays of `int256` values are not equal.", - "declaration": "function assertNotEq(int256[] calldata a, int256[] calldata b) external pure;", + "declaration": "function assertNotEq(int256[] calldata left, int256[] calldata right) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertNotEq(int256[],int256[])", @@ -1777,7 +1777,7 @@ "func": { "id": "assertNotEq_19", "description": "Asserts that two arrays of `int256` values are not equal and includes error message into revert string on failure.", - "declaration": "function assertNotEq(int256[] calldata a, int256[] calldata b, string calldata error) external pure;", + "declaration": "function assertNotEq(int256[] calldata left, int256[] calldata right, string calldata error) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertNotEq(int256[],int256[],string)", @@ -1797,7 +1797,7 @@ "func": { "id": "assertNotEq_2", "description": "Asserts that two `uint256` values are not equal.", - "declaration": "function assertNotEq(uint256 a, uint256 b) external pure;", + "declaration": "function assertNotEq(uint256 left, uint256 right) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertNotEq(uint256,uint256)", @@ -1817,7 +1817,7 @@ "func": { "id": "assertNotEq_20", "description": "Asserts that two arrays of `address` values are not equal.", - "declaration": "function assertNotEq(address[] calldata a, address[] calldata b) external pure;", + "declaration": "function assertNotEq(address[] calldata left, address[] calldata right) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertNotEq(address[],address[])", @@ -1837,7 +1837,7 @@ "func": { "id": "assertNotEq_21", "description": "Asserts that two arrays of `address` values are not equal and includes error message into revert string on failure.", - "declaration": "function assertNotEq(address[] calldata a, address[] calldata b, string calldata error) external pure;", + "declaration": "function assertNotEq(address[] calldata left, address[] calldata right, string calldata error) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertNotEq(address[],address[],string)", @@ -1857,7 +1857,7 @@ "func": { "id": "assertNotEq_22", "description": "Asserts that two arrays of `bytes32` values are not equal.", - "declaration": "function assertNotEq(bytes32[] calldata a, bytes32[] calldata b) external pure;", + "declaration": "function assertNotEq(bytes32[] calldata left, bytes32[] calldata right) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertNotEq(bytes32[],bytes32[])", @@ -1877,7 +1877,7 @@ "func": { "id": "assertNotEq_23", "description": "Asserts that two arrays of `bytes32` values are not equal and includes error message into revert string on failure.", - "declaration": "function assertNotEq(bytes32[] calldata a, bytes32[] calldata b, string calldata error) external pure;", + "declaration": "function assertNotEq(bytes32[] calldata left, bytes32[] calldata right, string calldata error) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertNotEq(bytes32[],bytes32[],string)", @@ -1897,7 +1897,7 @@ "func": { "id": "assertNotEq_24", "description": "Asserts that two arrays of `string` values are not equal.", - "declaration": "function assertNotEq(string[] calldata a, string[] calldata b) external pure;", + "declaration": "function assertNotEq(string[] calldata left, string[] calldata right) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertNotEq(string[],string[])", @@ -1917,7 +1917,7 @@ "func": { "id": "assertNotEq_25", "description": "Asserts that two arrays of `string` values are not equal and includes error message into revert string on failure.", - "declaration": "function assertNotEq(string[] calldata a, string[] calldata b, string calldata error) external pure;", + "declaration": "function assertNotEq(string[] calldata left, string[] calldata right, string calldata error) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertNotEq(string[],string[],string)", @@ -1937,7 +1937,7 @@ "func": { "id": "assertNotEq_26", "description": "Asserts that two arrays of `bytes` values are not equal.", - "declaration": "function assertNotEq(bytes[] calldata a, bytes[] calldata b) external pure;", + "declaration": "function assertNotEq(bytes[] calldata left, bytes[] calldata right) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertNotEq(bytes[],bytes[])", @@ -1957,7 +1957,7 @@ "func": { "id": "assertNotEq_27", "description": "Asserts that two arrays of `bytes` values are not equal and includes error message into revert string on failure.", - "declaration": "function assertNotEq(bytes[] calldata a, bytes[] calldata b, string calldata error) external pure;", + "declaration": "function assertNotEq(bytes[] calldata left, bytes[] calldata right, string calldata error) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertNotEq(bytes[],bytes[],string)", @@ -1977,7 +1977,7 @@ "func": { "id": "assertNotEq_3", "description": "Asserts that two `uint256` values are not equal and includes error message into revert string on failure.", - "declaration": "function assertNotEq(uint256 a, uint256 b, string calldata error) external pure;", + "declaration": "function assertNotEq(uint256 left, uint256 right, string calldata error) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertNotEq(uint256,uint256,string)", @@ -1997,7 +1997,7 @@ "func": { "id": "assertNotEq_4", "description": "Asserts that two `int256` values are not equal.", - "declaration": "function assertNotEq(int256 a, int256 b) external pure;", + "declaration": "function assertNotEq(int256 left, int256 right) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertNotEq(int256,int256)", @@ -2017,7 +2017,7 @@ "func": { "id": "assertNotEq_5", "description": "Asserts that two `int256` values are not equal and includes error message into revert string on failure.", - "declaration": "function assertNotEq(int256 a, int256 b, string calldata error) external pure;", + "declaration": "function assertNotEq(int256 left, int256 right, string calldata error) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertNotEq(int256,int256,string)", @@ -2037,7 +2037,7 @@ "func": { "id": "assertNotEq_6", "description": "Asserts that two `address` values are not equal.", - "declaration": "function assertNotEq(address a, address b) external pure;", + "declaration": "function assertNotEq(address left, address right) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertNotEq(address,address)", @@ -2057,7 +2057,7 @@ "func": { "id": "assertNotEq_7", "description": "Asserts that two `address` values are not equal and includes error message into revert string on failure.", - "declaration": "function assertNotEq(address a, address b, string calldata error) external pure;", + "declaration": "function assertNotEq(address left, address right, string calldata error) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertNotEq(address,address,string)", @@ -2077,7 +2077,7 @@ "func": { "id": "assertNotEq_8", "description": "Asserts that two `bytes32` values are not equal.", - "declaration": "function assertNotEq(bytes32 a, bytes32 b) external pure;", + "declaration": "function assertNotEq(bytes32 left, bytes32 right) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertNotEq(bytes32,bytes32)", @@ -2097,7 +2097,7 @@ "func": { "id": "assertNotEq_9", "description": "Asserts that two `bytes32` values are not equal and includes error message into revert string on failure.", - "declaration": "function assertNotEq(bytes32 a, bytes32 b, string calldata error) external pure;", + "declaration": "function assertNotEq(bytes32 left, bytes32 right, string calldata error) external pure;", "visibility": "external", "mutability": "pure", "signature": "assertNotEq(bytes32,bytes32,string)", diff --git a/crates/cheatcodes/spec/src/vm.rs b/crates/cheatcodes/spec/src/vm.rs index 9850ef01baaa..94c870b01b75 100644 --- a/crates/cheatcodes/spec/src/vm.rs +++ b/crates/cheatcodes/spec/src/vm.rs @@ -729,317 +729,317 @@ interface Vm { /// Asserts that two `bool` values are equal. #[cheatcode(group = Testing, safety = Safe)] - function assertEq(bool a, bool b) external pure; + function assertEq(bool left, bool right) external pure; /// Asserts that two `bool` values are equal and includes error message into revert string on failure. #[cheatcode(group = Testing, safety = Safe)] - function assertEq(bool a, bool b, string calldata error) external pure; + function assertEq(bool left, bool right, string calldata error) external pure; /// Asserts that two `uint256` values are equal. #[cheatcode(group = Testing, safety = Safe)] - function assertEq(uint256 a, uint256 b) external pure; + function assertEq(uint256 left, uint256 right) external pure; /// Asserts that two `uint256` values are equal and includes error message into revert string on failure. #[cheatcode(group = Testing, safety = Safe)] - function assertEq(uint256 a, uint256 b, string calldata error) external pure; + function assertEq(uint256 left, uint256 right, string calldata error) external pure; /// Asserts that two `int256` values are equal. #[cheatcode(group = Testing, safety = Safe)] - function assertEq(int256 a, int256 b) external pure; + function assertEq(int256 left, int256 right) external pure; /// Asserts that two `int256` values are equal and includes error message into revert string on failure. #[cheatcode(group = Testing, safety = Safe)] - function assertEq(int256 a, int256 b, string calldata error) external pure; + function assertEq(int256 left, int256 right, string calldata error) external pure; /// Asserts that two `address` values are equal. #[cheatcode(group = Testing, safety = Safe)] - function assertEq(address a, address b) external pure; + function assertEq(address left, address right) external pure; /// Asserts that two `address` values are equal and includes error message into revert string on failure. #[cheatcode(group = Testing, safety = Safe)] - function assertEq(address a, address b, string calldata error) external pure; + function assertEq(address left, address right, string calldata error) external pure; /// Asserts that two `bytes32` values are equal. #[cheatcode(group = Testing, safety = Safe)] - function assertEq(bytes32 a, bytes32 b) external pure; + function assertEq(bytes32 left, bytes32 right) external pure; /// Asserts that two `bytes32` values are equal and includes error message into revert string on failure. #[cheatcode(group = Testing, safety = Safe)] - function assertEq(bytes32 a, bytes32 b, string calldata error) external pure; + function assertEq(bytes32 left, bytes32 right, string calldata error) external pure; /// Asserts that two `string` values are equal. #[cheatcode(group = Testing, safety = Safe)] - function assertEq(string calldata a, string calldata b) external pure; + function assertEq(string calldata left, string calldata right) external pure; /// Asserts that two `string` values are equal and includes error message into revert string on failure. #[cheatcode(group = Testing, safety = Safe)] - function assertEq(string calldata a, string calldata b, string calldata error) external pure; + function assertEq(string calldata left, string calldata right, string calldata error) external pure; /// Asserts that two `bytes` values are equal. #[cheatcode(group = Testing, safety = Safe)] - function assertEq(bytes calldata a, bytes calldata b) external pure; + function assertEq(bytes calldata left, bytes calldata right) external pure; /// Asserts that two `bytes` values are equal and includes error message into revert string on failure. #[cheatcode(group = Testing, safety = Safe)] - function assertEq(bytes calldata a, bytes calldata b, string calldata error) external pure; + function assertEq(bytes calldata left, bytes calldata right, string calldata error) external pure; /// Asserts that two arrays of `bool` values are equal. #[cheatcode(group = Testing, safety = Safe)] - function assertEq(bool[] calldata a, bool[] calldata b) external pure; + function assertEq(bool[] calldata left, bool[] calldata right) external pure; /// Asserts that two arrays of `bool` values are equal and includes error message into revert string on failure. #[cheatcode(group = Testing, safety = Safe)] - function assertEq(bool[] calldata a, bool[] calldata b, string calldata error) external pure; + function assertEq(bool[] calldata left, bool[] calldata right, string calldata error) external pure; /// Asserts that two arrays of `uint256 values are equal. #[cheatcode(group = Testing, safety = Safe)] - function assertEq(uint256[] calldata a, uint256[] calldata b) external pure; + function assertEq(uint256[] calldata left, uint256[] calldata right) external pure; /// Asserts that two arrays of `uint256` values are equal and includes error message into revert string on failure. #[cheatcode(group = Testing, safety = Safe)] - function assertEq(uint256[] calldata a, uint256[] calldata b, string calldata error) external pure; + function assertEq(uint256[] calldata left, uint256[] calldata right, string calldata error) external pure; /// Asserts that two arrays of `int256` values are equal. #[cheatcode(group = Testing, safety = Safe)] - function assertEq(int256[] calldata a, int256[] calldata b) external pure; + function assertEq(int256[] calldata left, int256[] calldata right) external pure; /// Asserts that two arrays of `int256` values are equal and includes error message into revert string on failure. #[cheatcode(group = Testing, safety = Safe)] - function assertEq(int256[] calldata a, int256[] calldata b, string calldata error) external pure; + function assertEq(int256[] calldata left, int256[] calldata right, string calldata error) external pure; /// Asserts that two arrays of `address` values are equal. #[cheatcode(group = Testing, safety = Safe)] - function assertEq(address[] calldata a, address[] calldata b) external pure; + function assertEq(address[] calldata left, address[] calldata right) external pure; /// Asserts that two arrays of `address` values are equal and includes error message into revert string on failure. #[cheatcode(group = Testing, safety = Safe)] - function assertEq(address[] calldata a, address[] calldata b, string calldata error) external pure; + function assertEq(address[] calldata left, address[] calldata right, string calldata error) external pure; /// Asserts that two arrays of `bytes32` values are equal. #[cheatcode(group = Testing, safety = Safe)] - function assertEq(bytes32[] calldata a, bytes32[] calldata b) external pure; + function assertEq(bytes32[] calldata left, bytes32[] calldata right) external pure; /// Asserts that two arrays of `bytes32` values are equal and includes error message into revert string on failure. #[cheatcode(group = Testing, safety = Safe)] - function assertEq(bytes32[] calldata a, bytes32[] calldata b, string calldata error) external pure; + function assertEq(bytes32[] calldata left, bytes32[] calldata right, string calldata error) external pure; /// Asserts that two arrays of `string` values are equal. #[cheatcode(group = Testing, safety = Safe)] - function assertEq(string[] calldata a, string[] calldata b) external pure; + function assertEq(string[] calldata left, string[] calldata right) external pure; /// Asserts that two arrays of `string` values are equal and includes error message into revert string on failure. #[cheatcode(group = Testing, safety = Safe)] - function assertEq(string[] calldata a, string[] calldata b, string calldata error) external pure; + function assertEq(string[] calldata left, string[] calldata right, string calldata error) external pure; /// Asserts that two arrays of `bytes` values are equal. #[cheatcode(group = Testing, safety = Safe)] - function assertEq(bytes[] calldata a, bytes[] calldata b) external pure; + function assertEq(bytes[] calldata left, bytes[] calldata right) external pure; /// Asserts that two arrays of `bytes` values are equal and includes error message into revert string on failure. #[cheatcode(group = Testing, safety = Safe)] - function assertEq(bytes[] calldata a, bytes[] calldata b, string calldata error) external pure; + function assertEq(bytes[] calldata left, bytes[] calldata right, string calldata error) external pure; /// Asserts that two `bool` values are not equal. #[cheatcode(group = Testing, safety = Safe)] - function assertNotEq(bool a, bool b) external pure; + function assertNotEq(bool left, bool right) external pure; /// Asserts that two `bool` values are not equal and includes error message into revert string on failure. #[cheatcode(group = Testing, safety = Safe)] - function assertNotEq(bool a, bool b, string calldata error) external pure; + function assertNotEq(bool left, bool right, string calldata error) external pure; /// Asserts that two `uint256` values are not equal. #[cheatcode(group = Testing, safety = Safe)] - function assertNotEq(uint256 a, uint256 b) external pure; + function assertNotEq(uint256 left, uint256 right) external pure; /// Asserts that two `uint256` values are not equal and includes error message into revert string on failure. #[cheatcode(group = Testing, safety = Safe)] - function assertNotEq(uint256 a, uint256 b, string calldata error) external pure; + function assertNotEq(uint256 left, uint256 right, string calldata error) external pure; /// Asserts that two `int256` values are not equal. #[cheatcode(group = Testing, safety = Safe)] - function assertNotEq(int256 a, int256 b) external pure; + function assertNotEq(int256 left, int256 right) external pure; /// Asserts that two `int256` values are not equal and includes error message into revert string on failure. #[cheatcode(group = Testing, safety = Safe)] - function assertNotEq(int256 a, int256 b, string calldata error) external pure; + function assertNotEq(int256 left, int256 right, string calldata error) external pure; /// Asserts that two `address` values are not equal. #[cheatcode(group = Testing, safety = Safe)] - function assertNotEq(address a, address b) external pure; + function assertNotEq(address left, address right) external pure; /// Asserts that two `address` values are not equal and includes error message into revert string on failure. #[cheatcode(group = Testing, safety = Safe)] - function assertNotEq(address a, address b, string calldata error) external pure; + function assertNotEq(address left, address right, string calldata error) external pure; /// Asserts that two `bytes32` values are not equal. #[cheatcode(group = Testing, safety = Safe)] - function assertNotEq(bytes32 a, bytes32 b) external pure; + function assertNotEq(bytes32 left, bytes32 right) external pure; /// Asserts that two `bytes32` values are not equal and includes error message into revert string on failure. #[cheatcode(group = Testing, safety = Safe)] - function assertNotEq(bytes32 a, bytes32 b, string calldata error) external pure; + function assertNotEq(bytes32 left, bytes32 right, string calldata error) external pure; /// Asserts that two `string` values are not equal. #[cheatcode(group = Testing, safety = Safe)] - function assertNotEq(string calldata a, string calldata b) external pure; + function assertNotEq(string calldata left, string calldata right) external pure; /// Asserts that two `string` values are not equal and includes error message into revert string on failure. #[cheatcode(group = Testing, safety = Safe)] - function assertNotEq(string calldata a, string calldata b, string calldata error) external pure; + function assertNotEq(string calldata left, string calldata right, string calldata error) external pure; /// Asserts that two `bytes` values are not equal. #[cheatcode(group = Testing, safety = Safe)] - function assertNotEq(bytes calldata a, bytes calldata b) external pure; + function assertNotEq(bytes calldata left, bytes calldata right) external pure; /// Asserts that two `bytes` values are not equal and includes error message into revert string on failure. #[cheatcode(group = Testing, safety = Safe)] - function assertNotEq(bytes calldata a, bytes calldata b, string calldata error) external pure; + function assertNotEq(bytes calldata left, bytes calldata right, string calldata error) external pure; /// Asserts that two arrays of `bool` values are not equal. #[cheatcode(group = Testing, safety = Safe)] - function assertNotEq(bool[] calldata a, bool[] calldata b) external pure; + function assertNotEq(bool[] calldata left, bool[] calldata right) external pure; /// Asserts that two arrays of `bool` values are not equal and includes error message into revert string on failure. #[cheatcode(group = Testing, safety = Safe)] - function assertNotEq(bool[] calldata a, bool[] calldata b, string calldata error) external pure; + function assertNotEq(bool[] calldata left, bool[] calldata right, string calldata error) external pure; /// Asserts that two arrays of `uint256` values are not equal. #[cheatcode(group = Testing, safety = Safe)] - function assertNotEq(uint256[] calldata a, uint256[] calldata b) external pure; + function assertNotEq(uint256[] calldata left, uint256[] calldata right) external pure; /// Asserts that two arrays of `uint256` values are not equal and includes error message into revert string on failure. #[cheatcode(group = Testing, safety = Safe)] - function assertNotEq(uint256[] calldata a, uint256[] calldata b, string calldata error) external pure; + function assertNotEq(uint256[] calldata left, uint256[] calldata right, string calldata error) external pure; /// Asserts that two arrays of `int256` values are not equal. #[cheatcode(group = Testing, safety = Safe)] - function assertNotEq(int256[] calldata a, int256[] calldata b) external pure; + function assertNotEq(int256[] calldata left, int256[] calldata right) external pure; /// Asserts that two arrays of `int256` values are not equal and includes error message into revert string on failure. #[cheatcode(group = Testing, safety = Safe)] - function assertNotEq(int256[] calldata a, int256[] calldata b, string calldata error) external pure; + function assertNotEq(int256[] calldata left, int256[] calldata right, string calldata error) external pure; /// Asserts that two arrays of `address` values are not equal. #[cheatcode(group = Testing, safety = Safe)] - function assertNotEq(address[] calldata a, address[] calldata b) external pure; + function assertNotEq(address[] calldata left, address[] calldata right) external pure; /// Asserts that two arrays of `address` values are not equal and includes error message into revert string on failure. #[cheatcode(group = Testing, safety = Safe)] - function assertNotEq(address[] calldata a, address[] calldata b, string calldata error) external pure; + function assertNotEq(address[] calldata left, address[] calldata right, string calldata error) external pure; /// Asserts that two arrays of `bytes32` values are not equal. #[cheatcode(group = Testing, safety = Safe)] - function assertNotEq(bytes32[] calldata a, bytes32[] calldata b) external pure; + function assertNotEq(bytes32[] calldata left, bytes32[] calldata right) external pure; /// Asserts that two arrays of `bytes32` values are not equal and includes error message into revert string on failure. #[cheatcode(group = Testing, safety = Safe)] - function assertNotEq(bytes32[] calldata a, bytes32[] calldata b, string calldata error) external pure; + function assertNotEq(bytes32[] calldata left, bytes32[] calldata right, string calldata error) external pure; /// Asserts that two arrays of `string` values are not equal. #[cheatcode(group = Testing, safety = Safe)] - function assertNotEq(string[] calldata a, string[] calldata b) external pure; + function assertNotEq(string[] calldata left, string[] calldata right) external pure; /// Asserts that two arrays of `string` values are not equal and includes error message into revert string on failure. #[cheatcode(group = Testing, safety = Safe)] - function assertNotEq(string[] calldata a, string[] calldata b, string calldata error) external pure; + function assertNotEq(string[] calldata left, string[] calldata right, string calldata error) external pure; /// Asserts that two arrays of `bytes` values are not equal. #[cheatcode(group = Testing, safety = Safe)] - function assertNotEq(bytes[] calldata a, bytes[] calldata b) external pure; + function assertNotEq(bytes[] calldata left, bytes[] calldata right) external pure; /// Asserts that two arrays of `bytes` values are not equal and includes error message into revert string on failure. #[cheatcode(group = Testing, safety = Safe)] - function assertNotEq(bytes[] calldata a, bytes[] calldata b, string calldata error) external pure; + function assertNotEq(bytes[] calldata left, bytes[] calldata right, string calldata error) external pure; /// Compares two `uint256` values. Expects first value to be greater than second. #[cheatcode(group = Testing, safety = Safe)] - function assertGt(uint256 a, uint256 b) external pure; + function assertGt(uint256 left, uint256 right) external pure; /// Compares two `uint256` values. Expects first value to be greater than second. /// Includes error message into revert string on failure. #[cheatcode(group = Testing, safety = Safe)] - function assertGt(uint256 a, uint256 b, string calldata error) external pure; + function assertGt(uint256 left, uint256 right, string calldata error) external pure; /// Compares two `int256` values. Expects first value to be greater than second. #[cheatcode(group = Testing, safety = Safe)] - function assertGt(int256 a, int256 b) external pure; + function assertGt(int256 left, int256 right) external pure; /// Compares two `int256` values. Expects first value to be greater than second. /// Includes error message into revert string on failure. #[cheatcode(group = Testing, safety = Safe)] - function assertGt(int256 a, int256 b, string calldata error) external pure; + function assertGt(int256 left, int256 right, string calldata error) external pure; /// Compares two `uint256` values. Expects first value to be greater than or equal to second. #[cheatcode(group = Testing, safety = Safe)] - function assertGe(uint256 a, uint256 b) external pure; + function assertGe(uint256 left, uint256 right) external pure; /// Compares two `uint256` values. Expects first value to be greater than or equal to second. /// Includes error message into revert string on failure. #[cheatcode(group = Testing, safety = Safe)] - function assertGe(uint256 a, uint256 b, string calldata error) external pure; + function assertGe(uint256 left, uint256 right, string calldata error) external pure; /// Compares two `int256` values. Expects first value to be greater than or equal to second. #[cheatcode(group = Testing, safety = Safe)] - function assertGe(int256 a, int256 b) external pure; + function assertGe(int256 left, int256 right) external pure; /// Compares two `int256` values. Expects first value to be greater than or equal to second. /// Includes error message into revert string on failure. #[cheatcode(group = Testing, safety = Safe)] - function assertGe(int256 a, int256 b, string calldata error) external pure; + function assertGe(int256 left, int256 right, string calldata error) external pure; /// Compares two `uint256` values. Expects first value to be less than second. #[cheatcode(group = Testing, safety = Safe)] - function assertLt(uint256 a, uint256 b) external pure; + function assertLt(uint256 left, uint256 right) external pure; /// Compares two `uint256` values. Expects first value to be less than second. /// Includes error message into revert string on failure. #[cheatcode(group = Testing, safety = Safe)] - function assertLt(uint256 a, uint256 b, string calldata error) external pure; + function assertLt(uint256 left, uint256 right, string calldata error) external pure; /// Compares two `int256` values. Expects first value to be less than second. #[cheatcode(group = Testing, safety = Safe)] - function assertLt(int256 a, int256 b) external pure; + function assertLt(int256 left, int256 right) external pure; /// Compares two `int256` values. Expects first value to be less than second. /// Includes error message into revert string on failure. #[cheatcode(group = Testing, safety = Safe)] - function assertLt(int256 a, int256 b, string calldata error) external pure; + function assertLt(int256 left, int256 right, string calldata error) external pure; /// Compares two `uint256` values. Expects first value to be less than or equal to second. #[cheatcode(group = Testing, safety = Safe)] - function assertLe(uint256 a, uint256 b) external pure; + function assertLe(uint256 left, uint256 right) external pure; /// Compares two `uint256` values. Expects first value to be less than or equal to second. /// Includes error message into revert string on failure. #[cheatcode(group = Testing, safety = Safe)] - function assertLe(uint256 a, uint256 b, string calldata error) external pure; + function assertLe(uint256 left, uint256 right, string calldata error) external pure; /// Compares two `int256` values. Expects first value to be less than or equal to second. #[cheatcode(group = Testing, safety = Safe)] - function assertLe(int256 a, int256 b) external pure; + function assertLe(int256 left, int256 right) external pure; /// Compares two `int256` values. Expects first value to be less than or equal to second. /// Includes error message into revert string on failure. #[cheatcode(group = Testing, safety = Safe)] - function assertLe(int256 a, int256 b, string calldata error) external pure; + function assertLe(int256 left, int256 right, string calldata error) external pure; /// Compares two `uint256` values. Expects difference to be less than or equal to `maxDelta`. #[cheatcode(group = Testing, safety = Safe)] - function assertApproxEqAbs(uint256 a, uint256 b, uint256 maxDelta) external pure; + function assertApproxEqAbs(uint256 left, uint256 right, uint256 maxDelta) external pure; /// Compares two `uint256` values. Expects difference to be less than or equal to `maxDelta`. /// Includes error message into revert string on failure. #[cheatcode(group = Testing, safety = Safe)] - function assertApproxEqAbs(uint256 a, uint256 b, uint256 maxDelta, string calldata error) external pure; + function assertApproxEqAbs(uint256 left, uint256 right, uint256 maxDelta, string calldata error) external pure; /// Compares two `int256` values. Expects difference to be less than or equal to `maxDelta`. #[cheatcode(group = Testing, safety = Safe)] - function assertApproxEqAbs(int256 a, int256 b, uint256 maxDelta) external pure; + function assertApproxEqAbs(int256 left, int256 right, uint256 maxDelta) external pure; /// Compares two `int256` values. Expects difference to be less than or equal to `maxDelta`. /// Includes error message into revert string on failure. #[cheatcode(group = Testing, safety = Safe)] - function assertApproxEqAbs(int256 a, int256 b, uint256 maxDelta, string calldata error) external pure; + function assertApproxEqAbs(int256 left, int256 right, uint256 maxDelta, string calldata error) external pure; // ======== OS and Filesystem ======== diff --git a/crates/cheatcodes/src/test/assert.rs b/crates/cheatcodes/src/test/assert.rs index befc063e7922..37470ceebc46 100644 --- a/crates/cheatcodes/src/test/assert.rs +++ b/crates/cheatcodes/src/test/assert.rs @@ -21,38 +21,38 @@ enum ComparisonAssertionError<'a, T> { #[derive(thiserror::Error, Debug)] enum ApproxAssertionError { - #[error("{a} !~= {b} (max delta: {expected_delta}, real delta: {delta})")] - EqAbs { a: T, b: T, expected_delta: D, delta: D }, + #[error("{left} !~= {right} (max deltleft: {expected_delta}, real deltleft: {delta})")] + EqAbs { left: T, right: T, expected_delta: D, delta: D }, } impl<'a, T: Display> ComparisonAssertionError<'a, T> { fn format_for_values(&self) -> String { match self { - Self::NotEq(a, b) => format!("{} == {}", a, b), - Self::Eq(a, b) => format!("{} != {}", a, b), - Self::Ge(a, b) => format!("{} < {}", a, b), - Self::Gt(a, b) => format!("{} <= {}", a, b), - Self::Le(a, b) => format!("{} > {}", a, b), - Self::Lt(a, b) => format!("{} >= {}", a, b), + Self::NotEq(left, right) => format!("{} == {}", left, right), + Self::Eq(left, right) => format!("{} != {}", left, right), + Self::Ge(left, right) => format!("{} < {}", left, right), + Self::Gt(left, right) => format!("{} <= {}", left, right), + Self::Le(left, right) => format!("{} > {}", left, right), + Self::Lt(left, right) => format!("{} >= {}", left, right), } } } macro_rules! format_arrays { - ($a:expr, $b:expr, $c:literal) => { - format!("[{}] {} [{}]", $a.iter().join(", "), $c, $b.iter().join(", ")) + ($left:expr, $right:expr, $c:literal) => { + format!("[{}] {} [{}]", $left.iter().join(", "), $c, $right.iter().join(", ")) }; } impl<'a, T: Display> ComparisonAssertionError<'a, Vec> { fn format_for_arrays(&self) -> String { match self { - Self::NotEq(a, b) => format_arrays!(a, b, "=="), - Self::Eq(a, b) => format_arrays!(a, b, "!="), - Self::Ge(a, b) => format_arrays!(a, b, "<"), - Self::Gt(a, b) => format_arrays!(a, b, "<="), - Self::Le(a, b) => format_arrays!(a, b, ">"), - Self::Lt(a, b) => format_arrays!(a, b, ">="), + Self::NotEq(left, right) => format_arrays!(left, right, "=="), + Self::Eq(left, right) => format_arrays!(left, right, "!="), + Self::Ge(left, right) => format_arrays!(left, right, "<"), + Self::Gt(left, right) => format_arrays!(left, right, "<="), + Self::Le(left, right) => format_arrays!(left, right, ">"), + Self::Lt(left, right) => format_arrays!(left, right, ">="), } } } @@ -85,559 +85,592 @@ impl Cheatcode for assertFalse_1Call { impl Cheatcode for assertEq_0Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b } = self; - Ok(assert_eq(a, b).map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) + let Self { left, right } = self; + Ok(assert_eq(left, right) + .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) } } impl Cheatcode for assertEq_1Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b, error } = self; - Ok(assert_eq(a, b).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) + let Self { left, right, error } = self; + Ok(assert_eq(left, right).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) } } impl Cheatcode for assertEq_2Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b } = self; - Ok(assert_eq(a, b).map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) + let Self { left, right } = self; + Ok(assert_eq(left, right) + .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) } } impl Cheatcode for assertEq_3Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b, error } = self; - Ok(assert_eq(a, b).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) + let Self { left, right, error } = self; + Ok(assert_eq(left, right).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) } } impl Cheatcode for assertEq_4Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b } = self; - Ok(assert_eq(a, b).map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) + let Self { left, right } = self; + Ok(assert_eq(left, right) + .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) } } impl Cheatcode for assertEq_5Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b, error } = self; - Ok(assert_eq(a, b).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) + let Self { left, right, error } = self; + Ok(assert_eq(left, right).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) } } impl Cheatcode for assertEq_6Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b } = self; - Ok(assert_eq(a, b).map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) + let Self { left, right } = self; + Ok(assert_eq(left, right) + .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) } } impl Cheatcode for assertEq_7Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b, error } = self; - Ok(assert_eq(a, b).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) + let Self { left, right, error } = self; + Ok(assert_eq(left, right).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) } } impl Cheatcode for assertEq_8Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b } = self; - Ok(assert_eq(a, b).map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) + let Self { left, right } = self; + Ok(assert_eq(left, right) + .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) } } impl Cheatcode for assertEq_9Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b, error } = self; - Ok(assert_eq(a, b).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) + let Self { left, right, error } = self; + Ok(assert_eq(left, right).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) } } impl Cheatcode for assertEq_10Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b } = self; - Ok(assert_eq(&hex::encode_prefixed(a), &hex::encode_prefixed(b)) + let Self { left, right } = self; + Ok(assert_eq(&hex::encode_prefixed(left), &hex::encode_prefixed(right)) .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) } } impl Cheatcode for assertEq_11Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b, error } = self; - Ok(assert_eq(&hex::encode_prefixed(a), &hex::encode_prefixed(b)) + let Self { left, right, error } = self; + Ok(assert_eq(&hex::encode_prefixed(left), &hex::encode_prefixed(right)) .map_err(|e| format!("{}: {}", error, e.format_for_values()))?) } } impl Cheatcode for assertEq_12Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b } = self; - Ok(assert_eq(&hex::encode_prefixed(a), &hex::encode_prefixed(b)) + let Self { left, right } = self; + Ok(assert_eq(&hex::encode_prefixed(left), &hex::encode_prefixed(right)) .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) } } impl Cheatcode for assertEq_13Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b, error } = self; - Ok(assert_eq(&hex::encode_prefixed(a), &hex::encode_prefixed(b)) + let Self { left, right, error } = self; + Ok(assert_eq(&hex::encode_prefixed(left), &hex::encode_prefixed(right)) .map_err(|e| format!("{}: {}", error, e.format_for_values()))?) } } impl Cheatcode for assertEq_14Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b } = self; - Ok(assert_eq(a, b).map_err(|e| format!("Assertion failed: {}", e.format_for_arrays()))?) + let Self { left, right } = self; + Ok(assert_eq(left, right) + .map_err(|e| format!("Assertion failed: {}", e.format_for_arrays()))?) } } impl Cheatcode for assertEq_15Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b, error } = self; - Ok(assert_eq(a, b).map_err(|e| format!("{}: {}", error, e.format_for_arrays()))?) + let Self { left, right, error } = self; + Ok(assert_eq(left, right).map_err(|e| format!("{}: {}", error, e.format_for_arrays()))?) } } impl Cheatcode for assertEq_16Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b } = self; - Ok(assert_eq(a, b).map_err(|e| format!("Assertion failed: {}", e.format_for_arrays()))?) + let Self { left, right } = self; + Ok(assert_eq(left, right) + .map_err(|e| format!("Assertion failed: {}", e.format_for_arrays()))?) } } impl Cheatcode for assertEq_17Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b, error } = self; - Ok(assert_eq(a, b).map_err(|e| format!("{}: {}", error, e.format_for_arrays()))?) + let Self { left, right, error } = self; + Ok(assert_eq(left, right).map_err(|e| format!("{}: {}", error, e.format_for_arrays()))?) } } impl Cheatcode for assertEq_18Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b } = self; - Ok(assert_eq(a, b).map_err(|e| format!("Assertion failed: {}", e.format_for_arrays()))?) + let Self { left, right } = self; + Ok(assert_eq(left, right) + .map_err(|e| format!("Assertion failed: {}", e.format_for_arrays()))?) } } impl Cheatcode for assertEq_19Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b, error } = self; - Ok(assert_eq(a, b).map_err(|e| format!("{}: {}", error, e.format_for_arrays()))?) + let Self { left, right, error } = self; + Ok(assert_eq(left, right).map_err(|e| format!("{}: {}", error, e.format_for_arrays()))?) } } impl Cheatcode for assertEq_20Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b } = self; - Ok(assert_eq(a, b).map_err(|e| format!("Assertion failed: {}", e.format_for_arrays()))?) + let Self { left, right } = self; + Ok(assert_eq(left, right) + .map_err(|e| format!("Assertion failed: {}", e.format_for_arrays()))?) } } impl Cheatcode for assertEq_21Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b, error } = self; - Ok(assert_eq(a, b).map_err(|e| format!("{}: {}", error, e.format_for_arrays()))?) + let Self { left, right, error } = self; + Ok(assert_eq(left, right).map_err(|e| format!("{}: {}", error, e.format_for_arrays()))?) } } impl Cheatcode for assertEq_22Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b } = self; - Ok(assert_eq(a, b).map_err(|e| format!("Assertion failed: {}", e.format_for_arrays()))?) + let Self { left, right } = self; + Ok(assert_eq(left, right) + .map_err(|e| format!("Assertion failed: {}", e.format_for_arrays()))?) } } impl Cheatcode for assertEq_23Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b, error } = self; - Ok(assert_eq(a, b).map_err(|e| format!("{}: {}", error, e.format_for_arrays()))?) + let Self { left, right, error } = self; + Ok(assert_eq(left, right).map_err(|e| format!("{}: {}", error, e.format_for_arrays()))?) } } impl Cheatcode for assertEq_24Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b } = self; - Ok(assert_eq(a, b).map_err(|e| format!("Assertion failed: {}", e.format_for_arrays()))?) + let Self { left, right } = self; + Ok(assert_eq(left, right) + .map_err(|e| format!("Assertion failed: {}", e.format_for_arrays()))?) } } impl Cheatcode for assertEq_25Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b, error } = self; - Ok(assert_eq(a, b).map_err(|e| format!("{}: {}", error, e.format_for_arrays()))?) + let Self { left, right, error } = self; + Ok(assert_eq(left, right).map_err(|e| format!("{}: {}", error, e.format_for_arrays()))?) } } impl Cheatcode for assertEq_26Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b } = self; - let a = a.iter().map(hex::encode_prefixed).collect::>(); - let b = b.iter().map(hex::encode_prefixed).collect::>(); - Ok(assert_eq(&a, &b).map_err(|e| format!("Assertion failed: {}", e.format_for_arrays()))?) + let Self { left, right } = self; + let left = left.iter().map(hex::encode_prefixed).collect::>(); + let right = right.iter().map(hex::encode_prefixed).collect::>(); + Ok(assert_eq(&left, &right) + .map_err(|e| format!("Assertion failed: {}", e.format_for_arrays()))?) } } impl Cheatcode for assertEq_27Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b, error } = self; - let a = a.iter().map(hex::encode_prefixed).collect::>(); - let b = b.iter().map(hex::encode_prefixed).collect::>(); - Ok(assert_eq(&a, &b).map_err(|e| format!("{}: {}", error, e.format_for_arrays()))?) + let Self { left, right, error } = self; + let left = left.iter().map(hex::encode_prefixed).collect::>(); + let right = right.iter().map(hex::encode_prefixed).collect::>(); + Ok(assert_eq(&left, &right).map_err(|e| format!("{}: {}", error, e.format_for_arrays()))?) } } impl Cheatcode for assertNotEq_0Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b } = self; - Ok(assert_not_eq(a, b) + let Self { left, right } = self; + Ok(assert_not_eq(left, right) .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) } } impl Cheatcode for assertNotEq_1Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b, error } = self; - Ok(assert_not_eq(a, b).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) + let Self { left, right, error } = self; + Ok(assert_not_eq(left, right) + .map_err(|e| format!("{}: {}", error, e.format_for_values()))?) } } impl Cheatcode for assertNotEq_2Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b } = self; - Ok(assert_not_eq(a, b) + let Self { left, right } = self; + Ok(assert_not_eq(left, right) .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) } } impl Cheatcode for assertNotEq_3Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b, error } = self; - Ok(assert_not_eq(a, b).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) + let Self { left, right, error } = self; + Ok(assert_not_eq(left, right) + .map_err(|e| format!("{}: {}", error, e.format_for_values()))?) } } impl Cheatcode for assertNotEq_4Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b } = self; - Ok(assert_not_eq(a, b) + let Self { left, right } = self; + Ok(assert_not_eq(left, right) .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) } } impl Cheatcode for assertNotEq_5Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b, error } = self; - Ok(assert_not_eq(a, b).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) + let Self { left, right, error } = self; + Ok(assert_not_eq(left, right) + .map_err(|e| format!("{}: {}", error, e.format_for_values()))?) } } impl Cheatcode for assertNotEq_6Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b } = self; - Ok(assert_not_eq(a, b) + let Self { left, right } = self; + Ok(assert_not_eq(left, right) .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) } } impl Cheatcode for assertNotEq_7Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b, error } = self; - Ok(assert_not_eq(a, b).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) + let Self { left, right, error } = self; + Ok(assert_not_eq(left, right) + .map_err(|e| format!("{}: {}", error, e.format_for_values()))?) } } impl Cheatcode for assertNotEq_8Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b } = self; - Ok(assert_not_eq(a, b) + let Self { left, right } = self; + Ok(assert_not_eq(left, right) .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) } } impl Cheatcode for assertNotEq_9Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b, error } = self; - Ok(assert_not_eq(a, b).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) + let Self { left, right, error } = self; + Ok(assert_not_eq(left, right) + .map_err(|e| format!("{}: {}", error, e.format_for_values()))?) } } impl Cheatcode for assertNotEq_10Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b } = self; - Ok(assert_not_eq(a, b) + let Self { left, right } = self; + Ok(assert_not_eq(left, right) .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) } } impl Cheatcode for assertNotEq_11Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b, error } = self; - Ok(assert_not_eq(a, b).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) + let Self { left, right, error } = self; + Ok(assert_not_eq(left, right) + .map_err(|e| format!("{}: {}", error, e.format_for_values()))?) } } impl Cheatcode for assertNotEq_12Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b } = self; - Ok(assert_not_eq(&hex::encode_prefixed(a), &hex::encode_prefixed(b)) + let Self { left, right } = self; + Ok(assert_not_eq(&hex::encode_prefixed(left), &hex::encode_prefixed(right)) .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) } } impl Cheatcode for assertNotEq_13Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b, error } = self; - Ok(assert_not_eq(&hex::encode_prefixed(a), &hex::encode_prefixed(b)) + let Self { left, right, error } = self; + Ok(assert_not_eq(&hex::encode_prefixed(left), &hex::encode_prefixed(right)) .map_err(|e| format!("{}: {}", error, e.format_for_values()))?) } } impl Cheatcode for assertNotEq_14Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b } = self; - Ok(assert_not_eq(a, b) + let Self { left, right } = self; + Ok(assert_not_eq(left, right) .map_err(|e| format!("Assertion failed: {}", e.format_for_arrays()))?) } } impl Cheatcode for assertNotEq_15Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b, error } = self; - Ok(assert_not_eq(a, b).map_err(|e| format!("{}: {}", error, e.format_for_arrays()))?) + let Self { left, right, error } = self; + Ok(assert_not_eq(left, right) + .map_err(|e| format!("{}: {}", error, e.format_for_arrays()))?) } } impl Cheatcode for assertNotEq_16Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b } = self; - Ok(assert_not_eq(a, b) + let Self { left, right } = self; + Ok(assert_not_eq(left, right) .map_err(|e| format!("Assertion failed: {}", e.format_for_arrays()))?) } } impl Cheatcode for assertNotEq_17Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b, error } = self; - Ok(assert_not_eq(a, b).map_err(|e| format!("{}: {}", error, e.format_for_arrays()))?) + let Self { left, right, error } = self; + Ok(assert_not_eq(left, right) + .map_err(|e| format!("{}: {}", error, e.format_for_arrays()))?) } } impl Cheatcode for assertNotEq_18Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b } = self; - Ok(assert_not_eq(a, b) + let Self { left, right } = self; + Ok(assert_not_eq(left, right) .map_err(|e| format!("Assertion failed: {}", e.format_for_arrays()))?) } } impl Cheatcode for assertNotEq_19Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b, error } = self; - Ok(assert_not_eq(a, b).map_err(|e| format!("{}: {}", error, e.format_for_arrays()))?) + let Self { left, right, error } = self; + Ok(assert_not_eq(left, right) + .map_err(|e| format!("{}: {}", error, e.format_for_arrays()))?) } } impl Cheatcode for assertNotEq_20Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b } = self; - Ok(assert_not_eq(a, b) + let Self { left, right } = self; + Ok(assert_not_eq(left, right) .map_err(|e| format!("Assertion failed: {}", e.format_for_arrays()))?) } } impl Cheatcode for assertNotEq_21Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b, error } = self; - Ok(assert_not_eq(a, b).map_err(|e| format!("{}: {}", error, e.format_for_arrays()))?) + let Self { left, right, error } = self; + Ok(assert_not_eq(left, right) + .map_err(|e| format!("{}: {}", error, e.format_for_arrays()))?) } } impl Cheatcode for assertNotEq_22Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b } = self; - Ok(assert_not_eq(a, b) + let Self { left, right } = self; + Ok(assert_not_eq(left, right) .map_err(|e| format!("Assertion failed: {}", e.format_for_arrays()))?) } } impl Cheatcode for assertNotEq_23Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b, error } = self; - Ok(assert_not_eq(a, b).map_err(|e| format!("{}: {}", error, e.format_for_arrays()))?) + let Self { left, right, error } = self; + Ok(assert_not_eq(left, right) + .map_err(|e| format!("{}: {}", error, e.format_for_arrays()))?) } } impl Cheatcode for assertNotEq_24Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b } = self; - Ok(assert_not_eq(a, b) + let Self { left, right } = self; + Ok(assert_not_eq(left, right) .map_err(|e| format!("Assertion failed: {}", e.format_for_arrays()))?) } } impl Cheatcode for assertNotEq_25Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b, error } = self; - Ok(assert_not_eq(a, b).map_err(|e| format!("{}: {}", error, e.format_for_arrays()))?) + let Self { left, right, error } = self; + Ok(assert_not_eq(left, right) + .map_err(|e| format!("{}: {}", error, e.format_for_arrays()))?) } } impl Cheatcode for assertNotEq_26Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b } = self; - let a = a.iter().map(hex::encode_prefixed).collect::>(); - let b = b.iter().map(hex::encode_prefixed).collect::>(); - Ok(assert_not_eq(&a, &b) + let Self { left, right } = self; + let left = left.iter().map(hex::encode_prefixed).collect::>(); + let right = right.iter().map(hex::encode_prefixed).collect::>(); + Ok(assert_not_eq(&left, &right) .map_err(|e| format!("Assertion failed: {}", e.format_for_arrays()))?) } } impl Cheatcode for assertNotEq_27Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b, error } = self; - let a = a.iter().map(hex::encode_prefixed).collect::>(); - let b = b.iter().map(hex::encode_prefixed).collect::>(); - Ok(assert_not_eq(&a, &b).map_err(|e| format!("{}: {}", error, e.format_for_arrays()))?) + let Self { left, right, error } = self; + let left = left.iter().map(hex::encode_prefixed).collect::>(); + let right = right.iter().map(hex::encode_prefixed).collect::>(); + Ok(assert_not_eq(&left, &right) + .map_err(|e| format!("{}: {}", error, e.format_for_arrays()))?) } } impl Cheatcode for assertGt_0Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b } = self; - Ok(assert_gt(a, b).map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) + let Self { left, right } = self; + Ok(assert_gt(left, right) + .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) } } impl Cheatcode for assertGt_1Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b, error } = self; - Ok(assert_gt(a, b).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) + let Self { left, right, error } = self; + Ok(assert_gt(left, right).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) } } impl Cheatcode for assertGt_2Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b } = self; - Ok(assert_gt(a, b).map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) + let Self { left, right } = self; + Ok(assert_gt(left, right) + .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) } } impl Cheatcode for assertGt_3Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b, error } = self; - Ok(assert_gt(a, b).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) + let Self { left, right, error } = self; + Ok(assert_gt(left, right).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) } } impl Cheatcode for assertGe_0Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b } = self; - Ok(assert_ge(a, b).map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) + let Self { left, right } = self; + Ok(assert_ge(left, right) + .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) } } impl Cheatcode for assertGe_1Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b, error } = self; - Ok(assert_ge(a, b).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) + let Self { left, right, error } = self; + Ok(assert_ge(left, right).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) } } impl Cheatcode for assertGe_2Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b } = self; - Ok(assert_ge(a, b).map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) + let Self { left, right } = self; + Ok(assert_ge(left, right) + .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) } } impl Cheatcode for assertGe_3Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b, error } = self; - Ok(assert_ge(a, b).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) + let Self { left, right, error } = self; + Ok(assert_ge(left, right).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) } } impl Cheatcode for assertLt_0Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b } = self; - Ok(assert_lt(a, b).map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) + let Self { left, right } = self; + Ok(assert_lt(left, right) + .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) } } impl Cheatcode for assertLt_1Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b, error } = self; - Ok(assert_lt(a, b).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) + let Self { left, right, error } = self; + Ok(assert_lt(left, right).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) } } impl Cheatcode for assertLt_2Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b } = self; - Ok(assert_lt(a, b).map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) + let Self { left, right } = self; + Ok(assert_lt(left, right) + .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) } } impl Cheatcode for assertLt_3Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b, error } = self; - Ok(assert_lt(a, b).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) + let Self { left, right, error } = self; + Ok(assert_lt(left, right).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) } } impl Cheatcode for assertLe_0Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b } = self; - Ok(assert_le(a, b).map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) + let Self { left, right } = self; + Ok(assert_le(left, right) + .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) } } impl Cheatcode for assertLe_1Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b, error } = self; - Ok(assert_le(a, b).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) + let Self { left, right, error } = self; + Ok(assert_le(left, right).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) } } impl Cheatcode for assertLe_2Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b } = self; - Ok(assert_le(a, b).map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) + let Self { left, right } = self; + Ok(assert_le(left, right) + .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) } } impl Cheatcode for assertLe_3Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - let Self { a, b, error } = self; - Ok(assert_le(a, b).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) + let Self { left, right, error } = self; + Ok(assert_le(left, right).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) } } impl Cheatcode for assertApproxEqAbs_0Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - Ok(uint_assert_approx_eq_abs(self.a, self.b, self.maxDelta) + Ok(uint_assert_approx_eq_abs(self.left, self.right, self.maxDelta) .map_err(|e| format!("Assertion failed: {}", e.to_string()))?) } } impl Cheatcode for assertApproxEqAbs_1Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - Ok(uint_assert_approx_eq_abs(self.a, self.b, self.maxDelta) + Ok(uint_assert_approx_eq_abs(self.left, self.right, self.maxDelta) .map_err(|e| format!("{}: {}", self.error, e.to_string()))?) } } impl Cheatcode for assertApproxEqAbs_2Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - Ok(int_assert_approx_eq_abs(self.a, self.b, self.maxDelta) + Ok(int_assert_approx_eq_abs(self.left, self.right, self.maxDelta) .map_err(|e| format!("Assertion failed: {}", e.to_string()))?) } } impl Cheatcode for assertApproxEqAbs_3Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - Ok(int_assert_approx_eq_abs(self.a, self.b, self.maxDelta) + Ok(int_assert_approx_eq_abs(self.left, self.right, self.maxDelta) .map_err(|e| format!("{}: {}", self.error, e.to_string()))?) } } @@ -658,89 +691,89 @@ fn assert_false(condition: bool) -> Result, SimpleAssertionError> { } } -fn assert_eq<'a, T: PartialEq>(a: &'a T, b: &'a T) -> ComparisonResult<'a, T> { - if a == b { +fn assert_eq<'a, T: PartialEq>(left: &'a T, right: &'a T) -> ComparisonResult<'a, T> { + if left == right { Ok(Default::default()) } else { - Err(ComparisonAssertionError::Eq(a, b)) + Err(ComparisonAssertionError::Eq(left, right)) } } -fn assert_not_eq<'a, T: PartialEq>(a: &'a T, b: &'a T) -> ComparisonResult<'a, T> { - if a != b { +fn assert_not_eq<'a, T: PartialEq>(left: &'a T, right: &'a T) -> ComparisonResult<'a, T> { + if left != right { Ok(Default::default()) } else { - Err(ComparisonAssertionError::NotEq(a, b)) + Err(ComparisonAssertionError::NotEq(left, right)) } } fn uint_assert_approx_eq_abs( - a: U256, - b: U256, + left: U256, + right: U256, max_delta: U256, ) -> Result, ApproxAssertionError> { - let delta = if a > b { a - b } else { b - a }; + let delta = if left > right { left - right } else { right - left }; if delta <= max_delta { Ok(Default::default()) } else { - Err(ApproxAssertionError::EqAbs { a, b, expected_delta: max_delta, delta }) + Err(ApproxAssertionError::EqAbs { left, right, expected_delta: max_delta, delta }) } } fn int_assert_approx_eq_abs( - a: I256, - b: I256, + left: I256, + right: I256, max_delta: U256, ) -> Result, ApproxAssertionError> { - let (a_sign, a_abs) = a.into_sign_and_abs(); - let (b_sign, b_abs) = b.into_sign_and_abs(); + let (left_sign, left_abs) = left.into_sign_and_abs(); + let (right_sign, right_abs) = right.into_sign_and_abs(); - let delta = if a_sign == b_sign { - if a_abs > b_abs { - a_abs - b_abs + let delta = if left_sign == right_sign { + if left_abs > right_abs { + left_abs - right_abs } else { - b_abs - a_abs + right_abs - left_abs } } else { - a_abs + b_abs + left_abs + right_abs }; if delta <= max_delta { Ok(Default::default()) } else { - Err(ApproxAssertionError::EqAbs { a, b, expected_delta: max_delta, delta }) + Err(ApproxAssertionError::EqAbs { left, right, expected_delta: max_delta, delta }) } } -fn assert_gt<'a, T: PartialOrd>(a: &'a T, b: &'a T) -> ComparisonResult<'a, T> { - if a > b { +fn assert_gt<'a, T: PartialOrd>(left: &'a T, right: &'a T) -> ComparisonResult<'a, T> { + if left > right { Ok(Default::default()) } else { - Err(ComparisonAssertionError::Gt(a, b)) + Err(ComparisonAssertionError::Gt(left, right)) } } -fn assert_ge<'a, T: PartialOrd>(a: &'a T, b: &'a T) -> ComparisonResult<'a, T> { - if a >= b { +fn assert_ge<'a, T: PartialOrd>(left: &'a T, right: &'a T) -> ComparisonResult<'a, T> { + if left >= right { Ok(Default::default()) } else { - Err(ComparisonAssertionError::Ge(a, b)) + Err(ComparisonAssertionError::Ge(left, right)) } } -fn assert_lt<'a, T: PartialOrd>(a: &'a T, b: &'a T) -> ComparisonResult<'a, T> { - if a < b { +fn assert_lt<'a, T: PartialOrd>(left: &'a T, right: &'a T) -> ComparisonResult<'a, T> { + if left < right { Ok(Default::default()) } else { - Err(ComparisonAssertionError::Lt(a, b)) + Err(ComparisonAssertionError::Lt(left, right)) } } -fn assert_le<'a, T: PartialOrd>(a: &'a T, b: &'a T) -> ComparisonResult<'a, T> { - if a <= b { +fn assert_le<'a, T: PartialOrd>(left: &'a T, right: &'a T) -> ComparisonResult<'a, T> { + if left <= right { Ok(Default::default()) } else { - Err(ComparisonAssertionError::Le(a, b)) + Err(ComparisonAssertionError::Le(left, right)) } } diff --git a/testdata/cheats/Vm.sol b/testdata/cheats/Vm.sol index 1c9fbbdf12da..e1c46224cf7e 100644 --- a/testdata/cheats/Vm.sol +++ b/testdata/cheats/Vm.sol @@ -25,84 +25,84 @@ interface Vm { function activeFork() external view returns (uint256 forkId); function addr(uint256 privateKey) external pure returns (address keyAddr); function allowCheatcodes(address account) external; - function assertApproxEqAbs(uint256 a, uint256 b, uint256 maxDelta) external pure; - function assertApproxEqAbs(uint256 a, uint256 b, uint256 maxDelta, string calldata error) external pure; - function assertApproxEqAbs(int256 a, int256 b, uint256 maxDelta) external pure; - function assertApproxEqAbs(int256 a, int256 b, uint256 maxDelta, string calldata error) external pure; - function assertEq(bool a, bool b) external pure; - function assertEq(bool a, bool b, string calldata error) external pure; - function assertEq(string calldata a, string calldata b) external pure; - function assertEq(string calldata a, string calldata b, string calldata error) external pure; - function assertEq(bytes calldata a, bytes calldata b) external pure; - function assertEq(bytes calldata a, bytes calldata b, string calldata error) external pure; - function assertEq(bool[] calldata a, bool[] calldata b) external pure; - function assertEq(bool[] calldata a, bool[] calldata b, string calldata error) external pure; - function assertEq(uint256[] calldata a, uint256[] calldata b) external pure; - function assertEq(uint256[] calldata a, uint256[] calldata b, string calldata error) external pure; - function assertEq(int256[] calldata a, int256[] calldata b) external pure; - function assertEq(int256[] calldata a, int256[] calldata b, string calldata error) external pure; - function assertEq(uint256 a, uint256 b) external pure; - function assertEq(address[] calldata a, address[] calldata b) external pure; - function assertEq(address[] calldata a, address[] calldata b, string calldata error) external pure; - function assertEq(bytes32[] calldata a, bytes32[] calldata b) external pure; - function assertEq(bytes32[] calldata a, bytes32[] calldata b, string calldata error) external pure; - function assertEq(string[] calldata a, string[] calldata b) external pure; - function assertEq(string[] calldata a, string[] calldata b, string calldata error) external pure; - function assertEq(bytes[] calldata a, bytes[] calldata b) external pure; - function assertEq(bytes[] calldata a, bytes[] calldata b, string calldata error) external pure; - function assertEq(uint256 a, uint256 b, string calldata error) external pure; - function assertEq(int256 a, int256 b) external pure; - function assertEq(int256 a, int256 b, string calldata error) external pure; - function assertEq(address a, address b) external pure; - function assertEq(address a, address b, string calldata error) external pure; - function assertEq(bytes32 a, bytes32 b) external pure; - function assertEq(bytes32 a, bytes32 b, string calldata error) external pure; + function assertApproxEqAbs(uint256 left, uint256 right, uint256 maxDelta) external pure; + function assertApproxEqAbs(uint256 left, uint256 right, uint256 maxDelta, string calldata error) external pure; + function assertApproxEqAbs(int256 left, int256 right, uint256 maxDelta) external pure; + function assertApproxEqAbs(int256 left, int256 right, uint256 maxDelta, string calldata error) external pure; + function assertEq(bool left, bool right) external pure; + function assertEq(bool left, bool right, string calldata error) external pure; + function assertEq(string calldata left, string calldata right) external pure; + function assertEq(string calldata left, string calldata right, string calldata error) external pure; + function assertEq(bytes calldata left, bytes calldata right) external pure; + function assertEq(bytes calldata left, bytes calldata right, string calldata error) external pure; + function assertEq(bool[] calldata left, bool[] calldata right) external pure; + function assertEq(bool[] calldata left, bool[] calldata right, string calldata error) external pure; + function assertEq(uint256[] calldata left, uint256[] calldata right) external pure; + function assertEq(uint256[] calldata left, uint256[] calldata right, string calldata error) external pure; + function assertEq(int256[] calldata left, int256[] calldata right) external pure; + function assertEq(int256[] calldata left, int256[] calldata right, string calldata error) external pure; + function assertEq(uint256 left, uint256 right) external pure; + function assertEq(address[] calldata left, address[] calldata right) external pure; + function assertEq(address[] calldata left, address[] calldata right, string calldata error) external pure; + function assertEq(bytes32[] calldata left, bytes32[] calldata right) external pure; + function assertEq(bytes32[] calldata left, bytes32[] calldata right, string calldata error) external pure; + function assertEq(string[] calldata left, string[] calldata right) external pure; + function assertEq(string[] calldata left, string[] calldata right, string calldata error) external pure; + function assertEq(bytes[] calldata left, bytes[] calldata right) external pure; + function assertEq(bytes[] calldata left, bytes[] calldata right, string calldata error) external pure; + function assertEq(uint256 left, uint256 right, string calldata error) external pure; + function assertEq(int256 left, int256 right) external pure; + function assertEq(int256 left, int256 right, string calldata error) external pure; + function assertEq(address left, address right) external pure; + function assertEq(address left, address right, string calldata error) external pure; + function assertEq(bytes32 left, bytes32 right) external pure; + function assertEq(bytes32 left, bytes32 right, string calldata error) external pure; function assertFalse(bool condition) external pure; function assertFalse(bool condition, string calldata error) external pure; - function assertGe(uint256 a, uint256 b) external pure; - function assertGe(uint256 a, uint256 b, string calldata error) external pure; - function assertGe(int256 a, int256 b) external pure; - function assertGe(int256 a, int256 b, string calldata error) external pure; - function assertGt(uint256 a, uint256 b) external pure; - function assertGt(uint256 a, uint256 b, string calldata error) external pure; - function assertGt(int256 a, int256 b) external pure; - function assertGt(int256 a, int256 b, string calldata error) external pure; - function assertLe(uint256 a, uint256 b) external pure; - function assertLe(uint256 a, uint256 b, string calldata error) external pure; - function assertLe(int256 a, int256 b) external pure; - function assertLe(int256 a, int256 b, string calldata error) external pure; - function assertLt(uint256 a, uint256 b) external pure; - function assertLt(uint256 a, uint256 b, string calldata error) external pure; - function assertLt(int256 a, int256 b) external pure; - function assertLt(int256 a, int256 b, string calldata error) external pure; - function assertNotEq(bool a, bool b) external pure; - function assertNotEq(bool a, bool b, string calldata error) external pure; - function assertNotEq(string calldata a, string calldata b) external pure; - function assertNotEq(string calldata a, string calldata b, string calldata error) external pure; - function assertNotEq(bytes calldata a, bytes calldata b) external pure; - function assertNotEq(bytes calldata a, bytes calldata b, string calldata error) external pure; - function assertNotEq(bool[] calldata a, bool[] calldata b) external pure; - function assertNotEq(bool[] calldata a, bool[] calldata b, string calldata error) external pure; - function assertNotEq(uint256[] calldata a, uint256[] calldata b) external pure; - function assertNotEq(uint256[] calldata a, uint256[] calldata b, string calldata error) external pure; - function assertNotEq(int256[] calldata a, int256[] calldata b) external pure; - function assertNotEq(int256[] calldata a, int256[] calldata b, string calldata error) external pure; - function assertNotEq(uint256 a, uint256 b) external pure; - function assertNotEq(address[] calldata a, address[] calldata b) external pure; - function assertNotEq(address[] calldata a, address[] calldata b, string calldata error) external pure; - function assertNotEq(bytes32[] calldata a, bytes32[] calldata b) external pure; - function assertNotEq(bytes32[] calldata a, bytes32[] calldata b, string calldata error) external pure; - function assertNotEq(string[] calldata a, string[] calldata b) external pure; - function assertNotEq(string[] calldata a, string[] calldata b, string calldata error) external pure; - function assertNotEq(bytes[] calldata a, bytes[] calldata b) external pure; - function assertNotEq(bytes[] calldata a, bytes[] calldata b, string calldata error) external pure; - function assertNotEq(uint256 a, uint256 b, string calldata error) external pure; - function assertNotEq(int256 a, int256 b) external pure; - function assertNotEq(int256 a, int256 b, string calldata error) external pure; - function assertNotEq(address a, address b) external pure; - function assertNotEq(address a, address b, string calldata error) external pure; - function assertNotEq(bytes32 a, bytes32 b) external pure; - function assertNotEq(bytes32 a, bytes32 b, string calldata error) external pure; + function assertGe(uint256 left, uint256 right) external pure; + function assertGe(uint256 left, uint256 right, string calldata error) external pure; + function assertGe(int256 left, int256 right) external pure; + function assertGe(int256 left, int256 right, string calldata error) external pure; + function assertGt(uint256 left, uint256 right) external pure; + function assertGt(uint256 left, uint256 right, string calldata error) external pure; + function assertGt(int256 left, int256 right) external pure; + function assertGt(int256 left, int256 right, string calldata error) external pure; + function assertLe(uint256 left, uint256 right) external pure; + function assertLe(uint256 left, uint256 right, string calldata error) external pure; + function assertLe(int256 left, int256 right) external pure; + function assertLe(int256 left, int256 right, string calldata error) external pure; + function assertLt(uint256 left, uint256 right) external pure; + function assertLt(uint256 left, uint256 right, string calldata error) external pure; + function assertLt(int256 left, int256 right) external pure; + function assertLt(int256 left, int256 right, string calldata error) external pure; + function assertNotEq(bool left, bool right) external pure; + function assertNotEq(bool left, bool right, string calldata error) external pure; + function assertNotEq(string calldata left, string calldata right) external pure; + function assertNotEq(string calldata left, string calldata right, string calldata error) external pure; + function assertNotEq(bytes calldata left, bytes calldata right) external pure; + function assertNotEq(bytes calldata left, bytes calldata right, string calldata error) external pure; + function assertNotEq(bool[] calldata left, bool[] calldata right) external pure; + function assertNotEq(bool[] calldata left, bool[] calldata right, string calldata error) external pure; + function assertNotEq(uint256[] calldata left, uint256[] calldata right) external pure; + function assertNotEq(uint256[] calldata left, uint256[] calldata right, string calldata error) external pure; + function assertNotEq(int256[] calldata left, int256[] calldata right) external pure; + function assertNotEq(int256[] calldata left, int256[] calldata right, string calldata error) external pure; + function assertNotEq(uint256 left, uint256 right) external pure; + function assertNotEq(address[] calldata left, address[] calldata right) external pure; + function assertNotEq(address[] calldata left, address[] calldata right, string calldata error) external pure; + function assertNotEq(bytes32[] calldata left, bytes32[] calldata right) external pure; + function assertNotEq(bytes32[] calldata left, bytes32[] calldata right, string calldata error) external pure; + function assertNotEq(string[] calldata left, string[] calldata right) external pure; + function assertNotEq(string[] calldata left, string[] calldata right, string calldata error) external pure; + function assertNotEq(bytes[] calldata left, bytes[] calldata right) external pure; + function assertNotEq(bytes[] calldata left, bytes[] calldata right, string calldata error) external pure; + function assertNotEq(uint256 left, uint256 right, string calldata error) external pure; + function assertNotEq(int256 left, int256 right) external pure; + function assertNotEq(int256 left, int256 right, string calldata error) external pure; + function assertNotEq(address left, address right) external pure; + function assertNotEq(address left, address right, string calldata error) external pure; + function assertNotEq(bytes32 left, bytes32 right) external pure; + function assertNotEq(bytes32 left, bytes32 right, string calldata error) external pure; function assertTrue(bool condition) external pure; function assertTrue(bool condition, string calldata error) external pure; function assume(bool condition) external pure; From 057ebbbd67fd7ea2290bae665bc753a5009cdf8d Mon Sep 17 00:00:00 2001 From: Arsenii Kulikov Date: Tue, 16 Jan 2024 20:18:31 +0400 Subject: [PATCH 10/19] Refactor + decimals cheatcods --- crates/cheatcodes/assets/cheatcodes.json | 560 +++++++++++++++++++++++ crates/cheatcodes/spec/src/vm.rs | 148 ++++++ crates/cheatcodes/src/test/assert.rs | 328 +++++++++++-- crates/evm/core/src/abi/console.rs | 4 +- crates/evm/core/src/abi/mod.rs | 2 +- testdata/cheats/Vm.sol | 28 ++ 6 files changed, 1019 insertions(+), 51 deletions(-) diff --git a/crates/cheatcodes/assets/cheatcodes.json b/crates/cheatcodes/assets/cheatcodes.json index 97a102183431..d6f5a5941171 100644 --- a/crates/cheatcodes/assets/cheatcodes.json +++ b/crates/cheatcodes/assets/cheatcodes.json @@ -553,6 +553,86 @@ "status": "stable", "safety": "unsafe" }, + { + "func": { + "id": "assertApproxEqAbsDecimal_0", + "description": "Compares two `uint256` values. Expects difference to be less than or equal to `maxDelta`.\nFormats values with decimals in failure message.", + "declaration": "function assertApproxEqAbsDecimal(uint256 left, uint256 right, uint256 maxDelta, uint256 decimals) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertApproxEqAbsDecimal(uint256,uint256,uint256,uint256)", + "selector": "0x045c55ce", + "selectorBytes": [ + 4, + 92, + 85, + 206 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertApproxEqAbsDecimal_1", + "description": "Compares two `uint256` values. Expects difference to be less than or equal to `maxDelta`.\nFormats values with decimals in failure message. Includes error message into revert string on failure.", + "declaration": "function assertApproxEqAbsDecimal(uint256 left, uint256 right, uint256 maxDelta, uint256 decimals, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertApproxEqAbsDecimal(uint256,uint256,uint256,uint256,string)", + "selector": "0x60429eb2", + "selectorBytes": [ + 96, + 66, + 158, + 178 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertApproxEqAbsDecimal_2", + "description": "Compares two `int256` values. Expects difference to be less than or equal to `maxDelta`.\nFormats values with decimals in failure message.", + "declaration": "function assertApproxEqAbsDecimal(int256 left, int256 right, uint256 maxDelta, uint256 decimals) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertApproxEqAbsDecimal(int256,int256,uint256,uint256)", + "selector": "0x3d5bc8bc", + "selectorBytes": [ + 61, + 91, + 200, + 188 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertApproxEqAbsDecimal_3", + "description": "Compares two `int256` values. Expects difference to be less than or equal to `maxDelta`.\nFormats values with decimals in failure message. Includes error message into revert string on failure.", + "declaration": "function assertApproxEqAbsDecimal(int256 left, int256 right, uint256 maxDelta, uint256 decimals, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertApproxEqAbsDecimal(int256,int256,uint256,uint256,string)", + "selector": "0x6a5066d4", + "selectorBytes": [ + 106, + 80, + 102, + 212 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, { "func": { "id": "assertApproxEqAbs_0", @@ -633,6 +713,86 @@ "status": "stable", "safety": "safe" }, + { + "func": { + "id": "assertEqDecimal_0", + "description": "Asserts that two `uint256` values are equal, formatting them with decimals in failure message.", + "declaration": "function assertEqDecimal(uint256 left, uint256 right, uint256 decimals) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertEqDecimal(uint256,uint256,uint256)", + "selector": "0x27af7d9c", + "selectorBytes": [ + 39, + 175, + 125, + 156 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertEqDecimal_1", + "description": "Asserts that two `uint256` values are equal, formatting them with decimals in failure message.\nIncludes error message into revert string on failure.", + "declaration": "function assertEqDecimal(uint256 left, uint256 right, uint256 decimals, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertEqDecimal(uint256,uint256,uint256,string)", + "selector": "0xd0cbbdef", + "selectorBytes": [ + 208, + 203, + 189, + 239 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertEqDecimal_2", + "description": "Asserts that two `int256` values are equal, formatting them with decimals in failure message.", + "declaration": "function assertEqDecimal(int256 left, int256 right, uint256 decimals) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertEqDecimal(int256,int256,uint256)", + "selector": "0x48016c04", + "selectorBytes": [ + 72, + 1, + 108, + 4 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertEqDecimal_3", + "description": "Asserts that two `int256` values are equal, formatting them with decimals in failure message.\nIncludes error message into revert string on failure.", + "declaration": "function assertEqDecimal(int256 left, int256 right, uint256 decimals, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertEqDecimal(int256,int256,uint256,string)", + "selector": "0x7e77b0c5", + "selectorBytes": [ + 126, + 119, + 176, + 197 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, { "func": { "id": "assertEq_0", @@ -1233,6 +1393,86 @@ "status": "stable", "safety": "safe" }, + { + "func": { + "id": "assertGeDecimal_0", + "description": "Compares two `uint256` values. Expects first value to be greater than or equal to second.\nFormats values with decimals in failure message.", + "declaration": "function assertGeDecimal(uint256 left, uint256 right, uint256 decimals) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertGeDecimal(uint256,uint256,uint256)", + "selector": "0x3d1fe08a", + "selectorBytes": [ + 61, + 31, + 224, + 138 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertGeDecimal_1", + "description": "Compares two `uint256` values. Expects first value to be greater than or equal to second.\nFormats values with decimals in failure message. Includes error message into revert string on failure.", + "declaration": "function assertGeDecimal(uint256 left, uint256 right, uint256 decimals, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertGeDecimal(uint256,uint256,uint256,string)", + "selector": "0x8bff9133", + "selectorBytes": [ + 139, + 255, + 145, + 51 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertGeDecimal_2", + "description": "Compares two `int256` values. Expects first value to be greater than or equal to second.\nFormats values with decimals in failure message.", + "declaration": "function assertGeDecimal(int256 left, int256 right, uint256 decimals) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertGeDecimal(int256,int256,uint256)", + "selector": "0xdc28c0f1", + "selectorBytes": [ + 220, + 40, + 192, + 241 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertGeDecimal_3", + "description": "Compares two `int256` values. Expects first value to be greater than or equal to second.\nFormats values with decimals in failure message. Includes error message into revert string on failure.", + "declaration": "function assertGeDecimal(int256 left, int256 right, uint256 decimals, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertGeDecimal(int256,int256,uint256,string)", + "selector": "0x5df93c9b", + "selectorBytes": [ + 93, + 249, + 60, + 155 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, { "func": { "id": "assertGe_0", @@ -1313,6 +1553,86 @@ "status": "stable", "safety": "safe" }, + { + "func": { + "id": "assertGtDecimal_0", + "description": "Compares two `uint256` values. Expects first value to be greater than second.\nFormats values with decimals in failure message.", + "declaration": "function assertGtDecimal(uint256 left, uint256 right, uint256 decimals) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertGtDecimal(uint256,uint256,uint256)", + "selector": "0xeccd2437", + "selectorBytes": [ + 236, + 205, + 36, + 55 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertGtDecimal_1", + "description": "Compares two `uint256` values. Expects first value to be greater than second.\nFormats values with decimals in failure message. Includes error message into revert string on failure.", + "declaration": "function assertGtDecimal(uint256 left, uint256 right, uint256 decimals, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertGtDecimal(uint256,uint256,uint256,string)", + "selector": "0x64949a8d", + "selectorBytes": [ + 100, + 148, + 154, + 141 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertGtDecimal_2", + "description": "Compares two `int256` values. Expects first value to be greater than second.\nFormats values with decimals in failure message.", + "declaration": "function assertGtDecimal(int256 left, int256 right, uint256 decimals) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertGtDecimal(int256,int256,uint256)", + "selector": "0x78611f0e", + "selectorBytes": [ + 120, + 97, + 31, + 14 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertGtDecimal_3", + "description": "Compares two `int256` values. Expects first value to be greater than second.\nFormats values with decimals in failure message. Includes error message into revert string on failure.", + "declaration": "function assertGtDecimal(int256 left, int256 right, uint256 decimals, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertGtDecimal(int256,int256,uint256,string)", + "selector": "0x04a5c7ab", + "selectorBytes": [ + 4, + 165, + 199, + 171 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, { "func": { "id": "assertGt_0", @@ -1393,6 +1713,86 @@ "status": "stable", "safety": "safe" }, + { + "func": { + "id": "assertLeDecimal_0", + "description": "Compares two `uint256` values. Expects first value to be less than or equal to second.\nFormats values with decimals in failure message.", + "declaration": "function assertLeDecimal(uint256 left, uint256 right, uint256 decimals) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertLeDecimal(uint256,uint256,uint256)", + "selector": "0xc304aab7", + "selectorBytes": [ + 195, + 4, + 170, + 183 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertLeDecimal_1", + "description": "Compares two `uint256` values. Expects first value to be less than or equal to second.\nFormats values with decimals in failure message. Includes error message into revert string on failure.", + "declaration": "function assertLeDecimal(uint256 left, uint256 right, uint256 decimals, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertLeDecimal(uint256,uint256,uint256,string)", + "selector": "0x7fefbbe0", + "selectorBytes": [ + 127, + 239, + 187, + 224 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertLeDecimal_2", + "description": "Compares two `int256` values. Expects first value to be less than or equal to second.\nFormats values with decimals in failure message.", + "declaration": "function assertLeDecimal(int256 left, int256 right, uint256 decimals) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertLeDecimal(int256,int256,uint256)", + "selector": "0x11d1364a", + "selectorBytes": [ + 17, + 209, + 54, + 74 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertLeDecimal_3", + "description": "Compares two `int256` values. Expects first value to be less than or equal to second.\nFormats values with decimals in failure message. Includes error message into revert string on failure.", + "declaration": "function assertLeDecimal(int256 left, int256 right, uint256 decimals, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertLeDecimal(int256,int256,uint256,string)", + "selector": "0xaa5cf788", + "selectorBytes": [ + 170, + 92, + 247, + 136 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, { "func": { "id": "assertLe_0", @@ -1473,6 +1873,86 @@ "status": "stable", "safety": "safe" }, + { + "func": { + "id": "assertLtDecimal_0", + "description": "Compares two `uint256` values. Expects first value to be less than second.\nFormats values with decimals in failure message.", + "declaration": "function assertLtDecimal(uint256 left, uint256 right, uint256 decimals) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertLtDecimal(uint256,uint256,uint256)", + "selector": "0x2077337e", + "selectorBytes": [ + 32, + 119, + 51, + 126 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertLtDecimal_1", + "description": "Compares two `uint256` values. Expects first value to be less than second.\nFormats values with decimals in failure message. Includes error message into revert string on failure.", + "declaration": "function assertLtDecimal(uint256 left, uint256 right, uint256 decimals, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertLtDecimal(uint256,uint256,uint256,string)", + "selector": "0xa972d037", + "selectorBytes": [ + 169, + 114, + 208, + 55 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertLtDecimal_2", + "description": "Compares two `int256` values. Expects first value to be less than second.\nFormats values with decimals in failure message.", + "declaration": "function assertLtDecimal(int256 left, int256 right, uint256 decimals) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertLtDecimal(int256,int256,uint256)", + "selector": "0xdbe8d88b", + "selectorBytes": [ + 219, + 232, + 216, + 139 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertLtDecimal_3", + "description": "Compares two `int256` values. Expects first value to be less than second.\nFormats values with decimals in failure message. Includes error message into revert string on failure.", + "declaration": "function assertLtDecimal(int256 left, int256 right, uint256 decimals, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertLtDecimal(int256,int256,uint256,string)", + "selector": "0x40f0b4e0", + "selectorBytes": [ + 64, + 240, + 180, + 224 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, { "func": { "id": "assertLt_0", @@ -1553,6 +2033,86 @@ "status": "stable", "safety": "safe" }, + { + "func": { + "id": "assertNotEqDecimal_0", + "description": "Asserts that two `uint256` values are not equal, formatting them with decimals in failure message.", + "declaration": "function assertNotEqDecimal(uint256 left, uint256 right, uint256 decimals) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertNotEqDecimal(uint256,uint256,uint256)", + "selector": "0x669efca7", + "selectorBytes": [ + 102, + 158, + 252, + 167 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertNotEqDecimal_1", + "description": "Asserts that two `uint256` values are not equal, formatting them with decimals in failure message.\nIncludes error message into revert string on failure.", + "declaration": "function assertNotEqDecimal(uint256 left, uint256 right, uint256 decimals, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertNotEqDecimal(uint256,uint256,uint256,string)", + "selector": "0xf5a55558", + "selectorBytes": [ + 245, + 165, + 85, + 88 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertNotEqDecimal_2", + "description": "Asserts that two `int256` values are not equal, formatting them with decimals in failure message.", + "declaration": "function assertNotEqDecimal(int256 left, int256 right, uint256 decimals) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertNotEqDecimal(int256,int256,uint256)", + "selector": "0x14e75680", + "selectorBytes": [ + 20, + 231, + 86, + 128 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertNotEqDecimal_3", + "description": "Asserts that two `int256` values are not equal, formatting them with decimals in failure message.\nIncludes error message into revert string on failure.", + "declaration": "function assertNotEqDecimal(int256 left, int256 right, uint256 decimals, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertNotEqDecimal(int256,int256,uint256,string)", + "selector": "0x33949f0b", + "selectorBytes": [ + 51, + 148, + 159, + 11 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, { "func": { "id": "assertNotEq_0", diff --git a/crates/cheatcodes/spec/src/vm.rs b/crates/cheatcodes/spec/src/vm.rs index 94c870b01b75..15564e9bfd98 100644 --- a/crates/cheatcodes/spec/src/vm.rs +++ b/crates/cheatcodes/spec/src/vm.rs @@ -839,6 +839,24 @@ interface Vm { #[cheatcode(group = Testing, safety = Safe)] function assertEq(bytes[] calldata left, bytes[] calldata right, string calldata error) external pure; + /// Asserts that two `uint256` values are equal, formatting them with decimals in failure message. + #[cheatcode(group = Testing, safety = Safe)] + function assertEqDecimal(uint256 left, uint256 right, uint256 decimals) external pure; + + /// Asserts that two `uint256` values are equal, formatting them with decimals in failure message. + /// Includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertEqDecimal(uint256 left, uint256 right, uint256 decimals, string calldata error) external pure; + + /// Asserts that two `int256` values are equal, formatting them with decimals in failure message. + #[cheatcode(group = Testing, safety = Safe)] + function assertEqDecimal(int256 left, int256 right, uint256 decimals) external pure; + + /// Asserts that two `int256` values are equal, formatting them with decimals in failure message. + /// Includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertEqDecimal(int256 left, int256 right, uint256 decimals, string calldata error) external pure; + /// Asserts that two `bool` values are not equal. #[cheatcode(group = Testing, safety = Safe)] function assertNotEq(bool left, bool right) external pure; @@ -951,6 +969,24 @@ interface Vm { #[cheatcode(group = Testing, safety = Safe)] function assertNotEq(bytes[] calldata left, bytes[] calldata right, string calldata error) external pure; + /// Asserts that two `uint256` values are not equal, formatting them with decimals in failure message. + #[cheatcode(group = Testing, safety = Safe)] + function assertNotEqDecimal(uint256 left, uint256 right, uint256 decimals) external pure; + + /// Asserts that two `uint256` values are not equal, formatting them with decimals in failure message. + /// Includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertNotEqDecimal(uint256 left, uint256 right, uint256 decimals, string calldata error) external pure; + + /// Asserts that two `int256` values are not equal, formatting them with decimals in failure message. + #[cheatcode(group = Testing, safety = Safe)] + function assertNotEqDecimal(int256 left, int256 right, uint256 decimals) external pure; + + /// Asserts that two `int256` values are not equal, formatting them with decimals in failure message. + /// Includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertNotEqDecimal(int256 left, int256 right, uint256 decimals, string calldata error) external pure; + /// Compares two `uint256` values. Expects first value to be greater than second. #[cheatcode(group = Testing, safety = Safe)] function assertGt(uint256 left, uint256 right) external pure; @@ -969,6 +1005,26 @@ interface Vm { #[cheatcode(group = Testing, safety = Safe)] function assertGt(int256 left, int256 right, string calldata error) external pure; + /// Compares two `uint256` values. Expects first value to be greater than second. + /// Formats values with decimals in failure message. + #[cheatcode(group = Testing, safety = Safe)] + function assertGtDecimal(uint256 left, uint256 right, uint256 decimals) external pure; + + /// Compares two `uint256` values. Expects first value to be greater than second. + /// Formats values with decimals in failure message. Includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertGtDecimal(uint256 left, uint256 right, uint256 decimals, string calldata error) external pure; + + /// Compares two `int256` values. Expects first value to be greater than second. + /// Formats values with decimals in failure message. + #[cheatcode(group = Testing, safety = Safe)] + function assertGtDecimal(int256 left, int256 right, uint256 decimals) external pure; + + /// Compares two `int256` values. Expects first value to be greater than second. + /// Formats values with decimals in failure message. Includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertGtDecimal(int256 left, int256 right, uint256 decimals, string calldata error) external pure; + /// Compares two `uint256` values. Expects first value to be greater than or equal to second. #[cheatcode(group = Testing, safety = Safe)] function assertGe(uint256 left, uint256 right) external pure; @@ -987,6 +1043,26 @@ interface Vm { #[cheatcode(group = Testing, safety = Safe)] function assertGe(int256 left, int256 right, string calldata error) external pure; + /// Compares two `uint256` values. Expects first value to be greater than or equal to second. + /// Formats values with decimals in failure message. + #[cheatcode(group = Testing, safety = Safe)] + function assertGeDecimal(uint256 left, uint256 right, uint256 decimals) external pure; + + /// Compares two `uint256` values. Expects first value to be greater than or equal to second. + /// Formats values with decimals in failure message. Includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertGeDecimal(uint256 left, uint256 right, uint256 decimals, string calldata error) external pure; + + /// Compares two `int256` values. Expects first value to be greater than or equal to second. + /// Formats values with decimals in failure message. + #[cheatcode(group = Testing, safety = Safe)] + function assertGeDecimal(int256 left, int256 right, uint256 decimals) external pure; + + /// Compares two `int256` values. Expects first value to be greater than or equal to second. + /// Formats values with decimals in failure message. Includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertGeDecimal(int256 left, int256 right, uint256 decimals, string calldata error) external pure; + /// Compares two `uint256` values. Expects first value to be less than second. #[cheatcode(group = Testing, safety = Safe)] function assertLt(uint256 left, uint256 right) external pure; @@ -1005,6 +1081,26 @@ interface Vm { #[cheatcode(group = Testing, safety = Safe)] function assertLt(int256 left, int256 right, string calldata error) external pure; + /// Compares two `uint256` values. Expects first value to be less than second. + /// Formats values with decimals in failure message. + #[cheatcode(group = Testing, safety = Safe)] + function assertLtDecimal(uint256 left, uint256 right, uint256 decimals) external pure; + + /// Compares two `uint256` values. Expects first value to be less than second. + /// Formats values with decimals in failure message. Includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertLtDecimal(uint256 left, uint256 right, uint256 decimals, string calldata error) external pure; + + /// Compares two `int256` values. Expects first value to be less than second. + /// Formats values with decimals in failure message. + #[cheatcode(group = Testing, safety = Safe)] + function assertLtDecimal(int256 left, int256 right, uint256 decimals) external pure; + + /// Compares two `int256` values. Expects first value to be less than second. + /// Formats values with decimals in failure message. Includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertLtDecimal(int256 left, int256 right, uint256 decimals, string calldata error) external pure; + /// Compares two `uint256` values. Expects first value to be less than or equal to second. #[cheatcode(group = Testing, safety = Safe)] function assertLe(uint256 left, uint256 right) external pure; @@ -1023,6 +1119,26 @@ interface Vm { #[cheatcode(group = Testing, safety = Safe)] function assertLe(int256 left, int256 right, string calldata error) external pure; + /// Compares two `uint256` values. Expects first value to be less than or equal to second. + /// Formats values with decimals in failure message. + #[cheatcode(group = Testing, safety = Safe)] + function assertLeDecimal(uint256 left, uint256 right, uint256 decimals) external pure; + + /// Compares two `uint256` values. Expects first value to be less than or equal to second. + /// Formats values with decimals in failure message. Includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertLeDecimal(uint256 left, uint256 right, uint256 decimals, string calldata error) external pure; + + /// Compares two `int256` values. Expects first value to be less than or equal to second. + /// Formats values with decimals in failure message. + #[cheatcode(group = Testing, safety = Safe)] + function assertLeDecimal(int256 left, int256 right, uint256 decimals) external pure; + + /// Compares two `int256` values. Expects first value to be less than or equal to second. + /// Formats values with decimals in failure message. Includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertLeDecimal(int256 left, int256 right, uint256 decimals, string calldata error) external pure; + /// Compares two `uint256` values. Expects difference to be less than or equal to `maxDelta`. #[cheatcode(group = Testing, safety = Safe)] function assertApproxEqAbs(uint256 left, uint256 right, uint256 maxDelta) external pure; @@ -1041,6 +1157,38 @@ interface Vm { #[cheatcode(group = Testing, safety = Safe)] function assertApproxEqAbs(int256 left, int256 right, uint256 maxDelta, string calldata error) external pure; + /// Compares two `uint256` values. Expects difference to be less than or equal to `maxDelta`. + /// Formats values with decimals in failure message. + #[cheatcode(group = Testing, safety = Safe)] + function assertApproxEqAbsDecimal(uint256 left, uint256 right, uint256 maxDelta, uint256 decimals) external pure; + + /// Compares two `uint256` values. Expects difference to be less than or equal to `maxDelta`. + /// Formats values with decimals in failure message. Includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertApproxEqAbsDecimal( + uint256 left, + uint256 right, + uint256 maxDelta, + uint256 decimals, + string calldata error + ) external pure; + + /// Compares two `int256` values. Expects difference to be less than or equal to `maxDelta`. + /// Formats values with decimals in failure message. + #[cheatcode(group = Testing, safety = Safe)] + function assertApproxEqAbsDecimal(int256 left, int256 right, uint256 maxDelta, uint256 decimals) external pure; + + /// Compares two `int256` values. Expects difference to be less than or equal to `maxDelta`. + /// Formats values with decimals in failure message. Includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertApproxEqAbsDecimal( + int256 left, + int256 right, + uint256 maxDelta, + uint256 decimals, + string calldata error + ) external pure; + // ======== OS and Filesystem ======== // -------- Metadata -------- diff --git a/crates/cheatcodes/src/test/assert.rs b/crates/cheatcodes/src/test/assert.rs index 37470ceebc46..eade07b87757 100644 --- a/crates/cheatcodes/src/test/assert.rs +++ b/crates/cheatcodes/src/test/assert.rs @@ -1,6 +1,7 @@ use std::fmt::{Debug, Display}; use alloy_primitives::{I256, U256}; +use foundry_evm_core::abi::{format_units_int, format_units_uint}; use itertools::Itertools; use crate::{Cheatcode, Cheatcodes, Result, Vm::*}; @@ -11,49 +12,84 @@ struct SimpleAssertionError; #[derive(thiserror::Error, Debug)] enum ComparisonAssertionError<'a, T> { - NotEq(&'a T, &'a T), - Eq(&'a T, &'a T), - Ge(&'a T, &'a T), - Gt(&'a T, &'a T), - Le(&'a T, &'a T), - Lt(&'a T, &'a T), -} - -#[derive(thiserror::Error, Debug)] -enum ApproxAssertionError { - #[error("{left} !~= {right} (max deltleft: {expected_delta}, real deltleft: {delta})")] - EqAbs { left: T, right: T, expected_delta: D, delta: D }, + NotEq { left: &'a T, right: &'a T }, + Eq { left: &'a T, right: &'a T }, + Ge { left: &'a T, right: &'a T }, + Gt { left: &'a T, right: &'a T }, + Le { left: &'a T, right: &'a T }, + Lt { left: &'a T, right: &'a T }, +} + +macro_rules! format_values { + ($self:expr, $format_fn:expr) => { + match $self { + Self::NotEq { left, right } => format!("{} == {}", $format_fn(left), $format_fn(right)), + Self::Eq { left, right } => format!("{} != {}", $format_fn(left), $format_fn(right)), + Self::Ge { left, right } => format!("{} < {}", $format_fn(left), $format_fn(right)), + Self::Gt { left, right } => format!("{} <= {}", $format_fn(left), $format_fn(right)), + Self::Le { left, right } => format!("{} > {}", $format_fn(left), $format_fn(right)), + Self::Lt { left, right } => format!("{} >= {}", $format_fn(left), $format_fn(right)), + } + }; } impl<'a, T: Display> ComparisonAssertionError<'a, T> { fn format_for_values(&self) -> String { - match self { - Self::NotEq(left, right) => format!("{} == {}", left, right), - Self::Eq(left, right) => format!("{} != {}", left, right), - Self::Ge(left, right) => format!("{} < {}", left, right), - Self::Gt(left, right) => format!("{} <= {}", left, right), - Self::Le(left, right) => format!("{} > {}", left, right), - Self::Lt(left, right) => format!("{} >= {}", left, right), - } + format_values!(self, T::to_string) } } -macro_rules! format_arrays { - ($left:expr, $right:expr, $c:literal) => { - format!("[{}] {} [{}]", $left.iter().join(", "), $c, $right.iter().join(", ")) - }; -} - +#[allow(clippy::redundant_closure_call)] impl<'a, T: Display> ComparisonAssertionError<'a, Vec> { fn format_for_arrays(&self) -> String { - match self { - Self::NotEq(left, right) => format_arrays!(left, right, "=="), - Self::Eq(left, right) => format_arrays!(left, right, "!="), - Self::Ge(left, right) => format_arrays!(left, right, "<"), - Self::Gt(left, right) => format_arrays!(left, right, "<="), - Self::Le(left, right) => format_arrays!(left, right, ">"), - Self::Lt(left, right) => format_arrays!(left, right, ">="), - } + format_values!(self, |v: &Vec| format!("[{}]", v.iter().join(", "))) + } +} + +#[allow(clippy::redundant_closure_call)] +impl<'a> ComparisonAssertionError<'a, U256> { + fn format_with_decimals(&self, decimals: &U256) -> String { + format_values!(self, |v: &U256| format_units_uint(v, decimals)) + } +} + +#[allow(clippy::redundant_closure_call)] +impl<'a> ComparisonAssertionError<'a, I256> { + fn format_with_decimals(&self, decimals: &U256) -> String { + format_values!(self, |v: &I256| format_units_int(v, decimals)) + } +} + +#[derive(thiserror::Error, Debug)] +#[error("Assertion failed: {left} !~= {right} (max delta: {max_delta}, real delta: {real_delta})")] +struct EqAbsAssertionError { + left: T, + right: T, + max_delta: D, + real_delta: D, +} + +impl EqAbsAssertionError { + fn format_with_decimals(&self, decimals: &U256) -> String { + format!( + "{} !~= {} (max delta: {}, real delta: {})", + format_units_uint(&self.left, decimals), + format_units_uint(&self.right, decimals), + format_units_uint(&self.max_delta, decimals), + format_units_uint(&self.real_delta, decimals), + ) + } +} + +impl EqAbsAssertionError { + fn format_with_decimals(&self, decimals: &U256) -> String { + format!( + "{} !~= {} (max delta: {}, real delta: {})", + format_units_int(&self.left, decimals), + format_units_int(&self.right, decimals), + format_units_uint(&self.max_delta, decimals), + format_units_uint(&self.real_delta, decimals), + ) } } @@ -299,6 +335,34 @@ impl Cheatcode for assertEq_27Call { } } +impl Cheatcode for assertEqDecimal_0Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + Ok(assert_eq(&self.left, &self.right) + .map_err(|e| format!("Assertion failed: {}", e.format_with_decimals(&self.decimals)))?) + } +} + +impl Cheatcode for assertEqDecimal_1Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + Ok(assert_eq(&self.left, &self.right) + .map_err(|e| format!("{}: {}", self.error, e.format_with_decimals(&self.decimals)))?) + } +} + +impl Cheatcode for assertEqDecimal_2Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + Ok(assert_eq(&self.left, &self.right) + .map_err(|e| format!("Assertion failed: {}", e.format_with_decimals(&self.decimals)))?) + } +} + +impl Cheatcode for assertEqDecimal_3Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + Ok(assert_eq(&self.left, &self.right) + .map_err(|e| format!("{}: {}", self.error, e.format_with_decimals(&self.decimals)))?) + } +} + impl Cheatcode for assertNotEq_0Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { left, right } = self; @@ -527,6 +591,34 @@ impl Cheatcode for assertNotEq_27Call { } } +impl Cheatcode for assertNotEqDecimal_0Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + Ok(assert_not_eq(&self.left, &self.right) + .map_err(|e| format!("Assertion failed: {}", e.format_with_decimals(&self.decimals)))?) + } +} + +impl Cheatcode for assertNotEqDecimal_1Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + Ok(assert_not_eq(&self.left, &self.right) + .map_err(|e| format!("{}: {}", self.error, e.format_with_decimals(&self.decimals)))?) + } +} + +impl Cheatcode for assertNotEqDecimal_2Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + Ok(assert_not_eq(&self.left, &self.right) + .map_err(|e| format!("Assertion failed: {}", e.format_with_decimals(&self.decimals)))?) + } +} + +impl Cheatcode for assertNotEqDecimal_3Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + Ok(assert_not_eq(&self.left, &self.right) + .map_err(|e| format!("{}: {}", self.error, e.format_with_decimals(&self.decimals)))?) + } +} + impl Cheatcode for assertGt_0Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { left, right } = self; @@ -557,6 +649,34 @@ impl Cheatcode for assertGt_3Call { } } +impl Cheatcode for assertGtDecimal_0Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + Ok(assert_gt(&self.left, &self.right) + .map_err(|e| format!("Assertion failed: {}", e.format_with_decimals(&self.decimals)))?) + } +} + +impl Cheatcode for assertGtDecimal_1Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + Ok(assert_gt(&self.left, &self.right) + .map_err(|e| format!("{}: {}", self.error, e.format_with_decimals(&self.decimals)))?) + } +} + +impl Cheatcode for assertGtDecimal_2Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + Ok(assert_gt(&self.left, &self.right) + .map_err(|e| format!("Assertion failed: {}", e.format_with_decimals(&self.decimals)))?) + } +} + +impl Cheatcode for assertGtDecimal_3Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + Ok(assert_gt(&self.left, &self.right) + .map_err(|e| format!("{}: {}", self.error, e.format_with_decimals(&self.decimals)))?) + } +} + impl Cheatcode for assertGe_0Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { left, right } = self; @@ -587,6 +707,34 @@ impl Cheatcode for assertGe_3Call { } } +impl Cheatcode for assertGeDecimal_0Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + Ok(assert_ge(&self.left, &self.right) + .map_err(|e| format!("Assertion failed: {}", e.format_with_decimals(&self.decimals)))?) + } +} + +impl Cheatcode for assertGeDecimal_1Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + Ok(assert_ge(&self.left, &self.right) + .map_err(|e| format!("{}: {}", self.error, e.format_with_decimals(&self.decimals)))?) + } +} + +impl Cheatcode for assertGeDecimal_2Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + Ok(assert_ge(&self.left, &self.right) + .map_err(|e| format!("Assertion failed: {}", e.format_with_decimals(&self.decimals)))?) + } +} + +impl Cheatcode for assertGeDecimal_3Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + Ok(assert_ge(&self.left, &self.right) + .map_err(|e| format!("{}: {}", self.error, e.format_with_decimals(&self.decimals)))?) + } +} + impl Cheatcode for assertLt_0Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { left, right } = self; @@ -617,6 +765,34 @@ impl Cheatcode for assertLt_3Call { } } +impl Cheatcode for assertLtDecimal_0Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + Ok(assert_lt(&self.left, &self.right) + .map_err(|e| format!("Assertion failed: {}", e.format_with_decimals(&self.decimals)))?) + } +} + +impl Cheatcode for assertLtDecimal_1Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + Ok(assert_lt(&self.left, &self.right) + .map_err(|e| format!("{}: {}", self.error, e.format_with_decimals(&self.decimals)))?) + } +} + +impl Cheatcode for assertLtDecimal_2Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + Ok(assert_lt(&self.left, &self.right) + .map_err(|e| format!("Assertion failed: {}", e.format_with_decimals(&self.decimals)))?) + } +} + +impl Cheatcode for assertLtDecimal_3Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + Ok(assert_lt(&self.left, &self.right) + .map_err(|e| format!("{}: {}", self.error, e.format_with_decimals(&self.decimals)))?) + } +} + impl Cheatcode for assertLe_0Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { left, right } = self; @@ -647,31 +823,87 @@ impl Cheatcode for assertLe_3Call { } } +impl Cheatcode for assertLeDecimal_0Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + Ok(assert_le(&self.left, &self.right) + .map_err(|e| format!("Assertion failed: {}", e.format_with_decimals(&self.decimals)))?) + } +} + +impl Cheatcode for assertLeDecimal_1Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + Ok(assert_le(&self.left, &self.right) + .map_err(|e| format!("{}: {}", self.error, e.format_with_decimals(&self.decimals)))?) + } +} + +impl Cheatcode for assertLeDecimal_2Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + Ok(assert_le(&self.left, &self.right) + .map_err(|e| format!("Assertion failed: {}", e.format_with_decimals(&self.decimals)))?) + } +} + +impl Cheatcode for assertLeDecimal_3Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + Ok(assert_le(&self.left, &self.right) + .map_err(|e| format!("{}: {}", self.error, e.format_with_decimals(&self.decimals)))?) + } +} + impl Cheatcode for assertApproxEqAbs_0Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { Ok(uint_assert_approx_eq_abs(self.left, self.right, self.maxDelta) - .map_err(|e| format!("Assertion failed: {}", e.to_string()))?) + .map_err(|e| format!("Assertion failed: {}", e))?) } } impl Cheatcode for assertApproxEqAbs_1Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { Ok(uint_assert_approx_eq_abs(self.left, self.right, self.maxDelta) - .map_err(|e| format!("{}: {}", self.error, e.to_string()))?) + .map_err(|e| format!("{}: {}", self.error, e))?) } } impl Cheatcode for assertApproxEqAbs_2Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { Ok(int_assert_approx_eq_abs(self.left, self.right, self.maxDelta) - .map_err(|e| format!("Assertion failed: {}", e.to_string()))?) + .map_err(|e| format!("Assertion failed: {}", e))?) } } impl Cheatcode for assertApproxEqAbs_3Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { Ok(int_assert_approx_eq_abs(self.left, self.right, self.maxDelta) - .map_err(|e| format!("{}: {}", self.error, e.to_string()))?) + .map_err(|e| format!("{}: {}", self.error, e))?) + } +} + +impl Cheatcode for assertApproxEqAbsDecimal_0Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + Ok(uint_assert_approx_eq_abs(self.left, self.right, self.maxDelta) + .map_err(|e| format!("Assertion failed: {}", e.format_with_decimals(&self.decimals)))?) + } +} + +impl Cheatcode for assertApproxEqAbsDecimal_1Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + Ok(uint_assert_approx_eq_abs(self.left, self.right, self.maxDelta) + .map_err(|e| format!("{}: {}", self.error, e.format_with_decimals(&self.decimals)))?) + } +} + +impl Cheatcode for assertApproxEqAbsDecimal_2Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + Ok(int_assert_approx_eq_abs(self.left, self.right, self.maxDelta) + .map_err(|e| format!("Assertion failed: {}", e.format_with_decimals(&self.decimals)))?) + } +} + +impl Cheatcode for assertApproxEqAbsDecimal_3Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + Ok(int_assert_approx_eq_abs(self.left, self.right, self.maxDelta) + .map_err(|e| format!("{}: {}", self.error, e.format_with_decimals(&self.decimals)))?) } } @@ -695,7 +927,7 @@ fn assert_eq<'a, T: PartialEq>(left: &'a T, right: &'a T) -> ComparisonResult<'a if left == right { Ok(Default::default()) } else { - Err(ComparisonAssertionError::Eq(left, right)) + Err(ComparisonAssertionError::Eq { left, right }) } } @@ -703,7 +935,7 @@ fn assert_not_eq<'a, T: PartialEq>(left: &'a T, right: &'a T) -> ComparisonResul if left != right { Ok(Default::default()) } else { - Err(ComparisonAssertionError::NotEq(left, right)) + Err(ComparisonAssertionError::NotEq { left, right }) } } @@ -711,13 +943,13 @@ fn uint_assert_approx_eq_abs( left: U256, right: U256, max_delta: U256, -) -> Result, ApproxAssertionError> { +) -> Result, Box>> { let delta = if left > right { left - right } else { right - left }; if delta <= max_delta { Ok(Default::default()) } else { - Err(ApproxAssertionError::EqAbs { left, right, expected_delta: max_delta, delta }) + Err(Box::new(EqAbsAssertionError { left, right, max_delta, real_delta: delta })) } } @@ -725,7 +957,7 @@ fn int_assert_approx_eq_abs( left: I256, right: I256, max_delta: U256, -) -> Result, ApproxAssertionError> { +) -> Result, Box>> { let (left_sign, left_abs) = left.into_sign_and_abs(); let (right_sign, right_abs) = right.into_sign_and_abs(); @@ -742,7 +974,7 @@ fn int_assert_approx_eq_abs( if delta <= max_delta { Ok(Default::default()) } else { - Err(ApproxAssertionError::EqAbs { left, right, expected_delta: max_delta, delta }) + Err(Box::new(EqAbsAssertionError { left, right, max_delta, real_delta: delta })) } } @@ -750,7 +982,7 @@ fn assert_gt<'a, T: PartialOrd>(left: &'a T, right: &'a T) -> ComparisonResult<' if left > right { Ok(Default::default()) } else { - Err(ComparisonAssertionError::Gt(left, right)) + Err(ComparisonAssertionError::Gt { left, right }) } } @@ -758,7 +990,7 @@ fn assert_ge<'a, T: PartialOrd>(left: &'a T, right: &'a T) -> ComparisonResult<' if left >= right { Ok(Default::default()) } else { - Err(ComparisonAssertionError::Ge(left, right)) + Err(ComparisonAssertionError::Ge { left, right }) } } @@ -766,7 +998,7 @@ fn assert_lt<'a, T: PartialOrd>(left: &'a T, right: &'a T) -> ComparisonResult<' if left < right { Ok(Default::default()) } else { - Err(ComparisonAssertionError::Lt(left, right)) + Err(ComparisonAssertionError::Lt { left, right }) } } @@ -774,6 +1006,6 @@ fn assert_le<'a, T: PartialOrd>(left: &'a T, right: &'a T) -> ComparisonResult<' if left <= right { Ok(Default::default()) } else { - Err(ComparisonAssertionError::Le(left, right)) + Err(ComparisonAssertionError::Le { left, right }) } } diff --git a/crates/evm/core/src/abi/console.rs b/crates/evm/core/src/abi/console.rs index 54014359b9dd..e9757a4768de 100644 --- a/crates/evm/core/src/abi/console.rs +++ b/crates/evm/core/src/abi/console.rs @@ -77,12 +77,12 @@ interface Console { } } -fn format_units_int(x: &I256, decimals: &U256) -> String { +pub fn format_units_int(x: &I256, decimals: &U256) -> String { let (sign, x) = x.into_sign_and_abs(); format!("{sign}{}", format_units_uint(&x, decimals)) } -fn format_units_uint(x: &U256, decimals: &U256) -> String { +pub fn format_units_uint(x: &U256, decimals: &U256) -> String { match alloy_primitives::utils::Unit::new(decimals.saturating_to::()) { Some(units) => alloy_primitives::utils::ParseUnits::U256(*x).format_units(units), None => x.to_string(), diff --git a/crates/evm/core/src/abi/mod.rs b/crates/evm/core/src/abi/mod.rs index 39566cf796fc..54f35c966af2 100644 --- a/crates/evm/core/src/abi/mod.rs +++ b/crates/evm/core/src/abi/mod.rs @@ -3,7 +3,7 @@ pub use foundry_cheatcodes_spec::Vm; mod console; -pub use console::Console; +pub use console::{format_units_int, format_units_uint, Console}; mod hardhat_console; pub use hardhat_console::{ diff --git a/testdata/cheats/Vm.sol b/testdata/cheats/Vm.sol index e1c46224cf7e..4837963c2905 100644 --- a/testdata/cheats/Vm.sol +++ b/testdata/cheats/Vm.sol @@ -25,10 +25,18 @@ interface Vm { function activeFork() external view returns (uint256 forkId); function addr(uint256 privateKey) external pure returns (address keyAddr); function allowCheatcodes(address account) external; + function assertApproxEqAbsDecimal(uint256 left, uint256 right, uint256 maxDelta, uint256 decimals) external pure; + function assertApproxEqAbsDecimal(uint256 left, uint256 right, uint256 maxDelta, uint256 decimals, string calldata error) external pure; + function assertApproxEqAbsDecimal(int256 left, int256 right, uint256 maxDelta, uint256 decimals) external pure; + function assertApproxEqAbsDecimal(int256 left, int256 right, uint256 maxDelta, uint256 decimals, string calldata error) external pure; function assertApproxEqAbs(uint256 left, uint256 right, uint256 maxDelta) external pure; function assertApproxEqAbs(uint256 left, uint256 right, uint256 maxDelta, string calldata error) external pure; function assertApproxEqAbs(int256 left, int256 right, uint256 maxDelta) external pure; function assertApproxEqAbs(int256 left, int256 right, uint256 maxDelta, string calldata error) external pure; + function assertEqDecimal(uint256 left, uint256 right, uint256 decimals) external pure; + function assertEqDecimal(uint256 left, uint256 right, uint256 decimals, string calldata error) external pure; + function assertEqDecimal(int256 left, int256 right, uint256 decimals) external pure; + function assertEqDecimal(int256 left, int256 right, uint256 decimals, string calldata error) external pure; function assertEq(bool left, bool right) external pure; function assertEq(bool left, bool right, string calldata error) external pure; function assertEq(string calldata left, string calldata right) external pure; @@ -59,22 +67,42 @@ interface Vm { function assertEq(bytes32 left, bytes32 right, string calldata error) external pure; function assertFalse(bool condition) external pure; function assertFalse(bool condition, string calldata error) external pure; + function assertGeDecimal(uint256 left, uint256 right, uint256 decimals) external pure; + function assertGeDecimal(uint256 left, uint256 right, uint256 decimals, string calldata error) external pure; + function assertGeDecimal(int256 left, int256 right, uint256 decimals) external pure; + function assertGeDecimal(int256 left, int256 right, uint256 decimals, string calldata error) external pure; function assertGe(uint256 left, uint256 right) external pure; function assertGe(uint256 left, uint256 right, string calldata error) external pure; function assertGe(int256 left, int256 right) external pure; function assertGe(int256 left, int256 right, string calldata error) external pure; + function assertGtDecimal(uint256 left, uint256 right, uint256 decimals) external pure; + function assertGtDecimal(uint256 left, uint256 right, uint256 decimals, string calldata error) external pure; + function assertGtDecimal(int256 left, int256 right, uint256 decimals) external pure; + function assertGtDecimal(int256 left, int256 right, uint256 decimals, string calldata error) external pure; function assertGt(uint256 left, uint256 right) external pure; function assertGt(uint256 left, uint256 right, string calldata error) external pure; function assertGt(int256 left, int256 right) external pure; function assertGt(int256 left, int256 right, string calldata error) external pure; + function assertLeDecimal(uint256 left, uint256 right, uint256 decimals) external pure; + function assertLeDecimal(uint256 left, uint256 right, uint256 decimals, string calldata error) external pure; + function assertLeDecimal(int256 left, int256 right, uint256 decimals) external pure; + function assertLeDecimal(int256 left, int256 right, uint256 decimals, string calldata error) external pure; function assertLe(uint256 left, uint256 right) external pure; function assertLe(uint256 left, uint256 right, string calldata error) external pure; function assertLe(int256 left, int256 right) external pure; function assertLe(int256 left, int256 right, string calldata error) external pure; + function assertLtDecimal(uint256 left, uint256 right, uint256 decimals) external pure; + function assertLtDecimal(uint256 left, uint256 right, uint256 decimals, string calldata error) external pure; + function assertLtDecimal(int256 left, int256 right, uint256 decimals) external pure; + function assertLtDecimal(int256 left, int256 right, uint256 decimals, string calldata error) external pure; function assertLt(uint256 left, uint256 right) external pure; function assertLt(uint256 left, uint256 right, string calldata error) external pure; function assertLt(int256 left, int256 right) external pure; function assertLt(int256 left, int256 right, string calldata error) external pure; + function assertNotEqDecimal(uint256 left, uint256 right, uint256 decimals) external pure; + function assertNotEqDecimal(uint256 left, uint256 right, uint256 decimals, string calldata error) external pure; + function assertNotEqDecimal(int256 left, int256 right, uint256 decimals) external pure; + function assertNotEqDecimal(int256 left, int256 right, uint256 decimals, string calldata error) external pure; function assertNotEq(bool left, bool right) external pure; function assertNotEq(bool left, bool right, string calldata error) external pure; function assertNotEq(string calldata left, string calldata right) external pure; From c0922368900ebea9a6ed17a5d46201e20a840658 Mon Sep 17 00:00:00 2001 From: Arsenii Kulikov Date: Tue, 16 Jan 2024 21:20:02 +0400 Subject: [PATCH 11/19] Some fixes --- crates/cheatcodes/src/test/assert.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/crates/cheatcodes/src/test/assert.rs b/crates/cheatcodes/src/test/assert.rs index eade07b87757..a9d79071923c 100644 --- a/crates/cheatcodes/src/test/assert.rs +++ b/crates/cheatcodes/src/test/assert.rs @@ -12,7 +12,7 @@ struct SimpleAssertionError; #[derive(thiserror::Error, Debug)] enum ComparisonAssertionError<'a, T> { - NotEq { left: &'a T, right: &'a T }, + Ne { left: &'a T, right: &'a T }, Eq { left: &'a T, right: &'a T }, Ge { left: &'a T, right: &'a T }, Gt { left: &'a T, right: &'a T }, @@ -23,7 +23,7 @@ enum ComparisonAssertionError<'a, T> { macro_rules! format_values { ($self:expr, $format_fn:expr) => { match $self { - Self::NotEq { left, right } => format!("{} == {}", $format_fn(left), $format_fn(right)), + Self::Ne { left, right } => format!("{} == {}", $format_fn(left), $format_fn(right)), Self::Eq { left, right } => format!("{} != {}", $format_fn(left), $format_fn(right)), Self::Ge { left, right } => format!("{} < {}", $format_fn(left), $format_fn(right)), Self::Gt { left, right } => format!("{} <= {}", $format_fn(left), $format_fn(right)), @@ -42,26 +42,29 @@ impl<'a, T: Display> ComparisonAssertionError<'a, T> { #[allow(clippy::redundant_closure_call)] impl<'a, T: Display> ComparisonAssertionError<'a, Vec> { fn format_for_arrays(&self) -> String { - format_values!(self, |v: &Vec| format!("[{}]", v.iter().join(", "))) + let formatter = |v: &Vec| v.iter().format(", ").to_string(); + format_values!(self, formatter) } } #[allow(clippy::redundant_closure_call)] impl<'a> ComparisonAssertionError<'a, U256> { fn format_with_decimals(&self, decimals: &U256) -> String { - format_values!(self, |v: &U256| format_units_uint(v, decimals)) + let formatter = |v: &U256| format_units_uint(v, decimals); + format_values!(self, formatter) } } #[allow(clippy::redundant_closure_call)] impl<'a> ComparisonAssertionError<'a, I256> { fn format_with_decimals(&self, decimals: &U256) -> String { - format_values!(self, |v: &I256| format_units_int(v, decimals)) + let formatter = |v: &I256| format_units_int(v, decimals); + format_values!(self, formatter) } } #[derive(thiserror::Error, Debug)] -#[error("Assertion failed: {left} !~= {right} (max delta: {max_delta}, real delta: {real_delta})")] +#[error("{left} !~= {right} (max delta: {max_delta}, real delta: {real_delta})")] struct EqAbsAssertionError { left: T, right: T, @@ -935,7 +938,7 @@ fn assert_not_eq<'a, T: PartialEq>(left: &'a T, right: &'a T) -> ComparisonResul if left != right { Ok(Default::default()) } else { - Err(ComparisonAssertionError::NotEq { left, right }) + Err(ComparisonAssertionError::Ne { left, right }) } } From 9b248ff023f61bf6bea3b551cfa00f839eefb247 Mon Sep 17 00:00:00 2001 From: Arsenii Kulikov Date: Tue, 16 Jan 2024 21:21:47 +0400 Subject: [PATCH 12/19] chore: remove allows --- crates/cheatcodes/src/test/assert.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/crates/cheatcodes/src/test/assert.rs b/crates/cheatcodes/src/test/assert.rs index a9d79071923c..06ba1902abda 100644 --- a/crates/cheatcodes/src/test/assert.rs +++ b/crates/cheatcodes/src/test/assert.rs @@ -39,7 +39,6 @@ impl<'a, T: Display> ComparisonAssertionError<'a, T> { } } -#[allow(clippy::redundant_closure_call)] impl<'a, T: Display> ComparisonAssertionError<'a, Vec> { fn format_for_arrays(&self) -> String { let formatter = |v: &Vec| v.iter().format(", ").to_string(); @@ -47,7 +46,6 @@ impl<'a, T: Display> ComparisonAssertionError<'a, Vec> { } } -#[allow(clippy::redundant_closure_call)] impl<'a> ComparisonAssertionError<'a, U256> { fn format_with_decimals(&self, decimals: &U256) -> String { let formatter = |v: &U256| format_units_uint(v, decimals); @@ -55,7 +53,6 @@ impl<'a> ComparisonAssertionError<'a, U256> { } } -#[allow(clippy::redundant_closure_call)] impl<'a> ComparisonAssertionError<'a, I256> { fn format_with_decimals(&self, decimals: &U256) -> String { let formatter = |v: &I256| format_units_int(v, decimals); From fda8bfee05fd42f85f8fa34ba1d2b0e1e189df8a Mon Sep 17 00:00:00 2001 From: Arsenii Kulikov Date: Wed, 17 Jan 2024 03:19:21 +0400 Subject: [PATCH 13/19] assertApproxEqRel cheatcodes --- crates/cheatcodes/assets/cheatcodes.json | 160 +++++++++++++++++++ crates/cheatcodes/spec/src/vm.rs | 68 ++++++++ crates/cheatcodes/src/test/assert.rs | 194 +++++++++++++++++++++-- testdata/cheats/Vm.sol | 8 + 4 files changed, 418 insertions(+), 12 deletions(-) diff --git a/crates/cheatcodes/assets/cheatcodes.json b/crates/cheatcodes/assets/cheatcodes.json index d6f5a5941171..6ccbcd21f968 100644 --- a/crates/cheatcodes/assets/cheatcodes.json +++ b/crates/cheatcodes/assets/cheatcodes.json @@ -713,6 +713,166 @@ "status": "stable", "safety": "safe" }, + { + "func": { + "id": "assertApproxEqRelDecimal_0", + "description": "Compares two `uint256` values. Expects relative difference in percents to be less than or equal to `maxPercentDelta`.\n`maxPercentDelta` is an 18 decimal fixed point number, where 1e18 == 100%\nFormats values with decimals in failure message.", + "declaration": "function assertApproxEqRelDecimal(uint256 left, uint256 right, uint256 maxPercentDelta, uint256 decimals) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertApproxEqRelDecimal(uint256,uint256,uint256,uint256)", + "selector": "0x21ed2977", + "selectorBytes": [ + 33, + 237, + 41, + 119 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertApproxEqRelDecimal_1", + "description": "Compares two `uint256` values. Expects relative difference in percents to be less than or equal to `maxPercentDelta`.\n`maxPercentDelta` is an 18 decimal fixed point number, where 1e18 == 100%\nFormats values with decimals in failure message. Includes error message into revert string on failure.", + "declaration": "function assertApproxEqRelDecimal(uint256 left, uint256 right, uint256 maxPercentDelta, uint256 decimals, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertApproxEqRelDecimal(uint256,uint256,uint256,uint256,string)", + "selector": "0x82d6c8fd", + "selectorBytes": [ + 130, + 214, + 200, + 253 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertApproxEqRelDecimal_2", + "description": "Compares two `int256` values. Expects relative difference in percents to be less than or equal to `maxPercentDelta`.\n`maxPercentDelta` is an 18 decimal fixed point number, where 1e18 == 100%\nFormats values with decimals in failure message.", + "declaration": "function assertApproxEqRelDecimal(int256 left, int256 right, uint256 maxPercentDelta, uint256 decimals) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertApproxEqRelDecimal(int256,int256,uint256,uint256)", + "selector": "0xabbf21cc", + "selectorBytes": [ + 171, + 191, + 33, + 204 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertApproxEqRelDecimal_3", + "description": "Compares two `int256` values. Expects relative difference in percents to be less than or equal to `maxPercentDelta`.\n`maxPercentDelta` is an 18 decimal fixed point number, where 1e18 == 100%\nFormats values with decimals in failure message. Includes error message into revert string on failure.", + "declaration": "function assertApproxEqRelDecimal(int256 left, int256 right, uint256 maxPercentDelta, uint256 decimals, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertApproxEqRelDecimal(int256,int256,uint256,uint256,string)", + "selector": "0xfccc11c4", + "selectorBytes": [ + 252, + 204, + 17, + 196 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertApproxEqRel_0", + "description": "Compares two `uint256` values. Expects relative difference in percents to be less than or equal to `maxPercentDelta`.\n`maxPercentDelta` is an 18 decimal fixed point number, where 1e18 == 100%", + "declaration": "function assertApproxEqRel(uint256 left, uint256 right, uint256 maxPercentDelta) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertApproxEqRel(uint256,uint256,uint256)", + "selector": "0x8cf25ef4", + "selectorBytes": [ + 140, + 242, + 94, + 244 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertApproxEqRel_1", + "description": "Compares two `uint256` values. Expects relative difference in percents to be less than or equal to `maxPercentDelta`.\n`maxPercentDelta` is an 18 decimal fixed point number, where 1e18 == 100%\nIncludes error message into revert string on failure.", + "declaration": "function assertApproxEqRel(uint256 left, uint256 right, uint256 maxPercentDelta, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertApproxEqRel(uint256,uint256,uint256,string)", + "selector": "0x1ecb7d33", + "selectorBytes": [ + 30, + 203, + 125, + 51 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertApproxEqRel_2", + "description": "Compares two `int256` values. Expects relative difference in percents to be less than or equal to `maxPercentDelta`.\n`maxPercentDelta` is an 18 decimal fixed point number, where 1e18 == 100%", + "declaration": "function assertApproxEqRel(int256 left, int256 right, uint256 maxPercentDelta) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertApproxEqRel(int256,int256,uint256)", + "selector": "0xfea2d14f", + "selectorBytes": [ + 254, + 162, + 209, + 79 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "assertApproxEqRel_3", + "description": "Compares two `int256` values. Expects relative difference in percents to be less than or equal to `maxPercentDelta`.\n`maxPercentDelta` is an 18 decimal fixed point number, where 1e18 == 100%\nIncludes error message into revert string on failure.", + "declaration": "function assertApproxEqRel(int256 left, int256 right, uint256 maxPercentDelta, string calldata error) external pure;", + "visibility": "external", + "mutability": "pure", + "signature": "assertApproxEqRel(int256,int256,uint256,string)", + "selector": "0xef277d72", + "selectorBytes": [ + 239, + 39, + 125, + 114 + ] + }, + "group": "testing", + "status": "stable", + "safety": "safe" + }, { "func": { "id": "assertEqDecimal_0", diff --git a/crates/cheatcodes/spec/src/vm.rs b/crates/cheatcodes/spec/src/vm.rs index 15564e9bfd98..69f1e084572d 100644 --- a/crates/cheatcodes/spec/src/vm.rs +++ b/crates/cheatcodes/spec/src/vm.rs @@ -1189,6 +1189,74 @@ interface Vm { string calldata error ) external pure; + /// Compares two `uint256` values. Expects relative difference in percents to be less than or equal to `maxPercentDelta`. + /// `maxPercentDelta` is an 18 decimal fixed point number, where 1e18 == 100% + #[cheatcode(group = Testing, safety = Safe)] + function assertApproxEqRel(uint256 left, uint256 right, uint256 maxPercentDelta) external pure; + + /// Compares two `uint256` values. Expects relative difference in percents to be less than or equal to `maxPercentDelta`. + /// `maxPercentDelta` is an 18 decimal fixed point number, where 1e18 == 100% + /// Includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertApproxEqRel(uint256 left, uint256 right, uint256 maxPercentDelta, string calldata error) external pure; + + /// Compares two `int256` values. Expects relative difference in percents to be less than or equal to `maxPercentDelta`. + /// `maxPercentDelta` is an 18 decimal fixed point number, where 1e18 == 100% + #[cheatcode(group = Testing, safety = Safe)] + function assertApproxEqRel(int256 left, int256 right, uint256 maxPercentDelta) external pure; + + /// Compares two `int256` values. Expects relative difference in percents to be less than or equal to `maxPercentDelta`. + /// `maxPercentDelta` is an 18 decimal fixed point number, where 1e18 == 100% + /// Includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertApproxEqRel(int256 left, int256 right, uint256 maxPercentDelta, string calldata error) external pure; + + /// Compares two `uint256` values. Expects relative difference in percents to be less than or equal to `maxPercentDelta`. + /// `maxPercentDelta` is an 18 decimal fixed point number, where 1e18 == 100% + /// Formats values with decimals in failure message. + #[cheatcode(group = Testing, safety = Safe)] + function assertApproxEqRelDecimal( + uint256 left, + uint256 right, + uint256 maxPercentDelta, + uint256 decimals + ) external pure; + + /// Compares two `uint256` values. Expects relative difference in percents to be less than or equal to `maxPercentDelta`. + /// `maxPercentDelta` is an 18 decimal fixed point number, where 1e18 == 100% + /// Formats values with decimals in failure message. Includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertApproxEqRelDecimal( + uint256 left, + uint256 right, + uint256 maxPercentDelta, + uint256 decimals, + string calldata error + ) external pure; + + /// Compares two `int256` values. Expects relative difference in percents to be less than or equal to `maxPercentDelta`. + /// `maxPercentDelta` is an 18 decimal fixed point number, where 1e18 == 100% + /// Formats values with decimals in failure message. + #[cheatcode(group = Testing, safety = Safe)] + function assertApproxEqRelDecimal( + int256 left, + int256 right, + uint256 maxPercentDelta, + uint256 decimals + ) external pure; + + /// Compares two `int256` values. Expects relative difference in percents to be less than or equal to `maxPercentDelta`. + /// `maxPercentDelta` is an 18 decimal fixed point number, where 1e18 == 100% + /// Formats values with decimals in failure message. Includes error message into revert string on failure. + #[cheatcode(group = Testing, safety = Safe)] + function assertApproxEqRelDecimal( + int256 left, + int256 right, + uint256 maxPercentDelta, + uint256 decimals, + string calldata error + ) external pure; + // ======== OS and Filesystem ======== // -------- Metadata -------- diff --git a/crates/cheatcodes/src/test/assert.rs b/crates/cheatcodes/src/test/assert.rs index 06ba1902abda..333d864309d6 100644 --- a/crates/cheatcodes/src/test/assert.rs +++ b/crates/cheatcodes/src/test/assert.rs @@ -6,6 +6,8 @@ use itertools::Itertools; use crate::{Cheatcode, Cheatcodes, Result, Vm::*}; +const EQ_REL_DELTA_RESOLUTION: U256 = U256::from_limbs([18, 0, 0, 0]); + #[derive(Debug, thiserror::Error)] #[error("Assertion failed")] struct SimpleAssertionError; @@ -93,6 +95,61 @@ impl EqAbsAssertionError { } } +fn format_delta_percent(delta: &U256) -> String { + format!("{}%", format_units_uint(delta, &(EQ_REL_DELTA_RESOLUTION - U256::from(2)))) +} + +#[derive(thiserror::Error, Debug)] +#[error( + "{left} !~= {right} (max delta: {}, real delta: {})", + format_delta_percent(max_delta), + format_delta_percent(real_delta) +)] +struct EqRelAssertionFailure { + left: T, + right: T, + max_delta: U256, + real_delta: U256, +} + +#[derive(thiserror::Error, Debug)] +enum EqRelAssertionError { + #[error(transparent)] + Failure(Box>), + #[error("Overflow in delta calculation")] + Overflow, +} + +impl EqRelAssertionError { + fn format_with_decimals(&self, decimals: &U256) -> String { + match self { + Self::Failure(f) => format!( + "{} !~= {} (max delta: {}, real delta: {})", + format_units_uint(&f.left, decimals), + format_units_uint(&f.right, decimals), + format_delta_percent(&f.max_delta), + format_delta_percent(&f.real_delta), + ), + Self::Overflow => self.to_string(), + } + } +} + +impl EqRelAssertionError { + fn format_with_decimals(&self, decimals: &U256) -> String { + match self { + Self::Failure(f) => format!( + "{} !~= {} (max delta: {}, real delta: {})", + format_units_int(&f.left, decimals), + format_units_int(&f.right, decimals), + format_delta_percent(&f.max_delta), + format_delta_percent(&f.real_delta), + ), + Self::Overflow => self.to_string(), + } + } +} + type ComparisonResult<'a, T> = Result, ComparisonAssertionError<'a, T>>; impl Cheatcode for assertTrue_0Call { @@ -907,6 +964,62 @@ impl Cheatcode for assertApproxEqAbsDecimal_3Call { } } +impl Cheatcode for assertApproxEqRel_0Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + Ok(uint_assert_approx_eq_rel(self.left, self.right, self.maxPercentDelta) + .map_err(|e| format!("Assertion failed: {}", e))?) + } +} + +impl Cheatcode for assertApproxEqRel_1Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + Ok(uint_assert_approx_eq_rel(self.left, self.right, self.maxPercentDelta) + .map_err(|e| format!("{}: {}", self.error, e))?) + } +} + +impl Cheatcode for assertApproxEqRel_2Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + Ok(int_assert_approx_eq_rel(self.left, self.right, self.maxPercentDelta) + .map_err(|e| format!("Assertion failed: {}", e))?) + } +} + +impl Cheatcode for assertApproxEqRel_3Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + Ok(int_assert_approx_eq_rel(self.left, self.right, self.maxPercentDelta) + .map_err(|e| format!("{}: {}", self.error, e))?) + } +} + +impl Cheatcode for assertApproxEqRelDecimal_0Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + Ok(uint_assert_approx_eq_rel(self.left, self.right, self.maxPercentDelta) + .map_err(|e| format!("Assertion failed: {}", e.format_with_decimals(&self.decimals)))?) + } +} + +impl Cheatcode for assertApproxEqRelDecimal_1Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + Ok(uint_assert_approx_eq_rel(self.left, self.right, self.maxPercentDelta) + .map_err(|e| format!("{}: {}", self.error, e.format_with_decimals(&self.decimals)))?) + } +} + +impl Cheatcode for assertApproxEqRelDecimal_2Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + Ok(int_assert_approx_eq_rel(self.left, self.right, self.maxPercentDelta) + .map_err(|e| format!("Assertion failed: {}", e.format_with_decimals(&self.decimals)))?) + } +} + +impl Cheatcode for assertApproxEqRelDecimal_3Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + Ok(int_assert_approx_eq_rel(self.left, self.right, self.maxPercentDelta) + .map_err(|e| format!("{}: {}", self.error, e.format_with_decimals(&self.decimals)))?) + } +} + fn assert_true(condition: bool) -> Result, SimpleAssertionError> { if condition { Ok(Default::default()) @@ -939,12 +1052,35 @@ fn assert_not_eq<'a, T: PartialEq>(left: &'a T, right: &'a T) -> ComparisonResul } } +fn get_delta_uint(left: U256, right: U256) -> U256 { + if left > right { + left - right + } else { + right - left + } +} + +fn get_delta_int(left: I256, right: I256) -> U256 { + let (left_sign, left_abs) = left.into_sign_and_abs(); + let (right_sign, right_abs) = right.into_sign_and_abs(); + + if left_sign == right_sign { + if left_abs > right_abs { + left_abs - right_abs + } else { + right_abs - left_abs + } + } else { + left_abs + right_abs + } +} + fn uint_assert_approx_eq_abs( left: U256, right: U256, max_delta: U256, ) -> Result, Box>> { - let delta = if left > right { left - right } else { right - left }; + let delta = get_delta_uint(left, right); if delta <= max_delta { Ok(Default::default()) @@ -958,23 +1094,57 @@ fn int_assert_approx_eq_abs( right: I256, max_delta: U256, ) -> Result, Box>> { - let (left_sign, left_abs) = left.into_sign_and_abs(); - let (right_sign, right_abs) = right.into_sign_and_abs(); + let delta = get_delta_int(left, right); - let delta = if left_sign == right_sign { - if left_abs > right_abs { - left_abs - right_abs - } else { - right_abs - left_abs - } + if delta <= max_delta { + Ok(Default::default()) } else { - left_abs + right_abs - }; + Err(Box::new(EqAbsAssertionError { left, right, max_delta, real_delta: delta })) + } +} + +fn uint_assert_approx_eq_rel( + left: U256, + right: U256, + max_delta: U256, +) -> Result, EqRelAssertionError> { + let delta = get_delta_uint(left, right) + .checked_mul(U256::pow(U256::from(10), EQ_REL_DELTA_RESOLUTION)) + .ok_or(EqRelAssertionError::Overflow)? / + right; if delta <= max_delta { Ok(Default::default()) } else { - Err(Box::new(EqAbsAssertionError { left, right, max_delta, real_delta: delta })) + Err(EqRelAssertionError::Failure(Box::new(EqRelAssertionFailure { + left, + right, + max_delta, + real_delta: delta, + }))) + } +} + +fn int_assert_approx_eq_rel( + left: I256, + right: I256, + max_delta: U256, +) -> Result, EqRelAssertionError> { + let (_, abs_right) = right.into_sign_and_abs(); + let delta = get_delta_int(left, right) + .checked_mul(U256::pow(U256::from(10), EQ_REL_DELTA_RESOLUTION)) + .ok_or(EqRelAssertionError::Overflow)? / + abs_right; + + if delta <= max_delta { + Ok(Default::default()) + } else { + Err(EqRelAssertionError::Failure(Box::new(EqRelAssertionFailure { + left, + right, + max_delta, + real_delta: delta, + }))) } } diff --git a/testdata/cheats/Vm.sol b/testdata/cheats/Vm.sol index 4837963c2905..ed1563aa2b76 100644 --- a/testdata/cheats/Vm.sol +++ b/testdata/cheats/Vm.sol @@ -33,6 +33,14 @@ interface Vm { function assertApproxEqAbs(uint256 left, uint256 right, uint256 maxDelta, string calldata error) external pure; function assertApproxEqAbs(int256 left, int256 right, uint256 maxDelta) external pure; function assertApproxEqAbs(int256 left, int256 right, uint256 maxDelta, string calldata error) external pure; + function assertApproxEqRelDecimal(uint256 left, uint256 right, uint256 maxPercentDelta, uint256 decimals) external pure; + function assertApproxEqRelDecimal(uint256 left, uint256 right, uint256 maxPercentDelta, uint256 decimals, string calldata error) external pure; + function assertApproxEqRelDecimal(int256 left, int256 right, uint256 maxPercentDelta, uint256 decimals) external pure; + function assertApproxEqRelDecimal(int256 left, int256 right, uint256 maxPercentDelta, uint256 decimals, string calldata error) external pure; + function assertApproxEqRel(uint256 left, uint256 right, uint256 maxPercentDelta) external pure; + function assertApproxEqRel(uint256 left, uint256 right, uint256 maxPercentDelta, string calldata error) external pure; + function assertApproxEqRel(int256 left, int256 right, uint256 maxPercentDelta) external pure; + function assertApproxEqRel(int256 left, int256 right, uint256 maxPercentDelta, string calldata error) external pure; function assertEqDecimal(uint256 left, uint256 right, uint256 decimals) external pure; function assertEqDecimal(uint256 left, uint256 right, uint256 decimals, string calldata error) external pure; function assertEqDecimal(int256 left, int256 right, uint256 decimals) external pure; From 0cb07fd5b261734adfe06eadbc06c48cc6e351dc Mon Sep 17 00:00:00 2001 From: Arsenii Kulikov Date: Wed, 17 Jan 2024 13:51:58 +0400 Subject: [PATCH 14/19] Remove unneccesary conversions --- crates/cheatcodes/src/test/assert.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/crates/cheatcodes/src/test/assert.rs b/crates/cheatcodes/src/test/assert.rs index 333d864309d6..fb3a7c2c6582 100644 --- a/crates/cheatcodes/src/test/assert.rs +++ b/crates/cheatcodes/src/test/assert.rs @@ -254,7 +254,7 @@ impl Cheatcode for assertEq_9Call { impl Cheatcode for assertEq_10Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { left, right } = self; - Ok(assert_eq(&hex::encode_prefixed(left), &hex::encode_prefixed(right)) + Ok(assert_eq(left, right) .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) } } @@ -262,8 +262,7 @@ impl Cheatcode for assertEq_10Call { impl Cheatcode for assertEq_11Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { left, right, error } = self; - Ok(assert_eq(&hex::encode_prefixed(left), &hex::encode_prefixed(right)) - .map_err(|e| format!("{}: {}", error, e.format_for_values()))?) + Ok(assert_eq(left, right).map_err(|e| format!("{}: {}", error, e.format_for_values()))?) } } @@ -1109,7 +1108,7 @@ fn uint_assert_approx_eq_rel( max_delta: U256, ) -> Result, EqRelAssertionError> { let delta = get_delta_uint(left, right) - .checked_mul(U256::pow(U256::from(10), EQ_REL_DELTA_RESOLUTION)) + .checked_mul(U256::pow(U256::from(10), EQ_REL_DELTA_RESOLUTION)) .ok_or(EqRelAssertionError::Overflow)? / right; From 9e54c155907ffb330cf76cbe9a2481ce79302929 Mon Sep 17 00:00:00 2001 From: Arsenii Kulikov Date: Tue, 23 Jan 2024 00:31:41 +0200 Subject: [PATCH 15/19] Fix formatting --- crates/cheatcodes/src/test/assert.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/cheatcodes/src/test/assert.rs b/crates/cheatcodes/src/test/assert.rs index fb3a7c2c6582..09791f2018ec 100644 --- a/crates/cheatcodes/src/test/assert.rs +++ b/crates/cheatcodes/src/test/assert.rs @@ -43,7 +43,7 @@ impl<'a, T: Display> ComparisonAssertionError<'a, T> { impl<'a, T: Display> ComparisonAssertionError<'a, Vec> { fn format_for_arrays(&self) -> String { - let formatter = |v: &Vec| v.iter().format(", ").to_string(); + let formatter = |v: &Vec| format!("[{}]", v.iter().format(", ").to_string()); format_values!(self, formatter) } } @@ -1109,8 +1109,7 @@ fn uint_assert_approx_eq_rel( ) -> Result, EqRelAssertionError> { let delta = get_delta_uint(left, right) .checked_mul(U256::pow(U256::from(10), EQ_REL_DELTA_RESOLUTION)) - .ok_or(EqRelAssertionError::Overflow)? / - right; + .ok_or(EqRelAssertionError::Overflow)?.checked_div(right).ok_or(EqRelAssertionError::Overflow)?; if delta <= max_delta { Ok(Default::default()) @@ -1132,8 +1131,9 @@ fn int_assert_approx_eq_rel( let (_, abs_right) = right.into_sign_and_abs(); let delta = get_delta_int(left, right) .checked_mul(U256::pow(U256::from(10), EQ_REL_DELTA_RESOLUTION)) - .ok_or(EqRelAssertionError::Overflow)? / - abs_right; + .ok_or(EqRelAssertionError::Overflow)? + .checked_div(abs_right) + .ok_or(EqRelAssertionError::Overflow)?; if delta <= max_delta { Ok(Default::default()) From f00103f1c272411116e73aee7d694a13d598aa66 Mon Sep 17 00:00:00 2001 From: Arsenii Kulikov Date: Wed, 17 Jan 2024 16:20:03 +0400 Subject: [PATCH 16/19] Add tests --- testdata/cheats/Assert.t.sol | 823 +++++++++++++++++++++++++++++++++++ 1 file changed, 823 insertions(+) create mode 100644 testdata/cheats/Assert.t.sol diff --git a/testdata/cheats/Assert.t.sol b/testdata/cheats/Assert.t.sol new file mode 100644 index 000000000000..96ce5977a9a2 --- /dev/null +++ b/testdata/cheats/Assert.t.sol @@ -0,0 +1,823 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +pragma solidity 0.8.18; + +import "ds-test/test.sol"; +import "./Vm.sol"; + +contract AssertionsTest is DSTest { + string constant errorMessage = "User provided message"; + uint256 constant maxDecimals = 77; + + Vm constant vm = Vm(HEVM_ADDRESS); + + function _abs(int256 a) internal pure returns (uint256) { + // Required or it will fail when `a = type(int256).min` + if (a == type(int256).min) { + return uint256(type(int256).max) + 1; + } + + return uint256(a > 0 ? a : -a); + } + + function _getDelta(uint256 a, uint256 b) internal pure returns (uint256) { + return a > b ? a - b : b - a; + } + + function _getDelta(int256 a, int256 b) internal pure returns (uint256) { + // a and b are of the same sign + // this works thanks to two's complement, the left-most bit is the sign bit + if ((a ^ b) > -1) { + return _getDelta(_abs(a), _abs(b)); + } + + // a and b are of opposite signs + return _abs(a) + _abs(b); + } + + function _prefixDecWithZeroes(string memory intPart, string memory decimalPart, uint256 decimals) + internal + returns (string memory) + { + while (bytes(decimalPart).length < decimals) { + decimalPart = string.concat("0", decimalPart); + } + + return string.concat(intPart, ".", decimalPart); + } + + function _formatWithDecimals(uint256 value, uint256 decimals) internal returns (string memory) { + string memory intPart = vm.toString(value / (10 ** decimals)); + string memory decimalPart = vm.toString(value % (10 ** decimals)); + + return _prefixDecWithZeroes(intPart, decimalPart, decimals); + } + + function _formatWithDecimals(int256 value, uint256 decimals) internal returns (string memory) { + string memory intPart = vm.toString(value / int256(10 ** decimals)); + int256 mod = value % int256(10 ** decimals); + string memory decimalPart = vm.toString(mod > 0 ? mod : -mod); + + // Add - if we have something like 0.123 + if ((value < 0) && keccak256(abi.encode(intPart)) == keccak256(abi.encode("0"))) { + intPart = string.concat("-", intPart); + } + + return _prefixDecWithZeroes(intPart, decimalPart, decimals); + } + + function testFuzzAssertEqNotEq(uint256 left, uint256 right, uint256 decimals) public { + vm.assume(left != right); + vm.assume(decimals <= maxDecimals); + + vm.assertEq(left, left); + vm.assertEq(right, right); + vm.assertNotEq(left, right); + vm.assertNotEq(right, left); + + vm._expectCheatcodeRevert( + bytes(string.concat(errorMessage, ": ", vm.toString(left), " != ", vm.toString(right))) + ); + vm.assertEq(left, right, errorMessage); + + vm._expectCheatcodeRevert( + bytes(string.concat(errorMessage, ": ", vm.toString(left), " == ", vm.toString(left))) + ); + vm.assertNotEq(left, left, errorMessage); + + vm._expectCheatcodeRevert( + bytes( + string.concat( + "Assertion failed: ", + _formatWithDecimals(left, decimals), + " != ", + _formatWithDecimals(right, decimals) + ) + ) + ); + vm.assertEqDecimal(left, right, decimals); + + vm._expectCheatcodeRevert( + bytes( + string.concat( + "Assertion failed: ", + _formatWithDecimals(left, decimals), + " == ", + _formatWithDecimals(left, decimals) + ) + ) + ); + vm.assertNotEqDecimal(left, left, decimals); + } + + function testFuzzAssertEqNotEq(int256 left, int256 right, uint256 decimals) public { + vm.assume(left != right); + vm.assume(decimals <= maxDecimals); + + vm.assertEq(left, left); + vm.assertEq(right, right); + vm.assertNotEq(left, right); + vm.assertNotEq(right, left); + + vm._expectCheatcodeRevert( + bytes(string.concat(errorMessage, ": ", vm.toString(left), " != ", vm.toString(right))) + ); + vm.assertEq(left, right, errorMessage); + + vm._expectCheatcodeRevert( + bytes(string.concat(errorMessage, ": ", vm.toString(left), " == ", vm.toString(left))) + ); + vm.assertNotEq(left, left, errorMessage); + + vm._expectCheatcodeRevert( + bytes( + string.concat( + errorMessage, + ": ", + _formatWithDecimals(left, decimals), + " != ", + _formatWithDecimals(right, decimals) + ) + ) + ); + vm.assertEqDecimal(left, right, decimals, errorMessage); + + vm._expectCheatcodeRevert( + bytes( + string.concat( + errorMessage, ": ", _formatWithDecimals(left, decimals), " == ", _formatWithDecimals(left, decimals) + ) + ) + ); + vm.assertNotEqDecimal(left, left, decimals, errorMessage); + } + + function testFuzzAssertEqNotEq(bool left, bool right) public { + vm.assume(left != right); + + vm.assertEq(left, left); + vm.assertEq(right, right); + vm.assertNotEq(left, right); + vm.assertNotEq(right, left); + + vm._expectCheatcodeRevert( + bytes(string.concat(errorMessage, ": ", vm.toString(left), " != ", vm.toString(right))) + ); + vm.assertEq(left, right, errorMessage); + + vm._expectCheatcodeRevert( + bytes(string.concat(errorMessage, ": ", vm.toString(left), " == ", vm.toString(left))) + ); + vm.assertNotEq(left, left, errorMessage); + } + + function testFuzzAssertEqNotEq(address left, address right) public { + vm.assume(left != right); + + vm.assertEq(left, left); + vm.assertEq(right, right); + vm.assertNotEq(left, right); + vm.assertNotEq(right, left); + + vm._expectCheatcodeRevert( + bytes(string.concat(errorMessage, ": ", vm.toString(left), " != ", vm.toString(right))) + ); + vm.assertEq(left, right, errorMessage); + + vm._expectCheatcodeRevert( + bytes(string.concat(errorMessage, ": ", vm.toString(left), " == ", vm.toString(left))) + ); + vm.assertNotEq(left, left, errorMessage); + } + + function testFuzzAssertEqNotEq(bytes32 left, bytes32 right) public { + vm.assume(left != right); + + vm.assertEq(left, left); + vm.assertEq(right, right); + vm.assertNotEq(left, right); + vm.assertNotEq(right, left); + + vm._expectCheatcodeRevert( + bytes(string.concat(errorMessage, ": ", vm.toString(left), " != ", vm.toString(right))) + ); + vm.assertEq(left, right, errorMessage); + + vm._expectCheatcodeRevert( + bytes(string.concat(errorMessage, ": ", vm.toString(left), " == ", vm.toString(left))) + ); + vm.assertNotEq(left, left, errorMessage); + } + + function testFuzzAssertEqNotEq(string memory left, string memory right) public { + vm.assume(keccak256(abi.encodePacked(left)) != keccak256(abi.encodePacked(right))); + + vm.assertEq(left, left); + vm.assertEq(right, right); + vm.assertNotEq(left, right); + vm.assertNotEq(right, left); + + vm._expectCheatcodeRevert(bytes(string.concat(errorMessage, ": ", left, " != ", right))); + vm.assertEq(left, right, errorMessage); + + vm._expectCheatcodeRevert(bytes(string.concat(errorMessage, ": ", left, " == ", left))); + vm.assertNotEq(left, left, errorMessage); + } + + function testFuzzAssertEqNotEq(bytes memory left, bytes memory right) public { + vm.assume(keccak256(left) != keccak256(right)); + + vm.assertEq(left, left); + vm.assertEq(right, right); + vm.assertNotEq(left, right); + vm.assertNotEq(right, left); + + vm._expectCheatcodeRevert( + bytes(string.concat(errorMessage, ": ", vm.toString(left), " != ", vm.toString(right))) + ); + vm.assertEq(left, right, errorMessage); + + vm._expectCheatcodeRevert( + bytes(string.concat(errorMessage, ": ", vm.toString(left), " == ", vm.toString(left))) + ); + vm.assertNotEq(left, left, errorMessage); + } + + function testFuzzAssertGtLt(uint256 left, uint256 right, uint256 decimals) public { + vm.assume(left < right); + vm.assume(decimals <= maxDecimals); + + vm.assertGt(right, left); + vm.assertLt(left, right); + + vm._expectCheatcodeRevert( + bytes(string.concat(errorMessage, ": ", vm.toString(left), " <= ", vm.toString(right))) + ); + vm.assertGt(left, right, errorMessage); + + vm._expectCheatcodeRevert( + bytes(string.concat(errorMessage, ": ", vm.toString(right), " <= ", vm.toString(right))) + ); + vm.assertGt(right, right, errorMessage); + + vm._expectCheatcodeRevert( + bytes(string.concat(errorMessage, ": ", vm.toString(left), " >= ", vm.toString(left))) + ); + vm.assertLt(left, left, errorMessage); + + vm._expectCheatcodeRevert( + bytes(string.concat(errorMessage, ": ", vm.toString(right), " >= ", vm.toString(left))) + ); + vm.assertLt(right, left, errorMessage); + + vm._expectCheatcodeRevert( + bytes( + string.concat( + "Assertion failed: ", + _formatWithDecimals(left, decimals), + " <= ", + _formatWithDecimals(right, decimals) + ) + ) + ); + vm.assertGtDecimal(left, right, decimals); + + vm._expectCheatcodeRevert( + bytes( + string.concat( + "Assertion failed: ", + _formatWithDecimals(right, decimals), + " <= ", + _formatWithDecimals(right, decimals) + ) + ) + ); + vm.assertGtDecimal(right, right, decimals); + + vm._expectCheatcodeRevert( + bytes( + string.concat( + "Assertion failed: ", + _formatWithDecimals(left, decimals), + " >= ", + _formatWithDecimals(left, decimals) + ) + ) + ); + vm.assertLtDecimal(left, left, decimals); + + vm._expectCheatcodeRevert( + bytes( + string.concat( + "Assertion failed: ", + _formatWithDecimals(right, decimals), + " >= ", + _formatWithDecimals(left, decimals) + ) + ) + ); + vm.assertLtDecimal(right, left, decimals); + } + + function testFuzzAssertGtLt(int256 left, int256 right, uint256 decimals) public { + vm.assume(left < right); + vm.assume(decimals <= maxDecimals); + + vm.assertGt(right, left); + vm.assertLt(left, right); + + vm._expectCheatcodeRevert( + bytes(string.concat(errorMessage, ": ", vm.toString(left), " <= ", vm.toString(right))) + ); + vm.assertGt(left, right, errorMessage); + + vm._expectCheatcodeRevert( + bytes(string.concat(errorMessage, ": ", vm.toString(right), " <= ", vm.toString(right))) + ); + vm.assertGt(right, right, errorMessage); + + vm._expectCheatcodeRevert( + bytes(string.concat(errorMessage, ": ", vm.toString(left), " >= ", vm.toString(left))) + ); + vm.assertLt(left, left, errorMessage); + + vm._expectCheatcodeRevert( + bytes(string.concat(errorMessage, ": ", vm.toString(right), " >= ", vm.toString(left))) + ); + vm.assertLt(right, left, errorMessage); + + vm._expectCheatcodeRevert( + bytes( + string.concat( + "Assertion failed: ", + _formatWithDecimals(left, decimals), + " <= ", + _formatWithDecimals(right, decimals) + ) + ) + ); + vm.assertGtDecimal(left, right, decimals); + + vm._expectCheatcodeRevert( + bytes( + string.concat( + "Assertion failed: ", + _formatWithDecimals(right, decimals), + " <= ", + _formatWithDecimals(right, decimals) + ) + ) + ); + vm.assertGtDecimal(right, right, decimals); + + vm._expectCheatcodeRevert( + bytes( + string.concat( + "Assertion failed: ", + _formatWithDecimals(left, decimals), + " >= ", + _formatWithDecimals(left, decimals) + ) + ) + ); + vm.assertLtDecimal(left, left, decimals); + + vm._expectCheatcodeRevert( + bytes( + string.concat( + "Assertion failed: ", + _formatWithDecimals(right, decimals), + " >= ", + _formatWithDecimals(left, decimals) + ) + ) + ); + vm.assertLtDecimal(right, left, decimals); + } + + function testFuzzAssertGeLe(uint256 left, uint256 right, uint256 decimals) public { + vm.assume(left < right); + vm.assume(decimals <= maxDecimals); + + vm.assertGe(left, left); + vm.assertLe(left, left); + vm.assertGe(right, right); + vm.assertLe(right, right); + vm.assertGe(right, left); + vm.assertLe(left, right); + + vm._expectCheatcodeRevert( + bytes(string.concat(errorMessage, ": ", vm.toString(left), " < ", vm.toString(right))) + ); + vm.assertGe(left, right, errorMessage); + + vm._expectCheatcodeRevert( + bytes(string.concat(errorMessage, ": ", vm.toString(right), " > ", vm.toString(left))) + ); + vm.assertLe(right, left, errorMessage); + + vm._expectCheatcodeRevert( + bytes( + string.concat( + "Assertion failed: ", + _formatWithDecimals(left, decimals), + " < ", + _formatWithDecimals(right, decimals) + ) + ) + ); + vm.assertGeDecimal(left, right, decimals); + + vm._expectCheatcodeRevert( + bytes( + string.concat( + "Assertion failed: ", + _formatWithDecimals(right, decimals), + " > ", + _formatWithDecimals(left, decimals) + ) + ) + ); + vm.assertLeDecimal(right, left, decimals); + } + + function testFuzzAssertGeLe(int256 left, int256 right, uint256 decimals) public { + vm.assume(left < right); + vm.assume(decimals <= maxDecimals); + + vm.assertGe(left, left); + vm.assertLe(left, left); + vm.assertGe(right, right); + vm.assertLe(right, right); + vm.assertGe(right, left); + vm.assertLe(left, right); + + vm._expectCheatcodeRevert( + bytes(string.concat(errorMessage, ": ", vm.toString(left), " < ", vm.toString(right))) + ); + vm.assertGe(left, right, errorMessage); + + vm._expectCheatcodeRevert( + bytes(string.concat(errorMessage, ": ", vm.toString(right), " > ", vm.toString(left))) + ); + vm.assertLe(right, left, errorMessage); + + vm._expectCheatcodeRevert( + bytes( + string.concat( + "Assertion failed: ", + _formatWithDecimals(left, decimals), + " < ", + _formatWithDecimals(right, decimals) + ) + ) + ); + vm.assertGeDecimal(left, right, decimals); + + vm._expectCheatcodeRevert( + bytes( + string.concat( + "Assertion failed: ", + _formatWithDecimals(right, decimals), + " > ", + _formatWithDecimals(left, decimals) + ) + ) + ); + vm.assertLeDecimal(right, left, decimals); + } + + function testFuzzAssertApproxEqAbs(uint256 left, uint256 right, uint256 decimals) public { + uint256 delta = _getDelta(right, left); + vm.assume(decimals <= maxDecimals); + + vm.assertApproxEqAbs(left, right, delta); + + if (delta > 0) { + vm._expectCheatcodeRevert( + bytes( + string.concat( + errorMessage, + ": ", + vm.toString(left), + " !~= ", + vm.toString(right), + " (max delta: ", + vm.toString(delta - 1), + ", real delta: ", + vm.toString(delta), + ")" + ) + ) + ); + vm.assertApproxEqAbs(left, right, delta - 1, errorMessage); + + vm._expectCheatcodeRevert( + bytes( + string.concat( + "Assertion failed: ", + _formatWithDecimals(left, decimals), + " !~= ", + _formatWithDecimals(right, decimals), + " (max delta: ", + _formatWithDecimals(delta - 1, decimals), + ", real delta: ", + _formatWithDecimals(delta, decimals), + ")" + ) + ) + ); + vm.assertApproxEqAbsDecimal(left, right, delta - 1, decimals); + } + } + + function testFuzzAssertApproxEqAbs(int256 left, int256 right, uint256 decimals) public { + uint256 delta = _getDelta(right, left); + vm.assume(decimals <= maxDecimals); + + vm.assertApproxEqAbs(left, right, delta); + + if (delta > 0) { + vm._expectCheatcodeRevert( + bytes( + string.concat( + errorMessage, + ": ", + vm.toString(left), + " !~= ", + vm.toString(right), + " (max delta: ", + vm.toString(delta - 1), + ", real delta: ", + vm.toString(delta), + ")" + ) + ) + ); + vm.assertApproxEqAbs(left, right, delta - 1, errorMessage); + + vm._expectCheatcodeRevert( + bytes( + string.concat( + "Assertion failed: ", + _formatWithDecimals(left, decimals), + " !~= ", + _formatWithDecimals(right, decimals), + " (max delta: ", + _formatWithDecimals(delta - 1, decimals), + ", real delta: ", + _formatWithDecimals(delta, decimals), + ")" + ) + ) + ); + vm.assertApproxEqAbsDecimal(left, right, delta - 1, decimals); + } + } + + function testFuzzAssertApproxEqRel(uint256 left, uint256 right, uint256 decimals) public { + vm.assume(right != 0); + uint256 delta = _getDelta(right, left); + vm.assume(delta < type(uint256).max / (10 ** 18)); + vm.assume(decimals <= maxDecimals); + + uint256 percentDelta = delta * (10 ** 18) / right; + + vm.assertApproxEqRel(left, right, percentDelta); + + if (percentDelta > 0) { + vm._expectCheatcodeRevert( + bytes( + string.concat( + errorMessage, + ": ", + vm.toString(left), + " !~= ", + vm.toString(right), + " (max delta: ", + _formatWithDecimals(percentDelta - 1, 16), + "%, real delta: ", + _formatWithDecimals(percentDelta, 16), + "%)" + ) + ) + ); + vm.assertApproxEqRel(left, right, percentDelta - 1, errorMessage); + + vm._expectCheatcodeRevert( + bytes( + string.concat( + "Assertion failed: ", + _formatWithDecimals(left, decimals), + " !~= ", + _formatWithDecimals(right, decimals), + " (max delta: ", + _formatWithDecimals(percentDelta - 1, 16), + "%, real delta: ", + _formatWithDecimals(percentDelta, 16), + "%)" + ) + ) + ); + vm.assertApproxEqRelDecimal(left, right, percentDelta - 1, decimals); + } + } + + function testFuzzAssertApproxEqRel(int256 left, int256 right, uint256 decimals) public { + vm.assume(left < right); + vm.assume(right != 0); + uint256 delta = _getDelta(right, left); + vm.assume(delta < type(uint256).max / (10 ** 18)); + vm.assume(decimals <= maxDecimals); + + uint256 percentDelta = delta * (10 ** 18) / _abs(right); + + vm.assertApproxEqRel(left, right, percentDelta); + + if (percentDelta > 0) { + vm._expectCheatcodeRevert( + bytes( + string.concat( + errorMessage, + ": ", + vm.toString(left), + " !~= ", + vm.toString(right), + " (max delta: ", + _formatWithDecimals(percentDelta - 1, 16), + "%, real delta: ", + _formatWithDecimals(percentDelta, 16), + "%)" + ) + ) + ); + vm.assertApproxEqRel(left, right, percentDelta - 1, errorMessage); + + vm._expectCheatcodeRevert( + bytes( + string.concat( + "Assertion failed: ", + _formatWithDecimals(left, decimals), + " !~= ", + _formatWithDecimals(right, decimals), + " (max delta: ", + _formatWithDecimals(percentDelta - 1, 16), + "%, real delta: ", + _formatWithDecimals(percentDelta, 16), + "%)" + ) + ) + ); + vm.assertApproxEqRelDecimal(left, right, percentDelta - 1, decimals); + } + } + + function testAssertEqNotEqArrays() public { + { + uint256[] memory arr1 = new uint256[](1); + arr1[0] = 1; + uint256[] memory arr2 = new uint256[](2); + arr2[0] = 1; + arr2[1] = 2; + + vm.assertEq(arr1, arr1); + vm.assertEq(arr2, arr2); + vm.assertNotEq(arr1, arr2); + + vm._expectCheatcodeRevert(bytes("Assertion failed: [1] != [1, 2]")); + vm.assertEq(arr1, arr2); + + vm._expectCheatcodeRevert(bytes(string.concat("Assertion failed: [1, 2] == [1, 2]"))); + vm.assertNotEq(arr2, arr2); + } + { + int256[] memory arr1 = new int256[](2); + int256[] memory arr2 = new int256[](1); + arr1[0] = 5; + arr2[0] = type(int256).max; + + vm.assertEq(arr1, arr1); + vm.assertEq(arr2, arr2); + vm.assertNotEq(arr1, arr2); + + vm._expectCheatcodeRevert(bytes(string.concat(errorMessage, ": [5, 0] != [", vm.toString(arr2[0]), "]"))); + vm.assertEq(arr1, arr2, errorMessage); + + vm._expectCheatcodeRevert(bytes(string.concat("Assertion failed: [5, 0] == [5, 0]"))); + vm.assertNotEq(arr1, arr1); + } + { + bool[] memory arr1 = new bool[](2); + bool[] memory arr2 = new bool[](2); + arr1[0] = true; + arr2[1] = true; + + vm.assertEq(arr1, arr1); + vm.assertEq(arr2, arr2); + vm.assertNotEq(arr1, arr2); + + vm._expectCheatcodeRevert(bytes(string.concat(errorMessage, ": [true, false] != [false, true]"))); + vm.assertEq(arr1, arr2, errorMessage); + + vm._expectCheatcodeRevert(bytes(string("Assertion failed: [true, false] == [true, false]"))); + vm.assertNotEq(arr1, arr1); + } + { + address[] memory arr1 = new address[](1); + address[] memory arr2 = new address[](0); + + vm.assertEq(arr1, arr1); + vm.assertEq(arr2, arr2); + vm.assertNotEq(arr1, arr2); + + vm._expectCheatcodeRevert(bytes(string.concat(errorMessage, ": [", vm.toString(arr1[0]), "] != []"))); + vm.assertEq(arr1, arr2, errorMessage); + + vm._expectCheatcodeRevert(bytes(string("Assertion failed: [] == []"))); + vm.assertNotEq(arr2, arr2); + } + { + bytes32[] memory arr1 = new bytes32[](1); + bytes32[] memory arr2 = new bytes32[](1); + arr1[0] = bytes32(uint256(1)); + + vm.assertEq(arr1, arr1); + vm.assertEq(arr2, arr2); + vm.assertNotEq(arr1, arr2); + + vm._expectCheatcodeRevert( + bytes(string.concat(errorMessage, ": [", vm.toString(arr1[0]), "] != [", vm.toString(arr2[0]), "]")) + ); + vm.assertEq(arr1, arr2, errorMessage); + + vm._expectCheatcodeRevert( + bytes(string.concat("Assertion failed: [", vm.toString(arr2[0]), "] == [", vm.toString(arr2[0]), "]")) + ); + vm.assertNotEq(arr2, arr2); + } + { + string[] memory arr1 = new string[](1); + string[] memory arr2 = new string[](3); + + arr1[0] = "foo"; + arr2[2] = "bar"; + + vm.assertEq(arr1, arr1); + vm.assertEq(arr2, arr2); + vm.assertNotEq(arr1, arr2); + + vm._expectCheatcodeRevert(bytes("Assertion failed: [foo] != [, , bar]")); + vm.assertEq(arr1, arr2); + + vm._expectCheatcodeRevert(bytes(string.concat(errorMessage, ": [foo] == [foo]"))); + vm.assertNotEq(arr1, arr1, errorMessage); + } + { + bytes[] memory arr1 = new bytes[](1); + bytes[] memory arr2 = new bytes[](2); + + arr1[0] = hex"1111"; + arr2[1] = hex"1234"; + + vm.assertEq(arr1, arr1); + vm.assertEq(arr2, arr2); + vm.assertNotEq(arr1, arr2); + + vm._expectCheatcodeRevert(bytes("Assertion failed: [0x1111] != [0x, 0x1234]")); + vm.assertEq(arr1, arr2); + + vm._expectCheatcodeRevert(bytes(string.concat(errorMessage, ": [0x1111] == [0x1111]"))); + vm.assertNotEq(arr1, arr1, errorMessage); + } + } + + function testAssertBool() public { + vm.assertTrue(true); + vm.assertFalse(false); + + vm._expectCheatcodeRevert(bytes("Assertion failed")); + vm.assertTrue(false); + + vm._expectCheatcodeRevert(bytes(errorMessage)); + vm.assertTrue(false, errorMessage); + + vm._expectCheatcodeRevert(bytes("Assertion failed")); + vm.assertFalse(true); + + vm._expectCheatcodeRevert(bytes(errorMessage)); + vm.assertFalse(true, errorMessage); + } + + function testAssertApproxEqRel() public { + vm._expectCheatcodeRevert(bytes("Assertion failed: Overflow in delta calculation")); + vm.assertApproxEqRel(type(int256).min, type(int256).max, 0); + + vm._expectCheatcodeRevert(bytes(string.concat(errorMessage, ": Overflow in delta calculation"))); + vm.assertApproxEqRel(int256(1), int256(0), 0, errorMessage); + + vm._expectCheatcodeRevert(bytes(string.concat(errorMessage, ": Overflow in delta calculation"))); + vm.assertApproxEqRel(uint256(0), type(uint256).max, 0, errorMessage); + + vm._expectCheatcodeRevert(bytes("Assertion failed: Overflow in delta calculation")); + vm.assertApproxEqRel(uint256(1), uint256(0), uint256(0)); + } +} From be2523d6d46647c2ee724a962fe9d64c27f9d858 Mon Sep 17 00:00:00 2001 From: Arsenii Kulikov Date: Tue, 23 Jan 2024 00:32:28 +0200 Subject: [PATCH 17/19] rustfmt --- crates/cheatcodes/src/test/assert.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/cheatcodes/src/test/assert.rs b/crates/cheatcodes/src/test/assert.rs index 09791f2018ec..d77eb4806c22 100644 --- a/crates/cheatcodes/src/test/assert.rs +++ b/crates/cheatcodes/src/test/assert.rs @@ -1109,7 +1109,9 @@ fn uint_assert_approx_eq_rel( ) -> Result, EqRelAssertionError> { let delta = get_delta_uint(left, right) .checked_mul(U256::pow(U256::from(10), EQ_REL_DELTA_RESOLUTION)) - .ok_or(EqRelAssertionError::Overflow)?.checked_div(right).ok_or(EqRelAssertionError::Overflow)?; + .ok_or(EqRelAssertionError::Overflow)? + .checked_div(right) + .ok_or(EqRelAssertionError::Overflow)?; if delta <= max_delta { Ok(Default::default()) From e6842ccbaf2d23a117be238c8c46d7da207aa98f Mon Sep 17 00:00:00 2001 From: Arsenii Kulikov Date: Tue, 23 Jan 2024 00:35:50 +0200 Subject: [PATCH 18/19] fix clippy warning --- crates/cheatcodes/src/test/assert.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/cheatcodes/src/test/assert.rs b/crates/cheatcodes/src/test/assert.rs index d77eb4806c22..f0dde9afdfc4 100644 --- a/crates/cheatcodes/src/test/assert.rs +++ b/crates/cheatcodes/src/test/assert.rs @@ -43,7 +43,7 @@ impl<'a, T: Display> ComparisonAssertionError<'a, T> { impl<'a, T: Display> ComparisonAssertionError<'a, Vec> { fn format_for_arrays(&self) -> String { - let formatter = |v: &Vec| format!("[{}]", v.iter().format(", ").to_string()); + let formatter = |v: &Vec| format!("[{}]", v.iter().format(", ")); format_values!(self, formatter) } } From 01e2c017ecc3546b8a2f12e127af7a7a036c731a Mon Sep 17 00:00:00 2001 From: Arsenii Kulikov Date: Thu, 25 Jan 2024 00:33:11 +0200 Subject: [PATCH 19/19] lowercase error messages --- crates/cheatcodes/src/test/assert.rs | 120 +++++++++++++-------------- testdata/cheats/Assert.t.sol | 64 +++++++------- 2 files changed, 92 insertions(+), 92 deletions(-) diff --git a/crates/cheatcodes/src/test/assert.rs b/crates/cheatcodes/src/test/assert.rs index f0dde9afdfc4..70b2d5971a45 100644 --- a/crates/cheatcodes/src/test/assert.rs +++ b/crates/cheatcodes/src/test/assert.rs @@ -9,7 +9,7 @@ use crate::{Cheatcode, Cheatcodes, Result, Vm::*}; const EQ_REL_DELTA_RESOLUTION: U256 = U256::from_limbs([18, 0, 0, 0]); #[derive(Debug, thiserror::Error)] -#[error("Assertion failed")] +#[error("assertion failed")] struct SimpleAssertionError; #[derive(thiserror::Error, Debug)] @@ -116,7 +116,7 @@ struct EqRelAssertionFailure { enum EqRelAssertionError { #[error(transparent)] Failure(Box>), - #[error("Overflow in delta calculation")] + #[error("overflow in delta calculation")] Overflow, } @@ -154,7 +154,7 @@ type ComparisonResult<'a, T> = Result, ComparisonAssertionError<'a, T>>; impl Cheatcode for assertTrue_0Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - Ok(assert_true(self.condition).map_err(|_| "Assertion failed")?) + Ok(assert_true(self.condition).map_err(|e| e.to_string())?) } } @@ -166,7 +166,7 @@ impl Cheatcode for assertTrue_1Call { impl Cheatcode for assertFalse_0Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { - Ok(assert_false(self.condition).map_err(|_| "Assertion failed")?) + Ok(assert_false(self.condition).map_err(|e| e.to_string())?) } } @@ -180,7 +180,7 @@ impl Cheatcode for assertEq_0Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { left, right } = self; Ok(assert_eq(left, right) - .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) + .map_err(|e| format!("assertion failed: {}", e.format_for_values()))?) } } @@ -195,7 +195,7 @@ impl Cheatcode for assertEq_2Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { left, right } = self; Ok(assert_eq(left, right) - .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) + .map_err(|e| format!("assertion failed: {}", e.format_for_values()))?) } } @@ -210,7 +210,7 @@ impl Cheatcode for assertEq_4Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { left, right } = self; Ok(assert_eq(left, right) - .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) + .map_err(|e| format!("assertion failed: {}", e.format_for_values()))?) } } @@ -225,7 +225,7 @@ impl Cheatcode for assertEq_6Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { left, right } = self; Ok(assert_eq(left, right) - .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) + .map_err(|e| format!("assertion failed: {}", e.format_for_values()))?) } } @@ -240,7 +240,7 @@ impl Cheatcode for assertEq_8Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { left, right } = self; Ok(assert_eq(left, right) - .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) + .map_err(|e| format!("assertion failed: {}", e.format_for_values()))?) } } @@ -255,7 +255,7 @@ impl Cheatcode for assertEq_10Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { left, right } = self; Ok(assert_eq(left, right) - .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) + .map_err(|e| format!("assertion failed: {}", e.format_for_values()))?) } } @@ -270,7 +270,7 @@ impl Cheatcode for assertEq_12Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { left, right } = self; Ok(assert_eq(&hex::encode_prefixed(left), &hex::encode_prefixed(right)) - .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) + .map_err(|e| format!("assertion failed: {}", e.format_for_values()))?) } } @@ -286,7 +286,7 @@ impl Cheatcode for assertEq_14Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { left, right } = self; Ok(assert_eq(left, right) - .map_err(|e| format!("Assertion failed: {}", e.format_for_arrays()))?) + .map_err(|e| format!("assertion failed: {}", e.format_for_arrays()))?) } } @@ -301,7 +301,7 @@ impl Cheatcode for assertEq_16Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { left, right } = self; Ok(assert_eq(left, right) - .map_err(|e| format!("Assertion failed: {}", e.format_for_arrays()))?) + .map_err(|e| format!("assertion failed: {}", e.format_for_arrays()))?) } } @@ -316,7 +316,7 @@ impl Cheatcode for assertEq_18Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { left, right } = self; Ok(assert_eq(left, right) - .map_err(|e| format!("Assertion failed: {}", e.format_for_arrays()))?) + .map_err(|e| format!("assertion failed: {}", e.format_for_arrays()))?) } } @@ -331,7 +331,7 @@ impl Cheatcode for assertEq_20Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { left, right } = self; Ok(assert_eq(left, right) - .map_err(|e| format!("Assertion failed: {}", e.format_for_arrays()))?) + .map_err(|e| format!("assertion failed: {}", e.format_for_arrays()))?) } } @@ -346,7 +346,7 @@ impl Cheatcode for assertEq_22Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { left, right } = self; Ok(assert_eq(left, right) - .map_err(|e| format!("Assertion failed: {}", e.format_for_arrays()))?) + .map_err(|e| format!("assertion failed: {}", e.format_for_arrays()))?) } } @@ -361,7 +361,7 @@ impl Cheatcode for assertEq_24Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { left, right } = self; Ok(assert_eq(left, right) - .map_err(|e| format!("Assertion failed: {}", e.format_for_arrays()))?) + .map_err(|e| format!("assertion failed: {}", e.format_for_arrays()))?) } } @@ -378,7 +378,7 @@ impl Cheatcode for assertEq_26Call { let left = left.iter().map(hex::encode_prefixed).collect::>(); let right = right.iter().map(hex::encode_prefixed).collect::>(); Ok(assert_eq(&left, &right) - .map_err(|e| format!("Assertion failed: {}", e.format_for_arrays()))?) + .map_err(|e| format!("assertion failed: {}", e.format_for_arrays()))?) } } @@ -394,7 +394,7 @@ impl Cheatcode for assertEq_27Call { impl Cheatcode for assertEqDecimal_0Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { Ok(assert_eq(&self.left, &self.right) - .map_err(|e| format!("Assertion failed: {}", e.format_with_decimals(&self.decimals)))?) + .map_err(|e| format!("assertion failed: {}", e.format_with_decimals(&self.decimals)))?) } } @@ -408,7 +408,7 @@ impl Cheatcode for assertEqDecimal_1Call { impl Cheatcode for assertEqDecimal_2Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { Ok(assert_eq(&self.left, &self.right) - .map_err(|e| format!("Assertion failed: {}", e.format_with_decimals(&self.decimals)))?) + .map_err(|e| format!("assertion failed: {}", e.format_with_decimals(&self.decimals)))?) } } @@ -423,7 +423,7 @@ impl Cheatcode for assertNotEq_0Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { left, right } = self; Ok(assert_not_eq(left, right) - .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) + .map_err(|e| format!("assertion failed: {}", e.format_for_values()))?) } } @@ -439,7 +439,7 @@ impl Cheatcode for assertNotEq_2Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { left, right } = self; Ok(assert_not_eq(left, right) - .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) + .map_err(|e| format!("assertion failed: {}", e.format_for_values()))?) } } @@ -455,7 +455,7 @@ impl Cheatcode for assertNotEq_4Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { left, right } = self; Ok(assert_not_eq(left, right) - .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) + .map_err(|e| format!("assertion failed: {}", e.format_for_values()))?) } } @@ -471,7 +471,7 @@ impl Cheatcode for assertNotEq_6Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { left, right } = self; Ok(assert_not_eq(left, right) - .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) + .map_err(|e| format!("assertion failed: {}", e.format_for_values()))?) } } @@ -487,7 +487,7 @@ impl Cheatcode for assertNotEq_8Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { left, right } = self; Ok(assert_not_eq(left, right) - .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) + .map_err(|e| format!("assertion failed: {}", e.format_for_values()))?) } } @@ -503,7 +503,7 @@ impl Cheatcode for assertNotEq_10Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { left, right } = self; Ok(assert_not_eq(left, right) - .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) + .map_err(|e| format!("assertion failed: {}", e.format_for_values()))?) } } @@ -519,7 +519,7 @@ impl Cheatcode for assertNotEq_12Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { left, right } = self; Ok(assert_not_eq(&hex::encode_prefixed(left), &hex::encode_prefixed(right)) - .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) + .map_err(|e| format!("assertion failed: {}", e.format_for_values()))?) } } @@ -535,7 +535,7 @@ impl Cheatcode for assertNotEq_14Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { left, right } = self; Ok(assert_not_eq(left, right) - .map_err(|e| format!("Assertion failed: {}", e.format_for_arrays()))?) + .map_err(|e| format!("assertion failed: {}", e.format_for_arrays()))?) } } @@ -551,7 +551,7 @@ impl Cheatcode for assertNotEq_16Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { left, right } = self; Ok(assert_not_eq(left, right) - .map_err(|e| format!("Assertion failed: {}", e.format_for_arrays()))?) + .map_err(|e| format!("assertion failed: {}", e.format_for_arrays()))?) } } @@ -567,7 +567,7 @@ impl Cheatcode for assertNotEq_18Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { left, right } = self; Ok(assert_not_eq(left, right) - .map_err(|e| format!("Assertion failed: {}", e.format_for_arrays()))?) + .map_err(|e| format!("assertion failed: {}", e.format_for_arrays()))?) } } @@ -583,7 +583,7 @@ impl Cheatcode for assertNotEq_20Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { left, right } = self; Ok(assert_not_eq(left, right) - .map_err(|e| format!("Assertion failed: {}", e.format_for_arrays()))?) + .map_err(|e| format!("assertion failed: {}", e.format_for_arrays()))?) } } @@ -599,7 +599,7 @@ impl Cheatcode for assertNotEq_22Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { left, right } = self; Ok(assert_not_eq(left, right) - .map_err(|e| format!("Assertion failed: {}", e.format_for_arrays()))?) + .map_err(|e| format!("assertion failed: {}", e.format_for_arrays()))?) } } @@ -615,7 +615,7 @@ impl Cheatcode for assertNotEq_24Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { left, right } = self; Ok(assert_not_eq(left, right) - .map_err(|e| format!("Assertion failed: {}", e.format_for_arrays()))?) + .map_err(|e| format!("assertion failed: {}", e.format_for_arrays()))?) } } @@ -633,7 +633,7 @@ impl Cheatcode for assertNotEq_26Call { let left = left.iter().map(hex::encode_prefixed).collect::>(); let right = right.iter().map(hex::encode_prefixed).collect::>(); Ok(assert_not_eq(&left, &right) - .map_err(|e| format!("Assertion failed: {}", e.format_for_arrays()))?) + .map_err(|e| format!("assertion failed: {}", e.format_for_arrays()))?) } } @@ -650,7 +650,7 @@ impl Cheatcode for assertNotEq_27Call { impl Cheatcode for assertNotEqDecimal_0Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { Ok(assert_not_eq(&self.left, &self.right) - .map_err(|e| format!("Assertion failed: {}", e.format_with_decimals(&self.decimals)))?) + .map_err(|e| format!("assertion failed: {}", e.format_with_decimals(&self.decimals)))?) } } @@ -664,7 +664,7 @@ impl Cheatcode for assertNotEqDecimal_1Call { impl Cheatcode for assertNotEqDecimal_2Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { Ok(assert_not_eq(&self.left, &self.right) - .map_err(|e| format!("Assertion failed: {}", e.format_with_decimals(&self.decimals)))?) + .map_err(|e| format!("assertion failed: {}", e.format_with_decimals(&self.decimals)))?) } } @@ -679,7 +679,7 @@ impl Cheatcode for assertGt_0Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { left, right } = self; Ok(assert_gt(left, right) - .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) + .map_err(|e| format!("assertion failed: {}", e.format_for_values()))?) } } @@ -694,7 +694,7 @@ impl Cheatcode for assertGt_2Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { left, right } = self; Ok(assert_gt(left, right) - .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) + .map_err(|e| format!("assertion failed: {}", e.format_for_values()))?) } } @@ -708,7 +708,7 @@ impl Cheatcode for assertGt_3Call { impl Cheatcode for assertGtDecimal_0Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { Ok(assert_gt(&self.left, &self.right) - .map_err(|e| format!("Assertion failed: {}", e.format_with_decimals(&self.decimals)))?) + .map_err(|e| format!("assertion failed: {}", e.format_with_decimals(&self.decimals)))?) } } @@ -722,7 +722,7 @@ impl Cheatcode for assertGtDecimal_1Call { impl Cheatcode for assertGtDecimal_2Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { Ok(assert_gt(&self.left, &self.right) - .map_err(|e| format!("Assertion failed: {}", e.format_with_decimals(&self.decimals)))?) + .map_err(|e| format!("assertion failed: {}", e.format_with_decimals(&self.decimals)))?) } } @@ -737,7 +737,7 @@ impl Cheatcode for assertGe_0Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { left, right } = self; Ok(assert_ge(left, right) - .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) + .map_err(|e| format!("assertion failed: {}", e.format_for_values()))?) } } @@ -752,7 +752,7 @@ impl Cheatcode for assertGe_2Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { left, right } = self; Ok(assert_ge(left, right) - .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) + .map_err(|e| format!("assertion failed: {}", e.format_for_values()))?) } } @@ -766,7 +766,7 @@ impl Cheatcode for assertGe_3Call { impl Cheatcode for assertGeDecimal_0Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { Ok(assert_ge(&self.left, &self.right) - .map_err(|e| format!("Assertion failed: {}", e.format_with_decimals(&self.decimals)))?) + .map_err(|e| format!("assertion failed: {}", e.format_with_decimals(&self.decimals)))?) } } @@ -780,7 +780,7 @@ impl Cheatcode for assertGeDecimal_1Call { impl Cheatcode for assertGeDecimal_2Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { Ok(assert_ge(&self.left, &self.right) - .map_err(|e| format!("Assertion failed: {}", e.format_with_decimals(&self.decimals)))?) + .map_err(|e| format!("assertion failed: {}", e.format_with_decimals(&self.decimals)))?) } } @@ -795,7 +795,7 @@ impl Cheatcode for assertLt_0Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { left, right } = self; Ok(assert_lt(left, right) - .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) + .map_err(|e| format!("assertion failed: {}", e.format_for_values()))?) } } @@ -810,7 +810,7 @@ impl Cheatcode for assertLt_2Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { left, right } = self; Ok(assert_lt(left, right) - .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) + .map_err(|e| format!("assertion failed: {}", e.format_for_values()))?) } } @@ -824,7 +824,7 @@ impl Cheatcode for assertLt_3Call { impl Cheatcode for assertLtDecimal_0Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { Ok(assert_lt(&self.left, &self.right) - .map_err(|e| format!("Assertion failed: {}", e.format_with_decimals(&self.decimals)))?) + .map_err(|e| format!("assertion failed: {}", e.format_with_decimals(&self.decimals)))?) } } @@ -838,7 +838,7 @@ impl Cheatcode for assertLtDecimal_1Call { impl Cheatcode for assertLtDecimal_2Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { Ok(assert_lt(&self.left, &self.right) - .map_err(|e| format!("Assertion failed: {}", e.format_with_decimals(&self.decimals)))?) + .map_err(|e| format!("assertion failed: {}", e.format_with_decimals(&self.decimals)))?) } } @@ -853,7 +853,7 @@ impl Cheatcode for assertLe_0Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { left, right } = self; Ok(assert_le(left, right) - .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) + .map_err(|e| format!("assertion failed: {}", e.format_for_values()))?) } } @@ -868,7 +868,7 @@ impl Cheatcode for assertLe_2Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { left, right } = self; Ok(assert_le(left, right) - .map_err(|e| format!("Assertion failed: {}", e.format_for_values()))?) + .map_err(|e| format!("assertion failed: {}", e.format_for_values()))?) } } @@ -882,7 +882,7 @@ impl Cheatcode for assertLe_3Call { impl Cheatcode for assertLeDecimal_0Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { Ok(assert_le(&self.left, &self.right) - .map_err(|e| format!("Assertion failed: {}", e.format_with_decimals(&self.decimals)))?) + .map_err(|e| format!("assertion failed: {}", e.format_with_decimals(&self.decimals)))?) } } @@ -896,7 +896,7 @@ impl Cheatcode for assertLeDecimal_1Call { impl Cheatcode for assertLeDecimal_2Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { Ok(assert_le(&self.left, &self.right) - .map_err(|e| format!("Assertion failed: {}", e.format_with_decimals(&self.decimals)))?) + .map_err(|e| format!("assertion failed: {}", e.format_with_decimals(&self.decimals)))?) } } @@ -910,7 +910,7 @@ impl Cheatcode for assertLeDecimal_3Call { impl Cheatcode for assertApproxEqAbs_0Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { Ok(uint_assert_approx_eq_abs(self.left, self.right, self.maxDelta) - .map_err(|e| format!("Assertion failed: {}", e))?) + .map_err(|e| format!("assertion failed: {}", e))?) } } @@ -924,7 +924,7 @@ impl Cheatcode for assertApproxEqAbs_1Call { impl Cheatcode for assertApproxEqAbs_2Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { Ok(int_assert_approx_eq_abs(self.left, self.right, self.maxDelta) - .map_err(|e| format!("Assertion failed: {}", e))?) + .map_err(|e| format!("assertion failed: {}", e))?) } } @@ -938,7 +938,7 @@ impl Cheatcode for assertApproxEqAbs_3Call { impl Cheatcode for assertApproxEqAbsDecimal_0Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { Ok(uint_assert_approx_eq_abs(self.left, self.right, self.maxDelta) - .map_err(|e| format!("Assertion failed: {}", e.format_with_decimals(&self.decimals)))?) + .map_err(|e| format!("assertion failed: {}", e.format_with_decimals(&self.decimals)))?) } } @@ -952,7 +952,7 @@ impl Cheatcode for assertApproxEqAbsDecimal_1Call { impl Cheatcode for assertApproxEqAbsDecimal_2Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { Ok(int_assert_approx_eq_abs(self.left, self.right, self.maxDelta) - .map_err(|e| format!("Assertion failed: {}", e.format_with_decimals(&self.decimals)))?) + .map_err(|e| format!("assertion failed: {}", e.format_with_decimals(&self.decimals)))?) } } @@ -966,7 +966,7 @@ impl Cheatcode for assertApproxEqAbsDecimal_3Call { impl Cheatcode for assertApproxEqRel_0Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { Ok(uint_assert_approx_eq_rel(self.left, self.right, self.maxPercentDelta) - .map_err(|e| format!("Assertion failed: {}", e))?) + .map_err(|e| format!("assertion failed: {}", e))?) } } @@ -980,7 +980,7 @@ impl Cheatcode for assertApproxEqRel_1Call { impl Cheatcode for assertApproxEqRel_2Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { Ok(int_assert_approx_eq_rel(self.left, self.right, self.maxPercentDelta) - .map_err(|e| format!("Assertion failed: {}", e))?) + .map_err(|e| format!("assertion failed: {}", e))?) } } @@ -994,7 +994,7 @@ impl Cheatcode for assertApproxEqRel_3Call { impl Cheatcode for assertApproxEqRelDecimal_0Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { Ok(uint_assert_approx_eq_rel(self.left, self.right, self.maxPercentDelta) - .map_err(|e| format!("Assertion failed: {}", e.format_with_decimals(&self.decimals)))?) + .map_err(|e| format!("assertion failed: {}", e.format_with_decimals(&self.decimals)))?) } } @@ -1008,7 +1008,7 @@ impl Cheatcode for assertApproxEqRelDecimal_1Call { impl Cheatcode for assertApproxEqRelDecimal_2Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { Ok(int_assert_approx_eq_rel(self.left, self.right, self.maxPercentDelta) - .map_err(|e| format!("Assertion failed: {}", e.format_with_decimals(&self.decimals)))?) + .map_err(|e| format!("assertion failed: {}", e.format_with_decimals(&self.decimals)))?) } } diff --git a/testdata/cheats/Assert.t.sol b/testdata/cheats/Assert.t.sol index 96ce5977a9a2..680300dde988 100644 --- a/testdata/cheats/Assert.t.sol +++ b/testdata/cheats/Assert.t.sol @@ -87,7 +87,7 @@ contract AssertionsTest is DSTest { vm._expectCheatcodeRevert( bytes( string.concat( - "Assertion failed: ", + "assertion failed: ", _formatWithDecimals(left, decimals), " != ", _formatWithDecimals(right, decimals) @@ -99,7 +99,7 @@ contract AssertionsTest is DSTest { vm._expectCheatcodeRevert( bytes( string.concat( - "Assertion failed: ", + "assertion failed: ", _formatWithDecimals(left, decimals), " == ", _formatWithDecimals(left, decimals) @@ -272,7 +272,7 @@ contract AssertionsTest is DSTest { vm._expectCheatcodeRevert( bytes( string.concat( - "Assertion failed: ", + "assertion failed: ", _formatWithDecimals(left, decimals), " <= ", _formatWithDecimals(right, decimals) @@ -284,7 +284,7 @@ contract AssertionsTest is DSTest { vm._expectCheatcodeRevert( bytes( string.concat( - "Assertion failed: ", + "assertion failed: ", _formatWithDecimals(right, decimals), " <= ", _formatWithDecimals(right, decimals) @@ -296,7 +296,7 @@ contract AssertionsTest is DSTest { vm._expectCheatcodeRevert( bytes( string.concat( - "Assertion failed: ", + "assertion failed: ", _formatWithDecimals(left, decimals), " >= ", _formatWithDecimals(left, decimals) @@ -308,7 +308,7 @@ contract AssertionsTest is DSTest { vm._expectCheatcodeRevert( bytes( string.concat( - "Assertion failed: ", + "assertion failed: ", _formatWithDecimals(right, decimals), " >= ", _formatWithDecimals(left, decimals) @@ -348,7 +348,7 @@ contract AssertionsTest is DSTest { vm._expectCheatcodeRevert( bytes( string.concat( - "Assertion failed: ", + "assertion failed: ", _formatWithDecimals(left, decimals), " <= ", _formatWithDecimals(right, decimals) @@ -360,7 +360,7 @@ contract AssertionsTest is DSTest { vm._expectCheatcodeRevert( bytes( string.concat( - "Assertion failed: ", + "assertion failed: ", _formatWithDecimals(right, decimals), " <= ", _formatWithDecimals(right, decimals) @@ -372,7 +372,7 @@ contract AssertionsTest is DSTest { vm._expectCheatcodeRevert( bytes( string.concat( - "Assertion failed: ", + "assertion failed: ", _formatWithDecimals(left, decimals), " >= ", _formatWithDecimals(left, decimals) @@ -384,7 +384,7 @@ contract AssertionsTest is DSTest { vm._expectCheatcodeRevert( bytes( string.concat( - "Assertion failed: ", + "assertion failed: ", _formatWithDecimals(right, decimals), " >= ", _formatWithDecimals(left, decimals) @@ -418,7 +418,7 @@ contract AssertionsTest is DSTest { vm._expectCheatcodeRevert( bytes( string.concat( - "Assertion failed: ", + "assertion failed: ", _formatWithDecimals(left, decimals), " < ", _formatWithDecimals(right, decimals) @@ -430,7 +430,7 @@ contract AssertionsTest is DSTest { vm._expectCheatcodeRevert( bytes( string.concat( - "Assertion failed: ", + "assertion failed: ", _formatWithDecimals(right, decimals), " > ", _formatWithDecimals(left, decimals) @@ -464,7 +464,7 @@ contract AssertionsTest is DSTest { vm._expectCheatcodeRevert( bytes( string.concat( - "Assertion failed: ", + "assertion failed: ", _formatWithDecimals(left, decimals), " < ", _formatWithDecimals(right, decimals) @@ -476,7 +476,7 @@ contract AssertionsTest is DSTest { vm._expectCheatcodeRevert( bytes( string.concat( - "Assertion failed: ", + "assertion failed: ", _formatWithDecimals(right, decimals), " > ", _formatWithDecimals(left, decimals) @@ -514,7 +514,7 @@ contract AssertionsTest is DSTest { vm._expectCheatcodeRevert( bytes( string.concat( - "Assertion failed: ", + "assertion failed: ", _formatWithDecimals(left, decimals), " !~= ", _formatWithDecimals(right, decimals), @@ -558,7 +558,7 @@ contract AssertionsTest is DSTest { vm._expectCheatcodeRevert( bytes( string.concat( - "Assertion failed: ", + "assertion failed: ", _formatWithDecimals(left, decimals), " !~= ", _formatWithDecimals(right, decimals), @@ -606,7 +606,7 @@ contract AssertionsTest is DSTest { vm._expectCheatcodeRevert( bytes( string.concat( - "Assertion failed: ", + "assertion failed: ", _formatWithDecimals(left, decimals), " !~= ", _formatWithDecimals(right, decimals), @@ -655,7 +655,7 @@ contract AssertionsTest is DSTest { vm._expectCheatcodeRevert( bytes( string.concat( - "Assertion failed: ", + "assertion failed: ", _formatWithDecimals(left, decimals), " !~= ", _formatWithDecimals(right, decimals), @@ -683,10 +683,10 @@ contract AssertionsTest is DSTest { vm.assertEq(arr2, arr2); vm.assertNotEq(arr1, arr2); - vm._expectCheatcodeRevert(bytes("Assertion failed: [1] != [1, 2]")); + vm._expectCheatcodeRevert(bytes("assertion failed: [1] != [1, 2]")); vm.assertEq(arr1, arr2); - vm._expectCheatcodeRevert(bytes(string.concat("Assertion failed: [1, 2] == [1, 2]"))); + vm._expectCheatcodeRevert(bytes(string.concat("assertion failed: [1, 2] == [1, 2]"))); vm.assertNotEq(arr2, arr2); } { @@ -702,7 +702,7 @@ contract AssertionsTest is DSTest { vm._expectCheatcodeRevert(bytes(string.concat(errorMessage, ": [5, 0] != [", vm.toString(arr2[0]), "]"))); vm.assertEq(arr1, arr2, errorMessage); - vm._expectCheatcodeRevert(bytes(string.concat("Assertion failed: [5, 0] == [5, 0]"))); + vm._expectCheatcodeRevert(bytes(string.concat("assertion failed: [5, 0] == [5, 0]"))); vm.assertNotEq(arr1, arr1); } { @@ -718,7 +718,7 @@ contract AssertionsTest is DSTest { vm._expectCheatcodeRevert(bytes(string.concat(errorMessage, ": [true, false] != [false, true]"))); vm.assertEq(arr1, arr2, errorMessage); - vm._expectCheatcodeRevert(bytes(string("Assertion failed: [true, false] == [true, false]"))); + vm._expectCheatcodeRevert(bytes(string("assertion failed: [true, false] == [true, false]"))); vm.assertNotEq(arr1, arr1); } { @@ -732,7 +732,7 @@ contract AssertionsTest is DSTest { vm._expectCheatcodeRevert(bytes(string.concat(errorMessage, ": [", vm.toString(arr1[0]), "] != []"))); vm.assertEq(arr1, arr2, errorMessage); - vm._expectCheatcodeRevert(bytes(string("Assertion failed: [] == []"))); + vm._expectCheatcodeRevert(bytes(string("assertion failed: [] == []"))); vm.assertNotEq(arr2, arr2); } { @@ -750,7 +750,7 @@ contract AssertionsTest is DSTest { vm.assertEq(arr1, arr2, errorMessage); vm._expectCheatcodeRevert( - bytes(string.concat("Assertion failed: [", vm.toString(arr2[0]), "] == [", vm.toString(arr2[0]), "]")) + bytes(string.concat("assertion failed: [", vm.toString(arr2[0]), "] == [", vm.toString(arr2[0]), "]")) ); vm.assertNotEq(arr2, arr2); } @@ -765,7 +765,7 @@ contract AssertionsTest is DSTest { vm.assertEq(arr2, arr2); vm.assertNotEq(arr1, arr2); - vm._expectCheatcodeRevert(bytes("Assertion failed: [foo] != [, , bar]")); + vm._expectCheatcodeRevert(bytes("assertion failed: [foo] != [, , bar]")); vm.assertEq(arr1, arr2); vm._expectCheatcodeRevert(bytes(string.concat(errorMessage, ": [foo] == [foo]"))); @@ -782,7 +782,7 @@ contract AssertionsTest is DSTest { vm.assertEq(arr2, arr2); vm.assertNotEq(arr1, arr2); - vm._expectCheatcodeRevert(bytes("Assertion failed: [0x1111] != [0x, 0x1234]")); + vm._expectCheatcodeRevert(bytes("assertion failed: [0x1111] != [0x, 0x1234]")); vm.assertEq(arr1, arr2); vm._expectCheatcodeRevert(bytes(string.concat(errorMessage, ": [0x1111] == [0x1111]"))); @@ -794,13 +794,13 @@ contract AssertionsTest is DSTest { vm.assertTrue(true); vm.assertFalse(false); - vm._expectCheatcodeRevert(bytes("Assertion failed")); + vm._expectCheatcodeRevert(bytes("assertion failed")); vm.assertTrue(false); vm._expectCheatcodeRevert(bytes(errorMessage)); vm.assertTrue(false, errorMessage); - vm._expectCheatcodeRevert(bytes("Assertion failed")); + vm._expectCheatcodeRevert(bytes("assertion failed")); vm.assertFalse(true); vm._expectCheatcodeRevert(bytes(errorMessage)); @@ -808,16 +808,16 @@ contract AssertionsTest is DSTest { } function testAssertApproxEqRel() public { - vm._expectCheatcodeRevert(bytes("Assertion failed: Overflow in delta calculation")); + vm._expectCheatcodeRevert(bytes("assertion failed: overflow in delta calculation")); vm.assertApproxEqRel(type(int256).min, type(int256).max, 0); - vm._expectCheatcodeRevert(bytes(string.concat(errorMessage, ": Overflow in delta calculation"))); + vm._expectCheatcodeRevert(bytes(string.concat(errorMessage, ": overflow in delta calculation"))); vm.assertApproxEqRel(int256(1), int256(0), 0, errorMessage); - vm._expectCheatcodeRevert(bytes(string.concat(errorMessage, ": Overflow in delta calculation"))); + vm._expectCheatcodeRevert(bytes(string.concat(errorMessage, ": overflow in delta calculation"))); vm.assertApproxEqRel(uint256(0), type(uint256).max, 0, errorMessage); - vm._expectCheatcodeRevert(bytes("Assertion failed: Overflow in delta calculation")); + vm._expectCheatcodeRevert(bytes("assertion failed: overflow in delta calculation")); vm.assertApproxEqRel(uint256(1), uint256(0), uint256(0)); } }