initialize_immutable_owner.rs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. mod setup;
  2. use {
  3. setup::TOKEN_PROGRAM_ID,
  4. solana_keypair::Keypair,
  5. solana_program_pack::Pack,
  6. solana_program_test::{tokio, ProgramTest},
  7. solana_signer::Signer,
  8. solana_system_interface::instruction::create_account,
  9. solana_transaction::Transaction,
  10. spl_token_interface::state::AccountState,
  11. };
  12. #[tokio::test]
  13. async fn initialize_immutable_owner() {
  14. let context = ProgramTest::new("pinocchio_token_program", TOKEN_PROGRAM_ID, None)
  15. .start_with_context()
  16. .await;
  17. // Given an uninitialize account.
  18. let account = Keypair::new();
  19. let account_size = 165;
  20. let rent = context.banks_client.get_rent().await.unwrap();
  21. // When we execute the initialize_immutable_owner instruction.
  22. let instructions = vec![
  23. create_account(
  24. &context.payer.pubkey(),
  25. &account.pubkey(),
  26. rent.minimum_balance(account_size),
  27. account_size as u64,
  28. &TOKEN_PROGRAM_ID,
  29. ),
  30. spl_token_interface::instruction::initialize_immutable_owner(
  31. &TOKEN_PROGRAM_ID,
  32. &account.pubkey(),
  33. )
  34. .unwrap(),
  35. ];
  36. let tx = Transaction::new_signed_with_payer(
  37. &instructions,
  38. Some(&context.payer.pubkey()),
  39. &[&context.payer, &account],
  40. context.last_blockhash,
  41. );
  42. context.banks_client.process_transaction(tx).await.unwrap();
  43. // Then the instruction should succeed.
  44. let account = context
  45. .banks_client
  46. .get_account(account.pubkey())
  47. .await
  48. .unwrap();
  49. assert!(account.is_some());
  50. let account = account.unwrap();
  51. let account = spl_token_interface::state::Account::unpack_unchecked(&account.data).unwrap();
  52. assert_eq!(account.state, AccountState::Uninitialized);
  53. }