From 8ac9c73ea8d96c3ea1c2cc36d7b2da199a36ffbb Mon Sep 17 00:00:00 2001 From: Michael Schmoock Date: Thu, 20 Jul 2023 12:21:50 +0200 Subject: [PATCH] pytests: make pay helper able to route (optionaly) 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 --- contrib/pyln-testing/pyln/testing/utils.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/contrib/pyln-testing/pyln/testing/utils.py b/contrib/pyln-testing/pyln/testing/utils.py index 7b51fc3a8..ca1446c7e 100644 --- a/contrib/pyln-testing/pyln/testing/utils.py +++ b/contrib/pyln-testing/pyln/testing/utils.py @@ -1166,10 +1166,20 @@ class LightningNode(object): 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