Skip to content

Commit

Permalink
Merge branch 'main' into refactor/adapters
Browse files Browse the repository at this point in the history
  • Loading branch information
sujithsomraaj authored Sep 19, 2023
2 parents 27b00f2 + 5b9866d commit c50d195
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 36 deletions.
10 changes: 3 additions & 7 deletions src/MultiMessageReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,7 @@ contract MultiMessageReceiver is IMultiMessageReceiver, ExecutorAware, Initializ

/// @notice receive messages from allowed bridge receiver adapters
/// @param _message is the crosschain message sent by the mma sender
/// @param _bridgeName is the name of the bridge that relays the message
function receiveMessage(MessageLibrary.Message calldata _message, string memory _bridgeName)
external
override
onlyReceiverAdapter
{
function receiveMessage(MessageLibrary.Message calldata _message) external override onlyReceiverAdapter {
if (_message.dstChainId != block.chainid) {
revert Error.INVALID_DST_CHAIN();
}
Expand Down Expand Up @@ -147,7 +142,8 @@ contract MultiMessageReceiver is IMultiMessageReceiver, ExecutorAware, Initializ
);
}

emit SingleBridgeMsgReceived(msgId, _bridgeName, _message.nonce, msg.sender);
string memory bridgeName = IMessageReceiverAdapter(msg.sender).name();
emit SingleBridgeMsgReceived(msgId, bridgeName, _message.nonce, msg.sender);
}

/// @notice Execute the message (invoke external call according to the message content) if the message
Expand Down
2 changes: 1 addition & 1 deletion src/adapters/axelar/AxelarReceiverAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ contract AxelarReceiverAdapter is IAxelarExecutable, IMessageReceiverAdapter {

MessageLibrary.Message memory _data = abi.decode(decodedPayload.data, (MessageLibrary.Message));

try IMultiMessageReceiver(decodedPayload.finalDestination).receiveMessage(_data, name) {
try IMultiMessageReceiver(decodedPayload.finalDestination).receiveMessage(_data) {
emit MessageIdExecuted(_data.srcChainId, msgId);
} catch (bytes memory lowLevelData) {
revert MessageFailure(msgId, lowLevelData);
Expand Down
4 changes: 2 additions & 2 deletions src/adapters/wormhole/WormholeReceiverAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import "../../libraries/Message.sol";
/// @dev allows wormhole relayers to write to receiver adapter which then forwards the message to
/// the MMA receiver.
contract WormholeReceiverAdapter is IMessageReceiverAdapter, IWormholeReceiver {
string public constant name = "wormhole";
string public constant name = "WORMHOLE";
address public immutable relayer;
IGAC public immutable gac;
uint16 public immutable senderChain;
Expand Down Expand Up @@ -149,7 +149,7 @@ contract WormholeReceiverAdapter is IMessageReceiverAdapter, IWormholeReceiver {

MessageLibrary.Message memory _data = abi.decode(decodedPayload.data, (MessageLibrary.Message));

try IMultiMessageReceiver(decodedPayload.finalDestination).receiveMessage(_data, name) {
try IMultiMessageReceiver(decodedPayload.finalDestination).receiveMessage(_data) {
emit MessageIdExecuted(_data.srcChainId, msgId);
} catch (bytes memory lowLevelData) {
revert MessageFailure(msgId, lowLevelData);
Expand Down
3 changes: 1 addition & 2 deletions src/interfaces/IMultiMessageReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,5 @@ interface IMultiMessageReceiver {

/// @notice Receive messages from allowed bridge receiver adapters.
/// @dev Every receiver adapter should call this function with decoded MessageLibrary.Message
/// when receiver adapter receives a message produced by a corresponding sender adapter on the source chain.
function receiveMessage(MessageLibrary.Message calldata _message, string memory _bridgeName) external;
function receiveMessage(MessageLibrary.Message calldata _message) external;
}
40 changes: 18 additions & 22 deletions test/unit-tests/MultiMessageReceiver.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ contract MultiMessageReceiverTest is Setup {
vm.expectEmit(true, true, true, true, address(receiver));
emit SingleBridgeMsgReceived(msgId, "WORMHOLE", 42, wormholeAdapterAddr);

receiver.receiveMessage(message, "WORMHOLE");
receiver.receiveMessage(message);

assertFalse(receiver.isExecuted(msgId));

Expand Down Expand Up @@ -200,10 +200,10 @@ contract MultiMessageReceiverTest is Setup {
});
bytes32 msgId = MessageLibrary.computeMsgId(message);

receiver.receiveMessage(message, "WORMHOLE");
receiver.receiveMessage(message);

vm.startPrank(axelarAdapterAddr);
receiver.receiveMessage(message, "AXELAR");
receiver.receiveMessage(message);

assertEq(receiver.msgDeliveryCount(msgId), 2);
}
Expand All @@ -222,8 +222,7 @@ contract MultiMessageReceiverTest is Setup {
callData: bytes(""),
nativeValue: 0,
expiration: 0
}),
"WORMHOLE"
})
);
}

Expand All @@ -241,8 +240,7 @@ contract MultiMessageReceiverTest is Setup {
callData: bytes(""),
nativeValue: 0,
expiration: 0
}),
"WORMHOLE"
})
);
}

