Skip to content

Commit

Permalink
added event finding in utils
Browse files Browse the repository at this point in the history
  • Loading branch information
Foivos committed Nov 20, 2024
1 parent 63075d6 commit f733742
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
6 changes: 3 additions & 3 deletions move/its/sources/events.move
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ public(package) fun unregistered_coin_received<T>(
use its::coin::COIN;
#[test_only]
use its::token_id;
#[test_only]
use utils::utils;

// -----
// Tests
Expand Down Expand Up @@ -168,9 +170,7 @@ fun test_interchain_transfer() {
amount,
&data2,
);
let events = event::events_by_type<InterchainTransfer<COIN>>();

assert!(events.length() == 2);
let events = utils::multiple_events<InterchainTransfer<COIN>>(2);

assert!(events[0].data_hash == data1_hash);
assert!(events[1].data_hash == data2_hash);
Expand Down
25 changes: 18 additions & 7 deletions move/its/sources/its.move
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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<its::events::CoinRegistered<COIN>>().length() == 1);
utils::single_event<its::events::CoinRegistered<COIN>>();

sui::test_utils::destroy(its);
}
Expand All @@ -444,7 +446,8 @@ fun test_deploy_remote_interchain_token() {
token_id,
destination_chain,
);
assert!(sui::event::events_by_type<its::events::InterchainTokenDeploymentStarted<COIN>>().length() == 1);

utils::single_event<its::events::InterchainTokenDeploymentStarted<COIN>>();

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

Expand Down Expand Up @@ -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<its::events::CoinRegistered<COIN>>().length() == 1);

utils::single_event<its::events::CoinRegistered<COIN>>();

let amount = 1234;
let coin = sui::coin::mint_for_testing<COIN>(amount, ctx);
let destination_chain = ascii::string(b"Chain Name");
Expand All @@ -505,7 +510,9 @@ fun test_deploy_interchain_token() {
interchain_transfer_ticket,
&clock,
);
assert!(sui::event::events_by_type<its::events::InterchainTransfer<COIN>>().length() == 1);

utils::single_event<its::events::InterchainTransfer<COIN>>();

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

writer
Expand Down Expand Up @@ -575,7 +582,8 @@ fun test_receive_interchain_transfer() {
);

receive_interchain_transfer<COIN>(&mut its, approved_message, &clock, ctx);
assert!(sui::event::events_by_type<its::events::InterchainTransferReceived<COIN>>().length() == 1);

utils::single_event<its::events::InterchainTransferReceived<COIN>>();

clock.destroy_for_testing();
sui::test_utils::destroy(its);
Expand Down Expand Up @@ -636,7 +644,8 @@ fun test_receive_interchain_transfer_with_data() {
&clock,
ctx,
);
assert!(sui::event::events_by_type<its::events::InterchainTransferReceived<COIN>>().length() == 1);

utils::single_event<its::events::InterchainTransferReceived<COIN>>();

assert!(received_source_chain == source_chain);
assert!(received_source_address == its_source_address);
Expand Down Expand Up @@ -684,7 +693,9 @@ fun test_receive_deploy_interchain_token() {
);

receive_deploy_interchain_token<COIN>(&mut its, approved_message);
assert!(sui::event::events_by_type<its::events::CoinRegistered<COIN>>().length() == 1);

utils::single_event<its::events::CoinRegistered<COIN>>();

clock.destroy_for_testing();
sui::test_utils::destroy(its);
}
Expand Down
16 changes: 16 additions & 0 deletions move/utils/sources/utils/utils.move
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ public macro fun peel<$T>($data: vector<u8>, $peel_fn: |&mut BCS| -> $T): $T {
result
}

#[test_only]
use sui::event;

#[test_only]
public fun multiple_events<T: copy + drop>(n: u64): vector<T> {
let events = event::events_by_type<T>();
assert!(events.length() == n);
events
}

#[test_only]
public fun single_event<T: copy + drop>(): T {
let events = multiple_events<T>(1);
events[0]
}

#[test]
fun peel_bcs_data_succeeds() {
let test_bytes = b"test";
Expand Down

0 comments on commit f733742

Please sign in to comment.