Skip to content

Commit c5ee0cc

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#21989: test: Use COINBASE_MATURITY in functional tests
bfa9309 Use COINBASE_MATURITY constant in functional tests. (Kiminuo) 525448d Move COINBASE_MATURITY from `feature_nulldummy` test to `blocktools`. (Kiminuo) Pull request description: `COINBASE_MATURITY` constant was added to `feature_nulldummy` test in #21373. This PR moves the constant to `blocktools.py` file and uses the constant in more tests as suggested [here](bitcoin/bitcoin#21373 (comment)). Edit: Goal of this PR is to replace integer constants with `COINBASE_MATURITY` but not necessarily in *all* cases because that would mean to read and fully understand all tests. That's out of my time constraints. Any reports where `COINBASE_MATURITY` should be used are welcome though! ACKs for top commit: theStack: ACK bfa9309 🌇 Tree-SHA512: 01f04645f05a39028681f355cf3d42dd63ea3303f76d93c430e0fdce441934358a2d847a54e6068d61932f1b75e1d406f51859b057b3e4b569f7083915cb317f
2 parents d7a6bba + bfa9309 commit c5ee0cc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+135
-68
lines changed

test/functional/feature_assumevalid.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"""
3232

3333
from test_framework.blocktools import (
34+
COINBASE_MATURITY,
3435
create_block,
3536
create_coinbase,
3637
)
@@ -161,8 +162,8 @@ def run_test(self):
161162

162163
# Send blocks to node0. Block 102 will be rejected.
163164
self.send_blocks_until_disconnected(p2p0)
164-
self.wait_until(lambda: self.nodes[0].getblockcount() >= 101)
165-
assert_equal(self.nodes[0].getblockcount(), 101)
165+
self.wait_until(lambda: self.nodes[0].getblockcount() >= COINBASE_MATURITY + 1)
166+
assert_equal(self.nodes[0].getblockcount(), COINBASE_MATURITY + 1)
166167

167168
# Send all blocks to node1. All blocks will be accepted.
168169
for i in range(2202):
@@ -173,8 +174,8 @@ def run_test(self):
173174

174175
# Send blocks to node2. Block 102 will be rejected.
175176
self.send_blocks_until_disconnected(p2p2)
176-
self.wait_until(lambda: self.nodes[2].getblockcount() >= 101)
177-
assert_equal(self.nodes[2].getblockcount(), 101)
177+
self.wait_until(lambda: self.nodes[2].getblockcount() >= COINBASE_MATURITY + 1)
178+
assert_equal(self.nodes[2].getblockcount(), COINBASE_MATURITY + 1)
178179

179180

180181
if __name__ == '__main__':

test/functional/feature_backwards_compatibility.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import os
2323
import shutil
2424

25+
from test_framework.blocktools import COINBASE_MATURITY
2526
from test_framework.test_framework import BitcoinTestFramework
2627
from test_framework.descriptors import descsum_create
2728

@@ -64,13 +65,13 @@ def setup_nodes(self):
6465
self.import_deterministic_coinbase_privkeys()
6566

6667
def run_test(self):
67-
self.nodes[0].generatetoaddress(101, self.nodes[0].getnewaddress())
68+
self.nodes[0].generatetoaddress(COINBASE_MATURITY + 1, self.nodes[0].getnewaddress())
6869

6970
self.sync_blocks()
7071

7172
# Sanity check the test framework:
7273
res = self.nodes[self.num_nodes - 1].getblockchaininfo()
73-
assert_equal(res['blocks'], 101)
74+
assert_equal(res['blocks'], COINBASE_MATURITY + 1)
7475

7576
node_master = self.nodes[self.num_nodes - 5]
7677
node_v19 = self.nodes[self.num_nodes - 4]

test/functional/feature_coinstatsindex.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from decimal import Decimal
1313

1414
from test_framework.blocktools import (
15+
COINBASE_MATURITY,
1516
create_block,
1617
create_coinbase,
1718
)
@@ -68,7 +69,7 @@ def _test_coin_stats_index(self):
6869
index_hash_options = ['none', 'muhash']
6970

7071
# Generate a normal transaction and mine it
71-
node.generate(101)
72+
node.generate(COINBASE_MATURITY + 1)
7273
address = self.nodes[0].get_deterministic_priv_key().address
7374
node.sendtoaddress(address=address, amount=10, subtractfeefromamount=True)
7475
node.generate(1)

test/functional/feature_loadblock.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import tempfile
1717
import urllib
1818

19+
from test_framework.blocktools import COINBASE_MATURITY
1920
from test_framework.test_framework import BitcoinTestFramework
2021
from test_framework.util import assert_equal
2122

@@ -28,7 +29,7 @@ def set_test_params(self):
2829

2930
def run_test(self):
3031
self.nodes[1].setnetworkactive(state=False)
31-
self.nodes[0].generate(100)
32+
self.nodes[0].generate(COINBASE_MATURITY)
3233

3334
# Parsing the url of our node to get settings for config file
3435
data_dir = self.nodes[0].datadir

test/functional/feature_nulldummy.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,18 @@
1414
"""
1515
import time
1616

