1
0

amount_to_ui_amount.rs 1.3 KB

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