From 593e83a6ec00ff24924961502cbe7d509519b7dc Mon Sep 17 00:00:00 2001 From: steven nevins Date: Fri, 15 Sep 2023 19:27:09 -0400 Subject: [PATCH] initial commit --- foundry.toml | 1 - script/Counter.s.sol | 12 ------------ src/Counter.sol | 14 -------------- test/Counter.t.sol | 24 ------------------------ test/Create2.t.sol | 28 ++++++++++++++++++++++++++++ 5 files changed, 28 insertions(+), 51 deletions(-) delete mode 100644 script/Counter.s.sol delete mode 100644 src/Counter.sol delete mode 100644 test/Counter.t.sol create mode 100644 test/Create2.t.sol diff --git a/foundry.toml b/foundry.toml index 25b918f..49f9c28 100644 --- a/foundry.toml +++ b/foundry.toml @@ -1,5 +1,4 @@ [profile.default] -src = "src" out = "out" libs = ["lib"] diff --git a/script/Counter.s.sol b/script/Counter.s.sol deleted file mode 100644 index 1a47b40..0000000 --- a/script/Counter.s.sol +++ /dev/null @@ -1,12 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.13; - -import {Script, console2} from "forge-std/Script.sol"; - -contract CounterScript is Script { - function setUp() public {} - - function run() public { - vm.broadcast(); - } -} diff --git a/src/Counter.sol b/src/Counter.sol deleted file mode 100644 index aded799..0000000 --- a/src/Counter.sol +++ /dev/null @@ -1,14 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.13; - -contract Counter { - uint256 public number; - - function setNumber(uint256 newNumber) public { - number = newNumber; - } - - function increment() public { - number++; - } -} diff --git a/test/Counter.t.sol b/test/Counter.t.sol deleted file mode 100644 index e9b9e6a..0000000 --- a/test/Counter.t.sol +++ /dev/null @@ -1,24 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.13; - -import {Test, console2} from "forge-std/Test.sol"; -import {Counter} from "../src/Counter.sol"; - -contract CounterTest is Test { - Counter public counter; - - function setUp() public { - counter = new Counter(); - counter.setNumber(0); - } - - function test_Increment() public { - counter.increment(); - assertEq(counter.number(), 1); - } - - function testFuzz_SetNumber(uint256 x) public { - counter.setNumber(x); - assertEq(counter.number(), x); - } -} diff --git a/test/Create2.t.sol b/test/Create2.t.sol new file mode 100644 index 0000000..ca55dab --- /dev/null +++ b/test/Create2.t.sol @@ -0,0 +1,28 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.13; + +import {Test} from "forge-std/Test.sol"; + +contract Emitter { + event Ping(); + + function ping() external { + emit Ping(); + } +} + +contract Create2Test is Test { + function test_Create2() public { + bytes32 salt = bytes32(0); + bytes memory creationCode = type(Emitter).creationCode; + bytes memory initCode = bytes.concat(creationCode, abi.encode()); + (bool success,) = CREATE2_FACTORY.call(bytes.concat(salt, initCode)); + assertTrue(success); + address predictedTo = computeCreate2Address(salt, hashInitCode(creationCode)); + + (success,) = CREATE2_FACTORY.call(bytes.concat(salt, initCode)); + assertFalse(success); + + Emitter(predictedTo).ping(); + } +}