Skip to content

Commit f88f825

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

File tree

5 files changed

+48
-20
lines changed

5 files changed

+48
-20
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/NttManager.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ contract TestNttManager is Test, IRateLimiterEvents {
305305

306306
vm.expectRevert(
307307
abi.encodeWithSelector(
308-
TransceiverRegistry.TransceiverAlreadyEnabled.selector, address(e)
308+
TransceiverRegistryBase.TransceiverAlreadyEnabled.selector, address(e)
309309
)
310310
);
311311
nttManager.setTransceiver(address(e));

evm/test/NttManagerNoRateLimiting.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ contract TestNttManagerNoRateLimiting is Test, IRateLimiterEvents {
233233

234234
vm.expectRevert(
235235
abi.encodeWithSelector(
236-
TransceiverRegistry.TransceiverAlreadyEnabled.selector, address(e)
236+
TransceiverRegistryBase.TransceiverAlreadyEnabled.selector, address(e)
237237
)
238238
);
239239
nttManager.setTransceiver(address(e));

evm/test/libraries/TransceiverHelpers.sol

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,38 @@ library TransceiverHelpersLib {
2626
return (e1, e2);
2727
}
2828

29+
function setup_transceivers(
30+
uint16 chainId,
31+
NttManager nttManager
32+
) internal returns (DummyTransceiver, DummyTransceiver) {
33+
DummyTransceiver e1 = new DummyTransceiver(address(nttManager));
34+
DummyTransceiver e2 = new DummyTransceiver(address(nttManager));
35+
nttManager.setTransceiver(address(e1));
36+
nttManager.enableSendTransceiverForChain(chainId, address(e1));
37+
nttManager.enableRecvTransceiverForChain(chainId, address(e1));
38+
nttManager.setTransceiver(address(e2));
39+
nttManager.enableSendTransceiverForChain(chainId, address(e2));
40+
nttManager.enableRecvTransceiverForChain(chainId, address(e2));
41+
nttManager.setThreshold(2);
42+
return (e1, e2);
43+
}
44+
45+
function setAndEnableTransceiver(NttManager nttMgr, uint16 chnId, address transceiver) public {
46+
nttMgr.setTransceiver(address(transceiver));
47+
nttMgr.enableSendTransceiverForChain(chnId, address(transceiver));
48+
nttMgr.enableRecvTransceiverForChain(chnId, address(transceiver));
49+
}
50+
51+
function disableAndRemoveTransceiver(
52+
NttManager nttMgr,
53+
uint16 chnId,
54+
address transceiver
55+
) public {
56+
nttMgr.disableSendTransceiverForChain(chnId, address(transceiver));
57+
nttMgr.disableRecvTransceiverForChain(chnId, address(transceiver));
58+
nttMgr.removeTransceiver(address(transceiver));
59+
}
60+
2961
function attestTransceiversHelper(
3062
address to,
3163
bytes32 id,

0 commit comments

Comments
 (0)