Skip to content

Commit 7bf64ad

Browse files
authored
Fix the tests on main + clear up warnings (#138)
1 parent e2e4bc8 commit 7bf64ad

6 files changed

+59
-49
lines changed

test/IntegrationRelayer.t.sol

+10-6
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,6 @@ contract TestEndToEndRelayer is
254254
false,
255255
encodeEndpointInstruction(false)
256256
);
257-
return;
258257

259258
// Balance check on funds going in and out working as expected
260259
uint256 managerBalanceAfter = token1.balanceOf(address(managerChain1));
@@ -353,8 +352,16 @@ contract TestEndToEndRelayer is
353352
function encodeEndpointInstruction(bool relayer_off) public view returns (bytes memory) {
354353
WormholeEndpoint.WormholeEndpointInstruction memory instruction =
355354
WormholeEndpoint.WormholeEndpointInstruction(relayer_off);
356-
bytes memory encodedInstructionWormhole =
357-
wormholeEndpointChain1.encodeWormholeEndpointInstruction(instruction);
355+
356+
bytes memory encodedInstructionWormhole;
357+
// Source fork has id 0 and corresponds to chain 1
358+
if (vm.activeFork() == 0) {
359+
encodedInstructionWormhole =
360+
wormholeEndpointChain1.encodeWormholeEndpointInstruction(instruction);
361+
} else {
362+
encodedInstructionWormhole =
363+
wormholeEndpointChain2.encodeWormholeEndpointInstruction(instruction);
364+
}
358365
EndpointStructs.EndpointInstruction memory EndpointInstruction =
359366
EndpointStructs.EndpointInstruction({index: 0, payload: encodedInstructionWormhole});
360367
EndpointStructs.EndpointInstruction[] memory EndpointInstructions =
@@ -457,7 +464,6 @@ contract TestRelayerEndToEndManual is Test, IManagerEvents, IRateLimiterEvents {
457464

458465
// Setting up the transfer
459466
DummyToken token1 = DummyToken(managerChain1.token());
460-
DummyToken token2 = DummyTokenMintAndBurn(managerChain2.token());
461467

462468
uint8 decimals = token1.decimals();
463469
uint256 sendingAmount = 5 * 10 ** decimals;
@@ -467,8 +473,6 @@ contract TestRelayerEndToEndManual is Test, IManagerEvents, IRateLimiterEvents {
467473

468474
// Send token through the relayer
469475
{
470-
uint256 managerBalanceBefore = token1.balanceOf(address(managerChain1));
471-
uint256 userBalanceBefore = token1.balanceOf(address(userA));
472476
vm.deal(userA, 1 ether);
473477
managerChain1.transfer{value: wormholeEndpointChain1.quoteDeliveryPrice(chainId2)}(
474478
sendingAmount,

test/IntegrationStandalone.t.sol

+5-9
Original file line numberDiff line numberDiff line change
@@ -371,26 +371,24 @@ contract TestEndToEndBase is Test, IManagerEvents, IRateLimiterEvents {
371371
// Chain1 verification and checks with the receiving of the message
372372
vm.chainId(chainId1);
373373
vm.stopPrank(); // Back to the owner of everything for this one.
374+
vm.recordLogs();
374375

375376
{
376377
uint256 supplyBefore = token1.totalSupply();
377378

378379
managerChain1.setInboundLimit(0, chainId2);
379380
wormholeEndpointChain1.receiveMessage(encodedVMs[0]);
380381

381-
// TODO - get a specific event - InboundTransferQueued - and use this hash instead
382+
bytes32[] memory queuedDigests =
383+
Utils.fetchQueuedTransferDigestsFromLogs(vm.getRecordedLogs());
382384

383385
vm.warp(vm.getBlockTimestamp() + 100000);
384-
managerChain1.completeInboundQueuedTransfer(
385-
0xaec9ec1e50c5d68731ab3d17b9e7690c5fa900f94f2bd2315e92392499ae3f42
386-
);
386+
managerChain1.completeInboundQueuedTransfer(queuedDigests[0]);
387387

388388
// Double redeem
389389
vm.warp(vm.getBlockTimestamp() + 100000);
390390
vm.expectRevert();
391-
managerChain1.completeInboundQueuedTransfer(
392-
0xaec9ec1e50c5d68731ab3d17b9e7690c5fa900f94f2bd2315e92392499ae3f42
393-
);
391+
managerChain1.completeInboundQueuedTransfer(queuedDigests[0]);
394392

395393
uint256 supplyAfter = token1.totalSupply();
396394

@@ -458,8 +456,6 @@ contract TestEndToEndBase is Test, IManagerEvents, IRateLimiterEvents {
458456

459457
// Send token through standard means (not relayer)
460458
{
461-
uint256 managerBalanceBefore = token1.balanceOf(address(managerChain1));
462-
uint256 userBalanceBefore = token1.balanceOf(address(userA));
463459
managerChain1.transfer(
464460
sendingAmount,
465461
chainId2,

test/Upgrades.t.sol

+12-30
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ contract ManagerStandaloneMigrateBasic is ManagerStandalone {
3737
uint64 rateLimitDuration
3838
) ManagerStandalone(token, mode, chainId, rateLimitDuration) {}
3939

40-
function _migrate() internal override {
40+
function _migrate() internal view override {
4141
_checkThresholdInvariants();
4242
_checkEndpointsInvariants();
4343
revert("Proper migrate called");
@@ -96,7 +96,7 @@ contract WormholeEndpointStandaloneMigrateBasic is WormholeEndpointStandalone {
9696
address wormholeRelayerAddr
9797
) WormholeEndpointStandalone(manager, wormholeCoreBridge, wormholeRelayerAddr) {}
9898

99-
function _migrate() internal override {
99+
function _migrate() internal pure override {
100100
revert("Proper migrate called");
101101
}
102102
}
@@ -107,7 +107,7 @@ contract WormholeEndpointStandaloneImmutableCheck is WormholeEndpointStandalone
107107
address wormholeRelayerAddr
108108
) WormholeEndpointStandalone(address(0x1), wormholeCoreBridge, wormholeRelayerAddr) {}
109109

110-
function _migrate() internal override {
110+
function _migrate() internal pure override {
111111
revert("Proper migrate called");
112112
}
113113
}
@@ -171,7 +171,6 @@ contract TestUpgrades is Test, IManagerEvents, IRateLimiterEvents {
171171

172172
function setUp() public virtual {
173173
string memory url = "https://ethereum-goerli.publicnode.com";
174-
IWormhole wormhole = IWormhole(0x706abc4E45D419950511e474C7B9Ed348A4a716c);
175174
vm.createSelectFork(url);
176175
initialBlockTimestamp = vm.getBlockTimestamp();
177176

@@ -251,9 +250,7 @@ contract TestUpgrades is Test, IManagerEvents, IRateLimiterEvents {
251250
WormholeEndpointStandalone wormholeEndpointChain1Implementation = new WormholeEndpointStandalone(
252251
address(managerChain1), address(wormhole), address(relayer)
253252
);
254-
managerChain1.upgradeEndpoint(
255-
address(wormholeEndpointChain1), address(wormholeEndpointChain1Implementation)
256-
);
253+
wormholeEndpointChain1.upgrade(address(wormholeEndpointChain1Implementation));
257254

258255
basicFunctionality();
259256
}
@@ -281,19 +278,12 @@ contract TestUpgrades is Test, IManagerEvents, IRateLimiterEvents {
281278
WormholeEndpointStandalone wormholeEndpointChain1Implementation = new WormholeEndpointStandalone(
282279
address(managerChain1), address(wormhole), address(relayer)
283280
);
284-
managerChain1.upgradeEndpoint(
285-
address(wormholeEndpointChain1), address(wormholeEndpointChain1Implementation)
286-
);
281+
wormholeEndpointChain1.upgrade(address(wormholeEndpointChain1Implementation));
287282

288283
basicFunctionality();
289284

290285
// Basic call to upgrade with the same contact as well
291-
WormholeEndpointStandalone wormholeEndpointChain1Implementation2 = new WormholeEndpointStandalone(
292-
address(managerChain1), address(wormhole), address(relayer)
293-
);
294-
managerChain1.upgradeEndpoint(
295-
address(wormholeEndpointChain1), address(wormholeEndpointChain1Implementation2)
296-
);
286+
wormholeEndpointChain1.upgrade(address(wormholeEndpointChain1Implementation));
297287

298288
basicFunctionality();
299289
}
@@ -319,7 +309,7 @@ contract TestUpgrades is Test, IManagerEvents, IRateLimiterEvents {
319309
WormholeEndpointStandalone newImplementation = new WormholeEndpointStandaloneLayoutChange(
320310
address(managerChain1), address(wormhole), address(relayer)
321311
);
322-
managerChain1.upgradeEndpoint(address(wormholeEndpointChain1), address(newImplementation));
312+
wormholeEndpointChain1.upgrade(address(newImplementation));
323313

324314
address oldOwner = managerChain1.owner();
325315
WormholeEndpointStandaloneLayoutChange(address(wormholeEndpointChain1)).setData();
@@ -350,9 +340,7 @@ contract TestUpgrades is Test, IManagerEvents, IRateLimiterEvents {
350340
);
351341

352342
vm.expectRevert("Proper migrate called");
353-
managerChain1.upgradeEndpoint(
354-
address(wormholeEndpointChain1), address(wormholeEndpointChain1Implementation)
355-
);
343+
wormholeEndpointChain1.upgrade(address(wormholeEndpointChain1Implementation));
356344

357345
basicFunctionality();
358346
}
@@ -381,9 +369,7 @@ contract TestUpgrades is Test, IManagerEvents, IRateLimiterEvents {
381369
new WormholeEndpointStandaloneImmutableCheck(address(wormhole), address(relayer));
382370

383371
vm.expectRevert(); // Reverts with a panic on the assert. So, no way to tell WHY this happened.
384-
managerChain1.upgradeEndpoint(
385-
address(wormholeEndpointChain1), address(wormholeEndpointChain1Implementation)
386-
);
372+
wormholeEndpointChain1.upgrade(address(wormholeEndpointChain1Implementation));
387373

388374
require(
389375
wormholeEndpointChain1.manager() == oldManager, "Manager updated when it shouldn't be"
@@ -410,9 +396,7 @@ contract TestUpgrades is Test, IManagerEvents, IRateLimiterEvents {
410396
new WormholeEndpointStandaloneImmutableAllow(address(wormhole), address(relayer));
411397

412398
//vm.expectRevert(); // Reverts with a panic on the assert. So, no way to tell WHY this happened.
413-
managerChain1.upgradeEndpoint(
414-
address(wormholeEndpointChain1), address(wormholeEndpointChain1Implementation)
415-
);
399+
wormholeEndpointChain1.upgrade(address(wormholeEndpointChain1Implementation));
416400

417401
require(
418402
wormholeEndpointChain1.manager() == address(0x1), "Manager updated when it shouldn't be"
@@ -465,15 +449,13 @@ contract TestUpgrades is Test, IManagerEvents, IRateLimiterEvents {
465449
vm.expectRevert(
466450
abi.encodeWithSelector(OwnableUpgradeable.OwnableUnauthorizedAccount.selector, userA)
467451
);
468-
managerChain1.upgradeEndpoint(address(wormholeEndpointChain1), address(0x1));
452+
wormholeEndpointChain1.upgrade(address(0x01));
469453

470454
// Basic call so that we can easily see what the new endpoint is.
471455
WormholeEndpointStandalone wormholeEndpointChain1Implementation = new WormholeEndpointStandalone(
472456
address(managerChain1), address(wormhole), address(relayer)
473457
);
474-
managerChain1.upgradeEndpoint(
475-
address(wormholeEndpointChain1), address(wormholeEndpointChain1Implementation)
476-
);
458+
wormholeEndpointChain1.upgrade(address(wormholeEndpointChain1Implementation));
477459
basicFunctionality(); // Ensure that the upgrade was proper
478460

479461
// Test if we can 'migrate' from this point

test/libraries/ManagerHelpers.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ library ManagerHelpersLib {
1414
NormalizedAmount memory inboundLimit,
1515
ManagerStandalone manager,
1616
uint8 decimals
17-
) internal returns (uint8) {
17+
) internal {
1818
manager.setSibling(SENDING_CHAIN_ID, toWormholeFormat(address(manager)));
1919
manager.setInboundLimit(inboundLimit.denormalize(decimals), SENDING_CHAIN_ID);
2020
}

test/libraries/Utils.sol

+29-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
pragma solidity >=0.8.8 <0.9.0;
33

44
import {Test} from "forge-std/Test.sol";
5-
import {VmSafe} from "forge-std/Vm.sol";
5+
import {VmSafe, Vm} from "forge-std/Vm.sol";
66

77
import "../../src/libraries/external/Initializable.sol";
88

@@ -35,6 +35,34 @@ library Utils {
3535
revert("upgradeable implementation constructor didn't disable initializers");
3636
}
3737
}
38+
39+
// Fetches the queued transfer digests from the logs when an inbound transfer is queued
40+
function fetchQueuedTransferDigestsFromLogs(Vm.Log[] memory logs)
41+
public
42+
pure
43+
returns (bytes32[] memory)
44+
{
45+
uint256 count = 0;
46+
for (uint256 i = 0; i < logs.length; i++) {
47+
if (logs[i].topics[0] == keccak256("InboundTransferQueued(bytes32)")) {
48+
count += 1;
49+
}
50+
}
51+
52+
// create log array to save published messages
53+
bytes32[] memory published = new bytes32[](count);
54+
55+
uint256 publishedIndex = 0;
56+
for (uint256 i = 0; i < logs.length; i++) {
57+
if (logs[i].topics[0] == keccak256("InboundTransferQueued(bytes32)")) {
58+
published[publishedIndex] = bytes32(logs[i].data);
59+
// console.logBytes(logs[i].data);
60+
publishedIndex += 1;
61+
}
62+
}
63+
64+
return published;
65+
}
3866
}
3967

4068
contract WritesToStorage {

test/mocks/DummyToken.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ contract DummyToken is ERC20 {
1313
_mint(to, amount);
1414
}
1515

16-
function mint(address to, uint256 amount) public virtual {
16+
function mint(address, uint256) public virtual {
1717
revert("Locking manager should not call 'mint()'");
1818
}
1919

20-
function burnFrom(address to, uint256 amount) public virtual {
20+
function burnFrom(address, uint256) public virtual {
2121
revert("Locking manager should not call 'burnFrom()'");
2222
}
2323
}

0 commit comments

Comments
 (0)