Skip to content

Commit

Permalink
fixed some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Foivos committed Jan 20, 2025
1 parent 63beb53 commit 7ac8025
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8> = b"axelar";
#[test_only]
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -579,7 +580,6 @@ fun test_deploy_interchain_token() {
utils::assert_event<interchain_token_service::events::InterchainTransfer<COIN>>();

let mut writer = abi::new_writer(6);

writer
.write_u256(MESSAGE_TYPE_INTERCHAIN_TRANSFER)
.write_u256(token_id.to_u256())
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>, destination_chain: String) {
public(package) fun wrap_payload_sending(self: &InterchainTokenService_v0, payload: &mut vector<u8>, destination_chain: String) {
self.wrap_payload(payload, destination_chain);
}

#[test_only]
public fun wrap_payload_receiving(payload: &mut vector<u8>, 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
// -----
Expand Down
23 changes: 19 additions & 4 deletions move/squid/sources/squid/squid.move
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,17 @@ fun new_version_control(): VersionControl {
])
}

/// ---------
/// Test Only
/// ---------
/// // === HUB CONSTANTS ===
#[test_only]
// Axelar.
const ITS_HUB_CHAIN_NAME: vector<u8> = b"axelar";
#[test_only]
// The address of the ITS HUB.
const ITS_HUB_ADDRESS: vector<u8> = b"hub_address";

#[test_only]
public fun new_for_testing(ctx: &mut TxContext): Squid {
let mut version_control = new_version_control();
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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,
);
Expand Down
19 changes: 15 additions & 4 deletions move/squid/sources/squid/versioned/squid_v0.move
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,17 @@ public(package) fun withdraw<T>(
// ---------
// Test Only
// ---------
/// ---------
/// Test Only
/// ---------
/// // === HUB CONSTANTS ===
#[test_only]
// Axelar.
const ITS_HUB_CHAIN_NAME: vector<u8> = b"axelar";
#[test_only]
// The address of the ITS HUB.
const ITS_HUB_ADDRESS: vector<u8> = b"hub_address";

#[test_only]
public fun new_for_testing(ctx: &mut TxContext): Squid_v0 {
Squid_v0 {
Expand Down Expand Up @@ -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();
Expand All @@ -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,
);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, TrustedChain>"
}
]
}
},
"publicFunctions": {}
}
8 changes: 2 additions & 6 deletions test/testdata/interface_interchain_token_service_events.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"structs": {
"TrustedAddressSet": {
"name": "TrustedAddressSet",
"TrustedAddressAdded": {
"name": "TrustedAddressAdded",
"abilities": [
"copy",
"drop"
Expand All @@ -10,10 +10,6 @@
{
"name": "chain_name",
"type": "String"
},
{
"name": "trusted_address",
"type": "String"
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"type": "Channel"
},
{
"name": "address_tracker",
"type": "InterchainAddressTracker"
"name": "chain_tracker",
"type": "InterchainChainTracker"
},
{
"name": "unregistered_coin_types",
Expand Down

0 comments on commit 7ac8025

Please sign in to comment.