diff --git a/test/game1Test.js b/test/game1Test.js index 0a99a2f..3c67f17 100644 --- a/test/game1Test.js +++ b/test/game1Test.js @@ -1,24 +1,25 @@ -const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers'); -const { assert } = require('chai'); +const { loadFixture } = require("@nomicfoundation/hardhat-network-helpers"); +const { assert } = require("chai"); -describe('Game1', function () { +describe("Game1", function () { async function deployContractAndSetVariables() { - const Game = await ethers.getContractFactory('Game1'); + const Game = await ethers.getContractFactory("Game1"); const game = await Game.deploy(); return { game }; } - it('should be a winner', async function () { + it("should be a winner", async function () { // leave this as-is const { game } = await loadFixture(deployContractAndSetVariables); // you must call unlock before you can win + await game.unlock(); // leave this call to game.win() as-is await game.win(); // leave this testing assertion as-is - assert(await game.isWon(), 'You did not win the game'); + assert(await game.isWon(), "You did not win the game"); }); }); diff --git a/test/game2Test.js b/test/game2Test.js index 4cf5e3b..78c7434 100644 --- a/test/game2Test.js +++ b/test/game2Test.js @@ -1,22 +1,25 @@ -const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers'); -const { assert } = require('chai'); +const { loadFixture } = require("@nomicfoundation/hardhat-network-helpers"); +const { assert } = require("chai"); -describe('Game2', function () { +describe("Game2", function () { async function deployContractAndSetVariables() { - const Game = await ethers.getContractFactory('Game2'); + const Game = await ethers.getContractFactory("Game2"); const game = await Game.deploy(); return { game }; } - it('should be a winner', async function () { + it("should be a winner", async function () { const { game } = await loadFixture(deployContractAndSetVariables); // press all the right switches to win this stage + await game.switchOn(20); + await game.switchOn(47); + await game.switchOn(212); await game.win(); // leave this assertion as-is - assert(await game.isWon(), 'You did not win the game'); + assert(await game.isWon(), "You did not win the game"); }); }); diff --git a/test/game3Test.js b/test/game3Test.js index df0c52b..93b1adb 100644 --- a/test/game3Test.js +++ b/test/game3Test.js @@ -1,35 +1,45 @@ -const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers'); -const { assert } = require('chai'); +const { loadFixture } = require("@nomicfoundation/hardhat-network-helpers"); +const { assert } = require("chai"); -describe('Game3', function () { +describe("Game3", function () { async function deployContractAndSetVariables() { - const Game = await ethers.getContractFactory('Game3'); + const Game = await ethers.getContractFactory("Game3"); const game = await Game.deploy(); // Hardhat will create 10 accounts for you by default // you can get one of this accounts with ethers.provider.getSigner // and passing in the zero-based indexed of the signer you want: - const signer = ethers.provider.getSigner(0); + const signer1 = ethers.provider.getSigner(0); + const signer2 = ethers.provider.getSigner(1); + const signer3 = ethers.provider.getSigner(2); // you can get that signer's address via .getAddress() // this variable is NOT used for Contract 3, just here as an example - const address = await signer.getAddress(); + // const address = await signer.getAddress(); - return { game, signer }; + return { game, signer1, signer2, signer3 }; } - it('should be a winner', async function () { - const { game, signer } = await loadFixture(deployContractAndSetVariables); + it("should be a winner", async function () { + const { game, signer1, signer2, signer3 } = await loadFixture( + deployContractAndSetVariables + ); // you'll need to update the `balances` mapping to win this stage // to call a contract as a signer you can use contract.connect - await game.connect(signer).buy({ value: '1' }); + await game.connect(signer1).buy({ value: "5" }); + await game.connect(signer2).buy({ value: "10" }); + await game.connect(signer3).buy({ value: "1" }); + + const address1 = await await signer1.getAddress(); + const address2 = await await signer2.getAddress(); + const address3 = await await signer3.getAddress(); // TODO: win expects three arguments - await game.win(); + await game.win(address1, address2, address3); // leave this assertion as-is - assert(await game.isWon(), 'You did not win the game'); + assert(await game.isWon(), "You did not win the game"); }); }); diff --git a/test/game4Test.js b/test/game4Test.js index d688d53..a2d9b9b 100644 --- a/test/game4Test.js +++ b/test/game4Test.js @@ -1,21 +1,29 @@ -const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers'); -const { assert } = require('chai'); +const { loadFixture } = require("@nomicfoundation/hardhat-network-helpers"); +const { assert } = require("chai"); -describe('Game4', function () { +describe("Game4", function () { async function deployContractAndSetVariables() { - const Game = await ethers.getContractFactory('Game4'); + const Game = await ethers.getContractFactory("Game4"); const game = await Game.deploy(); - return { game }; + const signer1 = ethers.provider.getSigner(0); + const signer2 = ethers.provider.getSigner(1); + + return { game, signer1, signer2 }; } - it('should be a winner', async function () { - const { game } = await loadFixture(deployContractAndSetVariables); + it("should be a winner", async function () { + const { game, signer1, signer2 } = await loadFixture( + deployContractAndSetVariables + ); + + const address1 = await await signer1.getAddress(); + const address2 = await await signer2.getAddress(); - // nested mappings are rough :} + await game.connect(signer1).write(address1); - await game.win(); + await game.win(address1); // leave this assertion as-is - assert(await game.isWon(), 'You did not win the game'); + assert(await game.isWon(), "You did not win the game"); }); }); diff --git a/test/game5Test.js b/test/game5Test.js index 66461ed..9fc7439 100644 --- a/test/game5Test.js +++ b/test/game5Test.js @@ -1,21 +1,33 @@ -const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers'); -const { assert } = require('chai'); +const { loadFixture } = require("@nomicfoundation/hardhat-network-helpers"); +const { assert } = require("chai"); -describe('Game5', function () { +describe("Game5", function () { async function deployContractAndSetVariables() { - const Game = await ethers.getContractFactory('Game5'); + const Game = await ethers.getContractFactory("Game5"); const game = await Game.deploy(); return { game }; } - it('should be a winner', async function () { + it("should be a winner", async function () { const { game } = await loadFixture(deployContractAndSetVariables); - // good luck + const provider = ethers.provider; + const privateKey = + "2b06d60a9966dd409b6dac1d94887ad4de72c8a8e28b8e8c0033c2eefabcfd4d"; // will produce address 0x0000e0f1Fe76b8F37F71f80b8a2c301Fe6feB3E5 + const customWallet = new ethers.Wallet(privateKey, provider); - await game.win(); + // Fund the custom wallet (Hardhat default accounts can send it ETH) + const [owner] = await ethers.getSigners(); + await owner.sendTransaction({ + to: customWallet.address, + value: ethers.utils.parseEther("1.0"), // Send some ETH for gas fees + }); + + // Call `win()` from the custom wallet + const gameWithCustomWallet = game.connect(customWallet); + await gameWithCustomWallet.win(); // leave this assertion as-is - assert(await game.isWon(), 'You did not win the game'); + assert(await game.isWon(), "You did not win the game"); }); });