Skip to content
Open
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
59 changes: 59 additions & 0 deletions .github/workflows/ci_integration_tests_docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: ci_integration_tests_docker

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

permissions:
contents: read

jobs:
build:

runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-22.04]

# os: [ubuntu-22.04, macos-latest]


steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi

- name: Install dependencies
run: make prepare

- name: Run tests
run: make test
env:
DOCKER: true
DOCKER_CKB_VERSION: "nervos/ckb:v0.202.0-rc1"

#
#DOCKER = os.getenv('DOCKER',False)
#DOCKER_CKB_VERSION = os.getenv('DOCKER_CKB_VERSION',"nervos/ckb:v0.202.0-rc1")
# - name: Setup upterm session
# if: always()
# uses: lhotari/action-upterm@v1

- name: Publish reports
if: failure()
uses: actions/upload-artifact@v4
with:
name: jfoa-build-reports-${{ runner.os }}
path: ./report
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ develop_prepare:
python3 -m download_ckb_light_client
echo "install ckb cli"
bash develop_prepare.sh
# test_cases/ckb2023 \

test_cases := \
test_cases/replace_rpc \
test_cases/ckb_cli \
test_cases/ckb2023 \
test_cases/contracts \
test_cases/example \
test_cases/framework \
Expand All @@ -41,7 +41,8 @@ test_cases := \
test_cases/config \
test_cases/miner \
test_cases/get_fee_rate_statistics \
test_cases/ws
test_cases/ws \
test_cases/memory


test:
Expand Down
1 change: 1 addition & 0 deletions download.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"0.121.0",
"0.200.0",
"0.201.0",
"0.202.0",
] # Replace with your versions

DOWNLOAD_DIR = "download"
Expand Down
3 changes: 2 additions & 1 deletion download_ckb_light_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"0.3.5",
"0.3.6",
"0.4.1",
"0.5.3",
] # Replace with your versions

DOWNLOAD_DIR = "download"
Expand All @@ -34,7 +35,7 @@
"Linux": {
"x86_64": {
"url": "https://github.com/nervosnetwork/ckb-light-client/releases/download/v{version}/ckb-light-client_v{"
"version}-x86_64-linux.tar.gz",
"version}-x86_64-linux-portable.tar.gz",
"ext": ".tar.gz",
},
},
Expand Down
6 changes: 6 additions & 0 deletions framework/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import framework.test_cluster
import framework.config
import shutil

from framework.test_node import DOCKER
from framework.util import get_project_root


Expand Down Expand Up @@ -56,3 +58,7 @@ def teardown_method(self, method):
f"{get_project_root()}/tmp",
f"{get_project_root()}/report/{method.__name__}",
)

@staticmethod
def skip_docker():
return DOCKER
2 changes: 2 additions & 0 deletions framework/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
ALWAYS_SUCCESS_CONTRACT_PATH = f"{get_project_root()}/source/contract/always_success"
SPAWN_CONTRACT_PATH = f"{get_project_root()}/source/contract/test_cases/spawn_demo"
UDT_CONTRACT_PATH = f"{get_project_root()}/source/contract/XUDTType"
SPAWN_ARG_PATH = f"{get_project_root()}/source/contract/spawn_arg_length"
EXEC_ARG_PATH = f"{get_project_root()}/source/contract/exec_arg_length"


def get_tmp_path():
Expand Down
4 changes: 2 additions & 2 deletions framework/helper/ckb_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ def tx_add_input(tx_hash, index, tx_file, api_url="http://127.0.0.1:8114"):

def tx_add_multisig_config(ckb_address, tx_file, api_url="http://127.0.0.1:8114"):
"""
./ckb-cli tx add-multisig-config --sighash-address ckt1qyqdfjzl8ju2vfwjtl4mttx6me09hayzfldq8m3a0y --tx-file tx.txt
./ckb-cli tx add-multisig-config --multisig-code-hash legacy --sighash-address ckt1qyqdfjzl8ju2vfwjtl4mttx6me09hayzfldq8m3a0y --tx-file tx.txt
status: success
MacBook-Pro-4 0.111.0 % cat tx.txt
{
Expand Down Expand Up @@ -421,7 +421,7 @@ def tx_add_multisig_config(ckb_address, tx_file, api_url="http://127.0.0.1:8114"

"""
cmd = (
f"export API_URL={api_url} && {cli_path} tx add-multisig-config --sighash-address {ckb_address} "
f"export API_URL={api_url} && {cli_path} tx add-multisig-config --multisig-code-hash legacy --sighash-address {ckb_address} "
f"--tx-file {tx_file}"
)
return run_command(cmd)
Expand Down
3 changes: 2 additions & 1 deletion framework/helper/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,8 @@ def build_invoke_ckb_contract(
)
# get input_cell
account = util_key_info_by_private_key(account_private)
account_address = account["address"]["testnet"]
net = "testnet" if RPCClient(api_url).get_consensus()["id"] != "ckb" else "mainnet"
account_address = account["address"][net]
account_live_cells = wallet_get_live_cells(account_address, api_url=api_url)
assert len(account_live_cells["live_cells"]) > 0
input_cell_out_points = []
Expand Down
61 changes: 61 additions & 0 deletions framework/helper/exec_arg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
from framework.config import EXEC_ARG_PATH
from framework.helper.contract import deploy_ckb_contract, CkbContract
from framework.helper.miner import miner_until_tx_committed
from framework.helper.ckb_cli import util_key_info_by_private_key
from framework.helper.contract import invoke_ckb_contract

