mirror of
https://github.com/aljazceru/plugins.git
synced 2025-12-23 16:14:20 +01:00
paytest: Create a new plugin to test pay implementations
This commit is contained in:
60
paytest/test_paytest.py
Normal file
60
paytest/test_paytest.py
Normal file
@@ -0,0 +1,60 @@
|
||||
from pyln.testing.fixtures import * # noqa: F401,F403
|
||||
from pyln.testing.utils import DEVELOPER
|
||||
from pyln.client import RpcError
|
||||
import os
|
||||
import unittest
|
||||
import pytest
|
||||
from pprint import pprint
|
||||
|
||||
|
||||
pluginopt = {'plugin': os.path.join(os.path.dirname(__file__), "paytest.py")}
|
||||
EXPERIMENTAL_FEATURES = int(os.environ.get("EXPERIMENTAL_FEATURES", "0"))
|
||||
|
||||
|
||||
def test_start(node_factory):
|
||||
node_factory.get_node(options=pluginopt)
|
||||
|
||||
|
||||
def test_invoice(node_factory):
|
||||
l1 = node_factory.get_node(options=pluginopt)
|
||||
inv = l1.rpc.testinvoice('03'*33)
|
||||
details = l1.rpc.decodepay(inv['invoice'])
|
||||
pprint(details)
|
||||
|
||||
|
||||
def test_simple_pay(node_factory):
|
||||
""" l1 generates and pays an invoice on behalf of l2.
|
||||
"""
|
||||
l1, l2 = node_factory.line_graph(2, opts=pluginopt, wait_for_announce=True)
|
||||
|
||||
inv = l1.rpc.testinvoice(destination=l2.info['id'], amount=1)['invoice']
|
||||
details = l1.rpc.decodepay(inv)
|
||||
pprint(details)
|
||||
|
||||
# Paying the invoice without the reinterpretation from paytest
|
||||
# will cause an unknown payment details directly.
|
||||
with pytest.raises(RpcError, match=r'WIRE_INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS'):
|
||||
l1.rpc.pay(inv)
|
||||
|
||||
|
||||
def test_mpp_pay(node_factory):
|
||||
""" l1 send a payment that is going to be split.
|
||||
"""
|
||||
l1, l2 = node_factory.line_graph(2, opts=pluginopt, wait_for_announce=True)
|
||||
res = l1.rpc.paytest(l2.info['id'], 10**8)
|
||||
|
||||
from pprint import pprint
|
||||
#pprint(res)
|
||||
|
||||
l2.daemon.wait_for_log(r'Received 100000000/100000000 with [0-9]+ parts')
|
||||
|
||||
parts = res['status']['attempts']
|
||||
assert len(parts) > 2 # Initial split + >1 part
|
||||
|
||||
failures = [p['failure']['data'] for p in parts if 'failure' in p and 'data' in p['failure']]
|
||||
pprint(failures)
|
||||
|
||||
outcomes = [f['failcode'] for f in failures]
|
||||
is16399 = [p == 16399 for p in outcomes]
|
||||
assert all(is16399)
|
||||
assert len(is16399) >= 1
|
||||
Reference in New Issue
Block a user