From c55219799163420bb8ae0943bd953a563e735d6c Mon Sep 17 00:00:00 2001 From: Tyera Eulberg Date: Tue, 1 Feb 2022 14:02:02 -0700 Subject: [PATCH] Add initial realloc test --- token/program-2022/tests/memo_transfer.rs | 46 +++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/token/program-2022/tests/memo_transfer.rs b/token/program-2022/tests/memo_transfer.rs index a6aeeb09d75..7419ec6018a 100644 --- a/token/program-2022/tests/memo_transfer.rs +++ b/token/program-2022/tests/memo_transfer.rs @@ -73,3 +73,49 @@ async fn require_memo_transfers_without_realloc() { let bob_state = token.get_account_info(&bob_account).await.unwrap(); assert_eq!(bob_state.base.amount, 21); } + +#[tokio::test] +async fn require_memo_transfers_with_realloc() { + let mut context = TestContext::new().await; + context.init_token_with_mint(vec![]).await.unwrap(); + let TokenContext { + mint_authority, + token, + alice, + bob, + .. + } = context.token_context.unwrap(); + + // create token accounts + let alice_account = token + .create_auxiliary_token_account(&alice, &alice.pubkey()) + .await + .unwrap(); + let bob_account = token + .create_auxiliary_token_account(&bob, &bob.pubkey()) + .await + .unwrap(); + + // mint tokens + token + .mint_to(&alice_account, &mint_authority, 4242) + .await + .unwrap(); + + // require memo transfers into bob_account + token + .require_transfer_memos(&bob_account, &bob) + .await + .unwrap(); + + let bob_state = token.get_account_info(&bob_account).await.unwrap(); + let extension = bob_state.get_extension::().unwrap(); + assert!(extension.require_incoming_transfer_memos != 0); + + // attempt to transfer from alice to bob without memo + // TODO: should fail when token/program-2022/src/processor.rs#L376 is completed + token + .transfer_unchecked(&alice_account, &bob_account, &alice, 100) + .await + .unwrap(); +}