Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log topic on ethereum side #1404

Merged
merged 3 commits into from
Mar 7, 2025
Merged
Changes from all commits
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
@@ -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) {
2 changes: 1 addition & 1 deletion contracts/src/v2/IGateway.sol
Original file line number Diff line number Diff line change
@@ -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);
2 changes: 2 additions & 0 deletions contracts/src/v2/Types.sol
Original file line number Diff line number Diff line change
@@ -10,6 +10,8 @@ struct InboundMessage {
bytes32 origin;
// Message nonce
uint64 nonce;
// XCM Topic
bytes32 topic;
// Commands
Command[] commands;
}
59 changes: 45 additions & 14 deletions contracts/test/GatewayV2.t.sol
Original file line number Diff line number Diff line change
@@ -206,22 +206,35 @@ 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 {
InboundMessageV2 memory message =
InboundMessageV2({origin: keccak256("666"), nonce: 1, commands: makeMockCommand()});
bytes32 topic = keccak256("topic");

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

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

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

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

MockGateway(address(gateway)).setCommitmentsAreVerified(false);
vm.expectRevert(IGatewayBase.InvalidProof.selector);
@@ -345,18 +364,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,
@@ -366,6 +388,8 @@ contract GatewayV2Test is Test {
}

function testEncodeDecodeMessageV2() public {
bytes32 topic = bytes32(uint256(1));

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

//From OutboundQueueV2
bytes memory data = abi.encodePacked(
hex"000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000003e80000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000186a000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000060000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000eda338e4dc46038493b885327842fd3e301cab3900000000000000000000000000000000000000000000000000000000000f4240"
hex"000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000003e800000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000186a000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000060000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000eda338e4dc46038493b885327842fd3e301cab3900000000000000000000000000000000000000000000000000000000000f4240"
);
assertEq(data, rawBytes);
InboundMessageV2 memory result = abi.decode(data, (InboundMessageV2));
@@ -392,15 +420,15 @@ contract GatewayV2Test is Test {
function testSubmitRegisterPNA() public {
//From Relayer V2
bytes memory data = abi.encodePacked(
hex"000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000002c000000000000000000000000000000000000000000000000000000000000002e0d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000124f800000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000000209441dceeeffa7e032eedaccf9b7632e60e86711551a82ffbbb0dda8afd9e4ef7000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000020776e6401010101010101010101010101010101010101010101010101010101010000000000000000000000000000000000000000000000000000000000000020776e640101010101010101010101010101010101010101010101010101010101000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000560000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000357fd8184830ac484da672bb9741f2b506f8503a1ac7e1cc48a47e1e0658ff382000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000004bb47b15c3d292b996aa030ac4daa69f9ba4d07bba2846ad786fa9203cd7bba0e00000000000000000000000000000000000000000000000000000000000006200000000000000000000000000000000000000000000000000000000000000435620015748e29b5ddf1606eaa103b741d1b42cb5b6494e00e723415d50a8737f9000000000000000000000000000000000000000000000000000000000000001de0ab0b550176ac143add9e5dad46bf60f3ff09e6910ddcd8cbd0bd95d9af99c458e9af973605f8977d29a97331322ae8b7df3ee387660f4f78c391a8910b06c400000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000001e000000000000000000000000000000000000000000000000000000000000002a00000000000000000000000000000000000000000000000000000000000000006617572610000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000008b1cb3111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004525053520000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000021f2fa13b3689581ab90e8be6189a6a182bc5f18e67b0cd4d634780d57eda5e7abc800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000002100f97fc21a954ee5ce488329357e198fe1842be336d835186429d0d63b50ae6a43000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005617572610000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000040deba90c498fc585fab36e1c5e916453b5bf9b1db0053740f456c8bb3cd319818bae31266b4091b569265cc091096c3759f0a37ab3c3ff47c49db45179454588c0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000002c50ec1a82811ddd645332a2ba5b83d54e4b139cb6cccd8c243fe70ff46ee99107c8edcedf83c0365d02f0f0e81db16f5d26af633b1649447ae6227eb25f2d4d1000000000000000000000000000000000000000000000000000000000000000b4f279cd0d31616f60fbca046ca14d27d8c54183783356e2fde772b3af1ff640dec888d3366c7531cd23f04f924269472d18864602b96b8df7256bd5e13860bc455731c01ace46fb597458f801b25e372e783f539d5b1c4a2e0c1a821fe5338e3ca7022028de5b7152ca06f8f2c9665f08f9352e39863a626c356f01ffa8a56d0a468414d1d507347b97e913fa7ea12775f986069d3fb6a67536e17558485623d17e94f9962a75ef8b0653f508f4374e3ac17c983014d1155c1940a1f0b6facfd7c7665562546908af6e378cae444aa7cc88768e03607261892617aae0bbffe3409335c9382edbf4177711abc4d7918354a70a8c7fba91e8048b303ec2d2d3f23350f3eed8dc9af2607a0642499f364aedebfc250fb5658250702f131c5e866a02e21d45bc6f83c95b520aa8cee188cc3680179d112cc78227897faa8264f8b758bc8264207401f3a9fbc051fcf4f9083b3591c95de65c00175b88eefcc96723f"
hex"000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000003e80000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000124f80000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
);
InboundMessageV2 memory message = abi.decode(data, (InboundMessageV2));
assertEq(message.nonce, 0);
assertEq(message.nonce, 1);
assertEq(message.commands.length, 1);
hoax(relayer, 1 ether);
vm.expectEmit(true, false, false, false);
emit IGatewayBase.ForeignTokenRegistered(
bytes32(0x9441dceeeffa7e032eedaccf9b7632e60e86711551a82ffbbb0dda8afd9e4ef7),
bytes32(0x0000000000000000000000000000000000000000000000000000000000000001),
address(0x7ff9C67c93D9f7318219faacB5c619a773AFeF6A)
);
IGatewayV2(address(gateway)).v2_submit(
@@ -409,15 +437,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,
Loading
Loading