Skip to content

Commit

Permalink
Merge pull request #56 from cryptape/x/tx_index
Browse files Browse the repository at this point in the history
X/tx index
  • Loading branch information
15168316096 authored Aug 14, 2024
2 parents 6ac9cbe + 62a4f5e commit 65e2dbc
Show file tree
Hide file tree
Showing 94 changed files with 103 additions and 89 deletions.
4 changes: 1 addition & 3 deletions framework/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@

# contract
ALWAYS_SUCCESS_CONTRACT_PATH = f"{get_project_root()}/source/contract/always_success"
SPAWN_CONTRACT_PATH = (
f"{get_project_root()}/source/contract/spawn_peak_memory_2m_to_32m"
)
SPAWN_CONTRACT_PATH = f"{get_project_root()}/source/contract/test_cases/spawn_demo"


def get_tmp_path():
Expand Down
6 changes: 6 additions & 0 deletions prepare.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
set -e
# git clone https://github.com/nervosnetwork/ckb-cli.git
# cd ckb-cli
# git checkout pkg/v1.7.0
# make prod
# cp target/release/ckb-cli ../source/ckb-cli
# cd ../
cp download/0.110.2/ckb-cli ./source/ckb-cli-old
cp download/0.117.0/ckb-cli ./source/ckb-cli
#git clone https://github.com/quake/ckb-light-client.git
Expand Down
Binary file removed source/contract/spawn_peak_memory_2m_to_32m
Binary file not shown.
Binary file modified source/contract/test_cases/always_success
Binary file not shown.
Binary file modified source/contract/test_cases/atomic_i16
Binary file not shown.
Binary file modified source/contract/test_cases/atomic_i32
Binary file not shown.
Binary file modified source/contract/test_cases/atomic_i64
Binary file not shown.
Binary file modified source/contract/test_cases/atomic_i8
Binary file not shown.
Binary file modified source/contract/test_cases/atomic_isize
Binary file not shown.
Binary file modified source/contract/test_cases/atomic_ptr
Binary file not shown.
Binary file modified source/contract/test_cases/atomic_u16
Binary file not shown.
Binary file modified source/contract/test_cases/atomic_u32
Binary file not shown.
Binary file modified source/contract/test_cases/atomic_u64
Binary file not shown.
Binary file modified source/contract/test_cases/atomic_u8
Binary file not shown.
Binary file modified source/contract/test_cases/atomic_usize
Binary file not shown.
Binary file removed source/contract/test_cases/ckb_get_memory_limit
Binary file not shown.
Binary file not shown.
Binary file added source/contract/test_cases/ckb_load_cell_data
Binary file not shown.
Binary file added source/contract/test_cases/ckb_pipe
Binary file not shown.
Binary file added source/contract/test_cases/ckb_process_id_in_exec
Binary file not shown.
Binary file not shown.
Binary file added source/contract/test_cases/ckb_spawn_for
Binary file not shown.
Binary file added source/contract/test_cases/demo
Binary file not shown.
Binary file added source/contract/test_cases/exec
Binary file not shown.
Binary file added source/contract/test_cases/exec_with_block_opcode
Binary file not shown.
Binary file added source/contract/test_cases/exec_with_exec
Binary file not shown.
Binary file modified source/contract/test_cases/load_block_extension
Binary file not shown.
Binary file modified source/contract/test_cases/loop_contract
Binary file not shown.
Binary file added source/contract/test_cases/pipe_reader
Binary file not shown.
Binary file modified source/contract/test_cases/rfc49_atomic
Binary file not shown.
Binary file removed source/contract/test_cases/set_content
Binary file not shown.
Binary file not shown.
Binary file removed source/contract/test_cases/set_content_exceed_length
Binary file not shown.
Binary file not shown.
Binary file removed source/contract/test_cases/set_content_many_times
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed source/contract/test_cases/set_content_without_spawn
Binary file not shown.
Binary file added source/contract/test_cases/spawn-caller
Binary file not shown.
Binary file added source/contract/test_cases/spawn_16_run_same_time
Binary file not shown.
Binary file added source/contract/test_cases/spawn_argc_is_large
Binary file not shown.
Binary file removed source/contract/test_cases/spawn_argc_is_u64_max
Binary file not shown.
Binary file removed source/contract/test_cases/spawn_argc_not_eq
Binary file not shown.
Binary file removed source/contract/test_cases/spawn_argv
Binary file not shown.
Binary file added source/contract/test_cases/spawn_bounds_is_not_0
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed source/contract/test_cases/spawn_content
Binary file not shown.
Binary file added source/contract/test_cases/spawn_create_17_spawn
Binary file not shown.
Binary file removed source/contract/test_cases/spawn_current_cycles
Binary file not shown.
Binary file removed source/contract/test_cases/spawn_current_memory
Binary file not shown.
Binary file not shown.
Binary file modified source/contract/test_cases/spawn_demo
Binary file not shown.
Binary file added source/contract/test_cases/spawn_demo_debug
Binary file not shown.
Binary file removed source/contract/test_cases/spawn_elf_format_error
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed source/contract/test_cases/spawn_exec_set_content
Binary file not shown.
Binary file removed source/contract/test_cases/spawn_exec_spawn
Binary file not shown.
Binary file removed source/contract/test_cases/spawn_fib
Binary file not shown.
Binary file removed source/contract/test_cases/spawn_index
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added source/contract/test_cases/spawn_invaild_index
Binary file not shown.
Binary file not shown.
Binary file added source/contract/test_cases/spawn_loop_times
Binary file not shown.
Binary file added source/contract/test_cases/spawn_loop_times_max
Binary file not shown.
Binary file removed source/contract/test_cases/spawn_out_of_memory
Binary file not shown.
Binary file not shown.
Binary file added source/contract/test_cases/spawn_place_is_witness
Binary file not shown.
Binary file removed source/contract/test_cases/spawn_query
Binary file not shown.
Binary file added source/contract/test_cases/spawn_recursion_times
Binary file not shown.
Binary file removed source/contract/test_cases/spawn_recursive
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed source/contract/test_cases/spawn_times
Binary file not shown.
Binary file added source/contract/test_cases/spawn_with_exec
Binary file not shown.
Binary file removed source/contract/test_cases/spawn_wrong_memory_limit
Binary file not shown.
4 changes: 2 additions & 2 deletions test_cases/ckb2023/test_01_before_hardfork.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def test_06_0050_invoke_spawn_use_type(self):
"""
Before the fork, send a transaction contains spawn , use script:type invoke it. will return error
1. invoke spawn contrat
- return error: InvalidEcall(2101)
- return error: InvalidEcall(2603)
:return:
"""

