Skip to content

Commit

Permalink
Increase unit test coverage for receiver
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominator008 committed Oct 7, 2023
1 parent cf9f48c commit dd98e57
Showing 1 changed file with 75 additions and 4 deletions.
79 changes: 75 additions & 4 deletions test/unit-tests/MultiBridgeMessageReceiver.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,58 @@ contract MultiBridgeMessageReceiverTest is Setup {
timelockAddr = contractAddress[DST_CHAIN_ID]["TIMELOCK"];
}

/// @dev verifies default setup
function test_constructor() public {
assertEq(receiver.srcChainId(), SRC_CHAIN_ID);
assertEq(address(receiver.gac()), contractAddress[DST_CHAIN_ID]["GAC"]);
assertEq(receiver.quorum(), 2);
assertTrue(receiver.isTrustedExecutor(wormholeAdapterAddr));
assertTrue(receiver.isTrustedExecutor(axelarAdapterAddr));
}

/// @dev cannot be called with zero source chain id
function test_constructor_zero_chain_id_input() public {
vm.expectRevert(Error.INVALID_SENDER_CHAIN_ID.selector);

address[] memory receiverAdapters = new address[](1);
receiverAdapters[0] = address(43);

vm.expectRevert(Error.INVALID_SENDER_CHAIN_ID.selector);
new MultiBridgeMessageReceiver(0, address(42), receiverAdapters, 1);
}

/// @dev cannot be called with zero address GAC
function test_constructor_zero_gac_address_input() public {
address[] memory receiverAdapters = new address[](1);
receiverAdapters[0] = address(43);

vm.expectRevert(Error.ZERO_ADDRESS_INPUT.selector);
new MultiBridgeMessageReceiver(SRC_CHAIN_ID, address(0), receiverAdapters, 1);
}

/// @dev cannot be called with receiver adapters containing zero address
function test_constructor_zero_address_adapter() public {
address[] memory receiverAdapters = new address[](1);
receiverAdapters[0] = address(43);
receiverAdapters[0] = address(0);

new MultiBridgeMessageReceiver(1, address(0), receiverAdapters, 1);
vm.expectRevert(Error.ZERO_ADDRESS_INPUT.selector);
new MultiBridgeMessageReceiver(SRC_CHAIN_ID, address(42), receiverAdapters, 1);
}

/// @dev cannot be called with zero quorum
function test_constructor_zero_quorum() public {
address[] memory receiverAdapters = new address[](1);
receiverAdapters[0] = address(42);

vm.expectRevert(Error.INVALID_QUORUM_THRESHOLD.selector);
new MultiBridgeMessageReceiver(SRC_CHAIN_ID, address(43), receiverAdapters, 0);
}

/// @dev cannot be called with quorum too large
function test_constructor_quorum_too_large() public {
address[] memory receiverAdapters = new address[](1);
receiverAdapters[0] = address(42);

vm.expectRevert(Error.INVALID_QUORUM_THRESHOLD.selector);
new MultiBridgeMessageReceiver(SRC_CHAIN_ID, address(43), receiverAdapters, 2);
}

/// @dev receives message from one adapter
Expand Down Expand Up @@ -330,6 +364,22 @@ contract MultiBridgeMessageReceiverTest is Setup {
receiver.scheduleMessageExecution(msgId);
}

/// @dev updates governance timelock
function test_update_governance_timelock() public {
vm.startPrank(timelockAddr);

receiver.updateGovernanceTimelock(address(42));
assertEq(receiver.governanceTimelock(), address(42));
}

/// @dev cannot update governance timelock with zero address
function test_update_governance_timelock_zero_address() public {
vm.startPrank(timelockAddr);

vm.expectRevert(Error.ZERO_GOVERNANCE_TIMELOCK.selector);
receiver.updateGovernanceTimelock(address(0));
}

/// @dev adds one receiver adapter
function test_update_receiver_adapter_add() public {
vm.startPrank(timelockAddr);
Expand Down Expand Up @@ -391,6 +441,27 @@ contract MultiBridgeMessageReceiverTest is Setup {
receiver.updateReceiverAdapters(adapters, operations);
}

/// @dev cannot update with empty adapters list
function test_update_receiver_adapter_empty_lst() public {
vm.startPrank(timelockAddr);

vm.expectRevert(Error.ZERO_RECEIVER_ADAPTER.selector);

receiver.updateReceiverAdapters(new address[](0), new bool[](0));
}

/// @dev cannot update with zero adapter address
function test_update_receiver_adapter_zero_address() public {
vm.startPrank(timelockAddr);

address[] memory adapters = new address[](1);
adapters[0] = address(0);

vm.expectRevert(Error.ZERO_ADDRESS_INPUT.selector);

receiver.updateReceiverAdapters(adapters, new bool[](1));
}

/// @dev cannot remove one receiver adapter without reducing quorum first
function test_update_receiver_adapter_remove_invalid_quorum_threshold() public {
vm.startPrank(timelockAddr);
Expand Down

0 comments on commit dd98e57

Please sign in to comment.