Skip to content

Commit

Permalink
Add test scenario for invalid quorum
Browse files Browse the repository at this point in the history
Also rename "QuorumUpdated" event to use consistent casing.
  • Loading branch information
Dominator008 committed Aug 30, 2023
1 parent be85bb0 commit b406174
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/MultiMessageReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down Expand Up @@ -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)
Expand Down
22 changes: 17 additions & 5 deletions test/unit-tests/MultiMessageReceiver.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit b406174

Please sign in to comment.