test: fix lndrest on regtest (#2811)

* fix: lndrest on regtest
* fix some race conditions on lndrest
This commit is contained in:
dni ⚡ 2024-12-12 07:54:43 +01:00 committed by GitHub
parent 61c71660b8
commit 1b9bb32ca0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 19 additions and 11 deletions

View file

@ -75,7 +75,7 @@ jobs:
strategy: strategy:
matrix: matrix:
python-version: ["3.10"] python-version: ["3.10"]
backend-wallet-class: ["LndWallet", "CoreLightningWallet", "CoreLightningRestWallet", "LNbitsWallet", "EclairWallet"] backend-wallet-class: ["LndRestWallet", "LndWallet", "CoreLightningWallet", "CoreLightningRestWallet", "LNbitsWallet", "EclairWallet"]
with: with:
custom-pytest: "poetry run pytest tests/regtest" custom-pytest: "poetry run pytest tests/regtest"
python-version: ${{ matrix.python-version }} python-version: ${{ matrix.python-version }}

View file

@ -159,9 +159,15 @@ class LndRestNode(Node):
timeout=None, timeout=None,
) as stream: ) as stream:
async for chunk in stream.aiter_text(): async for chunk in stream.aiter_text():
if chunk: if not chunk:
chunk = json.loads(chunk) continue
logger.info(f"LND Channel close update: {chunk['result']}") chunk = json.loads(chunk)
if "error" in chunk:
raise HTTPException(
status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
detail=chunk["error"].get("message"),
)
logger.info(f"LND Channel close update: {chunk.get('result')}")
async def close_channel( async def close_channel(
self, self,

View file

@ -3,11 +3,6 @@ import pytest
from .helpers import get_hold_invoice, get_real_invoice from .helpers import get_hold_invoice, get_real_invoice
@pytest.fixture(scope="session")
def anyio_backend():
return "asyncio"
@pytest.fixture(scope="function") @pytest.fixture(scope="function")
async def hold_invoice(): async def hold_invoice():
invoice = get_hold_invoice(100) invoice = get_hold_invoice(100)

View file

@ -20,7 +20,8 @@ docker_lightning_cli = [
docker_bitcoin_cli = [ docker_bitcoin_cli = [
"docker", "docker",
"exec", "exec",
"lnbits-bitcoind-1-1" "bitcoin-cli", "lnbits-bitcoind-1",
"bitcoin-cli",
"-rpcuser=lnbits", "-rpcuser=lnbits",
"-rpcpassword=lnbits", "-rpcpassword=lnbits",
"-regtest", "-regtest",

View file

@ -57,6 +57,7 @@ async def test_pay_real_invoice(
await asyncio.sleep(1) await asyncio.sleep(1)
balance = await get_node_balance_sats() balance = await get_node_balance_sats()
# TODO: maybe take fee into consideration?
assert prev_balance - balance == 100 assert prev_balance - balance == 100
@ -158,7 +159,7 @@ async def test_pay_hold_invoice_check_pending(
headers=adminkey_headers_from, headers=adminkey_headers_from,
) )
) )
await asyncio.sleep(1) await asyncio.sleep(3)
# get payment hash from the invoice # get payment hash from the invoice
invoice_obj = bolt11.decode(invoice["payment_request"]) invoice_obj = bolt11.decode(invoice["payment_request"])
settle_invoice(preimage) settle_invoice(preimage)

View file

@ -102,6 +102,8 @@ async def test_node_payments(node_client, real_invoice, adminkey_headers_from):
@pytest.mark.anyio @pytest.mark.anyio
async def test_channel_management(node_client): async def test_channel_management(node_client):
async def get_channels(): async def get_channels():
# lndrest is slow / async with channel commands
await asyncio.sleep(3)
response = await node_client.get("/node/api/v1/channels") response = await node_client.get("/node/api/v1/channels")
assert response.status_code == 200 assert response.status_code == 200
return parse_obj_as(list[NodeChannel], response.json()) return parse_obj_as(list[NodeChannel], response.json())
@ -134,6 +136,7 @@ async def test_channel_management(node_client):
) )
assert response.status_code == 200 assert response.status_code == 200
created = ChannelPoint(**response.json()) created = ChannelPoint(**response.json())
data = await get_channels() data = await get_channels()
assert any( assert any(
channel.point == created and channel.state == ChannelState.PENDING channel.point == created and channel.state == ChannelState.PENDING
@ -145,6 +148,8 @@ async def test_channel_management(node_client):
# left for testing # left for testing
mine_blocks(5) mine_blocks(5)
await asyncio.sleep(1)
@pytest.mark.anyio @pytest.mark.anyio
async def test_peer_management(node_client): async def test_peer_management(node_client):