test.ts 1.9 KB

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