Skip to content

Commit

Permalink
feat: add transaction (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
gpBlockchain authored Jun 28, 2023
1 parent 1cef6a7 commit 6a76ee9
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 0 deletions.
Empty file added test_cases/__init__.py
Empty file.
Empty file added test_cases/rpc/__init__.py
Empty file.
81 changes: 81 additions & 0 deletions test_cases/rpc/get_transaction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import time

from framework.config import ACCOUNT_PRIVATE_1
from framework.helper.ckb_cli import wallet_transfer_by_private_key, util_key_info_by_private_key
from framework.helper.miner import miner_with_version, miner_until_tx_committed
from test_cases.rpc.node_fixture import get_cluster


class TestGetTransaction:

def test_query_tx_only_commit_is_true(self, get_cluster):
"""
pending tx
- enable committed: tx_status = uni
- not enable committed : tx_status = pending
proposed tx
- enable committed: tx_status = unknown
- not enable committed : tx_status = proposed
committed tx
- enable committed: tx_status = committed
- not enable committed : tx_status = committed
:return:
"""
cluster = get_cluster
account1 = util_key_info_by_private_key(ACCOUNT_PRIVATE_1)
tx_hash = wallet_transfer_by_private_key(ACCOUNT_PRIVATE_1,
account1["address"]["testnet"],
140,
cluster.ckb_nodes[0].client.url)

# pending tx
response_enable_commit = cluster.ckb_nodes[0].getClient().get_transaction(tx_hash, None, True)
response = cluster.ckb_nodes[0].getClient().get_transaction(tx_hash, None, False)
assert response['tx_status']['status'] == "pending"
assert response_enable_commit['tx_status']['status'] == "unknown"

# proposed tx
for i in range(100):
response = cluster.ckb_nodes[0].getClient().get_transaction(tx_hash, None, False)
if response['tx_status']['status'] == "proposed":
break
miner_with_version(cluster.ckb_nodes[0], "0x0")
time.sleep(1)
response_enable_commit = cluster.ckb_nodes[0].getClient().get_transaction(tx_hash, None, True)
response = cluster.ckb_nodes[0].getClient().get_transaction(tx_hash, None, False)
assert response['tx_status']['status'] == "proposed"
assert response_enable_commit['tx_status']['status'] == "unknown"

# committed tx
for i in range(100):
response = cluster.ckb_nodes[0].getClient().get_transaction(tx_hash, None, False)
if response['tx_status']['status'] == "committed":
break
miner_with_version(cluster.ckb_nodes[0], "0x0")
time.sleep(1)
response_enable_commit = cluster.ckb_nodes[0].getClient().get_transaction(tx_hash, None, True)
response = cluster.ckb_nodes[0].getClient().get_transaction(tx_hash, None, True)
assert response_enable_commit['tx_status']['status'] == "committed"
assert response['tx_status']['status'] == "committed"

def test_query_tx_without_only_commit(self, get_cluster):
"""
only_commit is None
- use default only_commit = False
:return:
"""
cluster = get_cluster
account1 = util_key_info_by_private_key(ACCOUNT_PRIVATE_1)
tx_hash = wallet_transfer_by_private_key(ACCOUNT_PRIVATE_1,
account1["address"]["testnet"],
140,
cluster.ckb_nodes[0].client.url)

# pending tx
response_use_default = cluster.ckb_nodes[0].getClient().get_transaction(tx_hash)
response = cluster.ckb_nodes[0].getClient().get_transaction(tx_hash, None, False)
assert response['tx_status']['status'] == "pending"
assert response_use_default['tx_status']['status'] == "pending"
miner_until_tx_committed(cluster.ckb_nodes[0], tx_hash)
31 changes: 31 additions & 0 deletions test_cases/rpc/node_fixture.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import os

import pytest

from framework.helper.miner import make_tip_height_number
from framework.helper.node import wait_cluster_height
from framework.test_cluster import Cluster
from framework.test_node import CkbNode, CkbNodeConfigPath
from framework.util import get_project_root

@pytest.fixture(scope='module')
def get_cluster():
nodes = [
CkbNode.init_dev_by_port(CkbNodeConfigPath.CURRENT_TEST, "cluster/hardfork/node{i}".format(i=i), 8114 + i,
8225 + i)
for
i in range(1, 5)
]

cluster = Cluster(nodes)
cluster.prepare_all_nodes()
cluster.start_all_nodes()
cluster.connected_all_nodes()
cluster.ckb_nodes[0].start_miner()
make_tip_height_number(cluster.ckb_nodes[0], 1100)
wait_cluster_height(cluster, 1100, 100)

yield cluster
print("\nTeardown TestClass1")
cluster.stop_all_nodes()
cluster.clean_all_nodes()

0 comments on commit 6a76ee9

Please sign in to comment.