Skip to content

Commit 746f203

Browse files
committed
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.
1 parent e3237b1 commit 746f203

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

test/functional/rpc_signrawtransaction.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
assert_equal,
1616
assert_raises_rpc_error,
1717
find_vout_for_address,
18+
generate_to_height,
1819
hex_str_to_bytes,
1920
)
2021
from test_framework.messages import (
@@ -270,7 +271,7 @@ def test_signing_with_csv(self):
270271
getcontext().prec = 8
271272

272273
# Make sure CSV is active
273-
self.nodes[0].generate(500)
274+
generate_to_height(self.nodes[0], 500)
274275
assert self.nodes[0].getblockchaininfo()['softforks']['csv']['active']
275276

276277
# Create a P2WSH script with CSV
@@ -306,7 +307,7 @@ def test_signing_with_cltv(self):
306307
getcontext().prec = 8
307308

308309
# Make sure CLTV is active
309-
self.nodes[0].generate(1500)
310+
generate_to_height(self.nodes[0], 1500)
310311
assert self.nodes[0].getblockchaininfo()['softforks']['bip65']['active']
311312

312313
# Create a P2WSH script with CLTV

test/functional/test_framework/util.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,17 @@ def mine_large_block(node, utxos=None):
559559
node.generate(1)
560560

561561

562+
def generate_to_height(node, target_height):
563+
"""Generates blocks until a given target block height has been reached.
564+
To prevent timeouts, only up to 200 blocks are generated per RPC call.
565+
Can be used to activate certain soft-forks (e.g. CSV, CLTV)."""
566+
current_height = node.getblockcount()
567+
while current_height < target_height:
568+
nblocks = min(200, target_height - current_height)
569+
current_height += len(node.generate(nblocks))
570+
assert_equal(node.getblockcount(), target_height)
571+
572+
562573
def find_vout_for_address(node, txid, addr):
563574
"""
564575
Locate the vout index of the given transaction sending to the

0 commit comments

Comments
 (0)