Skip to content

Commit d249162

Browse files
committed
evm: Fix tests
1 parent 3d93054 commit d249162

12 files changed

+234
-101
lines changed

evm/src/NttManager/ManagerBase.sol

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,9 @@ abstract contract ManagerBase is
142142
// The `msg.sender` is the transceiver. Get the index for it.
143143
uint8 index = _getTransceiverInfosStorage()[msg.sender].index;
144144

145-
// If this transceiver is not enabled for this chain, ignore this attestation.
146145
// TODO: Is there a race condition with disabling a transceiver while a tx is outstanding?
147146
if (!_isRecvTransceiverEnabledForChain(sourceChainId, index)) {
148-
return nttManagerMessageHash;
147+
revert CallerNotTransceiver(msg.sender);
149148
}
150149

151150
// set the attested flag for this transceiver.

evm/src/NttManager/TransceiverRegistry.sol

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ abstract contract TransceiverRegistryBase {
2727
uint8 enabled;
2828
}
2929

30+
/// @notice Error when attempting to enable an transceiver that is already enabled.
31+
/// @dev Selector: TODO.
32+
/// @param transceiver The address of the transceiver.
33+
error TransceiverAlreadyEnabled(address transceiver);
34+
3035
uint8 public constant MAX_TRANSCEIVERS = 64;
3136

