test.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import * as anchor from "@coral-xyz/anchor";
  2. import { Hand } from "../target/types/hand";
  3. import { Lever } from "../target/types/lever";
  4. describe("CPI Example", () => {
  5. const provider = anchor.AnchorProvider.env();
  6. anchor.setProvider(provider);
  7. const hand = anchor.workspace.Hand as anchor.Program<Hand>;
  8. const lever = anchor.workspace.Lever as anchor.Program<Lever>;
  9. const powerAccount = anchor.web3.Keypair.generate();
  10. it("Initialize the lever!", async () => {
  11. await lever.methods
  12. .initialize()
  13. .accounts({
  14. power: powerAccount.publicKey,
  15. user: provider.wallet.publicKey,
  16. systemProgram: anchor.web3.SystemProgram.programId,
  17. })
  18. .signers([powerAccount])
  19. .rpc();
  20. });
  21. it("Pull the lever!", async () => {
  22. await hand.methods
  23. .pullLever("Chris")
  24. .accounts({
  25. power: powerAccount.publicKey,
  26. leverProgram: lever.programId,
  27. })
  28. .rpc();
  29. });
  30. it("Pull it again!", async () => {
  31. await hand.methods
  32. .pullLever("Ashley")
  33. .accounts({
  34. power: powerAccount.publicKey,
  35. leverProgram: lever.programId,
  36. })
  37. .rpc();
  38. });
  39. });