Skip to content

Commit eff94d7

Browse files
Rahul MagantiRahulMaganti47
Rahul Maganti
authored andcommitted
evm: add revert signatures
1 parent ebd4984 commit eff94d7

6 files changed

+130
-40
lines changed

evm/test/IntegrationRelayer.t.sol

+32-6
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,11 @@ contract TestEndToEndRelayer is
213213

214214
// config not set correctly
215215
vm.startPrank(userA);
216-
vm.expectRevert(abi.encodeWithSignature("InvalidRelayingConfig(uint16)", chainId2));
216+
vm.expectRevert(
217+
abi.encodeWithSelector(
218+
IWormholeTransceiver.InvalidRelayingConfig.selector, chainId2
219+
)
220+
);
217221
nttManagerChain1.transfer{value: priceQuote1}(
218222
sendingAmount, chainId2, bytes32(uint256(uint160(userB))), false, instructions
219223
);
@@ -223,17 +227,31 @@ contract TestEndToEndRelayer is
223227
wormholeTransceiverChain1.setIsWormholeEvmChain(chainId2, true);
224228
vm.startPrank(userA);
225229

226-
vm.expectRevert(); // Dust error
230+
// revert if transfer amount has dust
231+
uint256 amount = sendingAmount - 1;
232+
TrimmedAmount trimmedAmount = amount.trim(decimals, 7);
233+
uint256 newAmount = trimmedAmount.untrim(decimals);
234+
vm.expectRevert(
235+
abi.encodeWithSelector(
236+
INttManager.TransferAmountHasDust.selector, amount, amount - newAmount
237+
)
238+
);
227239
nttManagerChain1.transfer{value: priceQuote1}(
228240
sendingAmount - 1, chainId2, bytes32(uint256(uint160(userB))), false, instructions
229241
);
230242

231-
vm.expectRevert(); // Zero funds error
243+
// Zero funds error
244+
vm.expectRevert(abi.encodeWithSelector(INttManager.ZeroAmount.selector));
232245
nttManagerChain1.transfer{value: priceQuote1}(
233246
0, chainId2, bytes32(uint256(uint160(userB))), false, instructions
234247
);
235248

236-
vm.expectRevert(); // Not enough in gas costs from the 'quote'.
249+
// Not enough in gas costs from the 'quote'.
250+
vm.expectRevert(
251+
abi.encodeWithSelector(
252+
INttManager.DeliveryPaymentTooLow.selector, priceQuote1, priceQuote1 - 1
253+
)
254+
);
237255
nttManagerChain1.transfer{value: priceQuote1 - 1}(
238256
sendingAmount, chainId2, bytes32(uint256(uint160(userB))), false, instructions
239257
);
@@ -587,7 +605,13 @@ contract TestRelayerEndToEndManual is
587605
chainId1, bytes32(uint256(uint160(address(0x1)))), 9, type(uint64).max
588606
);
589607
vm.startPrank(relayer);
590-
vm.expectRevert(); // bad nttManager peer
608+
609+
// bad nttManager peer
610+
vm.expectRevert(
611+
abi.encodeWithSelector(
612+
INttManagerState.InvalidPeer.selector, chainId1, address(nttManagerChain1)
613+
)
614+
);
591615
wormholeTransceiverChain2.receiveWormholeMessages(
592616
vaa.payload,
593617
a,
@@ -646,7 +670,9 @@ contract TestRelayerEndToEndManual is
646670
);
647671