Expand All @@ -260,8 +258,7 @@ contract MultiMessageReceiverTest is Setup {
callData: bytes(""),
nativeValue: 0,
expiration: 0
}),
"WORMHOLE"
})
);
}

Expand All @@ -279,8 +276,7 @@ contract MultiMessageReceiverTest is Setup {
callData: bytes(""),
nativeValue: 0,
expiration: 0
}),
"WORMHOLE"
})
);
}

Expand All @@ -298,10 +294,10 @@ contract MultiMessageReceiverTest is Setup {
expiration: type(uint256).max
});

receiver.receiveMessage(message, "WORMHOLE");
receiver.receiveMessage(message);

vm.expectRevert(Error.DUPLICATE_MESSAGE_DELIVERY_BY_ADAPTER.selector);
receiver.receiveMessage(message, "WORMHOLE");
receiver.receiveMessage(message);
}

/// @dev executed message should be rejected
Expand All @@ -322,13 +318,13 @@ contract MultiMessageReceiverTest is Setup {
receiver.updateQuorum(1);

vm.startPrank(wormholeAdapterAddr);
receiver.receiveMessage(message, "WORMHOLE");
receiver.receiveMessage(message);

receiver.executeMessage(msgId);

vm.startPrank(axelarAdapterAddr);
vm.expectRevert(Error.MSG_ID_ALREADY_EXECUTED.selector);
receiver.receiveMessage(message, "AXELAR");
receiver.receiveMessage(message);
}

/// @dev executes message delivered by two adapters
Expand All @@ -346,10 +342,10 @@ contract MultiMessageReceiverTest is Setup {
});
bytes32 msgId = MessageLibrary.computeMsgId(message);

receiver.receiveMessage(message, "WORMHOLE");
receiver.receiveMessage(message);

vm.startPrank(axelarAdapterAddr);
receiver.receiveMessage(message, "AXELAR");
receiver.receiveMessage(message);

vm.expectEmit(true, true, true, true, address(receiver));
emit MessageExecuted(msgId, address(42), 0, 42, bytes("42"));
Expand All @@ -374,7 +370,7 @@ contract MultiMessageReceiverTest is Setup {
});
bytes32 msgId = MessageLibrary.computeMsgId(message);

receiver.receiveMessage(message, "WORMHOLE");
receiver.receiveMessage(message);

vm.expectRevert(Error.MSG_EXECUTION_PASSED_DEADLINE.selector);
receiver.executeMessage(msgId);
Expand All @@ -395,10 +391,10 @@ contract MultiMessageReceiverTest is Setup {
});
bytes32 msgId = MessageLibrary.computeMsgId(message);

receiver.receiveMessage(message, "WORMHOLE");
receiver.receiveMessage(message);

vm.startPrank(axelarAdapterAddr);
receiver.receiveMessage(message, "AXELAR");
receiver.receiveMessage(message);

receiver.executeMessage(msgId);

Expand All @@ -421,7 +417,7 @@ contract MultiMessageReceiverTest is Setup {
});
bytes32 msgId = MessageLibrary.computeMsgId(message);

receiver.receiveMessage(message, "WORMHOLE");
receiver.receiveMessage(message);

vm.expectRevert(Error.QUORUM_NOT_ACHIEVED.selector);
receiver.executeMessage(msgId);
Expand Down Expand Up @@ -589,7 +585,7 @@ contract MultiMessageReceiverTest is Setup {
});
bytes32 msgId = MessageLibrary.computeMsgId(message);

receiver.receiveMessage(message, "WORMHOLE");
receiver.receiveMessage(message);

(bool isExecuted, uint256 msgCurrentVotes, string[] memory successfulBridge) = receiver.getMessageInfo(msgId);
assertFalse(isExecuted);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ contract AxelarReceiverAdapterTest is Setup {

/// @dev gets the name
function test_name() public {
assertEq(adapter.name(), "axelar");
assertEq(adapter.name(), "AXELAR");
}

/// @dev updates sender adapter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ contract WormholeReceiverAdapterTest is Setup {

/// @dev gets the name
function test_name() public {
assertEq(adapter.name(), "wormhole");
assertEq(adapter.name(), "WORMHOLE");
}

/// @dev updates sender adapter
Expand Down

0 comments on commit c50d195

Please sign in to comment.