bankrun.test.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { describe, it } from 'node:test';
  2. import * as anchor from '@coral-xyz/anchor';
  3. import { PublicKey } from '@solana/web3.js';
  4. import { BankrunProvider } from 'anchor-bankrun';
  5. import { startAnchor } from 'solana-bankrun';
  6. import type { Hand } from '../target/types/hand';
  7. import type { Lever } from '../target/types/lever';
  8. const HAND_IDL = require('../target/idl/hand.json');
  9. const LEVER_IDL = require('../target/idl/lever.json');
  10. const HAND_PROGRAM_ID = new PublicKey(HAND_IDL.address);
  11. const LEVER_PROGRAM_ID = new PublicKey(LEVER_IDL.address);
  12. describe('cpi', async () => {
  13. const context = await startAnchor(
  14. '',
  15. [
  16. {
  17. name: 'hand',
  18. programId: HAND_PROGRAM_ID,
  19. },
  20. {
  21. name: 'lever',
  22. programId: LEVER_PROGRAM_ID,
  23. },
  24. ],
  25. [],
  26. );
  27. const provider = new BankrunProvider(context);
  28. const hand = new anchor.Program<Hand>(HAND_IDL, provider);
  29. const lever = new anchor.Program<Lever>(LEVER_IDL, provider);
  30. // Generate a new keypair for the power account
  31. const powerAccount = new anchor.web3.Keypair();
  32. it('Initialize the lever!', async () => {
  33. await lever.methods
  34. .initialize()
  35. .accounts({
  36. power: powerAccount.publicKey,
  37. user: provider.wallet.publicKey,
  38. })
  39. .signers([powerAccount])
  40. .rpc();
  41. });
  42. it('Pull the lever!', async () => {
  43. await hand.methods
  44. .pullLever('Chris')
  45. .accounts({
  46. power: powerAccount.publicKey,
  47. })
  48. .rpc();
  49. });
  50. it('Pull it again!', async () => {
  51. await hand.methods
  52. .pullLever('Ashley')
  53. .accounts({
  54. power: powerAccount.publicKey,
  55. })
  56. .rpc();
  57. });
  58. });