diff --git a/.github/workflows/check-genesis.yml b/.github/workflows/check-genesis.yml new file mode 100644 index 00000000..fe947391 --- /dev/null +++ b/.github/workflows/check-genesis.yml @@ -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 diff --git a/scripts/check-genesis-bytecode.ts b/scripts/check-genesis-bytecode.ts new file mode 100644 index 00000000..b3362631 --- /dev/null +++ b/scripts/check-genesis-bytecode.ts @@ -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); + }); +