Skip to content

Commit

Permalink
test: adds wait mempool param to generate_block
Browse files Browse the repository at this point in the history
  • Loading branch information
m-schmoock authored and rustyrussell committed Jun 6, 2019
1 parent ba036b7 commit dd87024
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,19 @@ def get_proxy(self):
proxy.start()
return proxy

def generate_block(self, numblocks=1):
# wait_for_mempool can be used to wait for the mempool before generating blocks:
# True := wait for at least 1 transation
# int > 0 := wait for at least N transactions
# 'tx_id' := wait for one transaction id given as a string
# ['tx_id1', 'tx_id2'] := wait until all of the specified transaction IDs
def generate_block(self, numblocks=1, wait_for_mempool=0):
if wait_for_mempool:
if isinstance(wait_for_mempool, str):
wait_for_mempool = [wait_for_mempool]
if isinstance(wait_for_mempool, list):
wait_for(lambda: all(txid in self.rpc.getrawmempool() for txid in wait_for_mempool))
else:
wait_for(lambda: len(self.rpc.getrawmempool()) >= wait_for_mempool)
# As of 0.16, generate() is removed; use generatetoaddress.
return self.rpc.generatetoaddress(numblocks, self.rpc.getnewaddress())

Expand Down

0 comments on commit dd87024

Please sign in to comment.