mint_to_checked.rs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. mod setup;
  2. use {
  3. setup::{account, mint, TOKEN_PROGRAM_ID},
  4. solana_program_test::{tokio, ProgramTest},
  5. solana_sdk::{
  6. program_pack::Pack,
  7. pubkey::Pubkey,
  8. signature::{Keypair, Signer},
  9. transaction::Transaction,
  10. },
  11. };
  12. #[tokio::test]
  13. async fn mint_to_checked() {
  14. let mut context = ProgramTest::new("pinocchio_token_program", TOKEN_PROGRAM_ID, None)
  15. .start_with_context()
  16. .await;
  17. // Given a mint account.
  18. let mint_authority = Keypair::new();
  19. let freeze_authority = Pubkey::new_unique();
  20. let mint = mint::initialize(
  21. &mut context,
  22. mint_authority.pubkey(),
  23. Some(freeze_authority),
  24. &TOKEN_PROGRAM_ID,
  25. )
  26. .await
  27. .unwrap();
  28. // And a token account.
  29. let owner = Keypair::new();
  30. let account =
  31. account::initialize(&mut context, &mint, &owner.pubkey(), &TOKEN_PROGRAM_ID).await;
  32. // When we mint tokens to it.
  33. let mint_ix = spl_token::instruction::mint_to_checked(
  34. &spl_token::ID,
  35. &mint,
  36. &account,
  37. &mint_authority.pubkey(),
  38. &[],
  39. 100,
  40. 4,
  41. )
  42. .unwrap();
  43. let tx = Transaction::new_signed_with_payer(
  44. &[mint_ix],
  45. Some(&context.payer.pubkey()),
  46. &[&context.payer, &mint_authority],
  47. context.last_blockhash,
  48. );
  49. context.banks_client.process_transaction(tx).await.unwrap();
  50. // Then an account has the correct data.
  51. let account = context.banks_client.get_account(account).await.unwrap();
  52. assert!(account.is_some());
  53. let account = account.unwrap();
  54. let account = spl_token::state::Account::unpack(&account.data).unwrap();
  55. assert!(account.amount == 100);
  56. }