test: refactor lockup_drain add helpers drain and force_feerates

This commit is contained in:
Michael Schmoock
2020-03-08 11:36:25 +01:00
committed by Christian Decker
parent e1ba42f139
commit 80ff9c5b63
2 changed files with 31 additions and 22 deletions

View File

@@ -1,4 +1,5 @@
from bitcoin.rpc import RawProxy as BitcoinProxy
from pyln.client import RpcError
from pyln.testing.btcproxy import BitcoinRpcProxy
from collections import OrderedDict
from decimal import Decimal
@@ -811,6 +812,7 @@ class LightningNode(object):
if 'htlcs' in channel:
wait_for(lambda: len(self.rpc.listpeers()['peers'][p]['channels'][c]['htlcs']) == 0)
# This sends money to a directly connected peer
def pay(self, dst, amt, label=None):
if not label:
label = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(20))
@@ -839,6 +841,18 @@ class LightningNode(object):
result = self.rpc.waitsendpay(rhash)
assert(result.get('status') == 'complete')
# This helper sends all money to a peer until even 1 msat can't get through.
def drain(self, peer):
total = 0
msat = 16**9
while msat != 0:
try:
self.pay(peer, msat)
total += msat
except RpcError:
msat //= 2
return total
# Note: this feeds through the smoother in update_feerate, so changing
# it on a running daemon may not give expected result!
def set_feerates(self, feerates, wait_for_effect=True):
@@ -868,6 +882,15 @@ class LightningNode(object):
if wait_for_effect:
wait_for(lambda: self.daemon.rpcproxy.mock_counts['estimatesmartfee'] >= 3)
# force new feerates by restarting and thus skipping slow smoothed process
# Note: testnode must be created with: opts={'may_reconnect': True}
def force_feerates(self, rate):
assert(self.may_reconnect)
self.set_feerates([rate] * 3, False)
self.restart()
self.daemon.wait_for_log('peer_out WIRE_UPDATE_FEE')
assert(self.rpc.feerates('perkw')['perkw']['normal'] == rate)
def wait_for_onchaind_broadcast(self, name, resolve=None):
"""Wait for onchaind to drop tx name to resolve (if any)"""
if resolve: