Skip to content

Commit

Permalink
pytest: speed up test_opening.py::test_funder_contribution_limits whe…
Browse files Browse the repository at this point in the history
…n !DEVELOPER

This test takes 695 seconds, because fundwallet waits for the wallet to
notice the tx, which takes 60 seconds if not DEVELOPER.  Do all the waiting
at once, and this speeds the test up to 153 seconds.

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Jun 4, 2021
1 parent 2f21435 commit adbabbf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
7 changes: 4 additions & 3 deletions contrib/pyln-testing/pyln/testing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,11 +729,12 @@ def openchannel(self, remote_node, capacity=FUNDAMOUNT, addrtype="p2sh-segwit",
r'Funding tx {} depth'.format(fundingtx['txid']))
return {'address': addr, 'wallettxid': wallettxid, 'fundingtx': fundingtx}

def fundwallet(self, sats, addrtype="p2sh-segwit"):
def fundwallet(self, sats, addrtype="p2sh-segwit", mine_block=True):
addr = self.rpc.newaddr(addrtype)[addrtype]
txid = self.bitcoin.rpc.sendtoaddress(addr, sats / 10**8)
self.bitcoin.generate_block(1)
self.daemon.wait_for_log('Owning output .* txid {} CONFIRMED'.format(txid))
if mine_block:
self.bitcoin.generate_block(1)
self.daemon.wait_for_log('Owning output .* txid {} CONFIRMED'.format(txid))
return addr, txid

def fundbalancedchannel(self, remote_node, total_capacity, announce=True):
Expand Down
38 changes: 18 additions & 20 deletions tests/test_opening.py
Original file line number Diff line number Diff line change
Expand Up @@ -1027,30 +1027,28 @@ def test_funder_contribution_limits(node_factory, bitcoind):
'feerates': (5000, 5000, 5000, 5000)}
l1, l2, l3 = node_factory.get_nodes(3, opts=opts)

l1.fundwallet(10**8)
# We do a lot of these, so do them all then mine all at once.
addr, txid = l1.fundwallet(10**8, mine_block=False)
l1msgs = ['Owning output .* txid {} CONFIRMED'.format(txid)]

# Give l2 lots of utxos
l2.fundwallet(10**3) # this one is too small to add
l2.fundwallet(10**5)
l2.fundwallet(10**4)
l2.fundwallet(10**4)
l2.fundwallet(10**4)
l2.fundwallet(10**4)
l2.fundwallet(10**4)
l2msgs = []
for amt in (10**3, # this one is too small to add
10**5, 10**4, 10**4, 10**4, 10**4, 10**4):
addr, txid = l2.fundwallet(amt, mine_block=False)
l2msgs.append('Owning output .* txid {} CONFIRMED'.format(txid))

# Give l3 lots of utxos
l3.fundwallet(10**3) # this one is too small to add
l3.fundwallet(10**4)
l3.fundwallet(10**4)
l3.fundwallet(10**4)
l3.fundwallet(10**4)
l3.fundwallet(10**4)
l3.fundwallet(10**4)
l3.fundwallet(10**4)
l3.fundwallet(10**4)
l3.fundwallet(10**4)
l3.fundwallet(10**4)
l3.fundwallet(10**4)
l3msgs = []
for amt in (10**3, # this one is too small to add
10**4, 10**4, 10**4, 10**4, 10**4, 10**4, 10**4, 10**4, 10**4, 10**4, 10**4):
addr, txid = l3.fundwallet(amt, mine_block=False)
l3msgs.append('Owning output .* txid {} CONFIRMED'.format(txid))

bitcoind.generate_block(1)
l1.daemon.wait_for_logs(l1msgs)
l2.daemon.wait_for_logs(l2msgs)
l3.daemon.wait_for_logs(l3msgs)

# Contribute 100% of available funds to l2, all 6 utxos (smallest utxo
# 10**3 is left out)
Expand Down

0 comments on commit adbabbf

Please sign in to comment.