Skip to content

Commit

Permalink
update test race conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
callebtc committed Jun 19, 2024
1 parent 97072ae commit 9c3f9f7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
settings.mint_backend_bolt11_sat = settings.mint_backend_bolt11_sat or "FakeWallet"
settings.fakewallet_brr = True
settings.fakewallet_delay_outgoing_payment = None
settings.fakewallet_delay_incoming_payment = 2
settings.fakewallet_delay_incoming_payment = 5
settings.fakewallet_stochastic_invoice = False
assert (
settings.mint_test_database != settings.mint_database
Expand Down
16 changes: 15 additions & 1 deletion tests/test_wallet_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def test_balance(cli_prefix):
assert result.exit_code == 0


def test_invoice(mint, cli_prefix):
def test_invoice_no_check(mint, cli_prefix):
runner = CliRunner()
result = runner.invoke(
cli,
Expand All @@ -132,6 +132,20 @@ def test_invoice(mint, cli_prefix):
assert result.exit_code == 0


def test_invoice(mint, cli_prefix):
runner = CliRunner()
result = runner.invoke(
cli,
[*cli_prefix, "invoice", "1000"],
)

assert result.exception is None

wallet = asyncio.run(init_wallet())
assert wallet.available_balance >= 1000
assert result.exit_code == 0


def test_invoice_with_split(mint, cli_prefix):
runner = CliRunner()
result = runner.invoke(
Expand Down
15 changes: 10 additions & 5 deletions tests/test_wallet_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from cashu.wallet.wallet import Wallet
from tests.conftest import SERVER_ENDPOINT
from tests.helpers import (
is_fake,
pay_if_regtest,
)

Expand All @@ -27,6 +28,9 @@ async def wallet(mint):

@pytest.mark.asyncio
async def test_wallet_subscription_mint(wallet: Wallet):
if is_fake:
settings.fakewallet_delay_outgoing_payment = 2

if not wallet.mint_info.supports_nut(WEBSOCKETS_NUT):
pytest.skip("No websocket support")

Expand All @@ -45,20 +49,21 @@ def callback(msg: JSONRPCNotficationParams):
asyncio.run(wallet.mint(int(invoice.amount), id=invoice.id))

invoice, sub = await wallet.request_mint_with_callback(128, callback=callback)
pay_if_regtest(invoice.bolt11)
wait = settings.fakewallet_delay_incoming_payment or 2
await asyncio.sleep(wait + 2)

# TODO: check for pending and paid states according to: https://github.com/cashubtc/nuts/pull/136

# first we expect the issued=False state to arrive
await asyncio.sleep(2)

assert triggered
assert len(msg_stack) == 1
# assert len(msg_stack) == 1
assert msg_stack[0].payload["paid"] is True
assert msg_stack[0].payload["issued"] is False

# await asyncio.sleep(2)
# this will cause a second message
pay_if_regtest(invoice.bolt11)
wait = settings.fakewallet_delay_incoming_payment or 2
await asyncio.sleep(wait + 2)
assert len(msg_stack) == 2
assert msg_stack[1].payload["paid"] is True
assert msg_stack[1].payload["issued"] is True
Expand Down

0 comments on commit 9c3f9f7

Please sign in to comment.