Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update forge and change visibility in fuzz tests #5103

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/generate/templates/Checkpoints.t.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,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);
Expand Down
4 changes: 2 additions & 2 deletions scripts/generate/templates/Packing.t.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import {Packing} from "@openzeppelin/contracts/utils/Packing.sol";
`;

const testPack = (left, right) => `\
function testPack(bytes${left} left, bytes${right} right) external {
function testPack(bytes${left} left, bytes${right} right) external pure {
assertEq(left, Packing.pack_${left}_${right}(left, right).extract_${left + right}_${left}(0));
assertEq(right, Packing.pack_${left}_${right}(left, right).extract_${left + right}_${right}(${left}));
}
`;

const testReplace = (outer, inner) => `\
function testReplace(bytes${outer} container, bytes${inner} newValue, uint8 offset) external {
function testReplace(bytes${outer} container, bytes${inner} newValue, uint8 offset) external pure {
offset = uint8(bound(offset, 0, ${outer - inner}));

bytes${inner} oldValue = container.extract_${outer}_${inner}(offset);
Expand Down
8 changes: 4 additions & 4 deletions scripts/generate/templates/SlotDerivation.t.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions test/governance/Governor.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand All @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions test/proxy/Clones.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down Expand Up @@ -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);

Expand Down
6 changes: 3 additions & 3 deletions test/utils/Arrays.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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]);
}
Expand Down
4 changes: 2 additions & 2 deletions test/utils/Base64.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}

Expand Down
2 changes: 1 addition & 1 deletion test/utils/Create2.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
Loading