diff --git a/.github/workflows/ci-client-cli.yml b/.github/workflows/ci-client-cli.yml deleted file mode 100644 index fdc2c4e..0000000 --- a/.github/workflows/ci-client-cli.yml +++ /dev/null @@ -1,51 +0,0 @@ -name: ci-client-cli - -on: - push: - branches: - - master - pull_request: - - -jobs: - npm-install-1: - strategy: - fail-fast: false - matrix: - net: ['testnet_v1'] - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: '16' - - name: Get yarn cache directory path - id: yarn-cache-dir-path - run: echo "::set-output name=dir::$(yarn cache dir)" - - name: Node Cache - uses: actions/cache@v4 - id: npm-and-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 }} - ~/.npm - key: ${{ runner.os }}-node_modules-${{ hashFiles('/home/runner/work/**/package-lock.json', '/home/runner/work/**/yarn.lock') }} - restore-keys: | - ${{ runner.os }}-node_modules- - - name: prepare env - id: runtest - run: | - npm install --save-dev mocha @types/mocha chai @types/chai - sh prepare.sh - - name: run test - id: test-cli - run: | - npm run test-cli - - - name: Publish reports - if: failure() - uses: actions/upload-artifact@v4 - with: - name: jfoa-build-reports-${{ runner.os }} - path: mochawesome-report/ diff --git a/.github/workflows/ci-data-wasm.yml b/.github/workflows/ci-data-wasm.yml index 409f9c2..d2ba120 100644 --- a/.github/workflows/ci-data-wasm.yml +++ b/.github/workflows/ci-data-wasm.yml @@ -1,6 +1,21 @@ name: ci-data-wasm on: + workflow_dispatch: + inputs: + ckb_light_client_url: + description: 'CKB Light Client Repository URL' + required: false + default: 'https://github.com/nervosnetwork/ckb-light-client.git' + ckb_light_client_branch: + description: 'CKB Light Client Branch' + required: false + default: 'develop' + rusqlite: + description: 'Enable rusqlite feature' + required: false + default: '' + type: string push: branches: - master @@ -24,6 +39,10 @@ jobs: node-version: '16' - name: prepare env id: runtest + env: + CKB_LIGHT_CLIENT_URL: ${{ github.event.inputs.ckb_light_client_url || 'https://github.com/nervosnetwork/ckb-light-client.git' }} + CKB_LIGHT_CLIENT_BRANCH: ${{ github.event.inputs.ckb_light_client_branch || 'develop' }} + RUSQLITE: ${{ github.event.inputs.rusqlite }} run: | bash prepare_wasm.sh npm install --save-dev mocha @types/mocha chai @types/chai diff --git a/.github/workflows/ci-data.yml b/.github/workflows/ci-data.yml index e6bf476..6e33ab5 100644 --- a/.github/workflows/ci-data.yml +++ b/.github/workflows/ci-data.yml @@ -1,6 +1,21 @@ name: ci-data on: + workflow_dispatch: + inputs: + ckb_light_client_url: + description: 'CKB Light Client Repository URL' + required: false + default: 'https://github.com/nervosnetwork/ckb-light-client.git' + ckb_light_client_branch: + description: 'CKB Light Client Branch' + required: false + default: 'develop' + rusqlite: + description: 'Enable rusqlite feature' + required: false + default: '' + type: string push: branches: - master @@ -35,6 +50,10 @@ jobs: ${{ runner.os }}-node_modules- - name: prepare env id: runtest + env: + CKB_LIGHT_CLIENT_URL: ${{ github.event.inputs.ckb_light_client_url || 'https://github.com/nervosnetwork/ckb-light-client.git' }} + CKB_LIGHT_CLIENT_BRANCH: ${{ github.event.inputs.ckb_light_client_branch || 'develop' }} + RUSQLITE: ${{ github.event.inputs.rusqlite }} run: | npm install --save-dev mocha @types/mocha chai @types/chai sh prepare.sh diff --git a/.github/workflows/ci-dev.yml b/.github/workflows/ci-dev.yml index 8643fcf..06ae7d9 100644 --- a/.github/workflows/ci-dev.yml +++ b/.github/workflows/ci-dev.yml @@ -1,6 +1,21 @@ name: ci-dev on: + workflow_dispatch: + inputs: + ckb_light_client_url: + description: 'CKB Light Client Repository URL' + required: false + default: 'https://github.com/nervosnetwork/ckb-light-client.git' + ckb_light_client_branch: + description: 'CKB Light Client Branch' + required: false + default: 'develop' + rusqlite: + description: 'Enable rusqlite feature' + required: false + default: '' + type: string push: branches: - master @@ -24,6 +39,10 @@ jobs: node-version: '16' - name: prepare env id: runtest + env: + CKB_LIGHT_CLIENT_URL: ${{ github.event.inputs.ckb_light_client_url || 'https://github.com/nervosnetwork/ckb-light-client.git' }} + CKB_LIGHT_CLIENT_BRANCH: ${{ github.event.inputs.ckb_light_client_branch || 'develop' }} + RUSQLITE: ${{ github.event.inputs.rusqlite }} run: | npm install --save-dev mocha @types/mocha chai @types/chai sh prepare_dev.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 68b6620..6bbdc23 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,21 @@ name: ci on: + workflow_dispatch: + inputs: + ckb_light_client_url: + description: 'CKB Light Client Repository URL' + required: false + default: 'https://github.com/nervosnetwork/ckb-light-client.git' + ckb_light_client_branch: + description: 'CKB Light Client Branch' + required: false + default: 'develop' + rusqlite: + description: 'Enable rusqlite feature' + required: false + default: '' + type: string push: branches: - master diff --git a/.github/workflows/ckb-index-panic.yml b/.github/workflows/ckb-index-panic.yml deleted file mode 100644 index 07d7557..0000000 --- a/.github/workflows/ckb-index-panic.yml +++ /dev/null @@ -1,51 +0,0 @@ -name: ckb-index-panic - -on: - workflow_dispatch: - - - -jobs: - npm-install-1: - strategy: - fail-fast: false - matrix: - net: ['testnet_v1'] - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - with: - ref: roll-back - - uses: actions/setup-node@v3 - with: - node-version: '16' - - name: Get yarn cache directory path - id: yarn-cache-dir-path - run: echo "::set-output name=dir::$(yarn cache dir)" - - name: Node Cache - uses: actions/cache@v4 - id: npm-and-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 }} - ~/.npm - key: ${{ runner.os }}-node_modules-${{ hashFiles('/home/runner/work/**/package-lock.json', '/home/runner/work/**/yarn.lock') }} - restore-keys: | - ${{ runner.os }}-node_modules- - - name: test - id: runtest - run: | - npm install --save-dev mocha @types/mocha chai @types/chai - sh prepare.sh - cd tmp/startBlockchain/ckbDevWithIndexAndLightClient - sh prepare.sh - sh start.sh - cd ../../../ - npm run test-index-panic - - name: Publish reports - if: failure() - uses: actions/upload-artifact@v4 - with: - name: jfoa-build-reports-${{ runner.os }} - path: mochawesome-report/ diff --git a/.github/workflows/ckb-light-client-ci-wasm.yml b/.github/workflows/ckb-light-client-ci-wasm.yml index d19c69b..0e58723 100644 --- a/.github/workflows/ckb-light-client-ci-wasm.yml +++ b/.github/workflows/ckb-light-client-ci-wasm.yml @@ -2,6 +2,20 @@ name: ci-ckb-wasm on: workflow_dispatch: + inputs: + ckb_light_client_url: + description: 'CKB Light Client Repository URL' + required: false + default: 'https://github.com/nervosnetwork/ckb-light-client.git' + ckb_light_client_branch: + description: 'CKB Light Client Branch' + required: false + default: 'develop' + rusqlite: + description: 'Enable rusqlite feature' + required: false + default: '' + type: string push: branches: - master @@ -38,6 +52,10 @@ jobs: ${{ runner.os }}-node_modules- - name: prepare env id: runtest + env: + CKB_LIGHT_CLIENT_URL: ${{ github.event.inputs.ckb_light_client_url || 'https://github.com/nervosnetwork/ckb-light-client.git' }} + CKB_LIGHT_CLIENT_BRANCH: ${{ github.event.inputs.ckb_light_client_branch || 'develop' }} + RUSQLITE: ${{ github.event.inputs.rusqlite }} run: | npm install --save-dev mocha @types/mocha chai @types/chai bash prepare_wasm.sh diff --git a/.github/workflows/ckb-light-client-ci.yml b/.github/workflows/ckb-light-client-ci.yml index 24e3bee..92b244c 100644 --- a/.github/workflows/ckb-light-client-ci.yml +++ b/.github/workflows/ckb-light-client-ci.yml @@ -2,6 +2,20 @@ name: ci-ckb on: workflow_dispatch: + inputs: + ckb_light_client_url: + description: 'CKB Light Client Repository URL' + required: false + default: 'https://github.com/nervosnetwork/ckb-light-client.git' + ckb_light_client_branch: + description: 'CKB Light Client Branch' + required: false + default: 'develop' + rusqlite: + description: 'Enable rusqlite feature' + required: false + default: '' + type: string push: branches: - master @@ -36,6 +50,10 @@ jobs: ${{ runner.os }}-node_modules- - name: prepare env id: runtest + env: + CKB_LIGHT_CLIENT_URL: ${{ github.event.inputs.ckb_light_client_url || 'https://github.com/nervosnetwork/ckb-light-client.git' }} + CKB_LIGHT_CLIENT_BRANCH: ${{ github.event.inputs.ckb_light_client_branch || 'develop' }} + RUSQLITE: ${{ github.event.inputs.rusqlite }} run: | npm install --save-dev mocha @types/mocha chai @types/chai sh prepare.sh diff --git a/.github/workflows/ckb-light-client-roll-back.yml b/.github/workflows/ckb-light-client-roll-back.yml index 887a566..206744e 100644 --- a/.github/workflows/ckb-light-client-roll-back.yml +++ b/.github/workflows/ckb-light-client-roll-back.yml @@ -2,6 +2,20 @@ name: ckb-light-client-roll-back on: workflow_dispatch: + inputs: + ckb_light_client_url: + description: 'CKB Light Client Repository URL' + required: false + default: 'https://github.com/nervosnetwork/ckb-light-client.git' + ckb_light_client_branch: + description: 'CKB Light Client Branch' + required: false + default: 'develop' + rusqlite: + description: 'Enable rusqlite feature' + required: false + default: '' + type: string @@ -35,6 +49,10 @@ jobs: ${{ runner.os }}-node_modules- - name: test id: runtest + env: + CKB_LIGHT_CLIENT_URL: ${{ github.event.inputs.ckb_light_client_url || 'https://github.com/nervosnetwork/ckb-light-client.git' }} + CKB_LIGHT_CLIENT_BRANCH: ${{ github.event.inputs.ckb_light_client_branch || 'develop' }} + RUSQLITE: ${{ github.event.inputs.rusqlite }} run: | npm install --save-dev mocha @types/mocha chai @types/chai sh prepare.sh diff --git a/.github/workflows/miner-load.yml b/.github/workflows/miner-load.yml deleted file mode 100644 index 8a23b94..0000000 --- a/.github/workflows/miner-load.yml +++ /dev/null @@ -1,48 +0,0 @@ -name: miner-load - -on: - workflow_dispatch: - - -jobs: - npm-install-1: - strategy: - fail-fast: false - matrix: - net: ['testnet_v1'] - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: '16' - - name: Get yarn cache directory path - id: yarn-cache-dir-path - run: echo "::set-output name=dir::$(yarn cache dir)" - - name: Node Cache - uses: actions/cache@v4 - id: npm-and-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 }} - ~/.npm - key: ${{ runner.os }}-node_modules-${{ hashFiles('/home/runner/work/**/package-lock.json', '/home/runner/work/**/yarn.lock') }} - restore-keys: | - ${{ runner.os }}-node_modules- - - name: prepare env - id: runtest - run: | - npm install --save-dev mocha @types/mocha chai @types/chai - sh prepare.sh - - name: run test - id: load-test - run: | - npm run test-load - - - name: Publish reports - if: failure() - uses: actions/upload-artifact@v4 - with: - name: jfoa-build-reports-${{ runner.os }} - path: mochawesome-report/ diff --git a/prepare.sh b/prepare.sh index a66d717..8105e0b 100644 --- a/prepare.sh +++ b/prepare.sh @@ -8,8 +8,3 @@ sh start.sh sh status.sh cat ckb-light-client/target/release/node.log echo "prepare ckb Light Client finish" -cd ../../ -git clone https://github.com/TheWaWaR/ckb-cli-light-client.git -cd ckb-cli-light-client -cargo build -echo "prepare ckb-cli-light-client finish" diff --git a/service/node.ts b/service/node.ts index 3537238..cba6de0 100644 --- a/service/node.ts +++ b/service/node.ts @@ -16,6 +16,7 @@ class LightClient { async start(): Promise { if (checkLightClientWasm()){ await request(1,this.url,"start",[]) + await sleep(5*1000) return true } await sh("cd " + this.dirPath + "/target/release && RUST_LOG=info,ckb_light_client=trace ./ckb-light-client run --config-file ./config.toml > node.log 2>&1 &") diff --git a/service/txService.ts b/service/txService.ts index 85f3f47..898baa0 100644 --- a/service/txService.ts +++ b/service/txService.ts @@ -122,7 +122,7 @@ export async function getCkbTransactionList(scriptObject: Script, script_type: S }, "asc", - BI.from(3000).toHexString(), lastCursor + BI.from(1000).toHexString(), lastCursor ) if (result.objects.length == 0) { return txList @@ -158,7 +158,7 @@ export async function getLightTransactionList(scriptObject: Script, script_type: }, "asc", - BI.from(3000).toHexString(),lastCursor + BI.from(1000).toHexString(),lastCursor ) if (result.objects.length == 0) { return txList @@ -193,7 +193,7 @@ export async function getTransactionsLength(scriptObject: Script, script_type: S }, "asc", - BI.from(3000).toHexString() + BI.from(1000).toHexString() ) if (result.objects.length == 0) { break @@ -216,7 +216,7 @@ export async function getCellsByRange(scriptObject: Script, script_type: ScriptT filter: { blockRange: block_range } - }, "asc", "0xfff", lastCursor) + }, "asc", "0x1ff", lastCursor) if (result.objects.length == 0) { break } diff --git a/test/get_header.spec.ts b/test/get_header.spec.ts index ca45bcf..ddd7439 100644 --- a/test/get_header.spec.ts +++ b/test/get_header.spec.ts @@ -9,7 +9,10 @@ import {waitScriptsUpdate} from "../service/lightService"; describe('get_header', function () { this.timeout(600_000) - + it("dd",async ()=>{ + let acc = generateAccountFromPrivateKey(ACCOUNT_PRIVATE) + console.log(acc) + }) it("query the hash that does not exist on the ckb chain,should return null", async () => { let response = await getHeader("0x1d7c6f92fa3335bf01c3f43f8970cb586d2dee81b90d363169dbe1bba98d6c11") console.log('response:', response) @@ -20,7 +23,7 @@ describe('get_header', function () { let script = generateAccountFromPrivateKey(ACCOUNT_PRIVATE).lockScript let cells = await indexerMockLightRpc.getCells({ script:script,scriptType:"lock" - }, "asc","0xfff") + }, "asc","0x1ff") // set scripts :( account,cells[0].height -1 ) ,want to collected cells that not used ; await lightClientRPC.setScripts([{script: script,scriptType:"lock", blockNumber: BI.from(cells.objects[0].blockNumber).sub(1).toHexString()}]) @@ -32,7 +35,7 @@ describe('get_header', function () { let response = await lightClientRPC.getCells({ script:script, scriptType:"lock" - }, "asc", "0xfff") + }, "asc", "0x1ff") let block = await rpcCLient.getBlockByNumber(response.objects[0].blockNumber.toString()) if (block == undefined) { diff --git a/test/get_transactions.spec.ts b/test/get_transactions.spec.ts index cf7d5a2..db501c7 100644 --- a/test/get_transactions.spec.ts +++ b/test/get_transactions.spec.ts @@ -26,7 +26,7 @@ describe('get_transactions', function () { let txs = await rpcCLient.getTransactions({ "script": test_scripts[0].script, "scriptType": test_scripts[0].scriptType, "groupByTransaction": true - }, "asc", "0xfff") + }, "asc", "0x1ff") console.log(txs.objects[0].blockNumber) console.log(txs.objects[txs.objects.length - 1].blockNumber) await lightClientRPC.setScripts([ @@ -51,7 +51,7 @@ describe('get_transactions', function () { filter: { blockRange: [BI.from(12112687).sub(1).toHexString(), BI.from(12116260).toHexString()], } - }, "asc", "0xfff", lightAfterCursor + }, "asc", "0x1ff", lightAfterCursor ) let ckbTxs = await rpcCLient.getTransactions({ "script": test_scripts[0].script, "scriptType": test_scripts[0].scriptType, @@ -59,20 +59,20 @@ describe('get_transactions', function () { filter: { blockRange: [BI.from(12112687).sub(1).toHexString(), BI.from(12116260).toHexString()], } - }, "asc", "0xfff", ckbAfterCursor) + }, "asc", "0x1ff", ckbAfterCursor) console.log("lightTxs.objects.length:", lightTxs.objects.length) console.log("ckbTxs.objects.length:", ckbTxs.objects.length) - expect(lightTxs.objects.length == ckbTxs.objects.length, "light txs length not equal ckb txs length") + expect(lightTxs.objects.length ).to.be.equal( ckbTxs.objects.length, "light txs length not equal ckb txs length") for (let i = 0; i < lightTxs.objects.length; i++) { let lightTx = lightTxs.objects[i] let ckbTx = ckbTxs.objects[i] // console.log("lightTx:", lightTx) // console.log("ckbTx:", ckbTx) - expect(lightTx.transaction.hash == ckbTx.txHash, "light tx hash not equal ckb tx hash") - expect(lightTx.blockNumber == ckbTx.blockNumber, "light block number not equal ckb tx hash") - expect(lightTx.ioIndex == ckbTx.ioIndex, "light block number not equal ckb tx hash") - expect(lightTx.txIndex == ckbTx.txIndex, "light block number not equal ckb tx hash") + expect(lightTx.transaction.hash).to.be.equal(ckbTx.txHash, "light tx hash not equal ckb tx hash") + expect(lightTx.blockNumber ).to.be.equal( ckbTx.blockNumber, "light block number not equal ckb tx hash") + expect(lightTx.ioIndex ).to.be.equal( ckbTx.ioIndex, "light block number not equal ckb tx hash") + expect(lightTx.txIndex ).to.be.equal( ckbTx.txIndex, "light block number not equal ckb tx hash") } lightAfterCursor = lightTxs.lastCursor ckbAfterCursor = ckbTxs.lastCursor @@ -93,7 +93,7 @@ describe('get_transactions', function () { filter: { blockRange: [BI.from(12112687).sub(1).toHexString(), BI.from(12116260).toHexString()], } - }, "asc", BI.from(5000).toHexString(), lightAfterCursor + }, "asc", BI.from(1000).toHexString(), lightAfterCursor ) if(lightTxs.objects.length == 0){ return @@ -105,18 +105,20 @@ describe('get_transactions', function () { filter: { blockRange: [BI.from(12112687).sub(1).toHexString(), BI.from(12116260).toHexString()], } - }, "asc", BI.from(5000).toHexString(), ckbAfterCursor) + }, "asc", BI.from(1000).toHexString(), ckbAfterCursor) console.log("lightTxs.objects.length:", lightTxs.objects.length) console.log("ckbTxs.objects.length:", ckbTxs.objects.length) - expect(lightTxs.objects.length == ckbTxs.objects.length, "light txs length not equal ckb txs length") + expect(lightTxs.objects.length ).to.be.equal( ckbTxs.objects.length, "light txs length not equal ckb txs length") for (let i = 0; i < lightTxs.objects.length; i++) { let lightTx = lightTxs.objects[i] let ckbTx = ckbTxs.objects[i] - expect(lightTx.transaction.hash == ckbTx.txHash, "light tx hash not equal ckb tx hash") - expect(lightTx.blockNumber == ckbTx.blockNumber, "light block number not equal ckb tx hash") - expect(lightTx.cells == ckbTx.cells, "light block number not equal ckb tx hash") - expect(lightTx.txIndex == ckbTx.txIndex, "light block number not equal ckb tx hash") + // console.log("index:",i," lightTx:", lightTx.transaction.hash,JSON.stringify(lightTx.cells) ) + // console.log("ckbTx:", ckbTx.txHash) + expect(lightTx.transaction.hash ).to.be.equal( ckbTx.txHash, "light tx hash not equal ckb tx hash") + expect(lightTx.blockNumber ).to.be.equal( ckbTx.blockNumber, "light block number not equal ckb tx hash") + expect(JSON.stringify(lightTx.cells) ).to.be.equal( JSON.stringify(ckbTx.cells), "light block number not equal ckb tx hash") + expect(lightTx.txIndex ).to.be.equal( ckbTx.txIndex, "light block number not equal ckb tx hash") } lightAfterCursor = lightTxs.lastCursor ckbAfterCursor = ckbTxs.lastCursor @@ -125,4 +127,4 @@ describe('get_transactions', function () { } }) -}); +}); \ No newline at end of file diff --git a/update_submodule.sh b/update_submodule.sh new file mode 100644 index 0000000..34a1a62 --- /dev/null +++ b/update_submodule.sh @@ -0,0 +1,35 @@ +#!/bin/bash +set -e + +if [ $# -lt 2 ]; then + echo "Usage: $0 " + exit 1 +fi + +URL=$1 +BRANCH=$2 + +echo "Updating submodule 'ckb-light-wasm-demo' configuration..." +echo " URL: $URL" +echo " Branch: $BRANCH" + +# Ensure we are in the script's directory +cd "$(dirname "$0")" + +# Update .gitmodules +git config -f .gitmodules submodule.ckb-light-wasm-demo.url "$URL" +git config -f .gitmodules submodule.ckb-light-wasm-demo.branch "$BRANCH" + +# Sync configuration to .git/config +git submodule sync ckb-light-wasm-demo + +# Initialize and update the submodule +git submodule update --init --recursive --remote ckb-light-wasm-demo + +# Checkout the specific branch +cd ckb-light-wasm-demo +git fetch origin +git checkout "$BRANCH" +git pull origin "$BRANCH" + +echo "Submodule 'ckb-light-client' updated successfully." \ No newline at end of file