diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..33ef30c Binary files /dev/null and b/.DS_Store differ diff --git a/contracts/Game1.sol b/contracts/Game1.sol index b06a2b5..b8aeb0e 100644 --- a/contracts/Game1.sol +++ b/contracts/Game1.sol @@ -1,5 +1,6 @@ //SPDX-License-Identifier: Unlicense pragma solidity ^0.7.0; +import "hardhat/console.sol"; contract Game1 { bool public isWon; diff --git a/contracts/Game2.sol b/contracts/Game2.sol index fe61893..8d80eac 100644 --- a/contracts/Game2.sol +++ b/contracts/Game2.sol @@ -1,5 +1,6 @@ //SPDX-License-Identifier: Unlicense pragma solidity ^0.7.0; +import "hardhat/console.sol"; contract Game2 { bool public isWon; diff --git a/contracts/Game4.sol b/contracts/Game4.sol index 3d356a2..5a1ffc0 100644 --- a/contracts/Game4.sol +++ b/contracts/Game4.sol @@ -1,5 +1,6 @@ //SPDX-License-Identifier: Unlicense pragma solidity ^0.7.0; +import "hardhat/console.sol"; contract Game4 { bool public isWon; diff --git a/test/game1Test.js b/test/game1Test.js index 57d7506..01b7688 100644 --- a/test/game1Test.js +++ b/test/game1Test.js @@ -1,16 +1,17 @@ const { assert } = require("chai"); describe("Game1", function() { - it("should be a winner", async function() { - const Game = await ethers.getContractFactory("Game1"); - const game = await Game.deploy(); - await game.deployed(); + it("should be a winner", async function() { + const Game = await ethers.getContractFactory("Game1"); + const game = await Game.deploy(); + await game.deployed(); - // you must call unlock before you can win + // you must call unlock before you can win + await game.unlock(); - await game.win(); + await game.win(); - // leave this assertion as-is - assert(await game.isWon(), "You did not win the game"); - }); -}); + // leave this assertion as-is + assert(await game.isWon(), "You did not win the game"); + }); +}); \ No newline at end of file diff --git a/test/game2Test.js b/test/game2Test.js index f92dc83..22eb37a 100644 --- a/test/game2Test.js +++ b/test/game2Test.js @@ -1,16 +1,19 @@ const { assert } = require("chai"); describe("Game2", function() { - it("should be a winner", async function() { - const Game = await ethers.getContractFactory("Game2"); - const game = await Game.deploy(); - await game.deployed(); + it("should be a winner", async function() { + const Game = await ethers.getContractFactory("Game2"); + const game = await Game.deploy(); + await game.deployed(); - // press all the right switches to win this stage + // press all the right switches to win this stage + game.switchOn(20); + game.switchOn(47); + game.switchOn(212); - await game.win(); + await game.win(); - // leave this assertion as-is - assert(await game.isWon(), "You did not win the game"); - }); -}); + // leave this assertion as-is + assert(await game.isWon(), "You did not win the game"); + }); +}); \ No newline at end of file diff --git a/test/game3Test.js b/test/game3Test.js index b2e3003..0ae2de5 100644 --- a/test/game3Test.js +++ b/test/game3Test.js @@ -1,27 +1,36 @@ const { assert } = require("chai"); +const { ethers } = require("hardhat"); describe("Game3", function() { - it("should be a winner", async function() { - const Game = await ethers.getContractFactory("Game3"); - const game = await Game.deploy(); - await game.deployed(); - - // three addresses, three balances - // you'll need to update the mapping to win this stage - - // 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 address = await signer.getAddress(); - - // to call a contract as a signer you can use contract.connect - await game.connect(signer).buy({ value: "1" }); - - // TODO: win expects three arguments - await game.win(); - - // leave this assertion as-is - assert(await game.isWon(), "You did not win the game"); - }); -}); + it("should be a winner", async function() { + const Game = await ethers.getContractFactory("Game3"); + const game = await Game.deploy(); + await game.deployed(); + + // three addresses, three balances + // you'll need to update the mapping to win this stage + + // 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 signer1 = ethers.provider.getSigner(0); + const address1 = await signer1.getAddress(); + + const signer2 = ethers.provider.getSigner(1); + const address2 = await signer2.getAddress(); + + const signer3 = ethers.provider.getSigner(2); + const address3 = await signer3.getAddress(); + + // to call a contract as a signer you can use contract.connect + await game.connect(signer1).buy({ value: "5" }); + await game.connect(signer2).buy({ value: "10" }); + await game.connect(signer3).buy({ value: "1" }); + + // TODO: win expects three arguments + await game.win(address1, address2, address3); + + // leave this assertion as-is + assert(await game.isWon(), "You did not win the game"); + }); +}); \ No newline at end of file diff --git a/test/game4Test.js b/test/game4Test.js index dab5b45..12422f6 100644 --- a/test/game4Test.js +++ b/test/game4Test.js @@ -1,16 +1,22 @@ const { assert } = require("chai"); describe("Game4", function() { - it("should be a winner", async function() { - const Game = await ethers.getContractFactory("Game4"); - const game = await Game.deploy(); - await game.deployed(); + it("should be a winner", async function() { + const Game = await ethers.getContractFactory("Game4"); + const game = await Game.deploy(); + await game.deployed(); - // nested mappings are rough :} + // nested mappings are rough :} + const signer1 = ethers.provider.getSigner(0); + const address1 = await signer1.getAddress(); - await game.win(); + const signer2 = ethers.provider.getSigner(1); + const address2 = await signer2.getAddress(); - // leave this assertion as-is - assert(await game.isWon(), "You did not win the game"); - }); -}); + await game.connect(signer1).write(address2); + await game.connect(signer2).win(address1); + + // leave this assertion as-is + assert(await game.isWon(), "You did not win the game"); + }); +}); \ No newline at end of file diff --git a/test/game5Test.js b/test/game5Test.js index aeeb41c..3b948c1 100644 --- a/test/game5Test.js +++ b/test/game5Test.js @@ -1,16 +1,34 @@ const { assert } = require("chai"); +const { Signer } = require("ethers"); +const { ethers } = require("hardhat"); describe("Game5", function() { - it("should be a winner", async function() { - const Game = await ethers.getContractFactory("Game5"); - const game = await Game.deploy(); - await game.deployed(); + it("should be a winner", async function() { + const Game = await ethers.getContractFactory("Game5"); + const game = await Game.deploy(); + await game.deployed(); - // good luck + // good luck + const threshold = 0x00FfFFfFFFfFFFFFfFfFfffFFFfffFfFffFfFFFf; + let validAddress; + while (!validAddress) { + wallet = ethers.Wallet.createRandom(); + address = await wallet.getAddress(); + if (address < threshold) { + validAddress = true; + } + }; - await game.win(); + wallet = wallet.connect(ethers.provider); + const signer = ethers.provider.getSigner(0); + await signer.sendTransaction({ + to: address, + value: ethers.utils.parseEther("100") + }); - // leave this assertion as-is - assert(await game.isWon(), "You did not win the game"); - }); -}); + await game.connect(wallet).win(); + + // leave this assertion as-is + assert(await game.isWon(), "You did not win the game"); + }); +}); \ No newline at end of file