ui_amount_to_amount.rs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. mod setup;
  2. use {
  3. setup::{mint, TOKEN_PROGRAM_ID},
  4. solana_program_test::{tokio, ProgramTest},
  5. solana_sdk::{pubkey::Pubkey, signature::Signer, transaction::Transaction},
  6. };
  7. #[test_case::test_case(TOKEN_PROGRAM_ID ; "p-token")]
  8. #[tokio::test]
  9. async fn ui_amount_to_amount(token_program: Pubkey) {
  10. let mut context = ProgramTest::new("pinocchio_token_program", TOKEN_PROGRAM_ID, None)
  11. .start_with_context()
  12. .await;
  13. // Given a mint account.
  14. let mint_authority = Pubkey::new_unique();
  15. let freeze_authority = Pubkey::new_unique();
  16. let mint = mint::initialize(
  17. &mut context,
  18. mint_authority,
  19. Some(freeze_authority),
  20. &token_program,
  21. )
  22. .await
  23. .unwrap();
  24. let mut ui_amount_to_amount_ix =
  25. spl_token::instruction::ui_amount_to_amount(&spl_token::ID, &mint, "1000.00").unwrap();
  26. // Switches the program id to the token program.
  27. ui_amount_to_amount_ix.program_id = token_program;
  28. let tx = Transaction::new_signed_with_payer(
  29. &[ui_amount_to_amount_ix],
  30. Some(&context.payer.pubkey()),
  31. &[&context.payer],
  32. context.last_blockhash,
  33. );
  34. context.banks_client.process_transaction(tx).await.unwrap();
  35. // Then the transaction should succeed.
  36. let account = context.banks_client.get_account(mint).await.unwrap();
  37. assert!(account.is_some());
  38. }