1
0

set_authority.rs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. mod setup;
  2. use {
  3. setup::{mint, TOKEN_PROGRAM_ID},
  4. solana_program_test::{tokio, ProgramTest},
  5. solana_sdk::{
  6. program_option::COption,
  7. program_pack::Pack,
  8. pubkey::Pubkey,
  9. signature::{Keypair, Signer},
  10. transaction::Transaction,
  11. },
  12. spl_token::instruction::AuthorityType,
  13. };
  14. #[tokio::test]
  15. async fn set_authority() {
  16. let mut context = ProgramTest::new("pinocchio_token_program", TOKEN_PROGRAM_ID, None)
  17. .start_with_context()
  18. .await;
  19. // Given a mint account.
  20. let mint_authority = Keypair::new();
  21. let freeze_authority = Keypair::new();
  22. let mint = mint::initialize(
  23. &mut context,
  24. mint_authority.pubkey(),
  25. Some(freeze_authority.pubkey()),
  26. &TOKEN_PROGRAM_ID,
  27. )
  28. .await
  29. .unwrap();
  30. // When we set a new freeze authority.
  31. let new_authority = Pubkey::new_unique();
  32. let set_authority_ix = spl_token::instruction::set_authority(
  33. &spl_token::ID,
  34. &mint,
  35. Some(&new_authority),
  36. AuthorityType::FreezeAccount,
  37. &freeze_authority.pubkey(),
  38. &[],
  39. )
  40. .unwrap();
  41. let tx = Transaction::new_signed_with_payer(
  42. &[set_authority_ix],
  43. Some(&context.payer.pubkey()),
  44. &[&context.payer, &freeze_authority],
  45. context.last_blockhash,
  46. );
  47. context.banks_client.process_transaction(tx).await.unwrap();
  48. // Then the account should have the delegate and delegated amount.
  49. let account = context.banks_client.get_account(mint).await.unwrap();
  50. assert!(account.is_some());
  51. let account = account.unwrap();
  52. let mint = spl_token::state::Mint::unpack(&account.data).unwrap();
  53. assert!(mint.freeze_authority == COption::Some(new_authority));
  54. }