Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contracts/src/Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ contract Gateway is IGatewayBase, IGatewayV1, IGatewayV2, IInitializable, IUpgra

bool success = v2_dispatch(message);

emit IGatewayV2.InboundMessageDispatched(message.nonce, success, rewardAddress);
emit IGatewayV2.InboundMessageDispatched(message.nonce, message.topic, success, rewardAddress);
}

function v2_dispatch(InboundMessageV2 calldata message) internal returns (bool) {
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/v2/IGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface IGatewayV2 {
*/

// V2: Emitted when inbound message has been dispatched
event InboundMessageDispatched(uint64 indexed nonce, bool success, bytes32 rewardAddress);
event InboundMessageDispatched(uint64 indexed nonce, bytes32 topic, bool success, bytes32 rewardAddress);

// v2 Emitted when an outbound message has been accepted for delivery to a Polkadot parachain
event OutboundMessageAccepted(uint64 nonce, Payload payload);
Expand Down
2 changes: 2 additions & 0 deletions contracts/src/v2/Types.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ struct InboundMessage {
bytes32 origin;
// Message nonce
uint64 nonce;
// XCM Topic
bytes32 topic;
// Commands
Command[] commands;
}
Expand Down
28 changes: 21 additions & 7 deletions contracts/test/GatewayV2.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -206,22 +206,26 @@ contract GatewayV2Test is Test {
* Message Verification
*/
function testSubmitHappyPath() public {
bytes32 topic = keccak256("topic");

// Expect the gateway to emit `InboundMessageDispatched`
vm.expectEmit(true, false, false, true);
emit IGatewayV2.InboundMessageDispatched(1, true, relayerRewardAddress);
emit IGatewayV2.InboundMessageDispatched(1, topic, true, relayerRewardAddress);

hoax(relayer, 1 ether);
IGatewayV2(address(gateway)).v2_submit(
InboundMessageV2({origin: keccak256("666"), nonce: 1, commands: makeMockCommand()}),
InboundMessageV2({origin: keccak256("666"), nonce: 1, topic: topic, commands: makeMockCommand()}),
proof,
makeMockProof(),
relayerRewardAddress
);
}

function testSubmitFailInvalidNonce() public {
bytes32 topic = keccak256("topic");

InboundMessageV2 memory message =
InboundMessageV2({origin: keccak256("666"), nonce: 1, commands: makeMockCommand()});
InboundMessageV2({origin: keccak256("666"), nonce: 1, topic: topic, commands: makeMockCommand()});

hoax(relayer, 1 ether);
IGatewayV2(address(gateway)).v2_submit(
Expand All @@ -236,8 +240,10 @@ contract GatewayV2Test is Test {
}

function testSubmitFailInvalidProof() public {
bytes32 topic = keccak256("topic");

InboundMessageV2 memory message =
InboundMessageV2({origin: keccak256("666"), nonce: 1, commands: makeMockCommand()});
InboundMessageV2({origin: keccak256("666"), nonce: 1, topic: topic, commands: makeMockCommand()});

MockGateway(address(gateway)).setCommitmentsAreVerified(false);
vm.expectRevert(IGatewayBase.InvalidProof.selector);
Expand Down Expand Up @@ -345,18 +351,21 @@ contract GatewayV2Test is Test {
}

function testUnlockWethSuccess() public {
bytes32 topic = keccak256("topic");

hoax(assetHubAgent);
weth.deposit{value: 1 ether}();

vm.expectEmit(true, false, false, true);
emit IGatewayV2.InboundMessageDispatched(1, true, relayerRewardAddress);
emit IGatewayV2.InboundMessageDispatched(1, topic, true, relayerRewardAddress);

vm.deal(assetHubAgent, 1 ether);
hoax(relayer, 1 ether);
IGatewayV2(address(gateway)).v2_submit(
InboundMessageV2({
origin: Constants.ASSET_HUB_AGENT_ID,
nonce: 1,
topic: topic,
commands: makeUnlockWethCommand(0.1 ether)
}),
proof,
Expand All @@ -366,6 +375,8 @@ contract GatewayV2Test is Test {
}

function testEncodeDecodeMessageV2() public {
bytes32 topic = keccak256("topic");

UnlockNativeTokenParams memory params = UnlockNativeTokenParams({
token: 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2,
recipient: 0xEDa338E4dC46038493b885327842fD3E301CaB39,
Expand All @@ -376,7 +387,7 @@ contract GatewayV2Test is Test {
commands[0] =
CommandV2({kind: CommandKind.UnlockNativeToken, gas: 100_000, payload: encoded});
InboundMessageV2 memory message =
InboundMessageV2({origin: bytes32(uint256(1000)), nonce: 1, commands: commands});
InboundMessageV2({origin: bytes32(uint256(1000)), nonce: 1, topic: topic, commands: commands});
bytes memory rawBytes = abi.encode(message);

//From OutboundQueueV2
Expand Down Expand Up @@ -409,15 +420,18 @@ contract GatewayV2Test is Test {
}

function testAgentCallContractSuccess() public {
bytes32 topic = keccak256("topic");

vm.expectEmit(true, false, false, true);
emit IGatewayV2.InboundMessageDispatched(1, true, relayerRewardAddress);
emit IGatewayV2.InboundMessageDispatched(1, topic, true, relayerRewardAddress);

vm.deal(assetHubAgent, 1 ether);
hoax(relayer, 1 ether);
IGatewayV2(address(gateway)).v2_submit(
InboundMessageV2({
origin: Constants.ASSET_HUB_AGENT_ID,
nonce: 1,
topic: topic,
commands: makeCallContractCommand(0.1 ether)
}),
proof,
Expand Down
Loading