Skip to content

Commit a5d00d4

Browse files
Merge bitcoin#22788: scripted-diff: Use generate* from TestFramework
fa0b916 scripted-diff: Use generate* from TestFramework (MarcoFalke) Pull request description: This is needed for bitcoin#22567. By using the newly added `generate*` member functions of the test framework, it paves the way to make it easier to implicitly call `sync_all` after block generation to avoid intermittent issues. ACKs for top commit: jonatack: ACK fa0b916 Tree-SHA512: e74a324b60250a87c08847cdfd7b6ce3e1d89b891659fd168f6dd7dc0aa718d0edd28285374a613f462f34f4ef8e12c90ad44fb58721c91b2ea691406ad22c2a
2 parents eb1f570 + fa0b916 commit a5d00d4

File tree

117 files changed

+468
-468
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+468
-468
lines changed

test/functional/example_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def run_test(self):
141141
peer_messaging = self.nodes[0].add_p2p_connection(BaseNode())
142142

143143
# Generating a block on one of the nodes will get us out of IBD
144-
blocks = [int(self.nodes[0].generate(nblocks=1)[0], 16)]
144+
blocks = [int(self.generate(self.nodes[0], nblocks=1)[0], 16)]
145145
self.sync_all(self.nodes[0:2])
146146

147147
# Notice above how we called an RPC by calling a method with the same

test/functional/feature_abortnode.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@ def setup_network(self):
2626
# We'll connect the nodes later
2727

2828
def run_test(self):
29-
self.nodes[0].generate(3)
29+
self.generate(self.nodes[0], 3)
3030
datadir = get_datadir_path(self.options.tmpdir, 0)
3131

3232
# Deleting the undo file will result in reorg failure
3333
os.unlink(os.path.join(datadir, self.chain, 'blocks', 'rev00000.dat'))
3434

3535
# Connecting to a node with a more work chain will trigger a reorg
3636
# attempt.
37-
self.nodes[1].generate(3)
37+
self.generate(self.nodes[1], 3)
3838
with self.nodes[0].assert_debug_log(["Failed to disconnect block"]):
3939
self.connect_nodes(0, 1)
40-
self.nodes[1].generate(1)
40+
self.generate(self.nodes[1], 1)
4141

4242
# Check that node0 aborted
4343
self.log.info("Waiting for crash")

test/functional/feature_backwards_compatibility.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def setup_nodes(self):
6464
self.import_deterministic_coinbase_privkeys()
6565

6666
def run_test(self):
67-
self.nodes[0].generatetoaddress(COINBASE_MATURITY + 1, self.nodes[0].getnewaddress())
67+
self.generatetoaddress(self.nodes[0], COINBASE_MATURITY + 1, self.nodes[0].getnewaddress())
6868

6969
self.sync_blocks()
7070

@@ -92,15 +92,15 @@ def run_test(self):
9292
address = wallet.getnewaddress()
9393
self.nodes[0].sendtoaddress(address, 10)
9494
self.sync_mempools()
95-
self.nodes[0].generate(1)
95+
self.generate(self.nodes[0], 1)
9696
self.sync_blocks()
9797
# Create a conflicting transaction using RBF
9898
return_address = self.nodes[0].getnewaddress()
9999
tx1_id = self.nodes[1].sendtoaddress(return_address, 1)
100100
tx2_id = self.nodes[1].bumpfee(tx1_id)["txid"]
101101
# Confirm the transaction
102102
self.sync_mempools()
103-
self.nodes[0].generate(1)
103+
self.generate(self.nodes[0], 1)
104104
self.sync_blocks()
105105
# Create another conflicting transaction using RBF
106106
tx3_id = self.nodes[1].sendtoaddress(return_address, 1)

test/functional/feature_bip68_sequence.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def run_test(self):
5555
self.relayfee = self.nodes[0].getnetworkinfo()["relayfee"]
5656

5757
# Generate some coins
58-
self.nodes[0].generate(110)
58+
self.generate(self.nodes[0], 110)
5959

6060
self.log.info("Running test disable flag")
6161
self.test_disable_flag()
@@ -143,7 +143,7 @@ def test_sequence_lock_confirmed_inputs(self):
143143
for i in range(num_outputs):
144144
outputs[addresses[i]] = random.randint(1, 20)*0.01
145145
self.nodes[0].sendmany("", outputs)
146-
self.nodes[0].generate(1)
146+
self.generate(self.nodes[0], 1)
147147

148148
utxos = self.nodes[0].listunspent()
149149

