tictactoe.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. const anchor = require("@project-serum/anchor");
  2. describe("tictactoe", () => {
  3. anchor.setProvider(anchor.AnchorProvider.env());
  4. const program = anchor.workspace.Tictactoe;
  5. let dashboard = anchor.web3.Keypair.generate();
  6. let game = anchor.web3.Keypair.generate();
  7. let player_o = anchor.web3.Keypair.generate();
  8. it("Initialize Dashboard", async () => {
  9. const tx = await program.rpc.initializeDashboard({
  10. accounts: {
  11. authority: program.provider.wallet.publicKey,
  12. dashboard: dashboard.publicKey,
  13. rent: anchor.web3.SYSVAR_RENT_PUBKEY,
  14. },
  15. signers: [dashboard],
  16. instructions: [
  17. await program.account.dashboard.createInstruction(dashboard),
  18. ],
  19. });
  20. console.log("transaction: ", tx);
  21. });
  22. it("Initialize Game", async () => {
  23. const tx = await program.rpc.initialize({
  24. accounts: {
  25. playerX: program.provider.wallet.publicKey,
  26. dashboard: dashboard.publicKey,
  27. game: game.publicKey,
  28. rent: anchor.web3.SYSVAR_RENT_PUBKEY,
  29. },
  30. signers: [game],
  31. instructions: [await program.account.game.createInstruction(game)],
  32. });
  33. console.log("transaction: ", tx);
  34. });
  35. it("Player O joins", async () => {
  36. const tx = await program.rpc.playerJoin({
  37. accounts: {
  38. playerO: player_o.publicKey,
  39. game: game.publicKey,
  40. },
  41. signers: [player_o],
  42. });
  43. console.log("transaction: ", tx);
  44. });
  45. it("Player x plays", async () => {
  46. const tx = await program.rpc.playerMove(1, 0, {
  47. accounts: {
  48. player: program.provider.wallet.publicKey,
  49. game: game.publicKey,
  50. },
  51. });
  52. console.log("transaction: ", tx);
  53. });
  54. it("Player o plays", async () => {
  55. const tx = await program.rpc.playerMove(2, 1, {
  56. accounts: {
  57. player: player_o.publicKey,
  58. game: game.publicKey,
  59. },
  60. signers: [player_o],
  61. });
  62. console.log("transaction: ", tx);
  63. });
  64. it("Player x plays", async () => {
  65. const tx = await program.rpc.playerMove(1, 3, {
  66. accounts: {
  67. player: program.provider.wallet.publicKey,
  68. game: game.publicKey,
  69. },
  70. });
  71. console.log("transaction: ", tx);
  72. });
  73. it("Player o plays", async () => {
  74. const tx = await program.rpc.playerMove(2, 6, {
  75. accounts: {
  76. player: player_o.publicKey,
  77. game: game.publicKey,
  78. },
  79. signers: [player_o],
  80. });
  81. console.log("transaction: ", tx);
  82. });
  83. it("Player x plays", async () => {
  84. const tx = await program.rpc.playerMove(1, 2, {
  85. accounts: {
  86. player: program.provider.wallet.publicKey,
  87. game: game.publicKey,
  88. },
  89. });
  90. console.log("transaction: ", tx);
  91. });
  92. it("Player o plays", async () => {
  93. const tx = await program.rpc.playerMove(2, 4, {
  94. accounts: {
  95. player: player_o.publicKey,
  96. game: game.publicKey,
  97. },
  98. signers: [player_o],
  99. });
  100. console.log("transaction: ", tx);
  101. });
  102. it("Player x plays", async () => {
  103. const tx = await program.rpc.playerMove(1, 5, {
  104. accounts: {
  105. player: program.provider.wallet.publicKey,
  106. game: game.publicKey,
  107. },
  108. });
  109. console.log("transaction: ", tx);
  110. });
  111. it("Player o plays", async () => {
  112. const tx = await program.rpc.playerMove(2, 8, {
  113. accounts: {
  114. player: player_o.publicKey,
  115. game: game.publicKey,
  116. },
  117. signers: [player_o],
  118. });
  119. console.log("transaction: ", tx);
  120. });
  121. it("Player x plays", async () => {
  122. const tx = await program.rpc.playerMove(1, 7, {
  123. accounts: {
  124. player: program.provider.wallet.publicKey,
  125. game: game.publicKey,
  126. },
  127. });
  128. console.log("transaction: ", tx);
  129. });
  130. it("Status", async () => {
  131. const tx = await program.rpc.status({
  132. accounts: {
  133. dashboard: dashboard.publicKey,
  134. game: game.publicKey,
  135. },
  136. });
  137. console.log("transaction: ", tx);
  138. });
  139. });