test: introduce `generate_to_height` helper, use in rpc_signrawtransaction

This will speed up the test a bit and avoid potential .generate() RPC
timeouts (in sub-test `test_signing_with_cltv()`) on slower machines.
pull/826/head
Sebastian Falbesoner 3 years ago
parent e3237b1cd0
commit 746f203f19

@ -15,6 +15,7 @@ from test_framework.util import (
assert_equal,
assert_raises_rpc_error,
find_vout_for_address,
generate_to_height,
hex_str_to_bytes,
)
from test_framework.messages import (
@ -270,7 +271,7 @@ class SignRawTransactionsTest(BitcoinTestFramework):
getcontext().prec = 8
# Make sure CSV is active
self.nodes[0].generate(500)
generate_to_height(self.nodes[0], 500)
assert self.nodes[0].getblockchaininfo()['softforks']['csv']['active']
# Create a P2WSH script with CSV
@ -306,7 +307,7 @@ class SignRawTransactionsTest(BitcoinTestFramework):
getcontext().prec = 8
# Make sure CLTV is active
self.nodes[0].generate(1500)
generate_to_height(self.nodes[0], 1500)
assert self.nodes[0].getblockchaininfo()['softforks']['bip65']['active']
# Create a P2WSH script with CLTV

@ -559,6 +559,17 @@ def mine_large_block(node, utxos=None):
node.generate(1)
def generate_to_height(node, target_height):
"""Generates blocks until a given target block height has been reached.
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)."""
current_height = node.getblockcount()
while current_height < target_height:
nblocks = min(200, target_height - current_height)
current_height += len(node.generate(nblocks))
assert_equal(node.getblockcount(), target_height)
def find_vout_for_address(node, txid, addr):
"""
Locate the vout index of the given transaction sending to the

Loading…
Cancel
Save