In commit “rpc: Enable wallet import on pruned nodes and add test” (f42c077a8f948f5c93b68eb1b7fa246b4f6475ef)
This new create_large_block
seems very inflexible and also has a misleading name. Would drop it and instead just add a new option to create_coinbase
like:
0diff --git a/test/functional/feature_pruning.py b/test/functional/feature_pruning.py
1index 8d72d11baf5..d14970c9463 100755
2--- a/test/functional/feature_pruning.py
3+++ b/test/functional/feature_pruning.py
4@@ -10,7 +10,8 @@ This test takes 30 mins or more (up to 2 hours)
5 """
6 import os
7
8-from test_framework.blocktools import create_large_block
9+from test_framework.blocktools import create_block
10+from test_framework.blocktools import create_coinbase
11 from test_framework.test_framework import BitcoinTestFramework
12 from test_framework.util import (
13 assert_equal,
14@@ -47,7 +48,7 @@ def mine_large_blocks(node, n):
15 previousblockhash = int(best_block["hash"], 16)
16
17 for _ in range(n):
18- block = create_large_block(hashprev=previousblockhash, height=height, ntime=mine_large_blocks.nTime, scriptPubKey=scriptPubKey)
19+ block = create_block(hashprev=previousblockhash, ntime=mine_large_blocks.nTime, coinbase=create_coinbase(height, script_pubkey=scriptPubKey))
20 block.solve()
21
22 # Submit to the node
23diff --git a/test/functional/test_framework/blocktools.py b/test/functional/test_framework/blocktools.py
24index 5916ffc2b17..77653df96e9 100644
25--- a/test/functional/test_framework/blocktools.py
26+++ b/test/functional/test_framework/blocktools.py
27@@ -87,13 +87,6 @@ def create_block(hashprev=None, coinbase=None, ntime=None, *, version=None, tmpl
28 block.calc_sha256()
29 return block
30
31-def create_large_block(hashprev, ntime, height, scriptPubKey):
32- coinbase_tx = create_coinbase(height)
33- coinbase_tx.vout[0].scriptPubKey = scriptPubKey
34- coinbase_tx.rehash()
35-
36- return create_block(coinbase=coinbase_tx, ntime=ntime, hashprev=hashprev)
37-
38 def get_witness_script(witness_root, witness_nonce):
39 witness_commitment = uint256_from_str(hash256(ser_uint256(witness_root) + ser_uint256(witness_nonce)))
40 output_data = WITNESS_COMMITMENT_HEADER + ser_uint256(witness_commitment)
41@@ -127,7 +120,7 @@ def script_BIP34_coinbase_height(height):
42 return CScript([CScriptNum(height)])
43
44
45-def create_coinbase(height, pubkey=None, extra_output_script=None, fees=0, nValue=50):
46+def create_coinbase(height, pubkey=None, *, script_pubkey=None, extra_output_script=None, fees=0, nValue=50):
47 """Create a coinbase transaction.
48
49 If pubkey is passed in, the coinbase output will be a P2PK output;
50@@ -145,6 +138,8 @@ def create_coinbase(height, pubkey=None, extra_output_script=None, fees=0, nValu
51 coinbaseoutput.nValue += fees
52 if pubkey is not None:
53 coinbaseoutput.scriptPubKey = key_to_p2pk_script(pubkey)
54+ elif script_pubkey is not None:
55+ coinbaseoutput.scriptPubKey = script_pubkey
56 else:
57 coinbaseoutput.scriptPubKey = CScript([OP_TRUE])
58 coinbase.vout = [coinbaseoutput]
59diff --git a/test/functional/wallet_pruning.py b/test/functional/wallet_pruning.py
60index 9b8160a4490..e42994422e0 100755
61--- a/test/functional/wallet_pruning.py
62+++ b/test/functional/wallet_pruning.py
63@@ -7,7 +7,8 @@
64 import os
65
66 from test_framework.util import assert_raises_rpc_error
67-from test_framework.blocktools import create_large_block
68+from test_framework.blocktools import create_block
69+from test_framework.blocktools import create_coinbase
70 from test_framework.test_framework import BitcoinTestFramework
71
72 from test_framework.script import (
73@@ -26,7 +27,7 @@ class WalletPruningTest(BitcoinTestFramework):
74 self.nTime = max(self.nTime, int(best_block["time"])) + 1
75 previousblockhash = int(best_block["hash"], 16)
76 for _ in range(n):
77- block = create_large_block(hashprev=previousblockhash, height=height, ntime=self.nTime, scriptPubKey=self.scriptPubKey)
78+ block = create_block(hashprev=previousblockhash, ntime=self.nTime, coinbase=create_coinbase(height, script_pubkey=self.scriptPubKey))
79 block.solve()
80
81 # Submit to the node