Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

finished classroom activities #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
Binary file added .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions contracts/Game1.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.7.0;
import "hardhat/console.sol";

contract Game1 {
bool public isWon;
Expand Down
1 change: 1 addition & 0 deletions contracts/Game2.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.7.0;
import "hardhat/console.sol";

contract Game2 {
bool public isWon;
Expand Down
1 change: 1 addition & 0 deletions contracts/Game4.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.7.0;
import "hardhat/console.sol";

contract Game4 {
bool public isWon;
Expand Down
21 changes: 11 additions & 10 deletions test/game1Test.js
Original file line number Diff line number Diff line change
@@ -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");
});
});
23 changes: 13 additions & 10 deletions test/game2Test.js
Original file line number Diff line number Diff line change
@@ -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");
});
});
57 changes: 33 additions & 24 deletions test/game3Test.js
Original file line number Diff line number Diff line change
@@ -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");
});
});
26 changes: 16 additions & 10 deletions test/game4Test.js
Original file line number Diff line number Diff line change
@@ -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");
});
});
38 changes: 28 additions & 10 deletions test/game5Test.js
Original file line number Diff line number Diff line change
@@ -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");
});
});