Skip to content

Commit

Permalink
check using fuzzing
Browse files Browse the repository at this point in the history
  • Loading branch information
Amxx committed Mar 17, 2024
1 parent a52481a commit 66df9c6
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 60 deletions.
37 changes: 0 additions & 37 deletions contracts/mocks/ComputedAddressRemainderMock.sol

This file was deleted.

18 changes: 18 additions & 0 deletions test/proxy/Clones.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

import {Test} from "forge-std/Test.sol";
import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol";

contract ClonesTest is Test {
function testClonesPredicted(address implementation, bytes32 salt) public {
address predicted = Clones.predictDeterministicAddress(implementation, salt);
bytes32 spill;
/// @solidity memory-safe-assembly
assembly {
spill := and(predicted, 0xffffffffffffffffffffffff0000000000000000000000000000000000000000)
}
assertEq(spill, bytes32(0));
}
}
13 changes: 1 addition & 12 deletions test/proxy/Clones.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ async function fixture() {

const factory = await ethers.deployContract('$Clones');
const implementation = await ethers.deployContract('DummyImplementation');
const computedAddressMock = await ethers.deployContract('ComputedAddressRemainderMock');

const newClone = async (initData, opts = {}) => {
const clone = await factory.$clone.staticCall(implementation).then(address => implementation.attach(address));
Expand All @@ -28,7 +27,7 @@ async function fixture() {
return clone;
};

return { deployer, factory, implementation, computedAddressMock, newClone, newCloneDeterministic };
return { deployer, factory, implementation, newClone, newCloneDeterministic };
}

describe('Clones', function () {
Expand Down Expand Up @@ -84,15 +83,5 @@ describe('Clones', function () {
.to.emit(this.factory, 'return$cloneDeterministic')
.withArgs(predicted);
});

it('clean address prediction', async function () {
const salt = ethers.randomBytes(32);
const predictedRemainder = await this.computedAddressMock.getClonesPredictedRemainder(
this.implementation,
salt,
ethers.Typed.address(this.deployer),
);
expect(predictedRemainder).to.equal(0);
});
});
});
18 changes: 18 additions & 0 deletions test/utils/Create2.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

import {Test} from "forge-std/Test.sol";
import {Create2} from "@openzeppelin/contracts/utils/Create2.sol";

contract Create2Test is Test {
function testClonesPredicted(bytes32 salt, bytes32 bytecodeHash, address deployer) public {
address predicted = Create2.computeAddress(salt, bytecodeHash, deployer);
bytes32 spill;
/// @solidity memory-safe-assembly
assembly {
spill := and(predicted, 0xffffffffffffffffffffffff0000000000000000000000000000000000000000)
}
assertEq(spill, bytes32(0));
}
}
12 changes: 1 addition & 11 deletions test/utils/Create2.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ async function fixture() {
const [deployer, other] = await ethers.getSigners();

const factory = await ethers.deployContract('$Create2');
const computedAddressMock = await ethers.deployContract('ComputedAddressRemainderMock');

// Bytecode for deploying a contract that includes a constructor.
// We use a vesting wallet, with 3 constructor arguments.
Expand All @@ -20,7 +19,7 @@ async function fixture() {
.getContractFactory('$Create2')
.then(({ bytecode, interface }) => ethers.concat([bytecode, interface.encodeDeploy([])]));

return { deployer, other, factory, computedAddressMock, constructorByteCode, constructorLessBytecode };
return { deployer, other, factory, constructorByteCode, constructorLessBytecode };
}

describe('Create2', function () {
Expand Down Expand Up @@ -55,15 +54,6 @@ describe('Create2', function () {
);
expect(onChainComputed).to.equal(offChainComputed);
});

it('computes the clean contract address', async function () {
const computedRemainder = await this.computedAddressMock.getCreate2ComputedRemainder(
saltHex,
ethers.keccak256(this.constructorByteCode),
ethers.Typed.address(this.deployer),
);
expect(computedRemainder).to.equal(0);
});
});

describe('deploy', function () {
Expand Down

0 comments on commit 66df9c6

Please sign in to comment.