test.rs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. use hand_api::prelude::*;
  2. use lever_api::prelude::*;
  3. use solana_program::hash::Hash;
  4. use solana_program_test::{processor, BanksClient, ProgramTest};
  5. use solana_sdk::{signature::Keypair, signer::Signer, transaction::Transaction};
  6. async fn setup() -> (BanksClient, Keypair, Hash) {
  7. let mut program_test = ProgramTest::new(
  8. "hand_program",
  9. hand_api::ID,
  10. processor!(hand_program::process_instruction),
  11. );
  12. program_test.add_program(
  13. "lever_program",
  14. lever_api::ID,
  15. processor!(lever_program::process_instruction),
  16. );
  17. program_test.prefer_bpf(true);
  18. program_test.start().await
  19. }
  20. #[tokio::test]
  21. async fn run_test() {
  22. // Setup test
  23. let (mut banks, payer, blockhash) = setup().await;
  24. let power_account = Keypair::new();
  25. // Submit initialize transaction.
  26. let ix = initialize(payer.pubkey(), power_account.pubkey());
  27. let tx = Transaction::new_signed_with_payer(
  28. &[ix],
  29. Some(&payer.pubkey()),
  30. &[&payer, &power_account],
  31. blockhash,
  32. );
  33. let res = banks.process_transaction(tx).await;
  34. assert!(res.is_ok());
  35. // Submit pull_lever transaction.
  36. let ix = pull_lever(power_account.pubkey(), "Chris");
  37. let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash);
  38. let res = banks.process_transaction(tx).await;
  39. assert!(res.is_ok());
  40. let ix = pull_lever(power_account.pubkey(), "Ashley");
  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. }