From 3f8eef5dce07d059163c10077306558509bcb543 Mon Sep 17 00:00:00 2001 From: wenyuanhust Date: Tue, 19 Dec 2023 14:34:20 +0800 Subject: [PATCH] test: ci use local axon instead of standard eth client; update ckbMbtVerify --- .github/workflows/test.yaml | 43 +++++++++++++++++++++++++++--- contracts/clients/CkbProof.sol | 8 +----- contracts/clients/CkbTestProof.sol | 3 +-- truffle-config.js | 11 ++++++++ 4 files changed, 53 insertions(+), 12 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 1d46c95..f053fd0 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -8,6 +8,11 @@ on: jobs: test: runs-on: ubuntu-latest + env: + SRC_DIR: ${{ github.workspace }} + # https://github.com/axonweb3/axon/commits/forcerelay-dev + AXON_COMMIT: 343f329b78b8187e28fdac9e9af6c28222656b92 + AXON_HTTP_RPC_URL: "http://127.0.0.1:8000" steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 @@ -15,11 +20,43 @@ jobs: node-version: 18 cache: 'yarn' cache-dependency-path: 'yarn.lock' + + - name: Prepare Axon source + run: git clone --recursive https://github.com/axonweb3/axon.git $SRC_DIR/axon && cd $SRC_DIR/axon && git checkout $AXON_COMMIT + + - name: Rust cache + uses: Swatinem/rust-cache@v2 + with: + workspaces: "." + + - name: Cache axon bin + id: cache-axon-bin + uses: actions/cache@v3 + env: + cache-name: cache-axon-bin + with: + path: ${{env.SRC_DIR}}/axon/target/release/axon + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ env.AXON_COMMIT }} + + - name: Build Axon + if: ${{ steps.cache-axon-bin.outputs.cache-hit != 'true' }} + uses: actions-rs/cargo@v1 + with: + command: build + args: --release --manifest-path ${{env.SRC_DIR}}/axon/Cargo.toml + + - name: Add axon bin to path + run: echo "${{env.SRC_DIR}}/axon/target/release/" >> $GITHUB_PATH + + - name: Config axon + run: axon init --config ${{env.SRC_DIR}}/axon/devtools/chain/config.toml --chain-spec ${{env.SRC_DIR}}/axon/devtools/chain/specs/single_node/chain-spec.toml + + - name: Start axon + run: axon run --config ${{env.SRC_DIR}}/axon/devtools/chain/config.toml & + - run: yarn install - run: npx truffle version - - name: Run Ethereum locally for test - run: npx ganache > ganache.log & - run: yarn compile - name: Run test - run: npx truffle test + run: npx truffle test --network axon_forcerelay diff --git a/contracts/clients/CkbProof.sol b/contracts/clients/CkbProof.sol index 429b2e3..1e96210 100644 --- a/contracts/clients/CkbProof.sol +++ b/contracts/clients/CkbProof.sol @@ -116,13 +116,7 @@ function ckbMbtVerify(VerifyProofPayload memory payload) view returns (bool) { // axon_precompile_address(0x07) address ckb_mbt_addr = address(0x0107); (bool isSuccess, bytes memory res) = ckb_mbt_addr.staticcall( - abi.encode( - payload.verifyType, - payload.transactionsRoot, - payload.witnessesRoot, - payload.rawTransactionsRoot, - payload.proof - ) + abi.encode(payload) ); if (!isSuccess) { diff --git a/contracts/clients/CkbTestProof.sol b/contracts/clients/CkbTestProof.sol index cb1034d..5f8fee5 100644 --- a/contracts/clients/CkbTestProof.sol +++ b/contracts/clients/CkbTestProof.sol @@ -58,8 +58,7 @@ library CkbTestProof { // Create the VerifyProofPayload VerifyProofPayload memory payload = VerifyProofPayload({ verifyType: axonObjProof.proofPayload.verifyType, - // transactionsRoot: header.transactionsRoot, - transactionsRoot: 0x7c57536c95df426f5477c344f8f949e4dfd25443d6f586b4f350ae3e4b870433, + transactionsRoot: header.transactionsRoot, witnessesRoot: axonObjProof.proofPayload.witnessesRoot, rawTransactionsRoot: axonObjProof.proofPayload.rawTransactionsRoot, proof: axonObjProof.proofPayload.proof diff --git a/truffle-config.js b/truffle-config.js index ef0d5b7..2cef113 100644 --- a/truffle-config.js +++ b/truffle-config.js @@ -63,6 +63,17 @@ module.exports = { // Gas price used for deploys. Default is 20000000000 (20 Gwei). gasPrice: 8, }, + + // forcerelay contract is too large to be executed, it needs special version of axon + axon_forcerelay: { + network_id: "*", // Any network (default: none) + provider: () => new HDWalletProvider( + "test test test test test test test test test test test junk", + process.env.AXON_HTTP_RPC_URL + ), + // Gas price used for deploys. Default is 20000000000 (20 Gwei). + gasPrice: 8, + }, }, // Set default mocha options here, use special reporters etc.