from framework.test_node import CkbNode
from framework.util import (
ckb_hash_script,
to_big_uint128_le_compatible,
to_int_from_big_uint128_le,
)
from framework.helper.contract import get_ckb_contract_codehash


class ExecArgContract(CkbContract):

def __init__(self, contract_hash=None, contract_tx_index=None):
self.contract_hash = contract_hash
self.contract_tx_index = contract_tx_index
if contract_hash is None:
self.deployed = False
else:
self.deployed = True
self.contract_path = EXEC_ARG_PATH
self.method = {"demo": {"args": "0x", "data": "0x"}}

def deploy(self, account_private, node: CkbNode):
if self.deployed:
return
self.contract_hash = deploy_ckb_contract(
account_private, self.contract_path, api_url=node.getClient().url
)
self.contract_tx_index = 0
miner_until_tx_committed(node, self.contract_hash)
self.deployed = True

def get_deploy_hash_and_index(self) -> (str, int):
if not self.deployed:
raise Exception("pls deploy first")
return self.contract_hash, self.contract_tx_index

def get_code_hash(self, type_id, api):
return get_ckb_contract_codehash(
self.contract_hash, self.contract_tx_index, type_id, api
)

def get_owner_arg_by_lock_arg(self, lock_arg):
return ckb_hash_script(lock_arg)

@classmethod
def get_test_data(cls, mb_size, kb_size, byte_size) -> (str, str):
return "0x1234", to_big_uint128_le_compatible(
mb_size * 100000000 + kb_size * 10000 + byte_size
)

def get_arg_and_data(self, key) -> (str, str):
if key not in self.method.keys():
# return "0x0","0x0"
raise Exception("key not exist in method list")
return self.method[key]["args"], self.method[key]["data"]
61 changes: 61 additions & 0 deletions framework/helper/spawn_arg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
from framework.config import SPAWN_ARG_PATH
from framework.helper.contract import deploy_ckb_contract, CkbContract
from framework.helper.miner import miner_until_tx_committed
from framework.helper.ckb_cli import util_key_info_by_private_key
from framework.helper.contract import invoke_ckb_contract

from framework.test_node import CkbNode
from framework.util import (
ckb_hash_script,
to_big_uint128_le_compatible,
to_int_from_big_uint128_le,
)
from framework.helper.contract import get_ckb_contract_codehash


class SpawnArgContract(CkbContract):

def __init__(self, contract_hash=None, contract_tx_index=None):
self.contract_hash = contract_hash
self.contract_tx_index = contract_tx_index
if contract_hash is None:
self.deployed = False
else:
self.deployed = True
self.contract_path = SPAWN_ARG_PATH
self.method = {"demo": {"args": "0x", "data": "0x"}}

def deploy(self, account_private, node: CkbNode):
if self.deployed:
return
self.contract_hash = deploy_ckb_contract(
account_private, self.contract_path, api_url=node.getClient().url
)
self.contract_tx_index = 0
miner_until_tx_committed(node, self.contract_hash)
self.deployed = True

def get_deploy_hash_and_index(self) -> (str, int):
if not self.deployed:
raise Exception("pls deploy first")
return self.contract_hash, self.contract_tx_index

def get_code_hash(self, type_id, api):
return get_ckb_contract_codehash(
self.contract_hash, self.contract_tx_index, type_id, api
)

def get_owner_arg_by_lock_arg(self, lock_arg):
return ckb_hash_script(lock_arg)

@classmethod
def get_test_data(cls, mb_size, kb_size, byte_size) -> (str, str):
return "0x1234", to_big_uint128_le_compatible(
mb_size * 100000000 + kb_size * 10000 + byte_size
)

def get_arg_and_data(self, key) -> (str, str):
if key not in self.method.keys():
# return "0x0","0x0"
raise Exception("key not exist in method list")
return self.method[key]["args"], self.method[key]["data"]
3 changes: 3 additions & 0 deletions framework/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ def get_transaction_proof(self, tx_hash, block_hash):
def send_transaction(self, tx, outputs_validator="passthrough"):
return self.call("send_transaction", [tx, outputs_validator])

def send_test_transaction(self, tx, outputs_validator="passthrough"):
return self.call("send_test_transaction", [tx, outputs_validator])

def get_raw_tx_pool(self, verbose=None):
return self.call("get_raw_tx_pool", [verbose])

Expand Down
7 changes: 6 additions & 1 deletion framework/test_light_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,14 @@ class CkbLightClientConfigPath(Enum):
"download/0.4.2/ckb-light-client",
)

V0_5_0 = (
"source/template/ckb_light_client/0.3.0/testnet.toml.j2",
"download/0.5.0/ckb-light-client",
)

CURRENT_TEST = (
"source/template/ckb_light_client/0.3.0/testnet.toml.j2",
"download/0.4.1/ckb-light-client",
"download/0.5.3/ckb-light-client",
)

def __init__(self, ckb_light_client_config_path, ckb_light_bin_path):
Expand Down
Loading