test.rs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 steel_api::prelude::*;
  5. async fn setup() -> (BanksClient, Keypair, Hash) {
  6. let mut program_test = ProgramTest::new(
  7. "steel_program",
  8. steel_api::ID,
  9. processor!(steel_program::process_instruction),
  10. );
  11. program_test.prefer_bpf(true);
  12. program_test.start().await
  13. }
  14. #[tokio::test]
  15. async fn run_test() {
  16. // Setup test
  17. let (mut banks, payer, blockhash) = setup().await;
  18. let account_to_create = Keypair::new();
  19. let account_to_change = Keypair::new();
  20. let account_to_change_ix = solana_sdk::system_instruction::create_account(
  21. &payer.pubkey(),
  22. &account_to_change.pubkey(),
  23. solana_sdk::native_token::LAMPORTS_PER_SOL,
  24. 0,
  25. &steel_api::ID,
  26. );
  27. let tx = Transaction::new_signed_with_payer(
  28. &[account_to_change_ix],
  29. Some(&payer.pubkey()),
  30. &[&payer, &account_to_change],
  31. blockhash,
  32. );
  33. let res = banks.process_transaction(tx).await;
  34. assert!(res.is_ok());
  35. // Submit check_accounts transaction.
  36. let ix = check_accounts(
  37. payer.pubkey(),
  38. account_to_create.pubkey(),
  39. account_to_change.pubkey(),
  40. );
  41. let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash);
  42. let res = banks.process_transaction(tx).await;
  43. assert!(res.is_ok());
  44. }