diff --git a/.github/workflows/integration-test.yaml b/.github/workflows/integration-test.yaml index 82011340..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 * * *' @@ -49,9 +48,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 +59,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..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: ${{ secrets.SERVICE_URL }} - VITE_BTC_SERVICE_TOKEN: ${{ secrets.SERVICE_TOKEN }} - VITE_BTC_SERVICE_ORIGIN: ${{ secrets.SERVICE_ORIGIN }} + 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/env.ts b/tests/rgbpp/env.ts index e65e8a27..6a4ba5f7 100644 --- a/tests/rgbpp/env.ts +++ b/tests/rgbpp/env.ts @@ -1,21 +1,32 @@ -import { AddressPrefix, privateKeyToAddress } from '@nervosnetwork/ckb-sdk-utils'; -import { DataSource, BtcAssetsApi } from 'rgbpp'; +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 { 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', 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, -}); +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!; @@ -24,11 +35,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..5ac8b17a 100644 --- a/tests/rgbpp/shared/prepare-utxo.ts +++ b/tests/rgbpp/shared/prepare-utxo.ts @@ -1,24 +1,22 @@ 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); + console.log(btcAccount.from); // Send BTC tx const psbt = await sendBtc({ - from: btcAddress!, + from: btcAccount.from!, tos: [ { - address: btcAddress!, + address: btcAccount.from!, value: 546, minUtxoSatoshi: 546, }, ], - feeRate: feeRate, + feeRate: 1, source: btcDataSource, }); @@ -31,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 30d53c0a..d0b16d4a 100644 --- a/tests/rgbpp/spore/4-transfer-spore.ts +++ b/tests/rgbpp/spore/4-transfer-spore.ts @@ -2,9 +2,10 @@ 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, 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 SporeTransferParams { sporeRgbppLockArgs: Hex; @@ -20,14 +21,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,18 +41,15 @@ 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}`); + 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 6346c088..5600d681 100644 --- a/tests/rgbpp/spore/5-leap-spore-to-ckb.ts +++ b/tests/rgbpp/spore/5-leap-spore-to-ckb.ts @@ -2,9 +2,10 @@ 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, 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 SporeLeapParams { sporeRgbppLockArgs: Hex; @@ -20,15 +21,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,21 +39,18 @@ 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}`); + 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/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 4e5d9fe8..e398e52e 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.from); 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,26 +40,23 @@ 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, 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 9f180407..61efe851 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 '../../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,29 +44,26 @@ 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, }); 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 { @@ -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/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}`); }); }; diff --git a/tests/rgbpp/xudt/2-btc-transfer.ts b/tests/rgbpp/xudt/2-btc-transfer.ts index d1f7a7ff..c0f656bf 100644 --- a/tests/rgbpp/xudt/2-btc-transfer.ts +++ b/tests/rgbpp/xudt/2-btc-transfer.ts @@ -1,8 +1,10 @@ -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, BTC_TESTNET_TYPE, btcAccount } from '../env'; import { readStepLog, writeStepLog } from '../shared/utils'; +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,38 +16,32 @@ 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); - console.log(`explorer: https://mempool.space/testnet/tx/${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/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 5f2c752f..7d16fc5b 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,27 +28,29 @@ 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); - console.log(`explorer: https://mempool.space/testnet/tx/${btcTxId}`); + const { txId: btcTxId } = await signAndSendPsbt(psbt, btcAccount, btcService); + console.log(`BTC ${BTC_TESTNET_TYPE} TxId: ${btcTxId}`); + console.log(`explorer: https://mempool.space/signet/tx/${btcTxId}`); await btcService.sendRgbppCkbTransaction({ btc_txid: btcTxId, ckb_virtual_result: ckbVirtualTxResult });