test: add boltz fundingsource to regtest (#3677)
Co-authored-by: Vlad Stan <stan.v.vlad@gmail.com>
This commit is contained in:
parent
281c3df826
commit
132192bc94
10 changed files with 137 additions and 57 deletions
|
|
@ -6,6 +6,11 @@ from subprocess import PIPE, Popen, TimeoutExpired
|
|||
|
||||
from loguru import logger
|
||||
|
||||
from lnbits.wallets import get_funding_source
|
||||
|
||||
funding_source = get_funding_source()
|
||||
is_boltz_wallet = funding_source.__class__.__name__ == "BoltzWallet"
|
||||
|
||||
docker_lightning_cli = [
|
||||
"docker",
|
||||
"exec",
|
||||
|
|
@ -27,6 +32,16 @@ docker_bitcoin_cli = [
|
|||
]
|
||||
|
||||
|
||||
docker_elements_cli = [
|
||||
"docker",
|
||||
"exec",
|
||||
"lnbits-elementsd-1",
|
||||
"elements-cli",
|
||||
"-rpcport=18884",
|
||||
"-chain=liquidregtest",
|
||||
]
|
||||
|
||||
|
||||
docker_lightning_unconnected_cli = [
|
||||
"docker",
|
||||
"exec",
|
||||
|
|
@ -50,7 +65,7 @@ docker_lightning_noroute_cli = [
|
|||
|
||||
|
||||
def run_cmd(cmd: list) -> str:
|
||||
timeout = 10
|
||||
timeout = 30
|
||||
process = Popen(cmd, stdout=PIPE, stderr=PIPE)
|
||||
|
||||
logger.debug(f"running command: {cmd}")
|
||||
|
|
@ -128,6 +143,12 @@ def mine_blocks(blocks: int = 1) -> str:
|
|||
return run_cmd(cmd)
|
||||
|
||||
|
||||
def mine_blocks_liquid(blocks: int = 1) -> str:
|
||||
cmd = docker_elements_cli.copy()
|
||||
cmd.extend(["-generate", str(blocks)])
|
||||
return run_cmd(cmd)
|
||||
|
||||
|
||||
def get_unconnected_node_uri() -> str:
|
||||
cmd = docker_lightning_unconnected_cli.copy()
|
||||
cmd.append("getinfo")
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ from ..helpers import FakeError, is_fake, is_regtest
|
|||
from .helpers import (
|
||||
cancel_invoice,
|
||||
get_real_invoice,
|
||||
mine_blocks_liquid,
|
||||
pay_real_invoice,
|
||||
settle_invoice,
|
||||
)
|
||||
|
|
@ -66,7 +67,7 @@ async def test_pay_real_invoice(
|
|||
|
||||
await asyncio.sleep(1)
|
||||
balance = await get_node_balance_sats()
|
||||
assert prev_balance - balance == 100
|
||||
assert prev_balance - balance == 100 + abs(payment.fee // 1000)
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
|
|
@ -153,7 +154,8 @@ async def test_create_real_invoice(client, adminkey_headers_from, inkey_headers_
|
|||
|
||||
async def on_paid(payment: Payment):
|
||||
|
||||
assert payment.checking_id == invoice["payment_hash"]
|
||||
assert payment.payment_hash == invoice["payment_hash"]
|
||||
assert payment.checking_id == invoice["checking_id"]
|
||||
|
||||
response = await client.get(
|
||||
f'/api/v1/payments/{invoice["payment_hash"]}', headers=inkey_headers_from
|
||||
|
|
@ -164,7 +166,8 @@ async def test_create_real_invoice(client, adminkey_headers_from, inkey_headers_
|
|||
|
||||
await asyncio.sleep(1)
|
||||
balance = await get_node_balance_sats()
|
||||
assert balance - prev_balance == create_invoice.amount
|
||||
fee = abs(payment_status.get("details", {}).get("fee", 0) // 1000)
|
||||
assert balance - prev_balance == create_invoice.amount - fee
|
||||
|
||||
assert payment_status.get("preimage") is not None
|
||||
|
||||
|
|
@ -200,6 +203,8 @@ async def test_pay_real_invoice_set_pending_and_check_state(
|
|||
assert len(invoice["payment_hash"]) == 64
|
||||
assert len(invoice["checking_id"]) > 0
|
||||
|
||||
mine_blocks_liquid(1)
|
||||
await asyncio.sleep(1)
|
||||
# check the payment status
|
||||
response = await client.get(
|
||||
f'/api/v1/payments/{invoice["payment_hash"]}', headers=inkey_headers_from
|
||||
|
|
@ -341,6 +346,7 @@ async def test_pay_hold_invoice_check_pending_and_fail_cancel_payment_task_in_me
|
|||
assert preimage_hash == invoice_obj.payment_hash
|
||||
cancel_invoice(preimage_hash)
|
||||
|
||||
mine_blocks_liquid(1)
|
||||
# check if paid
|
||||
await asyncio.sleep(1)
|
||||
|
||||
|
|
@ -382,7 +388,9 @@ async def test_receive_real_invoice_set_pending_and_check_state(
|
|||
assert not payment_status["paid"]
|
||||
|
||||
async def on_paid(payment: Payment):
|
||||
assert payment.checking_id == invoice["payment_hash"]
|
||||
|
||||
assert payment.payment_hash == invoice["payment_hash"]
|
||||
assert payment.checking_id == invoice["checking_id"]
|
||||
|
||||
response = await client.get(
|
||||
f'/api/v1/payments/{invoice["payment_hash"]}', headers=inkey_headers_from
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ from lnbits.core.services import (
|
|||
from lnbits.wallets import get_funding_source
|
||||
from lnbits.wallets.base import PaymentStatus
|
||||
|
||||
from .helpers import is_boltz_wallet
|
||||
|
||||
description = "test create invoice"
|
||||
|
||||
|
||||
|
|
@ -17,7 +19,10 @@ async def test_create_invoice(from_wallet):
|
|||
amount=1000,
|
||||
memo=description,
|
||||
)
|
||||
assert payment.preimage
|
||||
|
||||
# we cannot know the preimage of the swap yet
|
||||
if not is_boltz_wallet:
|
||||
assert payment.preimage
|
||||
|
||||
invoice = decode(payment.bolt11)
|
||||
assert invoice.payment_hash == payment.payment_hash
|
||||
|
|
@ -35,7 +40,10 @@ async def test_create_internal_invoice(from_wallet):
|
|||
payment = await create_invoice(
|
||||
wallet_id=from_wallet.id, amount=1000, memo=description, internal=True
|
||||
)
|
||||
assert payment.preimage
|
||||
|
||||
# we cannot know the preimage of the swap yet
|
||||
if not is_boltz_wallet:
|
||||
assert payment.preimage
|
||||
|
||||
invoice = decode(payment.bolt11)
|
||||
assert invoice.payment_hash == payment.payment_hash
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ from lnbits.core.services import (
|
|||
)
|
||||
from lnbits.exceptions import PaymentError
|
||||
|
||||
from .helpers import is_boltz_wallet
|
||||
|
||||
description = "test pay invoice"
|
||||
|
||||
|
||||
|
|
@ -17,9 +19,12 @@ async def test_services_pay_invoice(to_wallet, real_invoice):
|
|||
description=description,
|
||||
)
|
||||
assert payment
|
||||
assert payment.status == PaymentState.SUCCESS
|
||||
assert payment.memo == description
|
||||
assert payment.preimage
|
||||
if not is_boltz_wallet:
|
||||
assert payment.status == PaymentState.SUCCESS
|
||||
assert payment.preimage
|
||||
else:
|
||||
assert payment.status == PaymentState.PENDING
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue