2
2
pragma solidity ^ 0.8.20 ;
3
3
4
4
import {Owned} from "solmate/src/auth/Owned.sol " ;
5
- import {Test, console2} from "forge-std/Test.sol " ;
5
+ import {Test} from "forge-std/Test.sol " ;
6
+ import {console2} from "forge-std/console2.sol " ;
6
7
import {PoolManager} from "@uniswap/v4-core/src/PoolManager.sol " ;
7
8
import {UniswapV4DeployerCompetition} from "../src/UniswapV4DeployerCompetition.sol " ;
8
9
import {TickMath} from "@uniswap/v4-core/src/libraries/TickMath.sol " ;
@@ -20,6 +21,8 @@ contract UniswapV4DeployerCompetitionTest is Test {
20
21
address winner;
21
22
uint256 competitionDeadline;
22
23
24
+ bytes32 mask20bytes = bytes32 (uint256 (type (uint96 ).max));
25
+
23
26
function setUp () public {
24
27
competitionDeadline = block .timestamp + 7 days ;
25
28
v4Owner = makeAddr ("V4Owner " );
@@ -31,7 +34,9 @@ contract UniswapV4DeployerCompetitionTest is Test {
31
34
assertEq (competition.v4Owner (), v4Owner);
32
35
}
33
36
34
- function testUpdateBestAddress (bytes32 salt ) public {
37
+ function test_updateBestAddress_succeeds (bytes32 salt ) public {
38
+ salt = (salt & mask20bytes) | bytes32 (bytes20 (winner));
39
+
35
40
assertEq (competition.bestAddress (), address (0 ));
36
41
assertEq (competition.bestAddressSubmitter (), address (0 ));
37
42
assertEq (competition.bestAddressSalt (), bytes32 (0 ));
@@ -57,7 +62,7 @@ contract UniswapV4DeployerCompetitionTest is Test {
57
62
assertEq (address (competition).balance, 0 ether);
58
63
}
59
64
60
- function testCompetitionOver (bytes32 salt ) public {
65
+ function test_updateBestAddress_reverts_CompetitionOver (bytes32 salt ) public {
61
66
vm.warp (competition.competitionDeadline () + 1 );
62
67
vm.expectRevert (
63
68
abi.encodeWithSelector (
@@ -69,7 +74,52 @@ contract UniswapV4DeployerCompetitionTest is Test {
69
74
competition.updateBestAddress (salt);
70
75
}
71
76
72
- function testUpdateBestAddressOpen (bytes32 salt ) public {
77
+ function test_updateBestAddress_reverts_InvalidSigner (bytes32 salt ) public {
78
+ vm.assume (bytes20 (salt) != bytes20 (0 ));
79
+ vm.assume (bytes20 (salt) != bytes20 (winner));
80
+
81
+ vm.expectRevert (abi.encodeWithSelector (IUniswapV4DeployerCompetition.InvalidSender.selector , salt, winner));
82
+ vm.prank (winner);
83
+ competition.updateBestAddress (salt);
84
+ }
85
+
86
+ function test_updateBestAddress_equalSalt_reverts_WorseAddress (bytes32 salt ) public {
87
+ vm.assume (salt != bytes32 (0 ));
88
+ console2.logBytes32 (salt);
89
+ salt = (salt & mask20bytes) | bytes32 (bytes20 (winner));
90
+ console2.logBytes32 (salt);
91
+
92
+ vm.prank (winner);
93
+ competition.updateBestAddress (salt);
94
+ assertFalse (competition.bestAddress () == address (0 ));
95
+ assertEq (competition.bestAddressSubmitter (), winner);
96
+ assertEq (competition.bestAddressSalt (), salt);
97
+
98
+ bytes32 newSalt = (salt & mask20bytes) | bytes32 (bytes20 (address (1 )));
99
+ address newAddr = Create2.computeAddress (newSalt, initCodeHash, address (competition));
100
+ if (! newAddr.betterThan (competition.bestAddress ())) {
101
+ vm.expectRevert (
102
+ abi.encodeWithSelector (
103
+ IUniswapV4DeployerCompetition.WorseAddress.selector ,
104
+ newAddr,
105
+ competition.bestAddress (),
106
+ newAddr.score (),
107
+ competition.bestAddress ().score ()
108
+ )
109
+ );
110
+ vm.prank (address (1 ));
111
+ competition.updateBestAddress (newSalt);
112
+ } else {
113
+ vm.prank (address (1 ));
114
+ competition.updateBestAddress (newSalt);
115
+ assertEq (competition.bestAddressSubmitter (), address (1 ));
116
+ assertEq (competition.bestAddressSalt (), newSalt);
117
+ }
118
+ }
119
+
120
+ function test_deploy_succeeds (bytes32 salt ) public {
121
+ salt = (salt & mask20bytes) | bytes32 (bytes20 (winner));
122
+
73
123
vm.prank (winner);
74
124
competition.updateBestAddress (salt);
75
125
address v4Core = competition.bestAddress ();
@@ -81,7 +131,9 @@ contract UniswapV4DeployerCompetitionTest is Test {
81
131
assertEq (TickMath.MAX_TICK_SPACING, type (int16 ).max);
82
132
}
83
133
84
- function testCompetitionNotOver (bytes32 salt , uint256 timestamp ) public {
134
+ function test_deploy_reverts_CompetitionNotOver (bytes32 salt , uint256 timestamp ) public {
135
+ salt = (salt & mask20bytes) | bytes32 (bytes20 (winner));
136
+
85
137
vm.assume (timestamp < competition.competitionDeadline ());
86
138
vm.prank (winner);
87
139
competition.updateBestAddress (salt);
@@ -94,15 +146,19 @@ contract UniswapV4DeployerCompetitionTest is Test {
94
146
competition.deploy (abi.encodePacked (type (PoolManager).creationCode, uint256 (uint160 (v4Owner))));
95
147
}
96
148
97
- function testInvalidBytecode (bytes32 salt ) public {
149
+ function test_deploy_reverts_InvalidBytecode (bytes32 salt ) public {
150
+ salt = (salt & mask20bytes) | bytes32 (bytes20 (winner));
151
+
98
152
vm.prank (winner);
99
153
competition.updateBestAddress (salt);
100
154
vm.expectRevert (IUniswapV4DeployerCompetition.InvalidBytecode.selector );
101
155
// set the owner as the winner not the correct owner
102
156
competition.deploy (abi.encodePacked (type (PoolManager).creationCode, uint256 (uint160 (winner))));
103
157
}
104
158
105
- function testInvalidMsgSender (bytes32 salt ) public {
159
+ function test_deploy_reverts_InvalidMsgSender (bytes32 salt ) public {
160
+ salt = (salt & mask20bytes) | bytes32 (bytes20 (winner));
161
+
106
162
vm.prank (winner);
107
163
competition.updateBestAddress (salt);
108
164
vm.warp (competition.competitionDeadline () + 1 );
@@ -113,34 +169,13 @@ contract UniswapV4DeployerCompetitionTest is Test {
113
169
competition.deploy (abi.encodePacked (type (PoolManager).creationCode, uint256 (uint160 (v4Owner))));
114
170
}
115
171
116
- function testAfterExcusiveDeployDeadline (bytes32 salt ) public {
172
+ function test_deploy_afterExcusiveDeployDeadline (bytes32 salt ) public {
173
+ salt = (salt & mask20bytes) | bytes32 (bytes20 (winner));
174
+
117
175
vm.prank (winner);
118
176
competition.updateBestAddress (salt);
119
177
vm.warp (competition.exclusiveDeployDeadline () + 1 );
120
178
vm.prank (address (1 ));
121
179
competition.deploy (abi.encodePacked (type (PoolManager).creationCode, uint256 (uint160 (v4Owner))));
122
180
}
123
-
124
- function testEqualSaltNotChanged (bytes32 salt ) public {
125
- vm.prank (winner);
126
- competition.updateBestAddress (salt);
127
- assertFalse (competition.bestAddress () == address (0 ));
128
- assertEq (competition.bestAddressSubmitter (), winner);
129
- assertEq (competition.bestAddressSalt (), salt);
130
-
131
- address newAddr = Create2.computeAddress (salt >> 1 , initCodeHash, address (competition));
132
- vm.assume (competition.bestAddress ().betterThan (newAddr));
133
-
134
- vm.prank (address (1 ));
135
- vm.expectRevert (
136
- abi.encodeWithSelector (
137
- IUniswapV4DeployerCompetition.WorseAddress.selector ,
138
- newAddr,
139
- competition.bestAddress (),
140
- newAddr.score (),
141
- competition.bestAddress ().score ()
142
- )
143
- );
144
- competition.updateBestAddress (salt >> 1 );
145
- }
146
181
}
0 commit comments