@@ -273,7 +273,7 @@ def test_nonzero_locks(orig_tx, node, relayfee, use_height_lock):
273273
cur_time = int(time.time())
274274
for _ in range(10):
275275
self.nodes[0].setmocktime(cur_time + 600)
276-
self.nodes[0].generate(1)
276+
self.generate(self.nodes[0], 1)
277277
cur_time += 600
278278

279279
assert tx2.hash in self.nodes[0].getrawmempool()
@@ -288,15 +288,15 @@ def test_nonzero_locks(orig_tx, node, relayfee, use_height_lock):
288288
self.nodes[0].setmocktime(cur_time+600)
289289
# Save block template now to use for the reorg later
290290
tmpl = self.nodes[0].getblocktemplate(NORMAL_GBT_REQUEST_PARAMS)
291-
self.nodes[0].generate(1)
291+
self.generate(self.nodes[0], 1)
292292
assert tx2.hash not in self.nodes[0].getrawmempool()
293293

294294
# Now that tx2 is not in the mempool, a sequence locked spend should
295295
# succeed
296296
tx3 = test_nonzero_locks(tx2, self.nodes[0], self.relayfee, use_height_lock=False)
297297
assert tx3.hash in self.nodes[0].getrawmempool()
298298

299-
self.nodes[0].generate(1)
299+
self.generate(self.nodes[0], 1)
300300
assert tx3.hash not in self.nodes[0].getrawmempool()
301301

302302
# One more test, this time using height locks
@@ -349,7 +349,7 @@ def test_nonzero_locks(orig_tx, node, relayfee, use_height_lock):
349349
# Reset the chain and get rid of the mocktimed-blocks
350350
self.nodes[0].setmocktime(0)
351351
self.nodes[0].invalidateblock(self.nodes[0].getblockhash(cur_height+1))
352-
self.nodes[0].generate(10)
352+
self.generate(self.nodes[0], 10)
353353

354354
# Make sure that BIP68 isn't being used to validate blocks prior to
355355
# activation height. If more blocks are mined prior to this test
@@ -403,9 +403,9 @@ def activateCSV(self):
403403
min_activation_height = 432
404404
height = self.nodes[0].getblockcount()
405405
assert_greater_than(min_activation_height - height, 2)
406-
self.nodes[0].generate(min_activation_height - height - 2)
406+
self.generate(self.nodes[0], min_activation_height - height - 2)
407407
assert not softfork_active(self.nodes[0], 'csv')
408-
self.nodes[0].generate(1)
408+
self.generate(self.nodes[0], 1)
409409
assert softfork_active(self.nodes[0], 'csv')
410410
self.sync_blocks()
411411

test/functional/feature_blockfilterindex_prune.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ def run_test(self):
2525
self.sync_index(height=200)
2626
assert_greater_than(len(self.nodes[0].getblockfilter(self.nodes[0].getbestblockhash())['filter']), 0)
2727
# Mine two batches of blocks to avoid hitting NODE_NETWORK_LIMITED_MIN_BLOCKS disconnection
28-
self.nodes[0].generate(250)
28+
self.generate(self.nodes[0], 250)
2929
self.sync_all()
30-
self.nodes[0].generate(250)
30+
self.generate(self.nodes[0], 250)
3131
self.sync_all()
3232
self.sync_index(height=700)
3333

@@ -46,7 +46,7 @@ def run_test(self):
4646

4747
self.log.info("make sure accessing the blockfilters throws an error")
4848
assert_raises_rpc_error(-1, "Index is not enabled for filtertype basic", self.nodes[0].getblockfilter, self.nodes[0].getblockhash(2))
49-
self.nodes[0].generate(1000)
49+
self.generate(self.nodes[0], 1000)
5050

5151
self.log.info("prune below the blockfilterindexes best block while blockfilters are disabled")
5252
pruneheight_new = self.nodes[0].pruneblockchain(1000)

test/functional/feature_blocksdir.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def run_test(self):
2929
self.log.info("Starting with existing blocksdir ...")
3030
self.start_node(0, [f"-blocksdir={blocksdir_path}"])
3131
self.log.info("mining blocks..")
32-
self.nodes[0].generatetoaddress(10, self.nodes[0].get_deterministic_priv_key().address)
32+
self.generatetoaddress(self.nodes[0], 10, self.nodes[0].get_deterministic_priv_key().address)
3333
assert os.path.isfile(os.path.join(blocksdir_path, self.chain, "blocks", "blk00000.dat"))
3434
assert os.path.isdir(os.path.join(self.nodes[0].datadir, self.chain, "blocks", "index"))
3535

test/functional/feature_cltv.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ def run_test(self):
102102
self.test_cltv_info(is_active=False)
103103

