Last active
April 8, 2024 15:54
-
-
Save julianeon/c7d148fd574b7dbacd06248f9afd359c to your computer and use it in GitHub Desktop.
A working test of the program in project-serum/anchor/tests/tictactoe, mostly the .js test shown there in /tests dir, but fixed to work (1 constraint removed) w/2 new tests added at bottom.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const anchor = require('@project-serum/anchor'); | |
describe('tiktaktoe', () => { | |
anchor.setProvider(anchor.Provider.env()); | |
const program = anchor.workspace.Tictactoe; | |
let dashboard = anchor.web3.Keypair.generate() | |
let game = anchor.web3.Keypair.generate() | |
let player_o = anchor.web3.Keypair.generate() | |
it('Initialize Dashboard', async () => { | |
const tx = await program.rpc.initializeDashboard({ | |
accounts: { | |
authority: program.provider.wallet.publicKey, | |
dashboard: dashboard.publicKey, | |
rent: anchor.web3.SYSVAR_RENT_PUBKEY, | |
}, | |
signers: [dashboard], | |
instructions: [await program.account.dashboard.createInstruction(dashboard)] | |
}) | |
console.log("transaction: ", tx) | |
//console.log("t-count: ", tx.gameCount) | |
}); | |
it('Initialize Game', async () => { | |
const tx = await program.rpc.initialize({ | |
accounts: { | |
playerX: program.provider.wallet.publicKey, | |
dashboard: dashboard.publicKey, | |
game: game.publicKey, | |
rent: anchor.web3.SYSVAR_RENT_PUBKEY, | |
}, | |
signers: [game], | |
instructions: [await program.account.game.createInstruction(game)] | |
}) | |
console.log("transaction: ", tx) | |
}); | |
it('Player O joins', async () => { | |
const tx = await program.rpc.playerJoin({ | |
accounts: { | |
playerO: player_o.publicKey, | |
game: game.publicKey, | |
}, | |
signers: [player_o], | |
}) | |
console.log("transaction: ", tx) | |
}); | |
it('Player x plays', async () => { | |
const tx = await program.rpc.playerMove(1, 0, { | |
accounts: { | |
player: program.provider.wallet.publicKey, | |
game: game.publicKey, | |
}, | |
}) | |
console.log("transaction: ", tx) | |
}); | |
it('Player o plays', async () => { | |
const tx = await program.rpc.playerMove(2, 1, { | |
accounts: { | |
player: player_o.publicKey, | |
game: game.publicKey, | |
}, | |
signers: [player_o] | |
}) | |
console.log("transaction: ", tx) | |
}); | |
it('Player x plays', async () => { | |
const tx = await program.rpc.playerMove(1, 3, { | |
accounts: { | |
player: program.provider.wallet.publicKey, | |
game: game.publicKey, | |
}, | |
}) | |
console.log("transaction: ", tx) | |
}); | |
it('Player o plays', async () => { | |
const tx = await program.rpc.playerMove(2, 6, { | |
accounts: { | |
player: player_o.publicKey, | |
game: game.publicKey, | |
}, | |
signers: [player_o] | |
}) | |
console.log("transaction: ", tx) | |
}); | |
it('Player x plays', async () => { | |
const tx = await program.rpc.playerMove(1, 2, { | |
accounts: { | |
player: program.provider.wallet.publicKey, | |
game: game.publicKey, | |
}, | |
}) | |
console.log("transaction: ", tx) | |
}); | |
it('Player o plays', async () => { | |
const tx = await program.rpc.playerMove(2, 4, { | |
accounts: { | |
player: player_o.publicKey, | |
game: game.publicKey, | |
}, | |
signers: [player_o] | |
}) | |
console.log("transaction: ", tx) | |
}); | |
it('Player x plays', async () => { | |
const tx = await program.rpc.playerMove(1, 5, { | |
accounts: { | |
player: program.provider.wallet.publicKey, | |
game: game.publicKey, | |
}, | |
}) | |
console.log("transaction: ", tx) | |
}); | |
it('Player o plays', async () => { | |
const tx = await program.rpc.playerMove(2, 8, { | |
accounts: { | |
player: player_o.publicKey, | |
game: game.publicKey, | |
}, | |
signers: [player_o] | |
}) | |
console.log("transaction: ", tx) | |
}); | |
it('Player x plays', async () => { | |
const tx = await program.rpc.playerMove(1, 7, { | |
accounts: { | |
player: program.provider.wallet.publicKey, | |
game: game.publicKey, | |
}, | |
}) | |
console.log("transaction: ", tx) | |
}); | |
it('Dashboard fetch', async () => { | |
const atx = await program.account.dashboard.fetch(dashboard.publicKey); | |
console.log("dash-game-count: ", atx.gameCount) | |
console.log("dash-address: ", atx.address) | |
}); | |
it('Game fetch', async () => { | |
const atx = await program.account.game.fetch(game.publicKey); | |
console.log("game-state: ", atx.gameState) | |
console.log("game-board: ", atx.board) | |
}); | |
it('Status', async () => { | |
const tx = await program.rpc.status({ | |
accounts: { | |
dashboard: dashboard.publicKey, | |
game: game.publicKey, | |
}, | |
}) | |
console.log("transaction: ", tx) | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment