From b4061743b896da2f8551d6e50e9da0cbbc07702d Mon Sep 17 00:00:00 2001 From: Michael Zhou Date: Tue, 29 Aug 2023 22:31:54 -0700 Subject: [PATCH] Add test scenario for invalid quorum Also rename "QuorumUpdated" event to use consistent casing. --- src/MultiMessageReceiver.sol | 4 ++-- test/unit-tests/MultiMessageReceiver.t.sol | 22 +++++++++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/MultiMessageReceiver.sol b/src/MultiMessageReceiver.sol index aed3f86..96a8989 100644 --- a/src/MultiMessageReceiver.sol +++ b/src/MultiMessageReceiver.sol @@ -41,7 +41,7 @@ contract MultiMessageReceiver is IMultiMessageReceiver, ExecutorAware, Initializ ////////////////////////////////////////////////////////////////*/ event ReceiverAdapterUpdated(address receiverAdapter, bool add); - event quorumUpdated(uint64 oldValue, uint64 newValue); + event QuorumUpdated(uint64 oldValue, uint64 newValue); event SingleBridgeMsgReceived( bytes32 indexed msgId, string indexed bridgeName, uint256 nonce, address receiverAdapter ); @@ -208,7 +208,7 @@ contract MultiMessageReceiver is IMultiMessageReceiver, ExecutorAware, Initializ uint64 oldValue = quorum; quorum = _quorum; - emit quorumUpdated(oldValue, _quorum); + emit QuorumUpdated(oldValue, _quorum); } /// @notice view message info, return (executed, msgPower, delivered adapters) diff --git a/test/unit-tests/MultiMessageReceiver.t.sol b/test/unit-tests/MultiMessageReceiver.t.sol index 2c78309..f4c33e3 100644 --- a/test/unit-tests/MultiMessageReceiver.t.sol +++ b/test/unit-tests/MultiMessageReceiver.t.sol @@ -14,7 +14,7 @@ import {MultiMessageReceiver} from "src/MultiMessageReceiver.sol"; contract MultiMessageReceiverTest is Setup { event ReceiverAdapterUpdated(address receiverAdapter, bool add); - event quorumUpdated(uint64 oldValue, uint64 newValue); + event QuorumUpdated(uint64 oldValue, uint64 newValue); event SingleBridgeMsgReceived( bytes32 indexed msgId, string indexed bridgeName, uint256 nonce, address receiverAdapter ); @@ -51,7 +51,7 @@ contract MultiMessageReceiverTest is Setup { receiver.initialize(new address[](0), 0); } - /// @dev initializer cannot be called with zero adapter + /// @dev cannot be called with zero adapter function test_initialize_zero_receiver_adapter() public { vm.startPrank(caller); @@ -60,7 +60,7 @@ contract MultiMessageReceiverTest is Setup { dummyReceiver.initialize(new address[](0), 0); } - /// @dev initializer cannot be called with zero address adapter + /// @dev cannot be called with zero address adapter function test_initialize_zero_address_input() public { vm.startPrank(caller); @@ -71,7 +71,7 @@ contract MultiMessageReceiverTest is Setup { dummyReceiver.initialize(adapters, 1); } - /// @dev initializer quorum too large + /// @dev quorum cannot be larger than the number of receiver adapters function test_initialize_quorum_too_large() public { vm.startPrank(caller); @@ -82,6 +82,18 @@ contract MultiMessageReceiverTest is Setup { dummyReceiver.initialize(adapters, 2); } + /// @dev quorum cannot be larger than the number of unique receiver adapters + function test_initialize_quorum_larger_than_num_trusted_executors() public { + vm.startPrank(caller); + + MultiMessageReceiver dummyReceiver = new MultiMessageReceiver(); + address[] memory adapters = new address[](2); + adapters[0] = address(42); + adapters[1] = address(42); + vm.expectRevert(Error.INVALID_QUORUM_THRESHOLD.selector); + dummyReceiver.initialize(adapters, 2); + } + /// @dev initializer quorum cannot be zero function test_initialize_zero_quorum() public { vm.startPrank(caller); @@ -441,7 +453,7 @@ contract MultiMessageReceiverTest is Setup { receiver.updateReceiverAdapter(updatedAdapters, operations); vm.expectEmit(true, true, true, true, address(receiver)); - emit quorumUpdated(2, 3); + emit QuorumUpdated(2, 3); receiver.updateQuorum(3); assertEq(receiver.quorum(), 3);