104104
self.log.info("Mining %d blocks", CLTV_HEIGHT - 2)
105-
wallet.generate(10)
106-
self.nodes[0].generate(CLTV_HEIGHT - 2 - 10)
105+
self.generate(wallet, 10)
106+
self.generate(self.nodes[0], CLTV_HEIGHT - 2 - 10)
107107
assert_equal(self.nodes[0].getblockcount(), CLTV_HEIGHT - 2)
108108

109109
self.log.info("Test that invalid-according-to-CLTV transactions can still appear in a block")

test/functional/feature_coinstatsindex.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ def _test_coin_stats_index(self):
6767
index_hash_options = ['none', 'muhash']
6868

6969
# Generate a normal transaction and mine it
70-
node.generate(COINBASE_MATURITY + 1)
70+
self.generate(node, COINBASE_MATURITY + 1)
7171
address = self.nodes[0].get_deterministic_priv_key().address
7272
node.sendtoaddress(address=address, amount=10, subtractfeefromamount=True)
73-
node.generate(1)
73+
self.generate(node, 1)
7474

7575
self.sync_blocks(timeout=120)
7676

@@ -92,7 +92,7 @@ def _test_coin_stats_index(self):
9292
self.log.info("Test that gettxoutsetinfo() can get fetch data on specific heights with index")
9393

9494
# Generate a new tip
95-
node.generate(5)
95+
self.generate(node, 5)
9696

9797
for hash_option in index_hash_options:
9898
# Fetch old stats by height
@@ -169,7 +169,7 @@ def _test_coin_stats_index(self):
169169
self.nodes[0].sendrawtransaction(tx2_hex)
170170

171171
# Include both txs in a block
172-
self.nodes[0].generate(1)
172+
self.generate(self.nodes[0], 1)
173173
self.sync_all()
174174

175175
for hash_option in index_hash_options:
@@ -228,7 +228,7 @@ def _test_coin_stats_index(self):
228228
res9 = index_node.gettxoutsetinfo('muhash')
229229
assert_equal(res8, res9)
230230

231-
index_node.generate(1)
231+
self.generate(index_node, 1)
232232
res10 = index_node.gettxoutsetinfo('muhash')
233233
assert(res8['txouts'] < res10['txouts'])
234234

@@ -247,14 +247,14 @@ def _test_reorg_index(self):
247247

248248
# Generate two block, let the index catch up, then invalidate the blocks
249249
index_node = self.nodes[1]
250-
reorg_blocks = index_node.generatetoaddress(2, index_node.getnewaddress())
250+
reorg_blocks = self.generatetoaddress(index_node, 2, index_node.getnewaddress())
251251
reorg_block = reorg_blocks[1]
252252
res_invalid = index_node.gettxoutsetinfo('muhash')
253253
index_node.invalidateblock(reorg_blocks[0])
254254
assert_equal(index_node.gettxoutsetinfo('muhash')['height'], 110)
255255

256256
# Add two new blocks
257-
block = index_node.generate(2)[1]
257+
block = self.generate(index_node, 2)[1]
258258
res = index_node.gettxoutsetinfo(hash_type='muhash', hash_or_height=None, use_index=False)
259259

260260
# Test that the result of the reorged block is not returned for its old block height
@@ -270,7 +270,7 @@ def _test_reorg_index(self):
270270

271271
# Add another block, so we don't depend on reconsiderblock remembering which
272272
# blocks were touched by invalidateblock
273-
index_node.generate(1)
273+
self.generate(index_node, 1)
274274
self.sync_all()
275275

276276
# Ensure that removing and re-adding blocks yields consistent results

test/functional/feature_csv_activation.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def run_test(self):
189189
self.log.info("Generate blocks in the past for coinbase outputs.")
190190
long_past_time = int(time.time()) - 600 * 1000 # enough to build up to 1000 blocks 10 minutes apart without worrying about getting into the future
191191
self.nodes[0].setmocktime(long_past_time - 100) # enough so that the generated blocks will still all be before long_past_time
192-
self.coinbase_blocks = self.miniwallet.generate(COINBASE_BLOCK_COUNT) # blocks generated for inputs
192+
self.coinbase_blocks = self.generate(self.miniwallet, COINBASE_BLOCK_COUNT) # blocks generated for inputs
193193
self.nodes[0].setmocktime(0) # set time back to present so yielded blocks aren't in the future as we advance last_block_time
194194
self.tipheight = COINBASE_BLOCK_COUNT # height of the next block to build
195195
self.last_block_time = long_past_time
@@ -235,7 +235,7 @@ def run_test(self):
235235
bip113input = self.send_generic_input_tx(self.coinbase_blocks)
236236

