Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Foivos committed Jan 20, 2025
1 parent 1bf88f1 commit eb43639
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 15 deletions.
8 changes: 8 additions & 0 deletions move/interchain_token_service/sources/discovery.move
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down
2 changes: 1 addition & 1 deletion src/common/bcs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ export interface Dependency {
export enum ITSMessageType {
InterchainTokenTransfer = 0,
InterchainTokenDeployment = 1,
SendToItsHub = 3,
ReceiveFromItsHub = 4,
RegisdterTokenMetadata = 6,
}

export enum GatewayMessageType {
Expand Down
18 changes: 13 additions & 5 deletions test/its.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -282,7 +286,7 @@ describe('ITS', () => {
objectIds.its,
objectIds.gateway,
objectIds.gasService,
trustedSourceChain,
otherChain,
TokenId,
gas,
'0x',
Expand Down Expand Up @@ -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,
Expand Down
25 changes: 17 additions & 8 deletions test/squid.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};

Expand Down Expand Up @@ -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],
});

Expand Down Expand Up @@ -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();
Expand All @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
],
"fields": [
{
"name": "trusted_addresses",
"name": "trusted_chains",
"type": "Table<String, TrustedChain>"
}
]
Expand Down

0 comments on commit eb43639

Please sign in to comment.