Skip to content

Commit 20cea87

Browse files
Scz/203 (#109)
* Update download.py * Update test_node.py * add test for listen 2address * add exec and spawn test * compare cycle vs 200 * fix path not found * black code * fix contract call err * format code * Update download.py * update light-client main branch * update ckb-light version * update light client download url * support docker * fix docker * fix ci for docker * update makefile * update light client * add test_ckbcli_dep_groups_enable_type_id_203.py --------- Co-authored-by: sunchengzhu <[email protected]>
1 parent 49b9ed0 commit 20cea87

File tree

11 files changed

+198
-23
lines changed

11 files changed

+198
-23
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# This workflow will install Python dependencies, run tests and lint with a single version of Python
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
3+
4+
name: ci_integration_tests_docker
5+
6+
on:
7+
push:
8+
branches: [ "main" ]
9+
pull_request:
10+
branches: [ "main" ]
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
build:
17+
18+
runs-on: ${{ matrix.os }}
19+
strategy:
20+
matrix:
21+
os: [ubuntu-22.04]
22+
23+
# os: [ubuntu-22.04, macos-latest]
24+
25+
26+
steps:
27+
- uses: actions/checkout@v3
28+
- name: Set up Python 3.10
29+
uses: actions/setup-python@v3
30+
with:
31+
python-version: "3.10"
32+
33+
- name: Install dependencies
34+
run: |
35+
python -m pip install --upgrade pip
36+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
37+
38+
- name: Install dependencies
39+
run: make prepare
40+
41+
- name: Run tests
42+
run: make test
43+
env:
44+
DOCKER: true
45+
DOCKER_CKB_VERSION: "nervos/ckb:v0.202.0-rc1"
46+
47+
#
48+
#DOCKER = os.getenv('DOCKER',False)
49+
#DOCKER_CKB_VERSION = os.getenv('DOCKER_CKB_VERSION',"nervos/ckb:v0.202.0-rc1")
50+
# - name: Setup upterm session
51+
# if: always()
52+
# uses: lhotari/action-upterm@v1
53+
54+
- name: Publish reports
55+
if: failure()
56+
uses: actions/upload-artifact@v4
57+
with:
58+
name: jfoa-build-reports-${{ runner.os }}
59+
path: ./report

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ develop_prepare:
2323
python3 -m download_ckb_light_client
2424
echo "install ckb cli"
2525
bash develop_prepare.sh
26+
# test_cases/ckb2023 \
2627
2728
test_cases := \
2829
test_cases/ckb_cli \
29-
test_cases/ckb2023 \
3030
test_cases/contracts \
3131
test_cases/example \
3232
test_cases/framework \

framework/basic.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import framework.test_cluster
1313
import framework.config
1414
import shutil
15+
16+
from framework.test_node import DOCKER
1517
from framework.util import get_project_root
1618

1719

@@ -56,3 +58,7 @@ def teardown_method(self, method):
5658
f"{get_project_root()}/tmp",
5759
f"{get_project_root()}/report/{method.__name__}",
5860
)
61+
62+
@staticmethod
63+
def skip_docker():
64+
return DOCKER

framework/helper/ckb_cli.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -601,19 +601,30 @@ def tx_add_header_dep(block_hash, tx_file):
601601
f.write(tx_info_str)
602602

603603

