litesvm.test.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import * as anchor from '@coral-xyz/anchor';
  2. import { Transaction } from '@solana/web3.js';
  3. import { LiteSVMProvider, fromWorkspace } from 'anchor-litesvm';
  4. import { Carnival } from '../target/types/carnival';
  5. const IDL = require('../target/idl/carnival.json');
  6. describe('anchor', () => {
  7. // Configure the Anchor provider & load the program IDL for LiteSVM
  8. // The IDL gives you a typescript module
  9. const client = fromWorkspace('');
  10. const provider = new LiteSVMProvider(client);
  11. const payer = provider.wallet.payer;
  12. const program = new anchor.Program<Carnival>(IDL, provider);
  13. async function sendCarnivalInstructions(instructionsList: anchor.web3.TransactionInstruction[]) {
  14. const tx = new Transaction();
  15. for (const ix of instructionsList) {
  16. tx.add(ix);
  17. }
  18. await provider.sendAndConfirm(tx, [payer]);
  19. }
  20. it('Go on some rides!', async () => {
  21. await sendCarnivalInstructions([
  22. await program.methods.goOnRide('Jimmy', 36, 15, 'Scrambler').instruction(),
  23. await program.methods.goOnRide('Mary', 52, 1, 'Ferris Wheel').instruction(),
  24. await program.methods.goOnRide('Alice', 56, 15, 'Scrambler').instruction(),
  25. await program.methods.goOnRide('Bob', 49, 6, 'Tilt-a-Whirl').instruction(),
  26. ]);
  27. });
  28. it('Play some games!', async () => {
  29. await sendCarnivalInstructions([
  30. await program.methods.playGame('Jimmy', 15, 'I Got It!').instruction(),
  31. await program.methods.playGame('Mary', 1, 'Ring Toss').instruction(),
  32. await program.methods.playGame('Alice', 15, 'Ladder Climb').instruction(),
  33. await program.methods.playGame('Bob', 6, 'Ring Toss').instruction(),
  34. ]);
  35. });
  36. it('Eat some food!', async () => {
  37. await sendCarnivalInstructions([
  38. await program.methods.eatFood('Jimmy', 15, 'Taco Shack').instruction(),
  39. await program.methods.eatFood('Mary', 1, "Larry's Pizza").instruction(),
  40. await program.methods.eatFood('Alice', 15, "Dough Boy's").instruction(),
  41. await program.methods.eatFood('Bob', 6, "Dough Boy's").instruction(),
  42. ]);
  43. });
  44. });