diff --git a/controller/program/tests/tests/admin/add_lst.rs b/controller/program/tests/tests/admin/add_lst.rs index 8bdf9103..32d4f2fe 100644 --- a/controller/program/tests/tests/admin/add_lst.rs +++ b/controller/program/tests/tests/admin/add_lst.rs @@ -146,20 +146,21 @@ fn add_lst_jitosol_fixture() { let ix = add_lst_ix(&keys); let mut accounts = add_lst_fixtures_accounts_opt(&keys); - accounts.insert( - Pubkey::new_from_array(admin), - Account { - lamports: u64::MAX, - ..Default::default() - }, - ); - - accounts.insert( - Pubkey::new_from_array(PROTOCOL_FEE_ID), - Account { - ..Default::default() - }, - ); + accounts.extend([ + ( + Pubkey::new_from_array(admin), + Account { + lamports: u64::MAX, + ..Default::default() + }, + ), + ( + Pubkey::new_from_array(PROTOCOL_FEE_ID), + Account { + ..Default::default() + }, + ), + ]); let ( accounts, @@ -213,51 +214,51 @@ fn add_lst_proptest( let ix = add_lst_ix(&keys); let mut accounts = add_lst_fixtures_accounts_opt(&keys); - // Common inserts - accounts.insert( - LST_STATE_LIST_ID.into(), - lst_state_list_account(lst_state_list), - ); - accounts.insert(POOL_STATE_ID.into(), pool_state_account(pool)); - accounts.insert( - Pubkey::new_from_array(admin), - Account { - ..Default::default() - }, - ); - accounts.insert( - Pubkey::new_from_array(payer), - Account { - lamports: u64::MAX, - ..Default::default() - }, - ); - accounts.insert( - Pubkey::new_from_array(PROTOCOL_FEE_ID), - Account { - ..Default::default() - }, - ); - let (pool_reserves_addr, _) = find_pool_reserves_ata(&token_program, &mint); let (protocol_fee_accumulator_addr, _) = find_protocol_fee_accumulator_ata(&token_program, &mint); - accounts.insert( - pool_reserves_addr, - mock_token_acc(raw_token_acc(mint, POOL_STATE_ID, 0)), - ); - - accounts.insert( - protocol_fee_accumulator_addr, - mock_token_acc(raw_token_acc(mint, PROTOCOL_FEE_ID, 0)), + accounts.extend( + [ + // Common accounts + ( + LST_STATE_LIST_ID.into(), + lst_state_list_account(lst_state_list), + ), + (POOL_STATE_ID.into(), pool_state_account(pool)), + ( + Pubkey::new_from_array(admin), + Account { + ..Default::default() + }, + ), + ( + Pubkey::new_from_array(payer), + Account { + lamports: u64::MAX, + ..Default::default() + }, + ), + ( + Pubkey::new_from_array(PROTOCOL_FEE_ID), + Account { + ..Default::default() + }, + ), + ( + pool_reserves_addr, + mock_token_acc(raw_token_acc(mint, POOL_STATE_ID, 0)), + ), + ( + protocol_fee_accumulator_addr, + mock_token_acc(raw_token_acc(mint, PROTOCOL_FEE_ID, 0)), + ), + ] + // Additional test-specific accounts + .into_iter() + .chain(additional_accounts), ); - // Additional test-specific inserts - for (pk, acc) in additional_accounts { - accounts.insert(pk, acc); - } - let ( accounts, InstructionResult { diff --git a/controller/program/tests/tests/admin/remove_lst.rs b/controller/program/tests/tests/admin/remove_lst.rs index b39ed5b8..6842023a 100644 --- a/controller/program/tests/tests/admin/remove_lst.rs +++ b/controller/program/tests/tests/admin/remove_lst.rs @@ -156,48 +156,45 @@ fn remove_lst_jupsol_fixture() { let ix = remove_lst_ix(&keys, jupsol_idx as u32); let mut accounts = remove_lst_fixtures_accounts_opt(&keys); - // Insert the modified LST state list - accounts.insert( - Pubkey::new_from_array(LST_STATE_LIST_ID), - lst_state_list_account(lst_state_list_data), - ); - - accounts.insert( - Pubkey::new_from_array(admin), - Account { - lamports: u64::MAX, - ..Default::default() - }, - ); - - accounts.insert( - Pubkey::new_from_array(refund_rent_to), - Account { - ..Default::default() - }, - ); - - accounts.insert( - Pubkey::new_from_array(PROTOCOL_FEE_ID), - Account { - ..Default::default() - }, - ); - - // Add the ATAs with zero balance let (pool_reserves_addr, _) = find_pool_reserves_ata(token_program, &JUPSOL_MINT.to_bytes()); let (protocol_fee_accumulator_addr, _) = find_protocol_fee_accumulator_ata(token_program, &JUPSOL_MINT.to_bytes()); - accounts.insert( - pool_reserves_addr, - mock_token_acc(raw_token_acc(JUPSOL_MINT.to_bytes(), POOL_STATE_ID, 0)), - ); - - accounts.insert( - protocol_fee_accumulator_addr, - mock_token_acc(raw_token_acc(JUPSOL_MINT.to_bytes(), PROTOCOL_FEE_ID, 0)), - ); + // Add the modified LST state list and accounts + accounts.extend([ + ( + Pubkey::new_from_array(LST_STATE_LIST_ID), + lst_state_list_account(lst_state_list_data), + ), + ( + Pubkey::new_from_array(admin), + Account { + lamports: u64::MAX, + ..Default::default() + }, + ), + ( + Pubkey::new_from_array(refund_rent_to), + Account { + ..Default::default() + }, + ), + ( + Pubkey::new_from_array(PROTOCOL_FEE_ID), + Account { + ..Default::default() + }, + ), + // Add the ATAs with zero balance + ( + pool_reserves_addr, + mock_token_acc(raw_token_acc(JUPSOL_MINT.to_bytes(), POOL_STATE_ID, 0)), + ), + ( + protocol_fee_accumulator_addr, + mock_token_acc(raw_token_acc(JUPSOL_MINT.to_bytes(), PROTOCOL_FEE_ID, 0)), + ), + ]); let ( accounts, @@ -252,48 +249,49 @@ fn remove_lst_proptest( let ix = remove_lst_ix(&keys, lst_idx); let mut accounts = remove_lst_fixtures_accounts_opt(&keys); - // Common inserts - accounts.insert( - LST_STATE_LIST_ID.into(), - lst_state_list_account(lst_state_list), - ); - accounts.insert(POOL_STATE_ID.into(), pool_state_account(pool)); - accounts.insert( - Pubkey::new_from_array(admin), - Account { - lamports: u64::MAX, - ..Default::default() - }, - ); - accounts.insert( - Pubkey::new_from_array(refund_rent_to), - Account { - ..Default::default() - }, - ); - accounts.insert( - Pubkey::new_from_array(mint), - mock_mint(raw_mint(None, None, u64::MAX, 9)), - ); - accounts.insert(Pubkey::new_from_array(PROTOCOL_FEE_ID), Account::default()); - let (pool_reserves_addr, _) = find_pool_reserves_ata(&TOKENKEG_ID, &mint); let (protocol_fee_accumulator_addr, _) = find_protocol_fee_accumulator_ata(&TOKENKEG_ID, &mint); - accounts.insert( - pool_reserves_addr, - mock_token_acc(raw_token_acc(mint, POOL_STATE_ID, 0)), - ); - accounts.insert( - protocol_fee_accumulator_addr, - mock_token_acc(raw_token_acc(mint, PROTOCOL_FEE_ID, 0)), + accounts.extend( + [ + // Common accounts + ( + LST_STATE_LIST_ID.into(), + lst_state_list_account(lst_state_list), + ), + (POOL_STATE_ID.into(), pool_state_account(pool)), + ( + Pubkey::new_from_array(admin), + Account { + lamports: u64::MAX, + ..Default::default() + }, + ), + ( + Pubkey::new_from_array(refund_rent_to), + Account { + ..Default::default() + }, + ), + ( + Pubkey::new_from_array(mint), + mock_mint(raw_mint(None, None, u64::MAX, 9)), + ), + (Pubkey::new_from_array(PROTOCOL_FEE_ID), Account::default()), + ( + pool_reserves_addr, + mock_token_acc(raw_token_acc(mint, POOL_STATE_ID, 0)), + ), + ( + protocol_fee_accumulator_addr, + mock_token_acc(raw_token_acc(mint, PROTOCOL_FEE_ID, 0)), + ), + ] + // Additional test-specific accounts + .into_iter() + .chain(additional_accounts), ); - // Additional test-specific inserts - for (pk, acc) in additional_accounts { - accounts.insert(pk, acc); - } - let ( accounts, InstructionResult { diff --git a/controller/program/tests/tests/admin/set_sol_value_calculator.rs b/controller/program/tests/tests/admin/set_sol_value_calculator.rs index 1116593b..14094252 100644 --- a/controller/program/tests/tests/admin/set_sol_value_calculator.rs +++ b/controller/program/tests/tests/admin/set_sol_value_calculator.rs @@ -176,14 +176,6 @@ fn set_sol_value_calculator_jupsol_fixture() { let ix = set_sol_value_calculator_ix(&builder, JUPSOL_FIXTURE_LST_IDX as u32); let mut accounts = set_sol_value_calculator_fixtures_accounts_opt(&builder); - accounts.insert( - Pubkey::new_from_array(admin), - Account { - lamports: u64::MAX, - ..Default::default() - }, - ); - let lsl_pk = Pubkey::new_from_array(LST_STATE_LIST_ID); let lsl_acc = ALL_FIXTURES.get(&lsl_pk).unwrap().clone(); let mut lsl_data = lsl_acc.data.to_vec(); @@ -199,7 +191,16 @@ fn set_sol_value_calculator_jupsol_fixture() { }; lst_mut.sol_value_calculator = Pubkey::new_unique().to_bytes(); - accounts.insert(lsl_pk, lst_state_list_account(lsl_data)); + accounts.extend([ + ( + Pubkey::new_from_array(admin), + Account { + lamports: u64::MAX, + ..Default::default() + }, + ), + (lsl_pk, lst_state_list_account(lsl_data)), + ]); let ( accounts, @@ -259,26 +260,28 @@ fn set_sol_value_calculator_proptest( let ix = set_sol_value_calculator_ix(&builder, lst_idx as u32); let mut accounts = set_sol_value_calculator_fixtures_accounts_opt(&builder); - // Common inserts - accounts.insert(LST_STATE_LIST_ID.into(), lst_state_list_account(lsl_data)); - accounts.insert(POOL_STATE_ID.into(), pool_state_account(pool)); - accounts.insert( - Pubkey::new_from_array(admin), - Account { - lamports: u64::MAX, - ..Default::default() - }, - ); - accounts.insert( - Pubkey::new_from_array(*all_pool_reserves.get(&mint).unwrap()), - mock_token_acc(raw_token_acc(mint, POOL_STATE_ID, new_balance)), + // Common accounts + accounts.extend( + [ + (LST_STATE_LIST_ID.into(), lst_state_list_account(lsl_data)), + (POOL_STATE_ID.into(), pool_state_account(pool)), + ( + Pubkey::new_from_array(admin), + Account { + lamports: u64::MAX, + ..Default::default() + }, + ), + ( + Pubkey::new_from_array(*all_pool_reserves.get(&mint).unwrap()), + mock_token_acc(raw_token_acc(mint, POOL_STATE_ID, new_balance)), + ), + ] + // Additional test-specific accounts + .into_iter() + .chain(additional_accounts), ); - // Additional test-specific inserts - for (pk, acc) in additional_accounts { - accounts.insert(pk, acc); - } - let ( accounts, InstructionResult { diff --git a/controller/program/tests/tests/rebalance/chain.rs b/controller/program/tests/tests/rebalance/chain.rs index e0c59353..73901561 100644 --- a/controller/program/tests/tests/rebalance/chain.rs +++ b/controller/program/tests/tests/rebalance/chain.rs @@ -213,31 +213,29 @@ fn setup_rebalance_transaction_accounts( ); let (sys_prog_pk, sys_prog_acc) = keyed_account_for_system_program(); - accounts.insert(sys_prog_pk, sys_prog_acc); - - accounts.insert( - Pubkey::new_from_array(owner_accs.owner), - mock_sys_acc(100_000_000_000), - ); - - accounts.insert( - Pubkey::new_from_array(owner_accs.owner_token_account), - mock_token_acc(raw_token_acc( - fixture.inp_lsd.lst_state.mint, - owner_accs.owner, - owner_accs.owner_balance, - )), - ); - - accounts.insert( - Pubkey::new_from_array(INSTRUCTIONS_SYSVAR_ID), - mock_instructions_sysvar(instructions, 0), - ); - - accounts.insert( - Pubkey::new_from_array(REBALANCE_RECORD_ID), - Account::default(), - ); + accounts.extend([ + (sys_prog_pk, sys_prog_acc), + ( + Pubkey::new_from_array(owner_accs.owner), + mock_sys_acc(100_000_000_000), + ), + ( + Pubkey::new_from_array(owner_accs.owner_token_account), + mock_token_acc(raw_token_acc( + fixture.inp_lsd.lst_state.mint, + owner_accs.owner, + owner_accs.owner_balance, + )), + ), + ( + Pubkey::new_from_array(INSTRUCTIONS_SYSVAR_ID), + mock_instructions_sysvar(instructions, 0), + ), + ( + Pubkey::new_from_array(REBALANCE_RECORD_ID), + Account::default(), + ), + ]); accounts } diff --git a/controller/program/tests/tests/rebalance/test_utils.rs b/controller/program/tests/tests/rebalance/test_utils.rs index f17474f9..12974698 100644 --- a/controller/program/tests/tests/rebalance/test_utils.rs +++ b/controller/program/tests/tests/rebalance/test_utils.rs @@ -224,47 +224,49 @@ pub fn add_common_accounts( out_balance: u64, inp_balance: u64, ) { - accounts.insert( - LST_STATE_LIST_ID.into(), - lst_state_list_account(lst_state_list.to_vec()), - ); - accounts.insert(POOL_STATE_ID.into(), pool_state_account(*pool)); - accounts.insert( - Pubkey::new_from_array(rebalance_auth), - Account { - lamports: u64::MAX, - owner: Pubkey::new_from_array(SYSTEM_PROGRAM_ID), - ..Default::default() - }, - ); - accounts.insert( - Pubkey::new_from_array(out_mint), - mock_mint(raw_mint(None, None, 0, 9)), - ); - accounts.insert( - Pubkey::new_from_array(inp_mint), - mock_mint(raw_mint(None, None, 0, 9)), - ); - accounts.insert( - pool_reserves_map - .and_then(|m| m.get(&out_mint).copied()) - .map(Pubkey::new_from_array) - .unwrap_or_else(|| { - inf1_test_utils::find_pool_reserves_ata(&TOKENKEG_PROGRAM, &out_mint).0 - }), - mock_token_acc(raw_token_acc(out_mint, POOL_STATE_ID, out_balance)), - ); - accounts.insert( - pool_reserves_map - .and_then(|m| m.get(&inp_mint).copied()) - .map(Pubkey::new_from_array) - .unwrap_or_else(|| { - inf1_test_utils::find_pool_reserves_ata(&TOKENKEG_PROGRAM, &inp_mint).0 - }), - mock_token_acc(raw_token_acc(inp_mint, POOL_STATE_ID, inp_balance)), - ); - accounts.insert( - Pubkey::new_from_array(withdraw_to), - mock_token_acc(raw_token_acc(out_mint, withdraw_to, 0)), - ); + accounts.extend([ + ( + LST_STATE_LIST_ID.into(), + lst_state_list_account(lst_state_list.to_vec()), + ), + (POOL_STATE_ID.into(), pool_state_account(*pool)), + ( + Pubkey::new_from_array(rebalance_auth), + Account { + lamports: u64::MAX, + owner: Pubkey::new_from_array(SYSTEM_PROGRAM_ID), + ..Default::default() + }, + ), + ( + Pubkey::new_from_array(out_mint), + mock_mint(raw_mint(None, None, 0, 9)), + ), + ( + Pubkey::new_from_array(inp_mint), + mock_mint(raw_mint(None, None, 0, 9)), + ), + ( + pool_reserves_map + .and_then(|m| m.get(&out_mint).copied()) + .map(Pubkey::new_from_array) + .unwrap_or_else(|| { + inf1_test_utils::find_pool_reserves_ata(&TOKENKEG_PROGRAM, &out_mint).0 + }), + mock_token_acc(raw_token_acc(out_mint, POOL_STATE_ID, out_balance)), + ), + ( + pool_reserves_map + .and_then(|m| m.get(&inp_mint).copied()) + .map(Pubkey::new_from_array) + .unwrap_or_else(|| { + inf1_test_utils::find_pool_reserves_ata(&TOKENKEG_PROGRAM, &inp_mint).0 + }), + mock_token_acc(raw_token_acc(inp_mint, POOL_STATE_ID, inp_balance)), + ), + ( + Pubkey::new_from_array(withdraw_to), + mock_token_acc(raw_token_acc(out_mint, withdraw_to, 0)), + ), + ]); } diff --git a/controller/program/tests/tests/sync_sol_value.rs b/controller/program/tests/tests/sync_sol_value.rs index 228d534f..91b400d9 100644 --- a/controller/program/tests/tests/sync_sol_value.rs +++ b/controller/program/tests/tests/sync_sol_value.rs @@ -185,19 +185,21 @@ fn sync_sol_value_wsol_proptest( }; let ix = sync_sol_value_ix(&builder, wsol_idx as u32); let mut accounts = sync_sol_value_fixtures_accounts_opt(&builder); - accounts.insert( - LST_STATE_LIST_ID.into(), - lst_state_list_account(lst_state_list), - ); - accounts.insert(POOL_STATE_ID.into(), pool_state_account(pool)); - accounts.insert( - Pubkey::new_from_array(*all_pool_reserves.get(WSOL_MINT.as_array()).unwrap()), - mock_token_acc(raw_token_acc( - WSOL_MINT.to_bytes(), - POOL_STATE_ID, - new_balance, - )), - ); + accounts.extend([ + ( + LST_STATE_LIST_ID.into(), + lst_state_list_account(lst_state_list), + ), + (POOL_STATE_ID.into(), pool_state_account(pool)), + ( + Pubkey::new_from_array(*all_pool_reserves.get(WSOL_MINT.as_array()).unwrap()), + mock_token_acc(raw_token_acc( + WSOL_MINT.to_bytes(), + POOL_STATE_ID, + new_balance, + )), + ), + ]); let ( bef, @@ -267,30 +269,32 @@ fn sync_sol_value_sanctum_spl_multi_proptest( }; let ix = sync_sol_value_ix(&builder, lst_idx as u32); let mut accounts = sync_sol_value_fixtures_accounts_opt(&builder); - accounts.insert( - LST_STATE_LIST_ID.into(), - lst_state_list_account(lst_state_list), - ); - accounts.insert(POOL_STATE_ID.into(), pool_state_account(pool)); - accounts.insert( - Pubkey::new_from_array(*all_pool_reserves.get(&lsd.lst_state.mint).unwrap()), - mock_token_acc(raw_token_acc( - lsd.lst_state.mint, - POOL_STATE_ID, - new_balance, - )), - ); - accounts.insert( - lsd.lst_state.mint.into(), - // TODO: for more realistic testing, these should be - // set to appropriate values. But the sol value calculator - // program does not look at the mint at all - mock_mint(raw_mint(None, None, u64::MAX, 9)), - ); - accounts.insert( - Pubkey::new_from_array(stake_pool_addr), - mock_spl_stake_pool(&stake_pool, sanctum_spl_multi::POOL_PROG_ID.into()), - ); + accounts.extend([ + ( + LST_STATE_LIST_ID.into(), + lst_state_list_account(lst_state_list), + ), + (POOL_STATE_ID.into(), pool_state_account(pool)), + ( + Pubkey::new_from_array(*all_pool_reserves.get(&lsd.lst_state.mint).unwrap()), + mock_token_acc(raw_token_acc( + lsd.lst_state.mint, + POOL_STATE_ID, + new_balance, + )), + ), + ( + lsd.lst_state.mint.into(), + // TODO: for more realistic testing, these should be + // set to appropriate values. But the sol value calculator + // program does not look at the mint at all + mock_mint(raw_mint(None, None, u64::MAX, 9)), + ), + ( + Pubkey::new_from_array(stake_pool_addr), + mock_spl_stake_pool(&stake_pool, sanctum_spl_multi::POOL_PROG_ID.into()), + ), + ]); let ( bef,