Skip to content

Commit

Permalink
support tx index in tx status
Browse files Browse the repository at this point in the history
  • Loading branch information
15168316096 committed Aug 14, 2024
1 parent 7609f17 commit 2bd8724
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 0 deletions.
7 changes: 7 additions & 0 deletions framework/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ class CkbNodeConfigPath(Enum):
"download/0.117.0",
)

develop = (
"source/template/ckb/v117/ckb.toml.j2",
"source/template/ckb/v117/ckb-miner.toml.j2",
"source/template/ckb/v117/specs/dev.toml",
"download/develop/ckb/target/prod",
)

v117 = (
"source/template/ckb/v117/ckb.toml.j2",
"source/template/ckb/v117/ckb-miner.toml.j2",
Expand Down
1 change: 1 addition & 0 deletions prepare.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
set -e
cp download/0.110.2/ckb-cli ./source/ckb-cli-old
cp download/0.117.0/ckb-cli ./source/ckb-cli
#cp ckb-cli/target/release/ckb-cli download/develop/ckb/target/prod/
#git clone https://github.com/quake/ckb-light-client.git
#cd ckb-light-client
#git checkout quake/fix-set-scripts-partial-bug
Expand Down
16 changes: 16 additions & 0 deletions prepare_ckb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
set -e

BRANCH="develop"
BASE_DIR="download/${BRANCH}/"
REPO_URL="https://github.com/nervosnetwork/ckb.git"

if [ ! -d "$BASE_DIR" ]; then
mkdir -p "$BASE_DIR"
fi

cd "$BASE_DIR"
git clone -b $BRANCH $REPO_URL

cd ckb/
make prod
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"

0 comments on commit 2bd8724

Please sign in to comment.