amount_to_ui_amount.rs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. #[tokio::test]
  8. async fn amount_to_ui_amount() {
  9. let mut context = ProgramTest::new("pinocchio_token_program", TOKEN_PROGRAM_ID, None)
  10. .start_with_context()
  11. .await;
  12. // Given a mint account.
  13. let mint_authority = Pubkey::new_unique();
  14. let freeze_authority = Pubkey::new_unique();
  15. let mint = mint::initialize(
  16. &mut context,
  17. mint_authority,
  18. Some(freeze_authority),
  19. &TOKEN_PROGRAM_ID,
  20. )
  21. .await
  22. .unwrap();
  23. let amount_to_ui_amount_ix =
  24. spl_token::instruction::amount_to_ui_amount(&spl_token::ID, &mint, 1000).unwrap();
  25. let tx = Transaction::new_signed_with_payer(
  26. &[amount_to_ui_amount_ix],
  27. Some(&context.payer.pubkey()),
  28. &[&context.payer],
  29. context.last_blockhash,
  30. );
  31. context.banks_client.process_transaction(tx).await.unwrap();
  32. // Then the transaction should succeed.
  33. let account = context.banks_client.get_account(mint).await.unwrap();
  34. assert!(account.is_some());
  35. }