648672
// Should from sending a *duplicate* message
649-
vm.expectRevert(); // Uses a custom error with a hash - don't know how to calculate the hash
673+
vm.expectRevert(
674+
abi.encodeWithSelector(IWormholeTransceiver.TransferAlreadyCompleted.selector, vaa.hash)
675+
);
650676
wormholeTransceiverChain2.receiveWormholeMessages(
651677
vaa.payload, // Verified
652678
a, // Should be zero

evm/test/IntegrationStandalone.t.sol

+50-9
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ contract TestEndToEndBase is Test, INttManagerEvents, IRateLimiterEvents {
194194
// Chain2 verification and checks
195195
vm.chainId(chainId2);
196196

197-
vm.expectRevert(); // Wrong chain receiving the signed VAA
197+
// Wrong chain receiving the signed VAA
198+
vm.expectRevert(abi.encodeWithSelector(InvalidFork.selector, chainId1, chainId2));
198199
wormholeTransceiverChain1.receiveMessage(encodedVMs[0]);
199200
{
200201
uint256 supplyBefore = token2.totalSupply();
@@ -209,7 +210,12 @@ contract TestEndToEndBase is Test, INttManagerEvents, IRateLimiterEvents {
209210
}
210211

211212
// Can't resubmit the same message twice
212-
vm.expectRevert(); // TransferAlreadyCompleted error
213+
(IWormhole.VM memory wormholeVM,,) = wormhole.parseAndVerifyVM(encodedVMs[0]);
214+
vm.expectRevert(
215+
abi.encodeWithSelector(
216+
IWormholeTransceiver.TransferAlreadyCompleted.selector, wormholeVM.hash
217+
)
218+
);
213219
wormholeTransceiverChain2.receiveMessage(encodedVMs[0]);
214220

215221
// Go back the other way from a THIRD user
@@ -337,7 +343,12 @@ contract TestEndToEndBase is Test, INttManagerEvents, IRateLimiterEvents {
337343
}
338344

339345
// Can't resubmit the same message twice
340-
vm.expectRevert(); // TransferAlreadyCompleted error
346+
(IWormhole.VM memory wormholeVM,,) = wormhole.parseAndVerifyVM(encodedVMs[0]);
347+
vm.expectRevert(
348+
abi.encodeWithSelector(
349+
IWormholeTransceiver.TransferAlreadyCompleted.selector, wormholeVM.hash
350+
)
351+
);
341352
wormholeTransceiverChain2.receiveMessage(encodedVMs[0]);
342353

343354
// Go back the other way from a THIRD user
@@ -365,18 +376,38 @@ contract TestEndToEndBase is Test, INttManagerEvents, IRateLimiterEvents {
365376
);
366377

367378
// Test timing on the queues
368-
vm.expectRevert();
379+
vm.expectRevert(
380+
abi.encodeWithSelector(
381+
IRateLimiter.OutboundQueuedTransferStillQueued.selector,
382+
0,
383+
vm.getBlockTimestamp()
384+
)
385+
);
369386
nttManagerChain2.completeOutboundQueuedTransfer(0);
370387
vm.warp(vm.getBlockTimestamp() + 1 days - 1);
371-
vm.expectRevert();
388+
389+
vm.expectRevert(
390+
abi.encodeWithSelector(
391+
IRateLimiter.OutboundQueuedTransferStillQueued.selector,
392+
0,
393+
vm.getBlockTimestamp() - 1 days + 1
394+
)
395+
);
372396
nttManagerChain2.completeOutboundQueuedTransfer(0);
397+
373398
vm.warp(vm.getBlockTimestamp() + 1);
374399
nttManagerChain2.completeOutboundQueuedTransfer(0);
375400

376-
vm.expectRevert(); // Replay - should be deleted
401+
// Replay - should be deleted
402+
vm.expectRevert(
403+
abi.encodeWithSelector(IRateLimiter.OutboundQueuedTransferNotFound.selector, 0)
404+
);
377405
nttManagerChain2.completeOutboundQueuedTransfer(0);
378406

379-
vm.expectRevert(); // Non-existant
407+
// Non-existant
408+
vm.expectRevert(
409+
abi.encodeWithSelector(IRateLimiter.OutboundQueuedTransferNotFound.selector, 1)
410+
);
380411
nttManagerChain2.completeOutboundQueuedTransfer(1);
381412

382413
uint256 supplyAfter = token2.totalSupply();
@@ -416,7 +447,11 @@ contract TestEndToEndBase is Test, INttManagerEvents, IRateLimiterEvents {
416447

417448
// Double redeem
418449
vm.warp(vm.getBlockTimestamp() + 100000);
419-
vm.expectRevert();
450+
vm.expectRevert(
451+
abi.encodeWithSelector(
452+
IRateLimiter.InboundQueuedTransferNotFound.selector, queuedDigests[0]
453+
)
454+
);
420455
nttManagerChain1.completeInboundQueuedTransfer(queuedDigests[0]);
421456

422457
uint256 supplyAfter = token1.totalSupply();
@@ -519,7 +554,13 @@ contract TestEndToEndBase is Test, INttManagerEvents, IRateLimiterEvents {
519554
uint256 supplyBefore = token2.totalSupply();
520555
wormholeTransceiverChain2_1.receiveMessage(encodedVMs[0]);
521556

522-
vm.expectRevert(); // Invalid wormhole peer
557+
vm.expectRevert(
558+
abi.encodeWithSelector(
559+
IWormholeTransceiver.InvalidWormholePeer.selector,
560+
chainId1,
561+
wormholeTransceiverChain1_1
562+
)
563+
);
523564
wormholeTransceiverChain2_2.receiveMessage(encodedVMs[0]);
524565

525566
// Threshold check

evm/test/NttManager.t.sol

+29-15
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ contract TestNttManager is Test, INttManagerEvents, IRateLimiterEvents {
160160
address notOwner = address(0x123);
161161
vm.startPrank(notOwner);
162162

163-
vm.expectRevert(abi.encodeWithSignature("OwnableUnauthorizedAccount(address)", notOwner));
163+
vm.expectRevert(
164+
abi.encodeWithSelector(OwnableUpgradeable.OwnableUnauthorizedAccount.selector, notOwner)
165+
);
164166
nttManager.transferOwnership(address(0x456));
165167
}
166168

@@ -178,18 +180,26 @@ contract TestNttManager is Test, INttManagerEvents, IRateLimiterEvents {
178180
address notOwner = address(0x123);
179181
vm.startPrank(notOwner);
180182

181-
vm.expectRevert(abi.encodeWithSignature("OwnableUnauthorizedAccount(address)", notOwner));
183+
vm.expectRevert(
184+
abi.encodeWithSelector(OwnableUpgradeable.OwnableUnauthorizedAccount.selector, notOwner)
185+
);
182186
nttManager.setTransceiver(address(e));
183187

184-
vm.expectRevert(abi.encodeWithSignature("OwnableUnauthorizedAccount(address)", notOwner));
188+
vm.expectRevert(
189+
abi.encodeWithSelector(OwnableUpgradeable.OwnableUnauthorizedAccount.selector, notOwner)
190+
);
185191
nttManager.removeTransceiver(address(e));
186192
}
187193

188194
function test_cantEnableTransceiverTwice() public {
189195
DummyTransceiver e = new DummyTransceiver(address(nttManager));
190196
nttManager.setTransceiver(address(e));
191197

192-
vm.expectRevert(abi.encodeWithSignature("TransceiverAlreadyEnabled(address)", address(e)));
198+
vm.expectRevert(
199+
abi.encodeWithSelector(
200+
TransceiverRegistry.TransceiverAlreadyEnabled.selector, address(e)
201+
)
202+
);
193203
nttManager.setTransceiver(address(e));
194204
}
195205

@@ -256,7 +266,7 @@ contract TestNttManager is Test, INttManagerEvents, IRateLimiterEvents {
256266

257267
function test_cantSetThresholdTooHigh() public {
258268
// no transceivers set, so can't set threshold to 1
259-
vm.expectRevert(abi.encodeWithSignature("ThresholdTooHigh(uint256,uint256)", 1, 0));
269+
vm.expectRevert(abi.encodeWithSelector(INttManagerState.ThresholdTooHigh.selector, 1, 0));
260270
nttManager.setThreshold(1);
261271
}
262272

@@ -275,15 +285,17 @@ contract TestNttManager is Test, INttManagerEvents, IRateLimiterEvents {
275285
DummyTransceiver e = new DummyTransceiver(address(nttManager));
276286
nttManager.setTransceiver(address(e));
277287

278-
vm.expectRevert(abi.encodeWithSignature("ZeroThreshold()"));
288+
vm.expectRevert(abi.encodeWithSelector(INttManagerState.ZeroThreshold.selector));
279289
nttManager.setThreshold(0);
280290
}
281291

282292
function test_onlyOwnerCanSetThreshold() public {
283293
address notOwner = address(0x123);
284294
vm.startPrank(notOwner);
285295

286-
vm.expectRevert(abi.encodeWithSignature("OwnableUnauthorizedAccount(address)", notOwner));
296+
vm.expectRevert(
297+
abi.encodeWithSelector(OwnableUpgradeable.OwnableUnauthorizedAccount.selector, notOwner)
298+
);
287299
nttManager.setThreshold(1);
288300
}
289301

@@ -317,7 +329,9 @@ contract TestNttManager is Test, INttManagerEvents, IRateLimiterEvents {
317329
0, bytes32(0), peer, toWormholeFormat(address(nttManagerOther)), abi.encode("payload")
318330
);
319331

320-
vm.expectRevert(abi.encodeWithSignature("CallerNotTransceiver(address)", address(e1)));
332+
vm.expectRevert(
333+
abi.encodeWithSelector(TransceiverRegistry.CallerNotTransceiver.selector, address(e1))
334+
);
321335
e1.receiveMessage(transceiverMessage);
322336
}
323337

@@ -335,8 +349,8 @@ contract TestNttManager is Test, INttManagerEvents, IRateLimiterEvents {
335349
);
336350

337351
vm.expectRevert(
338-
abi.encodeWithSignature(
339-
"InvalidPeer(uint16,bytes32)", TransceiverHelpersLib.SENDING_CHAIN_ID, peer
352+
abi.encodeWithSelector(
353+
INttManagerState.InvalidPeer.selector, TransceiverHelpersLib.SENDING_CHAIN_ID, peer
340354
)
341355
);
342356
e1.receiveMessage(transceiverMessage);
@@ -386,7 +400,7 @@ contract TestNttManager is Test, INttManagerEvents, IRateLimiterEvents {
386400

387401
e1.receiveMessage(transceiverMessage);
388402
vm.expectRevert(
389-
abi.encodeWithSignature("TransceiverAlreadyAttestedToMessage(bytes32)", hash)
403+
abi.encodeWithSelector(INttManager.TransceiverAlreadyAttestedToMessage.selector, hash)
390404
);
391405
e1.receiveMessage(transceiverMessage);
392406

@@ -528,8 +542,8 @@ contract TestNttManager is Test, INttManagerEvents, IRateLimiterEvents {
528542
// replay protection for transceiver
529543
vm.recordLogs();
530544
vm.expectRevert(
531-
abi.encodeWithSignature(
532-
"TransceiverAlreadyAttestedToMessage(bytes32)",
545+
abi.encodeWithSelector(
546+
INttManager.TransceiverAlreadyAttestedToMessage.selector,
533547
TransceiverStructs.nttManagerMessageDigest(
534548
TransceiverHelpersLib.SENDING_CHAIN_ID, m
535549
)
@@ -597,8 +611,8 @@ contract TestNttManager is Test, INttManagerEvents, IRateLimiterEvents {
597611
token.approve(address(nttManager), amountWithDust);
598612

599613
vm.expectRevert(
600-
abi.encodeWithSignature(
601-
"TransferAmountHasDust(uint256,uint256)", amountWithDust, dustAmount
614+
abi.encodeWithSelector(
615+
INttManager.TransferAmountHasDust.selector, amountWithDust, dustAmount
602616
)
603617
);
604618
nttManager.transfer(amountWithDust, chainId, toWormholeFormat(to), false, new bytes(1));

evm/test/TransceiverStructs.t.sol

+4-4
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ contract TestTransceiverStructs is Test {
141141
bytes memory junk = "junk";
142142

143143
vm.expectRevert(
144-
abi.encodeWithSignature(
145-
"LengthMismatch(uint256,uint256)", message.length + junk.length, message.length
144+
abi.encodeWithSelector(
145+
BytesParsing.LengthMismatch.selector, message.length + junk.length, message.length
146146
)
147147
);
148148
TransceiverStructs.parseNttManagerMessage(abi.encodePacked(message, junk));
@@ -169,8 +169,8 @@ contract TestTransceiverStructs is Test {
169169
bytes memory junk = "junk";
170170

171171
vm.expectRevert(
172-
abi.encodeWithSignature(
173-
"LengthMismatch(uint256,uint256)", message.length + junk.length, message.length
172+
abi.encodeWithSelector(
173+
BytesParsing.LengthMismatch.selector, message.length + junk.length, message.length
174174
)
175175
);
176176
TransceiverStructs.parseNativeTokenTransfer(abi.encodePacked(message, junk));

evm/test/TrimmedAmount.t.sol

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: Apache 2
22
pragma solidity >=0.8.8 <0.9.0;
33

4-
import {Test} from "forge-std/Test.sol";
4+
import {Test, stdError} from "forge-std/Test.sol";
55
import "../src/libraries/TrimmedAmount.sol";
66
import "forge-std/console.sol";
77

@@ -82,7 +82,7 @@ contract TrimmingTest is Test {
8282
TrimmedAmount trimmedAmount = amount.trim(decimals, 8);
8383
TrimmedAmount trimmedAmountOther = amountOther.trim(decimalsOther, 8);
8484

85-
vm.expectRevert();
85+
vm.expectRevert(abi.encodeWithSelector(NumberOfDecimalsNotEqual.selector, 8, decimalsOther));
8686
trimmedAmount + trimmedAmountOther;
8787
}
8888

@@ -149,7 +149,8 @@ contract TrimmingTest is Test {
149149
TrimmedAmount trimmedAmount = amount.trim(decimals[i], 8);
150150
TrimmedAmount trimmedAmountOther = amountOther.trim(decimals[i], 8);
151151

152-
vm.expectRevert();
152+
// arithmetic overflow
153+
vm.expectRevert(stdError.arithmeticError);
153154
trimmedAmount - trimmedAmountOther;
154155
}
155156
}

evm/test/Upgrades.t.sol

+11-3
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,8 @@ contract TestUpgrades is Test, INttManagerEvents, IRateLimiterEvents {
481481
// Chain2 verification and checks
482482
vm.chainId(chainId2);
483483

484-
vm.expectRevert(); // Wrong chain receiving the signed VAA
484+
// Wrong chain receiving the signed VAA
485+
vm.expectRevert(abi.encodeWithSelector(InvalidFork.selector, chainId1, chainId2));
485486
wormholeTransceiverChain1.receiveMessage(encodedVMs[0]);
486487
{
487488
uint256 supplyBefore = token2.totalSupply();
@@ -496,7 +497,12 @@ contract TestUpgrades is Test, INttManagerEvents, IRateLimiterEvents {
496497
}
497498

498499
// Can't resubmit the same message twice
499-
vm.expectRevert(); // TransferAlreadyCompleted error
500+
(IWormhole.VM memory wormholeVM,,) = wormhole.parseAndVerifyVM(encodedVMs[0]);
501+
vm.expectRevert(
502+
abi.encodeWithSelector(
503+
IWormholeTransceiver.TransferAlreadyCompleted.selector, wormholeVM.hash
504+
)
505+
);
500506
wormholeTransceiverChain2.receiveMessage(encodedVMs[0]);
501507

502508
// Go back the other way from a THIRD user
@@ -629,7 +635,9 @@ contract TestInitialize is Test {
629635
// Attempt to initialize the contract from a non-deployer account.
630636
vm.prank(userA);
631637
vm.expectRevert(
632-
abi.encodeWithSignature("UnexpectedDeployer(address,address)", address(this), userA)
638+
abi.encodeWithSelector(
639+
INttManagerState.UnexpectedDeployer.selector, address(this), userA
640+
)
633641
);
634642
nttManagerChain1.initialize();
635643
}

0 commit comments

Comments
 (0)