From eb43639bd76b53cefe360b2b18bde4bc77d0a058 Mon Sep 17 00:00:00 2001 From: Foivos <foivos@umich.edu> Date: Tue, 21 Jan 2025 01:39:26 +0200 Subject: [PATCH] fix tests --- .../sources/discovery.move | 8 ++++++ src/common/bcs.ts | 2 +- src/common/types.ts | 3 +++ test/its.js | 18 +++++++++---- test/squid.js | 25 +++++++++++++------ ...nterchain_token_service_chain_tracker.json | 2 +- 6 files changed, 43 insertions(+), 15 deletions(-) diff --git a/move/interchain_token_service/sources/discovery.move b/move/interchain_token_service/sources/discovery.move index 139b65a7..acc6e8be 100644 --- a/move/interchain_token_service/sources/discovery.move +++ b/move/interchain_token_service/sources/discovery.move @@ -30,6 +30,14 @@ public fun interchain_transfer_info( ): (TokenId, address, u64, vector<u8>) { let mut reader = abi::new_reader(payload); assert!( + reader.read_u256() == MESSAGE_TYPE_RECEIVE_FROM_HUB, + EInvalidMessageType, + ); + // Source chain validation is not done here. + reader.skip_slot(); + let payload = reader.read_bytes(); + reader = abi::new_reader(payload); + assert!( reader.read_u256() == MESSAGE_TYPE_INTERCHAIN_TRANSFER, EInvalidMessageType, ); diff --git a/src/common/bcs.ts b/src/common/bcs.ts index 9abc3cc1..b9a47e7d 100644 --- a/src/common/bcs.ts +++ b/src/common/bcs.ts @@ -270,7 +270,7 @@ function getITSStructs() { const InterchainTokenServiceV0 = bcs.struct('InterchainTokenService_v0', { channel: Channel, - address_tracker: InterchainChainTracker, + chain_tracker: InterchainChainTracker, unregistered_coin_types: Table, unregistered_coins: Bag, registered_coin_types: Table, diff --git a/src/common/types.ts b/src/common/types.ts index 57da06be..aa9ffb89 100644 --- a/src/common/types.ts +++ b/src/common/types.ts @@ -23,6 +23,9 @@ export interface Dependency { export enum ITSMessageType { InterchainTokenTransfer = 0, InterchainTokenDeployment = 1, + SendToItsHub = 3, + ReceiveFromItsHub = 4, + RegisdterTokenMetadata = 6, } export enum GatewayMessageType { diff --git a/test/its.js b/test/its.js index c6d7f1f6..370b42f6 100644 --- a/test/its.js +++ b/test/its.js @@ -57,7 +57,7 @@ describe('ITS', () => { // Parameters for Trusted Addresses const trustedSourceChain = 'axelar'; - const trustedSourceAddress = 'hub'; + const trustedSourceAddress = 'hub_address'; const otherChain = 'Avalanche'; async function setupGateway() { @@ -187,7 +187,7 @@ describe('ITS', () => { before(async () => { await setupGateway(); await registerItsTransaction(); - await setupTrustedAddresses(client, deployer, objectIds, deployments, [trustedSourceChain]); + await setupTrustedAddresses(client, deployer, objectIds, deployments, [otherChain]); }); describe('Interchain Token Transfer', () => { @@ -247,10 +247,14 @@ describe('ITS', () => { // Channel ID for the ITS example. This will be encoded in the payload const itsExampleChannelId = await getSingletonChannelId(client, objectIds.singleton); // ITS transfer payload from Ethereum to Sui - const payload = defaultAbiCoder.encode( + let payload = defaultAbiCoder.encode( ['uint256', 'uint256', 'bytes', 'bytes', 'uint256', 'bytes'], [messageType, tokenId, sourceAddress, itsExampleChannelId, amount, data], ); + payload = defaultAbiCoder.encode( + ['uint256', 'string', 'bytes'], + [ITSMessageType.ReceiveFromItsHub, otherChain, payload], + ); const message = { source_chain: trustedSourceChain, @@ -282,7 +286,7 @@ describe('ITS', () => { objectIds.its, objectIds.gateway, objectIds.gasService, - trustedSourceChain, + otherChain, TokenId, gas, '0x', @@ -331,10 +335,14 @@ describe('ITS', () => { const distributor = '0x'; // ITS transfer payload from Ethereum to Sui - const payload = defaultAbiCoder.encode( + let payload = defaultAbiCoder.encode( ['uint256', 'uint256', 'bytes', 'bytes', 'uint256', 'bytes'], [messageType, tokenId, byteName, byteSymbol, decimals, distributor], ); + payload = defaultAbiCoder.encode( + ['uint256', 'string', 'bytes'], + [ITSMessageType.ReceiveFromItsHub, otherChain, payload], + ) const message = { source_chain: trustedSourceChain, diff --git a/test/squid.js b/test/squid.js index bf7836ca..868e9fd3 100644 --- a/test/squid.js +++ b/test/squid.js @@ -51,8 +51,9 @@ describe('Squid', () => { const nonce = 0; // Parameters for Trusted Addresses - const trustedSourceChain = 'Avalanche'; - const trustedSourceAddress = hexlify(randomBytes(20)); + const trustedSourceChain = 'axelar'; + const trustedSourceAddress = 'hub_address'; + const otherChain = 'Avalanche'; const coins = {}; const pools = {}; @@ -228,7 +229,7 @@ describe('Squid', () => { const interchainTransfer = await builder.moveCall({ target: `${deployments.interchain_token_service.packageId}::interchain_token_service::prepare_interchain_transfer`, - arguments: [tokenId, input, trustedSourceChain, '0xadd1', '0x', channel], + arguments: [tokenId, input, otherChain, '0xadd1', '0x', channel], typeArguments: [coins[coinName].type], }); @@ -425,7 +426,7 @@ describe('Squid', () => { await setupGateway(); await registerItsTransaction(); await registerSquidTransaction(); - await setupTrustedAddresses(client, deployer, objectIds, deployments, [trustedSourceAddress], [trustedSourceChain]); + await setupTrustedAddresses(client, deployer, objectIds, deployments, [otherChain]); await new Promise((resolve) => setTimeout(resolve, 1000)); await registerCoin('a'); await giveDeepToSquid(); @@ -441,16 +442,20 @@ describe('Squid', () => { const messageType = ITSMessageType.InterchainTokenTransfer; const tokenId = objectIds.tokenId; - const sourceAddress = trustedSourceAddress; + const sourceAddress = '0x1234'; const destinationAddress = objectIds.itsChannel; // The ITS Channel ID. All ITS messages are sent to this channel const data = swapData; // Channel ID for Squid. This will be encoded in the payload const squidChannelId = objectIds.squidChannel; // ITS transfer payload from Ethereum to Sui - const payload = defaultAbiCoder.encode( + let payload = defaultAbiCoder.encode( ['uint256', 'uint256', 'bytes', 'bytes', 'uint256', 'bytes'], [messageType, tokenId, sourceAddress, squidChannelId, amount, data], ); + payload = defaultAbiCoder.encode( + ['uint256', 'string', 'bytes'], + [ITSMessageType.ReceiveFromItsHub, otherChain, payload], + ) const message = { source_chain: trustedSourceChain, @@ -477,16 +482,20 @@ describe('Squid', () => { const messageType = ITSMessageType.InterchainTokenTransfer; const tokenId = objectIds.tokenId; - const sourceAddress = trustedSourceAddress; + const sourceAddress = '0x1234'; const destinationAddress = objectIds.itsChannel; // The ITS Channel ID. All ITS messages are sent to this channel const data = swapData; // Channel ID for Squid. This will be encoded in the payload const squidChannelId = objectIds.squidChannel; // ITS transfer payload from Ethereum to Sui - const payload = defaultAbiCoder.encode( + let payload = defaultAbiCoder.encode( ['uint256', 'uint256', 'bytes', 'bytes', 'uint256', 'bytes'], [messageType, tokenId, sourceAddress, squidChannelId, amount, data], ); + payload = defaultAbiCoder.encode( + ['uint256', 'string', 'bytes'], + [ITSMessageType.ReceiveFromItsHub, otherChain, payload], + ); const message = { source_chain: trustedSourceChain, diff --git a/test/testdata/interface_interchain_token_service_chain_tracker.json b/test/testdata/interface_interchain_token_service_chain_tracker.json index 42c8c184..028546b2 100644 --- a/test/testdata/interface_interchain_token_service_chain_tracker.json +++ b/test/testdata/interface_interchain_token_service_chain_tracker.json @@ -20,7 +20,7 @@ ], "fields": [ { - "name": "trusted_addresses", + "name": "trusted_chains", "type": "Table<String, TrustedChain>" } ]