Merge bitcoin/bitcoin#21989: test: Use COINBASE_MATURITY in functional tests

bfa9309ad6 Use COINBASE_MATURITY constant in functional tests. (Kiminuo)
525448df9d 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 bfa9309ad6 🌇

Tree-SHA512: 01f04645f05a39028681f355cf3d42dd63ea3303f76d93c430e0fdce441934358a2d847a54e6068d61932f1b75e1d406f51859b057b3e4b569f7083915cb317f
This commit is contained in:
MarcoFalke 2021-05-31 11:26:16 +02:00
commit c5ee0cc11a
No known key found for this signature in database
GPG key ID: CE2B75697E69A548
47 changed files with 135 additions and 68 deletions

View file

@ -31,6 +31,7 @@ Start three nodes:
""" """
from test_framework.blocktools import ( from test_framework.blocktools import (
COINBASE_MATURITY,
create_block, create_block,
create_coinbase, create_coinbase,
) )
@ -161,8 +162,8 @@ class AssumeValidTest(BitcoinTestFramework):
# Send blocks to node0. Block 102 will be rejected. # Send blocks to node0. Block 102 will be rejected.
self.send_blocks_until_disconnected(p2p0) self.send_blocks_until_disconnected(p2p0)
self.wait_until(lambda: self.nodes[0].getblockcount() >= 101) self.wait_until(lambda: self.nodes[0].getblockcount() >= COINBASE_MATURITY + 1)
assert_equal(self.nodes[0].getblockcount(), 101) assert_equal(self.nodes[0].getblockcount(), COINBASE_MATURITY + 1)
# Send all blocks to node1. All blocks will be accepted. # Send all blocks to node1. All blocks will be accepted.
for i in range(2202): for i in range(2202):
@ -173,8 +174,8 @@ class AssumeValidTest(BitcoinTestFramework):
# Send blocks to node2. Block 102 will be rejected. # Send blocks to node2. Block 102 will be rejected.
self.send_blocks_until_disconnected(p2p2) self.send_blocks_until_disconnected(p2p2)
self.wait_until(lambda: self.nodes[2].getblockcount() >= 101) self.wait_until(lambda: self.nodes[2].getblockcount() >= COINBASE_MATURITY + 1)
assert_equal(self.nodes[2].getblockcount(), 101) assert_equal(self.nodes[2].getblockcount(), COINBASE_MATURITY + 1)
if __name__ == '__main__': if __name__ == '__main__':

View file

@ -22,6 +22,7 @@ needs an older patch version.
import os import os
import shutil import shutil
from test_framework.blocktools import COINBASE_MATURITY
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.descriptors import descsum_create from test_framework.descriptors import descsum_create
@ -64,13 +65,13 @@ class BackwardsCompatibilityTest(BitcoinTestFramework):
self.import_deterministic_coinbase_privkeys() self.import_deterministic_coinbase_privkeys()
def run_test(self): 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.sync_blocks() self.sync_blocks()
# Sanity check the test framework: # Sanity check the test framework:
res = self.nodes[self.num_nodes - 1].getblockchaininfo() res = self.nodes[self.num_nodes - 1].getblockchaininfo()
assert_equal(res['blocks'], 101) assert_equal(res['blocks'], COINBASE_MATURITY + 1)
node_master = self.nodes[self.num_nodes - 5] node_master = self.nodes[self.num_nodes - 5]
node_v19 = self.nodes[self.num_nodes - 4] node_v19 = self.nodes[self.num_nodes - 4]

View file

@ -12,6 +12,7 @@ the index.
from decimal import Decimal from decimal import Decimal
from test_framework.blocktools import ( from test_framework.blocktools import (
COINBASE_MATURITY,
create_block, create_block,
create_coinbase, create_coinbase,
) )
@ -68,7 +69,7 @@ class CoinStatsIndexTest(BitcoinTestFramework):
index_hash_options = ['none', 'muhash'] index_hash_options = ['none', 'muhash']
# Generate a normal transaction and mine it # Generate a normal transaction and mine it
node.generate(101) node.generate(COINBASE_MATURITY + 1)
address = self.nodes[0].get_deterministic_priv_key().address address = self.nodes[0].get_deterministic_priv_key().address
node.sendtoaddress(address=address, amount=10, subtractfeefromamount=True) node.sendtoaddress(address=address, amount=10, subtractfeefromamount=True)
node.generate(1) node.generate(1)

View file

@ -16,6 +16,7 @@ import sys
import tempfile import tempfile
import urllib import urllib
from test_framework.blocktools import COINBASE_MATURITY
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal from test_framework.util import assert_equal
@ -28,7 +29,7 @@ class LoadblockTest(BitcoinTestFramework):
def run_test(self): def run_test(self):
self.nodes[1].setnetworkactive(state=False) 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 # Parsing the url of our node to get settings for config file
data_dir = self.nodes[0].datadir data_dir = self.nodes[0].datadir

View file

@ -14,13 +14,18 @@ Generate COINBASE_MATURITY (CB) more blocks to ensure the coinbases are mature.
""" """
import time import time
from test_framework.blocktools import NORMAL_GBT_REQUEST_PARAMS, create_block, create_transaction, add_witness_commitment from test_framework.blocktools import (
COINBASE_MATURITY,
NORMAL_GBT_REQUEST_PARAMS,
add_witness_commitment,
create_block,
create_transaction,
)
from test_framework.messages import CTransaction from test_framework.messages import CTransaction
from test_framework.script import CScript from test_framework.script import CScript
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, assert_raises_rpc_error from test_framework.util import assert_equal, assert_raises_rpc_error
COINBASE_MATURITY = 100
NULLDUMMY_ERROR = "non-mandatory-script-verify-flag (Dummy CHECKMULTISIG argument must be zero)" NULLDUMMY_ERROR = "non-mandatory-script-verify-flag (Dummy CHECKMULTISIG argument must be zero)"
def trueDummy(tx): def trueDummy(tx):

View file

@ -6,6 +6,7 @@
from decimal import Decimal from decimal import Decimal
from test_framework.blocktools import COINBASE_MATURITY
from test_framework.messages import COIN, COutPoint, CTransaction, CTxIn, CTxOut from test_framework.messages import COIN, COutPoint, CTransaction, CTxIn, CTxOut
from test_framework.script import CScript, OP_DROP from test_framework.script import CScript, OP_DROP
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
@ -27,7 +28,7 @@ def make_utxo(node, amount, confirmed=True, scriptPubKey=DUMMY_P2WPKH_SCRIPT):
""" """
fee = 1*COIN fee = 1*COIN
while node.getbalance() < satoshi_round((amount + fee)/COIN): while node.getbalance() < satoshi_round((amount + fee)/COIN):
node.generate(100) node.generate(COINBASE_MATURITY)
new_addr = node.getnewaddress() new_addr = node.getnewaddress()
txid = node.sendtoaddress(new_addr, satoshi_round((amount+fee)/COIN)) txid = node.sendtoaddress(new_addr, satoshi_round((amount+fee)/COIN))

