Skip to content

test: Create integration tests for xUDT workflow #169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/workflows/integration-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Test the entire process of RGBPP to ensure the proper functioning of the rgbpp-sdk package.

name: Integration Tests

on:
workflow_dispatch:
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout rgbpp-sdk
uses: actions/checkout@v4

- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 20.x

- uses: pnpm/action-setup@v3
name: Install -g pnpm
with:
version: 8
run_install: false

- name: Install dependencies
run: pnpm i

- name: Build packages
run: pnpm run build:packages

- name: Run integration:xudt script
working-directory: ./tests/rgbpp
run: pnpm run integration:xudt
env:
VITE_SERVICE_URL: ${{ secrets.SERVICE_URL }}
VITE_SERVICE_TOKEN: ${{ secrets.SERVICE_TOKEN }}
VITE_SERVICE_ORIGIN: ${{ secrets.SERVICE_ORIGIN }}
INTEGRATION_CKB_PRIVATE_KEY: ${{ secrets.INTEGRATION_CKB_PRIVATE_KEY }}
INTEGRATION_BTC_PRIVATE_KEY: ${{ secrets.INTEGRATION_BTC_PRIVATE_KEY }}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"test:packages": "turbo run test --filter=./packages/*",
"build:packages": "turbo run build --filter=./packages/*",
"lint:fix": "turbo run lint:fix",
"lint:packages": "turbo run lint --filter=./{packages,examples}/*",
"format": "prettier --write '{packages,apps,examples}/**/*.{js,jsx,ts,tsx}'",
"lint:packages": "turbo run lint --filter=./{packages,examples,tests}/*",
"format": "prettier --write '{packages,apps,examples,tests}/**/*.{js,jsx,ts,tsx}'",
"clean": "turbo run clean",
"clean:packages": "turbo run clean --filter=./packages/*",
"clean:dependencies": "pnpm clean:sub-dependencies && rimraf node_modules",
Expand All @@ -33,7 +33,7 @@
"typescript": "^5.4.3"
},
"lint-staged": {
"{packages,apps,examples}/**/*.{js,jsx,ts,tsx}": [
"{packages,apps,examples,tests}/**/*.{js,jsx,ts,tsx}": [
"eslint --fix",
"prettier --ignore-unknown --write"
]
Expand Down
92 changes: 71 additions & 21 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ packages:
- "packages/*"
- "apps/*"
- "examples/*"
- "tests/*"
34 changes: 34 additions & 0 deletions tests/rgbpp/env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { AddressPrefix, privateKeyToAddress } from '@nervosnetwork/ckb-sdk-utils';
import { DataSource, BtcAssetsApi } from 'rgbpp';
import { ECPair, ECPairInterface, bitcoin, NetworkType } from 'rgbpp/btc';
import dotenv from 'dotenv';
import { Collector } from 'rgbpp/ckb';

dotenv.config({ path: __dirname + '/.env' });

export const isMainnet = false;

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 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 });
export const { address: btcAddress } = bitcoin.payments.p2wpkh({
pubkey: btcKeyPair.publicKey,
network,
});

const networkType = isMainnet ? NetworkType.MAINNET : NetworkType.TESTNET;
export const btcService = BtcAssetsApi.fromToken(BTC_SERVICE_URL, BTC_SERVICE_TOKEN, BTC_SERVICE_ORIGIN);
export const btcDataSource = new DataSource(btcService, networkType);
24 changes: 24 additions & 0 deletions tests/rgbpp/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "rgbpp-integration-tests",
"version": "0.1.0",
"description": "Test the entire process of RGBPP to ensure the proper functioning of the rgbpp-sdk package.",
"private": true,
"type": "commonjs",
"scripts": {
"format": "prettier --write '**/*.{js,ts}'",
"lint": "tsc && eslint . && prettier --check '**/*.{js,ts}'",
"lint:fix": "tsc && eslint --fix --ext .js,.ts . && prettier --write '**/*.{js,ts}'",
"integration:xudt": "npx ts-node shared/prepare-utxo.ts && npx ts-node xudt/xudt-on-ckb/1-issue-xudt.ts && npx ts-node xudt/1-ckb-leap-btc.ts && npx ts-node xudt/2-btc-transfer.ts && npx ts-node xudt/3-btc-leap-ckb.ts"
},
"dependencies": {
"@nervosnetwork/ckb-sdk-utils": "^0.109.1",
"rgbpp": "workspace:*",
"zx": "^8.0.2"
},
"devDependencies": {
"@types/node": "^20.11.28",
"typescript": "^5.4.2",
"dotenv": "^16.4.5",
"@types/dotenv": "^8.2.0"
}
}
Loading