test.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import * as anchor from '@coral-xyz/anchor';
  2. import type { Carnival } from '../target/types/carnival';
  3. describe('Carnival', () => {
  4. const provider = anchor.AnchorProvider.env();
  5. anchor.setProvider(provider);
  6. const wallet = provider.wallet as anchor.Wallet;
  7. const program = anchor.workspace.Carnival as anchor.Program<Carnival>;
  8. async function sendCarnivalInstructions(instructionsList: anchor.web3.TransactionInstruction[]) {
  9. const tx = new anchor.web3.Transaction();
  10. for (const ix of instructionsList) {
  11. tx.add(ix);
  12. }
  13. await anchor.web3.sendAndConfirmTransaction(provider.connection, tx, [wallet.payer]);
  14. }
  15. it('Go on some rides!', async () => {
  16. await sendCarnivalInstructions([
  17. await program.methods.goOnRide('Jimmy', 36, 15, 'Scrambler').instruction(),
  18. await program.methods.goOnRide('Mary', 52, 1, 'Ferris Wheel').instruction(),
  19. await program.methods.goOnRide('Alice', 56, 15, 'Scrambler').instruction(),
  20. await program.methods.goOnRide('Bob', 49, 6, 'Tilt-a-Whirl').instruction(),
  21. ]);
  22. });
  23. it('Play some games!', async () => {
  24. await sendCarnivalInstructions([
  25. await program.methods.playGame('Jimmy', 15, 'I Got It!').instruction(),
  26. await program.methods.playGame('Mary', 1, 'Ring Toss').instruction(),
  27. await program.methods.playGame('Alice', 15, 'Ladder Climb').instruction(),
  28. await program.methods.playGame('Bob', 6, 'Ring Toss').instruction(),
  29. ]);
  30. });
  31. it('Eat some food!', async () => {
  32. await sendCarnivalInstructions([
  33. await program.methods.eatFood('Jimmy', 15, 'Taco Shack').instruction(),
  34. await program.methods.eatFood('Mary', 1, "Larry's Pizza").instruction(),
  35. await program.methods.eatFood('Alice', 15, "Dough Boy's").instruction(),
  36. await program.methods.eatFood('Bob', 6, "Dough Boy's").instruction(),
  37. ]);
  38. });
  39. });