Skip to content
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

V113 #28

Merged
merged 23 commits into from
Feb 5, 2024
Merged

V113 #28

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
4 changes: 4 additions & 0 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ jobs:
- name: Run tests
run: make test

# - name: Setup upterm session
# if: always()
# uses: lhotari/action-upterm@v1

- name: Publish reports
if: failure()
uses: actions/upload-artifact@v2
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ check_failed_html:
exit 1; \
fi
test:
bash test.sh test_cases/replace_rpc
bash test.sh test_cases/ckb2023
bash test.sh test_cases/ckb_cli
bash test.sh test_cases/contracts
Expand Down
2 changes: 1 addition & 1 deletion download.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import requests
from tqdm import tqdm

versions = ['0.109.0', '0.110.2', '0.111.0', '0.112.1'] # Replace with your versions
versions = ['0.109.0', '0.110.2', '0.111.0', '0.112.1', '0.113.1'] # Replace with your versions
DOWNLOAD_DIR = "download"
SYSTEMS = {
'Windows': {
Expand Down
2 changes: 1 addition & 1 deletion download_ckb_light_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import requests
from tqdm import tqdm

versions = ['0.2.4', '0.3.0', '0.3.1'] # Replace with your versions
versions = ['0.2.4', '0.3.0', '0.3.1', '0.3.2', '0.3.3', '0.3.4', '0.3.5'] # Replace with your versions
DOWNLOAD_DIR = "download"
SYSTEMS = {
'Windows': {
Expand Down
3 changes: 1 addition & 2 deletions framework/basic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from abc import ABC, abstractmethod
from abc import ABC

import unittest
import framework.helper.miner
Expand All @@ -10,7 +10,6 @@
import framework.test_node
import framework.test_light_client
import framework.test_cluster
import framework.helper
import framework.config
import shutil
from framework.util import get_project_root
Expand Down
31 changes: 31 additions & 0 deletions framework/ckb_light_client_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@ def get_scripts(self):
def get_cells_capacity(self, script):
return self.call("get_cells_capacity", [script])

def get_cells(self, search_key, order, limit, after):
return self.call2("get_cells", [search_key, order, limit, after])

def fetch_transaction(self, tx_hash):
return self.call("fetch_transaction", [tx_hash])

def get_transactions(self, search_key, order, limit, after):
return self.call("get_transactions", [search_key, order, limit, after])

def send_transaction(self,tx):
return self.call("send_transaction",[tx])
Expand Down Expand Up @@ -54,3 +59,29 @@ def call(self, method, params):
time.sleep(2)
continue
raise Exception("request time out")

def call2(self, method, params):

headers = {'content-type': 'application/json'}
data = {
"id": 42,
"jsonrpc": "2.0",
"method": method,
"params": params
}
print("request:url:{url},data:\n{data}".format(url=self.url, data=json.dumps(data)))
for i in range(100):
try:
response = requests.post(self.url, data=json.dumps(data), headers=headers).json()
# print("response:\n{response}".format(response=json.dumps(response)))
if 'error' in response.keys():
error_message = response['error'].get('message', 'Unknown error')
raise Exception(f"Error: {error_message}")

return response.get('result', None)
except requests.exceptions.ConnectionError as e:
print(e)
print("request too quickly, wait 2s")
time.sleep(2)
continue
raise Exception("request time out")
103 changes: 103 additions & 0 deletions framework/helper/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,106 @@ def invoke_ckb_contract(account_private, contract_out_point_tx_hash, contract_ou
tx_info(tmp_tx_file, api_url)
# send tx return hash
return tx_send(tmp_tx_file, api_url).strip()


@exception_use_old_ckb()
def build_invoke_ckb_contract(account_private, contract_out_point_tx_hash, contract_out_point_tx_index, type_script_arg,
hash_type="type",
data="0x", fee=1000,
api_url="http://127.0.0.1:8114"):
"""

Args:
account_private:
contract_out_point_tx_hash:
contract_out_point_tx_index:
type_script_arg:
hash_type: data ,data1,type data2
data:
fee:
api_url:

Returns:

"""
if hash_type == "type":
contract_code_hash = get_ckb_contract_codehash(contract_out_point_tx_hash, contract_out_point_tx_index,
enable_type_id=True,
api_url=api_url)
else:
contract_code_hash = get_ckb_contract_codehash(contract_out_point_tx_hash, contract_out_point_tx_index,
enable_type_id=False,
api_url=api_url)
# get input_cell
account = util_key_info_by_private_key(account_private)
account_address = account["address"]["testnet"]
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 = []
input_cell_cap = 0
for i in range(len(account_live_cells['live_cells'])):
input_cell_out_point = {
'tx_hash': account_live_cells['live_cells'][i]['tx_hash'],
'index': account_live_cells['live_cells'][i]['output_index']
}
input_cell_cap += float(account_live_cells['live_cells'][i]['capacity'].replace('(CKB)', "").strip()) * 100000000
input_cell_out_points.append(input_cell_out_point)
if input_cell_cap> 10000000000:
break


# get output_cells.cap = input_cell.cap - fee
# "capacity": "21685.0 (CKB)",
output_cell_capacity = input_cell_cap - fee

output_cell = {
"capacity": hex(int(output_cell_capacity)),
# rand ckb address for pass ckb-cli check lock address
"lock": {
"code_hash": "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8",
"hash_type": "type",
"args": "0x470dcdc5e44064909650113a274b3b36aecb6dc7"
},
"type": {
"code_hash": contract_code_hash,
"hash_type": hash_type,
"args": type_script_arg
}
}
# add dep
cell_dep = {
'tx_hash': contract_out_point_tx_hash,
'index': hex(contract_out_point_tx_index)
}
# tx file init
tmp_tx_file = "/tmp/demo.json"
tx_init(tmp_tx_file, api_url)
tx_add_multisig_config(account_address, tmp_tx_file, api_url)
# add input
for i in range(len(input_cell_out_points)):
input_cell_out_point = input_cell_out_points[i]
tx_add_input(input_cell_out_point['tx_hash'], input_cell_out_point['index'], tmp_tx_file, api_url)
transaction = RPCClient(api_url).get_transaction(contract_out_point_tx_hash)
tx_add_header_dep(transaction['tx_status']['block_hash'], tmp_tx_file)
# add output
tx_add_type_out_put(output_cell["type"]["code_hash"], output_cell["type"]["hash_type"], output_cell["type"]["args"],
output_cell["capacity"], data, tmp_tx_file)
# add dep
tx_add_cell_dep(cell_dep['tx_hash'], cell_dep['index'], tmp_tx_file)
# sign
sign_data = tx_sign_inputs(account_private, tmp_tx_file, api_url)
tx_add_signature(sign_data[0]['lock-arg'], sign_data[0]['signature'], tmp_tx_file, api_url)
tx_info(tmp_tx_file, api_url)
# send tx return hash
return build_tx_info(tmp_tx_file)


def build_tx_info(tmp_tx_file):
with open(tmp_tx_file, "r") as file:
tx_info_str = file.read()
tx = json.loads(tx_info_str)
sign_keys = list(tx['signatures'].keys())[0]
witness = "0x5500000010000000550000005500000041000000" + tx['signatures'][sign_keys][0][2:]
tx_msg = tx['transaction']
tx_msg['witnesses'] = [witness]
return tx_msg
2 changes: 1 addition & 1 deletion framework/helper/miner.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def miner_until_tx_committed(node, tx_hash, with_unknown=False):
if tx_response['tx_status']['status'] == "rejected" or tx_response['tx_status']['status'] == "unknown":
raise Exception(f"status:{tx_response['tx_status']['status']},reason:{tx_response['tx_status']['reason']}")

raise Exception(f"miner 100 block ,but tx_response always pending:{tx_hash}")
raise Exception(f"miner 100 block ,but tx_response always pending:{tx_hash},tx_response:{tx_response}")


# https://github.com/nervosnetwork/rfcs/pull/416
Expand Down
4 changes: 4 additions & 0 deletions framework/helper/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ def wrapper(*args, **kwargs):
def wait_get_transaction(node, tx_hash, status):
return node.getClient().get_transaction(tx_hash)['tx_status']['status'] == status

@wait_until_timeout(wait_times=60)
def wait_fetch_transaction(node, tx_hash, status):
return node.getClient().fetch_transaction(tx_hash)['status'] == status


@wait_until_timeout(wait_times=60)
def wait_tx_pool(node, pool_key, gt_size):
Expand Down
53 changes: 53 additions & 0 deletions framework/helper/tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,56 @@ def send_transfer_self_tx_with_input(input_tx_hash_list, input_tx_index_list, si
tx_info(tmp_tx_file, api_url)
# send tx return hash
return tx_send(tmp_tx_file, api_url).strip()


def build_send_transfer_self_tx_with_input(input_tx_hash_list, input_tx_index_list, sign_private, data="0x",
fee=5000, output_count=1,
api_url="http://127.0.0.1:8114", dep_cells=[]):
# tx file init

tmp_tx_file = f"/tmp/demo{time.time()}-{random.randint(0, 100000000)}.json"
tx_init(tmp_tx_file, api_url)
account = util_key_info_by_private_key(sign_private)
account_address = account["address"]["testnet"]
tx_add_multisig_config(account_address, tmp_tx_file, api_url)
# add input
output_cell_capacity_total = 0
input_cell_template: any
for i in range(len(input_tx_hash_list)):
input_tx_index = input_tx_index_list[i]
input_tx_hash = input_tx_hash_list[i]
print(f"input_tx_index:{input_tx_index}")
tx_add_input(input_tx_hash, int(input_tx_index, 16), tmp_tx_file, api_url)
# add output
input_cell = RPCClient(api_url).get_transaction(input_tx_hash)["transaction"]["outputs"][
int(input_tx_index, 16)]
output_cell_capacity = int(int(input_cell["capacity"], 16) - fee)
output_cell_capacity_total += output_cell_capacity
input_cell_template = input_cell
min_output_count = min(int(output_cell_capacity_total / (100 * 100000000)), output_count)
min_output_count = max(min_output_count, 1)
output_cell_capacity = int(output_cell_capacity_total / min_output_count)
for i in range(min_output_count):
tx_add_type_out_put(input_cell_template["lock"]["code_hash"], input_cell_template["lock"]["hash_type"],
input_cell_template["lock"]["args"],
hex(output_cell_capacity), data, tmp_tx_file, False)
for i in range(len(dep_cells)):
tx_add_cell_dep(dep_cells[i]['tx_hash'],dep_cells[i]['index_hex'],tmp_tx_file)

# sign
sign_data = tx_sign_inputs(sign_private, tmp_tx_file, api_url)
tx_add_signature(sign_data[0]['lock-arg'], sign_data[0]['signature'], tmp_tx_file, api_url)
tx_info(tmp_tx_file, api_url)
# send tx return hash
return build_tx_info(tmp_tx_file)


def build_tx_info(tmp_tx_file):
with open(tmp_tx_file, "r") as file:
tx_info_str = file.read()
tx = json.loads(tx_info_str)
sign_keys = list(tx['signatures'].keys())[0]
witness = "0x5500000010000000550000005500000041000000" + tx['signatures'][sign_keys][0][2:]
tx_msg = tx['transaction']
tx_msg['witnesses'] = [witness]
return tx_msg
12 changes: 6 additions & 6 deletions framework/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def generate_epochs(self, epoch):
return self.call("generate_epochs", [epoch])

def generate_block(self):
return self.call("generate_block",[])
return self.call("generate_block", [])

def get_deployments_info(self):
return self.call("get_deployments_info", [])
Expand Down Expand Up @@ -145,7 +145,7 @@ def get_transaction(self, tx_hash, verbosity=None, only_committed=None):
return self.call("get_transaction", [tx_hash, verbosity, only_committed])

def get_transactions(self, search_key, order, limit, after):
return self.call("get_transactions", [search_key, order, limit,after])
return self.call("get_transactions", [search_key, order, limit, after])

def dry_run_transaction(self, tx):
return self.call("dry_run_transaction", [tx])
Expand Down Expand Up @@ -183,16 +183,16 @@ def get_live_cell(self, index, tx_hash, with_data=True):
def submit_block(self, work_id, block):
return self.call("submit_block", [work_id, block])

def subscribe(self,topic):
return self.call("subscribe",[topic])
def subscribe(self, topic):
return self.call("subscribe", [topic])

def get_cells_capacity(self, script):
return self.call("get_cells_capacity", [script])

def get_current_epoch(self):
return self.call("get_current_epoch", [])

def call(self, method, params):
def call(self, method, params, try_count=15):

headers = {'content-type': 'application/json'}
data = {
Expand All @@ -202,7 +202,7 @@ def call(self, method, params):
"params": params
}
print(f"request:url:{self.url},data:\n{json.dumps(data)}")
for i in range(15):
for i in range(try_count):
try:
response = requests.post(self.url, data=json.dumps(data), headers=headers).json()
print(f"response:\n{json.dumps(response)}")
Expand Down
9 changes: 7 additions & 2 deletions framework/test_light_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ class CkbLightClientConfigPath(Enum):
V0_2_4 = ("source/template/ckb_light_client/0.2.4/testnet.toml.j2", "download/0.2.4/ckb-light-client")
V0_3_0 = ("source/template/ckb_light_client/0.3.0/testnet.toml.j2", "download/0.3.0/ckb-light-client")
V0_3_1 = ("source/template/ckb_light_client/0.3.0/testnet.toml.j2", "download/0.3.1/ckb-light-client")
CURRENT_TEST = ("source/template/ckb_light_client/0.3.0/testnet.toml.j2", "download/0.3.1/ckb-light-client")
V0_3_2 = ("source/template/ckb_light_client/0.3.0/testnet.toml.j2", "download/0.3.2/ckb-light-client")
V0_3_3 = ("source/template/ckb_light_client/0.3.0/testnet.toml.j2", "download/0.3.3/ckb-light-client")
V0_3_4 = ("source/template/ckb_light_client/0.3.0/testnet.toml.j2", "download/0.3.4/ckb-light-client")
V0_3_5 = ("source/template/ckb_light_client/0.3.0/testnet.toml.j2", "download/0.3.5/ckb-light-client")
CURRENT_TEST = ("source/template/ckb_light_client/0.3.0/testnet.toml.j2", "download/0.3.5/ckb-light-client")

def __init__(self, ckb_light_client_config_path, ckb_light_bin_path):
self.ckb_light_client_config_path = ckb_light_client_config_path
Expand All @@ -31,7 +35,8 @@ def __init__(self, ckb_light_client_config_path: CkbLightClientConfigPath, ckb_p
self.ckb_light_config = {
"ckb_light_client_chain": ckb_spec_path,
"ckb_light_client_network_bootnodes": ckb_p2p_infos,
"ckb_light_client_rpc_listen_address": f"127.0.0.1:{rpc_port}"
"ckb_light_client_rpc_listen_address": f"127.0.0.1:{rpc_port}",
"ckb_light_client_network_listen_addresses": [f"/ip4/0.0.0.0/tcp/1{rpc_port}"]
}
self.ckb_light_config_path = f"{self.tmp_path}/testnet.toml"
self.client = CKBLightRPCClient(f"http://127.0.0.1:{rpc_port}")
Expand Down
Loading
Loading