Skip to content

Commit

Permalink
pytests: make pay helper able to route (optionaly)
Browse files Browse the repository at this point in the history
This makes the pay helper function being able to route
a payment using the optional `route` paramter that defaults to `False`.

I added this, as some plugins maintained their own version of `pay` that
needed routed payment helper.

Changelog-None
  • Loading branch information
m-schmoock authored and rustyrussell committed Oct 17, 2023
1 parent e938999 commit 8ac9c73
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion contrib/pyln-testing/pyln/testing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1166,10 +1166,20 @@ def wait_for_htlcs(self, scids=None):
wait_for(lambda: len(self.rpc.listpeerchannels(peer["id"])['channels'][idx]['htlcs']) == 0)

# This sends money to a directly connected peer
def pay(self, dst, amt, label=None):
# if `route` is `True`, it can also send over the network.
def pay(self, dst, amt, label=None, route=False):
if not label:
label = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(20))

if route is True:
invoice = dst.rpc.invoice(amt, label, "desc")
route = self.rpc.getroute(dst.info["id"], amt, riskfactor=0, fuzzpercent=0)
self.rpc.sendpay(route["route"], invoice["payment_hash"], payment_secret=invoice.get('payment_secret'))
result = self.rpc.waitsendpay(invoice["payment_hash"])
assert(result.get('status') == 'complete')
self.wait_for_htlcs()
return

# check we are connected
dst_id = dst.info['id']
assert len(self.rpc.listpeers(dst_id).get('peers')) == 1
Expand Down

0 comments on commit 8ac9c73

Please sign in to comment.