test.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import * as anchor from "@coral-xyz/anchor";
  2. import {
  3. Keypair,
  4. SystemProgram,
  5. Transaction,
  6. sendAndConfirmTransaction,
  7. } from "@solana/web3.js";
  8. import type { CheckingAccountProgram } from "../target/types/checking_account_program";
  9. describe("Anchor example", () => {
  10. const provider = anchor.AnchorProvider.env();
  11. anchor.setProvider(provider);
  12. const program = anchor.workspace
  13. .CheckingAccountProgram as anchor.Program<CheckingAccountProgram>;
  14. const wallet = provider.wallet as anchor.Wallet;
  15. // We'll create this ahead of time.
  16. // Our program will try to modify it.
  17. const accountToChange = new Keypair();
  18. // Our program will create this.
  19. const accountToCreate = new Keypair();
  20. it("Create an account owned by our program", async () => {
  21. const instruction = SystemProgram.createAccount({
  22. fromPubkey: provider.wallet.publicKey,
  23. newAccountPubkey: accountToChange.publicKey,
  24. lamports: await provider.connection.getMinimumBalanceForRentExemption(0),
  25. space: 0,
  26. programId: program.programId, // Our program
  27. });
  28. const transaction = new Transaction().add(instruction);
  29. await sendAndConfirmTransaction(provider.connection, transaction, [
  30. wallet.payer,
  31. accountToChange,
  32. ]);
  33. });
  34. it("Check accounts", async () => {
  35. await program.methods
  36. .checkAccounts()
  37. .accounts({
  38. payer: wallet.publicKey,
  39. accountToCreate: accountToCreate.publicKey,
  40. accountToChange: accountToChange.publicKey,
  41. })
  42. .rpc();
  43. });
  44. });