Skip to content

Commit

Permalink
feat: multiple tokenPoolPda accounts (#1407)
Browse files Browse the repository at this point in the history
* feat: multiple token pool accounts

* fix: lint

* chore: unify execute token program instruction with multiple token pool accounts

---------

Co-authored-by: ananas-block <[email protected]>
  • Loading branch information
2 people authored and Swenschaeferjohann committed Dec 26, 2024
1 parent f648104 commit 0dbbbe4
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test-programs/compressed-token-test/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4112,7 +4112,10 @@ async fn test_failing_thaw() {
/// 6: invalid token recipient
/// 7. invalid token pool pda (in struct)
/// 8. invalid token pool pda (in remaining accounts)
<<<<<<< HEAD
/// 8.1. invalid derived token pool pda (in struct and remaining accounts)
=======
>>>>>>> 39262bad7 (feat: multiple `tokenPoolPda` accounts (#1407))
/// 9. FailedToDecompress pass multiple correct token accounts with insufficient balance
/// 10. invalid token pool pda from invalid mint (in struct)
/// 11. invalid token pool pda from invalid mint (in remaining accounts)
Expand Down Expand Up @@ -4391,6 +4394,7 @@ async fn test_failing_decompression() {
)
.await
.unwrap();
<<<<<<< HEAD
} // Test 8.1: invalid derived token pool pda (in struct and remaining accounts)
{
let token_account_keypair_2 = Keypair::new();
Expand Down Expand Up @@ -4450,10 +4454,22 @@ async fn test_failing_decompression() {
)
.await
.unwrap();
=======
>>>>>>> 39262bad7 (feat: multiple `tokenPoolPda` accounts (#1407))
}
// Test 9: FailedToDecompress pass multiple correct token accounts with insufficient balance
{
let token_pool = get_token_pool_pda_with_bump(&mint, 3);
<<<<<<< HEAD
=======
let mut account = context.get_account(token_pool).await.unwrap().unwrap();
println!("token pool account {:?}", token_pool);
let amount =
TokenAccount::try_deserialize_unchecked(&mut &*account.data.as_mut_slice())
.unwrap()
.amount;
println!("{:?}", amount);
>>>>>>> 39262bad7 (feat: multiple `tokenPoolPda` accounts (#1407))
failing_compress_decompress(
&sender,
&mut context,
Expand Down
32 changes: 32 additions & 0 deletions test-utils/src/spl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,11 @@ pub async fn decompress_test<R: RpcConnection, I: Indexer<R>>(
transaction_params: Option<TransactionParams>,
is_token_22: bool,
token_pool_bump: u8,
<<<<<<< HEAD
additional_pool_accounts: Option<Vec<Pubkey>>,
=======
additonal_pool_accounts: Option<Vec<Pubkey>>,
>>>>>>> 39262bad7 (feat: multiple `tokenPoolPda` accounts (#1407))
) {
let max_amount: u64 = input_compressed_accounts
.iter()
Expand Down Expand Up @@ -799,7 +803,11 @@ pub async fn decompress_test<R: RpcConnection, I: Indexer<R>>(
None,
None,
is_token_22,
<<<<<<< HEAD
additional_pool_accounts
=======
additonal_pool_accounts
>>>>>>> 39262bad7 (feat: multiple `tokenPoolPda` accounts (#1407))
.clone()
.unwrap_or_default()
.as_slice(),
Expand Down Expand Up @@ -829,7 +837,11 @@ pub async fn decompress_test<R: RpcConnection, I: Indexer<R>>(
.unwrap()
.amount,
];
<<<<<<< HEAD
for additional_pool_account in additional_pool_accounts
=======
for additional_pool_account in additonal_pool_accounts
>>>>>>> 39262bad7 (feat: multiple `tokenPoolPda` accounts (#1407))
.clone()
.unwrap_or_default()
.as_slice()
Expand Down Expand Up @@ -899,7 +911,11 @@ pub async fn decompress_test<R: RpcConnection, I: Indexer<R>>(
token_pool_pre_balances[0].saturating_sub(amount)
);
let mut amount = amount - token_pool_pre_balances[0];
<<<<<<< HEAD
for (i, additional_account) in additional_pool_accounts
=======
for (i, additional_account) in additonal_pool_accounts
>>>>>>> 39262bad7 (feat: multiple `tokenPoolPda` accounts (#1407))
.unwrap_or_default()
.iter()
.enumerate()
Expand Down Expand Up @@ -1010,7 +1026,11 @@ pub async fn compress_test<R: RpcConnection, I: Indexer<R>>(
transaction_params: Option<TransactionParams>,
is_token_22: bool,
token_pool_bump: u8,
<<<<<<< HEAD
additional_pool_accounts: Option<Vec<Pubkey>>,
=======
additonal_pool_accounts: Option<Vec<Pubkey>>,
>>>>>>> 39262bad7 (feat: multiple `tokenPoolPda` accounts (#1407))
) {
let output_compressed_account = TokenTransferOutputData {
amount,
Expand Down Expand Up @@ -1038,7 +1058,11 @@ pub async fn compress_test<R: RpcConnection, I: Indexer<R>>(
None,
None,
is_token_22,
<<<<<<< HEAD
additional_pool_accounts.unwrap_or_default().as_slice(),
=======
additonal_pool_accounts.unwrap_or_default().as_slice(),
>>>>>>> 39262bad7 (feat: multiple `tokenPoolPda` accounts (#1407))
)
.unwrap();
let output_merkle_tree_pubkeys = vec![*output_merkle_tree_pubkey];
Expand Down Expand Up @@ -1713,7 +1737,11 @@ pub async fn create_burn_test_instruction<R: RpcConnection, I: Indexer<R>>(
mode: BurnInstructionMode,
is_token_22: bool,
token_pool_bump: u8,
<<<<<<< HEAD
additional_pool_accounts: Option<Vec<Pubkey>>,
=======
additonal_pool_accounts: Option<Vec<Pubkey>>,
>>>>>>> 39262bad7 (feat: multiple `tokenPoolPda` accounts (#1407))
) -> (Vec<[u8; 32]>, Vec<Pubkey>, Pubkey, u64, Instruction) {
let input_compressed_account_hashes = input_compressed_accounts
.iter()
Expand Down Expand Up @@ -1770,7 +1798,11 @@ pub async fn create_burn_test_instruction<R: RpcConnection, I: Indexer<R>>(
burn_amount,
is_token_22,
token_pool_bump,
<<<<<<< HEAD
additional_pool_accounts: additional_pool_accounts.unwrap_or_default(),
=======
additonal_pool_accounts: additonal_pool_accounts.unwrap_or_default(),
>>>>>>> 39262bad7 (feat: multiple `tokenPoolPda` accounts (#1407))
};
let input_amount_sum = input_compressed_accounts
.iter()
Expand Down

0 comments on commit 0dbbbe4

Please sign in to comment.