Expand All @@ -200,7 +200,7 @@ def test_06_0050_invoke_spawn_use_type(self):
api_url=self.cluster.ckb_nodes[0].getClient().url,
)
print("tx hash :", tx_hash)
expected_error_message = "InvalidEcall(2101)"
expected_error_message = "InvalidEcall(2603)"
assert expected_error_message in exc_info.value.args[0], (
f"Expected substring '{expected_error_message}' "
f"not found in actual string '{exc_info.value.args[0]}'"
Expand Down
10 changes: 5 additions & 5 deletions test_cases/ckb2023/test_02_after_hardfork.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,10 @@ def test_07_0050_spawn_use_data2(self):
def test_08_0050_spawn_use_data1(self):
"""
After a period of hard fork,send spawn tx by data1 .
- return Error: InvalidEcall(2101)
- return Error: InvalidEcall(2603)
1. send tx contains spawn opcode use data1
- return Error: InvalidEcall(2101)
- return Error: InvalidEcall(2603)
:return:
"""

Expand All @@ -260,7 +260,7 @@ def test_08_0050_spawn_use_data1(self):
invoke_data,
api_url=self.cluster.ckb_nodes[0].getClient().url,
)
expected_error_message = "InvalidEcall(2101)"
expected_error_message = "InvalidEcall(2603)"
assert (
expected_error_message in exc_info.value.args[0]
), f"Expected substring '{expected_error_message}' not found in actual string '{exc_info.value.args[0]}'"
Expand All @@ -271,7 +271,7 @@ def test_09_0050_spawn_use_data(self):
- return Error: InvalidInstruction
1. send tx contains spawn opcode use data
- return Error: InvalidEcall(2101)
- return Error: MemWriteOnExecutablePage
:return:
"""

Expand All @@ -288,7 +288,7 @@ def test_09_0050_spawn_use_data(self):
invoke_data,
api_url=self.cluster.ckb_nodes[0].getClient().url,
)
expected_error_message = "InvalidInstruction"
expected_error_message = "MemWriteOnExecutablePage"
assert (
expected_error_message in exc_info.value.args[0]
), f"Expected substring '{expected_error_message}' not found in actual string '{exc_info.value.args[0]}'"
Expand Down
2 changes: 2 additions & 0 deletions test_cases/ckb2023/test_03_ckb_light_client_after_hardfork.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ def test_04_ckb_light_client_current_transfer_data2_tx(self):
)
assert tx_hash == light_tx_hash

@pytest.mark.skip
def test_05_ckb_light_client_current_spawn_contract_use_data2(self):
"""
send spawn tx ( hash type : data2), on the ckb light client
Expand Down Expand Up @@ -317,6 +318,7 @@ def test_05_ckb_light_client_current_spawn_contract_use_data2(self):

