ui_amount_to_amount.rs 1.2 KB

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