View file

@ -5,6 +5,7 @@
# Test Taproot softfork (BIPs 340-342) # Test Taproot softfork (BIPs 340-342)
from test_framework.blocktools import ( from test_framework.blocktools import (
COINBASE_MATURITY,
create_coinbase, create_coinbase,
create_block, create_block,
add_witness_commitment, add_witness_commitment,
@ -1440,7 +1441,7 @@ class TaprootTest(BitcoinTestFramework):
def run_test(self): def run_test(self):
# Post-taproot activation tests go first (pre-taproot tests' blocks are invalid post-taproot). # Post-taproot activation tests go first (pre-taproot tests' blocks are invalid post-taproot).
self.log.info("Post-activation tests...") self.log.info("Post-activation tests...")
self.nodes[1].generate(101) self.nodes[1].generate(COINBASE_MATURITY + 1)
self.test_spenders(self.nodes[1], spenders_taproot_active(), input_counts=[1, 2, 2, 2, 2, 3]) self.test_spenders(self.nodes[1], spenders_taproot_active(), input_counts=[1, 2, 2, 2, 2, 3])
# Re-connect nodes in case they have been disconnected # Re-connect nodes in case they have been disconnected

View file

@ -5,6 +5,8 @@
"""Test bitcoin-cli""" """Test bitcoin-cli"""
from decimal import Decimal from decimal import Decimal
from test_framework.blocktools import COINBASE_MATURITY
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import ( from test_framework.util import (
assert_equal, assert_equal,
@ -16,7 +18,7 @@ from test_framework.util import (
# The block reward of coinbaseoutput.nValue (50) BTC/block matures after # The block reward of coinbaseoutput.nValue (50) BTC/block matures after
# COINBASE_MATURITY (100) blocks. Therefore, after mining 101 blocks we expect # COINBASE_MATURITY (100) blocks. Therefore, after mining 101 blocks we expect
# node 0 to have a balance of (BLOCKS - COINBASE_MATURITY) * 50 BTC/block. # node 0 to have a balance of (BLOCKS - COINBASE_MATURITY) * 50 BTC/block.
BLOCKS = 101 BLOCKS = COINBASE_MATURITY + 1
BALANCE = (BLOCKS - 100) * 50 BALANCE = (BLOCKS - 100) * 50
JSON_PARSING_ERROR = 'error: Error parsing JSON: foo' JSON_PARSING_ERROR = 'error: Error parsing JSON: foo'

View file

@ -15,6 +15,7 @@ Only v0.15.2 is required by this test. The rest is used in other backwards compa
import os import os
from test_framework.blocktools import COINBASE_MATURITY
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.wallet import MiniWallet from test_framework.wallet import MiniWallet
@ -41,7 +42,7 @@ class MempoolCompatibilityTest(BitcoinTestFramework):
old_node, new_node = self.nodes old_node, new_node = self.nodes
new_wallet = MiniWallet(new_node) new_wallet = MiniWallet(new_node)
new_wallet.generate(1) new_wallet.generate(1)
new_node.generate(100) new_node.generate(COINBASE_MATURITY)
# Sync the nodes to ensure old_node has the block that contains the coinbase that new_wallet will spend. # Sync the nodes to ensure old_node has the block that contains the coinbase that new_wallet will spend.
# Otherwise, because coinbases are only valid in a block and not as loose txns, if the nodes aren't synced # Otherwise, because coinbases are only valid in a block and not as loose txns, if the nodes aren't synced
# unbroadcasted_tx won't pass old_node's `MemPoolAccept::PreChecks`. # unbroadcasted_tx won't pass old_node's `MemPoolAccept::PreChecks`.

View file

@ -12,6 +12,7 @@ definable expiry timeout via the '-mempoolexpiry=<n>' command line argument
from datetime import timedelta from datetime import timedelta
from test_framework.blocktools import COINBASE_MATURITY
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import ( from test_framework.util import (
assert_equal, assert_equal,
@ -36,7 +37,7 @@ class MempoolExpiryTest(BitcoinTestFramework):
# Add enough mature utxos to the wallet so that all txs spend confirmed coins. # Add enough mature utxos to the wallet so that all txs spend confirmed coins.
self.wallet.generate(4) self.wallet.generate(4)
node.generate(100) node.generate(COINBASE_MATURITY)
# Send a parent transaction that will expire. # Send a parent transaction that will expire.
parent_txid = self.wallet.send_self_transfer(from_node=node)['txid'] parent_txid = self.wallet.send_self_transfer(from_node=node)['txid']

View file

@ -9,6 +9,7 @@
from decimal import Decimal from decimal import Decimal
from test_framework.blocktools import COINBASE_MATURITY
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, assert_raises_rpc_error, satoshi_round from test_framework.util import assert_equal, assert_raises_rpc_error, satoshi_round
@ -42,7 +43,7 @@ class MempoolPackagesTest(BitcoinTestFramework):
def run_test(self): def run_test(self):
# Mine some blocks and have them mature. # 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) utxo = self.nodes[0].listunspent(10)
txid = utxo[0]['txid'] txid = utxo[0]['txid']
vout = utxo[0]['vout'] vout = utxo[0]['vout']

View file

@ -6,6 +6,7 @@
from decimal import Decimal from decimal import Decimal
from test_framework.blocktools import COINBASE_MATURITY
from test_framework.messages import COIN from test_framework.messages import COIN
from test_framework.p2p import P2PTxInvStore from test_framework.p2p import P2PTxInvStore
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
@ -59,7 +60,7 @@ class MempoolPackagesTest(BitcoinTestFramework):
def run_test(self): def run_test(self):
# Mine some blocks and have them mature. # Mine some blocks and have them mature.
peer_inv_store = self.nodes[0].add_p2p_connection(P2PTxInvStore()) # keep track of invs peer_inv_store = 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) utxo = self.nodes[0].listunspent(10)
txid = utxo[0]['txid'] txid = utxo[0]['txid']
vout = utxo[0]['vout'] vout = utxo[0]['vout']

View file

@ -8,7 +8,10 @@ Test re-org scenarios with a mempool that contains transactions
that spend (directly or indirectly) coinbase 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.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, assert_raises_rpc_error 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 # 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), # Use invalidatblock to make all of the above coinbase spends invalid (immature coinbase),
# and make sure the mempool code behaves correctly. # 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] 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=49.99) spend_101_raw = create_raw_transaction(self.nodes[0], coinbase_txids[1], node1_address, amount=49.99)
spend_102_raw = create_raw_transaction(self.nodes[0], coinbase_txids[2], node0_address, amount=49.99) spend_102_raw = create_raw_transaction(self.nodes[0], coinbase_txids[2], node0_address, amount=49.99)

View file

@ -4,6 +4,7 @@
# file COPYING or http://www.opensource.org/licenses/mit-license.php. # file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test resurrection of mined transactions when the blockchain is re-organized.""" """Test resurrection of mined transactions when the blockchain is re-organized."""
from test_framework.blocktools import COINBASE_MATURITY
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal from test_framework.util import assert_equal
from test_framework.wallet import MiniWallet from test_framework.wallet import MiniWallet
@ -20,7 +21,7 @@ class MempoolCoinbaseTest(BitcoinTestFramework):
# Add enough mature utxos to the wallet so that all txs spend confirmed coins # Add enough mature utxos to the wallet so that all txs spend confirmed coins
wallet.generate(3) wallet.generate(3)
node.generate(100) node.generate(COINBASE_MATURITY)
# Spend block 1/2/3's coinbase transactions # Spend block 1/2/3's coinbase transactions
# Mine a block # Mine a block

View file

@ -8,6 +8,7 @@ from decimal import Decimal
import random import random
import threading import threading
from test_framework.blocktools import COINBASE_MATURITY
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import get_rpc_proxy from test_framework.util import get_rpc_proxy
from test_framework.wallet import MiniWallet from test_framework.wallet import MiniWallet
@ -62,7 +63,7 @@ class GetBlockTemplateLPTest(BitcoinTestFramework):
assert not thr.is_alive() assert not thr.is_alive()
# Add enough mature utxos to the wallets, so that all txs spend confirmed coins # Add enough mature utxos to the wallets, so that all txs spend confirmed coins
self.nodes[0].generate(100) self.nodes[0].generate(COINBASE_MATURITY)
self.sync_blocks() self.sync_blocks()
self.log.info("Test that introducing a new transaction into the mempool will terminate the longpoll") self.log.info("Test that introducing a new transaction into the mempool will terminate the longpoll")

View file

@ -6,6 +6,7 @@
import time import time
from test_framework.blocktools import COINBASE_MATURITY
from test_framework.messages import msg_tx from test_framework.messages import msg_tx
from test_framework.p2p import P2PInterface, P2PTxInvStore from test_framework.p2p import P2PInterface, P2PTxInvStore
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
@ -23,7 +24,7 @@ class P2PBlocksOnly(BitcoinTestFramework):
self.miniwallet = MiniWallet(self.nodes[0]) self.miniwallet = MiniWallet(self.nodes[0])
# Add enough mature utxos to the wallet, so that all txs spend confirmed coins # Add enough mature utxos to the wallet, so that all txs spend confirmed coins
self.miniwallet.generate(2) self.miniwallet.generate(2)
self.nodes[0].generate(100) self.nodes[0].generate(COINBASE_MATURITY)
self.blocksonly_mode_tests() self.blocksonly_mode_tests()
self.blocks_relay_conn_tests() self.blocks_relay_conn_tests()

View file

@ -9,7 +9,12 @@ Version 2 compact blocks are post-segwit (wtxids)
""" """
import random import random
from test_framework.blocktools import create_block, NORMAL_GBT_REQUEST_PARAMS, add_witness_commitment from test_framework.blocktools import (
COINBASE_MATURITY,
NORMAL_GBT_REQUEST_PARAMS,
add_witness_commitment,
create_block,
)
from test_framework.messages import BlockTransactions, BlockTransactionsRequest, calculate_shortid, CBlock, CBlockHeader, CInv, COutPoint, CTransaction, CTxIn, CTxInWitness, CTxOut, FromHex, HeaderAndShortIDs, msg_no_witness_block, msg_no_witness_blocktxn, msg_cmpctblock, msg_getblocktxn, msg_getdata, msg_getheaders, msg_headers, msg_inv, msg_sendcmpct, msg_sendheaders, msg_tx, msg_block, msg_blocktxn, MSG_BLOCK, MSG_CMPCT_BLOCK, MSG_WITNESS_FLAG, NODE_NETWORK, P2PHeaderAndShortIDs, PrefilledTransaction, ser_uint256, ToHex from test_framework.messages import BlockTransactions, BlockTransactionsRequest, calculate_shortid, CBlock, CBlockHeader, CInv, COutPoint, CTransaction, CTxIn, CTxInWitness, CTxOut, FromHex, HeaderAndShortIDs, msg_no_witness_block, msg_no_witness_blocktxn, msg_cmpctblock, msg_getblocktxn, msg_getdata, msg_getheaders, msg_headers, msg_inv, msg_sendcmpct, msg_sendheaders, msg_tx, msg_block, msg_blocktxn, MSG_BLOCK, MSG_CMPCT_BLOCK, MSG_WITNESS_FLAG, NODE_NETWORK, P2PHeaderAndShortIDs, PrefilledTransaction, ser_uint256, ToHex
from test_framework.p2p import p2p_lock, P2PInterface from test_framework.p2p import p2p_lock, P2PInterface
from test_framework.script import CScript, OP_TRUE, OP_DROP from test_framework.script import CScript, OP_TRUE, OP_DROP
@ -115,7 +120,7 @@ class CompactBlocksTest(BitcoinTestFramework):
block = self.build_block_on_tip(self.nodes[0]) block = self.build_block_on_tip(self.nodes[0])
self.segwit_node.send_and_ping(msg_no_witness_block(block)) self.segwit_node.send_and_ping(msg_no_witness_block(block))
assert int(self.nodes[0].getbestblockhash(), 16) == block.sha256 assert int(self.nodes[0].getbestblockhash(), 16) == block.sha256
self.nodes[0].generatetoaddress(100, self.nodes[0].getnewaddress(address_type="bech32")) self.nodes[0].generatetoaddress(COINBASE_MATURITY, self.nodes[0].getnewaddress(address_type="bech32"))
total_value = block.vtx[0].vout[0].nValue total_value = block.vtx[0].vout[0].nValue
out_value = total_value // 10 out_value = total_value // 10
@ -226,7 +231,7 @@ class CompactBlocksTest(BitcoinTestFramework):
# This test actually causes bitcoind to (reasonably!) disconnect us, so do this last. # This test actually causes bitcoind to (reasonably!) disconnect us, so do this last.
def test_invalid_cmpctblock_message(self): 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]) block = self.build_block_on_tip(self.nodes[0])
cmpct_block = P2PHeaderAndShortIDs() cmpct_block = P2PHeaderAndShortIDs()
@ -244,7 +249,7 @@ class CompactBlocksTest(BitcoinTestFramework):
version = test_node.cmpct_version version = test_node.cmpct_version
node = self.nodes[0] node = self.nodes[0]
# Generate a bunch of transactions. # Generate a bunch of transactions.
node.generate(101) node.generate(COINBASE_MATURITY + 1)
num_transactions = 25 num_transactions = 25
address = node.getnewaddress() address = node.getnewaddress()

View file

@ -15,7 +15,11 @@ Therefore, this test is limited to the remaining protection criteria.
import time 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.messages import CTransaction, FromHex, msg_pong, msg_tx from test_framework.messages import CTransaction, FromHex, msg_pong, msg_tx
from test_framework.p2p import P2PDataStore, P2PInterface from test_framework.p2p import P2PDataStore, P2PInterface
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
@ -45,7 +49,7 @@ class P2PEvict(BitcoinTestFramework):
protected_peers = set() # peers that we expect to be protected from eviction protected_peers = set() # peers that we expect to be protected from eviction
current_peer = -1 current_peer = -1
node = self.nodes[0] 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") self.log.info("Create 4 peers and protect them from eviction by sending us a block")
for _ in range(4): for _ in range(4):

View file

@ -6,6 +6,7 @@
from decimal import Decimal from decimal import Decimal
from test_framework.blocktools import COINBASE_MATURITY
from test_framework.messages import MSG_TX, MSG_WTX, msg_feefilter from test_framework.messages import MSG_TX, MSG_WTX, msg_feefilter
from test_framework.p2p import P2PInterface, p2p_lock from test_framework.p2p import P2PInterface, p2p_lock
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
@ -81,7 +82,7 @@ class FeeFilterTest(BitcoinTestFramework):
miniwallet = MiniWallet(node1) miniwallet = MiniWallet(node1)
# Add enough mature utxos to the wallet, so that all txs spend confirmed coins # Add enough mature utxos to the wallet, so that all txs spend confirmed coins
miniwallet.generate(5) miniwallet.generate(5)
node1.generate(100) node1.generate(COINBASE_MATURITY)
conn = self.nodes[0].add_p2p_connection(TestP2PConn()) conn = self.nodes[0].add_p2p_connection(TestP2PConn())

View file

@ -4,6 +4,7 @@
# file COPYING or http://www.opensource.org/licenses/mit-license.php. # file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test that we don't leak txs to inbound peers that we haven't yet announced to""" """Test that we don't leak txs to inbound peers that we haven't yet announced to"""
from test_framework.blocktools import COINBASE_MATURITY
from test_framework.messages import msg_getdata, CInv, MSG_TX from test_framework.messages import msg_getdata, CInv, MSG_TX
from test_framework.p2p import p2p_lock, P2PDataStore from test_framework.p2p import p2p_lock, P2PDataStore
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
@ -27,7 +28,7 @@ class P2PLeakTxTest(BitcoinTestFramework):
miniwallet = MiniWallet(gen_node) miniwallet = MiniWallet(gen_node)
# Add enough mature utxos to the wallet, so that all txs spend confirmed coins # Add enough mature utxos to the wallet, so that all txs spend confirmed coins
miniwallet.generate(1) miniwallet.generate(1)
gen_node.generate(100) gen_node.generate(COINBASE_MATURITY)
inbound_peer = self.nodes[0].add_p2p_connection(P2PNode()) # An "attacking" inbound peer inbound_peer = self.nodes[0].add_p2p_connection(P2PNode()) # An "attacking" inbound peer

View file

@ -9,6 +9,7 @@ import itertools
import json import json
import os import os
from test_framework.blocktools import COINBASE_MATURITY
from test_framework.authproxy import JSONRPCException from test_framework.authproxy import JSONRPCException
from test_framework.descriptors import descsum_create, drop_origins from test_framework.descriptors import descsum_create, drop_origins
from test_framework.key import ECPubKey, ECKey from test_framework.key import ECPubKey, ECKey
@ -109,7 +110,7 @@ class RpcCreateMultiSigTest(BitcoinTestFramework):
def checkbalances(self): def checkbalances(self):
node0, node1, node2 = self.nodes node0, node1, node2 = self.nodes
node0.generate(100) node0.generate(COINBASE_MATURITY)
self.sync_all() self.sync_all()
bal0 = node0.getbalance() bal0 = node0.getbalance()

View file

@ -4,6 +4,8 @@
# file COPYING or http://www.opensource.org/licenses/mit-license.php. # file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test the generation of UTXO snapshots using `dumptxoutset`. """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.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, assert_raises_rpc_error from test_framework.util import assert_equal, assert_raises_rpc_error
@ -21,7 +23,7 @@ class DumptxoutsetTest(BitcoinTestFramework):
node = self.nodes[0] node = self.nodes[0]
mocktime = node.getblockheader(node.getblockhash(0))['time'] + 1 mocktime = node.getblockheader(node.getblockhash(0))['time'] + 1
node.setmocktime(mocktime) node.setmocktime(mocktime)
node.generate(100) node.generate(COINBASE_MATURITY)
FILENAME = 'txoutset.dat' FILENAME = 'txoutset.dat'
out = node.dumptxoutset(FILENAME) out = node.dumptxoutset(FILENAME)

View file

@ -6,6 +6,8 @@
# #
# Test getblockstats rpc call # Test getblockstats rpc call
# #
from test_framework.blocktools import COINBASE_MATURITY
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import ( from test_framework.util import (
assert_equal, assert_equal,
@ -41,7 +43,7 @@ class GetblockstatsTest(BitcoinTestFramework):
def generate_test_data(self, filename): def generate_test_data(self, filename):
mocktime = 1525107225 mocktime = 1525107225
self.nodes[0].setmocktime(mocktime) self.nodes[0].setmocktime(mocktime)
self.nodes[0].generate(101) self.nodes[0].generate(COINBASE_MATURITY + 1)
address = self.nodes[0].get_deterministic_priv_key().address address = self.nodes[0].get_deterministic_priv_key().address
self.nodes[0].sendtoaddress(address=address, amount=10, subtractfeefromamount=True) self.nodes[0].sendtoaddress(address=address, amount=10, subtractfeefromamount=True)

View file

@ -11,6 +11,7 @@ from decimal import Decimal
from itertools import product from itertools import product
import time import time
from test_framework.blocktools import COINBASE_MATURITY
from test_framework.p2p import P2PInterface from test_framework.p2p import P2PInterface
import test_framework.messages import test_framework.messages
from test_framework.messages import ( from test_framework.messages import (
@ -53,7 +54,7 @@ class NetTest(BitcoinTestFramework):
self.wallet = MiniWallet(self.nodes[0]) self.wallet = MiniWallet(self.nodes[0])
self.wallet.generate(1) self.wallet.generate(1)
# Get out of IBD for the minfeefilter and getpeerinfo tests. # Get out of IBD for the minfeefilter and getpeerinfo tests.
self.nodes[0].generate(101) self.nodes[0].generate(COINBASE_MATURITY + 1)
# By default, the test framework sets up an addnode connection from # By default, the test framework sets up an addnode connection from
# node 1 --> node0. By connecting node0 --> node 1, we're left with # node 1 --> node0. By connecting node0 --> node 1, we're left with

View file

@ -15,6 +15,8 @@ Test the following RPCs:
from collections import OrderedDict from collections import OrderedDict
from decimal import Decimal from decimal import Decimal
from io import BytesIO from io import BytesIO
from test_framework.blocktools import COINBASE_MATURITY
from test_framework.messages import CTransaction, ToHex from test_framework.messages import CTransaction, ToHex
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import ( from test_framework.util import (
@ -66,7 +68,7 @@ class RawTransactionsTest(BitcoinTestFramework):
self.log.info('prepare some coins for multiple *rawtransaction commands') self.log.info('prepare some coins for multiple *rawtransaction commands')
self.nodes[2].generate(1) self.nodes[2].generate(1)
self.sync_all() self.sync_all()
self.nodes[0].generate(101) self.nodes[0].generate(COINBASE_MATURITY + 1)
self.sync_all() self.sync_all()
self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(),1.5) self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(),1.5)
self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(),1.0) self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(),1.0)

View file

@ -4,6 +4,7 @@
# file COPYING or http://www.opensource.org/licenses/mit-license.php. # file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test transaction signing using the signrawtransaction* RPCs.""" """Test transaction signing using the signrawtransaction* RPCs."""
from test_framework.blocktools import COINBASE_MATURITY
from test_framework.address import check_script, script_to_p2sh, script_to_p2wsh from test_framework.address import check_script, script_to_p2sh, script_to_p2wsh
from test_framework.key import ECKey from test_framework.key import ECKey
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
@ -155,7 +156,7 @@ class SignRawTransactionsTest(BitcoinTestFramework):
def test_fully_signed_tx(self): def test_fully_signed_tx(self):
self.log.info("Test signing a fully signed transaction does nothing") self.log.info("Test signing a fully signed transaction does nothing")
self.nodes[0].walletpassphrase("password", 9999) self.nodes[0].walletpassphrase("password", 9999)
self.nodes[0].generate(101) self.nodes[0].generate(COINBASE_MATURITY + 1)
rawtx = self.nodes[0].createrawtransaction([], [{self.nodes[0].getnewaddress(): 10}]) rawtx = self.nodes[0].createrawtransaction([], [{self.nodes[0].getnewaddress(): 10}])
fundedtx = self.nodes[0].fundrawtransaction(rawtx) fundedtx = self.nodes[0].fundrawtransaction(rawtx)
signedtx = self.nodes[0].signrawtransactionwithwallet(fundedtx["hex"]) signedtx = self.nodes[0].signrawtransactionwithwallet(fundedtx["hex"])
@ -174,7 +175,7 @@ class SignRawTransactionsTest(BitcoinTestFramework):
embedded_pubkey = eckey.get_pubkey().get_bytes().hex() embedded_pubkey = eckey.get_pubkey().get_bytes().hex()
p2sh_p2wsh_address = self.nodes[1].createmultisig(1, [embedded_pubkey], "p2sh-segwit") p2sh_p2wsh_address = self.nodes[1].createmultisig(1, [embedded_pubkey], "p2sh-segwit")
# send transaction to P2SH-P2WSH 1-of-1 multisig address # send transaction to P2SH-P2WSH 1-of-1 multisig address
self.nodes[0].generate(101) self.nodes[0].generate(COINBASE_MATURITY + 1)
self.nodes[0].sendtoaddress(p2sh_p2wsh_address["address"], 49.999) self.nodes[0].sendtoaddress(p2sh_p2wsh_address["address"], 49.999)
self.nodes[0].generate(1) self.nodes[0].generate(1)
self.sync_all() self.sync_all()

View file

@ -4,6 +4,7 @@
# file COPYING or http://www.opensource.org/licenses/mit-license.php. # file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test gettxoutproof and verifytxoutproof RPCs.""" """Test gettxoutproof and verifytxoutproof RPCs."""
from test_framework.blocktools import COINBASE_MATURITY
from test_framework.messages import CMerkleBlock, FromHex, ToHex from test_framework.messages import CMerkleBlock, FromHex, ToHex
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, assert_raises_rpc_error from test_framework.util import assert_equal, assert_raises_rpc_error
@ -23,7 +24,7 @@ class MerkleBlockTest(BitcoinTestFramework):
miniwallet = MiniWallet(self.nodes[0]) miniwallet = MiniWallet(self.nodes[0])
# Add enough mature utxos to the wallet, so that all txs spend confirmed coins # Add enough mature utxos to the wallet, so that all txs spend confirmed coins
miniwallet.generate(5) miniwallet.generate(5)
self.nodes[0].generate(100) self.nodes[0].generate(COINBASE_MATURITY)
self.sync_all() self.sync_all()
chain_height = self.nodes[1].getblockcount() chain_height = self.nodes[1].getblockcount()

View file

@ -52,6 +52,9 @@ MAX_BLOCK_SIGOPS_WEIGHT = MAX_BLOCK_SIGOPS * WITNESS_SCALE_FACTOR
# Genesis block time (regtest) # Genesis block time (regtest)
TIME_GENESIS_BLOCK = 1296688602 TIME_GENESIS_BLOCK = 1296688602
# Coinbase transaction outputs can only be spent after this number of new blocks (network rule)
COINBASE_MATURITY = 100
# From BIP141 # From BIP141
WITNESS_COMMITMENT_HEADER = b"\xaa\x21\xa9\xed" WITNESS_COMMITMENT_HEADER = b"\xaa\x21\xa9\xed"

View file

@ -12,6 +12,7 @@
""" """
from decimal import Decimal from decimal import Decimal
from test_framework.blocktools import COINBASE_MATURITY
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import ( from test_framework.util import (
assert_equal, assert_equal,
@ -28,7 +29,7 @@ class AbandonConflictTest(BitcoinTestFramework):
self.skip_if_no_wallet() self.skip_if_no_wallet()
def run_test(self): def run_test(self):
self.nodes[1].generate(100) self.nodes[1].generate(COINBASE_MATURITY)
self.sync_blocks() self.sync_blocks()
balance = self.nodes[0].getbalance() balance = self.nodes[0].getbalance()
txA = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), Decimal("10")) txA = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), Decimal("10"))

View file

@ -53,6 +53,7 @@ Test that the nodes generate the correct change address type:
from decimal import Decimal from decimal import Decimal
import itertools import itertools
from test_framework.blocktools import COINBASE_MATURITY
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.descriptors import ( from test_framework.descriptors import (
descsum_create, descsum_create,
@ -220,7 +221,7 @@ class AddressTypeTest(BitcoinTestFramework):
def run_test(self): def run_test(self):
# Mine 101 blocks on node5 to bring nodes out of IBD and make sure that # Mine 101 blocks on node5 to bring nodes out of IBD and make sure that
# no coinbases are maturing for the nodes-under-test during the test # no coinbases are maturing for the nodes-under-test during the test
self.nodes[5].generate(101) self.nodes[5].generate(COINBASE_MATURITY + 1)
self.sync_blocks() self.sync_blocks()
uncompressed_1 = "0496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52da7589379515d4e0a604f8141781e62294721166bf621e73a82cbf2342c858ee" uncompressed_1 = "0496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52da7589379515d4e0a604f8141781e62294721166bf621e73a82cbf2342c858ee"
@ -258,7 +259,7 @@ class AddressTypeTest(BitcoinTestFramework):
self.log.info("Sending from node {} ({}) with{} multisig using {}".format(from_node, self.extra_args[from_node], "" if multisig else "out", "default" if address_type is None else address_type)) self.log.info("Sending from node {} ({}) with{} multisig using {}".format(from_node, self.extra_args[from_node], "" if multisig else "out", "default" if address_type is None else address_type))
old_balances = self.get_balances() old_balances = self.get_balances()
self.log.debug("Old balances are {}".format(old_balances)) self.log.debug("Old balances are {}".format(old_balances))
to_send = (old_balances[from_node] / 101).quantize(Decimal("0.00000001")) to_send = (old_balances[from_node] / (COINBASE_MATURITY + 1)).quantize(Decimal("0.00000001"))
sends = {} sends = {}
addresses = {} addresses = {}

View file

@ -35,6 +35,7 @@ import os
from random import randint from random import randint
import shutil import shutil
from test_framework.blocktools import COINBASE_MATURITY
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import ( from test_framework.util import (
assert_equal, assert_equal,
@ -123,7 +124,7 @@ class WalletBackupTest(BitcoinTestFramework):
self.sync_blocks() self.sync_blocks()
self.nodes[2].generate(1) self.nodes[2].generate(1)
self.sync_blocks() self.sync_blocks()
self.nodes[3].generate(100) self.nodes[3].generate(COINBASE_MATURITY)
self.sync_blocks() self.sync_blocks()
assert_equal(self.nodes[0].getbalance(), 50) assert_equal(self.nodes[0].getbalance(), 50)
@ -152,7 +153,7 @@ class WalletBackupTest(BitcoinTestFramework):
self.do_one_round() self.do_one_round()
# Generate 101 more blocks, so any fees paid mature # Generate 101 more blocks, so any fees paid mature
self.nodes[3].generate(101) self.nodes[3].generate(COINBASE_MATURITY + 1)
self.sync_all() self.sync_all()
balance0 = self.nodes[0].getbalance() balance0 = self.nodes[0].getbalance()

View file

@ -7,6 +7,7 @@ from decimal import Decimal
import struct import struct
from test_framework.address import ADDRESS_BCRT1_UNSPENDABLE as ADDRESS_WATCHONLY 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.test_framework import BitcoinTestFramework
from test_framework.util import ( from test_framework.util import (
assert_equal, assert_equal,
@ -72,7 +73,7 @@ class WalletTest(BitcoinTestFramework):
self.nodes[0].generate(1) self.nodes[0].generate(1)
self.sync_all() self.sync_all()
self.nodes[1].generate(1) self.nodes[1].generate(1)
self.nodes[1].generatetoaddress(101, ADDRESS_WATCHONLY) self.nodes[1].generatetoaddress(COINBASE_MATURITY + 1, ADDRESS_WATCHONLY)
self.sync_all() self.sync_all()
if not self.options.descriptors: if not self.options.descriptors:

View file

@ -6,6 +6,7 @@
from decimal import Decimal from decimal import Decimal
from itertools import product from itertools import product
from test_framework.blocktools import COINBASE_MATURITY
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import ( from test_framework.util import (
assert_array_result, assert_array_result,
@ -65,7 +66,7 @@ class WalletTest(BitcoinTestFramework):
assert_equal(walletinfo['balance'], 0) assert_equal(walletinfo['balance'], 0)
self.sync_all(self.nodes[0:3]) 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]) self.sync_all(self.nodes[0:3])
assert_equal(self.nodes[0].getbalance(), 50) assert_equal(self.nodes[0].getbalance(), 50)
@ -158,7 +159,7 @@ class WalletTest(BitcoinTestFramework):
assert_equal(len(self.nodes[1].listlockunspent()), 0) assert_equal(len(self.nodes[1].listlockunspent()), 0)
# Have node1 generate 100 blocks (so node0 can recover the fee) # 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]) self.sync_all(self.nodes[0:3])
# node0 should end up with 100 btc in block rewards plus fees, but # node0 should end up with 100 btc in block rewards plus fees, but

View file

@ -16,6 +16,7 @@ make assumptions about execution order.
from decimal import Decimal from decimal import Decimal
import io import io
from test_framework.blocktools import COINBASE_MATURITY
from test_framework.blocktools import add_witness_commitment, create_block, create_coinbase, send_to_witness from test_framework.blocktools import add_witness_commitment, create_block, create_coinbase, send_to_witness
from test_framework.messages import BIP125_SEQUENCE_NUMBER, CTransaction from test_framework.messages import BIP125_SEQUENCE_NUMBER, CTransaction
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
@ -265,7 +266,7 @@ def test_small_output_with_feerate_succeeds(self, rbf_node, dest_address):
self.log.info('Testing small output with feerate bump succeeds') self.log.info('Testing small output with feerate bump succeeds')
# Make sure additional inputs exist # Make sure additional inputs exist
rbf_node.generatetoaddress(101, rbf_node.getnewaddress()) rbf_node.generatetoaddress(COINBASE_MATURITY + 1, rbf_node.getnewaddress())
rbfid = spend_one_input(rbf_node, dest_address) rbfid = spend_one_input(rbf_node, dest_address)
input_list = rbf_node.getrawtransaction(rbfid, 1)["vin"] input_list = rbf_node.getrawtransaction(rbfid, 1)["vin"]
assert_equal(len(input_list), 1) assert_equal(len(input_list), 1)

View file

@ -4,6 +4,7 @@
# file COPYING or http://www.opensource.org/licenses/mit-license.php. # file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test descriptor wallet function.""" """Test descriptor wallet function."""
from test_framework.blocktools import COINBASE_MATURITY
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import ( from test_framework.util import (
assert_equal, assert_equal,
@ -83,7 +84,7 @@ class WalletDescriptorTest(BitcoinTestFramework):
send_wrpc = self.nodes[0].get_wallet_rpc("desc1") send_wrpc = self.nodes[0].get_wallet_rpc("desc1")
# Generate some coins # Generate some coins
send_wrpc.generatetoaddress(101, send_wrpc.getnewaddress()) send_wrpc.generatetoaddress(COINBASE_MATURITY + 1, send_wrpc.getnewaddress())
# Make transactions # Make transactions
self.log.info("Test sending and receiving") self.log.info("Test sending and receiving")

View file

@ -3,6 +3,8 @@
# Distributed under the MIT software license, see the accompanying # Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php. # file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test wallet replace-by-fee capabilities in conjunction with the fallbackfee.""" """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.test_framework import BitcoinTestFramework
from test_framework.util import assert_raises_rpc_error from test_framework.util import assert_raises_rpc_error
@ -15,7 +17,7 @@ class WalletRBFTest(BitcoinTestFramework):
self.skip_if_no_wallet() self.skip_if_no_wallet()
def run_test(self): 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 # sending a transaction without fee estimations must be possible by default on regtest
self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1) self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1)

View file

@ -4,6 +4,7 @@
# file COPYING or http://www.opensource.org/licenses/mit-license.php. # file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test wallet group functionality.""" """Test wallet group functionality."""
from test_framework.blocktools import COINBASE_MATURITY
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.messages import CTransaction, FromHex, ToHex from test_framework.messages import CTransaction, FromHex, ToHex
from test_framework.util import ( from test_framework.util import (
@ -31,7 +32,7 @@ class WalletGroupTest(BitcoinTestFramework):
def run_test(self): def run_test(self):
self.log.info("Setting up") self.log.info("Setting up")
# Mine some coins # Mine some coins
self.nodes[0].generate(101) self.nodes[0].generate(COINBASE_MATURITY + 1)
# Get some addresses from the two nodes # Get some addresses from the two nodes
addr1 = [self.nodes[1].getnewaddress() for _ in range(3)] addr1 = [self.nodes[1].getnewaddress() for _ in range(3)]

View file

@ -7,6 +7,7 @@
import os import os
import shutil import shutil
from test_framework.blocktools import COINBASE_MATURITY
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import ( from test_framework.util import (
assert_equal, assert_equal,
@ -48,7 +49,7 @@ class WalletHDTest(BitcoinTestFramework):
# Derive some HD addresses and remember the last # Derive some HD addresses and remember the last
# Also send funds to each add # Also send funds to each add
self.nodes[0].generate(101) self.nodes[0].generate(COINBASE_MATURITY + 1)
hd_add = None hd_add = None
NUM_HD_ADDS = 10 NUM_HD_ADDS = 10
for i in range(1, NUM_HD_ADDS + 1): for i in range(1, NUM_HD_ADDS + 1):

View file

@ -16,6 +16,7 @@ variants.
and test the values returned.""" and test the values returned."""
from test_framework.address import key_to_p2pkh from test_framework.address import key_to_p2pkh
from test_framework.blocktools import COINBASE_MATURITY
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.descriptors import descsum_create from test_framework.descriptors import descsum_create
from test_framework.util import ( from test_framework.util import (
@ -73,7 +74,7 @@ class ImportDescriptorsTest(BitcoinTestFramework):
assert_equal(wpriv.getwalletinfo()['keypoolsize'], 0) assert_equal(wpriv.getwalletinfo()['keypoolsize'], 0)
self.log.info('Mining coins') self.log.info('Mining coins')
w0.generatetoaddress(101, w0.getnewaddress()) w0.generatetoaddress(COINBASE_MATURITY + 1, w0.getnewaddress())
# RPC importdescriptors ----------------------------------------------- # RPC importdescriptors -----------------------------------------------

View file

@ -15,6 +15,7 @@ variants.
- `test_address()` is called to call getaddressinfo for an address on node1 - `test_address()` is called to call getaddressinfo for an address on node1
and test the values returned.""" and test the values returned."""
from test_framework.blocktools import COINBASE_MATURITY
from test_framework.script import ( from test_framework.script import (
CScript, CScript,
OP_NOP, OP_NOP,
@ -255,7 +256,7 @@ class ImportMultiTest(BitcoinTestFramework):
# P2SH address # P2SH address
multisig = get_multisig(self.nodes[0]) 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].sendtoaddress(multisig.p2sh_addr, 10.00)
self.nodes[1].generate(1) self.nodes[1].generate(1)
timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime'] timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime']
@ -276,7 +277,7 @@ class ImportMultiTest(BitcoinTestFramework):
# P2SH + Redeem script # P2SH + Redeem script
multisig = get_multisig(self.nodes[0]) 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].sendtoaddress(multisig.p2sh_addr, 10.00)
self.nodes[1].generate(1) self.nodes[1].generate(1)
timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime'] timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime']
@ -297,7 +298,7 @@ class ImportMultiTest(BitcoinTestFramework):
# P2SH + Redeem script + Private Keys + !Watchonly # P2SH + Redeem script + Private Keys + !Watchonly
multisig = get_multisig(self.nodes[0]) 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].sendtoaddress(multisig.p2sh_addr, 10.00)
self.nodes[1].generate(1) self.nodes[1].generate(1)
timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime'] timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime']
@ -323,7 +324,7 @@ class ImportMultiTest(BitcoinTestFramework):
# P2SH + Redeem script + Private Keys + Watchonly # P2SH + Redeem script + Private Keys + Watchonly
multisig = get_multisig(self.nodes[0]) 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].sendtoaddress(multisig.p2sh_addr, 10.00)
self.nodes[1].generate(1) self.nodes[1].generate(1)
timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime'] timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime']

View file

@ -5,6 +5,7 @@
"""Test the importprunedfunds and removeprunedfunds RPCs.""" """Test the importprunedfunds and removeprunedfunds RPCs."""
from decimal import Decimal from decimal import Decimal
from test_framework.blocktools import COINBASE_MATURITY
from test_framework.address import key_to_p2wpkh from test_framework.address import key_to_p2wpkh
from test_framework.key import ECKey from test_framework.key import ECKey
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
@ -24,7 +25,7 @@ class ImportPrunedFundsTest(BitcoinTestFramework):
def run_test(self): def run_test(self):
self.log.info("Mining blocks...") self.log.info("Mining blocks...")
self.nodes[0].generate(101) self.nodes[0].generate(COINBASE_MATURITY + 1)
self.sync_all() self.sync_all()
@ -46,7 +47,7 @@ class ImportPrunedFundsTest(BitcoinTestFramework):
self.sync_all() self.sync_all()
# Node 1 sync test # 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 Test - before import
address_info = self.nodes[1].getaddressinfo(address1) address_info = self.nodes[1].getaddressinfo(address1)

View file

@ -13,6 +13,7 @@ Two nodes. Node1 is under test. Node0 is providing transactions and generating b
import os import os
import shutil import shutil
from test_framework.blocktools import COINBASE_MATURITY
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import ( from test_framework.util import (
assert_equal, assert_equal,
@ -31,7 +32,7 @@ class KeypoolRestoreTest(BitcoinTestFramework):
def run_test(self): 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_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") 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.log.info("Make backup of wallet")
self.stop_node(1) self.stop_node(1)

View file

@ -11,6 +11,7 @@ RPCs tested are:
""" """
from collections import defaultdict from collections import defaultdict
from test_framework.blocktools import COINBASE_MATURITY
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, assert_raises_rpc_error from test_framework.util import assert_equal, assert_raises_rpc_error
from test_framework.wallet_util import test_address 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 # Note each time we call generate, all generated coins go into
# the same address, so we call twice to get two addresses w/50 each # the same address, so we call twice to get two addresses w/50 each
node.generatetoaddress(nblocks=1, address=node.getnewaddress(label='coinbase')) 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(), 100) assert_equal(node.getbalance(), 100)
# there should be 2 address groups # there should be 2 address groups
@ -104,7 +105,7 @@ class WalletLabelsTest(BitcoinTestFramework):
label.verify(node) label.verify(node)
assert_equal(node.getreceivedbylabel(label.name), 2) assert_equal(node.getreceivedbylabel(label.name), 2)
label.verify(node) label.verify(node)
node.generate(101) node.generate(COINBASE_MATURITY + 1)
# Check that setlabel can assign a label to a new unused address. # Check that setlabel can assign a label to a new unused address.
for label in labels: for label in labels:
@ -124,7 +125,7 @@ class WalletLabelsTest(BitcoinTestFramework):
label.add_address(multisig_address) label.add_address(multisig_address)
label.purpose[multisig_address] = "send" label.purpose[multisig_address] = "send"
label.verify(node) label.verify(node)
node.generate(101) node.generate(COINBASE_MATURITY + 1)
# Check that setlabel can change the label of an address from a # Check that setlabel can change the label of an address from a
# different label. # different label.

View file

@ -5,6 +5,7 @@
"""Test the listsinceblock RPC.""" """Test the listsinceblock RPC."""
from test_framework.address import key_to_p2wpkh from test_framework.address import key_to_p2wpkh
from test_framework.blocktools import COINBASE_MATURITY
from test_framework.key import ECKey from test_framework.key import ECKey
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.messages import BIP125_SEQUENCE_NUMBER from test_framework.messages import BIP125_SEQUENCE_NUMBER
@ -29,7 +30,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 # 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) # only one connection. (See fPreferredDownload in net_processing)
self.connect_nodes(1, 2) self.connect_nodes(1, 2)
self.nodes[2].generate(101) self.nodes[2].generate(COINBASE_MATURITY + 1)
self.sync_all() self.sync_all()
self.test_no_blockhash() self.test_no_blockhash()

View file

@ -14,6 +14,7 @@ import stat
import time import time
from test_framework.authproxy import JSONRPCException from test_framework.authproxy import JSONRPCException
from test_framework.blocktools import COINBASE_MATURITY
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.test_node import ErrorMatch from test_framework.test_node import ErrorMatch
from test_framework.util import ( from test_framework.util import (
@ -229,7 +230,7 @@ class MultiWalletTest(BitcoinTestFramework):
assert_raises_rpc_error(-19, "Wallet file not specified", node.getwalletinfo) assert_raises_rpc_error(-19, "Wallet file not specified", node.getwalletinfo)
w1, w2, w3, w4, *_ = wallets 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(), 100) assert_equal(w1.getbalance(), 100)
assert_equal(w2.getbalance(), 0) assert_equal(w2.getbalance(), 0)
assert_equal(w3.getbalance(), 0) assert_equal(w3.getbalance(), 0)

View file

@ -17,6 +17,7 @@ import struct
from io import BytesIO from io import BytesIO
from test_framework.blocktools import COINBASE_MATURITY
from test_framework.bdb import dump_bdb_kv from test_framework.bdb import dump_bdb_kv
from test_framework.messages import deser_compact_size, deser_string from test_framework.messages import deser_compact_size, deser_string
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
@ -118,11 +119,11 @@ class UpgradeWalletTest(BitcoinTestFramework):
assert_equal(wallet.getwalletinfo()["walletversion"], previous_version) assert_equal(wallet.getwalletinfo()["walletversion"], previous_version)
def run_test(self): 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() self.dumb_sync_blocks()
# # Sanity check the test framework: # # Sanity check the test framework:
res = self.nodes[0].getblockchaininfo() res = self.nodes[0].getblockchaininfo()
assert_equal(res['blocks'], 101) assert_equal(res['blocks'], COINBASE_MATURITY + 1)
node_master = self.nodes[0] node_master = self.nodes[0]
v16_3_node = self.nodes[1] v16_3_node = self.nodes[1]
v15_2_node = self.nodes[2] v15_2_node = self.nodes[2]
@ -130,7 +131,7 @@ class UpgradeWalletTest(BitcoinTestFramework):
# Send coins to old wallets for later conversion checks. # Send coins to old wallets for later conversion checks.
v16_3_wallet = v16_3_node.get_wallet_rpc('wallet.dat') v16_3_wallet = v16_3_node.get_wallet_rpc('wallet.dat')
v16_3_address = v16_3_wallet.getnewaddress() 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() self.dumb_sync_blocks()
v16_3_balance = v16_3_wallet.getbalance() v16_3_balance = v16_3_wallet.getbalance()

View file

@ -5,6 +5,7 @@
"""Test createwallet watchonly arguments. """Test createwallet watchonly arguments.
""" """
from test_framework.blocktools import COINBASE_MATURITY
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import ( from test_framework.util import (
assert_equal, assert_equal,
@ -36,7 +37,7 @@ class CreateWalletWatchonlyTest(BitcoinTestFramework):
wo_wallet.importpubkey(pubkey=def_wallet.getaddressinfo(wo_change)['pubkey']) wo_wallet.importpubkey(pubkey=def_wallet.getaddressinfo(wo_change)['pubkey'])
# generate some btc for testing # generate some btc for testing
node.generatetoaddress(101, a1) node.generatetoaddress(COINBASE_MATURITY + 1, a1)
# send 1 btc to our watch-only address # send 1 btc to our watch-only address
txid = def_wallet.sendtoaddress(wo_addr, 1) txid = def_wallet.sendtoaddress(wo_addr, 1)