assert tx_hash == light_tx_hash

@pytest.mark.skip
def test_05_ckb_light_client_current_spawn_contract_use_type(self):
"""
1. send spawn tx ( hash type : type), on the ckb light client
Expand Down
3 changes: 3 additions & 0 deletions test_cases/ckb_cli/test_sync_state_by_ckbcli.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import pytest

from framework.basic import CkbTest


Expand Down Expand Up @@ -32,6 +34,7 @@ def teardown_class(cls):
cls.node.stop()
cls.node.clean()

@pytest.mark.skip
def test_01_sync_state(self):
"""
#1.The assume_valid_target specified by ckb, if no assume_valid_target, this will be all zero.
Expand Down
93 changes: 18 additions & 75 deletions test_cases/contracts/test_01_contract.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import json
import os
import time

import pytest
from parameterized import parameterized

from framework.basic import CkbTest
Expand All @@ -21,12 +19,16 @@ def get_all_files(directory):
def get_successful_files():
files = get_all_files(f"{get_project_root()}/source/contract/test_cases")
files_list = [
"spawn_exceeded_max_content_length",
"spawn_cycle_inc_when_contains_recursion_and_loop_spawn",
"spawn_source_is_input_cell",
"spawn_loop_times",
"spawn_source_is_output_cell",
"spawn_recursion_times",
"ckb_pipe",
"spawn_argc_is_large",
"spawn_place_is_witness",
"loop_contract",
"spawn_exec_memory_limit_le_7",
"spawn_argc_not_eq",
"spawn_argc_is_u64_max",
"spawn_out_of_memory",
"exec_with_block_opcode",
]
return [s for s in files if not any(s.endswith(suffix) for suffix in files_list)]

Expand All @@ -36,12 +38,16 @@ def get_failed_files():
files = get_all_files(f"{get_project_root()}/source/contract/test_cases")

files_list = [
"spawn_exceeded_max_content_length",
"spawn_cycle_inc_when_contains_recursion_and_loop_spawn",
"spawn_source_is_input_cell",
"spawn_loop_times",
"spawn_source_is_output_cell",
"spawn_recursion_times",
"ckb_pipe",
"spawn_argc_is_large",
"spawn_place_is_witness",
"loop_contract",
"spawn_exec_memory_limit_le_7",
"spawn_argc_not_eq",
"spawn_argc_is_u64_max",
"spawn_out_of_memory",
"exec_with_block_opcode",
]
# return [s for s in files if not any(s.endswith(suffix) for suffix in files_list)]
return [f"{project_root}/source/contract/test_cases/{x}" for x in files_list]
Expand Down Expand Up @@ -87,69 +93,6 @@ def test_02_deploy_and_invoke_demo_failed(self, path):
except Exception as e:
print(e)

def test_03_stack_overflow(self):
"""
contract link:
https://github.com/gpBlockchain/ckb-test-contracts/blob/main/rust/acceptance-contracts/contracts/spawn_demo/src/spawn_recursive.rs
:return:
"""
self.deploy_and_invoke(
self.Config.MINER_PRIVATE_1,
f"{get_project_root()}/source/contract/test_cases/spawn_recursive",
self.node,
)

# @pytest.mark.skip
def test_04_estimate_cycles_bug(self):
"""
https://github.com/gpBlockchain/ckb-test-contracts/blob/main/rust/acceptance-contracts/contracts/spawn_demo/src/spawn_times.rs
send_transaction( big cycle tx )
return tx;
query tx status
return tx_status == rejected
if status == pending ,is bug
query estimate_cycles
return : ExceededMaximumCycles
if return cycles > 1045122714,is bug
:return:
"""
deploy_hash = self.Contract.deploy_ckb_contract(
self.Config.MINER_PRIVATE_1,
f"{get_project_root()}/source/contract/test_cases/spawn_times",
enable_type_id=True,
api_url=self.node.getClient().url,
)
self.Miner.miner_until_tx_committed(self.node, deploy_hash)
for i in range(1, 10):
invoke_hash = self.Contract.invoke_ckb_contract(
account_private=self.Config.MINER_PRIVATE_1,
contract_out_point_tx_hash=deploy_hash,
contract_out_point_tx_index=0,
type_script_arg="0x02",
data=f"0x{i:02x}",
hash_type="type",
api_url=self.node.getClient().url,
)
time.sleep(5)
transaction = self.node.getClient().get_transaction(invoke_hash)
# if transaction["tx_status"]['status'] == ""
if transaction["tx_status"]["status"] == "rejected":
continue
if transaction["tx_status"]["status"] == "pending":
# bug
# es cycle
del transaction["transaction"]["hash"]
with open("./tmp.json", "w") as tmp_file:
tmp_file.write(json.dumps(transaction["transaction"]))
for i in range(5):
try:
result = self.Ckb_cli.estimate_cycles(
"./tmp.json", api_url=self.node.getClient().url
)
print(f"estimate_cycles:{result}")
except Exception:
pass

