Skip to content

Commit

Permalink
Merge bitcoin/bitcoin#22788: scripted-diff: Use generate* from TestFr…
Browse files Browse the repository at this point in the history
…amework

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
  • Loading branch information
bitcoin-core-merge-script committed Sep 9, 2021
2 parents eb1f570 + fa0b916 commit a5d00d4
Show file tree
Hide file tree
Showing 117 changed files with 468 additions and 468 deletions.
2 changes: 1 addition & 1 deletion test/functional/example_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def run_test(self):
peer_messaging = self.nodes[0].add_p2p_connection(BaseNode())

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

# Notice above how we called an RPC by calling a method with the same
Expand Down
6 changes: 3 additions & 3 deletions test/functional/feature_abortnode.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ def setup_network(self):
# We'll connect the nodes later

def run_test(self):
self.nodes[0].generate(3)
self.generate(self.nodes[0], 3)
datadir = get_datadir_path(self.options.tmpdir, 0)

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

# Connecting to a node with a more work chain will trigger a reorg
# attempt.
self.nodes[1].generate(3)
self.generate(self.nodes[1], 3)
with self.nodes[0].assert_debug_log(["Failed to disconnect block"]):
self.connect_nodes(0, 1)
self.nodes[1].generate(1)
self.generate(self.nodes[1], 1)

# Check that node0 aborted
self.log.info("Waiting for crash")
Expand Down
6 changes: 3 additions & 3 deletions test/functional/feature_backwards_compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def setup_nodes(self):
self.import_deterministic_coinbase_privkeys()

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

self.sync_blocks()

Expand Down Expand Up @@ -92,15 +92,15 @@ def run_test(self):
address = wallet.getnewaddress()
self.nodes[0].sendtoaddress(address, 10)
self.sync_mempools()
self.nodes[0].generate(1)
self.generate(self.nodes[0], 1)
self.sync_blocks()
# Create a conflicting transaction using RBF
return_address = self.nodes[0].getnewaddress()
tx1_id = self.nodes[1].sendtoaddress(return_address, 1)
tx2_id = self.nodes[1].bumpfee(tx1_id)["txid"]
# Confirm the transaction
self.sync_mempools()
self.nodes[0].generate(1)
self.generate(self.nodes[0], 1)
self.sync_blocks()
# Create another conflicting transaction using RBF
tx3_id = self.nodes[1].sendtoaddress(return_address, 1)
Expand Down
16 changes: 8 additions & 8 deletions test/functional/feature_bip68_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def run_test(self):
self.relayfee = self.nodes[0].getnetworkinfo()["relayfee"]

# Generate some coins
self.nodes[0].generate(110)
self.generate(self.nodes[0], 110)

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

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

Expand Down Expand Up @@ -273,7 +273,7 @@ def test_nonzero_locks(orig_tx, node, relayfee, use_height_lock):
cur_time = int(time.time())
for _ in range(10):
self.nodes[0].setmocktime(cur_time + 600)
self.nodes[0].generate(1)
self.generate(self.nodes[0], 1)
cur_time += 600

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

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

self.nodes[0].generate(1)
self.generate(self.nodes[0], 1)
assert tx3.hash not in self.nodes[0].getrawmempool()

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

# Make sure that BIP68 isn't being used to validate blocks prior to
# activation height. If more blocks are mined prior to this test
Expand Down Expand Up @@ -403,9 +403,9 @@ def activateCSV(self):
min_activation_height = 432
height = self.nodes[0].getblockcount()
assert_greater_than(min_activation_height - height, 2)
self.nodes[0].generate(min_activation_height - height - 2)
self.generate(self.nodes[0], min_activation_height - height - 2)
assert not softfork_active(self.nodes[0], 'csv')
self.nodes[0].generate(1)
self.generate(self.nodes[0], 1)
assert softfork_active(self.nodes[0], 'csv')
self.sync_blocks()

Expand Down
6 changes: 3 additions & 3 deletions test/functional/feature_blockfilterindex_prune.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ def run_test(self):
self.sync_index(height=200)
assert_greater_than(len(self.nodes[0].getblockfilter(self.nodes[0].getbestblockhash())['filter']), 0)
# Mine two batches of blocks to avoid hitting NODE_NETWORK_LIMITED_MIN_BLOCKS disconnection
self.nodes[0].generate(250)
self.generate(self.nodes[0], 250)
self.sync_all()
self.nodes[0].generate(250)
self.generate(self.nodes[0], 250)
self.sync_all()
self.sync_index(height=700)

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

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

