Skip to content

Commit

Permalink
Add unit tests for Axelar and Wormhole adapters
Browse files Browse the repository at this point in the history
Part of #45.
  • Loading branch information
Dominator008 committed Sep 12, 2023
1 parent 9aa65fe commit 38ed57e
Show file tree
Hide file tree
Showing 8 changed files with 1,031 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/adapters/Wormhole/WormholeSenderAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ contract WormholeSenderAdapter is BaseSenderAdapter {
/*/////////////////////////////////////////////////////////////////
STATE VARIABLES
////////////////////////////////////////////////////////////////*/
mapping(uint256 => uint16) chainIdMap;
mapping(uint256 => uint16) public chainIdMap;

/*/////////////////////////////////////////////////////////////////
CONSTRUCTOR
Expand Down
15 changes: 15 additions & 0 deletions test/contracts-mock/adapters/axelar/MockAxelarGateway.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity >=0.8.9;

/// @dev A mock Axelar gateway that either validates or rejects contract calls
contract MockAxelarGateway {
bool validate;

constructor(bool _validate) {
validate = _validate;
}

function validateContractCall(bytes32, string calldata, string calldata, bytes32) external view returns (bool) {
return validate;
}
}
4 changes: 2 additions & 2 deletions test/unit-tests/MultiMessageReceiver.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ contract MultiMessageReceiverTest is Setup {
assertEq(receiver.isExecuted(msgId), true);
}

/// @dev cannot executes message past deadline
/// @dev cannot execute message past deadline
function test_execute_message_passed_deadline() public {
vm.startPrank(wormholeAdapterAddr);

Expand Down Expand Up @@ -386,7 +386,7 @@ contract MultiMessageReceiverTest is Setup {
receiver.executeMessage(msgId);
}

/// @dev cannot executes message without quorum
/// @dev cannot execute message without quorum
function test_execute_message_invalid_quorum_for_execution() public {
vm.startPrank(wormholeAdapterAddr);

Expand Down
71 changes: 71 additions & 0 deletions test/unit-tests/adapters/BaseSenderAdapter.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity >=0.8.9;

/// library imports
import {Vm} from "forge-std/Test.sol";

/// local imports
import "../../Setup.t.sol";
import "src/libraries/Error.sol";
import {AxelarSenderAdapter} from "src/adapters/axelar/AxelarSenderAdapter.sol";

contract AxelarSenderAdapterTest is Setup {
event ReceiverAdapterUpdated(uint256 dstChainId, address receiverAdapter);

uint256 constant SRC_CHAIN_ID = 1;
uint256 constant DST_CHAIN_ID = 137;

// Test base contract with Axelar adapter
AxelarSenderAdapter adapter;

/// @dev initializes the setup
function setUp() public override {
super.setUp();

vm.selectFork(fork[SRC_CHAIN_ID]);
adapter = AxelarSenderAdapter(contractAddress[SRC_CHAIN_ID]["AXELAR_SENDER_ADAPTER"]);
}

/// @dev updates receiver adapter
function test_update_receiver_adapter() public {
vm.startPrank(owner);

uint256[] memory dstChainIds = new uint256[](2);
dstChainIds[0] = 56;
dstChainIds[1] = DST_CHAIN_ID;
address[] memory receiverAdapters = new address[](2);
receiverAdapters[0] = address(42);
receiverAdapters[1] = address(43);

vm.expectEmit(true, true, true, true, address(adapter));
emit ReceiverAdapterUpdated(56, address(42));
vm.expectEmit(true, true, true, true, address(adapter));
emit ReceiverAdapterUpdated(DST_CHAIN_ID, address(43));

adapter.updateReceiverAdapter(dstChainIds, receiverAdapters);

assertEq(adapter.receiverAdapters(56), address(42));
assertEq(adapter.receiverAdapters(DST_CHAIN_ID), address(43));
}

/// @dev only privileged caller can update receiver adapter
function test_update_receiver_adapter_only_privileged_caller() public {
vm.startPrank(caller);

vm.expectRevert(Error.INVALID_PRIVILEGED_CALLER.selector);
adapter.updateReceiverAdapter(new uint256[](0), new address[](0));
}

/// @dev cannot update receiver adapter with invalid arrays
function test_update_receiver_adapter_array_length_mismatched() public {
vm.startPrank(owner);

vm.expectRevert(Error.ARRAY_LENGTH_MISMATCHED.selector);
adapter.updateReceiverAdapter(new uint256[](0), new address[](1));
}

/// @dev gets chian ID
function test_get_chain_id() public {
assertEq(adapter.getChainId(), SRC_CHAIN_ID);
}
}
Loading

0 comments on commit 38ed57e

Please sign in to comment.