initialize_immutable_owner.rs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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::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::instruction::initialize_immutable_owner(&TOKEN_PROGRAM_ID, &account.pubkey())
  31. .unwrap(),
  32. ];
  33. let tx = Transaction::new_signed_with_payer(
  34. &instructions,
  35. Some(&context.payer.pubkey()),
  36. &[&context.payer, &account],
  37. context.last_blockhash,
  38. );
  39. context.banks_client.process_transaction(tx).await.unwrap();
  40. // Then the instruction should succeed.
  41. let account = context
  42. .banks_client
  43. .get_account(account.pubkey())
  44. .await
  45. .unwrap();
  46. assert!(account.is_some());
  47. let account = account.unwrap();
  48. let account = spl_token::state::Account::unpack_unchecked(&account.data).unwrap();
  49. assert_eq!(account.state, AccountState::Uninitialized);
  50. }