tictactoe.js 3.8 KB

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