3237
bytes32 internal constant TRANSCEIVER_INFOS_SLOT =
@@ -197,11 +202,6 @@ abstract contract TransceiverRegistry is TransceiverRegistryBase {
197202
/// @param transceiver The address of the transceiver.
198203
error NonRegisteredTransceiver(address transceiver);
199204

200-
/// @notice Error when attempting to enable a transceiver that is already enabled.
201-
/// @dev Selector 0x8d68f84d.
202-
/// @param transceiver The address of the transceiver.
203-
error TransceiverAlreadyEnabled(address transceiver);
204-
205205
/// @notice Error when attempting to use an incorrect chain.
206206
/// @dev Selector: 0x587c94c3.
207207
/// @param chain The id of the incorrect chain.
@@ -237,7 +237,7 @@ abstract contract TransceiverRegistry is TransceiverRegistryBase {
237237
_checkDelegateCallRevert(success, returnData);
238238
}
239239

240-
function _enableSendTransceiverForChain(uint16 chain, address transceiver) internal {
240+
function enableSendTransceiverForChain(uint16 chain, address transceiver) public {
241241
(bool success, bytes memory returnData) = _admin.delegatecall(
242242
abi.encodeWithSelector(
243243
TransceiverRegistryAdmin._enableSendTransceiverForChain.selector, chain, transceiver
@@ -246,7 +246,7 @@ abstract contract TransceiverRegistry is TransceiverRegistryBase {
246246
_checkDelegateCallRevert(success, returnData);
247247
}
248248

249-
function _disableSendTransceiverForChain(uint16 chain, address transceiver) internal {
249+
function disableSendTransceiverForChain(uint16 chain, address transceiver) public {
250250
(bool success, bytes memory returnData) = _admin.delegatecall(
251251
abi.encodeWithSelector(
252252
TransceiverRegistryAdmin._disableSendTransceiverForChain.selector,
@@ -257,7 +257,7 @@ abstract contract TransceiverRegistry is TransceiverRegistryBase {
257257
_checkDelegateCallRevert(success, returnData);
258258
}
259259

260-
function _enableRecvTransceiverForChain(uint16 chain, address transceiver) internal {
260+
function enableRecvTransceiverForChain(uint16 chain, address transceiver) public {
261261
(bool success, bytes memory returnData) = _admin.delegatecall(
262262
abi.encodeWithSelector(
263263
TransceiverRegistryAdmin._enableRecvTransceiverForChain.selector, chain, transceiver
@@ -266,10 +266,12 @@ abstract contract TransceiverRegistry is TransceiverRegistryBase {
266266
_checkDelegateCallRevert(success, returnData);
267267
}
268268

269-
function _disableRecvTransceiverForChain(uint16 chain, address transceiver) internal {
269+
function disableRecvTransceiverForChain(uint16 chain, address transceiver) public {
270270
(bool success, bytes memory returnData) = _admin.delegatecall(
271271
abi.encodeWithSelector(
272-
TransceiverRegistryAdmin._enableRecvTransceiverForChain.selector, chain, transceiver
272+
TransceiverRegistryAdmin._disableRecvTransceiverForChain.selector,
273+
chain,
274+
transceiver
273275
)
274276
);
275277
_checkDelegateCallRevert(success, returnData);
@@ -395,11 +397,6 @@ contract TransceiverRegistryAdmin is TransceiverRegistryBase {
395397
/// @param transceiver The address of the transceiver.
396398
event RecvTransceiverDisabledForChain(uint16 chain, address transceiver);
397399

398-
/// @notice Error when attempting to enable an transceiver that is already enabled.
399-
/// @dev Selector: TODO.
400-
/// @param transceiver The address of the transceiver.
401-
error TransceiverAlreadyEnabled(address transceiver);
402-
403400
/// @notice Error when the transceiver is the zero address.
404401
/// @dev Selector: TODO.
405402
error InvalidTransceiverZeroAddress();
@@ -455,7 +452,7 @@ contract TransceiverRegistryAdmin is TransceiverRegistryBase {
455452
_enabledTransceiverBitmap.bitmap | uint64(1 << transceiverInfos[transceiver].index);
456453
// ensure that this actually changed the bitmap
457454
if (updatedEnabledTransceiverBitmap == _enabledTransceiverBitmap.bitmap) {
458-
revert TransceiverRegistry.TransceiverAlreadyEnabled(transceiver);
455+
revert TransceiverAlreadyEnabled(transceiver);
459456
}
460457
_enabledTransceiverBitmap.bitmap = updatedEnabledTransceiverBitmap;
461458

evm/test/IntegrationAdditionalTransfer.t.sol

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {DummyToken, DummyTokenMintAndBurn} from "./NttManager.t.sol";
1616
import "../src/interfaces/IWormholeTransceiver.sol";
1717
import {WormholeTransceiver} from "../src/Transceiver/WormholeTransceiver/WormholeTransceiver.sol";
1818
import "../src/libraries/TransceiverStructs.sol";
19+
import "./libraries/TransceiverHelpers.sol";
1920
import "./mocks/MockNttManagerAdditionalPayload.sol";
2021
import "./mocks/MockTransceivers.sol";
2122

@@ -94,7 +95,9 @@ contract TestAdditionalPayload is Test {
9495
// Actually initialize properly now
9596
wormholeTransceiverChain1.initialize();
9697

97-
nttManagerChain1.setTransceiver(address(wormholeTransceiverChain1));
98+
TransceiverHelpersLib.setAndEnableTransceiver(
99+
nttManagerChain1, chainId2, address(wormholeTransceiverChain1)
100+
);
98101
// nttManagerChain1.setOutboundLimit(type(uint64).max);
99102
// nttManagerChain1.setInboundLimit(type(uint64).max, chainId2);
100103

@@ -123,7 +126,9 @@ contract TestAdditionalPayload is Test {
123126
);
124127
wormholeTransceiverChain2.initialize();
125128

126-
nttManagerChain2.setTransceiver(address(wormholeTransceiverChain2));
129+
TransceiverHelpersLib.setAndEnableTransceiver(
130+
nttManagerChain2, chainId1, address(wormholeTransceiverChain2)
131+
);
127132
// nttManagerChain2.setOutboundLimit(type(uint64).max);
128133
// nttManagerChain2.setInboundLimit(type(uint64).max, chainId1);
129134

evm/test/IntegrationManual.t.sol

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {WormholeRelayerBasicTest} from "wormhole-solidity-sdk/testing/WormholeRe
77
import "./libraries/IntegrationHelpers.sol";
88
import "wormhole-solidity-sdk/testing/helpers/WormholeSimulator.sol";
99
import "../src/NttManager/NttManager.sol";
10+
import "./libraries/TransceiverHelpers.sol";
1011
import "./mocks/MockNttManager.sol";
1112
import "./mocks/MockTransceivers.sol";
1213

@@ -67,7 +68,9 @@ contract TestRelayerEndToEndManual is IntegrationHelpers, IRateLimiterEvents {
6768
);
6869
wormholeTransceiverChain1.initialize();
6970

70-
nttManagerChain1.setTransceiver(address(wormholeTransceiverChain1));
71+
TransceiverHelpersLib.setAndEnableTransceiver(
72+
nttManagerChain1, chainId2, address(wormholeTransceiverChain1)
73+
);
7174
nttManagerChain1.setOutboundLimit(type(uint64).max);
7275
nttManagerChain1.setInboundLimit(type(uint64).max, chainId2);
7376

@@ -94,7 +97,9 @@ contract TestRelayerEndToEndManual is IntegrationHelpers, IRateLimiterEvents {
9497
);
9598
wormholeTransceiverChain2.initialize();
9699

97-
nttManagerChain2.setTransceiver(address(wormholeTransceiverChain2));
100+
TransceiverHelpersLib.setAndEnableTransceiver(
101+
nttManagerChain2, chainId1, address(wormholeTransceiverChain2)
102+
);
98103
nttManagerChain2.setOutboundLimit(type(uint64).max);
99104
nttManagerChain2.setInboundLimit(type(uint64).max, chainId1);
100105

evm/test/IntegrationRelayer.t.sol

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,12 @@ contract TestEndToEndRelayer is IntegrationHelpers, IRateLimiterEvents, Wormhole
9393
);
9494
wormholeTransceiverChain1Other.initialize();
9595

96-
nttManagerChain1.setTransceiver(address(wormholeTransceiverChain1));
97-
nttManagerChain1.setTransceiver(address(wormholeTransceiverChain1Other));
96+
TransceiverHelpersLib.setAndEnableTransceiver(
97+
nttManagerChain1, chainId2, address(wormholeTransceiverChain1)
98+
);
99+
TransceiverHelpersLib.setAndEnableTransceiver(
100+
nttManagerChain1, chainId2, address(wormholeTransceiverChain1Other)
101+
);
98102
nttManagerChain1.setOutboundLimit(type(uint64).max);
99103
nttManagerChain1.setInboundLimit(type(uint64).max, chainId2);
100104
nttManagerChain1.setThreshold(1);
@@ -141,8 +145,12 @@ contract TestEndToEndRelayer is IntegrationHelpers, IRateLimiterEvents, Wormhole
141145
);
142146
wormholeTransceiverChain2Other.initialize();
143147

144-
nttManagerChain2.setTransceiver(address(wormholeTransceiverChain2));
145-
nttManagerChain2.setTransceiver(address(wormholeTransceiverChain2Other));
148+
TransceiverHelpersLib.setAndEnableTransceiver(
149+
nttManagerChain2, chainId1, address(wormholeTransceiverChain2)
150+
);
151+
TransceiverHelpersLib.setAndEnableTransceiver(
152+
nttManagerChain2, chainId1, address(wormholeTransceiverChain2Other)
153+
);
146154
nttManagerChain2.setOutboundLimit(type(uint64).max);
147155
nttManagerChain2.setInboundLimit(type(uint64).max, chainId1);
148156

evm/test/IntegrationStandalone.t.sol

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {DummyToken, DummyTokenMintAndBurn} from "./NttManager.t.sol";
1616
import "../src/interfaces/IWormholeTransceiver.sol";
1717
import {WormholeTransceiver} from "../src/Transceiver/WormholeTransceiver/WormholeTransceiver.sol";
1818
import "../src/libraries/TransceiverStructs.sol";
19+
import "./libraries/TransceiverHelpers.sol";
1920
import "./mocks/MockNttManager.sol";
2021
import "./mocks/MockTransceivers.sol";
2122

@@ -93,7 +94,9 @@ contract TestEndToEndBase is Test, IRateLimiterEvents {
9394
// Actually initialize properly now
9495
wormholeTransceiverChain1.initialize();
9596

96-
nttManagerChain1.setTransceiver(address(wormholeTransceiverChain1));
97+
TransceiverHelpersLib.setAndEnableTransceiver(
98+
nttManagerChain1, chainId2, address(wormholeTransceiverChain1)
99+
);
97100
nttManagerChain1.setOutboundLimit(type(uint64).max);
98101
nttManagerChain1.setInboundLimit(type(uint64).max, chainId2);
99102

@@ -121,7 +124,9 @@ contract TestEndToEndBase is Test, IRateLimiterEvents {
121124
);
122125
wormholeTransceiverChain2.initialize();
123126

124-
nttManagerChain2.setTransceiver(address(wormholeTransceiverChain2));
127+
TransceiverHelpersLib.setAndEnableTransceiver(
128+
nttManagerChain2, chainId1, address(wormholeTransceiverChain2)
129+
);
125130
nttManagerChain2.setOutboundLimit(type(uint64).max);
126131
nttManagerChain2.setInboundLimit(type(uint64).max, chainId1);
127132

@@ -536,8 +541,12 @@ contract TestEndToEndBase is Test, IRateLimiterEvents {
536541
wormholeTransceiverChain2_2.setWormholePeer(
537542
chainId1, bytes32(uint256(uint160((address(wormholeTransceiverChain1_2)))))
538543
);
539-
nttManagerChain2.setTransceiver(address(wormholeTransceiverChain2_2));
540-
nttManagerChain1.setTransceiver(address(wormholeTransceiverChain1_2));
544+
TransceiverHelpersLib.setAndEnableTransceiver(
545+
nttManagerChain2, chainId1, address(wormholeTransceiverChain2_2)
546+
);
547+
TransceiverHelpersLib.setAndEnableTransceiver(
548+
nttManagerChain1, chainId2, address(wormholeTransceiverChain1_2)
549+
);
541550

542551
// Change the threshold from the setUp functions 1 to 2.
543552
nttManagerChain1.setThreshold(2);

evm/test/IntegrationWithoutRateLimiting.t.sol

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {DummyToken, DummyTokenMintAndBurn} from "./NttManager.t.sol";
1616
import "../src/interfaces/IWormholeTransceiver.sol";
1717
import {WormholeTransceiver} from "../src/Transceiver/WormholeTransceiver/WormholeTransceiver.sol";
1818
import "../src/libraries/TransceiverStructs.sol";
19+
import "./libraries/TransceiverHelpers.sol";
1920
import "./mocks/MockNttManager.sol";
2021
import "./mocks/MockTransceivers.sol";
2122

@@ -94,7 +95,9 @@ contract TestEndToEndNoRateLimiting is Test {
9495
// Actually initialize properly now
9596
wormholeTransceiverChain1.initialize();
9697

97-
nttManagerChain1.setTransceiver(address(wormholeTransceiverChain1));
98+
TransceiverHelpersLib.setAndEnableTransceiver(
99+
nttManagerChain1, chainId2, address(wormholeTransceiverChain1)
100+
);
98101
// nttManagerChain1.setOutboundLimit(type(uint64).max);
99102
// nttManagerChain1.setInboundLimit(type(uint64).max, chainId2);
100103

@@ -123,7 +126,9 @@ contract TestEndToEndNoRateLimiting is Test {
123126
);
124127
wormholeTransceiverChain2.initialize();
125128

126-
nttManagerChain2.setTransceiver(address(wormholeTransceiverChain2));
129+
TransceiverHelpersLib.setAndEnableTransceiver(
130+
nttManagerChain2, chainId1, address(wormholeTransceiverChain2)
131+
);
127132
// nttManagerChain2.setOutboundLimit(type(uint64).max);
128133
// nttManagerChain2.setInboundLimit(type(uint64).max, chainId1);
129134

@@ -524,8 +529,12 @@ contract TestEndToEndNoRateLimiting is Test {
524529
wormholeTransceiverChain2_2.setWormholePeer(
525530
chainId1, bytes32(uint256(uint160((address(wormholeTransceiverChain1_2)))))
526531
);
527-
nttManagerChain2.setTransceiver(address(wormholeTransceiverChain2_2));
528-
nttManagerChain1.setTransceiver(address(wormholeTransceiverChain1_2));
532+
TransceiverHelpersLib.setAndEnableTransceiver(
533+
nttManagerChain2, chainId1, address(wormholeTransceiverChain2_2)
534+
);
535+
TransceiverHelpersLib.setAndEnableTransceiver(
536+
nttManagerChain1, chainId2, address(wormholeTransceiverChain1_2)
537+
);
529538

530539
// Change the threshold from the setUp functions 1 to 2.
531540
nttManagerChain1.setThreshold(2);

0 commit comments

Comments
 (0)