self.log.info("prune below the blockfilterindexes best block while blockfilters are disabled")
pruneheight_new = self.nodes[0].pruneblockchain(1000)
Expand Down
2 changes: 1 addition & 1 deletion test/functional/feature_blocksdir.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def run_test(self):
self.log.info("Starting with existing blocksdir ...")
self.start_node(0, [f"-blocksdir={blocksdir_path}"])
self.log.info("mining blocks..")
self.nodes[0].generatetoaddress(10, self.nodes[0].get_deterministic_priv_key().address)
self.generatetoaddress(self.nodes[0], 10, self.nodes[0].get_deterministic_priv_key().address)
assert os.path.isfile(os.path.join(blocksdir_path, self.chain, "blocks", "blk00000.dat"))
assert os.path.isdir(os.path.join(self.nodes[0].datadir, self.chain, "blocks", "index"))

Expand Down
4 changes: 2 additions & 2 deletions test/functional/feature_cltv.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ def run_test(self):
self.test_cltv_info(is_active=False)

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

self.log.info("Test that invalid-according-to-CLTV transactions can still appear in a block")
Expand Down
16 changes: 8 additions & 8 deletions test/functional/feature_coinstatsindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ def _test_coin_stats_index(self):
index_hash_options = ['none', 'muhash']

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

self.sync_blocks(timeout=120)

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

# Generate a new tip
node.generate(5)
self.generate(node, 5)

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

# Include both txs in a block
self.nodes[0].generate(1)
self.generate(self.nodes[0], 1)
self.sync_all()

for hash_option in index_hash_options:
Expand Down Expand Up @@ -228,7 +228,7 @@ def _test_coin_stats_index(self):
res9 = index_node.gettxoutsetinfo('muhash')
assert_equal(res8, res9)

index_node.generate(1)
self.generate(index_node, 1)
res10 = index_node.gettxoutsetinfo('muhash')
assert(res8['txouts'] < res10['txouts'])

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

# Generate two block, let the index catch up, then invalidate the blocks
index_node = self.nodes[1]
reorg_blocks = index_node.generatetoaddress(2, index_node.getnewaddress())
reorg_blocks = self.generatetoaddress(index_node, 2, index_node.getnewaddress())
reorg_block = reorg_blocks[1]
res_invalid = index_node.gettxoutsetinfo('muhash')
index_node.invalidateblock(reorg_blocks[0])
assert_equal(index_node.gettxoutsetinfo('muhash')['height'], 110)

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

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

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

# Ensure that removing and re-adding blocks yields consistent results
Expand Down
4 changes: 2 additions & 2 deletions test/functional/feature_csv_activation.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def run_test(self):
self.log.info("Generate blocks in the past for coinbase outputs.")
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
self.nodes[0].setmocktime(long_past_time - 100) # enough so that the generated blocks will still all be before long_past_time
self.coinbase_blocks = self.miniwallet.generate(COINBASE_BLOCK_COUNT) # blocks generated for inputs
self.coinbase_blocks = self.generate(self.miniwallet, COINBASE_BLOCK_COUNT) # blocks generated for inputs
self.nodes[0].setmocktime(0) # set time back to present so yielded blocks aren't in the future as we advance last_block_time
self.tipheight = COINBASE_BLOCK_COUNT # height of the next block to build
self.last_block_time = long_past_time
Expand Down Expand Up @@ -235,7 +235,7 @@ def run_test(self):
bip113input = self.send_generic_input_tx(self.coinbase_blocks)

self.nodes[0].setmocktime(self.last_block_time + 600)
inputblockhash = self.nodes[0].generate(1)[0] # 1 block generated for inputs to be in chain at height 431
inputblockhash = self.generate(self.nodes[0], 1)[0] # 1 block generated for inputs to be in chain at height 431
self.nodes[0].setmocktime(0)
self.tip = int(inputblockhash, 16)
self.tipheight += 1
Expand Down
2 changes: 1 addition & 1 deletion test/functional/feature_dersig.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def run_test(self):
self.test_dersig_info(is_active=False)

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

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