237237
self.nodes[0].setmocktime(self.last_block_time + 600)
238-
inputblockhash = self.nodes[0].generate(1)[0] # 1 block generated for inputs to be in chain at height 431
238+
inputblockhash = self.generate(self.nodes[0], 1)[0] # 1 block generated for inputs to be in chain at height 431
239239
self.nodes[0].setmocktime(0)
240240
self.tip = int(inputblockhash, 16)
241241
self.tipheight += 1

test/functional/feature_dersig.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def run_test(self):
7272
self.test_dersig_info(is_active=False)
7373

7474
self.log.info("Mining %d blocks", DERSIG_HEIGHT - 2)
75-
self.coinbase_txids = [self.nodes[0].getblock(b)['tx'][0] for b in self.miniwallet.generate(DERSIG_HEIGHT - 2)]
75+
self.coinbase_txids = [self.nodes[0].getblock(b)['tx'][0] for b in self.generate(self.miniwallet, DERSIG_HEIGHT - 2)]
7676

7777
self.log.info("Test that a transaction with non-DER signature can still appear in a block")
7878

test/functional/feature_fee_estimation.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def transact_and_mine(self, numblocks, mining_node):
197197
tx_kbytes = (len(txhex) // 2) / 1000.0
198198
self.fees_per_kb.append(float(fee) / tx_kbytes)
199199
self.sync_mempools(wait=.1)
200-
mined = mining_node.getblock(mining_node.generate(1)[0], True)["tx"]
200+
mined = mining_node.getblock(self.generate(mining_node, 1)[0], True)["tx"]
201201
self.sync_blocks(wait=.1)
202202
# update which txouts are confirmed
203203
newmem = []
@@ -221,7 +221,7 @@ def run_test(self):
221221

222222
# Mine
223223
while len(self.nodes[0].getrawmempool()) > 0:
224-
self.nodes[0].generate(1)
224+
self.generate(self.nodes[0], 1)
225225

226226
# Repeatedly split those 2 outputs, doubling twice for each rep
227227
# Use txouts to monitor the available utxo, since these won't be tracked in wallet
@@ -231,12 +231,12 @@ def run_test(self):
231231
while len(self.txouts) > 0:
232232
split_inputs(self.nodes[0], self.txouts, self.txouts2)
233233
while len(self.nodes[0].getrawmempool()) > 0:
234-
self.nodes[0].generate(1)
234+
self.generate(self.nodes[0], 1)
235235
# Double txouts2 to txouts
236236
while len(self.txouts2) > 0:
237237
split_inputs(self.nodes[0], self.txouts2, self.txouts)
238238
while len(self.nodes[0].getrawmempool()) > 0:
239-
self.nodes[0].generate(1)
239+
self.generate(self.nodes[0], 1)
240240
reps += 1
241241
self.log.info("Finished splitting")
242242

@@ -269,7 +269,7 @@ def run_test(self):
269269

270270
# Finish by mining a normal-sized block:
271271
while len(self.nodes[1].getrawmempool()) > 0:
272-
self.nodes[1].generate(1)
272+
self.generate(self.nodes[1], 1)
273273

274274
self.sync_blocks(self.nodes[0:3], wait=.1)
275275
self.log.info("Final estimates after emptying mempools")

test/functional/feature_loadblock.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def set_test_params(self):
2929

3030
def run_test(self):
3131
self.nodes[1].setnetworkactive(state=False)
32-
self.nodes[0].generate(COINBASE_MATURITY)
32+
self.generate(self.nodes[0], COINBASE_MATURITY)
3333

3434
# Parsing the url of our node to get settings for config file
3535
data_dir = self.nodes[0].datadir

test/functional/feature_maxuploadtarget.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def run_test(self):
5656
self.nodes[0].setmocktime(old_time)
5757

5858
# Generate some old blocks
59-
self.nodes[0].generate(130)
59+
self.generate(self.nodes[0], 130)
6060

6161
# p2p_conns[0] will only request old blocks
6262
# p2p_conns[1] will only request new blocks

test/functional/feature_minchainwork.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def run_test(self):
5151

5252
num_blocks_to_generate = int((self.node_min_work[1] - starting_chain_work) / REGTEST_WORK_PER_BLOCK)
5353
self.log.info(f"Generating {num_blocks_to_generate} blocks on node0")
54-
hashes = self.nodes[0].generatetoaddress(num_blocks_to_generate,
54+
hashes = self.generatetoaddress(self.nodes[0], num_blocks_to_generate,
5555
self.nodes[0].get_deterministic_priv_key().address)
5656

5757
self.log.info(f"Node0 current chain work: {self.nodes[0].getblockheader(hashes[-1])['chainwork']}")
@@ -73,7 +73,7 @@ def run_test(self):
7373
assert_equal(self.nodes[2].getblockcount(), starting_blockcount)
7474

7575
self.log.info("Generating one more block")
76-
self.nodes[0].generatetoaddress(1, self.nodes[0].get_deterministic_priv_key().address)
76+
self.generatetoaddress(self.nodes[0], 1, self.nodes[0].get_deterministic_priv_key().address)
7777

7878
self.log.info("Verifying nodes are all synced")
7979

test/functional/feature_notifications.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def run_test(self):
7676

7777
self.log.info("test -blocknotify")
7878
block_count = 10
79-
blocks = self.nodes[1].generatetoaddress(block_count, self.nodes[1].getnewaddress() if self.is_wallet_compiled() else ADDRESS_BCRT1_UNSPENDABLE)
79+
blocks = self.generatetoaddress(self.nodes[1], block_count, self.nodes[1].getnewaddress() if self.is_wallet_compiled() else ADDRESS_BCRT1_UNSPENDABLE)
8080

8181
# wait at most 10 seconds for expected number of files before reading the content
8282
self.wait_until(lambda: len(os.listdir(self.blocknotify_dir)) == block_count, timeout=10)
@@ -110,7 +110,7 @@ def run_test(self):
110110
# triggered by node 1
111111
self.log.info("test -walletnotify with conflicting transactions")
112112
self.nodes[0].rescanblockchain()
113-
self.nodes[0].generatetoaddress(100, ADDRESS_BCRT1_UNSPENDABLE)
113+
self.generatetoaddress(self.nodes[0], 100, ADDRESS_BCRT1_UNSPENDABLE)
114114
self.sync_blocks()
115115

116116
# Generate transaction on node 0, sync mempools, and check for
@@ -131,7 +131,7 @@ def run_test(self):
131131

132132
# Add bump1 transaction to new block, checking for a notification
133133
# and the correct number of confirmations.
134-
blockhash1 = self.nodes[0].generatetoaddress(1, ADDRESS_BCRT1_UNSPENDABLE)[0]
134+
blockhash1 = self.generatetoaddress(self.nodes[0], 1, ADDRESS_BCRT1_UNSPENDABLE)[0]
135135
blockheight1 = self.nodes[0].getblockcount()
136136
self.sync_blocks()
137137
self.expect_wallet_notify([(bump1, blockheight1, blockhash1)])
@@ -148,7 +148,7 @@ def run_test(self):
148148
# about newly confirmed bump2 and newly conflicted tx2.
149149
self.disconnect_nodes(0, 1)
150150
bump2 = self.nodes[0].bumpfee(tx2)["txid"]
151-
blockhash2 = self.nodes[0].generatetoaddress(1, ADDRESS_BCRT1_UNSPENDABLE)[0]
151+
blockhash2 = self.generatetoaddress(self.nodes[0], 1, ADDRESS_BCRT1_UNSPENDABLE)[0]
152152
blockheight2 = self.nodes[0].getblockcount()
153153
assert_equal(self.nodes[0].gettransaction(bump2)["confirmations"], 1)
154154
assert_equal(tx2 in self.nodes[1].getrawmempool(), True)

test/functional/feature_nulldummy.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ def run_test(self):
7474
wmulti.importaddress(self.ms_address)
7575
wmulti.importaddress(self.wit_ms_address)
7676

77-
self.coinbase_blocks = self.nodes[0].generate(2) # block height = 2
77+
self.coinbase_blocks = self.generate(self.nodes[0], 2) # block height = 2
7878
coinbase_txid = []
7979
for i in self.coinbase_blocks:
8080
coinbase_txid.append(self.nodes[0].getblock(i)['tx'][0])
81-
self.nodes[0].generate(COINBASE_MATURITY) # block height = COINBASE_MATURITY + 2
81+
self.generate(self.nodes[0], COINBASE_MATURITY) # block height = COINBASE_MATURITY + 2
8282
self.lastblockhash = self.nodes[0].getbestblockhash()
8383
self.lastblockheight = COINBASE_MATURITY + 2
8484
self.lastblocktime = int(time.time()) + self.lastblockheight

test/functional/feature_presegwit_node_upgrade.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def run_test(self):
3030
assert not softfork_active(node, "segwit")
3131

3232
# Generate 8 blocks without witness data
33-
node.generate(8)
33+
self.generate(node, 8)
3434
assert_equal(node.getblockcount(), 8)
3535

3636
self.stop_node(0)

0 commit comments

Comments
 (0)