Skip to content

Commit 72f25e2

Browse files
committed
test: refactor: use Satoshis for fees in mempool_package_limits.py
This avoids having to convert from BTC to Sats and needs less imports. Also specify the tx's target size in vsize rather than in weight, which allows us to specify the fee-rate by a simple multiplication, rather than having another magic number for it.
1 parent b759cef commit 72f25e2

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

test/functional/mempool_package_limits.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,17 @@
33
# Distributed under the MIT software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Test logic for limiting mempool and package ancestors/descendants."""
6-
7-
from decimal import Decimal
8-
96
from test_framework.blocktools import COINBASE_MATURITY
10-
from test_framework.test_framework import BitcoinTestFramework
117
from test_framework.messages import (
12-
COIN,
138
WITNESS_SCALE_FACTOR,
149
)
10+
from test_framework.test_framework import BitcoinTestFramework
1511
from test_framework.util import (
1612
assert_equal,
1713
)
1814
from test_framework.wallet import MiniWallet
1915

16+
2017
class MempoolPackageLimitsTest(BitcoinTestFramework):
2118
def set_test_params(self):
2219
self.num_nodes = 1
@@ -304,8 +301,9 @@ def test_anc_size_limits(self):
304301
node = self.nodes[0]
305302
assert_equal(0, node.getmempoolinfo()["size"])
306303
parent_utxos = []
307-
target_weight = WITNESS_SCALE_FACTOR * 1000 * 30 # 30KvB
308-
high_fee = Decimal("0.003") # 10 sats/vB
304+
target_vsize = 30_000
305+
high_fee = 10 * target_vsize # 10 sats/vB
306+
target_weight = target_vsize * WITNESS_SCALE_FACTOR
309307
self.log.info("Check that in-mempool and in-package ancestor size limits are calculated properly in packages")
310308
# Mempool transactions A and B
311309
for _ in range(2):
@@ -314,7 +312,7 @@ def test_anc_size_limits(self):
314312
parent_utxos.append(bulked_tx["new_utxo"])
315313

316314
# Package transaction C
317-
pc_tx = self.wallet.create_self_transfer_multi(utxos_to_spend=parent_utxos, fee_per_output=int(high_fee * COIN), target_weight=target_weight)
315+
pc_tx = self.wallet.create_self_transfer_multi(utxos_to_spend=parent_utxos, fee_per_output=high_fee, target_weight=target_weight)
318316

319317
# Package transaction D
320318
pd_tx = self.wallet.create_self_transfer(utxo_to_spend=pc_tx["new_utxos"][0], target_weight=target_weight)
@@ -329,7 +327,7 @@ def test_anc_size_limits(self):
329327
assert all([res["allowed"] for res in node.testmempoolaccept(rawtxs=[pc_tx["hex"], pd_tx["hex"]])])
330328

331329
def test_desc_size_limits(self):
332-
"""Create 3 mempool transactions and 2 package transactions (25KvB each):
330+
"""Create 3 mempool transactions and 2 package transactions (21KvB each):
333331
Ma
334332
^ ^
335333
Mb Mc
@@ -340,11 +338,12 @@ def test_desc_size_limits(self):
340338
"""
341339
node = self.nodes[0]
342340
assert_equal(0, node.getmempoolinfo()["size"])
343-
target_weight = 21 * 1000 * WITNESS_SCALE_FACTOR
344-
high_fee = Decimal("0.0021") # 10 sats/vB
341+
target_vsize = 21_000
342+
high_fee = 10 * target_vsize # 10 sats/vB
343+
target_weight = target_vsize * WITNESS_SCALE_FACTOR
345344
self.log.info("Check that in-mempool and in-package descendant sizes are calculated properly in packages")
346345
# Top parent in mempool, Ma
347-
ma_tx = self.wallet.create_self_transfer_multi(num_outputs=2, fee_per_output=int(high_fee / 2 * COIN), target_weight=target_weight)
346+
ma_tx = self.wallet.create_self_transfer_multi(num_outputs=2, fee_per_output=high_fee // 2, target_weight=target_weight)
348347
self.wallet.sendrawtransaction(from_node=node, tx_hex=ma_tx["hex"])
349348

350349
package_hex = []
@@ -367,5 +366,6 @@ def test_desc_size_limits(self):
367366
self.generate(node, 1)
368367
assert all([res["allowed"] for res in node.testmempoolaccept(rawtxs=package_hex)])
369368

369+
370370
if __name__ == "__main__":
371371
MempoolPackageLimitsTest().main()

0 commit comments

Comments
 (0)