test.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import * as anchor from "@project-serum/anchor";
  2. import { 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. let tx = new anchor.web3.Transaction();
  10. for (var ix of instructionsList) {
  11. tx.add(ix);
  12. };
  13. await anchor.web3.sendAndConfirmTransaction(
  14. provider.connection,
  15. tx,
  16. [wallet.payer]
  17. );
  18. }
  19. it("Go on some rides!", async () => {
  20. await sendCarnivalInstructions([
  21. await program.methods.goOnRide("Jimmy", 36, 15, "Scrambler").instruction(),
  22. await program.methods.goOnRide("Mary", 52, 1, "Ferris Wheel").instruction(),
  23. await program.methods.goOnRide("Alice", 56, 15, "Scrambler").instruction(),
  24. await program.methods.goOnRide("Bob", 49, 6, "Tilt-a-Whirl").instruction(),
  25. ]);
  26. });
  27. it("Play some games!", async () => {
  28. await sendCarnivalInstructions([
  29. await program.methods.playGame("Jimmy", 15, "I Got It!").instruction(),
  30. await program.methods.playGame("Mary", 1, "Ring Toss").instruction(),
  31. await program.methods.playGame("Alice", 15, "Ladder Climb").instruction(),
  32. await program.methods.playGame("Bob", 6, "Ring Toss").instruction(),
  33. ]);
  34. });
  35. it("Eat some food!", async () => {
  36. await sendCarnivalInstructions([
  37. await program.methods.eatFood("Jimmy", 15, "Taco Shack").instruction(),
  38. await program.methods.eatFood("Mary", 1, "Larry's Pizza").instruction(),
  39. await program.methods.eatFood("Alice", 15, "Dough Boy's").instruction(),
  40. await program.methods.eatFood("Bob", 6, "Dough Boy's").instruction(),
  41. ]);
  42. });
  43. });