diff --git a/move/interchain_token_service/sources/interchain_token_service.move b/move/interchain_token_service/sources/interchain_token_service.move index db385bf0..43fb4062 100644 --- a/move/interchain_token_service/sources/interchain_token_service.move +++ b/move/interchain_token_service/sources/interchain_token_service.move @@ -405,6 +405,7 @@ const MESSAGE_TYPE_DEPLOY_INTERCHAIN_TOKEN: u256 = 1; const MESSAGE_TYPE_RECEIVE_FROM_HUB: u256 = 4; // === HUB CONSTANTS === +#[test_only] // Axelar. const ITS_HUB_CHAIN_NAME: vector = b"axelar"; #[test_only] @@ -526,7 +527,7 @@ fun test_deploy_remote_interchain_token() { .write_u256((token_decimals as u256)) .write_bytes(vector::empty()); let mut payload = writer.into_bytes(); - its.value!(b"").wrap_payload_for_testing(&mut payload, destination_chain); + its.value!(b"").wrap_payload_sending(&mut payload, destination_chain); assert!(message_ticket.source_id() == its.value!(b"").channel().to_address()); assert!(message_ticket.destination_chain() == ITS_HUB_CHAIN_NAME.to_ascii_string()); @@ -579,7 +580,6 @@ fun test_deploy_interchain_token() { utils::assert_event>(); let mut writer = abi::new_writer(6); - writer .write_u256(MESSAGE_TYPE_INTERCHAIN_TRANSFER) .write_u256(token_id.to_u256()) @@ -588,7 +588,7 @@ fun test_deploy_interchain_token() { .write_u256((amount as u256)) .write_bytes(b""); let mut payload = writer.into_bytes(); - its.value!(b"").wrap_payload_for_testing(&mut payload, destination_chain); + its.value!(b"").wrap_payload_sending(&mut payload, destination_chain); assert!(message_ticket.source_id() == its.value!(b"").channel().to_address()); assert!(message_ticket.destination_chain() == ITS_HUB_CHAIN_NAME.to_ascii_string()); diff --git a/move/interchain_token_service/sources/versioned/interchain_token_service_v0.move b/move/interchain_token_service/sources/versioned/interchain_token_service_v0.move index 76757da4..80810419 100644 --- a/move/interchain_token_service/sources/versioned/interchain_token_service_v0.move +++ b/move/interchain_token_service/sources/versioned/interchain_token_service_v0.move @@ -714,10 +714,19 @@ public(package) fun remove_registered_coin_type_for_testing( } #[test_only] -public(package) fun wrap_payload_for_testing(self: &InterchainTokenService_v0, payload: &mut vector, destination_chain: String) { +public(package) fun wrap_payload_sending(self: &InterchainTokenService_v0, payload: &mut vector, destination_chain: String) { self.wrap_payload(payload, destination_chain); } +#[test_only] +public fun wrap_payload_receiving(payload: &mut vector, source_chain: String) { + let mut writer = abi::new_writer(3); + writer.write_u256(MESSAGE_TYPE_RECEIVE_FROM_HUB); + writer.write_bytes(source_chain.into_bytes()); + writer.write_bytes(*payload); + *payload = writer.into_bytes(); +} + // ----- // Tests // ----- diff --git a/move/squid/sources/squid/squid.move b/move/squid/sources/squid/squid.move index fbd7a4c9..a7f5f1f5 100644 --- a/move/squid/sources/squid/squid.move +++ b/move/squid/sources/squid/squid.move @@ -151,6 +151,17 @@ fun new_version_control(): VersionControl { ]) } +/// --------- +/// Test Only +/// --------- +/// // === HUB CONSTANTS === +#[test_only] +// Axelar. +const ITS_HUB_CHAIN_NAME: vector = b"axelar"; +#[test_only] +// The address of the ITS HUB. +const ITS_HUB_ADDRESS: vector = b"hub_address"; + #[test_only] public fun new_for_testing(ctx: &mut TxContext): Squid { let mut version_control = new_version_control(); @@ -171,6 +182,9 @@ public fun new_for_testing(ctx: &mut TxContext): Squid { #[test_only] use interchain_token_service::coin::COIN; +/// ----- +/// Tests +/// ----- #[test] fun test_start_swap() { let ctx = &mut tx_context::dummy(); @@ -210,7 +224,6 @@ fun test_start_swap() { let source_chain = std::ascii::string(b"Chain Name"); let message_id = std::ascii::string(b"Message Id"); - let message_source_address = std::ascii::string(b"Address"); let its_source_address = b"Source Address"; let destination_address = squid.value!(b"").channel().to_address(); @@ -223,12 +236,14 @@ fun test_start_swap() { .write_bytes(destination_address.to_bytes()) .write_u256((amount as u256)) .write_bytes(data); - let payload = writer.into_bytes(); + + let mut payload = writer.into_bytes(); + interchain_token_service::interchain_token_service_v0::wrap_payload_receiving(&mut payload, source_chain); let approved_message = axelar_gateway::channel::new_approved_message( - source_chain, + ITS_HUB_CHAIN_NAME.to_ascii_string(), message_id, - message_source_address, + ITS_HUB_ADDRESS.to_ascii_string(), its.channel_address(), payload, ); diff --git a/move/squid/sources/squid/versioned/squid_v0.move b/move/squid/sources/squid/versioned/squid_v0.move index a08333a4..fb0e8c57 100644 --- a/move/squid/sources/squid/versioned/squid_v0.move +++ b/move/squid/sources/squid/versioned/squid_v0.move @@ -96,6 +96,17 @@ public(package) fun withdraw( // --------- // Test Only // --------- +/// --------- +/// Test Only +/// --------- +/// // === HUB CONSTANTS === +#[test_only] +// Axelar. +const ITS_HUB_CHAIN_NAME: vector = b"axelar"; +#[test_only] +// The address of the ITS HUB. +const ITS_HUB_ADDRESS: vector = b"hub_address"; + #[test_only] public fun new_for_testing(ctx: &mut TxContext): Squid_v0 { Squid_v0 { @@ -149,7 +160,6 @@ fun test_start_swap() { let source_chain = std::ascii::string(b"Chain Name"); let message_id = std::ascii::string(b"Message Id"); - let message_source_address = std::ascii::string(b"Address"); let its_source_address = b"Source Address"; let destination_address = squid.channel().to_address(); @@ -162,12 +172,13 @@ fun test_start_swap() { .write_bytes(destination_address.to_bytes()) .write_u256((amount as u256)) .write_bytes(data); - let payload = writer.into_bytes(); + let mut payload = writer.into_bytes(); + interchain_token_service::interchain_token_service_v0::wrap_payload_receiving(&mut payload, source_chain); let approved_message = channel::new_approved_message( - source_chain, + ITS_HUB_CHAIN_NAME.to_ascii_string(), message_id, - message_source_address, + ITS_HUB_ADDRESS.to_ascii_string(), its.channel_address(), payload, ); diff --git a/test/testdata/interface_interchain_token_service_chain_tracker.json b/test/testdata/interface_interchain_token_service_chain_tracker.json new file mode 100644 index 00000000..42c8c184 --- /dev/null +++ b/test/testdata/interface_interchain_token_service_chain_tracker.json @@ -0,0 +1,30 @@ +{ + "structs": { + "TrustedChain": { + "name": "TrustedChain", + "abilities": [ + "drop", + "store" + ], + "fields": [ + { + "name": "dummy_field", + "type": "bool" + } + ] + }, + "InterchainChainTracker": { + "name": "InterchainChainTracker", + "abilities": [ + "store" + ], + "fields": [ + { + "name": "trusted_addresses", + "type": "Table" + } + ] + } + }, + "publicFunctions": {} +} diff --git a/test/testdata/interface_interchain_token_service_events.json b/test/testdata/interface_interchain_token_service_events.json index de36422c..4c35d122 100644 --- a/test/testdata/interface_interchain_token_service_events.json +++ b/test/testdata/interface_interchain_token_service_events.json @@ -1,7 +1,7 @@ { "structs": { - "TrustedAddressSet": { - "name": "TrustedAddressSet", + "TrustedAddressAdded": { + "name": "TrustedAddressAdded", "abilities": [ "copy", "drop" @@ -10,10 +10,6 @@ { "name": "chain_name", "type": "String" - }, - { - "name": "trusted_address", - "type": "String" } ] }, diff --git a/test/testdata/interface_interchain_token_service_interchain_token_service_v0.json b/test/testdata/interface_interchain_token_service_interchain_token_service_v0.json index f850013e..a22c0db2 100644 --- a/test/testdata/interface_interchain_token_service_interchain_token_service_v0.json +++ b/test/testdata/interface_interchain_token_service_interchain_token_service_v0.json @@ -11,8 +11,8 @@ "type": "Channel" }, { - "name": "address_tracker", - "type": "InterchainAddressTracker" + "name": "chain_tracker", + "type": "InterchainChainTracker" }, { "name": "unregistered_coin_types",