test: add regtest testcase for no route failure (#3189)
This commit is contained in:
parent
ab3248da15
commit
c4c03d96a3
7 changed files with 128 additions and 53 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import pytest
|
||||
|
||||
from .helpers import get_hold_invoice, get_real_invoice
|
||||
from .helpers import get_hold_invoice, get_real_invoice, get_real_invoice_noroute
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
|
|
@ -22,3 +22,13 @@ async def real_amountless_invoice():
|
|||
invoice = get_real_invoice(0)
|
||||
yield invoice["payment_request"]
|
||||
del invoice
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
async def real_invoice_noroute():
|
||||
invoice = get_real_invoice_noroute(100)
|
||||
yield {
|
||||
"bolt11": invoice["payment_request"],
|
||||
"payment_hash": invoice["r_hash"],
|
||||
}
|
||||
del invoice
|
||||
|
|
|
|||
|
|
@ -39,6 +39,17 @@ docker_lightning_unconnected_cli = [
|
|||
]
|
||||
|
||||
|
||||
docker_lightning_noroute_cli = [
|
||||
"docker",
|
||||
"exec",
|
||||
"lnbits-lnd-4-1",
|
||||
"lncli",
|
||||
"--network",
|
||||
"regtest",
|
||||
"--rpcserver=lnd-4",
|
||||
]
|
||||
|
||||
|
||||
def run_cmd(cmd: list) -> str:
|
||||
timeout = 10
|
||||
process = Popen(cmd, stdout=PIPE, stderr=PIPE)
|
||||
|
|
@ -100,6 +111,12 @@ def get_real_invoice(sats: int) -> dict:
|
|||
return run_cmd_json(cmd)
|
||||
|
||||
|
||||
def get_real_invoice_noroute(sats: int) -> dict:
|
||||
cmd = docker_lightning_noroute_cli.copy()
|
||||
cmd.extend(["addinvoice", str(sats)])
|
||||
return run_cmd_json(cmd)
|
||||
|
||||
|
||||
def pay_real_invoice(invoice: str) -> str:
|
||||
cmd = docker_lightning_cli.copy()
|
||||
cmd.extend(["payinvoice", "--force", invoice])
|
||||
|
|
|
|||
|
|
@ -69,6 +69,68 @@ async def test_pay_real_invoice(
|
|||
assert prev_balance - balance == 100
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
@pytest.mark.skipif(is_fake, reason="this only works in regtest")
|
||||
async def test_pay_real_invoice_noroute(
|
||||
client,
|
||||
real_invoice_noroute,
|
||||
adminkey_headers_from,
|
||||
inkey_headers_from,
|
||||
):
|
||||
response = await client.post(
|
||||
"/api/v1/payments", json=real_invoice_noroute, headers=adminkey_headers_from
|
||||
)
|
||||
assert response.status_code == 520
|
||||
invoice = response.json()
|
||||
|
||||
assert invoice["status"] == "failed"
|
||||
|
||||
# check the payment status
|
||||
response = await client.get(
|
||||
f'/api/v1/payments/{real_invoice_noroute["payment_hash"]}',
|
||||
headers=inkey_headers_from,
|
||||
)
|
||||
assert response.status_code < 300
|
||||
payment = response.json()
|
||||
assert payment["paid"] is False
|
||||
assert payment["status"] == "failed"
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
@pytest.mark.skipif(is_fake, reason="this only works in regtest")
|
||||
async def test_pay_real_invoice_mainnet(
|
||||
client,
|
||||
adminkey_headers_from,
|
||||
inkey_headers_from,
|
||||
):
|
||||
"""regtest should fail paying a mainnet invoice"""
|
||||
inv = (
|
||||
"lnbc100n1p59ujlrpp5mn5g5tu7fz0up6asnz0gcceru4hwz0w42g7fuz8gxw67jl7kjjeqcqzyssp5qq"
|
||||
"5y92fwazqdtnu8u9p9qf333hqnkuvtuu5csdze5ak4q86hyrhq9q7sqqqqqqqqqqqqqqqqqqqsqqqqqys"
|
||||
"gqdq2f38xy6t5wvmqz9gxqrrssrzjqwryaup9lh50kkranzgcdnn2fgvx390wgj5jd07rwr3vxeje0glc"
|
||||
"lll4ttz7sp6kpvqqqqlgqqqqqeqqjqm9fkydmtwsxcxx3j44x9fckjqttg54zlxzw92yeaz9nzn8w7hgv"
|
||||
"87ph5ug4wmgxqpk929k7l6dsnc2y9532daaqlpg9tfjglshuh48cpjh0dua"
|
||||
)
|
||||
payment_hash = "dce88a2f9e489fc0ebb0989e8c6323e56ee13dd5523c9e08e833b5e97fd694b2"
|
||||
|
||||
response = await client.post(
|
||||
"/api/v1/payments", json={"bolt11": inv}, headers=adminkey_headers_from
|
||||
)
|
||||
assert response.status_code == 520
|
||||
invoice = response.json()
|
||||
assert invoice["status"] == "failed"
|
||||
|
||||
# check the payment status
|
||||
response = await client.get(
|
||||
f"/api/v1/payments/{payment_hash}",
|
||||
headers=inkey_headers_from,
|
||||
)
|
||||
assert response.status_code < 300
|
||||
payment = response.json()
|
||||
assert payment["paid"] is False
|
||||
assert payment["status"] == "failed"
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
@pytest.mark.skipif(is_fake, reason="this only works in regtest")
|
||||
async def test_create_real_invoice(client, adminkey_headers_from, inkey_headers_from):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue