Răsfoiți Sursa

Update forge and change visibility in fuzz tests (#5103)

Co-authored-by: cairo <cairoeth@protonmail.com>
Ernesto García 11 luni în urmă
părinte
comite
f96237308f

+ 1 - 1
lib/forge-std

@@ -1 +1 @@
-Subproject commit 8f24d6b04c92975e0795b5868aa0d783251cdeaa
+Subproject commit 1eea5bae12ae557d589f9f0f0edae2faa47cb262

+ 1 - 1
scripts/generate/templates/Checkpoints.t.js

@@ -36,7 +36,7 @@ function _prepareKeys(${opts.keyTypeName}[] memory keys, ${opts.keyTypeName} max
     }
 }
 
-function _assertLatestCheckpoint(bool exist, ${opts.keyTypeName} key, ${opts.valueTypeName} value) internal {
+function _assertLatestCheckpoint(bool exist, ${opts.keyTypeName} key, ${opts.valueTypeName} value) internal view {
     (bool _exist, ${opts.keyTypeName} _key, ${opts.valueTypeName} _value) = _ckpts.latestCheckpoint();
     assertEq(_exist, exist);
     assertEq(_key, key);

+ 4 - 4
scripts/generate/templates/SlotDerivation.t.js

@@ -45,7 +45,7 @@ function _assertDeriveArray(uint256 length, uint256 offset) public {
 const mapping = ({ type, name }) => `\
 mapping(${type} => bytes) private _${type}Mapping;
 
-function testSymbolicDeriveMapping${name}(${type} key) public {
+function testSymbolicDeriveMapping${name}(${type} key) public view {
     bytes32 baseSlot;
     assembly {
         baseSlot := _${type}Mapping.slot
@@ -76,15 +76,15 @@ function testSymbolicDeriveMapping${name}Dirty(bytes32 dirtyKey) public {
 const boundedMapping = ({ type, name }) => `\
 mapping(${type} => bytes) private _${type}Mapping;
 
-function testDeriveMapping${name}(${type} memory key) public {
+function testDeriveMapping${name}(${type} memory key) public view {
     _assertDeriveMapping${name}(key);
 }
 
-function symbolicDeriveMapping${name}() public {
+function symbolicDeriveMapping${name}() public view {
     _assertDeriveMapping${name}(svm.create${name}(256, "DeriveMapping${name}Input"));
 }
 
-function _assertDeriveMapping${name}(${type} memory key) internal {
+function _assertDeriveMapping${name}(${type} memory key) internal view {
     bytes32 baseSlot;
     assembly {
         baseSlot := _${type}Mapping.slot

+ 6 - 2
test/governance/Governor.t.sol

@@ -9,7 +9,11 @@ import {Governor} from "@openzeppelin/contracts/governance/Governor.sol";
 contract GovernorInternalTest is Test, Governor {
     constructor() Governor("") {}
 
-    function testValidDescriptionForProposer(string memory description, address proposer, bool includeProposer) public {
+    function testValidDescriptionForProposer(
+        string memory description,
+        address proposer,
+        bool includeProposer
+    ) public view {
         if (includeProposer) {
             description = string.concat(description, "#proposer=", Strings.toHexString(proposer));
         }
@@ -20,7 +24,7 @@ contract GovernorInternalTest is Test, Governor {
         string memory description,
         address commitProposer,
         address actualProposer
-    ) public {
+    ) public view {
         vm.assume(commitProposer != actualProposer);
         description = string.concat(description, "#proposer=", Strings.toHexString(commitProposer));
         assertFalse(_isValidDescriptionForProposer(actualProposer, description));

+ 3 - 3
test/proxy/Clones.t.sol

@@ -10,7 +10,7 @@ contract ClonesTest is Test {
         return 42;
     }
 
-    function testSymbolicPredictDeterministicAddressSpillage(address implementation, bytes32 salt) public {
+    function testSymbolicPredictDeterministicAddressSpillage(address implementation, bytes32 salt) public view {
         address predicted = Clones.predictDeterministicAddress(implementation, salt);
         bytes32 spillage;
         assembly ("memory-safe") {
@@ -23,7 +23,7 @@ contract ClonesTest is Test {
         address implementation,
         bytes32 salt,
         bytes memory args
-    ) public {
+    ) public view {
         vm.assume(args.length < 0xbfd3);
 
         address predicted = Clones.predictDeterministicAddressWithImmutableArgs(implementation, args, salt);
@@ -59,7 +59,7 @@ contract ClonesTest is Test {
         assertEq(ClonesTest(cloneDirty).getNumber(), this.getNumber());
     }
 
-    function testPredictDeterministicAddressDirty(bytes32 salt) external {
+    function testPredictDeterministicAddressDirty(bytes32 salt) external view {
         address predictClean = Clones.predictDeterministicAddress(address(this), salt);
         address predictDirty = Clones.predictDeterministicAddress(_dirty(address(this)), salt);
 

+ 3 - 3
test/utils/Arrays.t.sol

@@ -7,12 +7,12 @@ import {SymTest} from "halmos-cheatcodes/SymTest.sol";
 import {Arrays} from "@openzeppelin/contracts/utils/Arrays.sol";
 
 contract ArraysTest is Test, SymTest {
-    function testSort(uint256[] memory values) public {
+    function testSort(uint256[] memory values) public pure {
         Arrays.sort(values);
         _assertSort(values);
     }
 
-    function symbolicSort() public {
+    function symbolicSort() public pure {
         uint256[] memory values = new uint256[](3);
         for (uint256 i = 0; i < 3; i++) {
             values[i] = svm.createUint256("arrayElement");
@@ -23,7 +23,7 @@ contract ArraysTest is Test, SymTest {
 
     /// Asserts
 
-    function _assertSort(uint256[] memory values) internal {
+    function _assertSort(uint256[] memory values) internal pure {
         for (uint256 i = 1; i < values.length; ++i) {
             assertLe(values[i - 1], values[i]);
         }

+ 2 - 2
test/utils/Base64.t.sol

@@ -6,11 +6,11 @@ import {Test} from "forge-std/Test.sol";
 import {Base64} from "@openzeppelin/contracts/utils/Base64.sol";
 
 contract Base64Test is Test {
-    function testEncode(bytes memory input) external {
+    function testEncode(bytes memory input) external pure {
         assertEq(Base64.encode(input), vm.toBase64(input));
     }
 
-    function testEncodeURL(bytes memory input) external {
+    function testEncodeURL(bytes memory input) external pure {
         assertEq(Base64.encodeURL(input), _removePadding(vm.toBase64URL(input)));
     }
 

+ 1 - 1
test/utils/Create2.t.sol

@@ -6,7 +6,7 @@ import {Test} from "forge-std/Test.sol";
 import {Create2} from "@openzeppelin/contracts/utils/Create2.sol";
 
 contract Create2Test is Test {
-    function testSymbolicComputeAddressSpillage(bytes32 salt, bytes32 bytecodeHash, address deployer) public {
+    function testSymbolicComputeAddressSpillage(bytes32 salt, bytes32 bytecodeHash, address deployer) public pure {
         address predicted = Create2.computeAddress(salt, bytecodeHash, deployer);
         bytes32 spillage;
         assembly ("memory-safe") {

+ 6 - 6
test/utils/ShortStrings.t.sol

@@ -10,12 +10,12 @@ import {ShortStrings, ShortString} from "@openzeppelin/contracts/utils/ShortStri
 contract ShortStringsTest is Test, SymTest {
     string _fallback;
 
-    function testRoundtripShort(string memory input) external {
+    function testRoundtripShort(string memory input) external pure {
         vm.assume(_isShort(input));
         _assertRoundtripShort(input);
     }
 
-    function symbolicRoundtripShort() external {
+    function symbolicRoundtripShort() external pure {
         string memory input = svm.createString(31, "RoundtripShortInput");
         _assertRoundtripShort(input);
     }
@@ -41,12 +41,12 @@ contract ShortStringsTest is Test, SymTest {
         _assertRevertLong(input);
     }
 
-    function testLengthShort(string memory input) external {
+    function testLengthShort(string memory input) external pure {
         vm.assume(_isShort(input));
         _assertLengthShort(input);
     }
 
-    function symbolicLengthShort() external {
+    function symbolicLengthShort() external pure {
         string memory input = svm.createString(31, "LengthShortInput");
         _assertLengthShort(input);
     }
@@ -66,7 +66,7 @@ contract ShortStringsTest is Test, SymTest {
 
     /// Assertions
 
-    function _assertRoundtripShort(string memory input) internal {
+    function _assertRoundtripShort(string memory input) internal pure {
         ShortString short = ShortStrings.toShortString(input);
         string memory output = ShortStrings.toString(short);
         assertEq(input, output);
@@ -84,7 +84,7 @@ contract ShortStringsTest is Test, SymTest {
         this.toShortString(input);
     }
 
-    function _assertLengthShort(string memory input) internal {
+    function _assertLengthShort(string memory input) internal pure {
         ShortString short = ShortStrings.toShortString(input);
         uint256 shortLength = ShortStrings.byteLength(short);
         uint256 inputLength = bytes(input).length;

+ 14 - 14
test/utils/SlotDerivation.t.sol

@@ -42,7 +42,7 @@ contract SlotDerivationTest is Test, SymTest {
 
     mapping(address => bytes) private _addressMapping;
 
-    function testSymbolicDeriveMappingAddress(address key) public {
+    function testSymbolicDeriveMappingAddress(address key) public view {
         bytes32 baseSlot;
         assembly {
             baseSlot := _addressMapping.slot
@@ -59,7 +59,7 @@ contract SlotDerivationTest is Test, SymTest {
 
     mapping(bool => bytes) private _boolMapping;
 
-    function testSymbolicDeriveMappingBoolean(bool key) public {
+    function testSymbolicDeriveMappingBoolean(bool key) public view {
         bytes32 baseSlot;
         assembly {
             baseSlot := _boolMapping.slot
@@ -76,7 +76,7 @@ contract SlotDerivationTest is Test, SymTest {
 
     mapping(bytes32 => bytes) private _bytes32Mapping;
 
-    function testSymbolicDeriveMappingBytes32(bytes32 key) public {
+    function testSymbolicDeriveMappingBytes32(bytes32 key) public view {
         bytes32 baseSlot;
         assembly {
             baseSlot := _bytes32Mapping.slot
@@ -93,7 +93,7 @@ contract SlotDerivationTest is Test, SymTest {
 
     mapping(bytes4 => bytes) private _bytes4Mapping;
 
-    function testSymbolicDeriveMappingBytes4(bytes4 key) public {
+    function testSymbolicDeriveMappingBytes4(bytes4 key) public view {
         bytes32 baseSlot;
         assembly {
             baseSlot := _bytes4Mapping.slot
@@ -110,7 +110,7 @@ contract SlotDerivationTest is Test, SymTest {
 
     mapping(uint256 => bytes) private _uint256Mapping;
 
-    function testSymbolicDeriveMappingUint256(uint256 key) public {
+    function testSymbolicDeriveMappingUint256(uint256 key) public view {
         bytes32 baseSlot;
         assembly {
             baseSlot := _uint256Mapping.slot
@@ -127,7 +127,7 @@ contract SlotDerivationTest is Test, SymTest {
 
     mapping(uint32 => bytes) private _uint32Mapping;
 
-    function testSymbolicDeriveMappingUint32(uint32 key) public {
+    function testSymbolicDeriveMappingUint32(uint32 key) public view {
         bytes32 baseSlot;
         assembly {
             baseSlot := _uint32Mapping.slot
@@ -144,7 +144,7 @@ contract SlotDerivationTest is Test, SymTest {
 
     mapping(int256 => bytes) private _int256Mapping;
 
-    function testSymbolicDeriveMappingInt256(int256 key) public {
+    function testSymbolicDeriveMappingInt256(int256 key) public view {
         bytes32 baseSlot;
         assembly {
             baseSlot := _int256Mapping.slot
@@ -161,7 +161,7 @@ contract SlotDerivationTest is Test, SymTest {
 
     mapping(int32 => bytes) private _int32Mapping;
 
-    function testSymbolicDeriveMappingInt32(int32 key) public {
+    function testSymbolicDeriveMappingInt32(int32 key) public view {
         bytes32 baseSlot;
         assembly {
             baseSlot := _int32Mapping.slot
@@ -178,15 +178,15 @@ contract SlotDerivationTest is Test, SymTest {
 
     mapping(string => bytes) private _stringMapping;
 
-    function testDeriveMappingString(string memory key) public {
+    function testDeriveMappingString(string memory key) public view {
         _assertDeriveMappingString(key);
     }
 
-    function symbolicDeriveMappingString() public {
+    function symbolicDeriveMappingString() public view {
         _assertDeriveMappingString(svm.createString(256, "DeriveMappingStringInput"));
     }
 
-    function _assertDeriveMappingString(string memory key) internal {
+    function _assertDeriveMappingString(string memory key) internal view {
         bytes32 baseSlot;
         assembly {
             baseSlot := _stringMapping.slot
@@ -203,15 +203,15 @@ contract SlotDerivationTest is Test, SymTest {
 
     mapping(bytes => bytes) private _bytesMapping;
 
-    function testDeriveMappingBytes(bytes memory key) public {
+    function testDeriveMappingBytes(bytes memory key) public view {
         _assertDeriveMappingBytes(key);
     }
 
-    function symbolicDeriveMappingBytes() public {
+    function symbolicDeriveMappingBytes() public view {
         _assertDeriveMappingBytes(svm.createBytes(256, "DeriveMappingBytesInput"));
     }
 
-    function _assertDeriveMappingBytes(bytes memory key) internal {
+    function _assertDeriveMappingBytes(bytes memory key) internal view {
         bytes32 baseSlot;
         assembly {
             baseSlot := _bytesMapping.slot

+ 4 - 4
test/utils/Strings.t.sol

@@ -9,19 +9,19 @@ import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
 contract StringsTest is Test {
     using Strings for *;
 
-    function testParse(uint256 value) external {
+    function testParse(uint256 value) external pure {
         assertEq(value, value.toString().parseUint());
     }
 
-    function testParseSigned(int256 value) external {
+    function testParseSigned(int256 value) external pure {
         assertEq(value, value.toStringSigned().parseInt());
     }
 
-    function testParseHex(uint256 value) external {
+    function testParseHex(uint256 value) external pure {
         assertEq(value, value.toHexString().parseHexUint());
     }
 
-    function testParseChecksumHex(address value) external {
+    function testParseChecksumHex(address value) external pure {
         assertEq(value, value.toChecksumHexString().parseAddress());
     }
 }

+ 2 - 2
test/utils/cryptography/P256.t.sol

@@ -9,7 +9,7 @@ import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
 
 contract P256Test is Test {
     /// forge-config: default.fuzz.runs = 512
-    function testVerify(bytes32 digest, uint256 seed) public {
+    function testVerify(bytes32 digest, uint256 seed) public view {
         uint256 privateKey = _asPrivateKey(seed);
 
         (uint256 x, uint256 y) = vm.publicKeyP256(privateKey);
@@ -20,7 +20,7 @@ contract P256Test is Test {
     }
 
     /// forge-config: default.fuzz.runs = 512
-    function testRecover(bytes32 digest, uint256 seed) public {
+    function testRecover(bytes32 digest, uint256 seed) public view {
         uint256 privateKey = _asPrivateKey(seed);
 
         (uint256 x, uint256 y) = vm.publicKeyP256(privateKey);

+ 16 - 16
test/utils/math/Math.t.sol

@@ -7,18 +7,18 @@ import {Test, stdError} from "forge-std/Test.sol";
 import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
 
 contract MathTest is Test {
-    function testSymbolicTernary(bool f, uint256 a, uint256 b) public {
+    function testSymbolicTernary(bool f, uint256 a, uint256 b) public pure {
         assertEq(Math.ternary(f, a, b), f ? a : b);
     }
 
     // MIN & MAX
-    function testSymbolicMinMax(uint256 a, uint256 b) public {
+    function testSymbolicMinMax(uint256 a, uint256 b) public pure {
         assertEq(Math.min(a, b), a < b ? a : b);
         assertEq(Math.max(a, b), a > b ? a : b);
     }
 
     // CEILDIV
-    function testCeilDiv(uint256 a, uint256 b) public {
+    function testCeilDiv(uint256 a, uint256 b) public pure {
         vm.assume(b > 0);
 
         uint256 result = Math.ceilDiv(a, b);
@@ -35,7 +35,7 @@ contract MathTest is Test {
     }
 
     // SQRT
-    function testSqrt(uint256 input, uint8 r) public {
+    function testSqrt(uint256 input, uint8 r) public pure {
         Math.Rounding rounding = _asRounding(r);
 
         uint256 result = Math.sqrt(input, rounding);
@@ -66,31 +66,31 @@ contract MathTest is Test {
     }
 
     // INV
-    function testInvMod(uint256 value, uint256 p) public {
+    function testInvMod(uint256 value, uint256 p) public pure {
         _testInvMod(value, p, true);
     }
 
-    function testInvMod2(uint256 seed) public {
+    function testInvMod2(uint256 seed) public pure {
         uint256 p = 2; // prime
         _testInvMod(bound(seed, 1, p - 1), p, false);
     }
 
-    function testInvMod17(uint256 seed) public {
+    function testInvMod17(uint256 seed) public pure {
         uint256 p = 17; // prime
         _testInvMod(bound(seed, 1, p - 1), p, false);
     }
 
-    function testInvMod65537(uint256 seed) public {
+    function testInvMod65537(uint256 seed) public pure {
         uint256 p = 65537; // prime
         _testInvMod(bound(seed, 1, p - 1), p, false);
     }
 
-    function testInvModP256(uint256 seed) public {
+    function testInvModP256(uint256 seed) public pure {
         uint256 p = 0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff; // prime
         _testInvMod(bound(seed, 1, p - 1), p, false);
     }
 
-    function _testInvMod(uint256 value, uint256 p, bool allowZero) private {
+    function _testInvMod(uint256 value, uint256 p, bool allowZero) private pure {
         uint256 inverse = Math.invMod(value, p);
         if (inverse != 0) {
             assertEq(mulmod(value, inverse, p), 1);
@@ -101,7 +101,7 @@ contract MathTest is Test {
     }
 
     // LOG2
-    function testLog2(uint256 input, uint8 r) public {
+    function testLog2(uint256 input, uint8 r) public pure {
         Math.Rounding rounding = _asRounding(r);
 
         uint256 result = Math.log2(input, rounding);
@@ -128,7 +128,7 @@ contract MathTest is Test {
     }
 
     // LOG10
-    function testLog10(uint256 input, uint8 r) public {
+    function testLog10(uint256 input, uint8 r) public pure {
         Math.Rounding rounding = _asRounding(r);
 
         uint256 result = Math.log10(input, rounding);
@@ -155,7 +155,7 @@ contract MathTest is Test {
     }
 
     // LOG256
-    function testLog256(uint256 input, uint8 r) public {
+    function testLog256(uint256 input, uint8 r) public pure {
         Math.Rounding rounding = _asRounding(r);
 
         uint256 result = Math.log256(input, rounding);
@@ -182,7 +182,7 @@ contract MathTest is Test {
     }
 
     // MULDIV
-    function testMulDiv(uint256 x, uint256 y, uint256 d) public {
+    function testMulDiv(uint256 x, uint256 y, uint256 d) public pure {
         // Full precision for x * y
         (uint256 xyHi, uint256 xyLo) = _mulHighLow(x, y);
 
@@ -225,7 +225,7 @@ contract MathTest is Test {
         assertEq(result, _nativeModExp(b, e, m));
     }
 
-    function testTryModExp(uint256 b, uint256 e, uint256 m) public {
+    function testTryModExp(uint256 b, uint256 e, uint256 m) public view {
         (bool success, uint256 result) = Math.tryModExp(b, e, m);
         assertEq(success, m != 0);
         if (success) {
@@ -247,7 +247,7 @@ contract MathTest is Test {
         assertEq(res, _nativeModExp(b, e, m));
     }
 
-    function testTryModExpMemory(uint256 b, uint256 e, uint256 m) public {
+    function testTryModExpMemory(uint256 b, uint256 e, uint256 m) public view {
         (bool success, bytes memory result) = Math.tryModExp(
             abi.encodePacked(b),
             abi.encodePacked(e),

+ 7 - 7
test/utils/math/SignedMath.t.sol

@@ -8,18 +8,18 @@ import {Math} from "../../../contracts/utils/math/Math.sol";
 import {SignedMath} from "../../../contracts/utils/math/SignedMath.sol";
 
 contract SignedMathTest is Test {
-    function testSymbolicTernary(bool f, int256 a, int256 b) public {
+    function testSymbolicTernary(bool f, int256 a, int256 b) public pure {
         assertEq(SignedMath.ternary(f, a, b), f ? a : b);
     }
 
     // MIN & MAX
-    function testSymbolicMinMax(int256 a, int256 b) public {
+    function testSymbolicMinMax(int256 a, int256 b) public pure {
         assertEq(SignedMath.min(a, b), a < b ? a : b);
         assertEq(SignedMath.max(a, b), a > b ? a : b);
     }
 
     // MIN
-    function testSymbolicMin(int256 a, int256 b) public {
+    function testSymbolicMin(int256 a, int256 b) public pure {
         int256 result = SignedMath.min(a, b);
 
         assertLe(result, a);
@@ -28,7 +28,7 @@ contract SignedMathTest is Test {
     }
 
     // MAX
-    function testSymbolicMax(int256 a, int256 b) public {
+    function testSymbolicMax(int256 a, int256 b) public pure {
         int256 result = SignedMath.max(a, b);
 
         assertGe(result, a);
@@ -38,7 +38,7 @@ contract SignedMathTest is Test {
 
     // AVERAGE
     // 1. simple test, not full int256 range
-    function testAverage1(int256 a, int256 b) public {
+    function testAverage1(int256 a, int256 b) public pure {
         a = bound(a, type(int256).min / 2, type(int256).max / 2);
         b = bound(b, type(int256).min / 2, type(int256).max / 2);
 
@@ -48,7 +48,7 @@ contract SignedMathTest is Test {
     }
 
     // 2. more complex test, full int256 range
-    function testAverage2(int256 a, int256 b) public {
+    function testAverage2(int256 a, int256 b) public pure {
         (int256 result, int256 min, int256 max) = (
             SignedMath.average(a, b),
             SignedMath.min(a, b),
@@ -69,7 +69,7 @@ contract SignedMathTest is Test {
     }
 
     // ABS
-    function testSymbolicAbs(int256 a) public {
+    function testSymbolicAbs(int256 a) public pure {
         uint256 result = SignedMath.abs(a);
 
         unchecked {

+ 3 - 3
test/utils/structs/Checkpoints.t.sol

@@ -30,7 +30,7 @@ contract CheckpointsTrace224Test is Test {
         }
     }
 
-    function _assertLatestCheckpoint(bool exist, uint32 key, uint224 value) internal {
+    function _assertLatestCheckpoint(bool exist, uint32 key, uint224 value) internal view {
         (bool _exist, uint32 _key, uint224 _value) = _ckpts.latestCheckpoint();
         assertEq(_exist, exist);
         assertEq(_key, key);
@@ -138,7 +138,7 @@ contract CheckpointsTrace208Test is Test {
         }
     }
 
-    function _assertLatestCheckpoint(bool exist, uint48 key, uint208 value) internal {
+    function _assertLatestCheckpoint(bool exist, uint48 key, uint208 value) internal view {
         (bool _exist, uint48 _key, uint208 _value) = _ckpts.latestCheckpoint();
         assertEq(_exist, exist);
         assertEq(_key, key);
@@ -246,7 +246,7 @@ contract CheckpointsTrace160Test is Test {
         }
     }
 
-    function _assertLatestCheckpoint(bool exist, uint96 key, uint160 value) internal {
+    function _assertLatestCheckpoint(bool exist, uint96 key, uint160 value) internal view {
         (bool _exist, uint96 _key, uint160 _value) = _ckpts.latestCheckpoint();
         assertEq(_exist, exist);
         assertEq(_key, key);

+ 1 - 1
test/utils/structs/Heap.t.sol

@@ -12,7 +12,7 @@ contract Uint256HeapTest is Test {
 
     Heap.Uint256Heap internal heap;
 
-    function _validateHeap(function(uint256, uint256) view returns (bool) comp) internal {
+    function _validateHeap(function(uint256, uint256) view returns (bool) comp) internal view {
         for (uint32 i = 1; i < heap.length(); ++i) {
             assertFalse(comp(heap.tree[i], heap.tree[(i - 1) / 2]));
         }