cpi.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import * as anchor from '@coral-xyz/anchor';
  2. import type { Program } from '@coral-xyz/anchor';
  3. import type { Hand } from '../target/types/hand';
  4. import type { Lever } from '../target/types/lever';
  5. describe('cpi', () => {
  6. const provider = anchor.AnchorProvider.env();
  7. anchor.setProvider(provider);
  8. const hand = anchor.workspace.Hand as Program<Hand>;
  9. const lever = anchor.workspace.Lever as Program<Lever>;
  10. // Generate a new keypair for the power account
  11. const powerAccount = new anchor.web3.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. })
  28. .rpc();
  29. });
  30. it('Pull it again!', async () => {
  31. await hand.methods
  32. .pullLever('Ashley')
  33. .accounts({
  34. power: powerAccount.publicKey,
  35. })
  36. .rpc();
  37. });
  38. });