Skip to content

Commit bbebb82

Browse files
committed
all AnlogTokenV2 tests also to run after upgrade
1 parent 2cdcdf8 commit bbebb82

File tree

2 files changed

+83
-78
lines changed

2 files changed

+83
-78
lines changed

test/AnlogTokenV2.t.sol

Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ contract AnlogTokenV2Test is Test {
2929
using PrimitiveUtils for GmpMessage;
3030
using SigningUtils for SigningKey;
3131

32-
AnlogTokenV2 public token;
32+
AnlogTokenV2 public tokenV2;
3333

3434
address constant MINTER = address(0);
3535
address constant UPGRADER = address(1);
@@ -59,7 +59,7 @@ contract AnlogTokenV2Test is Test {
5959
/// @notice deploys an UUPS proxy.
6060
/// Here we start with the V2 implementation right away.
6161
/// For V1->V2 upgrade see another test.
62-
function setUp() public {
62+
function setUp() public virtual {
6363
sepoliaFork = vm.createFork(SEPOLIA_RPC_URL);
6464
vm.selectFork(sepoliaFork);
6565
assertEq(vm.activeFork(), sepoliaFork);
@@ -71,7 +71,7 @@ contract AnlogTokenV2Test is Test {
7171
address proxy = Upgrades.deployUUPSProxy(
7272
"AnlogTokenV2.sol", abi.encodeCall(AnlogTokenV2.initialize, (MINTER, UPGRADER, PAUSER, UNPAUSER)), opts
7373
);
74-
token = AnlogTokenV2(proxy);
74+
tokenV2 = AnlogTokenV2(proxy);
7575
}
7676

7777
modifier setRoute() {
@@ -98,17 +98,17 @@ contract AnlogTokenV2Test is Test {
9898
}
9999

100100
modifier preMint(address to, uint256 amount) {
101-
assertEq(token.totalSupply(), 0);
101+
assertEq(tokenV2.totalSupply(), 0);
102102
vm.prank(MINTER);
103-
token.mint(to, amount);
104-
assertEq(token.totalSupply(), amount);
105-
assertEq(token.balanceOf(to), amount);
103+
tokenV2.mint(to, amount);
104+
assertEq(tokenV2.totalSupply(), amount);
105+
assertEq(tokenV2.balanceOf(to), amount);
106106
_;
107107
}
108108

109109
modifier paused() {
110110
vm.prank(PAUSER);
111-
token.pause();
111+
tokenV2.pause();
112112
_;
113113
}
114114

@@ -119,125 +119,125 @@ contract AnlogTokenV2Test is Test {
119119
return Signature({xCoord: signer.xCoord(), e: e, s: s});
120120
}
121121

122-
function test_name_and_ticker() public view {
123-
assertEq(token.name(), "Wrapped Analog One Token");
124-
assertEq(token.symbol(), "WANLOG");
122+
function test_name_and_ticker() public virtual {
123+
assertEq(tokenV2.name(), "Wrapped Analog One Token");
124+
assertEq(tokenV2.symbol(), "WANLOG");
125125
}
126126

127-
function test_decimals() public view {
128-
assertEq(token.decimals(), 12);
127+
function test_decimals() public virtual {
128+
assertEq(tokenV2.decimals(), 12);
129129
}
130130

131-
function test_Mint() public preMint(address(this), 20_000) {
132-
assertEq(token.balanceOf(address(this)), 20_000);
131+
function test_Mint() public virtual preMint(address(this), 20_000) {
132+
assertEq(tokenV2.balanceOf(address(this)), 20_000);
133133
}
134134

135-
function test_Transfer() public preMint(address(this), 20_000) {
136-
assertEq(token.balanceOf(address(2)), 0);
137-
token.transfer(address(2), 5_000);
138-
assertEq(token.balanceOf(address(2)), 5_000);
135+
function test_Transfer() public virtual preMint(address(this), 20_000) {
136+
assertEq(tokenV2.balanceOf(address(2)), 0);
137+
tokenV2.transfer(address(2), 5_000);
138+
assertEq(tokenV2.balanceOf(address(2)), 5_000);
139139
}
140140

141-
function test_Pause() public preMint(address(this), 20_000) paused {
141+
function test_Pause() public virtual preMint(address(this), 20_000) paused {
142142
// error EnforcedPause()
143143
vm.expectRevert(PausableUpgradeable.EnforcedPause.selector);
144-
token.transfer(address(2), 5_000);
144+
tokenV2.transfer(address(2), 5_000);
145145

146146
vm.prank(MINTER);
147147
vm.expectRevert(PausableUpgradeable.EnforcedPause.selector);
148-
token.mint(address(this), 1);
148+
tokenV2.mint(address(this), 1);
149149
}
150150

151-
function test_UnPause() public preMint(address(this), 20_000) paused {
151+
function test_UnPause() public virtual preMint(address(this), 20_000) paused {
152152
vm.prank(UNPAUSER);
153-
token.unpause();
153+
tokenV2.unpause();
154154

155-
token.transfer(address(2), 5_000);
156-
assertEq(token.balanceOf(address(2)), 5_000);
155+
tokenV2.transfer(address(2), 5_000);
156+
assertEq(tokenV2.balanceOf(address(2)), 5_000);
157157
}
158158

159-
function test_GrantRole() public preMint(address(this), 20_000) {
160-
assertFalse(token.hasRole(keccak256("MINTER_ROLE"), NEW_MINTER));
159+
function test_GrantRole() public virtual preMint(address(this), 20_000) {
160+
assertFalse(tokenV2.hasRole(keccak256("MINTER_ROLE"), NEW_MINTER));
161161

162162
vm.prank(UPGRADER);
163-
token.grantRole(keccak256("MINTER_ROLE"), NEW_MINTER);
163+
tokenV2.grantRole(keccak256("MINTER_ROLE"), NEW_MINTER);
164164

165165
vm.prank(NEW_MINTER);
166-
token.mint(NEW_MINTER, 5_000);
167-
assertEq(token.balanceOf(NEW_MINTER), 5_000);
168-
assertEq(token.totalSupply(), 25_000);
166+
tokenV2.mint(NEW_MINTER, 5_000);
167+
assertEq(tokenV2.balanceOf(NEW_MINTER), 5_000);
168+
assertEq(tokenV2.totalSupply(), 25_000);
169169
}
170170

171-
function test_RevokeRole() public preMint(address(this), 20_000) {
171+
function test_RevokeRole() public virtual preMint(address(this), 20_000) {
172172
vm.prank(UPGRADER);
173-
token.revokeRole(keccak256("MINTER_ROLE"), MINTER);
173+
tokenV2.revokeRole(keccak256("MINTER_ROLE"), MINTER);
174174

175175
vm.prank(MINTER);
176176
vm.expectRevert(
177177
abi.encodeWithSelector(
178178
IAccessControl.AccessControlUnauthorizedAccount.selector, MINTER, keccak256("MINTER_ROLE")
179179
)
180180
);
181-
token.mint(MINTER, 5_000);
181+
tokenV2.mint(MINTER, 5_000);
182182
}
183183

184-
function test_RevertWhen_Unauthorized_RevokeRole() public {
184+
function test_RevertWhen_Unauthorized_RevokeRole() public virtual {
185185
vm.prank(PAUSER);
186186
vm.expectRevert(abi.encodeWithSelector(IAccessControl.AccessControlUnauthorizedAccount.selector, PAUSER, 0x00));
187-
token.revokeRole(keccak256("MINTER_ROLE"), MINTER);
187+
tokenV2.revokeRole(keccak256("MINTER_ROLE"), MINTER);
188188

189-
assert(token.hasRole(keccak256("MINTER_ROLE"), MINTER));
189+
assert(tokenV2.hasRole(keccak256("MINTER_ROLE"), MINTER));
190190
}
191191

192-
function test_RevertWhen_Unauthorized_Mint() public {
192+
function test_RevertWhen_Unauthorized_Mint() public virtual {
193193
vm.prank(UPGRADER);
194194
vm.expectRevert(
195195
abi.encodeWithSelector(
196196
IAccessControl.AccessControlUnauthorizedAccount.selector, UPGRADER, keccak256("MINTER_ROLE")
197197
)
198198
);
199-
token.mint(UPGRADER, 100_000);
199+
tokenV2.mint(UPGRADER, 100_000);
200200
}
201201

202-
function test_RevertWhen_Unauthorized_Pause() public {
202+
function test_RevertWhen_Unauthorized_Pause() public virtual {
203203
vm.prank(MINTER);
204204
vm.expectRevert(
205205
abi.encodeWithSelector(
206206
IAccessControl.AccessControlUnauthorizedAccount.selector, MINTER, keccak256("PAUSER_ROLE")
207207
)
208208
);
209-
token.pause();
209+
tokenV2.pause();
210210
}
211211

212-
function test_RevertWhen_Unauthorized_UnPause() public paused {
212+
function test_RevertWhen_Unauthorized_UnPause() public virtual paused {
213213
vm.prank(MINTER);
214214
vm.expectRevert(
215215
abi.encodeWithSelector(
216216
IAccessControl.AccessControlUnauthorizedAccount.selector, MINTER, keccak256("UNPAUSER_ROLE")
217217
)
218218
);
219-
token.unpause();
219+
tokenV2.unpause();
220220
}
221221

222-
function test_TeleportOut_Below_ED() public preMint(address(this), MIN_TELEPORT_VAL - 1) {
222+
function test_TeleportOut_Below_ED() public virtual preMint(address(this), MIN_TELEPORT_VAL - 1) {
223223
bytes32 dest = bytes32(bytes20(UPGRADER));
224224
vm.expectRevert("value below minimum required");
225-
token.teleport(dest, MIN_TELEPORT_VAL - 1);
225+
tokenV2.teleport(dest, MIN_TELEPORT_VAL - 1);
226226
}
227227

228-
function test_TeleportOut_Low_Value() public preMint(address(this), MIN_TELEPORT_VAL) setRoute {
228+
function test_TeleportOut_Low_Value() public virtual preMint(address(this), MIN_TELEPORT_VAL) setRoute {
229229
bytes32 dest = bytes32(bytes20(uint160(UPGRADER)));
230230

231-
vm.expectEmit(address(token));
231+
vm.expectEmit(address(tokenV2));
232232
emit IERC20.Transfer(address(this), address(0), MIN_TELEPORT_VAL);
233233
vm.expectRevert("insufficient tx value");
234-
token.teleport(dest, MIN_TELEPORT_VAL);
234+
tokenV2.teleport(dest, MIN_TELEPORT_VAL);
235235
}
236236

237-
function test_TeleportOut() public preMint(address(this), MIN_TELEPORT_VAL) setRoute {
237+
function test_TeleportOut() public virtual preMint(address(this), MIN_TELEPORT_VAL) setRoute {
238238
address payable gw = payable(GATEWAY);
239239
bytes32 dest = bytes32(uint256(uint160(UPGRADER)));
240-
uint256 cost = token.estimateTeleportCost();
240+
uint256 cost = tokenV2.estimateTeleportCost();
241241

242242
GmpSender source = GmpSender.wrap(bytes32(uint256(uint160(SIGNER_ADDRESS))));
243243

@@ -256,7 +256,7 @@ contract AnlogTokenV2Test is Test {
256256

257257
bytes32 messageID = gmp.eip712hash();
258258

259-
vm.expectEmit(address(token));
259+
vm.expectEmit(address(tokenV2));
260260
emit IERC20.Transfer(address(this), address(0), MIN_TELEPORT_VAL);
261261

262262
vm.expectEmit(true, true, true, true, address(GATEWAY));
@@ -271,13 +271,13 @@ contract AnlogTokenV2Test is Test {
271271
gmp.data
272272
);
273273

274-
vm.expectEmit(true, true, true, true, address(token));
274+
vm.expectEmit(true, true, true, true, address(tokenV2));
275275
emit AnlogTokenV2.OutboundTransfer(messageID, address(this), dest, MIN_TELEPORT_VAL);
276276

277-
token.teleport{value: cost}(dest, MIN_TELEPORT_VAL);
277+
tokenV2.teleport{value: cost}(dest, MIN_TELEPORT_VAL);
278278
}
279279

280-
function test_TeleportIn() public setRoute setShard {
280+
function test_TeleportIn() public virtual setRoute setShard {
281281
address payable gw = payable(GATEWAY);
282282
GmpSender source = GmpSender.wrap(bytes32(uint256(uint160(0))));
283283

@@ -287,14 +287,14 @@ contract AnlogTokenV2Test is Test {
287287
GmpMessage memory gmp = GmpMessage({
288288
source: source,
289289
srcNetwork: TIMECHAIN_ID,
290-
dest: address(token),
290+
dest: address(tokenV2),
291291
destNetwork: Gateway(gw).networkId(),
292292
gasLimit: 100_000,
293293
nonce: 0,
294294
data: abi.encode(command)
295295
});
296296

297-
assertEq(token.totalSupply(), 0);
297+
assertEq(tokenV2.totalSupply(), 0);
298298

299299
Signature memory sig = sign(gmp);
300300
bytes32 messageID = gmp.eip712hash();
@@ -305,7 +305,7 @@ contract AnlogTokenV2Test is Test {
305305
Gateway(gw).execute(sig, gmp);
306306
assertTrue(Gateway(gw).gmpInfo(messageID).status == GmpStatus.SUCCESS, "failed to execute GMP message");
307307

308-
assertEq(token.balanceOf(UPGRADER), MIN_TELEPORT_VAL);
309-
assertEq(token.totalSupply(), MIN_TELEPORT_VAL);
308+
assertEq(tokenV2.balanceOf(UPGRADER), MIN_TELEPORT_VAL);
309+
assertEq(tokenV2.totalSupply(), MIN_TELEPORT_VAL);
310310
}
311311
}

test/Upgrade.V1.V2.t.sol

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,18 @@ import {IAccessControl} from "@openzeppelin/contracts/access/IAccessControl.sol"
77
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
88
import {AnlogTokenV1} from "../src/AnlogTokenV1.sol";
99
import {AnlogTokenV2} from "../src/AnlogTokenV2.sol";
10+
import {AnlogTokenV2Test} from "./AnlogTokenV2.t.sol";
1011

1112
/// @notice test for V1->V2 AnlogToken upgrade
12-
contract UpgradeV1V2Test is Test {
13+
contract UpgradeV1V2Test is Test, AnlogTokenV2Test {
1314
AnlogTokenV1 public tokenV1;
14-
AnlogTokenV2 public tokenV2;
15-
16-
address constant MINTER = address(0);
17-
address constant UPGRADER = address(1);
18-
address constant PAUSER = address(2);
19-
address constant UNPAUSER = address(3);
2015

2116
uint256 constant MINT_AMOUNT1 = 100_000;
2217
uint256 constant MINT_AMOUNT2 = 50_000;
2318

24-
// V2 immutables
25-
address constant GATEWAY = 0xEb73D0D236DE8F8D09dc6A52916e5849ff1E8dfA;
26-
uint16 constant TIMECHAIN_ID = 1000;
27-
uint256 constant MIN_TELEPORT_VAL = 1000000000000;
28-
29-
// fork testing
30-
string SEPOLIA_RPC_URL = vm.envString("SEPOLIA_RPC_URL");
31-
uint256 sepoliaFork;
32-
3319
/// @notice deploys an UUPS proxy.
3420
/// Here we start with the V1 implementation
35-
function setUp() public {
21+
function setUp() public override {
3622
// NOTE: we need this in order to have deployed gateway.
3723
sepoliaFork = vm.createFork(SEPOLIA_RPC_URL);
3824
vm.selectFork(sepoliaFork);
@@ -67,9 +53,9 @@ contract UpgradeV1V2Test is Test {
6753

6854
vm.startPrank(UPGRADER);
6955
Upgrades.upgradeProxy(address(tokenV1), "AnlogTokenV2.sol", emptyData, opts);
70-
vm.stopPrank;
7156

7257
tokenV2 = AnlogTokenV2(address(tokenV1));
58+
vm.stopPrank();
7359
_;
7460
}
7561

@@ -84,9 +70,28 @@ contract UpgradeV1V2Test is Test {
8470
assertEq(tokenV2.balanceOf(address(this)), MINT_AMOUNT1);
8571
assertEq(tokenV2.balanceOf(PAUSER), 0);
8672
// TOKENS are transferrable
87-
vm.startPrank(address(this));
8873
tokenV2.transfer(PAUSER, MINT_AMOUNT2);
8974
assertEq(tokenV2.balanceOf(PAUSER), MINT_AMOUNT2);
9075
assertEq(tokenV2.balanceOf(address(this)), MINT_AMOUNT1 - MINT_AMOUNT2);
9176
}
77+
78+
/* ENSURE ALL AnlogTokenV2 functional WORKS fine AFTER UPGRADE */
79+
/* BASIC */
80+
function test_name_and_ticker() public override upgrade {}
81+
function test_decimals() public override upgrade {}
82+
function test_Mint() public override upgrade preMint(address(this), 20_000) {}
83+
function test_Transfer() public override upgrade preMint(address(this), 20_000) {}
84+
function test_Pause() public override upgrade preMint(address(this), 20_000) paused {}
85+
function test_UnPause() public override upgrade preMint(address(this), 20_000) paused {}
86+
function test_GrantRole() public override upgrade preMint(address(this), 20_000) {}
87+
function test_RevokeRole() public override upgrade preMint(address(this), 20_000) {}
88+
function test_RevertWhen_Unauthorized_RevokeRole() public override upgrade {}
89+
function test_RevertWhen_Unauthorized_Mint() public override upgrade {}
90+
function test_RevertWhen_Unauthorized_Pause() public override upgrade {}
91+
function test_RevertWhen_Unauthorized_UnPause() public override upgrade paused {}
92+
/* TELEPORTATION */
93+
function test_TeleportOut_Below_ED() public override upgrade preMint(address(this), MIN_TELEPORT_VAL - 1) {}
94+
function test_TeleportOut_Low_Value() public override upgrade preMint(address(this), MIN_TELEPORT_VAL) setRoute {}
95+
function test_TeleportOut() public override upgrade preMint(address(this), MIN_TELEPORT_VAL) setRoute {}
96+
function test_TeleportIn() public override upgrade setRoute setShard {}
9297
}

0 commit comments

Comments
 (0)