litesvm.test.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import * as anchor from '@coral-xyz/anchor';
  2. import { Program } from '@coral-xyz/anchor';
  3. import { Keypair } from '@solana/web3.js';
  4. import { LiteSVMProvider, fromWorkspace } from 'anchor-litesvm';
  5. import { Hand } from '../target/types/hand';
  6. import { Lever } from '../target/types/lever';
  7. const HAND_IDL = require('../target/idl/hand.json');
  8. const LEVER_IDL = require('../target/idl/lever.json');
  9. describe('anchor', () => {
  10. let client: any;
  11. let provider: LiteSVMProvider;
  12. let hand: Program<Hand>;
  13. let lever: Program<Lever>;
  14. let payer: Keypair;
  15. let accountToChange: Keypair;
  16. let accountToCreate: Keypair;
  17. before(async () => {
  18. client = fromWorkspace('');
  19. provider = new LiteSVMProvider(client);
  20. payer = provider.wallet.payer;
  21. hand = new anchor.Program<Hand>(HAND_IDL, provider);
  22. lever = new anchor.Program<Lever>(LEVER_IDL, provider);
  23. // We'll create this ahead of time.
  24. // Our program will try to modify it.
  25. accountToChange = new Keypair();
  26. // Our program will create this.
  27. accountToCreate = new Keypair();
  28. });
  29. // Generate a new keypair for the power account
  30. const powerAccount = new anchor.web3.Keypair();
  31. it('Initialize the lever!', async () => {
  32. await lever.methods
  33. .initialize()
  34. .accounts({
  35. power: powerAccount.publicKey,
  36. user: provider.wallet.publicKey,
  37. })
  38. .signers([powerAccount])
  39. .rpc();
  40. });
  41. it('Pull the lever!', async () => {
  42. await hand.methods
  43. .pullLever('Chris')
  44. .accounts({
  45. power: powerAccount.publicKey,
  46. })
  47. .rpc();
  48. });
  49. it('Pull it again!', async () => {
  50. await hand.methods
  51. .pullLever('Ashley')
  52. .accounts({
  53. power: powerAccount.publicKey,
  54. })
  55. .rpc();
  56. });
  57. });