diff options
author | fanquake <fanquake@gmail.com> | 2021-08-24 16:22:24 +0800 |
---|---|---|
committer | fanquake <fanquake@gmail.com> | 2021-08-24 16:22:30 +0800 |
commit | eb09c26724e3f714b613788fc506f2ff3a208d2c (patch) | |
tree | 941ac1005e0ffd55f6efa1107ba2b810244250ca /test/functional/test_framework | |
parent | dd455ecfa085f72dea5fe192491b7d0b474fbed1 (diff) | |
parent | fab2e23b579c44f1b4bed4d813bbe5a21eaa22c8 (diff) | |
download | bitcoin-eb09c26724e3f714b613788fc506f2ff3a208d2c.tar.xz |
Merge bitcoin/bitcoin#22741: test: Add generate* calls to test framework
fab2e23b579c44f1b4bed4d813bbe5a21eaa22c8 Use generate* from TestFramework (MarcoFalke)
faf7e9280487d643cf59681df2711d72675b5ad4 test: Add generate* calls to test framework (MarcoFalke)
Pull request description:
This is needed for #22567.
By making the calls to `generate*` member function of the test framework, it paves the way to make it easier to implicitly call the `sync_all` member function.
ACKs for top commit:
jnewbery:
utACK fab2e23b579c44f1b4bed4d813bbe5a21eaa22c8
Tree-SHA512: 7a7be6be71f0602119689df45d63a1adec309f323eac2330ee0f200676001afe825605859bd02c6a8a8dcf85d925dc1bc37370ef1ceb8ad1d85a66eec0dbfff9
Diffstat (limited to 'test/functional/test_framework')
-rwxr-xr-x | test/functional/test_framework/test_framework.py | 21 | ||||
-rw-r--r-- | test/functional/test_framework/util.py | 14 |
2 files changed, 26 insertions, 9 deletions
diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py index 6d8e6ef45c..f382e0fdb3 100755 --- a/test/functional/test_framework/test_framework.py +++ b/test/functional/test_framework/test_framework.py @@ -410,7 +410,7 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass): # To ensure that all nodes are out of IBD, the most recent block # must have a timestamp not too old (see IsInitialBlockDownload()). self.log.debug('Generate a block with current time') - block_hash = self.nodes[0].generate(1)[0] + block_hash = self.generate(self.nodes[0], 1)[0] block = self.nodes[0].getblock(blockhash=block_hash, verbosity=0) for n in self.nodes: n.submitblock(block) @@ -619,6 +619,22 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass): self.connect_nodes(1, 2) self.sync_all() + def generate(self, generator, *args, **kwargs): + blocks = generator.generate(*args, **kwargs) + return blocks + + def generateblock(self, generator, *args, **kwargs): + blocks = generator.generateblock(*args, **kwargs) + return blocks + + def generatetoaddress(self, generator, *args, **kwargs): + blocks = generator.generatetoaddress(*args, **kwargs) + return blocks + + def generatetodescriptor(self, generator, *args, **kwargs): + blocks = generator.generatetodescriptor(*args, **kwargs) + return blocks + def sync_blocks(self, nodes=None, wait=1, timeout=60): """ Wait until everybody has the same tip. @@ -749,7 +765,8 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass): gen_addresses = [k.address for k in TestNode.PRIV_KEYS][:3] + [ADDRESS_BCRT1_P2WSH_OP_TRUE] assert_equal(len(gen_addresses), 4) for i in range(8): - cache_node.generatetoaddress( + self.generatetoaddress( + cache_node, nblocks=25 if i != 7 else 24, address=gen_addresses[i % len(gen_addresses)], ) diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py index 54f2fdee21..ec27fd7f85 100644 --- a/test/functional/test_framework/util.py +++ b/test/functional/test_framework/util.py @@ -445,10 +445,10 @@ def find_output(node, txid, amount, *, blockhash=None): # Helper to create at least "count" utxos # Pass in a fee that is sufficient for relay and mining new transactions. -def create_confirmed_utxos(fee, node, count): +def create_confirmed_utxos(test_framework, fee, node, count): to_generate = int(0.5 * count) + 101 while to_generate > 0: - node.generate(min(25, to_generate)) + test_framework.generate(node, min(25, to_generate)) to_generate -= 25 utxos = node.listunspent() iterations = count - len(utxos) @@ -469,7 +469,7 @@ def create_confirmed_utxos(fee, node, count): node.sendrawtransaction(signed_tx) while (node.getmempoolinfo()['size'] > 0): - node.generate(1) + test_framework.generate(node, 1) utxos = node.listunspent() assert len(utxos) >= count @@ -541,7 +541,7 @@ def create_lots_of_big_transactions(node, txouts, utxos, num, fee): return txids -def mine_large_block(node, utxos=None): +def mine_large_block(test_framework, node, utxos=None): # generate a 66k transaction, # and 14 of them is close to the 1MB block limit num = 14 @@ -552,17 +552,17 @@ def mine_large_block(node, utxos=None): utxos.extend(node.listunspent()) fee = 100 * node.getnetworkinfo()["relayfee"] create_lots_of_big_transactions(node, txouts, utxos, num, fee=fee) - node.generate(1) + test_framework.generate(node, 1) -def generate_to_height(node, target_height): +def generate_to_height(test_framework, node, target_height): """Generates blocks until a given target block height has been reached. To prevent timeouts, only up to 200 blocks are generated per RPC call. Can be used to activate certain soft-forks (e.g. CSV, CLTV).""" current_height = node.getblockcount() while current_height < target_height: nblocks = min(200, target_height - current_height) - current_height += len(node.generate(nblocks)) + current_height += len(test_framework.generate(node, nblocks)) assert_equal(node.getblockcount(), target_height) |