Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions test/game1Test.js
Original file line number Diff line number Diff line change
@@ -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");
});
});
15 changes: 9 additions & 6 deletions test/game2Test.js
Original file line number Diff line number Diff line change
@@ -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");
});
});
34 changes: 22 additions & 12 deletions test/game3Test.js
Original file line number Diff line number Diff line change
@@ -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");
});
});
28 changes: 18 additions & 10 deletions test/game4Test.js
Original file line number Diff line number Diff line change
@@ -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");
});
});
28 changes: 20 additions & 8 deletions test/game5Test.js
Original file line number Diff line number Diff line change
@@ -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");
});
});