Skip to content

Commit

Permalink
Remove hard coding of source chain (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
ermyas authored Sep 17, 2023
1 parent 47836fe commit 479d185
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
12 changes: 8 additions & 4 deletions src/MultiMessageReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ contract MultiMessageReceiver is IMultiMessageReceiver, ExecutorAware, Initializ
STATE VARIABLES
////////////////////////////////////////////////////////////////*/

/// @notice the id of the only source chain that this contract can receive messages from
uint256 public srcChainId;

/// @notice minimum number of AMBs required for delivery before execution
uint64 public quorum;

Expand Down Expand Up @@ -59,23 +62,25 @@ contract MultiMessageReceiver is IMultiMessageReceiver, ExecutorAware, Initializ

/// @notice sets the initial parameters
function initialize(
uint256 _srcChainId,
address[] calldata _receiverAdapters,
bool[] calldata _operations,
uint64 _quorum,
address _governanceTimelock
) external initializer {
srcChainId = _srcChainId;

/// @dev adds the new receiver adapters before setting quorum and validations
_updateReceiverAdapters(_receiverAdapters, _operations);

if (_quorum > trustedExecutorsCount() || _quorum == 0) {
revert Error.INVALID_QUORUM_THRESHOLD();
}
quorum = _quorum;

if (_governanceTimelock == address(0)) {
revert Error.ZERO_GOVERNANCE_TIMELOCK();
}

quorum = _quorum;
governanceTimelock = _governanceTimelock;
}

Expand All @@ -99,8 +104,7 @@ contract MultiMessageReceiver is IMultiMessageReceiver, ExecutorAware, Initializ
revert Error.INVALID_TARGET();
}

/// FIXME: could make this configurable through GAC, instead of hardcoding 1
if (_message.srcChainId != 1) {
if (_message.srcChainId != srcChainId) {
revert Error.INVALID_SENDER_CHAIN_ID();
}

Expand Down
2 changes: 1 addition & 1 deletion test/Setup.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ abstract contract Setup is Test {
_operations[1] = true;

MultiMessageReceiver(contractAddress[DST_CHAINS[i]][bytes("MMA_RECEIVER")]).initialize(
_receiverAdapters, _operations, 2, contractAddress[chainId]["TIMELOCK"]
ETHEREUM_CHAIN_ID, _receiverAdapters, _operations, 2, contractAddress[chainId]["TIMELOCK"]
);

unchecked {
Expand Down
16 changes: 8 additions & 8 deletions test/unit-tests/MultiMessageReceiver.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ contract MultiMessageReceiverTest is Setup {
operation[1] = true;

MultiMessageReceiver dummyReceiver = new MultiMessageReceiver();
dummyReceiver.initialize(adapters, operation, 2, timelockAddr);
dummyReceiver.initialize(ETHEREUM_CHAIN_ID, adapters, operation, 2, timelockAddr);

assertEq(dummyReceiver.quorum(), 2);
assertTrue(dummyReceiver.isTrustedExecutor(wormholeAdapterAddr));
Expand All @@ -60,7 +60,7 @@ contract MultiMessageReceiverTest is Setup {
vm.startPrank(caller);

vm.expectRevert("Initializable: contract is already initialized");
receiver.initialize(new address[](0), new bool[](0), 0, address(0));
receiver.initialize(ETHEREUM_CHAIN_ID, new address[](0), new bool[](0), 0, address(0));
}

/// @dev cannot be called with zero adapter
Expand All @@ -70,7 +70,7 @@ contract MultiMessageReceiverTest is Setup {
MultiMessageReceiver dummyReceiver = new MultiMessageReceiver();

vm.expectRevert(Error.ZERO_RECEIVER_ADAPTER.selector);
dummyReceiver.initialize(new address[](0), new bool[](0), 0, address(0));
dummyReceiver.initialize(ETHEREUM_CHAIN_ID, new address[](0), new bool[](0), 0, address(0));
}

/// @dev cannot be called with zero address adapter
Expand All @@ -85,7 +85,7 @@ contract MultiMessageReceiverTest is Setup {
operation[0] = true;

vm.expectRevert(Error.ZERO_ADDRESS_INPUT.selector);
dummyReceiver.initialize(adapters, operation, 1, timelockAddr);
dummyReceiver.initialize(ETHEREUM_CHAIN_ID, adapters, operation, 1, timelockAddr);
}

/// @dev quorum cannot be larger than the number of receiver adapters
Expand All @@ -100,7 +100,7 @@ contract MultiMessageReceiverTest is Setup {
operation[0] = true;

vm.expectRevert(Error.INVALID_QUORUM_THRESHOLD.selector);
dummyReceiver.initialize(adapters, operation, 2, timelockAddr);
dummyReceiver.initialize(ETHEREUM_CHAIN_ID, adapters, operation, 2, timelockAddr);
}

/// @dev quorum cannot be larger than the number of unique receiver adapters
Expand All @@ -117,7 +117,7 @@ contract MultiMessageReceiverTest is Setup {
operation[1] = true;

vm.expectRevert(Error.INVALID_QUORUM_THRESHOLD.selector);
dummyReceiver.initialize(adapters, operation, 2, timelockAddr);
dummyReceiver.initialize(ETHEREUM_CHAIN_ID, adapters, operation, 2, timelockAddr);
}

/// @dev initializer quorum cannot be zero
Expand All @@ -132,7 +132,7 @@ contract MultiMessageReceiverTest is Setup {
operation[0] = true;

vm.expectRevert(Error.INVALID_QUORUM_THRESHOLD.selector);
dummyReceiver.initialize(adapters, operation, 0, timelockAddr);
dummyReceiver.initialize(ETHEREUM_CHAIN_ID, adapters, operation, 0, timelockAddr);
}

/// @dev governance timelock cannot be zero address
Expand All @@ -147,7 +147,7 @@ contract MultiMessageReceiverTest is Setup {
operation[0] = true;

vm.expectRevert(Error.ZERO_GOVERNANCE_TIMELOCK.selector);
dummyReceiver.initialize(adapters, operation, 1, address(0));
dummyReceiver.initialize(ETHEREUM_CHAIN_ID, adapters, operation, 1, address(0));
}

/// @dev receives message from one adapter
Expand Down

0 comments on commit 479d185

Please sign in to comment.