test.ts 1.1 KB

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