test.rs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. use solana_program::hash::Hash;
  2. use solana_program_test::{processor, BanksClient, ProgramTest};
  3. use solana_sdk::{signature::Keypair, signer::Signer, transaction::Transaction};
  4. use spl_token_minter_api::prelude::*;
  5. async fn setup() -> (BanksClient, Keypair, Hash) {
  6. let mut program_test = ProgramTest::new(
  7. "spl_token_minter_program",
  8. spl_token_minter_api::ID,
  9. processor!(spl_token_minter_program::process_instruction),
  10. );
  11. program_test.add_program("token_metadata", mpl_token_metadata::ID, None);
  12. program_test.prefer_bpf(true);
  13. program_test.start().await
  14. }
  15. #[tokio::test]
  16. async fn run_test() {
  17. // Setup test
  18. let (mut banks, payer, blockhash) = setup().await;
  19. let mint_keypair = Keypair::new();
  20. let name = str_to_bytes::<32>("Solana Gold");
  21. let symbol = str_to_bytes::<8>("GOLDSOL");
  22. let uri = str_to_bytes::<64>("https://raw.githubusercontent.com/solana-developers/program-examples/new-examples/tokens/tokens/.assets/spl-token.json");
  23. // Submit create transaction.
  24. let ix = create(payer.pubkey(), mint_keypair.pubkey(), name, symbol, uri);
  25. let tx = Transaction::new_signed_with_payer(
  26. &[ix],
  27. Some(&payer.pubkey()),
  28. &[&payer, &mint_keypair],
  29. blockhash,
  30. );
  31. let res = banks.process_transaction(tx).await;
  32. assert!(res.is_ok());
  33. let recipient = Keypair::new();
  34. let to_ata = spl_associated_token_account::get_associated_token_address(
  35. &recipient.pubkey(),
  36. &mint_keypair.pubkey(),
  37. );
  38. // Submit mint transaction.
  39. let ix = mint(
  40. payer.pubkey(),
  41. recipient.pubkey(),
  42. mint_keypair.pubkey(),
  43. to_ata,
  44. 100,
  45. );
  46. let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash);
  47. let res = banks.process_transaction(tx).await;
  48. assert!(res.is_ok());
  49. }