From 5c2cab5c0e7092c6b4586bce1b57388b271dd548 Mon Sep 17 00:00:00 2001 From: greatrat00 <> Date: Wed, 7 Jun 2023 12:12:45 +0200 Subject: [PATCH 01/13] advance blocks by running yarn advance-time X where X is the number of blocks to advance --- package.json | 3 ++- scripts/advanceBlocks.ts | 9 +++++++++ scripts/logBlock.ts | 9 +++++++++ scripts/utils/common.ts | 22 ++++++++++++++++++++++ 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 scripts/advanceBlocks.ts create mode 100644 scripts/logBlock.ts diff --git a/package.json b/package.json index dad499a..97b1964 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,8 @@ "test": "yarn ts-node scripts/nouns/nouns.ts", "postinstall": "patch-package", "check": "yarn run solhint 'contracts/interfaces/*.sol' 'contracts/nouns/*.sol'", - "format": "./node_modules/.bin/prettier --write 'contracts/**/*.sol' && ./node_modules/.bin/tsfmt -r `git ls-files '*.ts'`" + "format": "./node_modules/.bin/prettier --write 'contracts/**/*.sol' && ./node_modules/.bin/tsfmt -r `git ls-files '*.ts'`", + "advance-time": "yarn ts-node scripts/advanceBlocks.ts" }, "keywords": [], "author": "", diff --git a/scripts/advanceBlocks.ts b/scripts/advanceBlocks.ts new file mode 100644 index 0000000..a5027e4 --- /dev/null +++ b/scripts/advanceBlocks.ts @@ -0,0 +1,9 @@ +import { advanceBlocks } from "./utils/common"; + +async function advance() { + // process.argv[2] will be the first command-line argument + const numBlocks = process.argv[2] ? parseInt(process.argv[2]) : 1; + await advanceBlocks(numBlocks); +} + +advance(); \ No newline at end of file diff --git a/scripts/logBlock.ts b/scripts/logBlock.ts new file mode 100644 index 0000000..36a9af1 --- /dev/null +++ b/scripts/logBlock.ts @@ -0,0 +1,9 @@ +import { + logCurrentBlockNumber, + } from "./utils/common"; + +async function log() { + await logCurrentBlockNumber(); +} + +log(); \ No newline at end of file diff --git a/scripts/utils/common.ts b/scripts/utils/common.ts index 1035aee..4743b52 100644 --- a/scripts/utils/common.ts +++ b/scripts/utils/common.ts @@ -112,3 +112,25 @@ export async function verify2(addr: string, args) { } } } + +export const advanceBlocks = async (blocks: number): Promise => { + for (let i = 0; i < blocks; i++) { + await mineBlock(); + } +}; + +export const mineBlock = async (): Promise => { + try { + const provider = new ethers.providers.JsonRpcProvider('http://127.0.0.1:8545/'); + await provider.send('evm_mine', []); + //console.log('Block mined successfully'); + } catch (error) { + console.error('Error mining block:', error); + } +}; + +export const logCurrentBlockNumber = async (): Promise => { + const provider = new ethers.providers.JsonRpcProvider('http://127.0.0.1:8545/'); + const blockNumber = await provider.send('eth_blockNumber', []); + console.log('Current block number:', parseInt(blockNumber, 16)); +}; \ No newline at end of file From 920b72976c6dae1895d66efcea5ddcdab3e85eaa Mon Sep 17 00:00:00 2001 From: greatrat00 <> Date: Wed, 7 Jun 2023 12:52:38 +0200 Subject: [PATCH 02/13] changing README console tag to sh to avoid $ being copied when copying code --- README.md | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 5c17ffb..ca73468 100644 --- a/README.md +++ b/README.md @@ -9,26 +9,26 @@ zkVote demo 2. Run `yarn` ### Download ptau file -```console +```sh curl -o circuits/ptau.16 https://hermez.s3-eu-west-1.amazonaws.com/powersOfTau28_hez_final_16.ptau ``` ### Build -```console +```sh yarn build yarn tsc ``` ### Run workflow test -```console +```sh yarn test ``` ### Unit tests -```console +```sh yarn hardhat test ``` @@ -38,14 +38,14 @@ yarn hardhat test own terminal). Launch a development blockchain node: -```console +```sh $ yarn hardhat node ``` Deploy the contract and write the configuration to a file `nouns.config.json`. This file is read by later commands to connect to the contract. -```console +```sh $ yarn ts-node scripts/deploy.ts ``` @@ -53,29 +53,29 @@ Launch 3 committee daemons (each in it's own terminal, as the process will not terminate until votes are tallied). For demo purposes, we set the tally to be triggered when the total voting weight reaches 10. -```console +```sh $ yarn ts-node scripts/committee.ts -v 10 1 ``` -```console +```sh $ yarn ts-node scripts/committee.ts -v 10 2 ``` -```console +```sh $ yarn ts-node scripts/committee.ts -v 10 3 ``` In a new terminal, setup a vote with proposal Id 1 and end block 12345678, register some dummy voters and cast votes up to a total voting weight above 10 (max total voting weight is 20). For example: -```console +```sh $ yarn ts-node scripts/setup_vote.ts 1 12345678 ``` -```console +```sh $ yarn ts-node scripts/vote.ts 1 1 yay 6 ``` -```console +```sh $ yarn ts-node scripts/vote.ts 1 2 nay 3 ``` -```console +```sh $ yarn ts-node scripts/vote.ts 1 3 yay 5 ``` @@ -83,18 +83,18 @@ When the committee commands notice that the total voting weight used is at least 10, they begin the tallying, and will exit after the tallying process is complete. To query the contract for the vote totals for proposal Id 1, run: -```console +```sh $ yarn ts-node scripts/get_vote_tally.ts 1 ``` ## Development Run syntax checkers and linters: -```console +```sh $ yarn run check ``` Use `tsfmt` and `prettier-plugin-solidity` to format all code. Run these manually with: -```console +```sh $ yarn run format ``` From ae74fc48c1973c11a1284e14ca0b1458627a239c Mon Sep 17 00:00:00 2001 From: greatrat00 <> Date: Wed, 7 Jun 2023 12:57:31 +0200 Subject: [PATCH 03/13] adding instructions to README to run advanceBlocks script --- README.md | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ca73468..70e7b24 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ $ yarn ts-node scripts/deploy.ts Launch 3 committee daemons (each in it's own terminal, as the process will not terminate until votes are tallied). For demo purposes, we set the tally to be -triggered when the total voting weight reaches 10. +triggered when the total voting weight reaches 10. Alternatively, it can be run with no `-v` flag and only committee member number parameter. In this case, tally will trigger when `endBlock` is reached. ```sh $ yarn ts-node scripts/committee.ts -v 10 1 @@ -63,10 +63,10 @@ $ yarn ts-node scripts/committee.ts -v 10 2 $ yarn ts-node scripts/committee.ts -v 10 3 ``` -In a new terminal, setup a vote with proposal Id 1 and end block 12345678, register some dummy voters and cast votes up to a total voting weight above 10 +In a new terminal, setup a vote with proposal Id 1 and end block 1234, register some dummy voters and cast votes up to a total voting weight above 10 (max total voting weight is 20). For example: ```sh -$ yarn ts-node scripts/setup_vote.ts 1 12345678 +$ yarn ts-node scripts/setup_vote.ts 1 1234 ``` ```sh @@ -81,7 +81,17 @@ $ yarn ts-node scripts/vote.ts 1 3 yay 5 When the committee commands notice that the total voting weight used is at least 10, they begin the tallying, and will exit after the tallying process is -complete. To query the contract for the vote totals for proposal Id 1, run: +complete. + +If voting weight threshold isn't met or wasn't set upon committee daemon setup, force hardhat to mine `N` blocks by running: + +```sh +$ yarn ts-node scripts/advanceBlocks.ts N +``` + +For the example above, run with `N = 1234` to advance `1234` blocks and ensure `endBlock` is reached. If no `N` is passed, defaults to 1 block advanced. + +To query the contract for the vote totals for proposal Id 1, run: ```sh $ yarn ts-node scripts/get_vote_tally.ts 1 From a9e1ea808e1664346c6c8827888d3528cd0f6b03 Mon Sep 17 00:00:00 2001 From: greatrat00 <> Date: Wed, 7 Jun 2023 13:09:52 +0200 Subject: [PATCH 04/13] eliminating $ signs from cli commands --- README.md | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 70e7b24..e71cec8 100644 --- a/README.md +++ b/README.md @@ -39,14 +39,14 @@ own terminal). Launch a development blockchain node: ```sh -$ yarn hardhat node +yarn hardhat node ``` Deploy the contract and write the configuration to a file `nouns.config.json`. This file is read by later commands to connect to the contract. ```sh -$ yarn ts-node scripts/deploy.ts +yarn ts-node scripts/deploy.ts ``` Launch 3 committee daemons (each in it's own terminal, as the process will not @@ -54,29 +54,29 @@ terminate until votes are tallied). For demo purposes, we set the tally to be triggered when the total voting weight reaches 10. Alternatively, it can be run with no `-v` flag and only committee member number parameter. In this case, tally will trigger when `endBlock` is reached. ```sh -$ yarn ts-node scripts/committee.ts -v 10 1 +yarn ts-node scripts/committee.ts -v 10 1 ``` ```sh -$ yarn ts-node scripts/committee.ts -v 10 2 +yarn ts-node scripts/committee.ts -v 10 2 ``` ```sh -$ yarn ts-node scripts/committee.ts -v 10 3 +yarn ts-node scripts/committee.ts -v 10 3 ``` In a new terminal, setup a vote with proposal Id 1 and end block 1234, register some dummy voters and cast votes up to a total voting weight above 10 (max total voting weight is 20). For example: ```sh -$ yarn ts-node scripts/setup_vote.ts 1 1234 +yarn ts-node scripts/setup_vote.ts 1 1234 ``` ```sh -$ yarn ts-node scripts/vote.ts 1 1 yay 6 +yarn ts-node scripts/vote.ts 1 1 yay 6 ``` ```sh -$ yarn ts-node scripts/vote.ts 1 2 nay 3 +yarn ts-node scripts/vote.ts 1 2 nay 3 ``` ```sh -$ yarn ts-node scripts/vote.ts 1 3 yay 5 +yarn ts-node scripts/vote.ts 1 3 yay 5 ``` When the committee commands notice that the total voting weight used is at @@ -86,7 +86,7 @@ complete. If voting weight threshold isn't met or wasn't set upon committee daemon setup, force hardhat to mine `N` blocks by running: ```sh -$ yarn ts-node scripts/advanceBlocks.ts N +yarn ts-node scripts/advanceBlocks.ts N ``` For the example above, run with `N = 1234` to advance `1234` blocks and ensure `endBlock` is reached. If no `N` is passed, defaults to 1 block advanced. @@ -94,17 +94,17 @@ For the example above, run with `N = 1234` to advance `1234` blocks and ensure ` To query the contract for the vote totals for proposal Id 1, run: ```sh -$ yarn ts-node scripts/get_vote_tally.ts 1 +yarn ts-node scripts/get_vote_tally.ts 1 ``` ## Development Run syntax checkers and linters: ```sh -$ yarn run check +yarn run check ``` Use `tsfmt` and `prettier-plugin-solidity` to format all code. Run these manually with: ```sh -$ yarn run format +yarn run format ``` From 432fd52e08daba119a19a2b1ce40095aa7ddf738 Mon Sep 17 00:00:00 2001 From: greatrat00 <> Date: Wed, 7 Jun 2023 14:51:31 +0200 Subject: [PATCH 05/13] change node-version to 18.x in main.yml --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index dd5acf6..f1a5a1e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,7 +10,7 @@ jobs: strategy: matrix: - node-version: [16.x] + node-version: [18.x] steps: - name: check out git repo From 45d958f17c41f719b7c1c8e4f7e7986e38257ffd Mon Sep 17 00:00:00 2001 From: greatrat00 <> Date: Wed, 7 Jun 2023 15:15:12 +0200 Subject: [PATCH 06/13] changing node version in main.yml to 18.12.0 --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f1a5a1e..c64cfdc 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,7 +10,7 @@ jobs: strategy: matrix: - node-version: [18.x] + node-version: [18.12.0] steps: - name: check out git repo From b36994289cca5200a5df43f7135f8914825620e5 Mon Sep 17 00:00:00 2001 From: greatrat00 <> Date: Wed, 7 Jun 2023 15:18:13 +0200 Subject: [PATCH 07/13] new line at end of file --- scripts/advanceBlocks.ts | 2 +- scripts/logBlock.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/advanceBlocks.ts b/scripts/advanceBlocks.ts index a5027e4..932698f 100644 --- a/scripts/advanceBlocks.ts +++ b/scripts/advanceBlocks.ts @@ -6,4 +6,4 @@ async function advance() { await advanceBlocks(numBlocks); } -advance(); \ No newline at end of file +advance(); diff --git a/scripts/logBlock.ts b/scripts/logBlock.ts index 36a9af1..dc67800 100644 --- a/scripts/logBlock.ts +++ b/scripts/logBlock.ts @@ -6,4 +6,4 @@ async function log() { await logCurrentBlockNumber(); } -log(); \ No newline at end of file +log(); From d1c298cccebede88ea596233085325f03d50436c Mon Sep 17 00:00:00 2001 From: greatrat00 <> Date: Wed, 7 Jun 2023 15:24:28 +0200 Subject: [PATCH 08/13] fixing indentation --- scripts/advanceBlocks.ts | 6 +++--- scripts/logBlock.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/advanceBlocks.ts b/scripts/advanceBlocks.ts index 932698f..d061395 100644 --- a/scripts/advanceBlocks.ts +++ b/scripts/advanceBlocks.ts @@ -1,9 +1,9 @@ import { advanceBlocks } from "./utils/common"; async function advance() { - // process.argv[2] will be the first command-line argument - const numBlocks = process.argv[2] ? parseInt(process.argv[2]) : 1; - await advanceBlocks(numBlocks); + // process.argv[2] will be the first command-line argument + const numBlocks = process.argv[2] ? parseInt(process.argv[2]) : 1; + await advanceBlocks(numBlocks); } advance(); diff --git a/scripts/logBlock.ts b/scripts/logBlock.ts index dc67800..a6e2ecb 100644 --- a/scripts/logBlock.ts +++ b/scripts/logBlock.ts @@ -3,7 +3,7 @@ import { } from "./utils/common"; async function log() { - await logCurrentBlockNumber(); + await logCurrentBlockNumber(); } log(); From 1a8743695c45785585b676ac37790936f549841c Mon Sep 17 00:00:00 2001 From: greatrat00 <> Date: Wed, 7 Jun 2023 15:25:14 +0200 Subject: [PATCH 09/13] fixing indentation in logBlock.ts --- scripts/logBlock.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/logBlock.ts b/scripts/logBlock.ts index a6e2ecb..db4166a 100644 --- a/scripts/logBlock.ts +++ b/scripts/logBlock.ts @@ -1,6 +1,4 @@ -import { - logCurrentBlockNumber, - } from "./utils/common"; +import { logCurrentBlockNumber } from "./utils/common"; async function log() { await logCurrentBlockNumber(); From 2b41f5d68890ab4bd993e4a088216b13e7d0b21c Mon Sep 17 00:00:00 2001 From: greatrat00 <> Date: Wed, 7 Jun 2023 15:27:22 +0200 Subject: [PATCH 10/13] minor indentation edit --- scripts/logBlock.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/logBlock.ts b/scripts/logBlock.ts index db4166a..834a9cd 100644 --- a/scripts/logBlock.ts +++ b/scripts/logBlock.ts @@ -1,4 +1,4 @@ -import { logCurrentBlockNumber } from "./utils/common"; +import { logCurrentBlockNumber } from "./utils/common"; async function log() { await logCurrentBlockNumber(); From 26bab885225ceef1c35857f9cd1cbfa38ef6ba43 Mon Sep 17 00:00:00 2001 From: greatrat00 <> Date: Wed, 7 Jun 2023 15:41:08 +0200 Subject: [PATCH 11/13] adding 16.x and 18.x back into ci matrix --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c64cfdc..039b8f0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,7 +10,7 @@ jobs: strategy: matrix: - node-version: [18.12.0] + node-version: [16.x, 18.x] steps: - name: check out git repo @@ -47,7 +47,7 @@ jobs: uses: actions/cache@v3 with: path: node_modules - key: ${{ runner.os }}-node-modules-${{ hashFiles('**/yarn.lock') }} + key: ${{ runner.os }}-node-${{ matrix.node-version }}-modules-${{ hashFiles('**/yarn.lock') }} - name: Install run: | From 3b6a4693b5dab799a663b60ef10e2d2a8b0c0320 Mon Sep 17 00:00:00 2001 From: greatrat00 <> Date: Wed, 7 Jun 2023 15:53:26 +0200 Subject: [PATCH 12/13] changing 18.x to 18.12.0 which is a version that worked for me into ci matrix --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 039b8f0..4e9b78b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,7 +10,7 @@ jobs: strategy: matrix: - node-version: [16.x, 18.x] + node-version: [16.x, 18.12.0] steps: - name: check out git repo From b5785bccc037257a443e3aba62a42a61ba634e0d Mon Sep 17 00:00:00 2001 From: Duncan Tebbs Date: Wed, 7 Jun 2023 16:07:47 +0100 Subject: [PATCH 13/13] line ending --- scripts/utils/common.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/utils/common.ts b/scripts/utils/common.ts index 4743b52..8c06a14 100644 --- a/scripts/utils/common.ts +++ b/scripts/utils/common.ts @@ -133,4 +133,4 @@ export const logCurrentBlockNumber = async (): Promise => { const provider = new ethers.providers.JsonRpcProvider('http://127.0.0.1:8545/'); const blockNumber = await provider.send('eth_blockNumber', []); console.log('Current block number:', parseInt(blockNumber, 16)); -}; \ No newline at end of file +};