-
Notifications
You must be signed in to change notification settings - Fork 744
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add script and ci to check if genesis code is generated from la…
…test code
- Loading branch information
Showing
2 changed files
with
98 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,51 @@ | ||
name: Check If Genesis Is Latest | ||
on: | ||
push: | ||
branches: | ||
- master | ||
- develop | ||
pull_request: | ||
branches: | ||
- master | ||
- develop | ||
permissions: | ||
contents: read | ||
# Optional: allow read access to pull request. Use with `only-new-issues` option. | ||
# pull-requests: read | ||
jobs: | ||
unit-test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@master | ||
- name: Get yarn cache directory path | ||
id: yarn-cache-dir-path | ||
run: echo "::set-output name=dir::$(yarn cache dir)" | ||
- uses: actions/cache@v1 | ||
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) | ||
with: | ||
path: ${{ steps.yarn-cache-dir-path.outputs.dir }} | ||
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | ||
restore-keys: | | ||
${{ runner.os }}-yarn- | ||
- name: Install Foundry | ||
uses: foundry-rs/foundry-toolchain@v1 | ||
|
||
- name: Install Poetry | ||
uses: snok/install-poetry@v1 | ||
|
||
- name: Install Project Dependencies | ||
run: | | ||
npm install ts-node -g | ||
npm install | ||
poetry install | ||
forge install --no-git --no-commit foundry-rs/forge-std@v1.7.3 | ||
forge --version | ||
- name: Build | ||
run: | | ||
forge build | ||
- name: Check Genesis Bytecode | ||
run: | | ||
ts-node scripts/check-genesis-bytecode.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,47 @@ | ||
import 'dotenv/config'; | ||
import {execSync} from 'child_process'; | ||
import * as assert from "assert"; | ||
import * as fs from "fs"; | ||
|
||
const log = console.log; | ||
|
||
const work = async () => { | ||
log('compare current bytecode with latest mainnet contracts') | ||
let str = (fs.readFileSync(__dirname + '/../genesis.json')).toString(); | ||
const currentGenesis = JSON.parse(str); | ||
log('currentGenesis size:', JSON.stringify(currentGenesis, null, 2).length) | ||
|
||
const result = execSync('poetry run python -m scripts.generate mainnet') | ||
const resultStr = result.toString() | ||
if (resultStr.indexOf('Generate genesis of mainnet successfully') === -1) { | ||
throw Error(`generate mainnet genesis failed, error result: ${resultStr}`) | ||
} | ||
await sleep(5) | ||
log('generated mainnet genesis') | ||
|
||
str = (fs.readFileSync(__dirname + '/../genesis.json')).toString(); | ||
const generatedGenesis = JSON.parse(str); | ||
log('generatedGenesis size:', JSON.stringify(generatedGenesis, null, 2).length) | ||
|
||
log('try deepStrictEqual(currentGenesis, generatedGenesis)') | ||
assert.deepStrictEqual(currentGenesis, generatedGenesis) | ||
|
||
log('Success! genesis bytecode not changed') | ||
}; | ||
|
||
const sleep = async (seconds: number) => { | ||
console.log('sleep', seconds, 's'); | ||
await new Promise((resolve) => setTimeout(resolve, seconds * 1000)); | ||
}; | ||
|
||
const main = async () => { | ||
await work(); | ||
}; | ||
|
||
main() | ||
.then(() => process.exit(0)) | ||
.catch((error) => { | ||
console.error(error); | ||
process.exit(1); | ||
}); | ||
|