Skip to content

Commit a5d00d4

Browse files
Merge bitcoin/bitcoin#22788: scripted-diff: Use generate* from TestFramework
fa0b916 scripted-diff: Use generate* from TestFramework (MarcoFalke) Pull request description: This is needed for #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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 8 additions & 8 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 8 additions & 8 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

0 commit comments

Comments
 (0)