Skip to content

Commit 940edd6

Browse files
committed
test: refactor: introduce and use TRUC_CHILD_MAX_VSIZE constant
1 parent c16ae71 commit 940edd6

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

test/functional/mempool_truc.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
MAX_REPLACEMENT_CANDIDATES = 100
2424
TRUC_MAX_VSIZE = 10000
25+
TRUC_CHILD_MAX_VSIZE = 1000
2526

2627
def cleanup(extra_args=None):
2728
def decorator(func):
@@ -72,10 +73,10 @@ def test_truc_acceptance(self):
7273
self.check_mempool([tx_v3_parent_normal["txid"]])
7374
tx_v3_child_heavy = self.wallet.create_self_transfer(
7475
utxo_to_spend=tx_v3_parent_normal["new_utxo"],
75-
target_vsize=1001,
76+
target_vsize=TRUC_CHILD_MAX_VSIZE + 1,
7677
version=3
7778
)
78-
assert_greater_than_or_equal(tx_v3_child_heavy["tx"].get_vsize(), 1000)
79+
assert_greater_than_or_equal(tx_v3_child_heavy["tx"].get_vsize(), TRUC_CHILD_MAX_VSIZE)
7980
expected_error_child_heavy = f"TRUC-violation, version=3 child tx {tx_v3_child_heavy['txid']} (wtxid={tx_v3_child_heavy['wtxid']}) is too big"
8081
assert_raises_rpc_error(-26, expected_error_child_heavy, node.sendrawtransaction, tx_v3_child_heavy["hex"])
8182
self.check_mempool([tx_v3_parent_normal["txid"]])
@@ -87,10 +88,10 @@ def test_truc_acceptance(self):
8788
from_node=node,
8889
fee_rate=DEFAULT_FEE,
8990
utxo_to_spend=tx_v3_parent_normal["new_utxo"],
90-
target_vsize=997,
91+
target_vsize=TRUC_CHILD_MAX_VSIZE - 3,
9192
version=3
9293
)
93-
assert_greater_than_or_equal(1000, tx_v3_child_almost_heavy["tx"].get_vsize())
94+
assert_greater_than_or_equal(TRUC_CHILD_MAX_VSIZE, tx_v3_child_almost_heavy["tx"].get_vsize())
9495
self.check_mempool([tx_v3_parent_normal["txid"], tx_v3_child_almost_heavy["txid"]])
9596
assert_equal(node.getmempoolentry(tx_v3_parent_normal["txid"])["descendantcount"], 2)
9697
tx_v3_child_almost_heavy_rbf = self.wallet.send_self_transfer(
@@ -100,7 +101,8 @@ def test_truc_acceptance(self):
100101
target_vsize=875,
101102
version=3
102103
)
103-
assert_greater_than_or_equal(tx_v3_child_almost_heavy["tx"].get_vsize() + tx_v3_child_almost_heavy_rbf["tx"].get_vsize(), 1000)
104+
assert_greater_than_or_equal(tx_v3_child_almost_heavy["tx"].get_vsize() + tx_v3_child_almost_heavy_rbf["tx"].get_vsize(),
105+
TRUC_CHILD_MAX_VSIZE)
104106
self.check_mempool([tx_v3_parent_normal["txid"], tx_v3_child_almost_heavy_rbf["txid"]])
105107
assert_equal(node.getmempoolentry(tx_v3_parent_normal["txid"])["descendantcount"], 2)
106108

@@ -199,7 +201,7 @@ def test_truc_reorg(self):
199201
tx_v2_from_v3 = self.wallet.send_self_transfer(from_node=node, utxo_to_spend=tx_v3_block["new_utxo"], version=2)
200202
tx_v3_from_v2 = self.wallet.send_self_transfer(from_node=node, utxo_to_spend=tx_v2_block["new_utxo"], version=3)
201203
tx_v3_child_large = self.wallet.send_self_transfer(from_node=node, utxo_to_spend=tx_v3_block2["new_utxo"], target_vsize=1250, version=3)
202-
assert_greater_than(node.getmempoolentry(tx_v3_child_large["txid"])["vsize"], 1000)
204+
assert_greater_than(node.getmempoolentry(tx_v3_child_large["txid"])["vsize"], TRUC_CHILD_MAX_VSIZE)
203205
self.check_mempool([tx_v2_from_v3["txid"], tx_v3_from_v2["txid"], tx_v3_child_large["txid"]])
204206
node.invalidateblock(block[0])
205207
self.check_mempool([tx_v3_block["txid"], tx_v2_block["txid"], tx_v3_block2["txid"], tx_v2_from_v3["txid"], tx_v3_from_v2["txid"], tx_v3_child_large["txid"]])
@@ -231,7 +233,7 @@ def test_nondefault_package_limits(self):
231233

232234
# Parent and child are within v3 limits, but parent's 10kvB descendant limit is exceeded
233235
assert_greater_than_or_equal(TRUC_MAX_VSIZE, tx_v3_parent_large1["tx"].get_vsize())
234-
assert_greater_than_or_equal(1000, tx_v3_child_large1["tx"].get_vsize())
236+
assert_greater_than_or_equal(TRUC_CHILD_MAX_VSIZE, tx_v3_child_large1["tx"].get_vsize())
235237
assert_greater_than(tx_v3_parent_large1["tx"].get_vsize() + tx_v3_child_large1["tx"].get_vsize(), 10000)
236238

237239
assert_raises_rpc_error(-26, f"too-long-mempool-chain, exceeds descendant size limit for tx {tx_v3_parent_large1['txid']}", node.sendrawtransaction, tx_v3_child_large1["hex"])
@@ -254,7 +256,7 @@ def test_nondefault_package_limits(self):
254256

255257
# Parent and child are within TRUC limits
256258
assert_greater_than_or_equal(TRUC_MAX_VSIZE, tx_v3_parent_large2["tx"].get_vsize())
257-
assert_greater_than_or_equal(1000, tx_v3_child_large2["tx"].get_vsize())
259+
assert_greater_than_or_equal(TRUC_CHILD_MAX_VSIZE, tx_v3_child_large2["tx"].get_vsize())
258260
assert_greater_than(tx_v3_parent_large2["tx"].get_vsize() + tx_v3_child_large2["tx"].get_vsize(), 10000)
259261

260262
assert_raises_rpc_error(-26, f"too-long-mempool-chain, exceeds ancestor size limit", node.sendrawtransaction, tx_v3_child_large2["hex"])
@@ -281,7 +283,7 @@ def test_truc_ancestors_package(self):
281283
)
282284
tx_v3_child_heavy = self.wallet.create_self_transfer_multi(
283285
utxos_to_spend=[tx_v3_parent_normal["new_utxo"]],
284-
target_vsize=1001,
286+
target_vsize=TRUC_CHILD_MAX_VSIZE + 1,
285287
fee_per_output=10000,
286288
version=3
287289
)

0 commit comments

Comments
 (0)