-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
93 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
_; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.