From a708b3fe45f41a7870fb643ab26fd3c15adff4f5 Mon Sep 17 00:00:00 2001 From: Dawn <13477199767@163.com> Date: Mon, 17 Jun 2024 17:08:32 +0800 Subject: [PATCH 1/7] refactor: Refactor integration test cases --- .github/workflows/integration-test.yaml | 12 ++--- .github/workflows/test.yaml | 6 +-- tests/rgbpp/env.ts | 14 +++-- tests/rgbpp/shared/prepare-utxo.ts | 15 +++--- tests/rgbpp/spore/4-transfer-spore.ts | 21 ++++---- tests/rgbpp/spore/5-leap-spore-to-ckb.ts | 23 ++++---- tests/rgbpp/spore/launch/2-create-cluster.ts | 25 ++++----- tests/rgbpp/spore/launch/3-create-spores.ts | 37 +++++-------- tests/rgbpp/xudt/2-btc-transfer.ts | 57 ++++++++++---------- tests/rgbpp/xudt/3-btc-leap-ckb.ts | 22 ++++---- 10 files changed, 108 insertions(+), 124 deletions(-) diff --git a/.github/workflows/integration-test.yaml b/.github/workflows/integration-test.yaml index 82011340..13c30285 100644 --- a/.github/workflows/integration-test.yaml +++ b/.github/workflows/integration-test.yaml @@ -49,9 +49,9 @@ jobs: if: ${{ matrix.env_set == 'xudt' }} run: pnpm run integration:xudt env: - VITE_SERVICE_URL: ${{ secrets.SERVICE_URL }} - VITE_SERVICE_TOKEN: ${{ secrets.SERVICE_TOKEN }} - VITE_SERVICE_ORIGIN: ${{ secrets.SERVICE_ORIGIN }} + VITE_SERVICE_URL: https://api.signet.rgbpp.io + VITE_SERVICE_TOKEN: ${{ secrets.SIGNET_SERVICE_TOKEN }} + VITE_SERVICE_ORIGIN: https://api.signet.rgbpp.io INTEGRATION_CKB_PRIVATE_KEY: ${{ secrets.INTEGRATION_CKB_PRIVATE_KEY }} INTEGRATION_BTC_PRIVATE_KEY: ${{ secrets.INTEGRATION_BTC_PRIVATE_KEY }} @@ -60,8 +60,8 @@ jobs: if: ${{ matrix.env_set == 'spore' }} run: pnpm run integration:spore env: - VITE_SERVICE_URL: ${{ secrets.SERVICE_URL }} - VITE_SERVICE_TOKEN: ${{ secrets.SERVICE_TOKEN }} - VITE_SERVICE_ORIGIN: ${{ secrets.SERVICE_ORIGIN }} + VITE_SERVICE_URL: https://api.signet.rgbpp.io + VITE_SERVICE_TOKEN: ${{ secrets.SIGNET_SERVICE_TOKEN }} + VITE_SERVICE_ORIGIN: https://api.signet.rgbpp.io INTEGRATION_CKB_PRIVATE_KEY: ${{ secrets.INTEGRATION_CKB_SPORE_PRIVATE_KEY }} INTEGRATION_BTC_PRIVATE_KEY: ${{ secrets.INTEGRATION_BTC_SPORE_PRIVATE_KEY }} diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 07d120a6..b3c412f2 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -52,6 +52,6 @@ jobs: - name: Run tests for packages run: pnpm run test:packages env: - VITE_BTC_SERVICE_URL: ${{ secrets.SERVICE_URL }} - VITE_BTC_SERVICE_TOKEN: ${{ secrets.SERVICE_TOKEN }} - VITE_BTC_SERVICE_ORIGIN: ${{ secrets.SERVICE_ORIGIN }} + VITE_BTC_SERVICE_URL: https://api.signet.rgbpp.io + VITE_BTC_SERVICE_TOKEN: ${{ secrets.SIGNET_SERVICE_TOKEN }} + VITE_BTC_SERVICE_ORIGIN: https://api.signet.rgbpp.io diff --git a/tests/rgbpp/env.ts b/tests/rgbpp/env.ts index e65e8a27..e78e809a 100644 --- a/tests/rgbpp/env.ts +++ b/tests/rgbpp/env.ts @@ -1,12 +1,14 @@ import { AddressPrefix, privateKeyToAddress } from '@nervosnetwork/ckb-sdk-utils'; -import { DataSource, BtcAssetsApi } from 'rgbpp'; +import { DataSource, BtcAssetsApi, AddressType } from 'rgbpp'; import { ECPair, ECPairInterface, bitcoin, NetworkType } from 'rgbpp/btc'; import dotenv from 'dotenv'; import { Collector } from 'rgbpp/ckb'; +import { createBtcAccount } from '../../examples/rgbpp/shared/btc-account'; dotenv.config({ path: __dirname + '/.env' }); export const isMainnet = false; +export const BTC_TESTNET_TYPE = 'Signet'; export const collector = new Collector({ ckbNodeUrl: 'https://testnet.ckb.dev/rpc', @@ -24,11 +26,13 @@ export const BTC_SERVICE_ORIGIN = process.env.VITE_SERVICE_ORIGIN!; const network = isMainnet ? bitcoin.networks.bitcoin : bitcoin.networks.testnet; export const btcKeyPair: ECPairInterface = ECPair.fromPrivateKey(Buffer.from(BTC_PRIVATE_KEY, 'hex'), { network }); -export const { address: btcAddress } = bitcoin.payments.p2wpkh({ - pubkey: btcKeyPair.publicKey, - network, -}); +// Read more about the available address types: +// - P2WPKH: https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#p2wpkh +// - P2TR: https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki +const addressType = AddressType.P2WPKH; const networkType = isMainnet ? NetworkType.MAINNET : NetworkType.TESTNET; +export const btcAccount = createBtcAccount(BTC_PRIVATE_KEY, addressType, networkType); + export const btcService = BtcAssetsApi.fromToken(BTC_SERVICE_URL, BTC_SERVICE_TOKEN, BTC_SERVICE_ORIGIN); export const btcDataSource = new DataSource(btcService, networkType); diff --git a/tests/rgbpp/shared/prepare-utxo.ts b/tests/rgbpp/shared/prepare-utxo.ts index a10c9e4c..12ac11cf 100644 --- a/tests/rgbpp/shared/prepare-utxo.ts +++ b/tests/rgbpp/shared/prepare-utxo.ts @@ -1,24 +1,23 @@ import { sendBtc } from 'rgbpp/btc'; -import { getFastestFeeRate, writeStepLog } from './utils'; +import { writeStepLog } from './utils'; import { BtcAssetsApiError } from 'rgbpp/service'; -import { btcAddress, btcDataSource, btcKeyPair, btcService } from '../env'; +import { btcAccount, btcDataSource, btcKeyPair, btcService } from '../env'; const prepareUtxo = async (index: string | number) => { - const feeRate = await getFastestFeeRate(); - console.log('feeRate = ', feeRate); - console.log(btcAddress); + const address = btcAccount.toString(); + console.log(address); // Send BTC tx const psbt = await sendBtc({ - from: btcAddress!, + from: address!, tos: [ { - address: btcAddress!, + address: address!, value: 546, minUtxoSatoshi: 546, }, ], - feeRate: feeRate, + feeRate: 1, source: btcDataSource, }); diff --git a/tests/rgbpp/spore/4-transfer-spore.ts b/tests/rgbpp/spore/4-transfer-spore.ts index 30d53c0a..c99cf9e3 100644 --- a/tests/rgbpp/spore/4-transfer-spore.ts +++ b/tests/rgbpp/spore/4-transfer-spore.ts @@ -2,9 +2,11 @@ import { buildRgbppLockArgs } from 'rgbpp/ckb'; import { genTransferSporeCkbVirtualTx, sendRgbppUtxos } from 'rgbpp'; import { getSporeTypeScript, Hex } from 'rgbpp/ckb'; import { serializeScript } from '@nervosnetwork/ckb-sdk-utils'; -import { isMainnet, collector, btcAddress, btcDataSource, btcKeyPair, btcService } from '../env'; -import { getFastestFeeRate, readStepLog } from '../shared/utils'; +import { isMainnet, collector, btcDataSource, btcService, btcAccount } from '../env'; +import { readStepLog } from '../shared/utils'; import { saveCkbVirtualTxResult } from '../../../examples/rgbpp/shared/utils'; +import { BTC_TESTNET_TYPE } from '../../../examples/rgbpp/env'; +import { signAndSendPsbt } from '../../../examples/rgbpp/shared/btc-account'; interface SporeTransferParams { sporeRgbppLockArgs: Hex; @@ -20,14 +22,12 @@ const transferSpore = async ({ sporeRgbppLockArgs, toBtcAddress, sporeTypeArgs } args: sporeTypeArgs, }); - const feeRate = await getFastestFeeRate(); - console.log('feeRate = ', feeRate); - const ckbVirtualTxResult = await genTransferSporeCkbVirtualTx({ collector, sporeRgbppLockArgs, sporeTypeBytes, isMainnet, + btcTestnetType: BTC_TESTNET_TYPE, }); // Save ckbVirtualTxResult @@ -42,16 +42,13 @@ const transferSpore = async ({ sporeRgbppLockArgs, toBtcAddress, sporeTypeArgs } tos: [toBtcAddress], needPaymaster: needPaymasterCell, ckbCollector: collector, - from: btcAddress!, + from: btcAccount.from, + fromPubkey: btcAccount.fromPubkey, source: btcDataSource, - feeRate: feeRate, + feeRate: 1, }); - psbt.signAllInputs(btcKeyPair); - psbt.finalizeAllInputs(); - - const btcTx = psbt.extractTransaction(); - const { txid: btcTxId } = await btcService.sendBtcTransaction(btcTx.toHex()); + const { txId: btcTxId } = await signAndSendPsbt(psbt, btcAccount, btcService); console.log('BTC TxId: ', btcTxId); console.log(`explorer: https://mempool.space/testnet/tx/${btcTxId}`); diff --git a/tests/rgbpp/spore/5-leap-spore-to-ckb.ts b/tests/rgbpp/spore/5-leap-spore-to-ckb.ts index 6346c088..fc36708f 100644 --- a/tests/rgbpp/spore/5-leap-spore-to-ckb.ts +++ b/tests/rgbpp/spore/5-leap-spore-to-ckb.ts @@ -2,9 +2,11 @@ import { buildRgbppLockArgs } from 'rgbpp/ckb'; import { genLeapSporeFromBtcToCkbVirtualTx, sendRgbppUtxos } from 'rgbpp'; import { getSporeTypeScript, Hex } from 'rgbpp/ckb'; import { serializeScript } from '@nervosnetwork/ckb-sdk-utils'; -import { isMainnet, collector, btcAddress, btcDataSource, btcKeyPair, btcService } from '../env'; -import { getFastestFeeRate, readStepLog } from '../shared/utils'; +import { isMainnet, collector, btcDataSource, btcService, btcAccount } from '../env'; +import { readStepLog } from '../shared/utils'; import { saveCkbVirtualTxResult } from '../../../examples/rgbpp/shared/utils'; +import { BTC_TESTNET_TYPE } from '../../../examples/rgbpp/env'; +import { signAndSendPsbt } from '../../../examples/rgbpp/shared/btc-account'; interface SporeLeapParams { sporeRgbppLockArgs: Hex; @@ -20,15 +22,13 @@ const leapSporeFromBtcToCkb = async ({ sporeRgbppLockArgs, toCkbAddress, sporeTy args: sporeTypeArgs, }); - const feeRate = await getFastestFeeRate(); - console.log('feeRate = ', feeRate); - const ckbVirtualTxResult = await genLeapSporeFromBtcToCkbVirtualTx({ collector, sporeRgbppLockArgs, sporeTypeBytes, toCkbAddress, isMainnet, + btcTestnetType: BTC_TESTNET_TYPE, }); // Save ckbVirtualTxResult @@ -40,19 +40,16 @@ const leapSporeFromBtcToCkb = async ({ sporeRgbppLockArgs, toCkbAddress, sporeTy const psbt = await sendRgbppUtxos({ ckbVirtualTx: ckbRawTx, commitment, - tos: [btcAddress!], + tos: [btcAccount.from], needPaymaster: needPaymasterCell, ckbCollector: collector, - from: btcAddress!, + from: btcAccount.from, + fromPubkey: btcAccount.fromPubkey, source: btcDataSource, - feeRate: feeRate, + feeRate: 1, }); - psbt.signAllInputs(btcKeyPair); - psbt.finalizeAllInputs(); - - const btcTx = psbt.extractTransaction(); - const { txid: btcTxId } = await btcService.sendBtcTransaction(btcTx.toHex()); + const { txId: btcTxId } = await signAndSendPsbt(psbt, btcAccount, btcService); console.log('BTC TxId: ', btcTxId); console.log(`explorer: https://mempool.space/testnet/tx/${btcTxId}`); diff --git a/tests/rgbpp/spore/launch/2-create-cluster.ts b/tests/rgbpp/spore/launch/2-create-cluster.ts index 4e5d9fe8..4e4dc697 100644 --- a/tests/rgbpp/spore/launch/2-create-cluster.ts +++ b/tests/rgbpp/spore/launch/2-create-cluster.ts @@ -1,7 +1,6 @@ import { BtcAssetsApiError, genCreateClusterCkbVirtualTx, sendRgbppUtxos } from 'rgbpp'; -import { isMainnet, collector, btcAddress, btcDataSource, btcKeyPair, btcService } from '../../env'; +import { isMainnet, collector, btcDataSource, btcService, btcAccount, BTC_TESTNET_TYPE } from '../../env'; import { CLUSTER_DATA } from './0-cluster-info'; -import { transactionToHex } from 'rgbpp/btc'; import { appendCkbTxWitnesses, buildRgbppLockArgs, @@ -9,23 +8,22 @@ import { sendCkbTx, updateCkbTxWithRealBtcTxId, } from 'rgbpp/ckb'; -import { getFastestFeeRate, readStepLog, writeStepLog } from '../../shared/utils'; +import { readStepLog, writeStepLog } from '../../shared/utils'; import { saveCkbVirtualTxResult } from '../../../../examples/rgbpp/shared/utils'; +import { signAndSendPsbt } from '../../../../examples/rgbpp/shared/btc-account'; // Warning: Before runing this file, please run 1-prepare-cluster.ts const createCluster = async ({ ownerRgbppLockArgs }: { ownerRgbppLockArgs: string }) => { - console.log(btcAddress); + console.log(btcAccount); const { retry } = await import('zx'); await retry(20, '10s', async () => { - const feeRate = await getFastestFeeRate(); - console.log('feeRate = ', feeRate); - const ckbVirtualTxResult = await genCreateClusterCkbVirtualTx({ collector, rgbppLockArgs: ownerRgbppLockArgs, clusterData: CLUSTER_DATA, isMainnet, ckbFeeRate: BigInt(2000), + btcTestnetType: BTC_TESTNET_TYPE, }); // Save ckbVirtualTxResult @@ -42,19 +40,16 @@ const createCluster = async ({ ownerRgbppLockArgs }: { ownerRgbppLockArgs: strin const psbt = await sendRgbppUtxos({ ckbVirtualTx: ckbRawTx, commitment, - tos: [btcAddress!], + tos: [btcAccount.from], needPaymaster: needPaymasterCell, ckbCollector: collector, - from: btcAddress!, + from: btcAccount.from, + fromPubkey: btcAccount.fromPubkey, source: btcDataSource, - feeRate: feeRate, + feeRate: 1, }); - psbt.signAllInputs(btcKeyPair); - psbt.finalizeAllInputs(); - const btcTx = psbt.extractTransaction(); - const btcTxBytes = transactionToHex(btcTx, false); - const { txid: btcTxId } = await btcService.sendBtcTransaction(btcTx.toHex()); + const { txId: btcTxId, rawTxHex: btcTxBytes } = await signAndSendPsbt(psbt, btcAccount, btcService); writeStepLog('create-cluster-id', { txid: btcTxId, diff --git a/tests/rgbpp/spore/launch/3-create-spores.ts b/tests/rgbpp/spore/launch/3-create-spores.ts index 9f180407..35cac3af 100644 --- a/tests/rgbpp/spore/launch/3-create-spores.ts +++ b/tests/rgbpp/spore/launch/3-create-spores.ts @@ -1,14 +1,5 @@ import { BtcAssetsApiError, genCreateSporeCkbVirtualTx, sendRgbppUtxos } from 'rgbpp'; -import { - isMainnet, - collector, - btcAddress, - btcDataSource, - btcKeyPair, - btcService, - CKB_PRIVATE_KEY, - ckbAddress, -} from '../../env'; +import { isMainnet, collector, btcDataSource, btcService, CKB_PRIVATE_KEY, ckbAddress } from '../../env'; import { Hex, appendCkbTxWitnesses, @@ -19,9 +10,11 @@ import { updateCkbTxWithRealBtcTxId, RawSporeData, } from 'rgbpp/ckb'; -import { transactionToHex, utf8ToBuffer } from 'rgbpp/btc'; -import { getFastestFeeRate, readStepLog, writeStepLog } from '../../shared/utils'; +import { utf8ToBuffer } from 'rgbpp/btc'; +import { readStepLog, writeStepLog } from '../../shared/utils'; import { saveCkbVirtualTxResult } from '../../../../examples/rgbpp/shared/utils'; +import { BTC_TESTNET_TYPE, btcAccount } from '../../../../examples/rgbpp/env'; +import { signAndSendPsbt } from '../../../../examples/rgbpp/shared/btc-account'; interface SporeCreateParams { clusterRgbppLockArgs: Hex; @@ -35,15 +28,13 @@ interface SporeCreateParams { const createSpores = async ({ clusterRgbppLockArgs, receivers }: SporeCreateParams) => { const { retry } = await import('zx'); await retry(20, '10s', async () => { - const feeRate = await getFastestFeeRate(); - console.log('feeRate = ', feeRate); - const ckbVirtualTxResult = await genCreateSporeCkbVirtualTx({ collector, sporeDataList: receivers.map((receiver) => receiver.sporeData), clusterRgbppLockArgs, isMainnet, ckbFeeRate: BigInt(2000), + btcTestnetType: BTC_TESTNET_TYPE, }); // Save ckbVirtualTxResult @@ -53,23 +44,20 @@ const createSpores = async ({ clusterRgbppLockArgs, receivers }: SporeCreatePara // Send BTC tx // The first btc address is the owner of the cluster cell and the rest btc addresses are spore receivers - const btcTos = [btcAddress!, ...receivers.map((receiver) => receiver.toBtcAddress)]; + const btcTos = [btcAccount.from, ...receivers.map((receiver) => receiver.toBtcAddress)]; const psbt = await sendRgbppUtxos({ ckbVirtualTx: ckbRawTx, commitment, tos: btcTos, needPaymaster: needPaymasterCell, ckbCollector: collector, - from: btcAddress!, + from: btcAccount.from, + fromPubkey: btcAccount.fromPubkey, source: btcDataSource, - feeRate: feeRate, + feeRate: 1, }); - psbt.signAllInputs(btcKeyPair); - psbt.finalizeAllInputs(); - const btcTx = psbt.extractTransaction(); - const btcTxBytes = transactionToHex(btcTx, false); - const { txid: btcTxId } = await btcService.sendBtcTransaction(btcTx.toHex()); + const { txId: btcTxId, rawTxHex: btcTxBytes } = await signAndSendPsbt(psbt, btcAccount, btcService); writeStepLog('create-spores-id', { txid: btcTxId, @@ -131,6 +119,9 @@ const createSpores = async ({ clusterRgbppLockArgs, receivers }: SporeCreatePara }; // Please use your real BTC UTXO information on the BTC Testnet +// BTC Testnet3: https://mempool.space/testnet +// BTC Signet: https://mempool.space/signet + // rgbppLockArgs: outIndexU32 + btcTxId createSpores({ // The cluster cell will be spent and the new cluster cell will be created in each spore creation tx, diff --git a/tests/rgbpp/xudt/2-btc-transfer.ts b/tests/rgbpp/xudt/2-btc-transfer.ts index d1f7a7ff..272d9b7a 100644 --- a/tests/rgbpp/xudt/2-btc-transfer.ts +++ b/tests/rgbpp/xudt/2-btc-transfer.ts @@ -1,8 +1,11 @@ -import { buildRgbppLockArgs, getXudtTypeScript } from 'rgbpp/ckb'; -import { serializeScript } from '@nervosnetwork/ckb-sdk-utils'; -import { genBtcTransferCkbVirtualTx, sendRgbppUtxos } from 'rgbpp'; -import { isMainnet, collector, btcAddress, btcKeyPair, btcService, btcDataSource } from '../env'; +import { buildRgbppLockArgs } from 'rgbpp/ckb'; +import { buildRgbppTransferTx } from 'rgbpp'; +import { isMainnet, collector, btcService, btcDataSource } from '../env'; import { readStepLog, writeStepLog } from '../shared/utils'; +import { BTC_TESTNET_TYPE, btcAccount } from '../env'; +import { saveCkbVirtualTxResult } from '../../../examples/rgbpp/shared/utils'; +import { bitcoin } from 'rgbpp/btc'; +import { signAndSendPsbt } from '../../../examples/rgbpp/shared/btc-account'; interface RgbppTransferParams { rgbppLockArgsList: string[]; @@ -14,37 +17,31 @@ interface RgbppTransferParams { const transfer = async ({ rgbppLockArgsList, toBtcAddress, xudtTypeArgs, transferAmount }: RgbppTransferParams) => { const { retry } = await import('zx'); await retry(120, '10s', async () => { - const xudtType: CKBComponents.Script = { - ...getXudtTypeScript(isMainnet), - args: xudtTypeArgs, - }; - - const ckbVirtualTxResult = await genBtcTransferCkbVirtualTx({ - collector, - rgbppLockArgsList, - xudtTypeBytes: serializeScript(xudtType), - transferAmount, + const { ckbVirtualTxResult, btcPsbtHex } = await buildRgbppTransferTx({ + ckb: { + collector, + xudtTypeArgs, + rgbppLockArgsList, + transferAmount, + }, + btc: { + fromAddress: btcAccount.from, + toAddress: toBtcAddress, + fromPubkey: btcAccount.fromPubkey, + dataSource: btcDataSource, + testnetType: BTC_TESTNET_TYPE, + feeRate: 1, + }, isMainnet, }); - const { commitment, ckbRawTx } = ckbVirtualTxResult; + // Save ckbVirtualTxResult + saveCkbVirtualTxResult(ckbVirtualTxResult, '2-btc-transfer'); // Send BTC tx - const psbt = await sendRgbppUtxos({ - ckbVirtualTx: ckbRawTx, - commitment, - tos: [toBtcAddress], - ckbCollector: collector, - from: btcAddress!, - source: btcDataSource, - }); - psbt.signAllInputs(btcKeyPair); - psbt.finalizeAllInputs(); - - const btcTx = psbt.extractTransaction(); - const { txid: btcTxId } = await btcService.sendBtcTransaction(btcTx.toHex()); - - console.log('BTC TxId: ', btcTxId); + const psbt = bitcoin.Psbt.fromHex(btcPsbtHex); + const { txId: btcTxId } = await signAndSendPsbt(psbt, btcAccount, btcService); + console.log(`BTC ${BTC_TESTNET_TYPE} TxId: ${btcTxId}`); console.log(`explorer: https://mempool.space/testnet/tx/${btcTxId}`); writeStepLog('transfer-id', { diff --git a/tests/rgbpp/xudt/3-btc-leap-ckb.ts b/tests/rgbpp/xudt/3-btc-leap-ckb.ts index 5f2c752f..e7e66bf4 100644 --- a/tests/rgbpp/xudt/3-btc-leap-ckb.ts +++ b/tests/rgbpp/xudt/3-btc-leap-ckb.ts @@ -1,8 +1,10 @@ import { buildRgbppLockArgs, getXudtTypeScript } from 'rgbpp/ckb'; import { serializeScript } from '@nervosnetwork/ckb-sdk-utils'; import { genBtcJumpCkbVirtualTx, sendRgbppUtxos } from 'rgbpp'; -import { isMainnet, collector, btcAddress, btcKeyPair, btcService, btcDataSource } from '../env'; +import { isMainnet, collector, btcService, btcDataSource, btcAccount, BTC_TESTNET_TYPE } from '../env'; import { readStepLog } from '../shared/utils'; +import { saveCkbVirtualTxResult } from '../../../examples/rgbpp/shared/utils'; +import { signAndSendPsbt } from '../../../examples/rgbpp/shared/btc-account'; interface LeapToCkbParams { rgbppLockArgsList: string[]; @@ -26,26 +28,28 @@ const leapFromBtcToCKB = async ({ rgbppLockArgsList, toCkbAddress, xudtTypeArgs, transferAmount, toCkbAddress, isMainnet, + btcTestnetType: BTC_TESTNET_TYPE, }); + // Save ckbVirtualTxResult + saveCkbVirtualTxResult(ckbVirtualTxResult, '3-btc-leap-ckb'); + const { commitment, ckbRawTx } = ckbVirtualTxResult; // Send BTC tx const psbt = await sendRgbppUtxos({ ckbVirtualTx: ckbRawTx, commitment, - tos: [btcAddress!], + tos: [btcAccount.from], ckbCollector: collector, - from: btcAddress!, + from: btcAccount.from, + fromPubkey: btcAccount.fromPubkey, source: btcDataSource, + feeRate: 1, }); - psbt.signAllInputs(btcKeyPair); - psbt.finalizeAllInputs(); - - const btcTx = psbt.extractTransaction(); - const { txid: btcTxId } = await btcService.sendBtcTransaction(btcTx.toHex()); - console.log('BTC TxId: ', btcTxId); + const { txId: btcTxId } = await signAndSendPsbt(psbt, btcAccount, btcService); + console.log(`BTC ${BTC_TESTNET_TYPE} TxId: ${btcTxId}`); console.log(`explorer: https://mempool.space/testnet/tx/${btcTxId}`); await btcService.sendRgbppCkbTransaction({ btc_txid: btcTxId, ckb_virtual_result: ckbVirtualTxResult }); From f27cd8e3faeced5a5a2e1741556d99a52cf788a3 Mon Sep 17 00:00:00 2001 From: Dawn <13477199767@163.com> Date: Mon, 17 Jun 2024 17:22:11 +0800 Subject: [PATCH 2/7] fix: Fix the error in obtaining the address in the integration test --- .github/workflows/integration-test.yaml | 1 - tests/rgbpp/shared/prepare-utxo.ts | 7 +++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/integration-test.yaml b/.github/workflows/integration-test.yaml index 13c30285..43b3dbf4 100644 --- a/.github/workflows/integration-test.yaml +++ b/.github/workflows/integration-test.yaml @@ -4,7 +4,6 @@ name: Integration Tests on: workflow_dispatch: - pull_request: # Run integration-tests every day schedule: - cron: '59 0 * * *' diff --git a/tests/rgbpp/shared/prepare-utxo.ts b/tests/rgbpp/shared/prepare-utxo.ts index 12ac11cf..b9f0b456 100644 --- a/tests/rgbpp/shared/prepare-utxo.ts +++ b/tests/rgbpp/shared/prepare-utxo.ts @@ -4,15 +4,14 @@ import { BtcAssetsApiError } from 'rgbpp/service'; import { btcAccount, btcDataSource, btcKeyPair, btcService } from '../env'; const prepareUtxo = async (index: string | number) => { - const address = btcAccount.toString(); - console.log(address); + console.log(btcAccount.from); // Send BTC tx const psbt = await sendBtc({ - from: address!, + from: btcAccount.from!, tos: [ { - address: address!, + address: btcAccount.from!, value: 546, minUtxoSatoshi: 546, }, From add545149382c145605daee57f5ec5a44da60b8f Mon Sep 17 00:00:00 2001 From: Dawn <13477199767@163.com> Date: Mon, 17 Jun 2024 17:40:36 +0800 Subject: [PATCH 3/7] chore: Modify output messages --- .github/workflows/integration-test.yaml | 1 + .github/workflows/test.yaml | 6 +++--- tests/rgbpp/shared/prepare-utxo.ts | 2 +- tests/rgbpp/spore/4-transfer-spore.ts | 2 +- tests/rgbpp/spore/5-leap-spore-to-ckb.ts | 2 +- tests/rgbpp/spore/launch/2-create-cluster.ts | 2 +- tests/rgbpp/spore/launch/3-create-spores.ts | 2 +- tests/rgbpp/xudt/2-btc-transfer.ts | 2 +- tests/rgbpp/xudt/3-btc-leap-ckb.ts | 2 +- 9 files changed, 11 insertions(+), 10 deletions(-) diff --git a/.github/workflows/integration-test.yaml b/.github/workflows/integration-test.yaml index 43b3dbf4..13c30285 100644 --- a/.github/workflows/integration-test.yaml +++ b/.github/workflows/integration-test.yaml @@ -4,6 +4,7 @@ name: Integration Tests on: workflow_dispatch: + pull_request: # Run integration-tests every day schedule: - cron: '59 0 * * *' diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index b3c412f2..62c7d695 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -52,6 +52,6 @@ jobs: - name: Run tests for packages run: pnpm run test:packages env: - VITE_BTC_SERVICE_URL: https://api.signet.rgbpp.io - VITE_BTC_SERVICE_TOKEN: ${{ secrets.SIGNET_SERVICE_TOKEN }} - VITE_BTC_SERVICE_ORIGIN: https://api.signet.rgbpp.io + VITE_BTC_SERVICE_URL: https://btc-assets-api.testnet.mibao.pro + VITE_BTC_SERVICE_TOKEN: ${{ secrets.TESTNET_SERVICE_TOKEN }} + VITE_BTC_SERVICE_ORIGIN: https://btc-assets-api.testnet.mibao.pro diff --git a/tests/rgbpp/shared/prepare-utxo.ts b/tests/rgbpp/shared/prepare-utxo.ts index b9f0b456..5ac8b17a 100644 --- a/tests/rgbpp/shared/prepare-utxo.ts +++ b/tests/rgbpp/shared/prepare-utxo.ts @@ -29,7 +29,7 @@ const prepareUtxo = async (index: string | number) => { console.log(tx.toHex()); const { txid: btcTxId } = await btcService.sendBtcTransaction(tx.toHex()); - console.log(`explorer: https://mempool.space/testnet/tx/${btcTxId}`); + console.log(`explorer: https://mempool.space/signet/tx/${btcTxId}`); writeStepLog(String(index), { txid: btcTxId, diff --git a/tests/rgbpp/spore/4-transfer-spore.ts b/tests/rgbpp/spore/4-transfer-spore.ts index c99cf9e3..8a74e82a 100644 --- a/tests/rgbpp/spore/4-transfer-spore.ts +++ b/tests/rgbpp/spore/4-transfer-spore.ts @@ -50,7 +50,7 @@ const transferSpore = async ({ sporeRgbppLockArgs, toBtcAddress, sporeTypeArgs } const { txId: btcTxId } = await signAndSendPsbt(psbt, btcAccount, btcService); console.log('BTC TxId: ', btcTxId); - console.log(`explorer: https://mempool.space/testnet/tx/${btcTxId}`); + console.log(`explorer: https://mempool.space/signet/tx/${btcTxId}`); await btcService.sendRgbppCkbTransaction({ btc_txid: btcTxId, ckb_virtual_result: ckbVirtualTxResult }); diff --git a/tests/rgbpp/spore/5-leap-spore-to-ckb.ts b/tests/rgbpp/spore/5-leap-spore-to-ckb.ts index fc36708f..0a4e9e09 100644 --- a/tests/rgbpp/spore/5-leap-spore-to-ckb.ts +++ b/tests/rgbpp/spore/5-leap-spore-to-ckb.ts @@ -51,7 +51,7 @@ const leapSporeFromBtcToCkb = async ({ sporeRgbppLockArgs, toCkbAddress, sporeTy const { txId: btcTxId } = await signAndSendPsbt(psbt, btcAccount, btcService); console.log('BTC TxId: ', btcTxId); - console.log(`explorer: https://mempool.space/testnet/tx/${btcTxId}`); + console.log(`explorer: https://mempool.space/signet/tx/${btcTxId}`); await btcService.sendRgbppCkbTransaction({ btc_txid: btcTxId, ckb_virtual_result: ckbVirtualTxResult }); diff --git a/tests/rgbpp/spore/launch/2-create-cluster.ts b/tests/rgbpp/spore/launch/2-create-cluster.ts index 4e4dc697..136d9371 100644 --- a/tests/rgbpp/spore/launch/2-create-cluster.ts +++ b/tests/rgbpp/spore/launch/2-create-cluster.ts @@ -56,7 +56,7 @@ const createCluster = async ({ ownerRgbppLockArgs }: { ownerRgbppLockArgs: strin index: 1, }); console.log('BTC TxId: ', btcTxId); - console.log(`explorer: https://mempool.space/testnet/tx/${btcTxId}`); + console.log(`explorer: https://mempool.space/signet/tx/${btcTxId}`); const interval = setInterval(async () => { try { diff --git a/tests/rgbpp/spore/launch/3-create-spores.ts b/tests/rgbpp/spore/launch/3-create-spores.ts index 35cac3af..21daf795 100644 --- a/tests/rgbpp/spore/launch/3-create-spores.ts +++ b/tests/rgbpp/spore/launch/3-create-spores.ts @@ -63,7 +63,7 @@ const createSpores = async ({ clusterRgbppLockArgs, receivers }: SporeCreatePara txid: btcTxId, }); console.log('BTC TxId: ', btcTxId); - console.log(`explorer: https://mempool.space/testnet/tx/${btcTxId}`); + console.log(`explorer: https://mempool.space/signet/tx/${btcTxId}`); const interval = setInterval(async () => { try { diff --git a/tests/rgbpp/xudt/2-btc-transfer.ts b/tests/rgbpp/xudt/2-btc-transfer.ts index 272d9b7a..f71a3779 100644 --- a/tests/rgbpp/xudt/2-btc-transfer.ts +++ b/tests/rgbpp/xudt/2-btc-transfer.ts @@ -42,7 +42,7 @@ const transfer = async ({ rgbppLockArgsList, toBtcAddress, xudtTypeArgs, transfe const psbt = bitcoin.Psbt.fromHex(btcPsbtHex); const { txId: btcTxId } = await signAndSendPsbt(psbt, btcAccount, btcService); console.log(`BTC ${BTC_TESTNET_TYPE} TxId: ${btcTxId}`); - console.log(`explorer: https://mempool.space/testnet/tx/${btcTxId}`); + console.log(`explorer: https://mempool.space/signet/tx/${btcTxId}`); writeStepLog('transfer-id', { txid: btcTxId, diff --git a/tests/rgbpp/xudt/3-btc-leap-ckb.ts b/tests/rgbpp/xudt/3-btc-leap-ckb.ts index e7e66bf4..7d16fc5b 100644 --- a/tests/rgbpp/xudt/3-btc-leap-ckb.ts +++ b/tests/rgbpp/xudt/3-btc-leap-ckb.ts @@ -50,7 +50,7 @@ const leapFromBtcToCKB = async ({ rgbppLockArgsList, toCkbAddress, xudtTypeArgs, const { txId: btcTxId } = await signAndSendPsbt(psbt, btcAccount, btcService); console.log(`BTC ${BTC_TESTNET_TYPE} TxId: ${btcTxId}`); - console.log(`explorer: https://mempool.space/testnet/tx/${btcTxId}`); + console.log(`explorer: https://mempool.space/signet/tx/${btcTxId}`); await btcService.sendRgbppCkbTransaction({ btc_txid: btcTxId, ckb_virtual_result: ckbVirtualTxResult }); From 240c68e6957a5fdcdaaf6ce891375b87d6b0c8ee Mon Sep 17 00:00:00 2001 From: Dawn <13477199767@163.com> Date: Mon, 17 Jun 2024 23:13:51 +0800 Subject: [PATCH 4/7] fix: Resolve issue of no RGBPP cells found with the RGBPP lock args --- tests/rgbpp/env.ts | 32 ++++++++++++------- tests/rgbpp/spore/launch/1-prepare-cluster.ts | 4 +-- tests/rgbpp/spore/launch/2-create-cluster.ts | 2 +- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/tests/rgbpp/env.ts b/tests/rgbpp/env.ts index e78e809a..8479a062 100644 --- a/tests/rgbpp/env.ts +++ b/tests/rgbpp/env.ts @@ -1,28 +1,38 @@ -import { AddressPrefix, privateKeyToAddress } from '@nervosnetwork/ckb-sdk-utils'; +import { + blake160, + bytesToHex, + privateKeyToPublicKey, + scriptToAddress, + systemScripts, +} from '@nervosnetwork/ckb-sdk-utils'; import { DataSource, BtcAssetsApi, AddressType } from 'rgbpp'; import { ECPair, ECPairInterface, bitcoin, NetworkType } from 'rgbpp/btc'; import dotenv from 'dotenv'; -import { Collector } from 'rgbpp/ckb'; +import { BTCTestnetType, Collector } from 'rgbpp/ckb'; import { createBtcAccount } from '../../examples/rgbpp/shared/btc-account'; dotenv.config({ path: __dirname + '/.env' }); export const isMainnet = false; -export const BTC_TESTNET_TYPE = 'Signet'; +// export const BTC_TESTNET_TYPE = 'Signet'; +export const BTC_TESTNET_TYPE = process.env.BTC_TESTNET_TYPE! as BTCTestnetType; export const collector = new Collector({ ckbNodeUrl: 'https://testnet.ckb.dev/rpc', ckbIndexerUrl: 'https://testnet.ckb.dev/indexer', }); -export const CKB_PRIVATE_KEY = process.env.INTEGRATION_CKB_PRIVATE_KEY!; -export const ckbAddress = privateKeyToAddress(CKB_PRIVATE_KEY, { - prefix: isMainnet ? AddressPrefix.Mainnet : AddressPrefix.Testnet, -}); +export const CKB_PRIVATE_KEY = '0x469cc5b62555090f376866fe3fe780339104cfdcf5011e7d887d71bb99ca2e2b'; +const secp256k1Lock: CKBComponents.Script = { + ...systemScripts.SECP256K1_BLAKE160, + args: bytesToHex(blake160(privateKeyToPublicKey(CKB_PRIVATE_KEY))), +}; +export const ckbAddress = scriptToAddress(secp256k1Lock, isMainnet); -export const BTC_PRIVATE_KEY = process.env.INTEGRATION_BTC_PRIVATE_KEY!; -export const BTC_SERVICE_URL = process.env.VITE_SERVICE_URL!; -export const BTC_SERVICE_TOKEN = process.env.VITE_SERVICE_TOKEN!; -export const BTC_SERVICE_ORIGIN = process.env.VITE_SERVICE_ORIGIN!; +export const BTC_PRIVATE_KEY = '5c213d9478a310fcf9fb4a973d1b4a7592769b4bccbda335b5c1886a3929a00b'; +export const BTC_SERVICE_URL = 'https://api.signet.rgbpp.io'; +export const BTC_SERVICE_TOKEN = + 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJteS1hcHAiLCJhdWQiOiJhcGkuc2lnbmV0LnJnYnBwLmlvIiwianRpIjoiZWJkMGJlNGYtZTZlNS00M2M4LTlmMmMtNGUwYjk3YWM1ZjVkIiwiaWF0IjoxNzE4NTk1Mzg2fQ.8Q35BzMYHNHS0Fqe_4coALnIsBDVUm3Ro-zF6SN83PM'; +export const BTC_SERVICE_ORIGIN = 'https://api.signet.rgbpp.io'; const network = isMainnet ? bitcoin.networks.bitcoin : bitcoin.networks.testnet; export const btcKeyPair: ECPairInterface = ECPair.fromPrivateKey(Buffer.from(BTC_PRIVATE_KEY, 'hex'), { network }); diff --git a/tests/rgbpp/spore/launch/1-prepare-cluster.ts b/tests/rgbpp/spore/launch/1-prepare-cluster.ts index 76636543..d1e70d91 100644 --- a/tests/rgbpp/spore/launch/1-prepare-cluster.ts +++ b/tests/rgbpp/spore/launch/1-prepare-cluster.ts @@ -10,7 +10,7 @@ import { genRgbppLockScript, getSecp256k1CellDep, } from 'rgbpp/ckb'; -import { ckbAddress, isMainnet, collector, CKB_PRIVATE_KEY } from '../../env'; +import { ckbAddress, isMainnet, collector, CKB_PRIVATE_KEY, BTC_TESTNET_TYPE } from '../../env'; import { CLUSTER_DATA } from './0-cluster-info'; import { readStepLog } from '../../shared/utils'; @@ -36,7 +36,7 @@ const prepareClusterCell = async ({ outIndex, btcTxId }: { outIndex: number; btc const outputs: CKBComponents.CellOutput[] = [ { - lock: genRgbppLockScript(buildRgbppLockArgs(outIndex, btcTxId), isMainnet), + lock: genRgbppLockScript(buildRgbppLockArgs(outIndex, btcTxId), isMainnet, BTC_TESTNET_TYPE), capacity: append0x(clusterCellCapacity.toString(16)), }, ]; diff --git a/tests/rgbpp/spore/launch/2-create-cluster.ts b/tests/rgbpp/spore/launch/2-create-cluster.ts index 136d9371..e398e52e 100644 --- a/tests/rgbpp/spore/launch/2-create-cluster.ts +++ b/tests/rgbpp/spore/launch/2-create-cluster.ts @@ -14,7 +14,7 @@ import { signAndSendPsbt } from '../../../../examples/rgbpp/shared/btc-account'; // Warning: Before runing this file, please run 1-prepare-cluster.ts const createCluster = async ({ ownerRgbppLockArgs }: { ownerRgbppLockArgs: string }) => { - console.log(btcAccount); + console.log(btcAccount.from); const { retry } = await import('zx'); await retry(20, '10s', async () => { const ckbVirtualTxResult = await genCreateClusterCkbVirtualTx({ From 4efd9d24e85c00d0e647564f1e094075acdca969 Mon Sep 17 00:00:00 2001 From: Dawn <13477199767@163.com> Date: Mon, 17 Jun 2024 23:22:16 +0800 Subject: [PATCH 5/7] chore: Set BTC_TESTNET_TYPE to default to signet --- .github/workflows/integration-test.yaml | 1 - tests/rgbpp/env.ts | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/integration-test.yaml b/.github/workflows/integration-test.yaml index 13c30285..43b3dbf4 100644 --- a/.github/workflows/integration-test.yaml +++ b/.github/workflows/integration-test.yaml @@ -4,7 +4,6 @@ name: Integration Tests on: workflow_dispatch: - pull_request: # Run integration-tests every day schedule: - cron: '59 0 * * *' diff --git a/tests/rgbpp/env.ts b/tests/rgbpp/env.ts index 8479a062..51144335 100644 --- a/tests/rgbpp/env.ts +++ b/tests/rgbpp/env.ts @@ -8,14 +8,14 @@ import { import { DataSource, BtcAssetsApi, AddressType } from 'rgbpp'; import { ECPair, ECPairInterface, bitcoin, NetworkType } from 'rgbpp/btc'; import dotenv from 'dotenv'; -import { BTCTestnetType, Collector } from 'rgbpp/ckb'; +import { Collector } from 'rgbpp/ckb'; import { createBtcAccount } from '../../examples/rgbpp/shared/btc-account'; dotenv.config({ path: __dirname + '/.env' }); export const isMainnet = false; -// export const BTC_TESTNET_TYPE = 'Signet'; -export const BTC_TESTNET_TYPE = process.env.BTC_TESTNET_TYPE! as BTCTestnetType; + +export const BTC_TESTNET_TYPE = 'Signet'; export const collector = new Collector({ ckbNodeUrl: 'https://testnet.ckb.dev/rpc', From a4dbb33480df5b2f91f7e3ba65d5cc3be581120c Mon Sep 17 00:00:00 2001 From: Dawn <13477199767@163.com> Date: Tue, 18 Jun 2024 00:24:34 +0800 Subject: [PATCH 6/7] fix: Fix the problem that Private key cannot be read --- tests/rgbpp/env.ts | 11 +++++------ tests/rgbpp/spore/4-transfer-spore.ts | 3 +-- tests/rgbpp/spore/5-leap-spore-to-ckb.ts | 3 +-- tests/rgbpp/spore/launch/3-create-spores.ts | 2 +- tests/rgbpp/xudt/2-btc-transfer.ts | 3 +-- 5 files changed, 9 insertions(+), 13 deletions(-) diff --git a/tests/rgbpp/env.ts b/tests/rgbpp/env.ts index 51144335..6a4ba5f7 100644 --- a/tests/rgbpp/env.ts +++ b/tests/rgbpp/env.ts @@ -21,18 +21,17 @@ export const collector = new Collector({ ckbNodeUrl: 'https://testnet.ckb.dev/rpc', ckbIndexerUrl: 'https://testnet.ckb.dev/indexer', }); -export const CKB_PRIVATE_KEY = '0x469cc5b62555090f376866fe3fe780339104cfdcf5011e7d887d71bb99ca2e2b'; +export const CKB_PRIVATE_KEY = process.env.INTEGRATION_CKB_PRIVATE_KEY!; const secp256k1Lock: CKBComponents.Script = { ...systemScripts.SECP256K1_BLAKE160, args: bytesToHex(blake160(privateKeyToPublicKey(CKB_PRIVATE_KEY))), }; export const ckbAddress = scriptToAddress(secp256k1Lock, isMainnet); -export const BTC_PRIVATE_KEY = '5c213d9478a310fcf9fb4a973d1b4a7592769b4bccbda335b5c1886a3929a00b'; -export const BTC_SERVICE_URL = 'https://api.signet.rgbpp.io'; -export const BTC_SERVICE_TOKEN = - 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJteS1hcHAiLCJhdWQiOiJhcGkuc2lnbmV0LnJnYnBwLmlvIiwianRpIjoiZWJkMGJlNGYtZTZlNS00M2M4LTlmMmMtNGUwYjk3YWM1ZjVkIiwiaWF0IjoxNzE4NTk1Mzg2fQ.8Q35BzMYHNHS0Fqe_4coALnIsBDVUm3Ro-zF6SN83PM'; -export const BTC_SERVICE_ORIGIN = 'https://api.signet.rgbpp.io'; +export const BTC_PRIVATE_KEY = process.env.INTEGRATION_BTC_PRIVATE_KEY!; +export const BTC_SERVICE_URL = process.env.VITE_SERVICE_URL!; +export const BTC_SERVICE_TOKEN = process.env.VITE_SERVICE_TOKEN!; +export const BTC_SERVICE_ORIGIN = process.env.VITE_SERVICE_ORIGIN!; const network = isMainnet ? bitcoin.networks.bitcoin : bitcoin.networks.testnet; export const btcKeyPair: ECPairInterface = ECPair.fromPrivateKey(Buffer.from(BTC_PRIVATE_KEY, 'hex'), { network }); diff --git a/tests/rgbpp/spore/4-transfer-spore.ts b/tests/rgbpp/spore/4-transfer-spore.ts index 8a74e82a..d0b16d4a 100644 --- a/tests/rgbpp/spore/4-transfer-spore.ts +++ b/tests/rgbpp/spore/4-transfer-spore.ts @@ -2,10 +2,9 @@ import { buildRgbppLockArgs } from 'rgbpp/ckb'; import { genTransferSporeCkbVirtualTx, sendRgbppUtxos } from 'rgbpp'; import { getSporeTypeScript, Hex } from 'rgbpp/ckb'; import { serializeScript } from '@nervosnetwork/ckb-sdk-utils'; -import { isMainnet, collector, btcDataSource, btcService, btcAccount } from '../env'; +import { isMainnet, collector, btcDataSource, btcService, btcAccount, BTC_TESTNET_TYPE } from '../env'; import { readStepLog } from '../shared/utils'; import { saveCkbVirtualTxResult } from '../../../examples/rgbpp/shared/utils'; -import { BTC_TESTNET_TYPE } from '../../../examples/rgbpp/env'; import { signAndSendPsbt } from '../../../examples/rgbpp/shared/btc-account'; interface SporeTransferParams { diff --git a/tests/rgbpp/spore/5-leap-spore-to-ckb.ts b/tests/rgbpp/spore/5-leap-spore-to-ckb.ts index 0a4e9e09..5600d681 100644 --- a/tests/rgbpp/spore/5-leap-spore-to-ckb.ts +++ b/tests/rgbpp/spore/5-leap-spore-to-ckb.ts @@ -2,10 +2,9 @@ import { buildRgbppLockArgs } from 'rgbpp/ckb'; import { genLeapSporeFromBtcToCkbVirtualTx, sendRgbppUtxos } from 'rgbpp'; import { getSporeTypeScript, Hex } from 'rgbpp/ckb'; import { serializeScript } from '@nervosnetwork/ckb-sdk-utils'; -import { isMainnet, collector, btcDataSource, btcService, btcAccount } from '../env'; +import { isMainnet, collector, btcDataSource, btcService, btcAccount, BTC_TESTNET_TYPE } from '../env'; import { readStepLog } from '../shared/utils'; import { saveCkbVirtualTxResult } from '../../../examples/rgbpp/shared/utils'; -import { BTC_TESTNET_TYPE } from '../../../examples/rgbpp/env'; import { signAndSendPsbt } from '../../../examples/rgbpp/shared/btc-account'; interface SporeLeapParams { diff --git a/tests/rgbpp/spore/launch/3-create-spores.ts b/tests/rgbpp/spore/launch/3-create-spores.ts index 21daf795..61efe851 100644 --- a/tests/rgbpp/spore/launch/3-create-spores.ts +++ b/tests/rgbpp/spore/launch/3-create-spores.ts @@ -13,7 +13,7 @@ import { import { utf8ToBuffer } from 'rgbpp/btc'; import { readStepLog, writeStepLog } from '../../shared/utils'; import { saveCkbVirtualTxResult } from '../../../../examples/rgbpp/shared/utils'; -import { BTC_TESTNET_TYPE, btcAccount } from '../../../../examples/rgbpp/env'; +import { BTC_TESTNET_TYPE, btcAccount } from '../../env'; import { signAndSendPsbt } from '../../../../examples/rgbpp/shared/btc-account'; interface SporeCreateParams { diff --git a/tests/rgbpp/xudt/2-btc-transfer.ts b/tests/rgbpp/xudt/2-btc-transfer.ts index f71a3779..c0f656bf 100644 --- a/tests/rgbpp/xudt/2-btc-transfer.ts +++ b/tests/rgbpp/xudt/2-btc-transfer.ts @@ -1,8 +1,7 @@ import { buildRgbppLockArgs } from 'rgbpp/ckb'; import { buildRgbppTransferTx } from 'rgbpp'; -import { isMainnet, collector, btcService, btcDataSource } from '../env'; +import { isMainnet, collector, btcService, btcDataSource, BTC_TESTNET_TYPE, btcAccount } from '../env'; import { readStepLog, writeStepLog } from '../shared/utils'; -import { BTC_TESTNET_TYPE, btcAccount } from '../env'; import { saveCkbVirtualTxResult } from '../../../examples/rgbpp/shared/utils'; import { bitcoin } from 'rgbpp/btc'; import { signAndSendPsbt } from '../../../examples/rgbpp/shared/btc-account'; From 775e36a8f81e6cd00e189b5929ed1541e374b7db Mon Sep 17 00:00:00 2001 From: Dawn <13477199767@163.com> Date: Tue, 18 Jun 2024 01:28:42 +0800 Subject: [PATCH 7/7] fix: Resolve integration:xudt test failure issue --- tests/rgbpp/xudt/1-ckb-leap-btc.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/rgbpp/xudt/1-ckb-leap-btc.ts b/tests/rgbpp/xudt/1-ckb-leap-btc.ts index 340e02b4..6c3ed6a6 100644 --- a/tests/rgbpp/xudt/1-ckb-leap-btc.ts +++ b/tests/rgbpp/xudt/1-ckb-leap-btc.ts @@ -1,7 +1,7 @@ import { serializeScript } from '@nervosnetwork/ckb-sdk-utils'; import { genCkbJumpBtcVirtualTx } from 'rgbpp'; import { getSecp256k1CellDep, buildRgbppLockArgs, getXudtTypeScript } from 'rgbpp/ckb'; -import { CKB_PRIVATE_KEY, isMainnet, collector, ckbAddress } from '../env'; +import { CKB_PRIVATE_KEY, isMainnet, collector, ckbAddress, BTC_TESTNET_TYPE } from '../env'; import { readStepLog } from '../shared/utils'; interface LeapToBtcParams { @@ -28,19 +28,20 @@ const leapFromCkbToBtc = async ({ outIndex, btcTxId, xudtTypeArgs, transferAmoun toRgbppLockArgs, xudtTypeBytes: serializeScript(xudtType), transferAmount, + btcTestnetType: BTC_TESTNET_TYPE, }); const emptyWitness = { lock: '', inputType: '', outputType: '' }; const unsignedTx: CKBComponents.RawTransactionToSign = { ...ckbRawTx, - cellDeps: [...ckbRawTx.cellDeps, getSecp256k1CellDep(false)], + cellDeps: [...ckbRawTx.cellDeps, getSecp256k1CellDep(isMainnet)], witnesses: [emptyWitness, ...ckbRawTx.witnesses.slice(1)], }; const signedTx = collector.getCkb().signTransaction(CKB_PRIVATE_KEY)(unsignedTx); const txHash = await collector.getCkb().rpc.sendTransaction(signedTx, 'passthrough'); - console.info(`Rgbpp asset has been jumped from CKB to BTC and tx hash is ${txHash}`); + console.info(`Rgbpp asset has been jumped from CKB to BTC and CKB tx hash is ${txHash}`); console.info(`explorer: https://pudge.explorer.nervos.org/transaction/${txHash}`); }); };