Skip to content

Commit

Permalink
Push
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyYap committed May 3, 2023
1 parent 9e221fa commit 1cb8e09
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 158 deletions.
30 changes: 30 additions & 0 deletions Week6/project/contracts/HelloWorld.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;

contract HelloWorld {
string private text;
address public owner;

constructor() {
text = "Hello World";
owner = msg.sender;
}

function helloWorld() public view returns (string memory) {
return text;
}

function setText(string calldata newText) public onlyOwner {
text = newText;
}

function transferOwnership(address newOwner) public onlyOwner {
owner = newOwner;
}

modifier onlyOwner()
{
require (msg.sender == owner, "Caller is not the owner");
_;
}
}
34 changes: 0 additions & 34 deletions Week6/project/contracts/Lock.sol

This file was deleted.

63 changes: 63 additions & 0 deletions Week6/project/tests/HelloWorld.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { expect } from "chai";
import { ethers } from "hardhat";
// https://github.com/dethcrypto/TypeChain
import { HelloWorld } from "../typechain-types";

// https://mochajs.org/#getting-started
describe("HelloWorld", function () {
let helloWorldContract: HelloWorld;

// https://mochajs.org/#hooks
beforeEach(async function () {
// https://hardhat.org/plugins/nomiclabs-hardhat-ethers.html#helpers
const helloWorldFactory = await ethers.getContractFactory("HelloWorld");
// https://docs.ethers.io/v5/api/contract/contract-factory/#ContractFactory-deploy
helloWorldContract = await helloWorldFactory.deploy() as HelloWorld;
// https://docs.ethers.io/v5/api/contract/contract/#Contract-deployed
await helloWorldContract.deployed();
});

it("Should give a Hello World", async function () {
// https://docs.ethers.io/v5/api/contract/contract/#Contract-functionsCall
const helloWorldText = await helloWorldContract.helloWorld();
// https://www.chaijs.com/api/bdd/#method_equal
expect(helloWorldText).to.equal("Hello World");
});

it("Should set owner to deployer account", async function () {
// https://hardhat.org/plugins/nomiclabs-hardhat-ethers.html#helpers
const accounts = await ethers.getSigners();
// https://docs.ethers.io/v5/api/contract/contract/#Contract-functionsCall
const contractOwner = await helloWorldContract.owner();
// https://www.chaijs.com/api/bdd/#method_equal
expect(contractOwner).to.equal(accounts[0].address);
});

it("Should not allow anyone other than owner to call transferOwnership", async function () {
// https://hardhat.org/plugins/nomiclabs-hardhat-ethers.html#helpers
const accounts = await ethers.getSigners();
// https://docs.ethers.io/v5/api/contract/contract/#Contract-connect
// https://docs.ethers.io/v5/api/contract/contract/#contract-functionsSend
// https://hardhat.org/hardhat-chai-matchers/docs/overview#reverts
await expect(
helloWorldContract
.connect(accounts[1])
.transferOwnership(accounts[1].address)
).to.be.revertedWith("Caller is not the owner");
});

it("Should execute transferOwnership correctly", async function () {
// TODO
throw Error("Not implemented");
});

it("Should not allow anyone other than owner to change text", async function () {
// TODO
throw Error("Not implemented");
});

it("Should change text correctly", async function () {
// TODO
throw Error("Not implemented");
});
});
124 changes: 0 additions & 124 deletions Week6/project/tests/Lock.ts

This file was deleted.

0 comments on commit 1cb8e09

Please sign in to comment.