From d6a7963d5c5287a6908f79db077edb530d9f9dba Mon Sep 17 00:00:00 2001 From: alexanderliteplo Date: Sun, 12 Jan 2025 14:33:36 -0800 Subject: [PATCH] removing old tests --- examples/oft-move/README.md | 2 + .../internal_oapp/oapp_core_tests.move | 213 ------- .../internal_oapp/oapp_test_helper.move | 12 - .../movement/internal_oft/oft_core_tests.move | 522 ------------------ .../internal_oft/oft_impl_config_tests.move | 220 -------- .../oapp_receive_using_oft_fa_tests.move | 165 ------ .../oft-move/test/movement/oft_fa_tests.move | 458 --------------- .../test/movement/oft_using_oft_fa_tests.move | 305 ---------- 8 files changed, 2 insertions(+), 1895 deletions(-) delete mode 100644 examples/oft-move/test/movement/internal_oapp/oapp_core_tests.move delete mode 100644 examples/oft-move/test/movement/internal_oapp/oapp_test_helper.move delete mode 100644 examples/oft-move/test/movement/internal_oft/oft_core_tests.move delete mode 100644 examples/oft-move/test/movement/internal_oft/oft_impl_config_tests.move delete mode 100644 examples/oft-move/test/movement/oapp_receive_using_oft_fa_tests.move delete mode 100644 examples/oft-move/test/movement/oft_fa_tests.move delete mode 100644 examples/oft-move/test/movement/oft_using_oft_fa_tests.move diff --git a/examples/oft-move/README.md b/examples/oft-move/README.md index d2705fef4..94b5cdd2b 100644 --- a/examples/oft-move/README.md +++ b/examples/oft-move/README.md @@ -124,6 +124,8 @@ Then run the wire command: ```bash pnpm run lz:sdk:evm:wire --oapp-config move.layerzero.config.ts ``` +Troubleshooting: +Sometimes the command will fail part way through and need to be run multiple times. Also running running `pkill anvil` to reset the anvil node can help. For Move-VM: diff --git a/examples/oft-move/test/movement/internal_oapp/oapp_core_tests.move b/examples/oft-move/test/movement/internal_oapp/oapp_core_tests.move deleted file mode 100644 index 1f2f33f36..000000000 --- a/examples/oft-move/test/movement/internal_oapp/oapp_core_tests.move +++ /dev/null @@ -1,213 +0,0 @@ -#[test_only] -module oft::oapp_core_tests { - use std::account::create_account_for_test; - use std::account::create_signer_for_test; - use std::event::was_event_emitted; - use std::fungible_asset::{Self, FungibleAsset}; - use std::option; - use std::signer::address_of; - - use endpoint_v2::channels::packet_sent_event; - use endpoint_v2::messaging_receipt; - use endpoint_v2::test_helpers::setup_layerzero_for_test; - use endpoint_v2_common::bytes32::{Self, from_address, from_bytes32}; - use endpoint_v2_common::guid; - use endpoint_v2_common::native_token_test_helpers::{burn_token_for_test, initialize_native_token_for_test, - mint_native_token_for_test - }; - use endpoint_v2_common::packet_v1_codec; - use oft::oapp_core::{Self, pause_sending_set, set_pause_sending}; - use oft::oapp_store::OAPP_ADDRESS; - use oft::oft_core::{SEND, SEND_AND_CALL}; - - const SRC_EID: u32 = 101; - const DST_EID: u32 = 201; - - fun setup(local_eid: u32, remote_eid: u32) { - // Test the send function - setup_layerzero_for_test(@simple_msglib, local_eid, remote_eid); - let oft_admin = &create_signer_for_test(@oft_admin); - initialize_native_token_for_test(); - oft::oapp_test_helper::init_oapp(); - oapp_core::set_peer(oft_admin, SRC_EID, from_bytes32(from_address(@1234))); - oapp_core::set_peer(oft_admin, DST_EID, from_bytes32(from_address(@4321))); - } - - #[test] - fun test_send_internal() { - setup(SRC_EID, DST_EID); - - let called_send = false; - let called_inspect = false; - assert!(!called_inspect && !called_send, 0); - - let native_fee = mint_native_token_for_test(100000); - let zro_fee = option::none(); - - // pause then unpause (to test to make sure unpause works) - set_pause_sending(&create_signer_for_test(@oft_admin), DST_EID, true); - assert!(was_event_emitted(&pause_sending_set(DST_EID, true)), 0); - - set_pause_sending(&create_signer_for_test(@oft_admin), DST_EID, false); - assert!(was_event_emitted(&pause_sending_set(DST_EID, false)), 0); - - let messaging_receipt = oapp_core::lz_send( - DST_EID, - b"oapp-message", - b"options", - &mut native_fee, - &mut zro_fee, - ); - - let expected_guid = guid::compute_guid( - 1, - SRC_EID, - bytes32::from_address(OAPP_ADDRESS()), - DST_EID, - bytes32::from_address(@4321), - ); - - assert!(messaging_receipt::get_guid(&messaging_receipt) == expected_guid, 0); - - // 0 fees in simple msglib - assert!(messaging_receipt::get_native_fee(&messaging_receipt) == 0, 1); - assert!(messaging_receipt::get_zro_fee(&messaging_receipt) == 0, 1); - // nothing removed - assert!(fungible_asset::amount(&native_fee) == 100000, 0); - - assert!(messaging_receipt::get_nonce(&messaging_receipt) == 1, 2); - - let packet = packet_v1_codec::new_packet_v1( - SRC_EID, - bytes32::from_address(OAPP_ADDRESS()), - DST_EID, - bytes32::from_address(@4321), - 1, - expected_guid, - b"oapp-message", - ); - assert!(was_event_emitted(&packet_sent_event( - packet, - b"options", - @simple_msglib, - )), 0); - - burn_token_for_test(native_fee); - option::destroy_none(zro_fee); - } - - #[test] - #[expected_failure(abort_code = oft::oapp_core::ESEND_PAUSED)] - fun test_send_pause() { - setup(SRC_EID, DST_EID); - set_pause_sending(&create_signer_for_test(@oft_admin), DST_EID, true); - - let called_send = false; - let called_inspect = false; - assert!(!called_inspect && !called_send, 0); - - let native_fee = mint_native_token_for_test(100000); - let zro_fee = option::none(); - - assert!(was_event_emitted(&pause_sending_set(DST_EID, true)), 0); - - oapp_core::lz_send( - DST_EID, - b"oapp-message", - b"options", - &mut native_fee, - &mut zro_fee, - ); - - burn_token_for_test(native_fee); - option::destroy_none(zro_fee); - } - - #[test] - fun test_quote_internal() { - setup(SRC_EID, DST_EID); - - let (native_fee, zro_fee) = oapp_core::lz_quote( - DST_EID, - b"oapp-message", - b"options", - false, - ); - assert!(native_fee == 0, 0); - assert!(zro_fee == 0, 1); - } - - #[test] - fun test_set_enforced_options() { - setup(SRC_EID, DST_EID); - - // setup admin - let oft_admin = &create_signer_for_test(@oft_admin); - let admin = &create_account_for_test(@1111); - oapp_core::transfer_admin(oft_admin, address_of(admin)); - - oapp_core::set_enforced_options(admin, SRC_EID, SEND(), x"0003aaaa"); - oapp_core::set_enforced_options(admin, DST_EID, SEND(), x"0003bbbc"); - oapp_core::set_enforced_options(admin, DST_EID, SEND(), x"000355"); - oapp_core::set_enforced_options(admin, DST_EID, SEND_AND_CALL(), x"000344"); - assert!(oapp_core::get_enforced_options(DST_EID, SEND()) == x"000355", 0); - assert!(oapp_core::get_enforced_options(DST_EID, SEND_AND_CALL()) == x"000344", 0); - assert!(oapp_core::get_enforced_options(SRC_EID, SEND()) == x"0003aaaa", 0); - } - - #[test] - fun test_combine_options() { - setup(SRC_EID, DST_EID); - - // setup admin - let oft_admin = &create_signer_for_test(@oft_admin); - let admin = &create_account_for_test(@1111); - oapp_core::transfer_admin(oft_admin, address_of(admin)); - - let enforced_options = x"0003aaaa"; - let options = x"0003bbbb"; - oapp_core::set_enforced_options(admin, DST_EID, SEND(), enforced_options); - // unrelated option below just to make sure it doesn't get overwritten - oapp_core::set_enforced_options(admin, DST_EID, SEND_AND_CALL(), x"0003235326"); - let combined = oapp_core::combine_options(DST_EID, SEND(), options); - assert!(combined == x"0003aaaabbbb", 0); - } - - #[test] - fun test_peers() { - // Test the send function - setup(SRC_EID, DST_EID); - - // setup admin - let oft_admin = &create_signer_for_test(@oft_admin); - let admin = &create_account_for_test(@1111); - oapp_core::transfer_admin(oft_admin, address_of(admin)); - - assert!(!oapp_core::has_peer(1111), 0); - oapp_core::set_peer(admin, 1111, from_bytes32(from_address(@1234))); - oapp_core::set_peer(admin, 2222, from_bytes32(from_address(@2345))); - assert!(oapp_core::has_peer(1111), 0); - assert!(oapp_core::has_peer(2222), 0); - assert!(oapp_core::get_peer_bytes32(1111) == from_address(@1234), 0); - assert!(oapp_core::get_peer_bytes32(2222) == from_address(@2345), 0); - } - - #[test] - fun test_delegate() { - setup(SRC_EID, DST_EID); - - // setup admin - let oft_admin = &create_signer_for_test(@oft_admin); - let admin = &create_account_for_test(@1111); - oapp_core::transfer_admin(oft_admin, address_of(admin)); - - let delegate = &create_signer_for_test(@2222); - oapp_core::set_delegate(admin, address_of(delegate)); - assert!(oapp_core::get_delegate() == address_of(delegate), 0); - - let delegate2 = &create_signer_for_test(@3333); - oapp_core::set_delegate(admin, address_of(delegate2)); - - oapp_core::skip(delegate2, SRC_EID, from_bytes32(from_address(@1234)), 1); - } -} diff --git a/examples/oft-move/test/movement/internal_oapp/oapp_test_helper.move b/examples/oft-move/test/movement/internal_oapp/oapp_test_helper.move deleted file mode 100644 index 9f0a827dc..000000000 --- a/examples/oft-move/test/movement/internal_oapp/oapp_test_helper.move +++ /dev/null @@ -1,12 +0,0 @@ -#[test_only] -module oft::oapp_test_helper { - use oft::oapp_compose; - use oft::oapp_receive; - use oft::oapp_store; - - public fun init_oapp() { - oapp_store::init_module_for_test(); - oapp_receive::init_module_for_test(); - oapp_compose::init_module_for_test(); - } -} diff --git a/examples/oft-move/test/movement/internal_oft/oft_core_tests.move b/examples/oft-move/test/movement/internal_oft/oft_core_tests.move deleted file mode 100644 index c0cd148be..000000000 --- a/examples/oft-move/test/movement/internal_oft/oft_core_tests.move +++ /dev/null @@ -1,522 +0,0 @@ -#[test_only] -module oft::oft_core_tests { - use std::account::create_signer_for_test; - use std::event::was_event_emitted; - use std::fungible_asset; - use std::fungible_asset::FungibleAsset; - use std::option; - use std::string::utf8; - use std::vector; - - use endpoint_v2::endpoint; - use endpoint_v2::messaging_receipt; - use endpoint_v2::messaging_receipt::new_messaging_receipt_for_test; - use endpoint_v2::test_helpers::setup_layerzero_for_test; - use endpoint_v2_common::bytes32; - use endpoint_v2_common::bytes32::{from_address, from_bytes32}; - use endpoint_v2_common::native_token_test_helpers::{burn_token_for_test, initialize_native_token_for_test, - mint_native_token_for_test - }; - use endpoint_v2_common::packet_v1_codec; - use endpoint_v2_common::packet_v1_codec::compute_payload_hash; - use endpoint_v2_common::zro_test_helpers::create_fa; - use oft::oapp_core; - use oft::oapp_store::OAPP_ADDRESS; - use oft::oft_core::{Self, oft_v1_compatibility_mode_set, SEND, SEND_AND_CALL, set_v1_compatibility_mode}; - use oft::oft_store; - use oft_common::oft_compose_msg_codec; - use oft_common::oft_msg_codec; - use oft_common::oft_v1_msg_codec::{Self, PT_SEND, PT_SEND_AND_CALL}; - - const SRC_EID: u32 = 101; - const DST_EID: u32 = 201; - - fun setup(local_eid: u32, remote_eid: u32) { - // Test the send function - setup_layerzero_for_test(@simple_msglib, local_eid, remote_eid); - let oft_admin = &create_signer_for_test(@oft_admin); - initialize_native_token_for_test(); - let (_, metadata, _) = create_fa(b"ZRO"); - let local_decimals = fungible_asset::decimals(metadata); - oft::oapp_test_helper::init_oapp(); - - oft_store::init_module_for_test(); - oft_core::initialize(local_decimals, 6); - oapp_core::set_peer(oft_admin, SRC_EID, from_bytes32(from_address(@1234))); - oapp_core::set_peer(oft_admin, DST_EID, from_bytes32(from_address(@4321))); - } - - #[test] - fun test_send() { - setup(SRC_EID, DST_EID); - - let user_sender = @99; - let to = bytes32::from_address(@2001); - let native_fee = mint_native_token_for_test(100000); - let zro_fee = option::none(); - let compose_message = b"Hello"; - - let called_send = false; - let called_inspect = false; - assert!(!called_inspect && !called_send, 0); - - // Turn on and off v1 compatibility mode (to test turning off works) - set_v1_compatibility_mode(DST_EID, true); - set_v1_compatibility_mode(DST_EID, false); - - let (messaging_receipt, amount_sent_ld, amount_received_ld) = oft_core::send( - user_sender, - DST_EID, - to, - compose_message, - |message, options| { - called_send = true; - assert!(oft_msg_codec::has_compose(&message), 0); - assert!(oft_msg_codec::sender(&message) == from_address(user_sender), 1); - assert!(oft_msg_codec::send_to(&message) == to, 0); - assert!(oft_msg_codec::amount_sd(&message) == 40, 1); - assert!(options == b"options", 2); - - new_messaging_receipt_for_test( - from_address(@333), - 4, - 1111, - 2222, - ) - }, - |_unused| (5000, 4000), - |_amount_received_ld, _msg_type| b"options", - |message, options| { - called_inspect = true; - assert!(vector::length(message) > 0, 0); - assert!(*options == b"options", 0); - }, - ); - - assert!(called_send, 0); - assert!(called_inspect, 0); - - let (guid, nonce, native_fee_amount, zro_fee_amount) = messaging_receipt::unpack_messaging_receipt( - messaging_receipt, - ); - assert!(guid == from_address(@333), 0); - assert!(nonce == 4, 0); - assert!(native_fee_amount == 1111, 1); - assert!(zro_fee_amount == 2222, 2); - - assert!(amount_sent_ld == 5000, 3); - assert!(amount_received_ld == 4000, 4); - - burn_token_for_test(native_fee); - option::destroy_none(zro_fee); - } - - #[test] - fun test_send_v1_compatibility() { - setup(SRC_EID, DST_EID); - - let user_sender = @99; - let to = bytes32::from_address(@2001); - let native_fee = mint_native_token_for_test(100000); - let zro_fee = option::none(); - - // Compose message not allowed in v1 compatibility mode - let compose_message = b""; - - let called_send = false; - let called_inspect = false; - assert!(!called_inspect && !called_send, 0); - - set_v1_compatibility_mode(DST_EID, true); - assert!(was_event_emitted(&oft_v1_compatibility_mode_set(DST_EID, true)), 1); - - let (messaging_receipt, amount_sent_ld, amount_received_ld) = oft_core::send( - user_sender, - DST_EID, - to, - compose_message, - |message, options| { - called_send = true; - assert!(!oft_v1_msg_codec::has_compose(&message), 0); - assert!(oft_v1_msg_codec::send_to(&message) == to, 0); - assert!(oft_v1_msg_codec::amount_sd(&message) == 40, 1); - assert!(options == b"options", 2); - - new_messaging_receipt_for_test( - from_address(@333), - 4, - 1111, - 2222, - ) - }, - |_unused| (5000, 4000), - |_amount_received_ld, _msg_type| b"options", - |message, options| { - called_inspect = true; - assert!(vector::length(message) > 0, 0); - assert!(*options == b"options", 0); - }, - ); - - assert!(called_send, 0); - assert!(called_inspect, 0); - - let (guid, nonce, native_fee_amount, zro_fee_amount) = messaging_receipt::unpack_messaging_receipt( - messaging_receipt, - ); - assert!(guid == from_address(@333), 0); - assert!(nonce == 4, 0); - assert!(native_fee_amount == 1111, 1); - assert!(zro_fee_amount == 2222, 2); - - assert!(amount_sent_ld == 5000, 3); - assert!(amount_received_ld == 4000, 4); - - burn_token_for_test(native_fee); - option::destroy_none(zro_fee); - } - - #[test] - fun test_receive() { - setup(DST_EID, SRC_EID); - - let called_inspect = false; - assert!(!called_inspect, 0); - - let nonce = 1; - let guid = bytes32::from_address(@23498213432414324); - - let called_credit = false; - assert!(!called_credit, 1); - - let message = oft_msg_codec::encode( - bytes32::from_address(@0x2000), - 123, - bytes32::from_address(@0x3000), - b"", - ); - let sender = bytes32::from_address(@1234); - - endpoint::verify( - @simple_msglib, - packet_v1_codec::new_packet_v1_header_only_bytes( - SRC_EID, - sender, - DST_EID, - bytes32::from_address(OAPP_ADDRESS()), - nonce, - ), - bytes32::from_bytes32(compute_payload_hash(guid, message)), - ); - - oft_core::receive( - SRC_EID, - nonce, - guid, - message, - |_to, _index, _message| { - // should not be called - assert!(false, 0); - }, - |to_address, message_amount| { - called_credit = true; - - assert!(to_address == @0x2000, 0); - // Add 2 0s for (8 local decimals - 6 shared decimals) - assert!(message_amount == 12300, 1); - - 5000 - }, - ); - - assert!(called_credit, 2); - - assert!(was_event_emitted(&oft_core::oft_received_event( - from_bytes32(guid), - SRC_EID, - @0x2000, - 5000, - )), 3); - } - - #[test] - fun test_receive_v1() { - setup(DST_EID, SRC_EID); - set_v1_compatibility_mode(SRC_EID, true); - - let called_inspect = false; - assert!(!called_inspect, 0); - - let nonce = 1; - let guid = bytes32::from_address(@23498213432414324); - - let called_credit = false; - assert!(!called_credit, 1); - - let message = oft_v1_msg_codec::encode( - PT_SEND(), - bytes32::from_address(@0x2000), - 123, - bytes32::from_address(@0x3000), - 0, - b"", - ); - let sender = bytes32::from_address(@1234); - - - endpoint::verify( - @simple_msglib, - packet_v1_codec::new_packet_v1_header_only_bytes( - SRC_EID, - sender, - DST_EID, - bytes32::from_address(OAPP_ADDRESS()), - nonce, - ), - bytes32::from_bytes32(compute_payload_hash(guid, message)), - ); - - oft_core::receive( - SRC_EID, - nonce, - guid, - message, - |_to, _index, _message| { - // should not be called - assert!(false, 0); - }, - |to_address, message_amount| { - called_credit = true; - - assert!(to_address == @0x2000, 0); - // Add 2 0s for (8 local decimals - 6 shared decimals) - assert!(message_amount == 12300, 1); - - 5000 - }, - ); - - assert!(called_credit, 2); - - assert!(was_event_emitted(&oft_core::oft_received_event( - from_bytes32(guid), - SRC_EID, - @0x2000, - 5000, - )), 3); - } - - #[test] - fun test_receive_with_compose() { - setup(DST_EID, SRC_EID); - set_v1_compatibility_mode(SRC_EID, true); - - let called_inspect = false; - assert!(!called_inspect, 0); - - let nonce = 1; - let guid = bytes32::from_address(@23498213432414324); - - let called_credit = 0; - assert!(called_credit == 0, 1); - - - let message = oft_v1_msg_codec::encode( - PT_SEND_AND_CALL(), - bytes32::from_address(@0x2000), - 123, - bytes32::from_address(@0x3000), - 50, - b"Hello", - ); - - // Composer must be registered - let to_address_account = &create_signer_for_test(@0x2000); - endpoint::register_composer(to_address_account, utf8(b"oft")); - - let sender = bytes32::from_address(@1234); - - endpoint::verify( - @simple_msglib, - packet_v1_codec::new_packet_v1_header_only_bytes( - SRC_EID, - sender, - DST_EID, - bytes32::from_address(OAPP_ADDRESS()), - nonce, - ), - bytes32::from_bytes32(compute_payload_hash(guid, message)), - ); - - let called_compose = 0; - assert!(called_compose == 0, 0); - - oft_core::receive( - SRC_EID, - nonce, - guid, - message, - |to, index, message| { - called_compose = called_compose + 1; - assert!(to == @0x2000, 0); - assert!(index == 0, 1); - assert!(oft_compose_msg_codec::compose_payload_message(&message) == b"Hello", 2); - }, - |to_address, message_amount| { - called_credit = called_credit + 1; - - assert!(to_address == @0x2000, 0); - // Add 2 0s for (8 local decimals - 6 shared decimals) - assert!(message_amount == 12300, 1); - 12300 // message_amount - }, - ); - - assert!(called_compose == 1, 0); - assert!(called_credit == 1, 2); - - assert!(was_event_emitted(&oft_core::oft_received_event( - from_bytes32(guid), - SRC_EID, - @0x2000, - 12300, - )), 3); - } - - #[test] - fun test_receive_with_compose_v1() { - setup(DST_EID, SRC_EID); - - let called_inspect = false; - assert!(!called_inspect, 0); - - let nonce = 1; - let guid = bytes32::from_address(@23498213432414324); - - let called_credit = 0; - assert!(called_credit == 0, 1); - - - let message = oft_msg_codec::encode( - bytes32::from_address(@0x2000), - 123, - bytes32::from_address(@0x3000), - b"Hello", - ); - - // Composer must be registered - let to_address_account = &create_signer_for_test(@0x2000); - endpoint::register_composer(to_address_account, utf8(b"oft")); - - let sender = bytes32::from_address(@1234); - - endpoint::verify( - @simple_msglib, - packet_v1_codec::new_packet_v1_header_only_bytes( - SRC_EID, - sender, - DST_EID, - bytes32::from_address(OAPP_ADDRESS()), - nonce, - ), - bytes32::from_bytes32(compute_payload_hash(guid, message)), - ); - - let called_compose = 0; - assert!(called_compose == 0, 0); - - oft_core::receive( - SRC_EID, - nonce, - guid, - message, - |to, index, message| { - called_compose = called_compose + 1; - assert!(to == @0x2000, 0); - assert!(index == 0, 1); - assert!(oft_compose_msg_codec::compose_payload_message(&message) == b"Hello", 2); - }, - |to_address, message_amount| { - called_credit = called_credit + 1; - - assert!(to_address == @0x2000, 0); - // Add 2 0s for (8 local decimals - 6 shared decimals) - assert!(message_amount == 12300, 1); - 12300 // message_amount - }, - ); - - assert!(called_compose == 1, 0); - assert!(called_credit == 1, 2); - - assert!(was_event_emitted(&oft_core::oft_received_event( - from_bytes32(guid), - SRC_EID, - @0x2000, - 12300, - )), 3); - } - - - #[test] - fun test_no_fee_debit_view() { - setup(SRC_EID, DST_EID); - - let (sent, received) = oft_core::no_fee_debit_view(123456789, 200); - assert!(sent == received, 0); - // dust removed (last 2 digits cleared) - assert!(sent == 123456700, 1); - } - - #[test] - #[expected_failure(abort_code = oft::oft_core::ESLIPPAGE_EXCEEDED)] - fun test_no_fee_debit_view_fails_if_post_dust_remove_less_than_min() { - setup(SRC_EID, DST_EID); - - oft_core::no_fee_debit_view(99, 20); - } - - #[test] - fun test_encode_oft_msg() { - setup(SRC_EID, DST_EID); - - let (encoded, message_type) = oft_core::encode_oft_msg( - @0x12345678, - 123, - bytes32::from_address(@0x2000), - b"Hello", - ); - - assert!(message_type == SEND_AND_CALL(), 0); - - let expected_encoded = oft_msg_codec::encode( - bytes32::from_address(@0x2000), - // dust removed and SD - 1, - bytes32::from_address(@0x12345678), - b"Hello", - ); - - assert!(encoded == expected_encoded, 1); - - // without compose - let (encoded, message_type) = oft_core::encode_oft_msg( - @0x12345678, - 123, - bytes32::from_address(@0x2000), - b"", - ); - - assert!(message_type == SEND(), 2); - - let expected_encoded = oft_msg_codec::encode( - bytes32::from_address(@0x2000), - // dust removed and SD - 1, - bytes32::from_address(@0x12345678), - b"", - ); - - assert!(encoded == expected_encoded, 1); - } -} \ No newline at end of file diff --git a/examples/oft-move/test/movement/internal_oft/oft_impl_config_tests.move b/examples/oft-move/test/movement/internal_oft/oft_impl_config_tests.move deleted file mode 100644 index e4dc78a71..000000000 --- a/examples/oft-move/test/movement/internal_oft/oft_impl_config_tests.move +++ /dev/null @@ -1,220 +0,0 @@ -#[test_only] -module oft::oft_impl_config_tests { - use std::string::utf8; - use std::vector; - use aptos_framework::event::was_event_emitted; - - use oft::oapp_store; - use oft::oft_core; - use oft::oft_impl_config::{ - Self, - assert_not_blocklisted, - blocked_amount_redirected_event, - debit_view_with_possible_fee, - fee_details_with_possible_fee, - fee_bps, - has_rate_limit, - in_flight_at_timestamp, - rate_limit_capacity_at_timestamp, - rate_limit_config, - rate_limit_set_event, - rate_limit_updated_event, - redirect_to_admin_if_blocklisted, - release_rate_limit_capacity, - set_blocklist, set_fee_bps, try_consume_rate_limit_capacity_at_timestamp, unset_rate_limit, - }; - use oft::oft_store; - use oft_common::oft_fee_detail; - - const MAX_U64: u64 = 0xffffffffffffffff; - - fun setup() { - oapp_store::init_module_for_test(); - oft_store::init_module_for_test(); - oft_impl_config::init_module_for_test(); - oft_core::initialize(8, 6); - } - - #[test] - fun test_set_fee_bps() { - setup(); - - // Set the fee to 10% - let fee_bps = 1000; - set_fee_bps(fee_bps); - assert!(fee_bps() == fee_bps, 1); - - let (sent, received) = debit_view_with_possible_fee(1234, 1000); - // Send amount should include dust if there is a fee - assert!(sent == 1234, 1); - // Received amount should be 90% of the sent amount with dust removed: 1234 - 120 = 1114 => 1100 (dust removed) - assert!(received == 1100, 2); - - let fee_details = fee_details_with_possible_fee(1234, 1000); - assert!(vector::length(&fee_details) == 1, 1); - let (fee, is_reward) = oft_fee_detail::fee_amount_ld(vector::borrow(&fee_details, 0)); - assert!(fee == 134, 1); - assert!(is_reward == false, 2); - assert!(oft_fee_detail::description(vector::borrow(&fee_details, 0)) == utf8(b"OFT Fee"), 2); - - // Set the fee to 0% - let fee_bps = 0; - set_fee_bps(fee_bps); - - let (sent, received) = debit_view_with_possible_fee(1234, 1000); - // Sent and amount should be 100% of the amount with dust removed with no fee: 1234 => 1200 (dust removed) - assert!(sent == 1200, 3); - assert!(received == 1200, 4); - - // Expect no fee details if there is no fee - let fee_details = fee_details_with_possible_fee(1234, 1000); - assert!(vector::length(&fee_details) == 0, 1); - } - - #[test] - #[expected_failure(abort_code = oft::oft_impl_config::EINVALID_FEE)] - fun test_set_fee_bps_invalid() { - setup(); - - // Set the fee to 101% - let fee_bps = 10100; - set_fee_bps(fee_bps); - } - - #[test] - fun test_set_blocklist() { - setup(); - - assert!(oft_impl_config::is_blocklisted(@0x1234) == false, 1); - assert_not_blocklisted(@0x1234); - let redirected_address = redirect_to_admin_if_blocklisted(@0x1234, 1111); - assert!(redirected_address == @0x1234, 2); - - set_blocklist(@0x1234, true); - assert!(oft_impl_config::is_blocklisted(@0x1234), 1); - let redirected_address = redirect_to_admin_if_blocklisted(@0x1234, 1111); - assert!(redirected_address == @oft_admin, 2); - assert!(was_event_emitted(&blocked_amount_redirected_event(1111, @0x1234, @oft_admin)), 3); - } - - #[test] - #[expected_failure(abort_code = oft::oft_impl_config::EADDRESS_BLOCKED)] - fun test_assert_not_blocked() { - setup(); - - set_blocklist(@0x1234, true); - assert_not_blocklisted(@0x1234); - } - - #[test] - fun set_rate_limit() { - setup(); - - // No rate limit configured - assert!(has_rate_limit(30100) == false, 2); - let (limit, window) = rate_limit_config(30100); - assert!(limit == 0 && window == 0, 1); - assert!(in_flight_at_timestamp(30100, 10) == 0, 1); - assert!(rate_limit_capacity_at_timestamp(30100, 10) == MAX_U64, 2); - - // Configure rate limit (200/second) - oft_impl_config::set_rate_limit_at_timestamp(30100, 20000, 1000, 100); - assert!(was_event_emitted(&rate_limit_set_event(30100, 20000, 1000)), 1); - assert!(has_rate_limit(30100) == true, 2); - assert!(has_rate_limit(30200) == false, 2); // Different eid - let (limit, window) = rate_limit_config(30100); - assert!(limit == 20000 && window == 1000, 1); - assert!(in_flight_at_timestamp(30100, 100) == 0, 1); - assert!(rate_limit_capacity_at_timestamp(30100, 100) == 20000, 2); - - // 100 seconds later - assert!(in_flight_at_timestamp(30100, 200) == 0, 1); - assert!(rate_limit_capacity_at_timestamp(30100, 200) == 20000, 2); - - // consume 10% of the capacity - try_consume_rate_limit_capacity_at_timestamp(30100, 2000, 200); - assert!(in_flight_at_timestamp(30100, 200) == 2000, 1); - assert!(rate_limit_capacity_at_timestamp(30100, 200) == 18000, 2); - - // 10 seconds later: in flight should decline by 20000/1000s * 10s = 200 - assert!(in_flight_at_timestamp(30100, 210) == 1800, 1); - assert!(rate_limit_capacity_at_timestamp(30100, 210) == 18200, 2); - - // 20 seconds later: in flight should decline by 20000/1000s * 20s = 400 - assert!(in_flight_at_timestamp(30100, 220) == 1600, 1); - assert!(rate_limit_capacity_at_timestamp(30100, 220) == 18400, 2); - - // update rate limit (300/second) - oft_impl_config::set_rate_limit_at_timestamp(30100, 30000, 1000, 220); - assert!(was_event_emitted(&rate_limit_updated_event(30100, 30000, 1000)), 1); - // in flight shouldn't change, but capacity should be updated with the new limit in mind - assert!(in_flight_at_timestamp(30100, 220) == 1600, 1); - assert!(rate_limit_capacity_at_timestamp(30100, 220) == 28400, 2); - - // 10 seconds later: in flight should decline by 30000/1000s * 10s = 300 - assert!(in_flight_at_timestamp(30100, 230) == 1300, 1); - assert!(rate_limit_capacity_at_timestamp(30100, 230) == 28700, 2); - - // 10 seconds later: in flight should decline by 30000/1000s * 10s = 300 - assert!(in_flight_at_timestamp(30100, 240) == 1000, 1); - assert!(rate_limit_capacity_at_timestamp(30100, 240) == 29000, 2); - - // 100 seconds later: in flight should decline fully (without overshooting): 30000/1000s * 100s = 3000 - assert!(in_flight_at_timestamp(30100, 300) == 0, 1); - assert!(rate_limit_capacity_at_timestamp(30100, 300) == 30000, 2); - - // Consume again - try_consume_rate_limit_capacity_at_timestamp(30100, 2000, 300); - try_consume_rate_limit_capacity_at_timestamp(30100, 2000, 310); - // 2000 + (2000 - 30000/1000*10) = 3800 - assert!(in_flight_at_timestamp(30100, 310) == 3700, 1); - - // Unset rate limit - unset_rate_limit(30100); - assert!(has_rate_limit(30100) == false, 2); - let (limit, window) = rate_limit_config(30100); - assert!(limit == 0 && window == 0, 1); - assert!(in_flight_at_timestamp(30100, 320) == 0, 1); - assert!(rate_limit_capacity_at_timestamp(30100, 320) == MAX_U64, 2); - } - - #[test] - fun set_rate_limit_net() { - setup(); - - // No rate limit configured - assert!(has_rate_limit(30100) == false, 2); - let (limit, window) = rate_limit_config(30100); - assert!(limit == 0 && window == 0, 1); - assert!(in_flight_at_timestamp(30100, 10) == 0, 1); - assert!(rate_limit_capacity_at_timestamp(30100, 10) == MAX_U64, 2); - - // Configure rate limit (200/second) - oft_impl_config::set_rate_limit_at_timestamp(30100, 20000, 1000, 100); - assert!(has_rate_limit(30100) == true, 2); - - // consume 100% of the capacity - try_consume_rate_limit_capacity_at_timestamp(30100, 20000, 0); - assert!(in_flight_at_timestamp(30100, 0) == 20000, 1); - assert!(rate_limit_capacity_at_timestamp(30100, 0) == 0, 2); - - // 50 seconds later: in flight should decline by 20000/1000s * 500s = 10000 - assert!(in_flight_at_timestamp(30100, 500) == 10000, 1); - assert!(rate_limit_capacity_at_timestamp(30100, 500) == 10000, 2); - - // release most of remaining capacity - release_rate_limit_capacity(30100, 9000); - assert!(in_flight_at_timestamp(30100, 500) == 1000, 1); - assert!(rate_limit_capacity_at_timestamp(30100, 500) == 19000, 2); - - // consume all of remaining capacity - try_consume_rate_limit_capacity_at_timestamp(30100, 19000, 500); - assert!(in_flight_at_timestamp(30100, 500) == 20000, 1); - assert!(rate_limit_capacity_at_timestamp(30100, 500) == 0, 2); - - // release excess capacity (5x limit) - should not overshoot - release_rate_limit_capacity(30100, 100_000); - assert!(in_flight_at_timestamp(30100, 500) == 0, 1); - assert!(rate_limit_capacity_at_timestamp(30100, 500) == 20000, 2); - } -} diff --git a/examples/oft-move/test/movement/oapp_receive_using_oft_fa_tests.move b/examples/oft-move/test/movement/oapp_receive_using_oft_fa_tests.move deleted file mode 100644 index b6160c030..000000000 --- a/examples/oft-move/test/movement/oapp_receive_using_oft_fa_tests.move +++ /dev/null @@ -1,165 +0,0 @@ -#[test_only] -module oft::oapp_receive_using_oft_fa_tests { - use std::account::create_signer_for_test; - use std::event::was_event_emitted; - use std::string::utf8; - - use endpoint_v2::endpoint; - use endpoint_v2::test_helpers::setup_layerzero_for_test; - use endpoint_v2_common::bytes32::{Self, from_address, from_bytes32}; - use endpoint_v2_common::native_token_test_helpers::initialize_native_token_for_test; - use endpoint_v2_common::packet_v1_codec::{Self, compute_payload_hash}; - use oft::oapp_core; - use oft::oapp_receive; - use oft::oapp_store::OAPP_ADDRESS; - use oft::oft_core; - use oft::oft_impl; - use oft::oft_impl_config; - use oft::oft_store; - use oft_common::oft_compose_msg_codec; - use oft_common::oft_msg_codec; - - const SRC_EID: u32 = 101; - const DST_EID: u32 = 201; - - fun setup(local_eid: u32, remote_eid: u32) { - // Test the send function - setup_layerzero_for_test(@simple_msglib, local_eid, remote_eid); - let oft_admin = &create_signer_for_test(@oft_admin); - initialize_native_token_for_test(); - oft::oapp_test_helper::init_oapp(); - - oft_store::init_module_for_test(); - oft_impl_config::init_module_for_test(); - oft_impl::init_module_for_test(); - oft_impl::initialize( - &create_signer_for_test(@oft_admin), - b"My Test Token", - b"MYT", - b"", - b"", - 6, - 8, - ); - oapp_core::set_peer(oft_admin, SRC_EID, from_bytes32(from_address(@1234))); - oapp_core::set_peer(oft_admin, DST_EID, from_bytes32(from_address(@4321))); - } - - #[test] - fun test_receive() { - setup(DST_EID, SRC_EID); - - let called_inspect = false; - assert!(!called_inspect, 0); - - let nonce = 1; - let guid = bytes32::from_address(@23498213432414324); - - let message = oft_msg_codec::encode( - bytes32::from_address(@0x2000), - 123, - bytes32::from_address(@0x3000), - b"", - ); - let sender = bytes32::from_address(@1234); - - endpoint::verify( - @simple_msglib, - packet_v1_codec::new_packet_v1_header_only_bytes( - SRC_EID, - sender, - DST_EID, - bytes32::from_address(OAPP_ADDRESS()), - nonce, - ), - bytes32::from_bytes32(compute_payload_hash(guid, message)), - ); - - - oapp_receive::lz_receive( - SRC_EID, - from_bytes32(sender), - nonce, - from_bytes32(guid), - message, - b"", - ); - - assert!(was_event_emitted(&oft_core::oft_received_event( - from_bytes32(guid), - SRC_EID, - @0x2000, - 12300, - )), 3); - } - - #[test] - fun test_receive_with_compose() { - setup(DST_EID, SRC_EID); - - let called_inspect = false; - assert!(!called_inspect, 0); - - let nonce = 1; - let guid = bytes32::from_address(@23498213432414324); - - let message = oft_msg_codec::encode( - bytes32::from_address(@0x2000), - 123, - bytes32::from_address(@0x3000), - b"Hello", - ); - - // Composer must be registered - let to_address_account = &create_signer_for_test(@0x2000); - endpoint::register_composer(to_address_account, utf8(b"composer")); - - let sender = bytes32::from_address(@1234); - - endpoint::verify( - @simple_msglib, - packet_v1_codec::new_packet_v1_header_only_bytes( - SRC_EID, - sender, - DST_EID, - bytes32::from_address(OAPP_ADDRESS()), - nonce, - ), - bytes32::from_bytes32(compute_payload_hash(guid, message)), - ); - - - oapp_receive::lz_receive( - SRC_EID, - from_bytes32(sender), - nonce, - from_bytes32(guid), - message, - b"", - ); - - assert!(was_event_emitted(&oft_core::oft_received_event( - from_bytes32(guid), - SRC_EID, - @0x2000, - 12300, - )), 3); - - let compose_message_part = oft_msg_codec::compose_payload(&message); - let expected_compose_message = oft_compose_msg_codec::encode( - nonce, - SRC_EID, - 12300, - compose_message_part, - ); - - // Compose Triggered to the same address - assert!(was_event_emitted(&endpoint_v2::messaging_composer::compose_sent_event( - OAPP_ADDRESS(), - @0x2000, - from_bytes32(guid), - 0, - expected_compose_message, - )), 0); - } -} \ No newline at end of file diff --git a/examples/oft-move/test/movement/oft_fa_tests.move b/examples/oft-move/test/movement/oft_fa_tests.move deleted file mode 100644 index e33bce426..000000000 --- a/examples/oft-move/test/movement/oft_fa_tests.move +++ /dev/null @@ -1,458 +0,0 @@ -#[test_only] -module oft::oft_fa_tests { - use std::account::{create_account_for_test, create_signer_for_test}; - use std::event::was_event_emitted; - use std::fungible_asset::{Self, Metadata}; - use std::object::address_to_object; - use std::option; - use std::primary_fungible_store; - use std::string::utf8; - use std::timestamp; - use std::vector; - - use endpoint_v2::test_helpers::setup_layerzero_for_test; - use endpoint_v2_common::bytes32; - use endpoint_v2_common::native_token_test_helpers::{burn_token_for_test, mint_native_token_for_test}; - use oft::oapp_core; - use oft::oft_impl::{ - Self, fee_bps, fee_deposit_address, is_blocklisted, mint_tokens_for_test, set_fee_bps, set_fee_deposit_address, - }; - use oft::oft_impl_config; - use oft::oft_store; - use oft_common::oft_limit::new_unbounded_oft_limit; - - const MAXU64: u64 = 0xffffffffffffffff; - - const LOCAL_EID: u32 = 101; - - fun setup() { - setup_layerzero_for_test(@simple_msglib, LOCAL_EID, LOCAL_EID); - - oft::oapp_test_helper::init_oapp(); - - oft_store::init_module_for_test(); - oft_impl::init_module_for_test(); - oft_impl_config::init_module_for_test(); - oft_impl::initialize( - &create_signer_for_test(@oft_admin), - b"My Test Token", - b"MYT", - b"https://example.com/icon.png", - b"https://example.com/project", - 6, - 8, - ); - - assert!(fungible_asset::name(oft::oft::metadata()) == utf8(b"My Test Token"), 0); - assert!(fungible_asset::symbol(oft::oft::metadata()) == utf8(b"MYT"), 0); - assert!(fungible_asset::icon_uri(oft::oft::metadata()) == utf8(b"https://example.com/icon.png"), 0); - assert!(fungible_asset::project_uri(oft::oft::metadata()) == utf8(b"https://example.com/project"), 0); - assert!(fungible_asset::decimals(oft::oft::metadata()) == 8, 0); - } - - #[test] - fun test_debit() { - setup(); - - let dst_eid = 2u32; - // This configuration function (debit) is not resposible for handling dust, therefore the tested amount excludes - // the dust amount (last two digits) - let amount_ld = 123456700; - let min_amount_ld = 0u64; - - let fa = mint_tokens_for_test(amount_ld); - let (sent, received) = oft_impl::debit_fungible_asset( - @444, - &mut fa, - min_amount_ld, - dst_eid, - ); - - // amount sent and received should reflect the amount debited - assert!(sent == 123456700, 0); - assert!(received == 123456700, 0); - - // no remaining balance - let remaining_balance = fungible_asset::amount(&fa); - assert!(remaining_balance == 00, 0); - burn_token_for_test(fa); - } - - #[test] - fun test_credit() { - setup(); - - let amount_ld = 123456700; - let lz_receive_value = option::none(); - let src_eid = 12345; - - let to = @555; - create_account_for_test(to); - - // 0 balance before crediting - let balance = primary_fungible_store::balance(to, oft_impl::metadata()); - assert!(balance == 0, 0); - - let credited = oft_impl::credit( - to, - amount_ld, - src_eid, - lz_receive_value, - ); - // amount credited should reflect the amount credited - assert!(credited == 123456700, 0); - - // balance should appear in account - let balance = primary_fungible_store::balance(to, oft_impl::metadata()); - assert!(balance == 123456700, 0); - } - - #[test] - fun test_credit_with_extra_lz_receive_drop() { - setup(); - - let amount_ld = 123456700; - let lz_receive_value = option::some(mint_native_token_for_test(100)); - let src_eid = 12345; - - let to = @555; - create_account_for_test(to); - - // 0 balance before crediting - let balance = primary_fungible_store::balance(to, oft_impl::metadata()); - assert!(balance == 0, 0); - - oft_impl::credit( - to, - amount_ld, - src_eid, - lz_receive_value, - ); - - let native_token_metadata = address_to_object(@native_token_metadata_address); - assert!(primary_fungible_store::balance(@oft_admin, native_token_metadata) == 100, 1) - } - - #[test] - fun test_debit_view() { - setup(); - - // shouldn't take a fee - let (sent, received) = oft_impl::debit_view(123456700, 100, 2); - assert!(sent == 123456700, 0); - assert!(received == 123456700, 0); - } - - #[test] - #[expected_failure(abort_code = oft::oft_core::ESLIPPAGE_EXCEEDED)] - fun test_debit_view_fails_if_less_than_min() { - setup(); - - oft_impl::debit_view(32, 100, 2); - } - - #[test] - fun test_build_options() { - setup(); - let dst_eid = 103; - - let message_type = 2; - - let options = oft_impl::build_options( - message_type, - dst_eid, - // OKAY that it's not type 3 if no enforced options are set - x"1234", - @123, - 123324, - bytes32::from_address(@444), - x"8888", - x"34" - ); - // should pass through the options if none configured - assert!(options == x"1234", 0); - - let oft_admin = &create_signer_for_test(@oft_admin); - oapp_core::set_enforced_options( - oft_admin, - dst_eid, - message_type, - x"00037777" - ); - - let options = oft_impl::build_options( - message_type, - dst_eid, - x"00031234", - @123, - 123324, - bytes32::from_address(@444), - x"8888", - x"34" - ); - - // should append to configured options - assert!(options == x"000377771234", 0); - } - - #[test] - fun test_inspect_message() { - // doesn't do anything, just tests that it doesn't fail - oft_impl::inspect_message( - &x"1234", - &x"1234", - true, - ); - } - - #[test] - fun test_oft_limit_and_fees() { - setup(); - - timestamp::set_time_has_started_for_testing(&create_signer_for_test(@std)); - let (limit, fees) = oft_impl::oft_limit_and_fees( - 123, - x"1234", - 123, - 100, - x"1234", - x"1234", - x"1234" - ); - - // always unbounded and empty for this oft configuration - assert!(limit == new_unbounded_oft_limit(), 0); - assert!(vector::length(&fees) == 0, 0); - } - - #[test] - fun test_set_fee_bps() { - setup(); - - let oft_admin = &create_signer_for_test(@oft_admin); - let fee_bps = 500; // 5% - - set_fee_bps( - oft_admin, - fee_bps, - ); - - let fee_bps_result = fee_bps(); - assert!(fee_bps_result == fee_bps, 0); - - let (oft_limit, oft_fee_details) = oft_impl::oft_limit_and_fees( - 123, - x"1234", - 100_000_000, - 100, - x"1234", - x"1234", - x"1234" - ); - - // Check fee detail - assert!(vector::length(&oft_fee_details) == 1, 1); - let fee_detail = *vector::borrow(&oft_fee_details, 0); - let (fee_amount, is_reward) = oft_common::oft_fee_detail::fee_amount_ld(&fee_detail); - assert!(fee_amount == 5_000_000, 2); - assert!(is_reward == false, 3); - - // Check limit - assert!(oft_limit == new_unbounded_oft_limit(), 4); - - let deposit_address = @5555; - create_account_for_test(deposit_address); - set_fee_deposit_address( - oft_admin, - deposit_address, - ); - assert!(fee_deposit_address() == @5555, 1); - - // debit with fee - let dst_eid = 2u32; - // This configuration function (debit) is not resposible for handling dust, therefore the tested amount excludes - // the dust amount (last two digits) - let amount_ld = 123456700; - let min_amount_ld = 0u64; - - let fa = mint_tokens_for_test(amount_ld); - let (sent, received) = oft_impl::debit_fungible_asset( - @444, - &mut fa, - min_amount_ld, - dst_eid, - ); - - // amount sent and received should reflect the amount debited - assert!(sent == 123456700, 0); - // Any dust is also included in the fee - assert!(received == 117283800, 0); // 123456700 * 0.95 = 117283865 - remove dust -> 117283800 - - // no remaining balance - let remaining_balance = fungible_asset::amount(&fa); - assert!(remaining_balance == 00, 0); - burn_token_for_test(fa); - - // check that the fee was deposited - let fee_deposited = primary_fungible_store::balance(deposit_address, oft_impl::metadata()); - assert!(fee_deposited == 6172900, 0); // 123456700 - 117283800 = 6172900 - - // check the invariant that the total amount is conserved - assert!(received + fee_deposited == sent, 1); - } - - #[test] - fun test_set_blocklist_credit() { - setup(); - - let blocklisted_address = @0x1234; - assert!(is_blocklisted(blocklisted_address) == false, 0); - - let admin = &create_signer_for_test(@oft_admin); - oft_impl::set_blocklist( - admin, - blocklisted_address, - true, - ); - assert!(was_event_emitted(&oft_impl_config::blocklist_set_event(blocklisted_address, true)), 1); - assert!(is_blocklisted(blocklisted_address), 1); - - oft_impl::credit( - blocklisted_address, - 1234, - 12345, - option::none(), - ); - - assert!( - was_event_emitted(&oft_impl_config::blocked_amount_redirected_event(1234, blocklisted_address, @oft_admin)), - 2 - ); - - let admin_balance = primary_fungible_store::balance(@oft_admin, oft_impl::metadata()); - assert!(admin_balance == 1234, 3); - - oft_impl::set_blocklist( - admin, - blocklisted_address, - false, - ); - assert!(was_event_emitted(&oft_impl_config::blocklist_set_event(blocklisted_address, false)), 4); - assert!(is_blocklisted(blocklisted_address) == false, 5); - - oft_impl::credit( - blocklisted_address, - 1234, - 12345, - option::none(), - ); - - let to_balance = primary_fungible_store::balance(blocklisted_address, oft_impl::metadata()); - assert!(to_balance == 1234, 6); - - let admin_balance = primary_fungible_store::balance(@oft_admin, oft_impl::metadata()); - // unchanged - assert!(admin_balance == 1234, 7); - } - - #[test] - #[expected_failure(abort_code = oft::oft_impl_config::EADDRESS_BLOCKED)] - fun test_set_blocklist_debit() { - setup(); - - let blocklisted_address = @0x1234; - primary_fungible_store::deposit(blocklisted_address, oft_impl::mint_tokens_for_test(10_000)); - - assert!(is_blocklisted(blocklisted_address) == false, 0); - - let admin = &create_signer_for_test(@oft_admin); - oft_impl::set_blocklist( - admin, - blocklisted_address, - true, - ); - - let debit_tokens = mint_tokens_for_test(1234); - oft_impl::debit_fungible_asset( - blocklisted_address, - &mut debit_tokens, - 0, - 12345, - ); - burn_token_for_test(debit_tokens); - } - - #[test] - #[expected_failure(abort_code = 0x50003, location = std::fungible_asset)] - fun cannot_transfer_blocklisted_tokens() { - setup(); - - let blocklisted_address = @0x1234; - primary_fungible_store::deposit(blocklisted_address, oft_impl::mint_tokens_for_test(10_000)); - - assert!(is_blocklisted(blocklisted_address) == false, 0); - - let admin = &create_signer_for_test(@oft_admin); - oft_impl::set_blocklist( - admin, - blocklisted_address, - true, - ); - - primary_fungible_store::transfer( - &create_signer_for_test(blocklisted_address), - oft_impl::metadata(), - @9888, - 2000 - ); - } - - #[test] - #[expected_failure(abort_code = oft::oft_impl_config::EBLOCKLIST_DISABLED)] - fun test_disable_blocklist() { - setup(); - - let admin = &create_signer_for_test(@oft_admin); - oft_impl::irrevocably_disable_blocklist(admin); - assert!(was_event_emitted(&oft_impl_config::blocklisting_disabled_event()), 1); - - let blocklisted_address = @0x1234; - oft_impl::set_blocklist( - admin, - blocklisted_address, - true, - ); - } - - #[test] - fun test_rate_limit() { - setup(); - - let (limit, window) = oft_impl::rate_limit_config(30100); - assert!(limit == 0 && window == 0, 0); - - let admin = &create_signer_for_test(@oft_admin); - oft_impl::set_rate_limit(admin, 30100, 2500, 100); - assert!(was_event_emitted(&oft_impl_config::rate_limit_set_event(30100, 2500, 100)), 1); - - let (limit, window) = oft_impl::rate_limit_config(30100); - assert!(limit == 2500 && window == 100, 1); - - let (oft_limit, fee_detail) = oft_impl::oft_limit_and_fees( - 30100, - x"1234", - 123, - 100, - x"1234", - x"1234", - x"1234" - ); - - // no fee - assert!(vector::length(&fee_detail) == 0, 2); - - // rate limit - let (min_amount_ld, max_amount_ld) = oft_common::oft_limit::unpack_oft_limit(oft_limit); - assert!(min_amount_ld == 0 && max_amount_ld == 2500, 3); - } -} diff --git a/examples/oft-move/test/movement/oft_using_oft_fa_tests.move b/examples/oft-move/test/movement/oft_using_oft_fa_tests.move deleted file mode 100644 index a1d4ee579..000000000 --- a/examples/oft-move/test/movement/oft_using_oft_fa_tests.move +++ /dev/null @@ -1,305 +0,0 @@ -// **Important** This module tests the behavior of OFT assuming that it is connected to OFT_FA. When connecting to -// a different template such as OFT_ADAPTER_FA or configuring the OFT module differently, the tests will no longer be -// valid. -#[test_only] -module oft::oft_using_oft_fa_tests { - use std::account::create_signer_for_test; - use std::fungible_asset; - use std::option; - use std::primary_fungible_store::{Self, balance}; - use std::signer::address_of; - use std::vector; - - use endpoint_v2::endpoint; - use endpoint_v2::test_helpers::setup_layerzero_for_test; - use endpoint_v2_common::bytes32::{Self, from_address, from_bytes32}; - use endpoint_v2_common::contract_identity::make_dynamic_call_ref_for_test; - use endpoint_v2_common::guid; - use endpoint_v2_common::native_token_test_helpers::{burn_token_for_test, mint_native_token_for_test}; - use endpoint_v2_common::packet_raw; - use endpoint_v2_common::packet_v1_codec::{Self, compute_payload}; - use oft::oapp_core::{set_pause_sending, set_peer}; - use oft::oapp_receive::lz_receive; - use oft::oapp_store::OAPP_ADDRESS; - use oft::oft::{ - debit_view, quote_oft, quote_send, remove_dust, send, send_withdraw, to_ld, to_sd, token, unpack_oft_receipt, - }; - use oft::oft_impl::{mint_tokens_for_test, set_fee_bps, set_rate_limit}; - use oft::oft_store; - use oft_common::oft_limit::{max_amount_ld, min_amount_ld}; - use oft_common::oft_msg_codec; - - const MAXU64: u64 = 0xffffffffffffffff; - const SRC_EID: u32 = 101; - const DST_EID: u32 = 201; - - fun setup(local_eid: u32, remote_eid: u32) { - let oft_admin = &create_signer_for_test(@oft_admin); - setup_layerzero_for_test(@simple_msglib, local_eid, remote_eid); - oft::oapp_test_helper::init_oapp(); - - oft::oft_impl_config::init_module_for_test(); - oft_store::init_module_for_test(); - oft::oft_impl::init_module_for_test(); - oft::oft_impl::initialize( - oft_admin, - b"My Test Token", - b"MYT", - b"", - b"", - 6, - 8, - ); - - let remote_oapp = from_address(@2000); - set_peer(oft_admin, DST_EID, from_bytes32(remote_oapp)); - } - - #[test] - fun test_quote_oft() { - setup(SRC_EID, DST_EID); - - let receipient = from_address(@2000); - let amount_ld = 100u64 * 100_000_000; // 100 TOKEN - let compose_msg = vector[]; - let (limit, fees, amount_sent_ld, amount_received_ld) = quote_oft( - DST_EID, - from_bytes32(receipient), - amount_ld, - 0, - vector[], - compose_msg, - vector[] - ); - assert!(min_amount_ld(&limit) == 0, 0); - assert!(max_amount_ld(&limit) == MAXU64, 1); - assert!(vector::length(&fees) == 0, 2); - - assert!(amount_sent_ld == amount_ld, 3); - assert!(amount_received_ld == amount_ld, 3); - } - - #[test] - fun test_quote_send() { - setup(SRC_EID, DST_EID); - - let amount = 100u64 * 100_000_000; // 100 TOKEN - let (native_fee, zro_fee) = quote_send( - @1000, - DST_EID, - from_bytes32(from_address(@2000)), - amount, - amount, - vector[], - vector[], - vector[], - false, - ); - assert!(native_fee == 0, 0); - assert!(zro_fee == 0, 1); - } - - #[test] - fun test_send_fa() { - setup(SRC_EID, DST_EID); - - let amount = 100u64 * 100_000_000; // 100 TOKEN - let alice = &create_signer_for_test(@1234); - let fa = mint_native_token_for_test(100_000_000); // mint 1 APT to alice - primary_fungible_store::deposit(address_of(alice), fa); - let bob = from_address(@5678); - let tokens = mint_tokens_for_test(amount); - - let native_fee = mint_native_token_for_test(10000000); - let zro_fee = option::none(); - send( - &make_dynamic_call_ref_for_test(address_of(alice), OAPP_ADDRESS(), b"send"), - DST_EID, - bob, - &mut tokens, - amount, - vector[], - vector[], - vector[], - &mut native_fee, - &mut zro_fee, - ); - assert!(fungible_asset::amount(&tokens) == 0, 1); // after send balance - - burn_token_for_test(native_fee); - option::destroy_none(zro_fee); - burn_token_for_test(tokens); - } - - #[test] - fun test_send_fa_with_fee() { - setup(SRC_EID, DST_EID); - // 10% fee - set_fee_bps(&create_signer_for_test(@oft_admin), 1000); - - let amount = 100u64 * 100_000_000; // 100 TOKEN - let alice = &create_signer_for_test(@1234); - let fa = mint_native_token_for_test(100_000_000); // mint 1 APT to alice - primary_fungible_store::deposit(address_of(alice), fa); - let bob = from_address(@5678); - let tokens = mint_tokens_for_test(amount); - - let native_fee = mint_native_token_for_test(10000000); - let zro_fee = option::none(); - let (_messaging_receipt, oft_receipt) = send( - &make_dynamic_call_ref_for_test(address_of(alice), OAPP_ADDRESS(), b"send"), - DST_EID, - bob, - &mut tokens, - 9_000_000, - vector[], - vector[], - vector[], - &mut native_fee, - &mut zro_fee, - ); - assert!(fungible_asset::amount(&tokens) == 0, 1); // after send balance - - let (sent, received) = unpack_oft_receipt(&oft_receipt); - assert!(sent == 10_000_000_000, 2); - assert!(received == 9_000_000_000, 2); - - burn_token_for_test(native_fee); - option::destroy_none(zro_fee); - burn_token_for_test(tokens); - } - - #[test] - fun test_send() { - setup(SRC_EID, DST_EID); - - let amount = 100u64 * 100_000_000; // 100 TOKEN - let alice = &create_signer_for_test(@1234); - let fa = mint_native_token_for_test(100_000_000); // mint 1 APT to alice - primary_fungible_store::deposit(address_of(alice), fa); - let bob = from_bytes32(from_address(@5678)); - let tokens = mint_tokens_for_test(amount); - primary_fungible_store::deposit(address_of(alice), tokens); - assert!(balance(address_of(alice), oft::oft::metadata()) == amount, 0); // before send balance - - send_withdraw(alice, DST_EID, bob, amount, amount, vector[], vector[], vector[], 0, 0); - assert!(balance(address_of(alice), oft::oft::metadata()) == 0, 1); // after send balance - } - - #[test] - #[expected_failure(abort_code = oft::oapp_core::ESEND_PAUSED)] - fun test_send_paused() { - setup(SRC_EID, DST_EID); - set_pause_sending(&create_signer_for_test(@oft_admin), DST_EID, true); - - let amount = 100u64 * 100_000_000; // 100 TOKEN - let alice = &create_signer_for_test(@1234); - let fa = mint_native_token_for_test(100_000_000); // mint 1 APT to alice - primary_fungible_store::deposit(address_of(alice), fa); - let bob = from_bytes32(from_address(@5678)); - let tokens = mint_tokens_for_test(amount); - primary_fungible_store::deposit(address_of(alice), tokens); - assert!(balance(address_of(alice), oft::oft::metadata()) == amount, 0); // before send balance - - send_withdraw(alice, DST_EID, bob, amount, amount, vector[], vector[], vector[], 0, 0); - } - - #[test] - #[expected_failure(abort_code = oft::oft_impl_config::EEXCEEDED_RATE_LIMIT)] - fun test_send_exceed_rate_limit() { - setup(SRC_EID, DST_EID); - set_rate_limit(&create_signer_for_test(@oft_admin), DST_EID, 19_000_000_000, 10); - - let amount = 100u64 * 100_000_000; // 100 TOKEN - let alice = &create_signer_for_test(@1234); - let fa = mint_native_token_for_test(100_000_000); // mint 1 APT to alice - primary_fungible_store::deposit(address_of(alice), fa); - let bob = from_bytes32(from_address(@5678)); - // 3x the required tokens - let tokens = mint_tokens_for_test(amount * 3); - primary_fungible_store::deposit(address_of(alice), tokens); - - // Succeeds: consumes 10_000_000_000 of 19_000_000_000 - send_withdraw(alice, DST_EID, bob, amount, amount, vector[], vector[], vector[], 0, 0); - // Fails (rate limit exceeded): consumes 20_000_000_000 of 19_000_000_000 - send_withdraw(alice, DST_EID, bob, amount, amount, vector[], vector[], vector[], 0, 0); - } - - #[test] - fun test_send_rate_limit_netted_by_receive() { - setup(SRC_EID, DST_EID); - set_rate_limit(&create_signer_for_test(@oft_admin), DST_EID, 19_000_000_000, 10); - - let amount = 100u64 * 100_000_000; // 100 TOKEN - let alice = &create_signer_for_test(@1234); - let fa = mint_native_token_for_test(100_000_000); // mint 1 APT to alice - primary_fungible_store::deposit(address_of(alice), fa); - let bob = from_bytes32(from_address(@5678)); - // 3x the required tokens - let tokens = mint_tokens_for_test(amount * 3); - primary_fungible_store::deposit(address_of(alice), tokens); - - // Succeeds: consumes 10_000_000_000 of 19_000_000_000 in flight - send_withdraw(alice, DST_EID, bob, amount, amount, vector[], vector[], vector[], 0, 0); - - // Receive 5_000_000_000: 5_000_000_000 of 19_000_000_000 in flight - let message = oft_msg_codec::encode( - from_address(@1234), - 5_000_000_000, - from_address(@0xffff), - b"", - ); - // Reverse the EIDs to simulate a receive from the remote OFT - let packet = packet_v1_codec::new_packet_v1( - DST_EID, - from_address(@2000), // remote OFT - SRC_EID, - from_address(@oft), - 1, - guid::compute_guid( - 1, - DST_EID, - from_address(@2000), - SRC_EID, - from_address(@oft), - ), - message, - ); - endpoint::verify( - @simple_msglib, - packet_raw::get_packet_bytes(packet_v1_codec::extract_header(&packet)), - from_bytes32(bytes32::keccak256(compute_payload( - packet_v1_codec::get_guid(&packet), - packet_v1_codec::get_message(&packet), - ))), - ); - lz_receive( - packet_v1_codec::get_src_eid(&packet), - from_bytes32(packet_v1_codec::get_sender(&packet)), - packet_v1_codec::get_nonce(&packet), - from_bytes32(packet_v1_codec::get_guid(&packet)), - message, - vector[], - ); - - - // Fails (rate limit exceeded): consumes 15_000_000_000 of 19_000_000_000 in flight - send_withdraw(alice, DST_EID, bob, amount, amount, vector[], vector[], vector[], 0, 0); - } - - #[test] - fun test_metadata_view_functions() { - setup(SRC_EID, DST_EID); - - // token is unknown at time of test - just calling to check it doesn't abort - token(); - - assert!(to_ld(100) == 10000, 0); - assert!(to_sd(100) == 1, 1); - assert!(remove_dust(123) == 100, 2); - - let (sent, received) = debit_view(1234, 0, DST_EID); - assert!(sent == 1200, 3); - assert!(received == 1200, 4); - } -} \ No newline at end of file