0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-02 09:46:52 -05:00

Use generate* from TestFramework

The changes in feature_rbf can be reviewed with
--color-moved=dimmed-zebra --color-moved-ws=ignore-all-space
This commit is contained in:
MarcoFalke 2021-07-27 20:04:51 +02:00
parent faf7e92804
commit fab2e23b57
No known key found for this signature in database
GPG key ID: CE2B75697E69A548
14 changed files with 83 additions and 84 deletions

View file

@ -217,7 +217,7 @@ class ChainstateWriteCrashTest(BitcoinTestFramework):
# Start by creating a lot of utxos on node3 # Start by creating a lot of utxos on node3
initial_height = self.nodes[3].getblockcount() initial_height = self.nodes[3].getblockcount()
utxo_list = create_confirmed_utxos(self.nodes[3].getnetworkinfo()['relayfee'], self.nodes[3], 5000) utxo_list = create_confirmed_utxos(self, self.nodes[3].getnetworkinfo()['relayfee'], self.nodes[3], 5000)
self.log.info(f"Prepped {len(utxo_list)} utxo entries") self.log.info(f"Prepped {len(utxo_list)} utxo entries")
# Sync these blocks with the other nodes # Sync these blocks with the other nodes
@ -253,7 +253,8 @@ class ChainstateWriteCrashTest(BitcoinTestFramework):
self.log.debug("Mining longer tip") self.log.debug("Mining longer tip")
block_hashes = [] block_hashes = []
while current_height + 1 > self.nodes[3].getblockcount(): while current_height + 1 > self.nodes[3].getblockcount():
block_hashes.extend(self.nodes[3].generatetoaddress( block_hashes.extend(self.generatetoaddress(
self.nodes[3],
nblocks=min(10, current_height + 1 - self.nodes[3].getblockcount()), nblocks=min(10, current_height + 1 - self.nodes[3].getblockcount()),
# new address to avoid mining a block that has just been invalidated # new address to avoid mining a block that has just been invalidated
address=self.nodes[3].getnewaddress(), address=self.nodes[3].getnewaddress(),

View file

@ -67,7 +67,7 @@ class MaxUploadTest(BitcoinTestFramework):
p2p_conns.append(self.nodes[0].add_p2p_connection(TestP2PConn())) p2p_conns.append(self.nodes[0].add_p2p_connection(TestP2PConn()))
# Now mine a big block # Now mine a big block
mine_large_block(self.nodes[0], self.utxo_cache) mine_large_block(self, self.nodes[0], self.utxo_cache)
# Store the hash; we'll request this later # Store the hash; we'll request this later
big_old_block = self.nodes[0].getbestblockhash() big_old_block = self.nodes[0].getbestblockhash()
@ -78,7 +78,7 @@ class MaxUploadTest(BitcoinTestFramework):
self.nodes[0].setmocktime(int(time.time()) - 2*60*60*24) self.nodes[0].setmocktime(int(time.time()) - 2*60*60*24)
# Mine one more block, so that the prior block looks old # Mine one more block, so that the prior block looks old
mine_large_block(self.nodes[0], self.utxo_cache) mine_large_block(self, self.nodes[0], self.utxo_cache)
# We'll be requesting this new block too # We'll be requesting this new block too
big_new_block = self.nodes[0].getbestblockhash() big_new_block = self.nodes[0].getbestblockhash()

View file

@ -23,49 +23,6 @@ from test_framework.script_util import DUMMY_P2WPKH_SCRIPT, DUMMY_2_P2WPKH_SCRIP
from test_framework.wallet import MiniWallet from test_framework.wallet import MiniWallet
MAX_REPLACEMENT_LIMIT = 100 MAX_REPLACEMENT_LIMIT = 100
def make_utxo(node, amount, confirmed=True, scriptPubKey=DUMMY_P2WPKH_SCRIPT):
"""Create a txout with a given amount and scriptPubKey
Mines coins as needed.
confirmed - txouts created will be confirmed in the blockchain;
unconfirmed otherwise.
"""
fee = 1 * COIN
while node.getbalance() < satoshi_round((amount + fee) / COIN):
node.generate(COINBASE_MATURITY)
new_addr = node.getnewaddress()
txid = node.sendtoaddress(new_addr, satoshi_round((amount + fee) / COIN))
tx1 = node.getrawtransaction(txid, 1)
txid = int(txid, 16)
i, _ = next(filter(lambda vout: new_addr == vout[1]['scriptPubKey']['address'], enumerate(tx1['vout'])))
tx2 = CTransaction()
tx2.vin = [CTxIn(COutPoint(txid, i))]
tx2.vout = [CTxOut(amount, scriptPubKey)]
tx2.rehash()
signed_tx = node.signrawtransactionwithwallet(tx2.serialize().hex())
txid = node.sendrawtransaction(signed_tx['hex'], 0)
# If requested, ensure txouts are confirmed.
if confirmed:
mempool_size = len(node.getrawmempool())
while mempool_size > 0:
node.generate(1)
new_size = len(node.getrawmempool())
# Error out if we have something stuck in the mempool, as this
# would likely be a bug.
assert new_size < mempool_size
mempool_size = new_size
return COutPoint(int(txid, 16), 0)
class ReplaceByFeeTest(BitcoinTestFramework): class ReplaceByFeeTest(BitcoinTestFramework):
def set_test_params(self): def set_test_params(self):
self.num_nodes = 1 self.num_nodes = 1
@ -129,6 +86,46 @@ class ReplaceByFeeTest(BitcoinTestFramework):
self.log.info("Passed") self.log.info("Passed")
def make_utxo(self, node, amount, confirmed=True, scriptPubKey=DUMMY_P2WPKH_SCRIPT):
"""Create a txout with a given amount and scriptPubKey
Mines coins as needed.
confirmed - txouts created will be confirmed in the blockchain;
unconfirmed otherwise.
"""
fee = 1 * COIN
while node.getbalance() < satoshi_round((amount + fee) / COIN):
self.generate(node, COINBASE_MATURITY)
new_addr = node.getnewaddress()
txid = node.sendtoaddress(new_addr, satoshi_round((amount + fee) / COIN))
tx1 = node.getrawtransaction(txid, 1)
txid = int(txid, 16)
i, _ = next(filter(lambda vout: new_addr == vout[1]['scriptPubKey']['address'], enumerate(tx1['vout'])))
tx2 = CTransaction()
tx2.vin = [CTxIn(COutPoint(txid, i))]
tx2.vout = [CTxOut(amount, scriptPubKey)]
tx2.rehash()
signed_tx = node.signrawtransactionwithwallet(tx2.serialize().hex())
txid = node.sendrawtransaction(signed_tx['hex'], 0)
# If requested, ensure txouts are confirmed.
if confirmed:
mempool_size = len(node.getrawmempool())
while mempool_size > 0:
self.generate(node, 1)
new_size = len(node.getrawmempool())
# Error out if we have something stuck in the mempool, as this
# would likely be a bug.
assert new_size < mempool_size
mempool_size = new_size
return COutPoint(int(txid, 16), 0)
def test_simple_doublespend(self): def test_simple_doublespend(self):
"""Simple doublespend""" """Simple doublespend"""
# we use MiniWallet to create a transaction template with inputs correctly set, # we use MiniWallet to create a transaction template with inputs correctly set,
@ -165,7 +162,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
"""Doublespend of a long chain""" """Doublespend of a long chain"""
initial_nValue = 50 * COIN initial_nValue = 50 * COIN
tx0_outpoint = make_utxo(self.nodes[0], initial_nValue) tx0_outpoint = self.make_utxo(self.nodes[0], initial_nValue)
prevout = tx0_outpoint prevout = tx0_outpoint
remaining_value = initial_nValue remaining_value = initial_nValue
@ -205,7 +202,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
"""Doublespend of a big tree of transactions""" """Doublespend of a big tree of transactions"""
initial_nValue = 50 * COIN initial_nValue = 50 * COIN
tx0_outpoint = make_utxo(self.nodes[0], initial_nValue) tx0_outpoint = self.make_utxo(self.nodes[0], initial_nValue)
def branch(prevout, initial_value, max_txs, tree_width=5, fee=0.0001 * COIN, _total_txs=None): def branch(prevout, initial_value, max_txs, tree_width=5, fee=0.0001 * COIN, _total_txs=None):
if _total_txs is None: if _total_txs is None:
@ -268,7 +265,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
# double-spent at once" anti-DoS limit. # double-spent at once" anti-DoS limit.
for n in (MAX_REPLACEMENT_LIMIT + 1, MAX_REPLACEMENT_LIMIT * 2): for n in (MAX_REPLACEMENT_LIMIT + 1, MAX_REPLACEMENT_LIMIT * 2):
fee = int(0.0001 * COIN) fee = int(0.0001 * COIN)
tx0_outpoint = make_utxo(self.nodes[0], initial_nValue) tx0_outpoint = self.make_utxo(self.nodes[0], initial_nValue)
tree_txs = list(branch(tx0_outpoint, initial_nValue, n, fee=fee)) tree_txs = list(branch(tx0_outpoint, initial_nValue, n, fee=fee))
assert_equal(len(tree_txs), n) assert_equal(len(tree_txs), n)
@ -285,7 +282,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
def test_replacement_feeperkb(self): def test_replacement_feeperkb(self):
"""Replacement requires fee-per-KB to be higher""" """Replacement requires fee-per-KB to be higher"""
tx0_outpoint = make_utxo(self.nodes[0], int(1.1 * COIN)) tx0_outpoint = self.make_utxo(self.nodes[0], int(1.1 * COIN))
tx1a = CTransaction() tx1a = CTransaction()
tx1a.vin = [CTxIn(tx0_outpoint, nSequence=0)] tx1a.vin = [CTxIn(tx0_outpoint, nSequence=0)]
@ -305,8 +302,8 @@ class ReplaceByFeeTest(BitcoinTestFramework):
def test_spends_of_conflicting_outputs(self): def test_spends_of_conflicting_outputs(self):
"""Replacements that spend conflicting tx outputs are rejected""" """Replacements that spend conflicting tx outputs are rejected"""
utxo1 = make_utxo(self.nodes[0], int(1.2 * COIN)) utxo1 = self.make_utxo(self.nodes[0], int(1.2 * COIN))
utxo2 = make_utxo(self.nodes[0], 3 * COIN) utxo2 = self.make_utxo(self.nodes[0], 3 * COIN)
tx1a = CTransaction() tx1a = CTransaction()
tx1a.vin = [CTxIn(utxo1, nSequence=0)] tx1a.vin = [CTxIn(utxo1, nSequence=0)]
@ -345,8 +342,8 @@ class ReplaceByFeeTest(BitcoinTestFramework):
def test_new_unconfirmed_inputs(self): def test_new_unconfirmed_inputs(self):
"""Replacements that add new unconfirmed inputs are rejected""" """Replacements that add new unconfirmed inputs are rejected"""
confirmed_utxo = make_utxo(self.nodes[0], int(1.1 * COIN)) confirmed_utxo = self.make_utxo(self.nodes[0], int(1.1 * COIN))
unconfirmed_utxo = make_utxo(self.nodes[0], int(0.1 * COIN), False) unconfirmed_utxo = self.make_utxo(self.nodes[0], int(0.1 * COIN), False)
tx1 = CTransaction() tx1 = CTransaction()
tx1.vin = [CTxIn(confirmed_utxo)] tx1.vin = [CTxIn(confirmed_utxo)]
@ -369,7 +366,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
# Start by creating a single transaction with many outputs # Start by creating a single transaction with many outputs
initial_nValue = 10 * COIN initial_nValue = 10 * COIN
utxo = make_utxo(self.nodes[0], initial_nValue) utxo = self.make_utxo(self.nodes[0], initial_nValue)
fee = int(0.0001 * COIN) fee = int(0.0001 * COIN)
split_value = int((initial_nValue - fee) / (MAX_REPLACEMENT_LIMIT + 1)) split_value = int((initial_nValue - fee) / (MAX_REPLACEMENT_LIMIT + 1))
@ -417,7 +414,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
def test_opt_in(self): def test_opt_in(self):
"""Replacing should only work if orig tx opted in""" """Replacing should only work if orig tx opted in"""
tx0_outpoint = make_utxo(self.nodes[0], int(1.1 * COIN)) tx0_outpoint = self.make_utxo(self.nodes[0], int(1.1 * COIN))
# Create a non-opting in transaction # Create a non-opting in transaction
tx1a = CTransaction() tx1a = CTransaction()
@ -438,7 +435,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
# This will raise an exception # This will raise an exception
assert_raises_rpc_error(-26, "txn-mempool-conflict", self.nodes[0].sendrawtransaction, tx1b_hex, 0) assert_raises_rpc_error(-26, "txn-mempool-conflict", self.nodes[0].sendrawtransaction, tx1b_hex, 0)
tx1_outpoint = make_utxo(self.nodes[0], int(1.1 * COIN)) tx1_outpoint = self.make_utxo(self.nodes[0], int(1.1 * COIN))
# Create a different non-opting in transaction # Create a different non-opting in transaction
tx2a = CTransaction() tx2a = CTransaction()
@ -494,7 +491,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
# correctly used by replacement logic # correctly used by replacement logic
# 1. Check that feeperkb uses modified fees # 1. Check that feeperkb uses modified fees
tx0_outpoint = make_utxo(self.nodes[0], int(1.1 * COIN)) tx0_outpoint = self.make_utxo(self.nodes[0], int(1.1 * COIN))
tx1a = CTransaction() tx1a = CTransaction()
tx1a.vin = [CTxIn(tx0_outpoint, nSequence=0)] tx1a.vin = [CTxIn(tx0_outpoint, nSequence=0)]
@ -520,7 +517,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
assert tx1b_txid in self.nodes[0].getrawmempool() assert tx1b_txid in self.nodes[0].getrawmempool()
# 2. Check that absolute fee checks use modified fee. # 2. Check that absolute fee checks use modified fee.
tx1_outpoint = make_utxo(self.nodes[0], int(1.1 * COIN)) tx1_outpoint = self.make_utxo(self.nodes[0], int(1.1 * COIN))
tx2a = CTransaction() tx2a = CTransaction()
tx2a.vin = [CTxIn(tx1_outpoint, nSequence=0)] tx2a.vin = [CTxIn(tx1_outpoint, nSequence=0)]

View file

@ -82,8 +82,8 @@ class ZMQTestSetupBlock:
raw transaction data. raw transaction data.
""" """
def __init__(self, node): def __init__(self, test_framework, node):
self.block_hash = node.generate(1)[0] self.block_hash = test_framework.generate(node, 1)[0]
coinbase = node.getblock(self.block_hash, 2)['tx'][0] coinbase = node.getblock(self.block_hash, 2)['tx'][0]
self.tx_hash = coinbase['txid'] self.tx_hash = coinbase['txid']
self.raw_tx = coinbase['hex'] self.raw_tx = coinbase['hex']
@ -147,7 +147,7 @@ class ZMQTest (BitcoinTestFramework):
for sub in subscribers: for sub in subscribers:
sub.socket.set(zmq.RCVTIMEO, 1000) sub.socket.set(zmq.RCVTIMEO, 1000)
while True: while True:
test_block = ZMQTestSetupBlock(self.nodes[0]) test_block = ZMQTestSetupBlock(self, self.nodes[0])
recv_failed = False recv_failed = False
for sub in subscribers: for sub in subscribers:
try: try:

View file

@ -32,7 +32,7 @@ class MempoolLimitTest(BitcoinTestFramework):
assert_equal(self.nodes[0].getmempoolinfo()['mempoolminfee'], Decimal('0.00001000')) assert_equal(self.nodes[0].getmempoolinfo()['mempoolminfee'], Decimal('0.00001000'))
txids = [] txids = []
utxos = create_confirmed_utxos(relayfee, self.nodes[0], 91) utxos = create_confirmed_utxos(self, relayfee, self.nodes[0], 91)
self.log.info('Create a mempool tx that will be evicted') self.log.info('Create a mempool tx that will be evicted')
us0 = utxos.pop() us0 = utxos.pop()

View file

@ -32,7 +32,7 @@ class MempoolUnbroadcastTest(BitcoinTestFramework):
node = self.nodes[0] node = self.nodes[0]
min_relay_fee = node.getnetworkinfo()["relayfee"] min_relay_fee = node.getnetworkinfo()["relayfee"]
utxos = create_confirmed_utxos(min_relay_fee, node, 10) utxos = create_confirmed_utxos(self, min_relay_fee, node, 10)
self.disconnect_nodes(0, 1) self.disconnect_nodes(0, 1)

View file

@ -48,9 +48,9 @@ class GetBlockTemplateLPTest(BitcoinTestFramework):
thr.join(5) # wait 5 seconds or until thread exits thr.join(5) # wait 5 seconds or until thread exits
assert thr.is_alive() assert thr.is_alive()
miniwallets = [ MiniWallet(node) for node in self.nodes ] miniwallets = [MiniWallet(node) for node in self.nodes]
self.log.info("Test that longpoll will terminate if another node generates a block") self.log.info("Test that longpoll will terminate if another node generates a block")
miniwallets[1].generate(1) # generate a block on another node self.generate(miniwallets[1], 1) # generate a block on another node
# check that thread will exit now that new transaction entered mempool # check that thread will exit now that new transaction entered mempool
thr.join(5) # wait 5 seconds or until thread exits thr.join(5) # wait 5 seconds or until thread exits
assert not thr.is_alive() assert not thr.is_alive()
@ -58,7 +58,7 @@ class GetBlockTemplateLPTest(BitcoinTestFramework):
self.log.info("Test that longpoll will terminate if we generate a block ourselves") self.log.info("Test that longpoll will terminate if we generate a block ourselves")
thr = LongpollThread(self.nodes[0]) thr = LongpollThread(self.nodes[0])
thr.start() thr.start()
miniwallets[0].generate(1) # generate a block on own node self.generate(miniwallets[0], 1) # generate a block on own node
thr.join(5) # wait 5 seconds or until thread exits thr.join(5) # wait 5 seconds or until thread exits
assert not thr.is_alive() assert not thr.is_alive()

View file

@ -48,7 +48,7 @@ class PrioritiseTransactionTest(BitcoinTestFramework):
self.relayfee = self.nodes[0].getnetworkinfo()['relayfee'] self.relayfee = self.nodes[0].getnetworkinfo()['relayfee']
utxo_count = 90 utxo_count = 90
utxos = create_confirmed_utxos(self.relayfee, self.nodes[0], utxo_count) utxos = create_confirmed_utxos(self, self.relayfee, self.nodes[0], utxo_count)
base_fee = self.relayfee*100 # our transactions are smaller than 100kb base_fee = self.relayfee*100 # our transactions are smaller than 100kb
txids = [] txids = []

View file

@ -77,7 +77,7 @@ class AcceptBlockTest(BitcoinTestFramework):
min_work_node = self.nodes[1].add_p2p_connection(P2PInterface()) min_work_node = self.nodes[1].add_p2p_connection(P2PInterface())
# 1. Have nodes mine a block (leave IBD) # 1. Have nodes mine a block (leave IBD)
[n.generatetoaddress(1, n.get_deterministic_priv_key().address) for n in self.nodes] [self.generatetoaddress(n, 1, n.get_deterministic_priv_key().address) for n in self.nodes]
tips = [int("0x" + n.getbestblockhash(), 0) for n in self.nodes] tips = [int("0x" + n.getbestblockhash(), 0) for n in self.nodes]
# 2. Send one block that builds on each tip. # 2. Send one block that builds on each tip.

View file

@ -274,7 +274,7 @@ class SignRawTransactionsTest(BitcoinTestFramework):
getcontext().prec = 8 getcontext().prec = 8
# Make sure CSV is active # Make sure CSV is active
generate_to_height(self.nodes[0], CSV_ACTIVATION_HEIGHT) generate_to_height(self, self.nodes[0], CSV_ACTIVATION_HEIGHT)
assert self.nodes[0].getblockchaininfo()['softforks']['csv']['active'] assert self.nodes[0].getblockchaininfo()['softforks']['csv']['active']
# Create a P2WSH script with CSV # Create a P2WSH script with CSV
@ -310,7 +310,7 @@ class SignRawTransactionsTest(BitcoinTestFramework):
getcontext().prec = 8 getcontext().prec = 8
# Make sure CLTV is active # Make sure CLTV is active
generate_to_height(self.nodes[0], CLTV_HEIGHT) generate_to_height(self, self.nodes[0], CLTV_HEIGHT)
assert self.nodes[0].getblockchaininfo()['softforks']['bip65']['active'] assert self.nodes[0].getblockchaininfo()['softforks']['bip65']['active']
# Create a P2WSH script with CLTV # Create a P2WSH script with CLTV

View file

@ -410,7 +410,7 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
# To ensure that all nodes are out of IBD, the most recent block # To ensure that all nodes are out of IBD, the most recent block
# must have a timestamp not too old (see IsInitialBlockDownload()). # must have a timestamp not too old (see IsInitialBlockDownload()).
self.log.debug('Generate a block with current time') self.log.debug('Generate a block with current time')
block_hash = self.nodes[0].generate(1)[0] block_hash = self.generate(self.nodes[0], 1)[0]
block = self.nodes[0].getblock(blockhash=block_hash, verbosity=0) block = self.nodes[0].getblock(blockhash=block_hash, verbosity=0)
for n in self.nodes: for n in self.nodes:
n.submitblock(block) n.submitblock(block)
@ -765,7 +765,8 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
gen_addresses = [k.address for k in TestNode.PRIV_KEYS][:3] + [ADDRESS_BCRT1_P2WSH_OP_TRUE] gen_addresses = [k.address for k in TestNode.PRIV_KEYS][:3] + [ADDRESS_BCRT1_P2WSH_OP_TRUE]
assert_equal(len(gen_addresses), 4) assert_equal(len(gen_addresses), 4)
for i in range(8): for i in range(8):
cache_node.generatetoaddress( self.generatetoaddress(
cache_node,
nblocks=25 if i != 7 else 24, nblocks=25 if i != 7 else 24,
address=gen_addresses[i % len(gen_addresses)], address=gen_addresses[i % len(gen_addresses)],
) )

View file

@ -445,10 +445,10 @@ def find_output(node, txid, amount, *, blockhash=None):
# Helper to create at least "count" utxos # Helper to create at least "count" utxos
# Pass in a fee that is sufficient for relay and mining new transactions. # Pass in a fee that is sufficient for relay and mining new transactions.
def create_confirmed_utxos(fee, node, count): def create_confirmed_utxos(test_framework, fee, node, count):
to_generate = int(0.5 * count) + 101 to_generate = int(0.5 * count) + 101
while to_generate > 0: while to_generate > 0:
node.generate(min(25, to_generate)) test_framework.generate(node, min(25, to_generate))
to_generate -= 25 to_generate -= 25
utxos = node.listunspent() utxos = node.listunspent()
iterations = count - len(utxos) iterations = count - len(utxos)
@ -469,7 +469,7 @@ def create_confirmed_utxos(fee, node, count):
node.sendrawtransaction(signed_tx) node.sendrawtransaction(signed_tx)
while (node.getmempoolinfo()['size'] > 0): while (node.getmempoolinfo()['size'] > 0):
node.generate(1) test_framework.generate(node, 1)
utxos = node.listunspent() utxos = node.listunspent()
assert len(utxos) >= count assert len(utxos) >= count
@ -541,7 +541,7 @@ def create_lots_of_big_transactions(node, txouts, utxos, num, fee):
return txids return txids
def mine_large_block(node, utxos=None): def mine_large_block(test_framework, node, utxos=None):
# generate a 66k transaction, # generate a 66k transaction,
# and 14 of them is close to the 1MB block limit # and 14 of them is close to the 1MB block limit
num = 14 num = 14
@ -552,17 +552,17 @@ def mine_large_block(node, utxos=None):
utxos.extend(node.listunspent()) utxos.extend(node.listunspent())
fee = 100 * node.getnetworkinfo()["relayfee"] fee = 100 * node.getnetworkinfo()["relayfee"]
create_lots_of_big_transactions(node, txouts, utxos, num, fee=fee) create_lots_of_big_transactions(node, txouts, utxos, num, fee=fee)
node.generate(1) test_framework.generate(node, 1)
def generate_to_height(node, target_height): def generate_to_height(test_framework, node, target_height):
"""Generates blocks until a given target block height has been reached. """Generates blocks until a given target block height has been reached.
To prevent timeouts, only up to 200 blocks are generated per RPC call. To prevent timeouts, only up to 200 blocks are generated per RPC call.
Can be used to activate certain soft-forks (e.g. CSV, CLTV).""" Can be used to activate certain soft-forks (e.g. CSV, CLTV)."""
current_height = node.getblockcount() current_height = node.getblockcount()
while current_height < target_height: while current_height < target_height:
nblocks = min(200, target_height - current_height) nblocks = min(200, target_height - current_height)
current_height += len(node.generate(nblocks)) current_height += len(test_framework.generate(node, nblocks))
assert_equal(node.getblockcount(), target_height) assert_equal(node.getblockcount(), target_height)

View file

@ -84,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(COINBASE_MATURITY + 1, send_wrpc.getnewaddress()) self.generatetoaddress(send_wrpc, 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

@ -74,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(COINBASE_MATURITY + 1, w0.getnewaddress()) self.generatetoaddress(w0, COINBASE_MATURITY + 1, w0.getnewaddress())
# RPC importdescriptors ----------------------------------------------- # RPC importdescriptors -----------------------------------------------
@ -405,7 +405,7 @@ class ImportDescriptorsTest(BitcoinTestFramework):
solvable=True, solvable=True,
ismine=True) ismine=True)
txid = w0.sendtoaddress(address, 49.99995540) txid = w0.sendtoaddress(address, 49.99995540)
w0.generatetoaddress(6, w0.getnewaddress()) self.generatetoaddress(w0, 6, w0.getnewaddress())
self.sync_blocks() self.sync_blocks()
tx = wpriv.createrawtransaction([{"txid": txid, "vout": 0}], {w0.getnewaddress(): 49.999}) tx = wpriv.createrawtransaction([{"txid": txid, "vout": 0}], {w0.getnewaddress(): 49.999})
signed_tx = wpriv.signrawtransactionwithwallet(tx) signed_tx = wpriv.signrawtransactionwithwallet(tx)