Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Commit

Permalink
Add initial realloc test
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyera Eulberg committed Feb 2, 2022
1 parent 41be073 commit c552197
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions token/program-2022/tests/memo_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<MemoTransfer>().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();
}

0 comments on commit c552197

Please sign in to comment.