anchor/tests/tictactoe/tests/tictactoe.js

158 lines
3.9 KiB
JavaScript
Raw Normal View History

const anchor = require("@coral-xyz/anchor");
2021-08-18 23:50:50 -07:00
describe("tictactoe", () => {
anchor.setProvider(anchor.AnchorProvider.env());
2021-08-18 23:50:50 -07:00
const program = anchor.workspace.Tictactoe;
let dashboard = anchor.web3.Keypair.generate();
let game = anchor.web3.Keypair.generate();
let player_o = anchor.web3.Keypair.generate();
2021-08-18 23:50:50 -07:00
it("Initialize Dashboard", async () => {
2021-08-18 23:50:50 -07:00
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),
],
});
2021-08-18 23:50:50 -07:00
console.log("transaction: ", tx);
2021-08-18 23:50:50 -07:00
});
it("Initialize Game", async () => {
2021-08-18 23:50:50 -07:00
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)],
});
2021-08-18 23:50:50 -07:00
console.log("transaction: ", tx);
2021-08-18 23:50:50 -07:00
});
it("Player O joins", async () => {
2021-08-18 23:50:50 -07:00
const tx = await program.rpc.playerJoin({
accounts: {
playerO: player_o.publicKey,
game: game.publicKey,
},
signers: [player_o],
});
2021-08-18 23:50:50 -07:00
console.log("transaction: ", tx);
2021-08-18 23:50:50 -07:00
});
it("Player x plays", async () => {
2021-08-18 23:50:50 -07:00
const tx = await program.rpc.playerMove(1, 0, {
accounts: {
player: program.provider.wallet.publicKey,
game: game.publicKey,
},
});
console.log("transaction: ", tx);
2021-08-18 23:50:50 -07:00
});
it("Player o plays", async () => {
2021-08-18 23:50:50 -07:00
const tx = await program.rpc.playerMove(2, 1, {
accounts: {
player: player_o.publicKey,
game: game.publicKey,
},
signers: [player_o],
});
console.log("transaction: ", tx);
2021-08-18 23:50:50 -07:00
});
it("Player x plays", async () => {
2021-08-18 23:50:50 -07:00
const tx = await program.rpc.playerMove(1, 3, {
accounts: {
player: program.provider.wallet.publicKey,
game: game.publicKey,
},
});
console.log("transaction: ", tx);
2021-08-18 23:50:50 -07:00
});
it("Player o plays", async () => {
2021-08-18 23:50:50 -07:00
const tx = await program.rpc.playerMove(2, 6, {
accounts: {
player: player_o.publicKey,
game: game.publicKey,
},
signers: [player_o],
});
console.log("transaction: ", tx);
2021-08-18 23:50:50 -07:00
});
it("Player x plays", async () => {
2021-08-18 23:50:50 -07:00
const tx = await program.rpc.playerMove(1, 2, {
accounts: {
player: program.provider.wallet.publicKey,
game: game.publicKey,
},
});
console.log("transaction: ", tx);
2021-08-18 23:50:50 -07:00
});
it("Player o plays", async () => {
2021-08-18 23:50:50 -07:00
const tx = await program.rpc.playerMove(2, 4, {
accounts: {
player: player_o.publicKey,
game: game.publicKey,
},
signers: [player_o],
});
console.log("transaction: ", tx);
2021-08-18 23:50:50 -07:00
});
it("Player x plays", async () => {
2021-08-18 23:50:50 -07:00
const tx = await program.rpc.playerMove(1, 5, {
accounts: {
player: program.provider.wallet.publicKey,
game: game.publicKey,
},
});
console.log("transaction: ", tx);
2021-08-18 23:50:50 -07:00
});
it("Player o plays", async () => {
2021-08-18 23:50:50 -07:00
const tx = await program.rpc.playerMove(2, 8, {
accounts: {
player: player_o.publicKey,
game: game.publicKey,
},
signers: [player_o],
});
console.log("transaction: ", tx);
2021-08-18 23:50:50 -07:00
});
it("Player x plays", async () => {
2021-08-18 23:50:50 -07:00
const tx = await program.rpc.playerMove(1, 7, {
accounts: {
player: program.provider.wallet.publicKey,
game: game.publicKey,
},
});
console.log("transaction: ", tx);
2021-08-18 23:50:50 -07:00
});
it("Status", async () => {
2021-08-18 23:50:50 -07:00
const tx = await program.rpc.status({
accounts: {
dashboard: dashboard.publicKey,
game: game.publicKey,
},
});
2021-08-18 23:50:50 -07:00
console.log("transaction: ", tx);
2021-08-18 23:50:50 -07:00
});
});