-
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
15 changed files
with
8,364 additions
and
0 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,10 @@ | ||
root = true | ||
|
||
[*] | ||
end_of_line = lf | ||
insert_final_newline = true | ||
|
||
[*.{js,json,yml}] | ||
charset = utf-8 | ||
indent_style = space | ||
indent_size = 2 |
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,23 @@ | ||
.yarn/* | ||
!.yarn/patches | ||
!.yarn/plugins | ||
!.yarn/releases | ||
!.yarn/sdks | ||
!.yarn/versions | ||
|
||
# Swap the comments on the following lines if you don't wish to use zero-installs | ||
# Documentation here: https://yarnpkg.com/features/zero-installs | ||
!.yarn/cache | ||
#.pnp.* | ||
|
||
node_modules | ||
.env | ||
coverage | ||
coverage.json | ||
typechain | ||
typechain-types | ||
|
||
# Hardhat files | ||
cache | ||
artifacts | ||
|
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,5 @@ | ||
{ | ||
"require": "hardhat/register", | ||
"timeout": 40000, | ||
"_": ["tests/**/*.ts"] | ||
} |
Large diffs are not rendered by default.
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,3 @@ | ||
nodeLinker: node-modules | ||
|
||
yarnPath: .yarn/releases/yarn-3.5.1.cjs |
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,22 @@ | ||
➤ YN0027: @types/mocha@@unknown can't be resolved to a satisfying range | ||
➤ YN0035: The remote server failed to provide the requested resource | ||
➤ YN0035: Response Code: 404 (Not Found) | ||
➤ YN0035: Request Method: GET | ||
➤ YN0035: Request URL: https://registry.yarnpkg.com/@types%2fmocha@ | ||
➤ YN0027: @types/node@@unknown can't be resolved to a satisfying range | ||
➤ YN0035: The remote server failed to provide the requested resource | ||
➤ YN0035: Response Code: 404 (Not Found) | ||
➤ YN0035: Request Method: GET | ||
➤ YN0035: Request URL: https://registry.yarnpkg.com/@types%2fnode@ | ||
➤ YN0027: ts-node@@unknown can't be resolved to a satisfying range | ||
➤ YN0035: The remote server failed to provide the requested resource | ||
➤ YN0035: Response Code: 404 (Not Found) | ||
➤ YN0035: Request Method: GET | ||
➤ YN0035: Request URL: https://registry.yarnpkg.com/ts-node@ | ||
➤ YN0027: typescript@@unknown can't be resolved to a satisfying range | ||
➤ YN0035: The remote server failed to provide the requested resource | ||
➤ YN0035: Response Code: 404 (Not Found) | ||
➤ YN0035: Request Method: GET | ||
➤ YN0035: Request URL: https://registry.yarnpkg.com/typescript@ | ||
|
||
➤ Errors happened when preparing the environment required to run this command. |
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,7 @@ | ||
➤ YN0027: @types/mocha@@unknown can't be resolved to a satisfying range | ||
➤ YN0035: The remote server failed to provide the requested resource | ||
➤ YN0035: Response Code: 404 (Not Found) | ||
➤ YN0035: Request Method: GET | ||
➤ YN0035: Request URL: https://registry.yarnpkg.com/@types%2fmocha@ | ||
|
||
➤ Errors happened when preparing the environment required to run this command. |
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,13 @@ | ||
# Sample Hardhat Project | ||
|
||
This project demonstrates a basic Hardhat use case. It comes with a sample contract, a test for that contract, and a script that deploys that contract. | ||
|
||
Try running some of the following tasks: | ||
|
||
```shell | ||
npx hardhat help | ||
npx hardhat test | ||
REPORT_GAS=true npx hardhat test | ||
npx hardhat node | ||
npx hardhat run scripts/deploy.ts | ||
``` |
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,34 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.9; | ||
|
||
// Uncomment this line to use console.log | ||
// import "hardhat/console.sol"; | ||
|
||
contract Lock { | ||
uint public unlockTime; | ||
address payable public owner; | ||
|
||
event Withdrawal(uint amount, uint when); | ||
|
||
constructor(uint _unlockTime) payable { | ||
require( | ||
block.timestamp < _unlockTime, | ||
"Unlock time should be in the future" | ||
); | ||
|
||
unlockTime = _unlockTime; | ||
owner = payable(msg.sender); | ||
} | ||
|
||
function withdraw() public { | ||
// Uncomment this line, and the import of "hardhat/console.sol", to print a log in your terminal | ||
// console.log("Unlock time is %o and block timestamp is %o", unlockTime, block.timestamp); | ||
|
||
require(block.timestamp >= unlockTime, "You can't withdraw yet"); | ||
require(msg.sender == owner, "You aren't the owner"); | ||
|
||
emit Withdrawal(address(this).balance, block.timestamp); | ||
|
||
owner.transfer(address(this).balance); | ||
} | ||
} |
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,9 @@ | ||
import { HardhatUserConfig } from "hardhat/config"; | ||
import "@nomicfoundation/hardhat-toolbox"; | ||
|
||
const config: HardhatUserConfig = { | ||
solidity: "0.8.18", | ||
paths: { tests: "tests" }, | ||
}; | ||
|
||
export default config; |
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,24 @@ | ||
{ | ||
"name": "project", | ||
"packageManager": "[email protected]", | ||
"devDependencies": { | ||
"@nomicfoundation/hardhat-chai-matchers": "1.0.0", | ||
"@nomicfoundation/hardhat-network-helpers": "1.0.0", | ||
"@nomicfoundation/hardhat-toolbox": "2.0.0", | ||
"@nomiclabs/hardhat-ethers": "2.0.0", | ||
"@nomiclabs/hardhat-etherscan": "3.0.0", | ||
"@typechain/ethers-v5": "10.1.0", | ||
"@typechain/hardhat": "6.1.2", | ||
"@types/chai": "4.2.0", | ||
"chai": "4.2.0", | ||
"ethers": "5.4.7", | ||
"hardhat": "2.11.1", | ||
"hardhat-gas-reporter": "1.0.8", | ||
"mocha": "^10.2.0", | ||
"solidity-coverage": "0.8.0", | ||
"typechain": "8.1.0" | ||
}, | ||
"dependencies": { | ||
"typescript": "^5.0.4" | ||
} | ||
} |
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,24 @@ | ||
import { ethers } from "hardhat"; | ||
|
||
async function main() { | ||
const currentTimestampInSeconds = Math.round(Date.now() / 1000); | ||
const unlockTime = currentTimestampInSeconds + 60; | ||
|
||
const lockedAmount = ethers.utils.parseEther("0.001"); | ||
|
||
const Lock = await ethers.getContractFactory("Lock"); | ||
const lock = await Lock.deploy(unlockTime, { value: lockedAmount }); | ||
|
||
await lock.deployed(); | ||
|
||
console.log( | ||
`Lock with ${ethers.utils.formatEther(lockedAmount)}ETH and unlock timestamp ${unlockTime} deployed to ${lock.address}` | ||
); | ||
} | ||
|
||
// We recommend this pattern to be able to use async/await everywhere | ||
// and properly handle errors. | ||
main().catch((error) => { | ||
console.error(error); | ||
process.exitCode = 1; | ||
}); |
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,134 @@ | ||
import { expect } from "chai"; | ||
import { ethers } from "hardhat"; | ||
import { Ballot } from "../typechain-types"; | ||
|
||
const PROPOSALS = ["Proposal 1", "Proposal 2", "Proposal 3"]; | ||
|
||
function convertStringArrayToBytes32(array: string[]) { | ||
const bytes32Array = []; | ||
for (let index = 0; index < array.length; index++) { | ||
bytes32Array.push(ethers.utils.formatBytes32String(array[index])); | ||
} | ||
return bytes32Array; | ||
} | ||
|
||
describe("Ballot", function () { | ||
let ballotContract: Ballot; | ||
|
||
beforeEach(async function () { | ||
const ballotFactory = await ethers.getContractFactory("Ballot"); | ||
ballotContract = await ballotFactory.deploy( | ||
convertStringArrayToBytes32(PROPOSALS) | ||
); | ||
await ballotContract.deployed(); | ||
}); | ||
|
||
describe("when the contract is deployed", function () { | ||
it("has the provided proposals", async function () { | ||
for (let index = 0; index < PROPOSALS.length; index++) { | ||
const proposal = await ballotContract.proposals(index); | ||
expect(ethers.utils.parseBytes32String(proposal.name)).to.eq( | ||
PROPOSALS[index] | ||
); | ||
} | ||
}); | ||
|
||
it("has zero votes for all proposals", async function () { | ||
// TODO | ||
throw Error("Not implemented"); | ||
}); | ||
it("sets the deployer address as chairperson", async function () { | ||
// TODO | ||
throw Error("Not implemented"); | ||
}); | ||
it("sets the voting weight for the chairperson as 1", async function () { | ||
// TODO | ||
throw Error("Not implemented"); | ||
}); | ||
}); | ||
|
||
describe("when the chairperson interacts with the giveRightToVote function in the contract", function () { | ||
it("gives right to vote for another address", async function () { | ||
// TODO | ||
throw Error("Not implemented"); | ||
}); | ||
it("can not give right to vote for someone that has voted", async function () { | ||
// TODO | ||
throw Error("Not implemented"); | ||
}); | ||
it("can not give right to vote for someone that has already voting rights", async function () { | ||
// TODO | ||
throw Error("Not implemented"); | ||
}); | ||
}); | ||
|
||
describe("when the voter interact with the vote function in the contract", function () { | ||
// TODO | ||
it("should register the vote", async () => { | ||
throw Error("Not implemented"); | ||
}); | ||
}); | ||
|
||
describe("when the voter interact with the delegate function in the contract", function () { | ||
// TODO | ||
it("should transfer voting power", async () => { | ||
throw Error("Not implemented"); | ||
}); | ||
}); | ||
|
||
describe("when the an attacker interact with the giveRightToVote function in the contract", function () { | ||
// TODO | ||
it("should revert", async () => { | ||
throw Error("Not implemented"); | ||
}); | ||
}); | ||
|
||
describe("when the an attacker interact with the vote function in the contract", function () { | ||
// TODO | ||
it("should revert", async () => { | ||
throw Error("Not implemented"); | ||
}); | ||
}); | ||
|
||
describe("when the an attacker interact with the delegate function in the contract", function () { | ||
// TODO | ||
it("should revert", async () => { | ||
throw Error("Not implemented"); | ||
}); | ||
}); | ||
|
||
describe("when someone interact with the winningProposal function before any votes are cast", function () { | ||
// TODO | ||
it("should return 0", async () => { | ||
throw Error("Not implemented"); | ||
}); | ||
}); | ||
|
||
describe("when someone interact with the winningProposal function after one vote is cast for the first proposal", function () { | ||
// TODO | ||
it("should return 0", async () => { | ||
throw Error("Not implemented"); | ||
}); | ||
}); | ||
|
||
describe("when someone interact with the winnerName function before any votes are cast", function () { | ||
// TODO | ||
it("should return name of proposal 0", async () => { | ||
throw Error("Not implemented"); | ||
}); | ||
}); | ||
|
||
describe("when someone interact with the winnerName function after one vote is cast for the first proposal", function () { | ||
// TODO | ||
it("should return name of proposal 0", async () => { | ||
throw Error("Not implemented"); | ||
}); | ||
}); | ||
|
||
describe("when someone interact with the winningProposal function and winnerName after 5 random votes are cast for the proposals", function () { | ||
// TODO | ||
it("should return the name of the winner proposal", async () => { | ||
throw Error("Not implemented"); | ||
}); | ||
}); | ||
}); |
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,13 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2020", | ||
"module": "commonjs", | ||
"esModuleInterop": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"strict": true, | ||
"skipLibCheck": true, | ||
"resolveJsonModule": true, | ||
"include": ["./scripts", "./tests", "./typechain-types"], | ||
"files": ["./hardhat.config.ts"], | ||
} | ||
} |
Oops, something went wrong.