Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add script and ci to check if genesis is generated from latest contracts #585

Merged
merged 2 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions .github/workflows/check-genesis.yml
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:
check-genesis:
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
47 changes: 47 additions & 0 deletions scripts/check-genesis-bytecode.ts
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);
});

Loading