Expand Down
10 changes: 5 additions & 5 deletions test/functional/feature_fee_estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def transact_and_mine(self, numblocks, mining_node):
tx_kbytes = (len(txhex) // 2) / 1000.0
self.fees_per_kb.append(float(fee) / tx_kbytes)
self.sync_mempools(wait=.1)
mined = mining_node.getblock(mining_node.generate(1)[0], True)["tx"]
mined = mining_node.getblock(self.generate(mining_node, 1)[0], True)["tx"]
self.sync_blocks(wait=.1)
# update which txouts are confirmed
newmem = []
Expand All @@ -221,7 +221,7 @@ def run_test(self):

# Mine
while len(self.nodes[0].getrawmempool()) > 0:
self.nodes[0].generate(1)
self.generate(self.nodes[0], 1)

# Repeatedly split those 2 outputs, doubling twice for each rep
# Use txouts to monitor the available utxo, since these won't be tracked in wallet
Expand All @@ -231,12 +231,12 @@ def run_test(self):
while len(self.txouts) > 0:
split_inputs(self.nodes[0], self.txouts, self.txouts2)
while len(self.nodes[0].getrawmempool()) > 0:
self.nodes[0].generate(1)
self.generate(self.nodes[0], 1)
# Double txouts2 to txouts
while len(self.txouts2) > 0:
split_inputs(self.nodes[0], self.txouts2, self.txouts)
while len(self.nodes[0].getrawmempool()) > 0:
self.nodes[0].generate(1)
self.generate(self.nodes[0], 1)
reps += 1
self.log.info("Finished splitting")

Expand Down Expand Up @@ -269,7 +269,7 @@ def run_test(self):

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

self.sync_blocks(self.nodes[0:3], wait=.1)
self.log.info("Final estimates after emptying mempools")
Expand Down
2 changes: 1 addition & 1 deletion test/functional/feature_loadblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def set_test_params(self):

def run_test(self):
self.nodes[1].setnetworkactive(state=False)
self.nodes[0].generate(COINBASE_MATURITY)
self.generate(self.nodes[0], COINBASE_MATURITY)

# Parsing the url of our node to get settings for config file
data_dir = self.nodes[0].datadir
Expand Down
2 changes: 1 addition & 1 deletion test/functional/feature_maxuploadtarget.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def run_test(self):
self.nodes[0].setmocktime(old_time)

# Generate some old blocks
self.nodes[0].generate(130)
self.generate(self.nodes[0], 130)

# p2p_conns[0] will only request old blocks
# p2p_conns[1] will only request new blocks
Expand Down
4 changes: 2 additions & 2 deletions test/functional/feature_minchainwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def run_test(self):

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

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

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

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

Expand Down
8 changes: 4 additions & 4 deletions test/functional/feature_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def run_test(self):

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

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

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

# Add bump1 transaction to new block, checking for a notification
# and the correct number of confirmations.
blockhash1 = self.nodes[0].generatetoaddress(1, ADDRESS_BCRT1_UNSPENDABLE)[0]
blockhash1 = self.generatetoaddress(self.nodes[0], 1, ADDRESS_BCRT1_UNSPENDABLE)[0]
blockheight1 = self.nodes[0].getblockcount()
self.sync_blocks()
self.expect_wallet_notify([(bump1, blockheight1, blockhash1)])
Expand All @@ -148,7 +148,7 @@ def run_test(self):
# about newly confirmed bump2 and newly conflicted tx2.
self.disconnect_nodes(0, 1)
bump2 = self.nodes[0].bumpfee(tx2)["txid"]
blockhash2 = self.nodes[0].generatetoaddress(1, ADDRESS_BCRT1_UNSPENDABLE)[0]
blockhash2 = self.generatetoaddress(self.nodes[0], 1, ADDRESS_BCRT1_UNSPENDABLE)[0]
blockheight2 = self.nodes[0].getblockcount()
assert_equal(self.nodes[0].gettransaction(bump2)["confirmations"], 1)
assert_equal(tx2 in self.nodes[1].getrawmempool(), True)
Expand Down
4 changes: 2 additions & 2 deletions test/functional/feature_nulldummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ def run_test(self):
wmulti.importaddress(self.ms_address)
wmulti.importaddress(self.wit_ms_address)

self.coinbase_blocks = self.nodes[0].generate(2) # block height = 2
self.coinbase_blocks = self.generate(self.nodes[0], 2) # block height = 2
coinbase_txid = []
for i in self.coinbase_blocks:
coinbase_txid.append(self.nodes[0].getblock(i)['tx'][0])
self.nodes[0].generate(COINBASE_MATURITY) # block height = COINBASE_MATURITY + 2
self.generate(self.nodes[0], COINBASE_MATURITY) # block height = COINBASE_MATURITY + 2
self.lastblockhash = self.nodes[0].getbestblockhash()
self.lastblockheight = COINBASE_MATURITY + 2
self.lastblocktime = int(time.time()) + self.lastblockheight
Expand Down
2 changes: 1 addition & 1 deletion test/functional/feature_presegwit_node_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def run_test(self):
assert not softfork_active(node, "segwit")

# Generate 8 blocks without witness data
node.generate(8)
self.generate(node, 8)
assert_equal(node.getblockcount(), 8)

self.stop_node(0)
Expand Down
Loading

0 comments on commit a5d00d4

Please sign in to comment.