From 1035893fd99f51cb3de26e15a890bce1925e9d23 Mon Sep 17 00:00:00 2001 From: jonesmarvin8 <83104039+jonesmarvin8@users.noreply.github.com> Date: Tue, 17 Mar 2026 19:09:25 -0400 Subject: [PATCH] fix lint --- programs/amm/src/full_tests.rs | 1345 -------------------------------- programs/amm/src/tests.rs | 134 ++-- 2 files changed, 65 insertions(+), 1414 deletions(-) delete mode 100644 programs/amm/src/full_tests.rs diff --git a/programs/amm/src/full_tests.rs b/programs/amm/src/full_tests.rs deleted file mode 100644 index 5c918eae..00000000 --- a/programs/amm/src/full_tests.rs +++ /dev/null @@ -1,1345 +0,0 @@ -use amm_core::PoolDefinition; -use nssa::{ - Account, AccountId, Data, PrivateKey, PublicKey, PublicTransaction, V02State, program::Program, - public_transaction, -}; -use token_core::{TokenDefinition, TokenHolding}; - -struct PrivateKeysForTests; - -impl PrivateKeysForTests { - fn user_token_a_key() -> PrivateKey { - PrivateKey::try_new([31; 32]).expect("Keys constructor expects valid private key") - } - - fn user_token_b_key() -> PrivateKey { - PrivateKey::try_new([32; 32]).expect("Keys constructor expects valid private key") - } - - fn user_token_lp_key() -> PrivateKey { - PrivateKey::try_new([33; 32]).expect("Keys constructor expects valid private key") - } -} - -struct BalanceForTests; - -impl BalanceForTests { - fn user_token_a_holding_init() -> u128 { - 10_000 - } - - fn user_token_b_holding_init() -> u128 { - 10_000 - } - - fn user_token_lp_holding_init() -> u128 { - 2_000 - } - - fn vault_a_balance_init() -> u128 { - 5_000 - } - - fn vault_b_balance_init() -> u128 { - 2_500 - } - - fn pool_lp_supply_init() -> u128 { - 5_000 - } - - fn token_a_supply() -> u128 { - 100_000 - } - - fn token_b_supply() -> u128 { - 100_000 - } - - fn token_lp_supply() -> u128 { - 5_000 - } - - fn remove_lp() -> u128 { - 1_000 - } - - fn remove_min_amount_a() -> u128 { - 500 - } - - fn remove_min_amount_b() -> u128 { - 500 - } - - fn add_min_amount_lp() -> u128 { - 1_000 - } - - fn add_max_amount_a() -> u128 { - 2_000 - } - - fn add_max_amount_b() -> u128 { - 1_000 - } - - fn swap_amount_in() -> u128 { - 1_000 - } - - fn swap_min_amount_out() -> u128 { - 200 - } - - fn vault_a_balance_swap_1() -> u128 { - 3_572 - } - - fn vault_b_balance_swap_1() -> u128 { - 3_500 - } - - fn user_token_a_holding_swap_1() -> u128 { - 11_428 - } - - fn user_token_b_holding_swap_1() -> u128 { - 9_000 - } - - fn vault_a_balance_swap_2() -> u128 { - 6_000 - } - - fn vault_b_balance_swap_2() -> u128 { - 2_084 - } - - fn user_token_a_holding_swap_2() -> u128 { - 9_000 - } - - fn user_token_b_holding_swap_2() -> u128 { - 10_416 - } - - fn vault_a_balance_add() -> u128 { - 7_000 - } - - fn vault_b_balance_add() -> u128 { - 3_500 - } - - fn user_token_a_holding_add() -> u128 { - 8_000 - } - - fn user_token_b_holding_add() -> u128 { - 9_000 - } - - fn user_token_lp_holding_add() -> u128 { - 4_000 - } - - fn token_lp_supply_add() -> u128 { - 7_000 - } - - fn vault_a_balance_remove() -> u128 { - 4_000 - } - - fn vault_b_balance_remove() -> u128 { - 2_000 - } - - fn user_token_a_holding_remove() -> u128 { - 11_000 - } - - fn user_token_b_holding_remove() -> u128 { - 10_500 - } - - fn user_token_lp_holding_remove() -> u128 { - 1_000 - } - - fn token_lp_supply_remove() -> u128 { - 4_000 - } - - fn user_token_a_holding_new_definition() -> u128 { - 5_000 - } - - fn user_token_b_holding_new_definition() -> u128 { - 7_500 - } - - fn lp_supply_init() -> u128 { - // isqrt(vault_a_balance_init * vault_b_balance_init) = isqrt(5_000 * 2_500) = 3535 - (BalanceForTests::vault_a_balance_init() * BalanceForTests::vault_b_balance_init()).isqrt() - } -} - -struct IdForTests; - -impl IdForTests { - fn pool_definition_id() -> AccountId { - amm_core::compute_pool_pda( - Program::amm().id(), - IdForTests::token_a_definition_id(), - IdForTests::token_b_definition_id(), - ) - } - - fn token_lp_definition_id() -> AccountId { - amm_core::compute_liquidity_token_pda(Program::amm().id(), IdForTests::pool_definition_id()) - } - - fn token_a_definition_id() -> AccountId { - AccountId::new([3; 32]) - } - - fn token_b_definition_id() -> AccountId { - AccountId::new([4; 32]) - } - - fn user_token_a_id() -> AccountId { - AccountId::from(&PublicKey::new_from_private_key( - &PrivateKeysForTests::user_token_a_key(), - )) - } - - fn user_token_b_id() -> AccountId { - AccountId::from(&PublicKey::new_from_private_key( - &PrivateKeysForTests::user_token_b_key(), - )) - } - - fn user_token_lp_id() -> AccountId { - AccountId::from(&PublicKey::new_from_private_key( - &PrivateKeysForTests::user_token_lp_key(), - )) - } - - fn vault_a_id() -> AccountId { - amm_core::compute_vault_pda( - Program::amm().id(), - IdForTests::pool_definition_id(), - IdForTests::token_a_definition_id(), - ) - } - - fn vault_b_id() -> AccountId { - amm_core::compute_vault_pda( - Program::amm().id(), - IdForTests::pool_definition_id(), - IdForTests::token_b_definition_id(), - ) - } -} - -struct AccountForTests; - -impl AccountForTests { - fn user_token_a_holding() -> Account { - Account { - program_owner: Program::token().id(), - balance: 0u128, - data: Data::from(&TokenHolding::Fungible { - definition_id: IdForTests::token_a_definition_id(), - balance: BalanceForTests::user_token_a_holding_init(), - }), - nonce: 0, - } - } - - fn user_token_b_holding() -> Account { - Account { - program_owner: Program::token().id(), - balance: 0u128, - data: Data::from(&TokenHolding::Fungible { - definition_id: IdForTests::token_b_definition_id(), - balance: BalanceForTests::user_token_b_holding_init(), - }), - nonce: 0, - } - } - - fn pool_definition_init() -> Account { - Account { - program_owner: Program::amm().id(), - balance: 0u128, - data: Data::from(&PoolDefinition { - definition_token_a_id: IdForTests::token_a_definition_id(), - definition_token_b_id: IdForTests::token_b_definition_id(), - vault_a_id: IdForTests::vault_a_id(), - vault_b_id: IdForTests::vault_b_id(), - liquidity_pool_id: IdForTests::token_lp_definition_id(), - liquidity_pool_supply: BalanceForTests::pool_lp_supply_init(), - reserve_a: BalanceForTests::vault_a_balance_init(), - reserve_b: BalanceForTests::vault_b_balance_init(), - fees: 0u128, - active: true, - }), - nonce: 0, - } - } - - fn token_a_definition_account() -> Account { - Account { - program_owner: Program::token().id(), - balance: 0u128, - data: Data::from(&TokenDefinition::Fungible { - name: String::from("test"), - total_supply: BalanceForTests::token_a_supply(), - metadata_id: None, - }), - nonce: 0, - } - } - - fn token_b_definition_acc() -> Account { - Account { - program_owner: Program::token().id(), - balance: 0u128, - data: Data::from(&TokenDefinition::Fungible { - name: String::from("test"), - total_supply: BalanceForTests::token_b_supply(), - metadata_id: None, - }), - nonce: 0, - } - } - - fn token_lp_definition_acc() -> Account { - Account { - program_owner: Program::token().id(), - balance: 0u128, - data: Data::from(&TokenDefinition::Fungible { - name: String::from("LP Token"), - total_supply: BalanceForTests::token_lp_supply(), - metadata_id: None, - }), - nonce: 0, - } - } - - fn vault_a_init() -> Account { - Account { - program_owner: Program::token().id(), - balance: 0u128, - data: Data::from(&TokenHolding::Fungible { - definition_id: IdForTests::token_a_definition_id(), - balance: BalanceForTests::vault_a_balance_init(), - }), - nonce: 0, - } - } - - fn vault_b_init() -> Account { - Account { - program_owner: Program::token().id(), - balance: 0u128, - data: Data::from(&TokenHolding::Fungible { - definition_id: IdForTests::token_b_definition_id(), - balance: BalanceForTests::vault_b_balance_init(), - }), - nonce: 0, - } - } - - fn user_token_lp_holding() -> Account { - Account { - program_owner: Program::token().id(), - balance: 0u128, - data: Data::from(&TokenHolding::Fungible { - definition_id: IdForTests::token_lp_definition_id(), - balance: BalanceForTests::user_token_lp_holding_init(), - }), - nonce: 0, - } - } - - fn vault_a_swap_1() -> Account { - Account { - program_owner: Program::token().id(), - balance: 0u128, - data: Data::from(&TokenHolding::Fungible { - definition_id: IdForTests::token_a_definition_id(), - balance: BalanceForTests::vault_a_balance_swap_1(), - }), - nonce: 0, - } - } - - fn vault_b_swap_1() -> Account { - Account { - program_owner: Program::token().id(), - balance: 0u128, - data: Data::from(&TokenHolding::Fungible { - definition_id: IdForTests::token_b_definition_id(), - balance: BalanceForTests::vault_b_balance_swap_1(), - }), - nonce: 0, - } - } - - fn pool_definition_swap_1() -> Account { - Account { - program_owner: Program::amm().id(), - balance: 0u128, - data: Data::from(&PoolDefinition { - definition_token_a_id: IdForTests::token_a_definition_id(), - definition_token_b_id: IdForTests::token_b_definition_id(), - vault_a_id: IdForTests::vault_a_id(), - vault_b_id: IdForTests::vault_b_id(), - liquidity_pool_id: IdForTests::token_lp_definition_id(), - liquidity_pool_supply: BalanceForTests::pool_lp_supply_init(), - reserve_a: BalanceForTests::vault_a_balance_swap_1(), - reserve_b: BalanceForTests::vault_b_balance_swap_1(), - fees: 0u128, - active: true, - }), - nonce: 0, - } - } - - fn user_token_a_holding_swap_1() -> Account { - Account { - program_owner: Program::token().id(), - balance: 0u128, - data: Data::from(&TokenHolding::Fungible { - definition_id: IdForTests::token_a_definition_id(), - balance: BalanceForTests::user_token_a_holding_swap_1(), - }), - nonce: 0, - } - } - - fn user_token_b_holding_swap_1() -> Account { - Account { - program_owner: Program::token().id(), - balance: 0u128, - data: Data::from(&TokenHolding::Fungible { - definition_id: IdForTests::token_b_definition_id(), - balance: BalanceForTests::user_token_b_holding_swap_1(), - }), - nonce: 1, - } - } - - fn vault_a_swap_2() -> Account { - Account { - program_owner: Program::token().id(), - balance: 0u128, - data: Data::from(&TokenHolding::Fungible { - definition_id: IdForTests::token_a_definition_id(), - balance: BalanceForTests::vault_a_balance_swap_2(), - }), - nonce: 0, - } - } - - fn vault_b_swap_2() -> Account { - Account { - program_owner: Program::token().id(), - balance: 0u128, - data: Data::from(&TokenHolding::Fungible { - definition_id: IdForTests::token_b_definition_id(), - balance: BalanceForTests::vault_b_balance_swap_2(), - }), - nonce: 0, - } - } - - fn pool_definition_swap_2() -> Account { - Account { - program_owner: Program::amm().id(), - balance: 0u128, - data: Data::from(&PoolDefinition { - definition_token_a_id: IdForTests::token_a_definition_id(), - definition_token_b_id: IdForTests::token_b_definition_id(), - vault_a_id: IdForTests::vault_a_id(), - vault_b_id: IdForTests::vault_b_id(), - liquidity_pool_id: IdForTests::token_lp_definition_id(), - liquidity_pool_supply: BalanceForTests::pool_lp_supply_init(), - reserve_a: BalanceForTests::vault_a_balance_swap_2(), - reserve_b: BalanceForTests::vault_b_balance_swap_2(), - fees: 0u128, - active: true, - }), - nonce: 0, - } - } - - fn user_token_a_holding_swap_2() -> Account { - Account { - program_owner: Program::token().id(), - balance: 0u128, - data: Data::from(&TokenHolding::Fungible { - definition_id: IdForTests::token_a_definition_id(), - balance: BalanceForTests::user_token_a_holding_swap_2(), - }), - nonce: 1, - } - } - - fn user_token_b_holding_swap_2() -> Account { - Account { - program_owner: Program::token().id(), - balance: 0u128, - data: Data::from(&TokenHolding::Fungible { - definition_id: IdForTests::token_b_definition_id(), - balance: BalanceForTests::user_token_b_holding_swap_2(), - }), - nonce: 0, - } - } - - fn vault_a_add() -> Account { - Account { - program_owner: Program::token().id(), - balance: 0u128, - data: Data::from(&TokenHolding::Fungible { - definition_id: IdForTests::token_a_definition_id(), - balance: BalanceForTests::vault_a_balance_add(), - }), - nonce: 0, - } - } - - fn vault_b_add() -> Account { - Account { - program_owner: Program::token().id(), - balance: 0u128, - data: Data::from(&TokenHolding::Fungible { - definition_id: IdForTests::token_b_definition_id(), - balance: BalanceForTests::vault_b_balance_add(), - }), - nonce: 0, - } - } - - fn pool_definition_add() -> Account { - Account { - program_owner: Program::amm().id(), - balance: 0u128, - data: Data::from(&PoolDefinition { - definition_token_a_id: IdForTests::token_a_definition_id(), - definition_token_b_id: IdForTests::token_b_definition_id(), - vault_a_id: IdForTests::vault_a_id(), - vault_b_id: IdForTests::vault_b_id(), - liquidity_pool_id: IdForTests::token_lp_definition_id(), - liquidity_pool_supply: BalanceForTests::token_lp_supply_add(), - reserve_a: BalanceForTests::vault_a_balance_add(), - reserve_b: BalanceForTests::vault_b_balance_add(), - fees: 0u128, - active: true, - }), - nonce: 0, - } - } - - fn user_token_a_holding_add() -> Account { - Account { - program_owner: Program::token().id(), - balance: 0u128, - data: Data::from(&TokenHolding::Fungible { - definition_id: IdForTests::token_a_definition_id(), - balance: BalanceForTests::user_token_a_holding_add(), - }), - nonce: 1, - } - } - - fn user_token_b_holding_add() -> Account { - Account { - program_owner: Program::token().id(), - balance: 0u128, - data: Data::from(&TokenHolding::Fungible { - definition_id: IdForTests::token_b_definition_id(), - balance: BalanceForTests::user_token_b_holding_add(), - }), - nonce: 1, - } - } - - fn user_token_lp_holding_add() -> Account { - Account { - program_owner: Program::token().id(), - balance: 0u128, - data: Data::from(&TokenHolding::Fungible { - definition_id: IdForTests::token_lp_definition_id(), - balance: BalanceForTests::user_token_lp_holding_add(), - }), - nonce: 0, - } - } - - fn token_lp_definition_add() -> Account { - Account { - program_owner: Program::token().id(), - balance: 0u128, - data: Data::from(&TokenDefinition::Fungible { - name: String::from("LP Token"), - total_supply: BalanceForTests::token_lp_supply_add(), - metadata_id: None, - }), - nonce: 0, - } - } - - fn vault_a_remove() -> Account { - Account { - program_owner: Program::token().id(), - balance: 0u128, - data: Data::from(&TokenHolding::Fungible { - definition_id: IdForTests::token_a_definition_id(), - balance: BalanceForTests::vault_a_balance_remove(), - }), - nonce: 0, - } - } - - fn vault_b_remove() -> Account { - Account { - program_owner: Program::token().id(), - balance: 0u128, - data: Data::from(&TokenHolding::Fungible { - definition_id: IdForTests::token_b_definition_id(), - balance: BalanceForTests::vault_b_balance_remove(), - }), - nonce: 0, - } - } - - fn pool_definition_remove() -> Account { - Account { - program_owner: Program::amm().id(), - balance: 0u128, - data: Data::from(&PoolDefinition { - definition_token_a_id: IdForTests::token_a_definition_id(), - definition_token_b_id: IdForTests::token_b_definition_id(), - vault_a_id: IdForTests::vault_a_id(), - vault_b_id: IdForTests::vault_b_id(), - liquidity_pool_id: IdForTests::token_lp_definition_id(), - liquidity_pool_supply: BalanceForTests::token_lp_supply_remove(), - reserve_a: BalanceForTests::vault_a_balance_remove(), - reserve_b: BalanceForTests::vault_b_balance_remove(), - fees: 0u128, - active: true, - }), - nonce: 0, - } - } - - fn user_token_a_holding_remove() -> Account { - Account { - program_owner: Program::token().id(), - balance: 0u128, - data: Data::from(&TokenHolding::Fungible { - definition_id: IdForTests::token_a_definition_id(), - balance: BalanceForTests::user_token_a_holding_remove(), - }), - nonce: 0, - } - } - - fn user_token_b_holding_remove() -> Account { - Account { - program_owner: Program::token().id(), - balance: 0u128, - data: Data::from(&TokenHolding::Fungible { - definition_id: IdForTests::token_b_definition_id(), - balance: BalanceForTests::user_token_b_holding_remove(), - }), - nonce: 0, - } - } - - fn user_token_lp_holding_remove() -> Account { - Account { - program_owner: Program::token().id(), - balance: 0u128, - data: Data::from(&TokenHolding::Fungible { - definition_id: IdForTests::token_lp_definition_id(), - balance: BalanceForTests::user_token_lp_holding_remove(), - }), - nonce: 1, - } - } - - fn token_lp_definition_remove() -> Account { - Account { - program_owner: Program::token().id(), - balance: 0u128, - data: Data::from(&TokenDefinition::Fungible { - name: String::from("LP Token"), - total_supply: BalanceForTests::token_lp_supply_remove(), - metadata_id: None, - }), - nonce: 0, - } - } - - fn token_lp_definition_init_inactive() -> Account { - Account { - program_owner: Program::token().id(), - balance: 0u128, - data: Data::from(&TokenDefinition::Fungible { - name: String::from("LP Token"), - total_supply: 0, - metadata_id: None, - }), - nonce: 0, - } - } - - fn vault_a_init_inactive() -> Account { - Account { - program_owner: Program::token().id(), - balance: 0u128, - data: Data::from(&TokenHolding::Fungible { - definition_id: IdForTests::token_a_definition_id(), - balance: 0, - }), - nonce: 0, - } - } - - fn vault_b_init_inactive() -> Account { - Account { - program_owner: Program::token().id(), - balance: 0u128, - data: Data::from(&TokenHolding::Fungible { - definition_id: IdForTests::token_b_definition_id(), - balance: 0, - }), - nonce: 0, - } - } - - fn pool_definition_inactive() -> Account { - Account { - program_owner: Program::amm().id(), - balance: 0u128, - data: Data::from(&PoolDefinition { - definition_token_a_id: IdForTests::token_a_definition_id(), - definition_token_b_id: IdForTests::token_b_definition_id(), - vault_a_id: IdForTests::vault_a_id(), - vault_b_id: IdForTests::vault_b_id(), - liquidity_pool_id: IdForTests::token_lp_definition_id(), - liquidity_pool_supply: 0, - reserve_a: 0, - reserve_b: 0, - fees: 0u128, - active: false, - }), - nonce: 0, - } - } - - fn user_token_a_holding_new_init() -> Account { - Account { - program_owner: Program::token().id(), - balance: 0u128, - data: Data::from(&TokenHolding::Fungible { - definition_id: IdForTests::token_a_definition_id(), - balance: BalanceForTests::user_token_a_holding_new_definition(), - }), - nonce: 1, - } - } - - fn user_token_b_holding_new_init() -> Account { - Account { - program_owner: Program::token().id(), - balance: 0u128, - data: Data::from(&TokenHolding::Fungible { - definition_id: IdForTests::token_b_definition_id(), - balance: BalanceForTests::user_token_b_holding_new_definition(), - }), - nonce: 1, - } - } - - fn user_token_lp_holding_new_init() -> Account { - Account { - program_owner: Program::token().id(), - balance: 0u128, - data: Data::from(&TokenHolding::Fungible { - definition_id: IdForTests::token_lp_definition_id(), - balance: BalanceForTests::lp_supply_init(), - }), - nonce: 0, - } - } - - fn token_lp_definition_new_init() -> Account { - Account { - program_owner: Program::token().id(), - balance: 0u128, - data: Data::from(&TokenDefinition::Fungible { - name: String::from("LP Token"), - total_supply: BalanceForTests::lp_supply_init(), - metadata_id: None, - }), - nonce: 0, - } - } - - fn pool_definition_new_init() -> Account { - Account { - program_owner: Program::amm().id(), - balance: 0u128, - data: Data::from(&PoolDefinition { - definition_token_a_id: IdForTests::token_a_definition_id(), - definition_token_b_id: IdForTests::token_b_definition_id(), - vault_a_id: IdForTests::vault_a_id(), - vault_b_id: IdForTests::vault_b_id(), - liquidity_pool_id: IdForTests::token_lp_definition_id(), - liquidity_pool_supply: BalanceForTests::lp_supply_init(), - reserve_a: BalanceForTests::vault_a_balance_init(), - reserve_b: BalanceForTests::vault_b_balance_init(), - fees: 0u128, - active: true, - }), - nonce: 0, - } - } - - fn user_token_lp_holding_init_zero() -> Account { - Account { - program_owner: Program::token().id(), - balance: 0u128, - data: Data::from(&TokenHolding::Fungible { - definition_id: IdForTests::token_lp_definition_id(), - balance: 0, - }), - nonce: 0, - } - } -} - -fn state_for_amm_tests() -> V02State { - let initial_data = []; - let mut state = V02State::new_with_genesis_accounts(&initial_data, &[]); - state.force_insert_account( - IdForTests::pool_definition_id(), - AccountForTests::pool_definition_init(), - ); - state.force_insert_account( - IdForTests::token_a_definition_id(), - AccountForTests::token_a_definition_account(), - ); - state.force_insert_account( - IdForTests::token_b_definition_id(), - AccountForTests::token_b_definition_acc(), - ); - state.force_insert_account( - IdForTests::token_lp_definition_id(), - AccountForTests::token_lp_definition_acc(), - ); - state.force_insert_account( - IdForTests::user_token_a_id(), - AccountForTests::user_token_a_holding(), - ); - state.force_insert_account( - IdForTests::user_token_b_id(), - AccountForTests::user_token_b_holding(), - ); - state.force_insert_account( - IdForTests::user_token_lp_id(), - AccountForTests::user_token_lp_holding(), - ); - state.force_insert_account(IdForTests::vault_a_id(), AccountForTests::vault_a_init()); - state.force_insert_account(IdForTests::vault_b_id(), AccountForTests::vault_b_init()); - - state -} - -fn state_for_amm_tests_with_new_def() -> V02State { - let initial_data = []; - let mut state = V02State::new_with_genesis_accounts(&initial_data, &[]); - state.force_insert_account( - IdForTests::token_a_definition_id(), - AccountForTests::token_a_definition_account(), - ); - state.force_insert_account( - IdForTests::token_b_definition_id(), - AccountForTests::token_b_definition_acc(), - ); - state.force_insert_account( - IdForTests::user_token_a_id(), - AccountForTests::user_token_a_holding(), - ); - state.force_insert_account( - IdForTests::user_token_b_id(), - AccountForTests::user_token_b_holding(), - ); - state -} - -#[test] -fn test_simple_amm_remove() { - let mut state = state_for_amm_tests(); - - let instruction = amm_core::Instruction::RemoveLiquidity { - remove_liquidity_amount: BalanceForTests::remove_lp(), - min_amount_to_remove_token_a: BalanceForTests::remove_min_amount_a(), - min_amount_to_remove_token_b: BalanceForTests::remove_min_amount_b(), - }; - - let message = public_transaction::Message::try_new( - Program::amm().id(), - vec![ - IdForTests::pool_definition_id(), - IdForTests::vault_a_id(), - IdForTests::vault_b_id(), - IdForTests::token_lp_definition_id(), - IdForTests::user_token_a_id(), - IdForTests::user_token_b_id(), - IdForTests::user_token_lp_id(), - ], - vec![0], - instruction, - ) - .unwrap(); - - let witness_set = public_transaction::WitnessSet::for_message( - &message, - &[&PrivateKeysForTests::user_token_lp_key()], - ); - - let tx = PublicTransaction::new(message, witness_set); - state.transition_from_public_transaction(&tx).unwrap(); - - let pool_post = state.get_account_by_id(IdForTests::pool_definition_id()); - let vault_a_post = state.get_account_by_id(IdForTests::vault_a_id()); - let vault_b_post = state.get_account_by_id(IdForTests::vault_b_id()); - let token_lp_post = state.get_account_by_id(IdForTests::token_lp_definition_id()); - let user_token_a_post = state.get_account_by_id(IdForTests::user_token_a_id()); - let user_token_b_post = state.get_account_by_id(IdForTests::user_token_b_id()); - let user_token_lp_post = state.get_account_by_id(IdForTests::user_token_lp_id()); - - let expected_pool = AccountForTests::pool_definition_remove(); - let expected_vault_a = AccountForTests::vault_a_remove(); - let expected_vault_b = AccountForTests::vault_b_remove(); - let expected_token_lp = AccountForTests::token_lp_definition_remove(); - let expected_user_token_a = AccountForTests::user_token_a_holding_remove(); - let expected_user_token_b = AccountForTests::user_token_b_holding_remove(); - let expected_user_token_lp = AccountForTests::user_token_lp_holding_remove(); - - assert_eq!(pool_post, expected_pool); - assert_eq!(vault_a_post, expected_vault_a); - assert_eq!(vault_b_post, expected_vault_b); - assert_eq!(token_lp_post, expected_token_lp); - assert_eq!(user_token_a_post, expected_user_token_a); - assert_eq!(user_token_b_post, expected_user_token_b); - assert_eq!(user_token_lp_post, expected_user_token_lp); -} - -#[test] -fn test_simple_amm_new_definition_inactive_initialized_pool_and_uninit_user_lp() { - let mut state = state_for_amm_tests_with_new_def(); - - // Uninitialized in constructor - state.force_insert_account( - IdForTests::vault_a_id(), - AccountForTests::vault_a_init_inactive(), - ); - state.force_insert_account( - IdForTests::vault_b_id(), - AccountForTests::vault_b_init_inactive(), - ); - state.force_insert_account( - IdForTests::pool_definition_id(), - AccountForTests::pool_definition_inactive(), - ); - state.force_insert_account( - IdForTests::token_lp_definition_id(), - AccountForTests::token_lp_definition_init_inactive(), - ); - - let instruction = amm_core::Instruction::NewDefinition { - token_a_amount: BalanceForTests::vault_a_balance_init(), - token_b_amount: BalanceForTests::vault_b_balance_init(), - amm_program_id: Program::amm().id(), - }; - - let message = public_transaction::Message::try_new( - Program::amm().id(), - vec![ - IdForTests::pool_definition_id(), - IdForTests::vault_a_id(), - IdForTests::vault_b_id(), - IdForTests::token_lp_definition_id(), - IdForTests::user_token_a_id(), - IdForTests::user_token_b_id(), - IdForTests::user_token_lp_id(), - ], - vec![0, 0], - instruction, - ) - .unwrap(); - - let witness_set = public_transaction::WitnessSet::for_message( - &message, - &[ - &PrivateKeysForTests::user_token_a_key(), - &PrivateKeysForTests::user_token_b_key(), - ], - ); - - let tx = PublicTransaction::new(message, witness_set); - state.transition_from_public_transaction(&tx).unwrap(); - - let pool_post = state.get_account_by_id(IdForTests::pool_definition_id()); - let vault_a_post = state.get_account_by_id(IdForTests::vault_a_id()); - let vault_b_post = state.get_account_by_id(IdForTests::vault_b_id()); - let token_lp_post = state.get_account_by_id(IdForTests::token_lp_definition_id()); - let user_token_a_post = state.get_account_by_id(IdForTests::user_token_a_id()); - let user_token_b_post = state.get_account_by_id(IdForTests::user_token_b_id()); - let user_token_lp_post = state.get_account_by_id(IdForTests::user_token_lp_id()); - - let expected_pool = AccountForTests::pool_definition_new_init(); - let expected_vault_a = AccountForTests::vault_a_init(); - let expected_vault_b = AccountForTests::vault_b_init(); - let expected_token_lp = AccountForTests::token_lp_definition_new_init(); - let expected_user_token_a = AccountForTests::user_token_a_holding_new_init(); - let expected_user_token_b = AccountForTests::user_token_b_holding_new_init(); - let expected_user_token_lp = AccountForTests::user_token_lp_holding_new_init(); - - assert_eq!(pool_post, expected_pool); - assert_eq!(vault_a_post, expected_vault_a); - assert_eq!(vault_b_post, expected_vault_b); - assert_eq!(token_lp_post, expected_token_lp); - assert_eq!(user_token_a_post, expected_user_token_a); - assert_eq!(user_token_b_post, expected_user_token_b); - assert_eq!(user_token_lp_post, expected_user_token_lp); -} - -#[test] -fn test_simple_amm_new_definition_inactive_initialized_pool_init_user_lp() { - let mut state = state_for_amm_tests_with_new_def(); - - // Uninitialized in constructor - state.force_insert_account( - IdForTests::vault_a_id(), - AccountForTests::vault_a_init_inactive(), - ); - state.force_insert_account( - IdForTests::vault_b_id(), - AccountForTests::vault_b_init_inactive(), - ); - state.force_insert_account( - IdForTests::pool_definition_id(), - AccountForTests::pool_definition_inactive(), - ); - state.force_insert_account( - IdForTests::token_lp_definition_id(), - AccountForTests::token_lp_definition_init_inactive(), - ); - state.force_insert_account( - IdForTests::user_token_lp_id(), - AccountForTests::user_token_lp_holding_init_zero(), - ); - - let instruction = amm_core::Instruction::NewDefinition { - token_a_amount: BalanceForTests::vault_a_balance_init(), - token_b_amount: BalanceForTests::vault_b_balance_init(), - amm_program_id: Program::amm().id(), - }; - - let message = public_transaction::Message::try_new( - Program::amm().id(), - vec![ - IdForTests::pool_definition_id(), - IdForTests::vault_a_id(), - IdForTests::vault_b_id(), - IdForTests::token_lp_definition_id(), - IdForTests::user_token_a_id(), - IdForTests::user_token_b_id(), - IdForTests::user_token_lp_id(), - ], - vec![0, 0], - instruction, - ) - .unwrap(); - - let witness_set = public_transaction::WitnessSet::for_message( - &message, - &[ - &PrivateKeysForTests::user_token_a_key(), - &PrivateKeysForTests::user_token_b_key(), - ], - ); - - let tx = PublicTransaction::new(message, witness_set); - state.transition_from_public_transaction(&tx).unwrap(); - - let pool_post = state.get_account_by_id(IdForTests::pool_definition_id()); - let vault_a_post = state.get_account_by_id(IdForTests::vault_a_id()); - let vault_b_post = state.get_account_by_id(IdForTests::vault_b_id()); - let token_lp_post = state.get_account_by_id(IdForTests::token_lp_definition_id()); - let user_token_a_post = state.get_account_by_id(IdForTests::user_token_a_id()); - let user_token_b_post = state.get_account_by_id(IdForTests::user_token_b_id()); - let user_token_lp_post = state.get_account_by_id(IdForTests::user_token_lp_id()); - - let expected_pool = AccountForTests::pool_definition_new_init(); - let expected_vault_a = AccountForTests::vault_a_init(); - let expected_vault_b = AccountForTests::vault_b_init(); - let expected_token_lp = AccountForTests::token_lp_definition_new_init(); - let expected_user_token_a = AccountForTests::user_token_a_holding_new_init(); - let expected_user_token_b = AccountForTests::user_token_b_holding_new_init(); - let expected_user_token_lp = AccountForTests::user_token_lp_holding_new_init(); - - assert_eq!(pool_post, expected_pool); - assert_eq!(vault_a_post, expected_vault_a); - assert_eq!(vault_b_post, expected_vault_b); - assert_eq!(token_lp_post, expected_token_lp); - assert_eq!(user_token_a_post, expected_user_token_a); - assert_eq!(user_token_b_post, expected_user_token_b); - assert_eq!(user_token_lp_post, expected_user_token_lp); -} - -#[test] -fn test_simple_amm_new_definition_uninitialized_pool() { - let mut state = state_for_amm_tests_with_new_def(); - - // Uninitialized in constructor - state.force_insert_account( - IdForTests::vault_a_id(), - AccountForTests::vault_a_init_inactive(), - ); - state.force_insert_account( - IdForTests::vault_b_id(), - AccountForTests::vault_b_init_inactive(), - ); - - let instruction = amm_core::Instruction::NewDefinition { - token_a_amount: BalanceForTests::vault_a_balance_init(), - token_b_amount: BalanceForTests::vault_b_balance_init(), - amm_program_id: Program::amm().id(), - }; - - let message = public_transaction::Message::try_new( - Program::amm().id(), - vec![ - IdForTests::pool_definition_id(), - IdForTests::vault_a_id(), - IdForTests::vault_b_id(), - IdForTests::token_lp_definition_id(), - IdForTests::user_token_a_id(), - IdForTests::user_token_b_id(), - IdForTests::user_token_lp_id(), - ], - vec![0, 0], - instruction, - ) - .unwrap(); - - let witness_set = public_transaction::WitnessSet::for_message( - &message, - &[ - &PrivateKeysForTests::user_token_a_key(), - &PrivateKeysForTests::user_token_b_key(), - ], - ); - - let tx = PublicTransaction::new(message, witness_set); - state.transition_from_public_transaction(&tx).unwrap(); - - let pool_post = state.get_account_by_id(IdForTests::pool_definition_id()); - let vault_a_post = state.get_account_by_id(IdForTests::vault_a_id()); - let vault_b_post = state.get_account_by_id(IdForTests::vault_b_id()); - let token_lp_post = state.get_account_by_id(IdForTests::token_lp_definition_id()); - let user_token_a_post = state.get_account_by_id(IdForTests::user_token_a_id()); - let user_token_b_post = state.get_account_by_id(IdForTests::user_token_b_id()); - let user_token_lp_post = state.get_account_by_id(IdForTests::user_token_lp_id()); - - let expected_pool = AccountForTests::pool_definition_new_init(); - let expected_vault_a = AccountForTests::vault_a_init(); - let expected_vault_b = AccountForTests::vault_b_init(); - let expected_token_lp = AccountForTests::token_lp_definition_new_init(); - let expected_user_token_a = AccountForTests::user_token_a_holding_new_init(); - let expected_user_token_b = AccountForTests::user_token_b_holding_new_init(); - let expected_user_token_lp = AccountForTests::user_token_lp_holding_new_init(); - - assert_eq!(pool_post, expected_pool); - assert_eq!(vault_a_post, expected_vault_a); - assert_eq!(vault_b_post, expected_vault_b); - assert_eq!(token_lp_post, expected_token_lp); - assert_eq!(user_token_a_post, expected_user_token_a); - assert_eq!(user_token_b_post, expected_user_token_b); - assert_eq!(user_token_lp_post, expected_user_token_lp); -} - -#[test] -fn test_simple_amm_add() { - let mut state = state_for_amm_tests(); - - let instruction = amm_core::Instruction::AddLiquidity { - min_amount_liquidity: BalanceForTests::add_min_amount_lp(), - max_amount_to_add_token_a: BalanceForTests::add_max_amount_a(), - max_amount_to_add_token_b: BalanceForTests::add_max_amount_b(), - }; - - let message = public_transaction::Message::try_new( - Program::amm().id(), - vec![ - IdForTests::pool_definition_id(), - IdForTests::vault_a_id(), - IdForTests::vault_b_id(), - IdForTests::token_lp_definition_id(), - IdForTests::user_token_a_id(), - IdForTests::user_token_b_id(), - IdForTests::user_token_lp_id(), - ], - vec![0, 0], - instruction, - ) - .unwrap(); - - let witness_set = public_transaction::WitnessSet::for_message( - &message, - &[ - &PrivateKeysForTests::user_token_a_key(), - &PrivateKeysForTests::user_token_b_key(), - ], - ); - - let tx = PublicTransaction::new(message, witness_set); - state.transition_from_public_transaction(&tx).unwrap(); - - let pool_post = state.get_account_by_id(IdForTests::pool_definition_id()); - let vault_a_post = state.get_account_by_id(IdForTests::vault_a_id()); - let vault_b_post = state.get_account_by_id(IdForTests::vault_b_id()); - let token_lp_post = state.get_account_by_id(IdForTests::token_lp_definition_id()); - let user_token_a_post = state.get_account_by_id(IdForTests::user_token_a_id()); - let user_token_b_post = state.get_account_by_id(IdForTests::user_token_b_id()); - let user_token_lp_post = state.get_account_by_id(IdForTests::user_token_lp_id()); - - let expected_pool = AccountForTests::pool_definition_add(); - let expected_vault_a = AccountForTests::vault_a_add(); - let expected_vault_b = AccountForTests::vault_b_add(); - let expected_token_lp = AccountForTests::token_lp_definition_add(); - let expected_user_token_a = AccountForTests::user_token_a_holding_add(); - let expected_user_token_b = AccountForTests::user_token_b_holding_add(); - let expected_user_token_lp = AccountForTests::user_token_lp_holding_add(); - - assert_eq!(pool_post, expected_pool); - assert_eq!(vault_a_post, expected_vault_a); - assert_eq!(vault_b_post, expected_vault_b); - assert_eq!(token_lp_post, expected_token_lp); - assert_eq!(user_token_a_post, expected_user_token_a); - assert_eq!(user_token_b_post, expected_user_token_b); - assert_eq!(user_token_lp_post, expected_user_token_lp); -} - -#[test] -fn test_simple_amm_swap_1() { - let mut state = state_for_amm_tests(); - - let instruction = amm_core::Instruction::Swap { - swap_amount_in: BalanceForTests::swap_amount_in(), - min_amount_out: BalanceForTests::swap_min_amount_out(), - token_definition_id_in: IdForTests::token_b_definition_id(), - }; - - let message = public_transaction::Message::try_new( - Program::amm().id(), - vec![ - IdForTests::pool_definition_id(), - IdForTests::vault_a_id(), - IdForTests::vault_b_id(), - IdForTests::user_token_a_id(), - IdForTests::user_token_b_id(), - ], - vec![0], - instruction, - ) - .unwrap(); - - let witness_set = public_transaction::WitnessSet::for_message( - &message, - &[&PrivateKeysForTests::user_token_b_key()], - ); - - let tx = PublicTransaction::new(message, witness_set); - state.transition_from_public_transaction(&tx).unwrap(); - - let pool_post = state.get_account_by_id(IdForTests::pool_definition_id()); - let vault_a_post = state.get_account_by_id(IdForTests::vault_a_id()); - let vault_b_post = state.get_account_by_id(IdForTests::vault_b_id()); - let user_token_a_post = state.get_account_by_id(IdForTests::user_token_a_id()); - let user_token_b_post = state.get_account_by_id(IdForTests::user_token_b_id()); - - let expected_pool = AccountForTests::pool_definition_swap_1(); - let expected_vault_a = AccountForTests::vault_a_swap_1(); - let expected_vault_b = AccountForTests::vault_b_swap_1(); - let expected_user_token_a = AccountForTests::user_token_a_holding_swap_1(); - let expected_user_token_b = AccountForTests::user_token_b_holding_swap_1(); - - assert_eq!(pool_post, expected_pool); - assert_eq!(vault_a_post, expected_vault_a); - assert_eq!(vault_b_post, expected_vault_b); - assert_eq!(user_token_a_post, expected_user_token_a); - assert_eq!(user_token_b_post, expected_user_token_b); -} - -#[test] -fn test_simple_amm_swap_2() { - let mut state = state_for_amm_tests(); - - let instruction = amm_core::Instruction::Swap { - swap_amount_in: BalanceForTests::swap_amount_in(), - min_amount_out: BalanceForTests::swap_min_amount_out(), - token_definition_id_in: IdForTests::token_a_definition_id(), - }; - let message = public_transaction::Message::try_new( - Program::amm().id(), - vec![ - IdForTests::pool_definition_id(), - IdForTests::vault_a_id(), - IdForTests::vault_b_id(), - IdForTests::user_token_a_id(), - IdForTests::user_token_b_id(), - ], - vec![0], - instruction, - ) - .unwrap(); - - let witness_set = public_transaction::WitnessSet::for_message( - &message, - &[&PrivateKeysForTests::user_token_a_key()], - ); - - let tx = PublicTransaction::new(message, witness_set); - state.transition_from_public_transaction(&tx).unwrap(); - - let pool_post = state.get_account_by_id(IdForTests::pool_definition_id()); - let vault_a_post = state.get_account_by_id(IdForTests::vault_a_id()); - let vault_b_post = state.get_account_by_id(IdForTests::vault_b_id()); - let user_token_a_post = state.get_account_by_id(IdForTests::user_token_a_id()); - let user_token_b_post = state.get_account_by_id(IdForTests::user_token_b_id()); - - let expected_pool = AccountForTests::pool_definition_swap_2(); - let expected_vault_a = AccountForTests::vault_a_swap_2(); - let expected_vault_b = AccountForTests::vault_b_swap_2(); - let expected_user_token_a = AccountForTests::user_token_a_holding_swap_2(); - let expected_user_token_b = AccountForTests::user_token_b_holding_swap_2(); - - assert_eq!(pool_post, expected_pool); - assert_eq!(vault_a_post, expected_vault_a); - assert_eq!(vault_b_post, expected_vault_b); - assert_eq!(user_token_a_post, expected_user_token_a); - assert_eq!(user_token_b_post, expected_user_token_b); -} diff --git a/programs/amm/src/tests.rs b/programs/amm/src/tests.rs index 9aa4bce6..9509d39e 100644 --- a/programs/amm/src/tests.rs +++ b/programs/amm/src/tests.rs @@ -1168,8 +1168,7 @@ impl BalanceForExeTests { fn lp_supply_init() -> u128 { // isqrt(vault_a_balance_init * vault_b_balance_init) = isqrt(5_000 * 2_500) = 3535 - (BalanceForExeTests::vault_a_balance_init() * BalanceForExeTests::vault_b_balance_init()) - .isqrt() + (Self::vault_a_balance_init() * Self::vault_b_balance_init()).isqrt() } } @@ -1178,16 +1177,13 @@ impl IdForExeTests { fn pool_definition_id() -> AccountId { amm_core::compute_pool_pda( Program::amm().id(), - IdForExeTests::token_a_definition_id(), - IdForExeTests::token_b_definition_id(), + Self::token_a_definition_id(), + Self::token_b_definition_id(), ) } fn token_lp_definition_id() -> AccountId { - amm_core::compute_liquidity_token_pda( - Program::amm().id(), - IdForExeTests::pool_definition_id(), - ) + amm_core::compute_liquidity_token_pda(Program::amm().id(), Self::pool_definition_id()) } fn token_a_definition_id() -> AccountId { @@ -1219,16 +1215,16 @@ impl IdForExeTests { fn vault_a_id() -> AccountId { amm_core::compute_vault_pda( Program::amm().id(), - IdForExeTests::pool_definition_id(), - IdForExeTests::token_a_definition_id(), + Self::pool_definition_id(), + Self::token_a_definition_id(), ) } fn vault_b_id() -> AccountId { amm_core::compute_vault_pda( Program::amm().id(), - IdForExeTests::pool_definition_id(), - IdForExeTests::token_b_definition_id(), + Self::pool_definition_id(), + Self::token_b_definition_id(), ) } } @@ -1238,7 +1234,7 @@ impl AccountsForExeTests { fn user_token_a_holding() -> Account { Account { program_owner: Program::token().id(), - balance: 0u128, + balance: 0_u128, data: Data::from(&TokenHolding::Fungible { definition_id: IdForExeTests::token_a_definition_id(), balance: BalanceForExeTests::user_token_a_holding_init(), @@ -1250,7 +1246,7 @@ impl AccountsForExeTests { fn user_token_b_holding() -> Account { Account { program_owner: Program::token().id(), - balance: 0u128, + balance: 0_u128, data: Data::from(&TokenHolding::Fungible { definition_id: IdForExeTests::token_b_definition_id(), balance: BalanceForExeTests::user_token_b_holding_init(), @@ -1262,7 +1258,7 @@ impl AccountsForExeTests { fn pool_definition_init() -> Account { Account { program_owner: Program::amm().id(), - balance: 0u128, + balance: 0_u128, data: Data::from(&PoolDefinition { definition_token_a_id: IdForExeTests::token_a_definition_id(), definition_token_b_id: IdForExeTests::token_b_definition_id(), @@ -1272,7 +1268,7 @@ impl AccountsForExeTests { liquidity_pool_supply: BalanceForExeTests::pool_lp_supply_init(), reserve_a: BalanceForExeTests::vault_a_balance_init(), reserve_b: BalanceForExeTests::vault_b_balance_init(), - fees: 0u128, + fees: 0_u128, active: true, }), nonce: 0, @@ -1282,7 +1278,7 @@ impl AccountsForExeTests { fn token_a_definition_account() -> Account { Account { program_owner: Program::token().id(), - balance: 0u128, + balance: 0_u128, data: Data::from(&TokenDefinition::Fungible { name: String::from("test"), total_supply: BalanceForExeTests::token_a_supply(), @@ -1295,7 +1291,7 @@ impl AccountsForExeTests { fn token_b_definition_acc() -> Account { Account { program_owner: Program::token().id(), - balance: 0u128, + balance: 0_u128, data: Data::from(&TokenDefinition::Fungible { name: String::from("test"), total_supply: BalanceForExeTests::token_b_supply(), @@ -1308,7 +1304,7 @@ impl AccountsForExeTests { fn token_lp_definition_acc() -> Account { Account { program_owner: Program::token().id(), - balance: 0u128, + balance: 0_u128, data: Data::from(&TokenDefinition::Fungible { name: String::from("LP Token"), total_supply: BalanceForExeTests::token_lp_supply(), @@ -1321,7 +1317,7 @@ impl AccountsForExeTests { fn vault_a_init() -> Account { Account { program_owner: Program::token().id(), - balance: 0u128, + balance: 0_u128, data: Data::from(&TokenHolding::Fungible { definition_id: IdForExeTests::token_a_definition_id(), balance: BalanceForExeTests::vault_a_balance_init(), @@ -1333,7 +1329,7 @@ impl AccountsForExeTests { fn vault_b_init() -> Account { Account { program_owner: Program::token().id(), - balance: 0u128, + balance: 0_u128, data: Data::from(&TokenHolding::Fungible { definition_id: IdForExeTests::token_b_definition_id(), balance: BalanceForExeTests::vault_b_balance_init(), @@ -1345,7 +1341,7 @@ impl AccountsForExeTests { fn user_token_lp_holding() -> Account { Account { program_owner: Program::token().id(), - balance: 0u128, + balance: 0_u128, data: Data::from(&TokenHolding::Fungible { definition_id: IdForExeTests::token_lp_definition_id(), balance: BalanceForExeTests::user_token_lp_holding_init(), @@ -1357,7 +1353,7 @@ impl AccountsForExeTests { fn vault_a_swap_1() -> Account { Account { program_owner: Program::token().id(), - balance: 0u128, + balance: 0_u128, data: Data::from(&TokenHolding::Fungible { definition_id: IdForExeTests::token_a_definition_id(), balance: BalanceForExeTests::vault_a_balance_swap_1(), @@ -1369,7 +1365,7 @@ impl AccountsForExeTests { fn vault_b_swap_1() -> Account { Account { program_owner: Program::token().id(), - balance: 0u128, + balance: 0_u128, data: Data::from(&TokenHolding::Fungible { definition_id: IdForExeTests::token_b_definition_id(), balance: BalanceForExeTests::vault_b_balance_swap_1(), @@ -1381,7 +1377,7 @@ impl AccountsForExeTests { fn pool_definition_swap_1() -> Account { Account { program_owner: Program::amm().id(), - balance: 0u128, + balance: 0_u128, data: Data::from(&PoolDefinition { definition_token_a_id: IdForExeTests::token_a_definition_id(), definition_token_b_id: IdForExeTests::token_b_definition_id(), @@ -1391,7 +1387,7 @@ impl AccountsForExeTests { liquidity_pool_supply: BalanceForExeTests::pool_lp_supply_init(), reserve_a: BalanceForExeTests::vault_a_balance_swap_1(), reserve_b: BalanceForExeTests::vault_b_balance_swap_1(), - fees: 0u128, + fees: 0_u128, active: true, }), nonce: 0, @@ -1401,7 +1397,7 @@ impl AccountsForExeTests { fn user_token_a_holding_swap_1() -> Account { Account { program_owner: Program::token().id(), - balance: 0u128, + balance: 0_u128, data: Data::from(&TokenHolding::Fungible { definition_id: IdForExeTests::token_a_definition_id(), balance: BalanceForExeTests::user_token_a_holding_swap_1(), @@ -1413,7 +1409,7 @@ impl AccountsForExeTests { fn user_token_b_holding_swap_1() -> Account { Account { program_owner: Program::token().id(), - balance: 0u128, + balance: 0_u128, data: Data::from(&TokenHolding::Fungible { definition_id: IdForExeTests::token_b_definition_id(), balance: BalanceForExeTests::user_token_b_holding_swap_1(), @@ -1425,7 +1421,7 @@ impl AccountsForExeTests { fn vault_a_swap_2() -> Account { Account { program_owner: Program::token().id(), - balance: 0u128, + balance: 0_u128, data: Data::from(&TokenHolding::Fungible { definition_id: IdForExeTests::token_a_definition_id(), balance: BalanceForExeTests::vault_a_balance_swap_2(), @@ -1437,7 +1433,7 @@ impl AccountsForExeTests { fn vault_b_swap_2() -> Account { Account { program_owner: Program::token().id(), - balance: 0u128, + balance: 0_u128, data: Data::from(&TokenHolding::Fungible { definition_id: IdForExeTests::token_b_definition_id(), balance: BalanceForExeTests::vault_b_balance_swap_2(), @@ -1449,7 +1445,7 @@ impl AccountsForExeTests { fn pool_definition_swap_2() -> Account { Account { program_owner: Program::amm().id(), - balance: 0u128, + balance: 0_u128, data: Data::from(&PoolDefinition { definition_token_a_id: IdForExeTests::token_a_definition_id(), definition_token_b_id: IdForExeTests::token_b_definition_id(), @@ -1459,7 +1455,7 @@ impl AccountsForExeTests { liquidity_pool_supply: BalanceForExeTests::pool_lp_supply_init(), reserve_a: BalanceForExeTests::vault_a_balance_swap_2(), reserve_b: BalanceForExeTests::vault_b_balance_swap_2(), - fees: 0u128, + fees: 0_u128, active: true, }), nonce: 0, @@ -1469,7 +1465,7 @@ impl AccountsForExeTests { fn user_token_a_holding_swap_2() -> Account { Account { program_owner: Program::token().id(), - balance: 0u128, + balance: 0_u128, data: Data::from(&TokenHolding::Fungible { definition_id: IdForExeTests::token_a_definition_id(), balance: BalanceForExeTests::user_token_a_holding_swap_2(), @@ -1481,7 +1477,7 @@ impl AccountsForExeTests { fn user_token_b_holding_swap_2() -> Account { Account { program_owner: Program::token().id(), - balance: 0u128, + balance: 0_u128, data: Data::from(&TokenHolding::Fungible { definition_id: IdForExeTests::token_b_definition_id(), balance: BalanceForExeTests::user_token_b_holding_swap_2(), @@ -1493,7 +1489,7 @@ impl AccountsForExeTests { fn vault_a_add() -> Account { Account { program_owner: Program::token().id(), - balance: 0u128, + balance: 0_u128, data: Data::from(&TokenHolding::Fungible { definition_id: IdForExeTests::token_a_definition_id(), balance: BalanceForExeTests::vault_a_balance_add(), @@ -1505,7 +1501,7 @@ impl AccountsForExeTests { fn vault_b_add() -> Account { Account { program_owner: Program::token().id(), - balance: 0u128, + balance: 0_u128, data: Data::from(&TokenHolding::Fungible { definition_id: IdForExeTests::token_b_definition_id(), balance: BalanceForExeTests::vault_b_balance_add(), @@ -1517,7 +1513,7 @@ impl AccountsForExeTests { fn pool_definition_add() -> Account { Account { program_owner: Program::amm().id(), - balance: 0u128, + balance: 0_u128, data: Data::from(&PoolDefinition { definition_token_a_id: IdForExeTests::token_a_definition_id(), definition_token_b_id: IdForExeTests::token_b_definition_id(), @@ -1527,7 +1523,7 @@ impl AccountsForExeTests { liquidity_pool_supply: BalanceForExeTests::token_lp_supply_add(), reserve_a: BalanceForExeTests::vault_a_balance_add(), reserve_b: BalanceForExeTests::vault_b_balance_add(), - fees: 0u128, + fees: 0_u128, active: true, }), nonce: 0, @@ -1537,7 +1533,7 @@ impl AccountsForExeTests { fn user_token_a_holding_add() -> Account { Account { program_owner: Program::token().id(), - balance: 0u128, + balance: 0_u128, data: Data::from(&TokenHolding::Fungible { definition_id: IdForExeTests::token_a_definition_id(), balance: BalanceForExeTests::user_token_a_holding_add(), @@ -1549,7 +1545,7 @@ impl AccountsForExeTests { fn user_token_b_holding_add() -> Account { Account { program_owner: Program::token().id(), - balance: 0u128, + balance: 0_u128, data: Data::from(&TokenHolding::Fungible { definition_id: IdForExeTests::token_b_definition_id(), balance: BalanceForExeTests::user_token_b_holding_add(), @@ -1561,7 +1557,7 @@ impl AccountsForExeTests { fn user_token_lp_holding_add() -> Account { Account { program_owner: Program::token().id(), - balance: 0u128, + balance: 0_u128, data: Data::from(&TokenHolding::Fungible { definition_id: IdForExeTests::token_lp_definition_id(), balance: BalanceForExeTests::user_token_lp_holding_add(), @@ -1573,7 +1569,7 @@ impl AccountsForExeTests { fn token_lp_definition_add() -> Account { Account { program_owner: Program::token().id(), - balance: 0u128, + balance: 0_u128, data: Data::from(&TokenDefinition::Fungible { name: String::from("LP Token"), total_supply: BalanceForExeTests::token_lp_supply_add(), @@ -1586,7 +1582,7 @@ impl AccountsForExeTests { fn vault_a_remove() -> Account { Account { program_owner: Program::token().id(), - balance: 0u128, + balance: 0_u128, data: Data::from(&TokenHolding::Fungible { definition_id: IdForExeTests::token_a_definition_id(), balance: BalanceForExeTests::vault_a_balance_remove(), @@ -1598,7 +1594,7 @@ impl AccountsForExeTests { fn vault_b_remove() -> Account { Account { program_owner: Program::token().id(), - balance: 0u128, + balance: 0_u128, data: Data::from(&TokenHolding::Fungible { definition_id: IdForExeTests::token_b_definition_id(), balance: BalanceForExeTests::vault_b_balance_remove(), @@ -1610,7 +1606,7 @@ impl AccountsForExeTests { fn pool_definition_remove() -> Account { Account { program_owner: Program::amm().id(), - balance: 0u128, + balance: 0_u128, data: Data::from(&PoolDefinition { definition_token_a_id: IdForExeTests::token_a_definition_id(), definition_token_b_id: IdForExeTests::token_b_definition_id(), @@ -1620,7 +1616,7 @@ impl AccountsForExeTests { liquidity_pool_supply: BalanceForExeTests::token_lp_supply_remove(), reserve_a: BalanceForExeTests::vault_a_balance_remove(), reserve_b: BalanceForExeTests::vault_b_balance_remove(), - fees: 0u128, + fees: 0_u128, active: true, }), nonce: 0, @@ -1630,7 +1626,7 @@ impl AccountsForExeTests { fn user_token_a_holding_remove() -> Account { Account { program_owner: Program::token().id(), - balance: 0u128, + balance: 0_u128, data: Data::from(&TokenHolding::Fungible { definition_id: IdForExeTests::token_a_definition_id(), balance: BalanceForExeTests::user_token_a_holding_remove(), @@ -1642,7 +1638,7 @@ impl AccountsForExeTests { fn user_token_b_holding_remove() -> Account { Account { program_owner: Program::token().id(), - balance: 0u128, + balance: 0_u128, data: Data::from(&TokenHolding::Fungible { definition_id: IdForExeTests::token_b_definition_id(), balance: BalanceForExeTests::user_token_b_holding_remove(), @@ -1654,7 +1650,7 @@ impl AccountsForExeTests { fn user_token_lp_holding_remove() -> Account { Account { program_owner: Program::token().id(), - balance: 0u128, + balance: 0_u128, data: Data::from(&TokenHolding::Fungible { definition_id: IdForExeTests::token_lp_definition_id(), balance: BalanceForExeTests::user_token_lp_holding_remove(), @@ -1666,7 +1662,7 @@ impl AccountsForExeTests { fn token_lp_definition_remove() -> Account { Account { program_owner: Program::token().id(), - balance: 0u128, + balance: 0_u128, data: Data::from(&TokenDefinition::Fungible { name: String::from("LP Token"), total_supply: BalanceForExeTests::token_lp_supply_remove(), @@ -1679,7 +1675,7 @@ impl AccountsForExeTests { fn token_lp_definition_init_inactive() -> Account { Account { program_owner: Program::token().id(), - balance: 0u128, + balance: 0_u128, data: Data::from(&TokenDefinition::Fungible { name: String::from("LP Token"), total_supply: 0, @@ -1692,7 +1688,7 @@ impl AccountsForExeTests { fn vault_a_init_inactive() -> Account { Account { program_owner: Program::token().id(), - balance: 0u128, + balance: 0_u128, data: Data::from(&TokenHolding::Fungible { definition_id: IdForExeTests::token_a_definition_id(), balance: 0, @@ -1704,7 +1700,7 @@ impl AccountsForExeTests { fn vault_b_init_inactive() -> Account { Account { program_owner: Program::token().id(), - balance: 0u128, + balance: 0_u128, data: Data::from(&TokenHolding::Fungible { definition_id: IdForExeTests::token_b_definition_id(), balance: 0, @@ -1716,7 +1712,7 @@ impl AccountsForExeTests { fn pool_definition_inactive() -> Account { Account { program_owner: Program::amm().id(), - balance: 0u128, + balance: 0_u128, data: Data::from(&PoolDefinition { definition_token_a_id: IdForExeTests::token_a_definition_id(), definition_token_b_id: IdForExeTests::token_b_definition_id(), @@ -1726,7 +1722,7 @@ impl AccountsForExeTests { liquidity_pool_supply: 0, reserve_a: 0, reserve_b: 0, - fees: 0u128, + fees: 0_u128, active: false, }), nonce: 0, @@ -1736,7 +1732,7 @@ impl AccountsForExeTests { fn user_token_a_holding_new_init() -> Account { Account { program_owner: Program::token().id(), - balance: 0u128, + balance: 0_u128, data: Data::from(&TokenHolding::Fungible { definition_id: IdForExeTests::token_a_definition_id(), balance: BalanceForExeTests::user_token_a_holding_new_definition(), @@ -1748,7 +1744,7 @@ impl AccountsForExeTests { fn user_token_b_holding_new_init() -> Account { Account { program_owner: Program::token().id(), - balance: 0u128, + balance: 0_u128, data: Data::from(&TokenHolding::Fungible { definition_id: IdForExeTests::token_b_definition_id(), balance: BalanceForExeTests::user_token_b_holding_new_definition(), @@ -1760,7 +1756,7 @@ impl AccountsForExeTests { fn user_token_lp_holding_new_init() -> Account { Account { program_owner: Program::token().id(), - balance: 0u128, + balance: 0_u128, data: Data::from(&TokenHolding::Fungible { definition_id: IdForExeTests::token_lp_definition_id(), balance: BalanceForExeTests::lp_supply_init(), @@ -1772,7 +1768,7 @@ impl AccountsForExeTests { fn token_lp_definition_new_init() -> Account { Account { program_owner: Program::token().id(), - balance: 0u128, + balance: 0_u128, data: Data::from(&TokenDefinition::Fungible { name: String::from("LP Token"), total_supply: BalanceForExeTests::lp_supply_init(), @@ -1785,7 +1781,7 @@ impl AccountsForExeTests { fn pool_definition_new_init() -> Account { Account { program_owner: Program::amm().id(), - balance: 0u128, + balance: 0_u128, data: Data::from(&PoolDefinition { definition_token_a_id: IdForExeTests::token_a_definition_id(), definition_token_b_id: IdForExeTests::token_b_definition_id(), @@ -1795,7 +1791,7 @@ impl AccountsForExeTests { liquidity_pool_supply: BalanceForExeTests::lp_supply_init(), reserve_a: BalanceForExeTests::vault_a_balance_init(), reserve_b: BalanceForExeTests::vault_b_balance_init(), - fees: 0u128, + fees: 0_u128, active: true, }), nonce: 0, @@ -1805,7 +1801,7 @@ impl AccountsForExeTests { fn user_token_lp_holding_init_zero() -> Account { Account { program_owner: Program::token().id(), - balance: 0u128, + balance: 0_u128, data: Data::from(&TokenHolding::Fungible { definition_id: IdForExeTests::token_lp_definition_id(), balance: 0, @@ -2714,7 +2710,7 @@ fn state_for_amm_tests_with_new_def() -> V02State { #[cfg(feature = "nssa")] #[test] -fn test_simple_amm_remove() { +fn simple_amm_remove() { let mut state = state_for_amm_tests(); let instruction = amm_core::Instruction::RemoveLiquidity { @@ -2774,7 +2770,7 @@ fn test_simple_amm_remove() { #[cfg(feature = "nssa")] #[test] -fn test_simple_amm_new_definition_inactive_initialized_pool_and_uninit_user_lp() { +fn simple_amm_new_definition_inactive_initialized_pool_and_uninit_user_lp() { let mut state = state_for_amm_tests_with_new_def(); // Uninitialized in constructor @@ -2855,7 +2851,7 @@ fn test_simple_amm_new_definition_inactive_initialized_pool_and_uninit_user_lp() #[cfg(feature = "nssa")] #[test] -fn test_simple_amm_new_definition_inactive_initialized_pool_init_user_lp() { +fn simple_amm_new_definition_inactive_initialized_pool_init_user_lp() { let mut state = state_for_amm_tests_with_new_def(); // Uninitialized in constructor @@ -2940,7 +2936,7 @@ fn test_simple_amm_new_definition_inactive_initialized_pool_init_user_lp() { #[cfg(feature = "nssa")] #[test] -fn test_simple_amm_new_definition_uninitialized_pool() { +fn simple_amm_new_definition_uninitialized_pool() { let mut state = state_for_amm_tests_with_new_def(); // Uninitialized in constructor @@ -3013,7 +3009,7 @@ fn test_simple_amm_new_definition_uninitialized_pool() { #[cfg(feature = "nssa")] #[test] -fn test_simple_amm_add() { +fn simple_amm_add() { let mut state = state_for_amm_tests(); let instruction = amm_core::Instruction::AddLiquidity { @@ -3076,7 +3072,7 @@ fn test_simple_amm_add() { #[cfg(feature = "nssa")] #[test] -fn test_simple_amm_swap_1() { +fn simple_amm_swap_1() { let mut state = state_for_amm_tests(); let instruction = amm_core::Instruction::Swap { @@ -3128,7 +3124,7 @@ fn test_simple_amm_swap_1() { #[cfg(feature = "nssa")] #[test] -fn test_simple_amm_swap_2() { +fn simple_amm_swap_2() { let mut state = state_for_amm_tests(); let instruction = amm_core::Instruction::Swap {