def deploy_and_invoke(self, account, path, node, try_count=5):
if try_count < 0:
raise Exception("try out of times")
Expand Down
62 changes: 62 additions & 0 deletions test_cases/feature/test_get_transaction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from framework.basic import CkbTest
import pytest


class TestGetTransaction(CkbTest):

@classmethod
def setup_class(cls):
"""
1. start 1 ckb node in tmp/get_transaction/node1 node dir
2. miner 100block
Returns:
"""
# 1. start 1 ckb node in tmp/get_transaction/node1 node dir
cls.node = cls.CkbNode.init_dev_by_port(
cls.CkbNodeConfigPath.develop, "get_transaction/node1", 8120, 8225
)
cls.node.prepare(other_ckb_config={"ckb_tx_pool_max_tx_pool_size": "180_000"})
cls.node.start()
# 2. miner 100 block
cls.Miner.make_tip_height_number(cls.node, 100)

@classmethod
def teardown_class(cls):
"""
1. stop ckb node
2. clean ckb node tmp dir
Returns:
"""
cls.node.stop()
cls.node.clean()

# @pytest.mark.skip("util v118 rc")
def test_get_transaction_by_tx_index(self):
"""
1. new tx in block
2. query tx index is null
3. miner block until tx committed, query tx index is 0x1
Returns:
"""
# 1. new tx in block
account = self.Ckb_cli.util_key_info_by_private_key(self.Config.MINER_PRIVATE_1)
tx_hash = self.Ckb_cli.wallet_transfer_by_private_key(
self.Config.MINER_PRIVATE_1,
account["address"]["testnet"],
100,
self.node.getClient().url,
"1500",
)
print(f"txHash:{tx_hash}")
# 2. query tx index is null
transaction1 = self.node.getClient().get_transaction(tx_hash)
print(f"tx_index:{transaction1['tx_status']['tx_index']}")
assert transaction1["tx_status"]["tx_index"] is None
# 3. miner block until tx committed, query tx index is 0x1
self.Miner.miner_until_tx_committed(self.node, tx_hash)
transaction2 = self.node.getClient().get_transaction(tx_hash)
print(f"after miner tx_hash, tx_index:{transaction2['tx_status']['tx_index']}")
assert transaction2["tx_status"]["tx_index"] == "0x1"
8 changes: 4 additions & 4 deletions test_cases/node_compatible/test_before_ckb2023_hardfork.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ def test_03_transfer(self, version, node):
def test_04_spawn_tx(self, version, node):
"""
1. send spawn tx by data1 .
- return Error: InvalidEcall(2101)
- return Error: InvalidEcall(2603)
2. send spawn tx by type .
- return Error: InvalidEcall(2101)
- return Error: InvalidEcall(2603)
:param version:
:param node:
:return:
Expand All @@ -140,7 +140,7 @@ def test_04_spawn_tx(self, version, node):
invoke_data,
api_url=node.getClient().url,
)
expected_error_message = "InvalidEcall(2101)"
expected_error_message = "InvalidEcall(2603)"
assert (
expected_error_message in exc_info.value.args[0]
), f"Expected substring '{expected_error_message}' not found in actual string '{exc_info.value.args[0]}'"
Expand All @@ -156,7 +156,7 @@ def test_04_spawn_tx(self, version, node):
invoke_data,
api_url=node.getClient().url,
)
expected_error_message = "InvalidEcall(2101)"
expected_error_message = "InvalidEcall(2603)"
assert (
expected_error_message in exc_info.value.args[0]
), f"Expected substring '{expected_error_message}' not found in actual string '{exc_info.value.args[0]}'"

0 comments on commit 65e2dbc

Please sign in to comment.