diff --git a/move/its/sources/events.move b/move/its/sources/events.move index 77040b0f..26a6ff8c 100644 --- a/move/its/sources/events.move +++ b/move/its/sources/events.move @@ -136,6 +136,8 @@ public(package) fun unregistered_coin_received( use its::coin::COIN; #[test_only] use its::token_id; +#[test_only] +use utils::utils; // ----- // Tests @@ -168,9 +170,7 @@ fun test_interchain_transfer() { amount, &data2, ); - let events = event::events_by_type>(); - - assert!(events.length() == 2); + let events = utils::multiple_events>(2); assert!(events[0].data_hash == data1_hash); assert!(events[1].data_hash == data2_hash); diff --git a/move/its/sources/its.move b/move/its/sources/its.move index 99455494..1fc652dd 100644 --- a/move/its/sources/its.move +++ b/move/its/sources/its.move @@ -323,6 +323,8 @@ use axelar_gateway::channel; use std::string; #[test_only] use abi::abi; +#[test_only] +use utils::utils; // === MESSAGE TYPES === #[test_only] @@ -417,7 +419,7 @@ fun test_register_coin() { let coin_management = its::coin_management::new_locked(); register_coin(&mut its, coin_info, coin_management); - assert!(sui::event::events_by_type>().length() == 1); + utils::single_event>(); sui::test_utils::destroy(its); } @@ -444,7 +446,8 @@ fun test_deploy_remote_interchain_token() { token_id, destination_chain, ); - assert!(sui::event::events_by_type>().length() == 1); + + utils::single_event>(); let mut writer = abi::new_writer(6); @@ -483,7 +486,9 @@ fun test_deploy_interchain_token() { let coin_management = its::coin_management::new_locked(); let token_id = register_coin(&mut its, coin_info, coin_management); - assert!(sui::event::events_by_type>().length() == 1); + + utils::single_event>(); + let amount = 1234; let coin = sui::coin::mint_for_testing(amount, ctx); let destination_chain = ascii::string(b"Chain Name"); @@ -505,7 +510,9 @@ fun test_deploy_interchain_token() { interchain_transfer_ticket, &clock, ); - assert!(sui::event::events_by_type>().length() == 1); + + utils::single_event>(); + let mut writer = abi::new_writer(6); writer @@ -575,7 +582,8 @@ fun test_receive_interchain_transfer() { ); receive_interchain_transfer(&mut its, approved_message, &clock, ctx); - assert!(sui::event::events_by_type>().length() == 1); + + utils::single_event>(); clock.destroy_for_testing(); sui::test_utils::destroy(its); @@ -636,7 +644,8 @@ fun test_receive_interchain_transfer_with_data() { &clock, ctx, ); - assert!(sui::event::events_by_type>().length() == 1); + + utils::single_event>(); assert!(received_source_chain == source_chain); assert!(received_source_address == its_source_address); @@ -684,7 +693,9 @@ fun test_receive_deploy_interchain_token() { ); receive_deploy_interchain_token(&mut its, approved_message); - assert!(sui::event::events_by_type>().length() == 1); + + utils::single_event>(); + clock.destroy_for_testing(); sui::test_utils::destroy(its); } diff --git a/move/utils/sources/utils/utils.move b/move/utils/sources/utils/utils.move index 57cd6edc..979468f1 100644 --- a/move/utils/sources/utils/utils.move +++ b/move/utils/sources/utils/utils.move @@ -29,6 +29,22 @@ public macro fun peel<$T>($data: vector, $peel_fn: |&mut BCS| -> $T): $T { result } +#[test_only] +use sui::event; + +#[test_only] +public fun multiple_events(n: u64): vector { + let events = event::events_by_type(); + assert!(events.length() == n); + events +} + +#[test_only] +public fun single_event(): T { + let events = multiple_events(1); + events[0] +} + #[test] fun peel_bcs_data_succeeds() { let test_bytes = b"test";