17-
from test_framework.blocktools import NORMAL_GBT_REQUEST_PARAMS, create_block, create_transaction, add_witness_commitment
17+
from test_framework.blocktools import (
18+
COINBASE_MATURITY,
19+
NORMAL_GBT_REQUEST_PARAMS,
20+
add_witness_commitment,
21+
create_block,
22+
create_transaction,
23+
)
1824
from test_framework.messages import CTransaction
1925
from test_framework.script import CScript
2026
from test_framework.test_framework import BitcoinTestFramework
2127
from test_framework.util import assert_equal, assert_raises_rpc_error
2228

23-
COINBASE_MATURITY = 100
2429
NULLDUMMY_ERROR = "non-mandatory-script-verify-flag (Dummy CHECKMULTISIG argument must be zero)"
2530

2631
def trueDummy(tx):

test/functional/feature_rbf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from decimal import Decimal
88

9+
from test_framework.blocktools import COINBASE_MATURITY
910
from test_framework.messages import COIN, COutPoint, CTransaction, CTxIn, CTxOut
1011
from test_framework.script import CScript, OP_DROP
1112
from test_framework.test_framework import BitcoinTestFramework
@@ -27,7 +28,7 @@ def make_utxo(node, amount, confirmed=True, scriptPubKey=DUMMY_P2WPKH_SCRIPT):
2728
"""
2829
fee = 1*COIN
2930
while node.getbalance() < satoshi_round((amount + fee)/COIN):
30-
node.generate(100)
31+
node.generate(COINBASE_MATURITY)
3132

3233
new_addr = node.getnewaddress()
3334
txid = node.sendtoaddress(new_addr, satoshi_round((amount+fee)/COIN))

test/functional/feature_taproot.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# Test Taproot softfork (BIPs 340-342)
66

77
from test_framework.blocktools import (
8+
COINBASE_MATURITY,
89
create_coinbase,
910
create_block,
1011
add_witness_commitment,
@@ -1440,7 +1441,7 @@ def test_spenders(self, node, spenders, input_counts):
14401441
def run_test(self):
14411442
# Post-taproot activation tests go first (pre-taproot tests' blocks are invalid post-taproot).
14421443
self.log.info("Post-activation tests...")
1443-
self.nodes[1].generate(101)
1444+
self.nodes[1].generate(COINBASE_MATURITY + 1)
14441445
self.test_spenders(self.nodes[1], spenders_taproot_active(), input_counts=[1, 2, 2, 2, 2, 3])
14451446

14461447
# Re-connect nodes in case they have been disconnected

test/functional/interface_bitcoin_cli.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
"""Test bitcoin-cli"""
66

77
from decimal import Decimal
8+
9+
from test_framework.blocktools import COINBASE_MATURITY
810
from test_framework.test_framework import BitcoinTestFramework
911
from test_framework.util import (
1012
assert_equal,
@@ -16,7 +18,7 @@
1618
# The block reward of coinbaseoutput.nValue (50) BTC/block matures after
1719
# COINBASE_MATURITY (100) blocks. Therefore, after mining 101 blocks we expect
1820
# node 0 to have a balance of (BLOCKS - COINBASE_MATURITY) * 50 BTC/block.
19-
BLOCKS = 101
21+
BLOCKS = COINBASE_MATURITY + 1
2022
BALANCE = (BLOCKS - 100) * 50
2123

2224
JSON_PARSING_ERROR = 'error: Error parsing JSON: foo'

test/functional/mempool_compatibility.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import os
1717

18+
from test_framework.blocktools import COINBASE_MATURITY
1819
from test_framework.test_framework import BitcoinTestFramework
1920
from test_framework.wallet import MiniWallet
2021

@@ -41,7 +42,7 @@ def run_test(self):
4142
old_node, new_node = self.nodes
4243
new_wallet = MiniWallet(new_node)
4344
new_wallet.generate(1)
44-
new_node.generate(100)
45+
new_node.generate(COINBASE_MATURITY)
4546
# Sync the nodes to ensure old_node has the block that contains the coinbase that new_wallet will spend.
4647
# Otherwise, because coinbases are only valid in a block and not as loose txns, if the nodes aren't synced
4748
# unbroadcasted_tx won't pass old_node's `MemPoolAccept::PreChecks`.

test/functional/mempool_expiry.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
from datetime import timedelta
1414

15+
from test_framework.blocktools import COINBASE_MATURITY
1516
from test_framework.test_framework import BitcoinTestFramework
1617
from test_framework.util import (
1718
assert_equal,
@@ -36,7 +37,7 @@ def test_transaction_expiry(self, timeout):
3637

3738
# Add enough mature utxos to the wallet so that all txs spend confirmed coins.
3839
self.wallet.generate(4)
39-
node.generate(100)
40+
node.generate(COINBASE_MATURITY)
4041

4142
# Send a parent transaction that will expire.
4243
parent_txid = self.wallet.send_self_transfer(from_node=node)['txid']

0 commit comments

Comments
 (0)