From 8db2aabee06da3a67c9d815024cc326ff4d2b943 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Mon, 31 May 2021 11:26:16 +0200 Subject: [PATCH] Merge bitcoin/bitcoin#21989: test: Use COINBASE_MATURITY in functional tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit bfa9309ad606102f24c9bd3c33dfe78949f09418 Use COINBASE_MATURITY constant in functional tests. (Kiminuo) 525448df9dc2ab6b7e960ff138956ae3e2efdf60 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](https://github.com/bitcoin/bitcoin/pull/21373#discussion_r605418462). 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 bfa9309ad606102f24c9bd3c33dfe78949f09418 🌇 Tree-SHA512: 01f04645f05a39028681f355cf3d42dd63ea3303f76d93c430e0fdce441934358a2d847a54e6068d61932f1b75e1d406f51859b057b3e4b569f7083915cb317f --- test/functional/feature_assumevalid.py | 6 +++--- test/functional/feature_loadblock.py | 3 ++- test/functional/interface_bitcoin_cli.py | 4 +++- test/functional/mempool_package_onemore.py | 3 ++- test/functional/mempool_packages.py | 3 ++- test/functional/mempool_reorg.py | 7 +++++-- test/functional/p2p_compactblocks.py | 8 ++++---- test/functional/p2p_eviction.py | 4 ++-- test/functional/rpc_dumptxoutset.py | 4 +++- test/functional/rpc_getblockstats.py | 4 +++- test/functional/rpc_rawtransaction.py | 4 +++- test/functional/rpc_txoutproof.py | 3 ++- test/functional/test_framework/blocktools.py | 3 +++ test/functional/wallet_abandonconflict.py | 3 ++- test/functional/wallet_backup.py | 5 +++-- test/functional/wallet_balance.py | 3 ++- test/functional/wallet_basic.py | 5 +++-- test/functional/wallet_fallbackfee.py | 4 +++- test/functional/wallet_groups.py | 3 ++- test/functional/wallet_hd.py | 3 ++- test/functional/wallet_importmulti.py | 9 +++++---- test/functional/wallet_importprunedfunds.py | 5 +++-- test/functional/wallet_keypool_topup.py | 3 ++- test/functional/wallet_labels.py | 7 ++++--- test/functional/wallet_listsinceblock.py | 3 ++- test/functional/wallet_multiwallet.py | 3 ++- test/functional/wallet_upgradewallet.py | 7 ++++--- test/functional/wallet_watchonly.py | 3 ++- 28 files changed, 78 insertions(+), 44 deletions(-) diff --git a/test/functional/feature_assumevalid.py b/test/functional/feature_assumevalid.py index 0108d831b5..f6a5b7fc22 100755 --- a/test/functional/feature_assumevalid.py +++ b/test/functional/feature_assumevalid.py @@ -31,7 +31,7 @@ Start three nodes: """ import time -from test_framework.blocktools import (create_block, create_coinbase) +from test_framework.blocktools import (COINBASE_MATURITY,create_block, create_coinbase) from test_framework.key import ECKey from test_framework.messages import ( CBlockHeader, @@ -187,7 +187,7 @@ class AssumeValidTest(BitcoinTestFramework): # Send blocks to node0. Block 102 will be rejected. self.send_blocks_until_disconnected(p2p0) - self.assert_blockchain_height(self.nodes[0], 101) + self.assert_blockchain_height(self.nodes[0], COINBASE_MATURITY + 1) # Send 200 blocks to node1. All blocks, including block 102, will be accepted. for i in range(200): @@ -198,7 +198,7 @@ class AssumeValidTest(BitcoinTestFramework): # Send blocks to node2. Block 102 will be rejected. self.send_blocks_until_disconnected(p2p2) - self.assert_blockchain_height(self.nodes[2], 101) + self.assert_blockchain_height(self.nodes[2], COINBASE_MATURITY + 1) if __name__ == '__main__': diff --git a/test/functional/feature_loadblock.py b/test/functional/feature_loadblock.py index 2089d4e510..898943ae5f 100755 --- a/test/functional/feature_loadblock.py +++ b/test/functional/feature_loadblock.py @@ -16,6 +16,7 @@ import sys import tempfile import urllib +from test_framework.blocktools import COINBASE_MATURITY from test_framework.test_framework import BitcoinTestFramework from test_framework.util import assert_equal @@ -28,7 +29,7 @@ class LoadblockTest(BitcoinTestFramework): def run_test(self): self.nodes[1].setnetworkactive(state=False) - self.nodes[0].generate(100) + self.nodes[0].generate(COINBASE_MATURITY) # Parsing the url of our node to get settings for config file data_dir = self.nodes[0].datadir diff --git a/test/functional/interface_bitcoin_cli.py b/test/functional/interface_bitcoin_cli.py index cf3bbaa9f9..45bc5f2ae5 100755 --- a/test/functional/interface_bitcoin_cli.py +++ b/test/functional/interface_bitcoin_cli.py @@ -5,6 +5,8 @@ """Test dash-cli""" from decimal import Decimal + +from test_framework.blocktools import COINBASE_MATURITY from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( assert_equal, @@ -16,7 +18,7 @@ from test_framework.util import ( # The block reward of coinbaseoutput.nValue (500) DASH/block matures after # COINBASE_MATURITY (100) blocks. Therefore, after mining 101 blocks we expect # node 0 to have a balance of (BLOCKS - COINBASE_MATURITY) * 500 DASH/block. -BLOCKS = 101 +BLOCKS = COINBASE_MATURITY + 1 BALANCE = (BLOCKS - 100) * 500 JSON_PARSING_ERROR = 'error: Error parsing JSON: foo' diff --git a/test/functional/mempool_package_onemore.py b/test/functional/mempool_package_onemore.py index 464e163596..9db36da77c 100755 --- a/test/functional/mempool_package_onemore.py +++ b/test/functional/mempool_package_onemore.py @@ -9,6 +9,7 @@ from decimal import Decimal +from test_framework.blocktools import COINBASE_MATURITY from test_framework.test_framework import BitcoinTestFramework from test_framework.util import assert_equal, assert_raises_rpc_error, satoshi_round @@ -42,7 +43,7 @@ class MempoolPackagesTest(BitcoinTestFramework): def run_test(self): # Mine some blocks and have them mature. - self.nodes[0].generate(101) + self.nodes[0].generate(COINBASE_MATURITY + 1) utxo = self.nodes[0].listunspent(10) txid = utxo[0]['txid'] vout = utxo[0]['vout'] diff --git a/test/functional/mempool_packages.py b/test/functional/mempool_packages.py index fe213e322e..d0a4d305b9 100755 --- a/test/functional/mempool_packages.py +++ b/test/functional/mempool_packages.py @@ -6,6 +6,7 @@ from decimal import Decimal +from test_framework.blocktools import COINBASE_MATURITY from test_framework.messages import COIN from test_framework.mininode import P2PTxInvStore from test_framework.test_framework import BitcoinTestFramework @@ -60,7 +61,7 @@ class MempoolPackagesTest(BitcoinTestFramework): def run_test(self): # Mine some blocks and have them mature. self.nodes[0].add_p2p_connection(P2PTxInvStore()) # keep track of invs - self.nodes[0].generate(101) + self.nodes[0].generate(COINBASE_MATURITY + 1) utxo = self.nodes[0].listunspent(10) txid = utxo[0]['txid'] vout = utxo[0]['vout'] diff --git a/test/functional/mempool_reorg.py b/test/functional/mempool_reorg.py index e89d59f973..94af90c4d0 100755 --- a/test/functional/mempool_reorg.py +++ b/test/functional/mempool_reorg.py @@ -8,7 +8,10 @@ Test re-org scenarios with a mempool that contains transactions that spend (directly or indirectly) coinbase transactions. """ -from test_framework.blocktools import create_raw_transaction +from test_framework.blocktools import ( + COINBASE_MATURITY, + create_raw_transaction, +) from test_framework.test_framework import BitcoinTestFramework from test_framework.util import assert_equal, assert_raises_rpc_error @@ -44,7 +47,7 @@ class MempoolCoinbaseTest(BitcoinTestFramework): # 3. Indirect (coinbase and child both in chain) : spend_103 and spend_103_1 # Use invalidatblock to make all of the above coinbase spends invalid (immature coinbase), # and make sure the mempool code behaves correctly. - b = [self.nodes[0].getblockhash(n) for n in range(101, 105)] + b = [self.nodes[0].getblockhash(n) for n in range(COINBASE_MATURITY + 1, COINBASE_MATURITY + 5)] coinbase_txids = [self.nodes[0].getblock(h)['tx'][0] for h in b] spend_101_raw = create_raw_transaction(self.nodes[0], coinbase_txids[1], node1_address, amount=499.99) spend_102_raw = create_raw_transaction(self.nodes[0], coinbase_txids[2], node0_address, amount=499.99) diff --git a/test/functional/p2p_compactblocks.py b/test/functional/p2p_compactblocks.py index f06a746006..3ffa57801f 100755 --- a/test/functional/p2p_compactblocks.py +++ b/test/functional/p2p_compactblocks.py @@ -7,7 +7,7 @@ import random -from test_framework.blocktools import create_block, create_coinbase +from test_framework.blocktools import COINBASE_MATURITY, create_block, create_coinbase from test_framework.messages import BlockTransactions, BlockTransactionsRequest, calculate_shortid, CBlock, CBlockHeader, CInv, COutPoint, CTransaction, CTxIn, CTxOut, FromHex, HeaderAndShortIDs, msg_block, msg_blocktxn, msg_cmpctblock, msg_getblocktxn, msg_getdata, msg_getheaders, msg_headers, msg_inv, msg_sendcmpct, msg_sendheaders, msg_tx, MSG_BLOCK, MSG_CMPCT_BLOCK, NODE_NETWORK, P2PHeaderAndShortIDs, PrefilledTransaction, ToHex, NODE_HEADERS_COMPRESSED from test_framework.mininode import mininode_lock, P2PInterface from test_framework.script import CScript, OP_TRUE, OP_DROP @@ -115,7 +115,7 @@ class CompactBlocksTest(BitcoinTestFramework): block = self.build_block_on_tip(self.nodes[0]) self.test_node.send_and_ping(msg_block(block)) assert int(self.nodes[0].getbestblockhash(), 16) == block.sha256 - self.nodes[0].generatetoaddress(100, self.nodes[0].getnewaddress()) + self.nodes[0].generatetoaddress(COINBASE_MATURITY, self.nodes[0].getnewaddress()) total_value = block.vtx[0].vout[0].nValue out_value = total_value // 10 @@ -227,7 +227,7 @@ class CompactBlocksTest(BitcoinTestFramework): # This test actually causes dashd to (reasonably!) disconnect us, so do this last. def test_invalid_cmpctblock_message(self): - self.nodes[0].generate(101) + self.nodes[0].generate(COINBASE_MATURITY + 1) block = self.build_block_on_tip(self.nodes[0]) cmpct_block = P2PHeaderAndShortIDs() @@ -245,7 +245,7 @@ class CompactBlocksTest(BitcoinTestFramework): version = test_node.cmpct_version node = self.nodes[0] # Generate a bunch of transactions. - node.generate(101) + node.generate(COINBASE_MATURITY + 1) num_transactions = 25 address = node.getnewaddress() diff --git a/test/functional/p2p_eviction.py b/test/functional/p2p_eviction.py index b2b3a89aab..8fbe16cfc3 100755 --- a/test/functional/p2p_eviction.py +++ b/test/functional/p2p_eviction.py @@ -18,7 +18,7 @@ import time from test_framework.test_framework import BitcoinTestFramework from test_framework.mininode import P2PInterface, P2PDataStore from test_framework.util import assert_equal, wait_until -from test_framework.blocktools import create_block, create_coinbase +from test_framework.blocktools import COINBASE_MATURITY, create_block, create_coinbase from test_framework.messages import CTransaction, FromHex, msg_pong, msg_tx @@ -45,7 +45,7 @@ class P2PEvict(BitcoinTestFramework): protected_peers = set() # peers that we expect to be protected from eviction current_peer = -1 node = self.nodes[0] - node.generatetoaddress(101, node.get_deterministic_priv_key().address) + node.generatetoaddress(COINBASE_MATURITY + 1, node.get_deterministic_priv_key().address) self.log.info("Create 4 peers and protect them from eviction by sending us a block") for _ in range(4): diff --git a/test/functional/rpc_dumptxoutset.py b/test/functional/rpc_dumptxoutset.py index 41cf466c2f..a4204966b4 100755 --- a/test/functional/rpc_dumptxoutset.py +++ b/test/functional/rpc_dumptxoutset.py @@ -4,6 +4,8 @@ # file COPYING or http://www.opensource.org/licenses/mit-license.php. """Test the generation of UTXO snapshots using `dumptxoutset`. """ + +from test_framework.blocktools import COINBASE_MATURITY from test_framework.test_framework import BitcoinTestFramework from test_framework.util import assert_equal, assert_raises_rpc_error @@ -21,7 +23,7 @@ class DumptxoutsetTest(BitcoinTestFramework): node = self.nodes[0] mocktime = node.getblockheader(node.getblockhash(0))['time'] + 1 node.setmocktime(mocktime) - node.generate(100) + node.generate(COINBASE_MATURITY) FILENAME = 'txoutset.dat' out = node.dumptxoutset(FILENAME) diff --git a/test/functional/rpc_getblockstats.py b/test/functional/rpc_getblockstats.py index dcf5c540f7..ebcf4e2ebb 100755 --- a/test/functional/rpc_getblockstats.py +++ b/test/functional/rpc_getblockstats.py @@ -6,6 +6,8 @@ # # Test getblockstats rpc call # + +from test_framework.blocktools import COINBASE_MATURITY from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( assert_equal, @@ -41,7 +43,7 @@ class GetblockstatsTest(BitcoinTestFramework): def generate_test_data(self, filename): self.nodes[0].setmocktime(self.mocktime) - self.nodes[0].generate(101) + self.nodes[0].generate(COINBASE_MATURITY + 1) address = self.nodes[0].get_deterministic_priv_key().address self.nodes[0].sendtoaddress(address=address, amount=10, subtractfeefromamount=True) diff --git a/test/functional/rpc_rawtransaction.py b/test/functional/rpc_rawtransaction.py index a14678125e..84c40f857d 100755 --- a/test/functional/rpc_rawtransaction.py +++ b/test/functional/rpc_rawtransaction.py @@ -15,6 +15,8 @@ Test the following RPCs: from collections import OrderedDict from decimal import Decimal from io import BytesIO + +from test_framework.blocktools import COINBASE_MATURITY from test_framework.messages import CTransaction, ToHex from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( @@ -65,7 +67,7 @@ class RawTransactionsTest(BitcoinTestFramework): self.log.info('prepare some coins for multiple *rawtransaction commands') self.nodes[2].generate(1) self.sync_all() - self.nodes[0].generate(101) + self.nodes[0].generate(COINBASE_MATURITY + 1) self.sync_all() self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(),1.5) self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(),1.0) diff --git a/test/functional/rpc_txoutproof.py b/test/functional/rpc_txoutproof.py index 65d5b5eda8..e681c63fe6 100755 --- a/test/functional/rpc_txoutproof.py +++ b/test/functional/rpc_txoutproof.py @@ -6,6 +6,7 @@ from decimal import Decimal +from test_framework.blocktools import COINBASE_MATURITY from test_framework.messages import CMerkleBlock, FromHex, ToHex from test_framework.test_framework import BitcoinTestFramework from test_framework.util import assert_equal, assert_raises_rpc_error @@ -30,7 +31,7 @@ class MerkleBlockTest(BitcoinTestFramework): def run_test(self): self.log.info("Mining blocks...") - self.nodes[0].generate(105) + self.nodes[0].generate(COINBASE_MATURITY + 5) self.sync_all() chain_height = self.nodes[1].getblockcount() diff --git a/test/functional/test_framework/blocktools.py b/test/functional/test_framework/blocktools.py index e3252a9573..9235c4557c 100644 --- a/test/functional/test_framework/blocktools.py +++ b/test/functional/test_framework/blocktools.py @@ -24,6 +24,9 @@ MAX_BLOCK_SIGOPS = 20000 # Genesis block time (regtest) TIME_GENESIS_BLOCK = 1417713337 +# Coinbase transaction outputs can only be spent after this number of new blocks (network rule) +COINBASE_MATURITY = 100 + def create_block(hashprev, coinbase, ntime=None, *, version=1): """Create a block (with regtest difficulty).""" block = CBlock() diff --git a/test/functional/wallet_abandonconflict.py b/test/functional/wallet_abandonconflict.py index b6e79ccfd0..4e243dd3c6 100755 --- a/test/functional/wallet_abandonconflict.py +++ b/test/functional/wallet_abandonconflict.py @@ -12,6 +12,7 @@ """ from decimal import Decimal +from test_framework.blocktools import COINBASE_MATURITY from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( assert_equal, @@ -28,7 +29,7 @@ class AbandonConflictTest(BitcoinTestFramework): self.skip_if_no_wallet() def run_test(self): - self.nodes[1].generate(100) + self.nodes[1].generate(COINBASE_MATURITY) self.sync_blocks() balance = self.nodes[0].getbalance() txA = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), Decimal("10")) diff --git a/test/functional/wallet_backup.py b/test/functional/wallet_backup.py index 914691ac43..597db8aeca 100755 --- a/test/functional/wallet_backup.py +++ b/test/functional/wallet_backup.py @@ -35,6 +35,7 @@ import os from random import randint import shutil +from test_framework.blocktools import COINBASE_MATURITY from test_framework.test_framework import BitcoinTestFramework from test_framework.util import assert_equal, assert_raises_rpc_error @@ -119,7 +120,7 @@ class WalletBackupTest(BitcoinTestFramework): self.sync_blocks() self.nodes[2].generate(1) self.sync_blocks() - self.nodes[3].generate(100) + self.nodes[3].generate(COINBASE_MATURITY) self.sync_blocks() assert_equal(self.nodes[0].getbalance(), 500) @@ -146,7 +147,7 @@ class WalletBackupTest(BitcoinTestFramework): self.do_one_round() # Generate 101 more blocks, so any fees paid mature - self.nodes[3].generate(101) + self.nodes[3].generate(COINBASE_MATURITY + 1) self.sync_all() balance0 = self.nodes[0].getbalance() diff --git a/test/functional/wallet_balance.py b/test/functional/wallet_balance.py index 5d0b9d0bd1..3839b8a8dd 100755 --- a/test/functional/wallet_balance.py +++ b/test/functional/wallet_balance.py @@ -7,6 +7,7 @@ from decimal import Decimal import struct from test_framework.address import ADDRESS_BCRT1_UNSPENDABLE as ADDRESS_WATCHONLY +from test_framework.blocktools import COINBASE_MATURITY from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( assert_equal, @@ -70,7 +71,7 @@ class WalletTest(BitcoinTestFramework): self.nodes[0].generate(1) self.sync_all() self.nodes[1].generate(1) - self.nodes[1].generatetoaddress(101, ADDRESS_WATCHONLY) + self.nodes[1].generatetoaddress(COINBASE_MATURITY + 1, ADDRESS_WATCHONLY) self.sync_all() assert_equal(self.nodes[0].getbalances()['mine']['trusted'], 500) diff --git a/test/functional/wallet_basic.py b/test/functional/wallet_basic.py index 377333cb14..632d91e830 100755 --- a/test/functional/wallet_basic.py +++ b/test/functional/wallet_basic.py @@ -5,6 +5,7 @@ """Test the wallet.""" from decimal import Decimal +from test_framework.blocktools import COINBASE_MATURITY from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( assert_array_result, @@ -60,7 +61,7 @@ class WalletTest(BitcoinTestFramework): assert_equal(walletinfo['balance'], 0) self.sync_all(self.nodes[0:3]) - self.nodes[1].generate(101) + self.nodes[1].generate(COINBASE_MATURITY + 1) self.sync_all(self.nodes[0:3]) assert_equal(self.nodes[0].getbalance(), 500) @@ -145,7 +146,7 @@ class WalletTest(BitcoinTestFramework): assert_equal(len(self.nodes[1].listlockunspent()), 0) # Have node1 generate 100 blocks (so node0 can recover the fee) - self.nodes[1].generate(100) + self.nodes[1].generate(COINBASE_MATURITY) self.sync_all(self.nodes[0:3]) # node0 should end up with 1000 DASH in block rewards plus fees, but diff --git a/test/functional/wallet_fallbackfee.py b/test/functional/wallet_fallbackfee.py index b06f71020c..aba436b43c 100755 --- a/test/functional/wallet_fallbackfee.py +++ b/test/functional/wallet_fallbackfee.py @@ -3,6 +3,8 @@ # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. """Test wallet replace-by-fee capabilities in conjunction with the fallbackfee.""" + +from test_framework.blocktools import COINBASE_MATURITY from test_framework.test_framework import BitcoinTestFramework from test_framework.util import assert_raises_rpc_error @@ -15,7 +17,7 @@ class WalletRBFTest(BitcoinTestFramework): self.skip_if_no_wallet() def run_test(self): - self.nodes[0].generate(101) + self.nodes[0].generate(COINBASE_MATURITY + 1) # sending a transaction without fee estimations must be possible by default on regtest self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1) diff --git a/test/functional/wallet_groups.py b/test/functional/wallet_groups.py index 27cb09be04..71e0fe0d00 100755 --- a/test/functional/wallet_groups.py +++ b/test/functional/wallet_groups.py @@ -4,6 +4,7 @@ # file COPYING or http://www.opensource.org/licenses/mit-license.php. """Test wallet group functionality.""" +from test_framework.blocktools import COINBASE_MATURITY from test_framework.test_framework import BitcoinTestFramework from test_framework.messages import CTransaction, FromHex, ToHex from test_framework.util import ( @@ -25,7 +26,7 @@ class WalletGroupTest(BitcoinTestFramework): def run_test(self): # Mine some coins - self.nodes[0].generate(110) + self.nodes[0].generate(COINBASE_MATURITY + 10) # Get some addresses from the two nodes addr1 = [self.nodes[1].getnewaddress() for i in range(3)] diff --git a/test/functional/wallet_hd.py b/test/functional/wallet_hd.py index 5c374d9c4e..ebfcd114d2 100755 --- a/test/functional/wallet_hd.py +++ b/test/functional/wallet_hd.py @@ -7,6 +7,7 @@ import shutil import os +from test_framework.blocktools import COINBASE_MATURITY from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( assert_equal, @@ -52,7 +53,7 @@ class WalletHDTest(BitcoinTestFramework): # Derive some HD addresses and remember the last # Also send funds to each add - self.nodes[0].generate(101) + self.nodes[0].generate(COINBASE_MATURITY + 1) hd_add = None NUM_HD_ADDS = 10 for i in range(NUM_HD_ADDS): diff --git a/test/functional/wallet_importmulti.py b/test/functional/wallet_importmulti.py index c1a2f76478..b3ee1b0563 100755 --- a/test/functional/wallet_importmulti.py +++ b/test/functional/wallet_importmulti.py @@ -15,6 +15,7 @@ variants. - `test_address()` is called to call getaddressinfo for an address on node1 and test the values returned.""" +from test_framework.blocktools import COINBASE_MATURITY from test_framework.script import ( CScript, OP_NOP, @@ -254,7 +255,7 @@ class ImportMultiTest(BitcoinTestFramework): # P2SH address multisig = get_multisig(self.nodes[0]) - self.nodes[1].generate(100) + self.nodes[1].generate(COINBASE_MATURITY) self.nodes[1].sendtoaddress(multisig.p2sh_addr, 10.00) self.nodes[1].generate(1) timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime'] @@ -275,7 +276,7 @@ class ImportMultiTest(BitcoinTestFramework): # P2SH + Redeem script multisig = get_multisig(self.nodes[0]) - self.nodes[1].generate(100) + self.nodes[1].generate(COINBASE_MATURITY) self.nodes[1].sendtoaddress(multisig.p2sh_addr, 10.00) self.nodes[1].generate(1) timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime'] @@ -296,7 +297,7 @@ class ImportMultiTest(BitcoinTestFramework): # P2SH + Redeem script + Private Keys + !Watchonly multisig = get_multisig(self.nodes[0]) - self.nodes[1].generate(100) + self.nodes[1].generate(COINBASE_MATURITY) self.nodes[1].sendtoaddress(multisig.p2sh_addr, 10.00) self.nodes[1].generate(1) timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime'] @@ -322,7 +323,7 @@ class ImportMultiTest(BitcoinTestFramework): # P2SH + Redeem script + Private Keys + Watchonly multisig = get_multisig(self.nodes[0]) - self.nodes[1].generate(100) + self.nodes[1].generate(COINBASE_MATURITY) self.nodes[1].sendtoaddress(multisig.p2sh_addr, 10.00) self.nodes[1].generate(1) timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime'] diff --git a/test/functional/wallet_importprunedfunds.py b/test/functional/wallet_importprunedfunds.py index ce4d8705d7..50da2d13c6 100755 --- a/test/functional/wallet_importprunedfunds.py +++ b/test/functional/wallet_importprunedfunds.py @@ -5,6 +5,7 @@ """Test the importprunedfunds and removeprunedfunds RPCs.""" from decimal import Decimal +from test_framework.blocktools import COINBASE_MATURITY from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( assert_equal, @@ -21,7 +22,7 @@ class ImportPrunedFundsTest(BitcoinTestFramework): def run_test(self): self.log.info("Mining blocks...") - self.nodes[0].generate(101) + self.nodes[0].generate(COINBASE_MATURITY + 1) self.sync_all() @@ -40,7 +41,7 @@ class ImportPrunedFundsTest(BitcoinTestFramework): self.sync_all() # Node 1 sync test - assert_equal(self.nodes[1].getblockcount(), 101) + assert_equal(self.nodes[1].getblockcount(), COINBASE_MATURITY + 1) # Address Test - before import address_info = self.nodes[1].getaddressinfo(address1) diff --git a/test/functional/wallet_keypool_topup.py b/test/functional/wallet_keypool_topup.py index a44866b8b1..55fa940152 100755 --- a/test/functional/wallet_keypool_topup.py +++ b/test/functional/wallet_keypool_topup.py @@ -13,6 +13,7 @@ Two nodes. Node1 is under test. Node0 is providing transactions and generating b import os import shutil +from test_framework.blocktools import COINBASE_MATURITY from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( assert_equal, @@ -31,7 +32,7 @@ class KeypoolRestoreTest(BitcoinTestFramework): def run_test(self): wallet_path = os.path.join(self.nodes[1].datadir, self.chain, "wallets", self.default_wallet_name, self.wallet_data_filename) wallet_backup_path = os.path.join(self.nodes[1].datadir, "wallet.bak") - self.nodes[0].generate(101) + self.nodes[0].generate(COINBASE_MATURITY + 1) self.log.info("Make backup of wallet") self.stop_node(1) diff --git a/test/functional/wallet_labels.py b/test/functional/wallet_labels.py index d0c58910fb..cd0b862280 100755 --- a/test/functional/wallet_labels.py +++ b/test/functional/wallet_labels.py @@ -11,6 +11,7 @@ RPCs tested are: """ from collections import defaultdict +from test_framework.blocktools import COINBASE_MATURITY from test_framework.test_framework import BitcoinTestFramework from test_framework.util import assert_equal, assert_raises_rpc_error from test_framework.wallet_util import test_address @@ -32,7 +33,7 @@ class WalletLabelsTest(BitcoinTestFramework): # Note each time we call generate, all generated coins go into # the same address, so we call twice to get two addresses w/500 each node.generatetoaddress(nblocks=1, address=node.getnewaddress(label='coinbase')) - node.generatetoaddress(nblocks=101, address=node.getnewaddress(label='coinbase')) + node.generatetoaddress(nblocks=COINBASE_MATURITY + 1, address=node.getnewaddress(label='coinbase')) assert_equal(node.getbalance(), 1000) # there should be 2 address groups @@ -106,7 +107,7 @@ class WalletLabelsTest(BitcoinTestFramework): label.verify(node) assert_equal(node.getreceivedbylabel(label.name), 2) label.verify(node) - node.generate(101) + node.generate(COINBASE_MATURITY + 1) # Check that setlabel can assign a label to a new unused address. for label in labels: @@ -125,7 +126,7 @@ class WalletLabelsTest(BitcoinTestFramework): label.add_address(multisig_address) label.purpose[multisig_address] = "send" label.verify(node) - node.generate(101) + node.generate(COINBASE_MATURITY + 1) # Check that setlabel can change the label of an address from a # different label. diff --git a/test/functional/wallet_listsinceblock.py b/test/functional/wallet_listsinceblock.py index 0f8ebdf211..cde6b9f247 100755 --- a/test/functional/wallet_listsinceblock.py +++ b/test/functional/wallet_listsinceblock.py @@ -4,6 +4,7 @@ # file COPYING or http://www.opensource.org/licenses/mit-license.php. """Test the listsinceblock RPC.""" +from test_framework.blocktools import COINBASE_MATURITY from test_framework.test_framework import BitcoinTestFramework from test_framework.messages import BIP125_SEQUENCE_NUMBER from test_framework.util import ( @@ -26,7 +27,7 @@ class ListSinceBlockTest(BitcoinTestFramework): # All nodes are in IBD from genesis, so they'll need the miner (node2) to be an outbound connection, or have # only one connection. (See fPreferredDownload in net_processing) self.connect_nodes(1, 2) - self.nodes[2].generate(101) + self.nodes[2].generate(COINBASE_MATURITY + 1) self.sync_all() self.test_no_blockhash() diff --git a/test/functional/wallet_multiwallet.py b/test/functional/wallet_multiwallet.py index a7aa92b0a4..cd66169b91 100755 --- a/test/functional/wallet_multiwallet.py +++ b/test/functional/wallet_multiwallet.py @@ -13,6 +13,7 @@ import shutil import time from test_framework.authproxy import JSONRPCException +from test_framework.blocktools import COINBASE_MATURITY from test_framework.test_framework import BitcoinTestFramework from test_framework.test_node import ErrorMatch from test_framework.util import ( @@ -208,7 +209,7 @@ class MultiWalletTest(BitcoinTestFramework): assert_raises_rpc_error(-19, "Wallet file not specified", node.getwalletinfo) w1, w2, w3, w4, *_ = wallets - node.generatetoaddress(nblocks=101, address=w1.getnewaddress()) + node.generatetoaddress(nblocks=COINBASE_MATURITY + 1, address=w1.getnewaddress()) assert_equal(w1.getbalance(), 1000) assert_equal(w2.getbalance(), 0) assert_equal(w3.getbalance(), 0) diff --git a/test/functional/wallet_upgradewallet.py b/test/functional/wallet_upgradewallet.py index bc272eba09..260b02880c 100755 --- a/test/functional/wallet_upgradewallet.py +++ b/test/functional/wallet_upgradewallet.py @@ -12,6 +12,7 @@ contrib/devtools/previous_release.sh -b v0.15.2 v0.16.3 import os import shutil +from test_framework.blocktools import COINBASE_MATURITY from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( adjust_bitcoin_conf_for_pre_17, @@ -70,11 +71,11 @@ class UpgradeWalletTest(BitcoinTestFramework): assert_equal(v16_3_node.getblockcount(), to_height) def run_test(self): - self.nodes[0].generatetoaddress(101, self.nodes[0].getnewaddress()) + self.nodes[0].generatetoaddress(COINBASE_MATURITY + 1, self.nodes[0].getnewaddress()) self.dumb_sync_blocks() # # Sanity check the test framework: res = self.nodes[0].getblockchaininfo() - assert_equal(res['blocks'], 101) + assert_equal(res['blocks'], COINBASE_MATURITY + 1) node_master = self.nodes[0] v16_3_node = self.nodes[1] v15_2_node = self.nodes[2] @@ -82,7 +83,7 @@ class UpgradeWalletTest(BitcoinTestFramework): # Send coins to old wallets for later conversion checks. v16_3_wallet = v16_3_node.get_wallet_rpc('wallet.dat') v16_3_address = v16_3_wallet.getnewaddress() - node_master.generatetoaddress(101, v16_3_address) + node_master.generatetoaddress(COINBASE_MATURITY + 1, v16_3_address) self.dumb_sync_blocks() v16_3_balance = v16_3_wallet.getbalance() diff --git a/test/functional/wallet_watchonly.py b/test/functional/wallet_watchonly.py index be8d7714fb..36d9118749 100755 --- a/test/functional/wallet_watchonly.py +++ b/test/functional/wallet_watchonly.py @@ -5,6 +5,7 @@ """Test createwallet arguments. """ +from test_framework.blocktools import COINBASE_MATURITY from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( assert_equal, @@ -38,7 +39,7 @@ class CreateWalletWatchonlyTest(BitcoinTestFramework): wo_wallet.importpubkey(pubkey=def_wallet.getaddressinfo(wo_change)['pubkey']) # generate some btc for testing - node.generatetoaddress(101, a1) + node.generatetoaddress(COINBASE_MATURITY + 1, a1) # send 1 btc to our watch-only address txid = def_wallet.sendtoaddress(wo_addr, 1)