604-
def get_deploy_toml_config(account_private, contract_bin_path, enable_type_id):
604+
def get_deploy_toml_config(
605+
account_private, contract_bin_path, enable_type_id, dep_groups_enable_type_id="old"
606+
):
605607
# get account script
606608
account = util_key_info_by_private_key(account_private)
609+
# handle enable_type_id line in dep_groups
610+
dep_groups_enable_line = ""
611+
if not (
612+
isinstance(dep_groups_enable_type_id, str)
613+
and dep_groups_enable_type_id.lower() == "old"
614+
):
615+
dep_groups_enable_line = (
616+
f"\nenable_type_id = {str(dep_groups_enable_type_id).lower()}"
617+
)
618+
607619
# return format toml
608620
return f"""
609-
[[cells]]
621+
[[cells]]
610622
name = "compact_udt_lock"
611623
enable_type_id = {str(enable_type_id).lower()}
612624
location = {{ file = "{contract_bin_path}" }}
613625
614626
[[dep_groups]]
615-
name = "my_dep_group"
616-
enable_type_id = {str(enable_type_id).lower()}
627+
name = "my_dep_group"{dep_groups_enable_line}
617628
cells = []
618629
619630
[lock]

framework/helper/contract.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ def deploy_ckb_contract(
2626
contract_path,
2727
fee_rate=2000,
2828
enable_type_id=True,
29+
dep_groups_enable_type_id="old",
30+
return_tx="cell_tx",
2931
api_url="http://127.0.0.1:8114",
3032
):
3133
"""
@@ -44,7 +46,7 @@ def deploy_ckb_contract(
4446
tmp_tx_info_path = f"/tmp/tx-{time.time_ns().real}.json"
4547
tmp_deploy_toml_path = "/tmp/deploy1.toml"
4648
deploy_toml_str = get_deploy_toml_config(
47-
private_key, contract_path, enable_type_id
49+
private_key, contract_path, enable_type_id, dep_groups_enable_type_id
4850
)
4951
with open(tmp_deploy_toml_path, "w") as f:
5052
f.write(deploy_toml_str)
@@ -62,6 +64,8 @@ def deploy_ckb_contract(
6264
)
6365
deploy_sign_txs(private_key, tmp_tx_info_path, api_url)
6466
deploy_tx_result = deploy_apply_txs(tmp_tx_info_path, api_url)
67+
if return_tx == "dep_group_tx":
68+
return deploy_tx_result["dep_group_tx"]
6569
return deploy_tx_result["cell_tx"]
6670

6771
# rand ckb address ,provider contract cell cant be used

framework/test_node.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
import os
1515

1616

17+
DOCKER = os.getenv("DOCKER", False)
18+
DOCKER_CKB_VERSION = os.getenv("DOCKER_CKB_VERSION", "nervos/ckb:v0.202.0-rc1")
19+
20+
1721
DOCKER = os.getenv("DOCKER", False)
1822
DOCKER_CKB_VERSION = os.getenv("DOCKER_CKB_VERSION", "nervos/ckb:v0.203.0-rc1")
1923

@@ -206,13 +210,13 @@ def start(self):
206210
ws_port = self.ckb_config["ckb_ws_listen_address"].split(":")[-1]
207211
tcp_port = self.ckb_config["ckb_tcp_listen_address"].split(":")[-1]
208212
self.ckb_pid = run_command(
209-
f"docker run --name {self.ckb_dir.split('/')[-1]} -p {p2p_port}:{p2p_port} -p {rpc_port}:{rpc_port} -p {ws_port}:{ws_port} -p {tcp_port}:{tcp_port} -v {self.ckb_dir}:/var/lib/ckb {DOCKER_CKB_VERSION} run -C /var/lib/ckb "
213+
f"docker run --name {self.ckb_dir.split('/')[-1]} -p {p2p_port}:{p2p_port} -p {rpc_port}:{rpc_port} -p {ws_port}:{ws_port} -p {tcp_port}:{tcp_port} --network my-network -v {self.ckb_dir}:/var/lib/ckb {DOCKER_CKB_VERSION} run -C /var/lib/ckb "
210214
f"--indexer --skip-spec-check > {self.ckb_dir}/node.log 2>&1 &"
211215
)
212216
time.sleep(3)
213217
return
214218
self.ckb_pid = run_command(
215-
f"docker run --name {self.ckb_dir.split('/')[-1]} -p {p2p_port}:{p2p_port} -p {rpc_port}:{rpc_port} -v {self.ckb_dir}:/var/lib/ckb {DOCKER_CKB_VERSION} run -C /var/lib/ckb "
219+
f"docker run --name {self.ckb_dir.split('/')[-1]} -p {p2p_port}:{p2p_port} -p {rpc_port}:{rpc_port} --network my-network -v {self.ckb_dir}:/var/lib/ckb {DOCKER_CKB_VERSION} run -C /var/lib/ckb "
216220
f"--indexer --skip-spec-check > {self.ckb_dir}/node.log 2>&1 &"
217221
)
218222
time.sleep(3)

framework/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def get_ckb_configs(p2p_port, rpc_port, spec='{ file = "dev.toml" }'):
3434
"ckb_network_listen_addresses": [
3535
"/ip4/0.0.0.0/tcp/{p2p_port}".format(p2p_port=p2p_port)
3636
],
37-
"ckb_rpc_listen_address": "127.0.0.1:{rpc_port}".format(rpc_port=rpc_port),
37+
"ckb_rpc_listen_address": "0.0.0.0:{rpc_port}".format(rpc_port=rpc_port),
3838
"ckb_rpc_modules": [
3939
"Net",
4040
"Pool",
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
from framework.basic import CkbTest
2+
3+
4+
class TestCkbCliMultisig203(CkbTest):
5+
6+
@classmethod
7+
def setup_class(cls):
8+
"""
9+
1. start 1 ckb node in tmp/ckb_cli/node dir
10+
2. miner 2 block
11+
Returns:
12+
13+
"""
14+
# 1. start 1 ckb node in tmp/ckb_cli/node dir
15+
cls.node = cls.CkbNode.init_dev_by_port(
16+
cls.CkbNodeConfigPath.CURRENT_TEST, "ckb_cli/node", 8314, 8315
17+
)
18+
cls.node.prepare()
19+
cls.node.start()
20+
# 2. miner 2 block
21+
cls.Miner.make_tip_height_number(cls.node, 2)
22+
23+
@classmethod
24+
def teardown_class(cls):
25+
"""
26+
1. stop ckb node
27+
2. clean ckb node tmp dir
28+
Returns:
29+
30+
"""
31+
print("stop node and clean")
32+
cls.node.stop()
33+
cls.node.clean()
34+
35+
def test_01_dep_groups_enable_type_id_true(self):
36+
# 1. deploy contract return deploy tx hash
37+
dep_group_tx_hash = self.Contract.deploy_ckb_contract(
38+
self.Config.ACCOUNT_PRIVATE_2,
39+
self.Config.ALWAYS_SUCCESS_CONTRACT_PATH,
40+
enable_type_id=True,
41+
dep_groups_enable_type_id=True,
42+
return_tx="dep_group_tx",
43+
api_url=self.node.getClient().url,
44+
)
45+
# 2. miner until deploy contrct tx hash
46+
tx_response = self.Miner.miner_until_tx_committed(self.node, dep_group_tx_hash)
47+
output = tx_response["transaction"]["outputs"][0]
48+
# 3. check hash_type
49+
output_type = output.get("type")
50+
assert (
51+
output_type is not None
52+
), "Failed: Output does not contain a 'type' field."
53+
54+
def test_02_dep_groups_enable_type_id_false(self):
55+
# 1. deploy contract return deploy tx hash
56+
dep_group_tx_hash = self.Contract.deploy_ckb_contract(
57+
self.Config.ACCOUNT_PRIVATE_2,
58+
self.Config.ALWAYS_SUCCESS_CONTRACT_PATH,
59+
enable_type_id=True,
60+
dep_groups_enable_type_id=False,
61+
return_tx="dep_group_tx",
62+
api_url=self.node.getClient().url,
63+
)
64+
# 2. miner until deploy contrct tx hash
65+
tx_response = self.Miner.miner_until_tx_committed(self.node, dep_group_tx_hash)
66+
output = tx_response["transaction"]["outputs"][0]
67+
# 3. check hash_type
68+
assert (
69+
output.get("type") is None
70+
), f"Failed: type field should be None, got {output.get('type')}"
71+
72+
def test_03_dep_groups_enable_type_id_old(self):
73+
# 1. deploy contract return deploy tx hash
74+
dep_group_tx_hash = self.Contract.deploy_ckb_contract(
75+
self.Config.ACCOUNT_PRIVATE_2,
76+
self.Config.ALWAYS_SUCCESS_CONTRACT_PATH,
77+
enable_type_id=True,
78+
dep_groups_enable_type_id="old",
79+
return_tx="dep_group_tx",
80+
api_url=self.node.getClient().url,
81+
)
82+
# 2. miner until deploy contrct tx hash
83+
tx_response = self.Miner.miner_until_tx_committed(self.node, dep_group_tx_hash)
84+
output = tx_response["transaction"]["outputs"][0]
85+
# 3. check hash_type
86+
assert (
87+
output.get("type") is None
88+
), f"Failed: type field should be None, got {output.get('type')}"

test_cases/replace_rpc/test_sub_telnet_with_websocket.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import time
33

44
from framework.basic import CkbTest
5+
from framework.test_node import DOCKER
56

67

78
class TestTelnetAndWebsocket(CkbTest):
@@ -21,8 +22,8 @@ def setup_class(cls):
2122
cls.node113.prepare(
2223
other_ckb_config={
2324
"ckb_logger_filter": "debug",
24-
"ckb_tcp_listen_address": "127.0.0.1:18116",
25-
"ckb_ws_listen_address": "127.0.0.1:18124",
25+
"ckb_tcp_listen_address": "0.0.0.0:18116",
26+
"ckb_ws_listen_address": "0.0.0.0:18124",
2627
}
2728
)
2829

test_cases/replace_rpc/test_telnet.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ def setup_class(cls):
2424
cls.node113.prepare(
2525
other_ckb_config={
2626
"ckb_logger_filter": "debug",
27-
"ckb_tcp_listen_address": "127.0.0.1:18115",
28-
"ckb_ws_listen_address": "127.0.0.1:18124",
27+
"ckb_tcp_listen_address": "0.0.0.0:18115",
28+
"ckb_ws_listen_address": "0.0.0.0:18124",
2929
}
3030
)
3131

@@ -53,7 +53,7 @@ def test_link_count_max(self):
5353
"""
5454
# 1.test 113 max link count
5555
telnets = []
56-
for i in range(10000):
56+
for i in range(100):
5757
print(i)
5858
telnet = self.node113.subscribe_telnet("new_tip_header")
5959
telnets.append(telnet)
@@ -74,7 +74,7 @@ def test_link_time_max(self):
7474
"""
7575
telnet113 = self.node113.subscribe_telnet("new_tip_header")
7676

77-
for i in range(300):
77+
for i in range(30):
7878
self.Miner.miner_with_version(self.node113, "0x0")
7979
print("current idx:", i)
8080
ret113 = telnet113.read_very_eager()
@@ -91,7 +91,10 @@ def test_link_websocket(self):
9191
"""
9292
with pytest.raises(Exception) as exc_info:
9393
socket = self.node113.subscribe_websocket(
94-
"new_tip_header", self.node113.ckb_config["ckb_tcp_listen_address"]
94+
"new_tip_header",
95+
self.node113.ckb_config["ckb_tcp_listen_address"].replace(
96+
"0.0.0.0", "127.0.0.1"
97+
),
9598
)
9699
expected_error_message = "invalid literal for int() with base 10"
97100
assert (
@@ -106,7 +109,7 @@ def test_rpc(self):
106109
"""
107110

108111
client = self.node113.getClient()
109-
client.url = f"http://{self.node113.ckb_config['ckb_tcp_listen_address']}"
112+
client.url = f"http://{self.node113.ckb_config['ckb_tcp_listen_address'].replace('0.0.0.0','127.0.0.1')}"
110113

111114
with pytest.raises(Exception) as exc_info:
112115
response = client.call("get_tip_block_number", [], 1)
@@ -142,7 +145,7 @@ def test_unsubscribe(self):
142145
"""
143146

144147
client = self.node113.getClient()
145-
client.url = f"http://{self.node113.ckb_config['ckb_rpc_listen_address']}"
148+
client.url = f"http://{self.node113.ckb_config['ckb_rpc_listen_address'].replace('0.0.0.0','127.0.0.1')}"
146149
socket = self.node113.subscribe_telnet("new_tip_header")
147150
self.Miner.miner_with_version(self.node113, "0x0")
148151
ret = socket.read_very_eager()

0 commit comments

Comments
 (0)