From fe2ea0852bf8c1d7b8f4f1fd77268c172189be6c Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Tue, 14 Nov 2023 21:14:54 -0300 Subject: [PATCH] tests succeed with lndrestwallet --- Makefile | 7 ++-- cashu/wallet/cli/cli.py | 16 +++++++-- tests/helpers.py | 5 +++ tests/test_cli.py | 65 +++++++++++++++++++++++++++++++---- tests/test_mint_operations.py | 5 +++ tests/test_wallet.py | 54 ++++++++++++++++++----------- tests/test_wallet_api.py | 16 +++++++++ tests/test_wallet_htlc.py | 10 ++++++ tests/test_wallet_p2pk.py | 15 ++++++++ tests/test_wallet_restore.py | 7 ++++ 10 files changed, 167 insertions(+), 33 deletions(-) diff --git a/Makefile b/Makefile index 154188d2..93964999 100644 --- a/Makefile +++ b/Makefile @@ -31,7 +31,6 @@ package: test: PYTHONUNBUFFERED=1 \ DEBUG=true \ - MINT_LIGHTNING_BACKEND=FakeWallet \ poetry run pytest tests --cov-report xml --cov cashu test-lndrest: @@ -39,9 +38,9 @@ test-lndrest: DEBUG=true \ MINT_LIGHTNING_BACKEND=LndRestWallet \ MINT_LND_REST_ENDPOINT=https://localhost:8081/ \ - MINT_LND_REST_CERT=../legend-regtest-enviroment/data/lnd-3/tls.cert \ - MINT_LND_REST_MACAROON=../legend-regtest-enviroment/data/lnd-3/data/chain/bitcoin/regtest/admin.macaroon \ - poetry run pytest tests/test_wallet.py --cov-report xml --cov cashu + MINT_LND_REST_CERT=../cashu-regtest-enviroment/data/lnd-3/tls.cert \ + MINT_LND_REST_MACAROON=../cashu-regtest-enviroment/data/lnd-3/data/chain/bitcoin/regtest/admin.macaroon \ + poetry run pytest tests/test_cli.py --cov-report xml --cov cashu install: make clean diff --git a/cashu/wallet/cli/cli.py b/cashu/wallet/cli/cli.py index 4be2cbea..eceb4fe5 100644 --- a/cashu/wallet/cli/cli.py +++ b/cashu/wallet/cli/cli.py @@ -210,9 +210,17 @@ async def pay(ctx: Context, invoice: str, yes: bool): help="Split minted tokens with a specific amount.", type=int, ) +@click.option( + "--no-check", + "-n", + default=False, + is_flag=True, + help="Do not check if invoice is paid.", + type=bool, +) @click.pass_context @coro -async def invoice(ctx: Context, amount: int, id: str, split: int): +async def invoice(ctx: Context, amount: int, id: str, split: int, no_check: bool): wallet: Wallet = ctx.obj["WALLET"] await wallet.load_mint() wallet.status() @@ -236,9 +244,11 @@ async def invoice(ctx: Context, amount: int, id: str, split: int): print(f"Invoice: {invoice.bolt11}") print("") print( - "If you abort this you can use this command to recheck the" - f" invoice:\ncashu invoice {amount} --id {invoice.id}" + "You can use this command to check the invoice: cashu invoice" + f" {amount} --id {invoice.id}" ) + if no_check: + return check_until = time.time() + 5 * 60 # check for five minutes print("") print( diff --git a/tests/helpers.py b/tests/helpers.py index b897112f..e6d084a6 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -177,3 +177,8 @@ def pay_onchain(address: str, sats: int) -> str: # # FIXME: do this once mock data is removed from test data folder # # os.remove(settings.lnbits_data_folder + "/database.sqlite3") # pass + + +def pay_if_regtest(bolt11: str): + if is_regtest: + pay_real_invoice(bolt11) diff --git a/tests/test_cli.py b/tests/test_cli.py index 9bb1f86b..1e942905 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -7,6 +7,7 @@ from cashu.core.settings import settings from cashu.wallet.cli.cli import cli from cashu.wallet.wallet import Wallet +from tests.helpers import is_fake, pay_if_regtest @pytest.fixture(autouse=True, scope="session") @@ -14,6 +15,16 @@ def cli_prefix(): yield ["--wallet", "test_cli_wallet", "--host", settings.mint_url, "--tests"] +def get_bolt11_and_invoice_id_from_invoice_command(output: str) -> (str, str): + invoice = [ + line.split(" ")[1] for line in output.split("\n") if line.startswith("Invoice") + ][0] + invoice_id = [ + line.split(" ")[-1] for line in output.split("\n") if line.startswith("You can") + ][0] + return invoice, invoice_id + + async def init_wallet(): wallet = await Wallet.with_db( url=settings.mint_host, @@ -77,17 +88,42 @@ def test_balance(cli_prefix): assert result.exit_code == 0 -def test_invoice(mint, cli_prefix): +@pytest.mark.skipif(not is_fake, reason="only on fakewallet") +def test_invoice_automatic_fakewallet(mint, cli_prefix): runner = CliRunner() result = runner.invoke( cli, - [*cli_prefix, "invoice", "1000"], + [*cli_prefix, "invoice", "-n", "1000"], ) assert result.exception is None print("INVOICE") print(result.output) wallet = asyncio.run(init_wallet()) - # assert wallet.available_balance >= 1000 + assert wallet.available_balance >= 1000 + assert f"Balance: {wallet.available_balance} sat" in result.output + assert result.exit_code == 0 + + +def test_invoice(mint, cli_prefix): + runner = CliRunner() + result = runner.invoke( + cli, + [*cli_prefix, "invoice", "-n", "1000"], + ) + + assert result.exception is None + + invoice, invoice_id = get_bolt11_and_invoice_id_from_invoice_command(result.output) + pay_if_regtest(invoice) + + result = runner.invoke( + cli, + [*cli_prefix, "invoice", "1000", "--id", invoice_id], + ) + assert result.exception is None + + wallet = asyncio.run(init_wallet()) + assert wallet.available_balance >= 1000 assert f"Balance: {wallet.available_balance} sat" in result.output assert result.exit_code == 0 @@ -96,11 +132,28 @@ def test_invoice_with_split(mint, cli_prefix): runner = CliRunner() result = runner.invoke( cli, - [*cli_prefix, "invoice", "10", "-s", "1"], + [ + *cli_prefix, + "invoice", + "10", + "-s", + "1", + "-n", + ], ) assert result.exception is None - # wallet = asyncio.run(init_wallet()) - # assert wallet.proof_amounts.count(1) >= 10 + + invoice, invoice_id = get_bolt11_and_invoice_id_from_invoice_command(result.output) + pay_if_regtest(invoice) + result = runner.invoke( + cli, + [*cli_prefix, "invoice", "10", "-s", "1", "--id", invoice_id], + ) + assert result.exception is None + + assert result.exception is None + wallet = asyncio.run(init_wallet()) + assert wallet.proof_amounts.count(1) >= 10 def test_wallets(cli_prefix): diff --git a/tests/test_mint_operations.py b/tests/test_mint_operations.py index 35e8c479..e4e9e739 100644 --- a/tests/test_mint_operations.py +++ b/tests/test_mint_operations.py @@ -5,6 +5,7 @@ from cashu.wallet.wallet import Wallet from cashu.wallet.wallet import Wallet as Wallet1 from tests.conftest import SERVER_ENDPOINT +from tests.helpers import pay_if_regtest @pytest_asyncio.fixture(scope="function") @@ -23,8 +24,10 @@ async def wallet1(mint): async def test_melt(wallet1: Wallet, ledger: Ledger): # mint twice so we have enough to pay the second invoice back invoice = await wallet1.request_mint(64) + pay_if_regtest(invoice.bolt11) await wallet1.mint(64, id=invoice.id) invoice = await wallet1.request_mint(64) + pay_if_regtest(invoice.bolt11) await wallet1.mint(64, id=invoice.id) assert wallet1.balance == 128 total_amount, fee_reserve_sat = await wallet1.get_pay_amount_with_fees( @@ -41,6 +44,7 @@ async def test_melt(wallet1: Wallet, ledger: Ledger): @pytest.mark.asyncio async def test_split(wallet1: Wallet, ledger: Ledger): invoice = await wallet1.request_mint(64) + pay_if_regtest(invoice.bolt11) await wallet1.mint(64, id=invoice.id) keep_proofs, send_proofs = await wallet1.split_to_send(wallet1.proofs, 10) @@ -57,6 +61,7 @@ async def test_split(wallet1: Wallet, ledger: Ledger): @pytest.mark.asyncio async def test_check_proof_state(wallet1: Wallet, ledger: Ledger): invoice = await wallet1.request_mint(64) + pay_if_regtest(invoice.bolt11) await wallet1.mint(64, id=invoice.id) keep_proofs, send_proofs = await wallet1.split_to_send(wallet1.proofs, 10) diff --git a/tests/test_wallet.py b/tests/test_wallet.py index 59e69f00..6433009c 100644 --- a/tests/test_wallet.py +++ b/tests/test_wallet.py @@ -1,4 +1,3 @@ -import asyncio import shutil from pathlib import Path from typing import List, Union @@ -15,7 +14,7 @@ from cashu.wallet.wallet import Wallet as Wallet1 from cashu.wallet.wallet import Wallet as Wallet2 from tests.conftest import SERVER_ENDPOINT -from tests.helpers import is_regtest, pay_real_invoice +from tests.helpers import get_real_invoice, is_regtest, pay_if_regtest async def assert_err(f, msg: Union[str, CashuError]): @@ -140,12 +139,7 @@ async def test_get_keyset_ids(wallet1: Wallet): @pytest.mark.asyncio async def test_mint(wallet1: Wallet): invoice = await wallet1.request_mint(64) - if is_regtest: - await asyncio.sleep(2) - print("paying invoice in regtest...") - pay_real_invoice(invoice.bolt11) - print("Done") - await asyncio.sleep(5) + pay_if_regtest(invoice.bolt11) await wallet1.mint(64, id=invoice.id) assert wallet1.balance == 64 @@ -166,7 +160,7 @@ async def test_mint(wallet1: Wallet): async def test_mint_amounts(wallet1: Wallet): """Mint predefined amounts""" invoice = await wallet1.request_mint(64) - + pay_if_regtest(invoice.bolt11) amts = [1, 1, 1, 2, 2, 4, 16] await wallet1.mint(amount=sum(amts), split=amts, id=invoice.id) assert wallet1.balance == 27 @@ -196,6 +190,7 @@ async def test_mint_amounts_wrong_order(wallet1: Wallet): @pytest.mark.asyncio async def test_split(wallet1: Wallet): invoice = await wallet1.request_mint(64) + pay_if_regtest(invoice.bolt11) await wallet1.mint(64, id=invoice.id) assert wallet1.balance == 64 p1, p2 = await wallet1.split(wallet1.proofs, 20) @@ -211,6 +206,7 @@ async def test_split(wallet1: Wallet): @pytest.mark.asyncio async def test_split_to_send(wallet1: Wallet): invoice = await wallet1.request_mint(64) + pay_if_regtest(invoice.bolt11) await wallet1.mint(64, id=invoice.id) keep_proofs, spendable_proofs = await wallet1.split_to_send( wallet1.proofs, 32, set_reserved=True @@ -226,6 +222,7 @@ async def test_split_to_send(wallet1: Wallet): @pytest.mark.asyncio async def test_split_more_than_balance(wallet1: Wallet): invoice = await wallet1.request_mint(64) + pay_if_regtest(invoice.bolt11) await wallet1.mint(64, id=invoice.id) await assert_err( wallet1.split(wallet1.proofs, 128), @@ -239,8 +236,10 @@ async def test_split_more_than_balance(wallet1: Wallet): async def test_melt(wallet1: Wallet): # mint twice so we have enough to pay the second invoice back invoice = await wallet1.request_mint(64) + pay_if_regtest(invoice.bolt11) await wallet1.mint(64, id=invoice.id) invoice = await wallet1.request_mint(64) + pay_if_regtest(invoice.bolt11) await wallet1.mint(64, id=invoice.id) assert wallet1.balance == 128 @@ -252,38 +251,46 @@ async def test_melt(wallet1: Wallet): assert fee_reserve_sat == 2 _, send_proofs = await wallet1.split_to_send(wallet1.proofs, total_amount) + invoice_to_pay = invoice.bolt11 + invoice_payment_hash = str(invoice.payment_hash) + if is_regtest: + invoice_dict = get_real_invoice(64) + invoice_to_pay = invoice_dict["payment_request"] + invoice_payment_hash = str(invoice_dict["r_hash"]) + melt_response = await wallet1.pay_lightning( - send_proofs, invoice=invoice.bolt11, fee_reserve_sat=fee_reserve_sat + send_proofs, invoice=invoice_to_pay, fee_reserve_sat=fee_reserve_sat ) - assert melt_response.change - assert len(melt_response.change) == 1 + assert melt_response.change, "No change returned" + assert len(melt_response.change) == 1, "More than one change returned" # NOTE: we assume that we will get a token back from the same keyset as the ones we melted # this could be wrong if we melted tokens from an old keyset but the returned ones are # from a newer one. - assert melt_response.change[0].id == send_proofs[0].id + assert melt_response.change[0].id == send_proofs[0].id, "Wrong keyset returned" # verify that proofs in proofs_used db have the same melt_id as the invoice in the db - assert invoice.payment_hash + assert invoice.payment_hash, "No payment hash in invoice" invoice_db = await get_lightning_invoice( - db=wallet1.db, payment_hash=invoice.payment_hash, out=True + db=wallet1.db, payment_hash=invoice_payment_hash, out=True ) - assert invoice_db + assert invoice_db, "No invoice in db" proofs_used = await get_proofs( db=wallet1.db, melt_id=invoice_db.id, table="proofs_used" ) - assert len(proofs_used) == len(send_proofs) - assert all([p.melt_id == invoice_db.id for p in proofs_used]) + assert len(proofs_used) == len(send_proofs), "Not all proofs used" + assert all([p.melt_id == invoice_db.id for p in proofs_used]), "Wrong melt_id" # the payment was without fees so we need to remove it from the total amount - assert wallet1.balance == 128 - (total_amount - fee_reserve_sat) - assert wallet1.balance == 64 + assert wallet1.balance == 128 - (total_amount - fee_reserve_sat), "Wrong balance" + assert wallet1.balance == 64, "Wrong balance" @pytest.mark.asyncio async def test_split_to_send_more_than_balance(wallet1: Wallet): invoice = await wallet1.request_mint(64) + pay_if_regtest(invoice.bolt11) await wallet1.mint(64, id=invoice.id) await assert_err( wallet1.split_to_send(wallet1.proofs, 128, set_reserved=True), @@ -296,6 +303,7 @@ async def test_split_to_send_more_than_balance(wallet1: Wallet): @pytest.mark.asyncio async def test_double_spend(wallet1: Wallet): invoice = await wallet1.request_mint(64) + pay_if_regtest(invoice.bolt11) doublespend = await wallet1.mint(64, id=invoice.id) await wallet1.split(wallet1.proofs, 20) await assert_err( @@ -309,6 +317,7 @@ async def test_double_spend(wallet1: Wallet): @pytest.mark.asyncio async def test_duplicate_proofs_double_spent(wallet1: Wallet): invoice = await wallet1.request_mint(64) + pay_if_regtest(invoice.bolt11) doublespend = await wallet1.mint(64, id=invoice.id) await assert_err( wallet1.split(wallet1.proofs + doublespend, 20), @@ -321,6 +330,7 @@ async def test_duplicate_proofs_double_spent(wallet1: Wallet): @pytest.mark.asyncio async def test_send_and_redeem(wallet1: Wallet, wallet2: Wallet): invoice = await wallet1.request_mint(64) + pay_if_regtest(invoice.bolt11) await wallet1.mint(64, id=invoice.id) _, spendable_proofs = await wallet1.split_to_send( wallet1.proofs, 32, set_reserved=True @@ -339,6 +349,7 @@ async def test_send_and_redeem(wallet1: Wallet, wallet2: Wallet): async def test_invalidate_unspent_proofs(wallet1: Wallet): """Try to invalidate proofs that have not been spent yet. Should not work!""" invoice = await wallet1.request_mint(64) + pay_if_regtest(invoice.bolt11) await wallet1.mint(64, id=invoice.id) await wallet1.invalidate(wallet1.proofs) assert wallet1.balance == 64 @@ -348,6 +359,7 @@ async def test_invalidate_unspent_proofs(wallet1: Wallet): async def test_invalidate_unspent_proofs_without_checking(wallet1: Wallet): """Try to invalidate proofs that have not been spent yet but force no check.""" invoice = await wallet1.request_mint(64) + pay_if_regtest(invoice.bolt11) await wallet1.mint(64, id=invoice.id) await wallet1.invalidate(wallet1.proofs, check_spendable=False) assert wallet1.balance == 0 @@ -356,6 +368,7 @@ async def test_invalidate_unspent_proofs_without_checking(wallet1: Wallet): @pytest.mark.asyncio async def test_split_invalid_amount(wallet1: Wallet): invoice = await wallet1.request_mint(64) + pay_if_regtest(invoice.bolt11) await wallet1.mint(64, id=invoice.id) await assert_err( wallet1.split(wallet1.proofs, -1), @@ -366,6 +379,7 @@ async def test_split_invalid_amount(wallet1: Wallet): @pytest.mark.asyncio async def test_token_state(wallet1: Wallet): invoice = await wallet1.request_mint(64) + pay_if_regtest(invoice.bolt11) await wallet1.mint(64, id=invoice.id) assert wallet1.balance == 64 resp = await wallet1.check_proof_state(wallet1.proofs) diff --git a/tests/test_wallet_api.py b/tests/test_wallet_api.py index d07fa388..4bd66369 100644 --- a/tests/test_wallet_api.py +++ b/tests/test_wallet_api.py @@ -8,6 +8,7 @@ from cashu.wallet.api.app import app from cashu.wallet.wallet import Wallet from tests.conftest import SERVER_ENDPOINT +from tests.helpers import is_regtest @pytest_asyncio.fixture(scope="function") @@ -22,6 +23,7 @@ async def wallet(mint): yield wallet +@pytest.mark.skipif(is_regtest, reason="regtest") @pytest.mark.asyncio async def test_invoice(wallet: Wallet): with TestClient(app) as client: @@ -40,6 +42,7 @@ async def test_invoice(wallet: Wallet): print("paid") +@pytest.mark.skipif(is_regtest, reason="regtest") @pytest.mark.asyncio async def test_balance(): with TestClient(app) as client: @@ -50,6 +53,7 @@ async def test_balance(): assert response.json()["mints"] +@pytest.mark.skipif(is_regtest, reason="regtest") @pytest.mark.asyncio async def test_send(wallet: Wallet): with TestClient(app) as client: @@ -58,6 +62,7 @@ async def test_send(wallet: Wallet): assert response.json()["balance"] +@pytest.mark.skipif(is_regtest, reason="regtest") @pytest.mark.asyncio async def test_send_without_split(wallet: Wallet): with TestClient(app) as client: @@ -66,6 +71,7 @@ async def test_send_without_split(wallet: Wallet): assert response.json()["balance"] +@pytest.mark.skipif(is_regtest, reason="regtest") @pytest.mark.asyncio async def test_send_without_split_but_wrong_amount(wallet: Wallet): with TestClient(app) as client: @@ -73,6 +79,7 @@ async def test_send_without_split_but_wrong_amount(wallet: Wallet): assert response.status_code == 400 +@pytest.mark.skipif(is_regtest, reason="regtest") @pytest.mark.asyncio async def test_pending(): with TestClient(app) as client: @@ -80,6 +87,7 @@ async def test_pending(): assert response.status_code == 200 +@pytest.mark.skipif(is_regtest, reason="regtest") @pytest.mark.asyncio async def test_receive_all(wallet: Wallet): with TestClient(app) as client: @@ -89,6 +97,7 @@ async def test_receive_all(wallet: Wallet): assert response.json()["balance"] +@pytest.mark.skipif(is_regtest, reason="regtest") @pytest.mark.asyncio async def test_burn_all(wallet: Wallet): with TestClient(app) as client: @@ -99,6 +108,7 @@ async def test_burn_all(wallet: Wallet): assert response.json()["balance"] +@pytest.mark.skipif(is_regtest, reason="regtest") @pytest.mark.asyncio async def test_pay(): with TestClient(app) as client: @@ -113,6 +123,7 @@ async def test_pay(): assert response.status_code == 200 +@pytest.mark.skipif(is_regtest, reason="regtest") @pytest.mark.asyncio async def test_lock(): with TestClient(app) as client: @@ -120,6 +131,7 @@ async def test_lock(): assert response.status_code == 200 +@pytest.mark.skipif(is_regtest, reason="regtest") @pytest.mark.asyncio async def test_locks(): with TestClient(app) as client: @@ -127,6 +139,7 @@ async def test_locks(): assert response.status_code == 200 +@pytest.mark.skipif(is_regtest, reason="regtest") @pytest.mark.asyncio async def test_invoices(): with TestClient(app) as client: @@ -134,6 +147,7 @@ async def test_invoices(): assert response.status_code == 200 +@pytest.mark.skipif(is_regtest, reason="regtest") @pytest.mark.asyncio async def test_wallets(): with TestClient(app) as client: @@ -141,6 +155,7 @@ async def test_wallets(): assert response.status_code == 200 +@pytest.mark.skipif(is_regtest, reason="regtest") @pytest.mark.asyncio async def test_info(): with TestClient(app) as client: @@ -149,6 +164,7 @@ async def test_info(): assert response.json()["version"] +@pytest.mark.skipif(is_regtest, reason="regtest") @pytest.mark.asyncio async def test_flow(wallet: Wallet): with TestClient(app) as client: diff --git a/tests/test_wallet_htlc.py b/tests/test_wallet_htlc.py index 2bd0ce16..b64557f8 100644 --- a/tests/test_wallet_htlc.py +++ b/tests/test_wallet_htlc.py @@ -15,6 +15,7 @@ from cashu.wallet.wallet import Wallet as Wallet1 from cashu.wallet.wallet import Wallet as Wallet2 from tests.conftest import SERVER_ENDPOINT +from tests.helpers import pay_if_regtest async def assert_err(f, msg): @@ -59,6 +60,7 @@ async def wallet2(mint): @pytest.mark.asyncio async def test_create_htlc_secret(wallet1: Wallet): invoice = await wallet1.request_mint(64) + pay_if_regtest(invoice.bolt11) await wallet1.mint(64, id=invoice.id) preimage = "00000000000000000000000000000000" preimage_hash = hashlib.sha256(bytes.fromhex(preimage)).hexdigest() @@ -69,6 +71,7 @@ async def test_create_htlc_secret(wallet1: Wallet): @pytest.mark.asyncio async def test_htlc_split(wallet1: Wallet, wallet2: Wallet): invoice = await wallet1.request_mint(64) + pay_if_regtest(invoice.bolt11) await wallet1.mint(64, id=invoice.id) preimage = "00000000000000000000000000000000" preimage_hash = hashlib.sha256(bytes.fromhex(preimage)).hexdigest() @@ -81,6 +84,7 @@ async def test_htlc_split(wallet1: Wallet, wallet2: Wallet): @pytest.mark.asyncio async def test_htlc_redeem_with_preimage(wallet1: Wallet, wallet2: Wallet): invoice = await wallet1.request_mint(64) + pay_if_regtest(invoice.bolt11) await wallet1.mint(64, id=invoice.id) preimage = "00000000000000000000000000000000" # preimage_hash = hashlib.sha256(bytes.fromhex(preimage)).hexdigest() @@ -94,6 +98,7 @@ async def test_htlc_redeem_with_preimage(wallet1: Wallet, wallet2: Wallet): @pytest.mark.asyncio async def test_htlc_redeem_with_wrong_preimage(wallet1: Wallet, wallet2: Wallet): invoice = await wallet1.request_mint(64) + pay_if_regtest(invoice.bolt11) await wallet1.mint(64, id=invoice.id) preimage = "00000000000000000000000000000000" # preimage_hash = hashlib.sha256(bytes.fromhex(preimage)).hexdigest() @@ -111,6 +116,7 @@ async def test_htlc_redeem_with_wrong_preimage(wallet1: Wallet, wallet2: Wallet) @pytest.mark.asyncio async def test_htlc_redeem_with_no_signature(wallet1: Wallet, wallet2: Wallet): invoice = await wallet1.request_mint(64) + pay_if_regtest(invoice.bolt11) await wallet1.mint(64, id=invoice.id) preimage = "00000000000000000000000000000000" pubkey_wallet1 = await wallet1.create_p2pk_pubkey() @@ -130,6 +136,7 @@ async def test_htlc_redeem_with_no_signature(wallet1: Wallet, wallet2: Wallet): @pytest.mark.asyncio async def test_htlc_redeem_with_wrong_signature(wallet1: Wallet, wallet2: Wallet): invoice = await wallet1.request_mint(64) + pay_if_regtest(invoice.bolt11) await wallet1.mint(64, id=invoice.id) preimage = "00000000000000000000000000000000" pubkey_wallet1 = await wallet1.create_p2pk_pubkey() @@ -153,6 +160,7 @@ async def test_htlc_redeem_with_wrong_signature(wallet1: Wallet, wallet2: Wallet @pytest.mark.asyncio async def test_htlc_redeem_with_correct_signature(wallet1: Wallet, wallet2: Wallet): invoice = await wallet1.request_mint(64) + pay_if_regtest(invoice.bolt11) await wallet1.mint(64, id=invoice.id) preimage = "00000000000000000000000000000000" pubkey_wallet1 = await wallet1.create_p2pk_pubkey() @@ -174,6 +182,7 @@ async def test_htlc_redeem_hashlock_wrong_signature_timelock_correct_signature( wallet1: Wallet, wallet2: Wallet ): invoice = await wallet1.request_mint(64) + pay_if_regtest(invoice.bolt11) await wallet1.mint(64, id=invoice.id) preimage = "00000000000000000000000000000000" pubkey_wallet1 = await wallet1.create_p2pk_pubkey() @@ -207,6 +216,7 @@ async def test_htlc_redeem_hashlock_wrong_signature_timelock_wrong_signature( wallet1: Wallet, wallet2: Wallet ): invoice = await wallet1.request_mint(64) + pay_if_regtest(invoice.bolt11) await wallet1.mint(64, id=invoice.id) preimage = "00000000000000000000000000000000" pubkey_wallet1 = await wallet1.create_p2pk_pubkey() diff --git a/tests/test_wallet_p2pk.py b/tests/test_wallet_p2pk.py index 2dbd5bfb..bb6771c4 100644 --- a/tests/test_wallet_p2pk.py +++ b/tests/test_wallet_p2pk.py @@ -16,6 +16,7 @@ from cashu.wallet.wallet import Wallet as Wallet1 from cashu.wallet.wallet import Wallet as Wallet2 from tests.conftest import SERVER_ENDPOINT +from tests.helpers import pay_if_regtest async def assert_err(f, msg): @@ -60,6 +61,7 @@ async def wallet2(mint): @pytest.mark.asyncio async def test_create_p2pk_pubkey(wallet1: Wallet): invoice = await wallet1.request_mint(64) + pay_if_regtest(invoice.bolt11) await wallet1.mint(64, id=invoice.id) pubkey = await wallet1.create_p2pk_pubkey() PublicKey(bytes.fromhex(pubkey), raw=True) @@ -68,6 +70,7 @@ async def test_create_p2pk_pubkey(wallet1: Wallet): @pytest.mark.asyncio async def test_p2pk(wallet1: Wallet, wallet2: Wallet): invoice = await wallet1.request_mint(64) + pay_if_regtest(invoice.bolt11) await wallet1.mint(64, id=invoice.id) pubkey_wallet2 = await wallet2.create_p2pk_pubkey() # p2pk test @@ -81,6 +84,7 @@ async def test_p2pk(wallet1: Wallet, wallet2: Wallet): @pytest.mark.asyncio async def test_p2pk_sig_all(wallet1: Wallet, wallet2: Wallet): invoice = await wallet1.request_mint(64) + pay_if_regtest(invoice.bolt11) await wallet1.mint(64, id=invoice.id) pubkey_wallet2 = await wallet2.create_p2pk_pubkey() # p2pk test @@ -96,6 +100,7 @@ async def test_p2pk_sig_all(wallet1: Wallet, wallet2: Wallet): @pytest.mark.asyncio async def test_p2pk_receive_with_wrong_private_key(wallet1: Wallet, wallet2: Wallet): invoice = await wallet1.request_mint(64) + pay_if_regtest(invoice.bolt11) await wallet1.mint(64, id=invoice.id) pubkey_wallet2 = await wallet2.create_p2pk_pubkey() # receiver side # sender side @@ -116,6 +121,7 @@ async def test_p2pk_short_locktime_receive_with_wrong_private_key( wallet1: Wallet, wallet2: Wallet ): invoice = await wallet1.request_mint(64) + pay_if_regtest(invoice.bolt11) await wallet1.mint(64, id=invoice.id) pubkey_wallet2 = await wallet2.create_p2pk_pubkey() # receiver side # sender side @@ -141,6 +147,7 @@ async def test_p2pk_short_locktime_receive_with_wrong_private_key( @pytest.mark.asyncio async def test_p2pk_locktime_with_refund_pubkey(wallet1: Wallet, wallet2: Wallet): invoice = await wallet1.request_mint(64) + pay_if_regtest(invoice.bolt11) await wallet1.mint(64, id=invoice.id) pubkey_wallet2 = await wallet2.create_p2pk_pubkey() # receiver side # sender side @@ -169,6 +176,7 @@ async def test_p2pk_locktime_with_refund_pubkey(wallet1: Wallet, wallet2: Wallet @pytest.mark.asyncio async def test_p2pk_locktime_with_wrong_refund_pubkey(wallet1: Wallet, wallet2: Wallet): invoice = await wallet1.request_mint(64) + pay_if_regtest(invoice.bolt11) await wallet1.mint(64, id=invoice.id) await wallet2.create_p2pk_pubkey() # receiver side # sender side @@ -204,6 +212,7 @@ async def test_p2pk_locktime_with_second_refund_pubkey( wallet1: Wallet, wallet2: Wallet ): invoice = await wallet1.request_mint(64) + pay_if_regtest(invoice.bolt11) await wallet1.mint(64, id=invoice.id) pubkey_wallet1 = await wallet1.create_p2pk_pubkey() # receiver side pubkey_wallet2 = await wallet2.create_p2pk_pubkey() # receiver side @@ -235,6 +244,7 @@ async def test_p2pk_locktime_with_second_refund_pubkey( @pytest.mark.asyncio async def test_p2pk_multisig_2_of_2(wallet1: Wallet, wallet2: Wallet): invoice = await wallet1.request_mint(64) + pay_if_regtest(invoice.bolt11) await wallet1.mint(64, id=invoice.id) pubkey_wallet1 = await wallet1.create_p2pk_pubkey() pubkey_wallet2 = await wallet2.create_p2pk_pubkey() @@ -256,6 +266,7 @@ async def test_p2pk_multisig_2_of_2(wallet1: Wallet, wallet2: Wallet): @pytest.mark.asyncio async def test_p2pk_multisig_duplicate_signature(wallet1: Wallet, wallet2: Wallet): invoice = await wallet1.request_mint(64) + pay_if_regtest(invoice.bolt11) await wallet1.mint(64, id=invoice.id) pubkey_wallet1 = await wallet1.create_p2pk_pubkey() pubkey_wallet2 = await wallet2.create_p2pk_pubkey() @@ -279,6 +290,7 @@ async def test_p2pk_multisig_duplicate_signature(wallet1: Wallet, wallet2: Walle @pytest.mark.asyncio async def test_p2pk_multisig_quorum_not_met_1_of_2(wallet1: Wallet, wallet2: Wallet): invoice = await wallet1.request_mint(64) + pay_if_regtest(invoice.bolt11) await wallet1.mint(64, id=invoice.id) pubkey_wallet1 = await wallet1.create_p2pk_pubkey() pubkey_wallet2 = await wallet2.create_p2pk_pubkey() @@ -299,6 +311,7 @@ async def test_p2pk_multisig_quorum_not_met_1_of_2(wallet1: Wallet, wallet2: Wal @pytest.mark.asyncio async def test_p2pk_multisig_quorum_not_met_2_of_3(wallet1: Wallet, wallet2: Wallet): invoice = await wallet1.request_mint(64) + pay_if_regtest(invoice.bolt11) await wallet1.mint(64, id=invoice.id) pubkey_wallet1 = await wallet1.create_p2pk_pubkey() pubkey_wallet2 = await wallet2.create_p2pk_pubkey() @@ -323,6 +336,7 @@ async def test_p2pk_multisig_quorum_not_met_2_of_3(wallet1: Wallet, wallet2: Wal @pytest.mark.asyncio async def test_p2pk_multisig_with_duplicate_publickey(wallet1: Wallet, wallet2: Wallet): invoice = await wallet1.request_mint(64) + pay_if_regtest(invoice.bolt11) await wallet1.mint(64, id=invoice.id) pubkey_wallet2 = await wallet2.create_p2pk_pubkey() # p2pk test @@ -340,6 +354,7 @@ async def test_p2pk_multisig_with_wrong_first_private_key( wallet1: Wallet, wallet2: Wallet ): invoice = await wallet1.request_mint(64) + pay_if_regtest(invoice.bolt11) await wallet1.mint(64, id=invoice.id) await wallet1.create_p2pk_pubkey() pubkey_wallet2 = await wallet2.create_p2pk_pubkey() diff --git a/tests/test_wallet_restore.py b/tests/test_wallet_restore.py index ebb439ba..1e9b213a 100644 --- a/tests/test_wallet_restore.py +++ b/tests/test_wallet_restore.py @@ -12,6 +12,7 @@ from cashu.wallet.wallet import Wallet as Wallet1 from cashu.wallet.wallet import Wallet as Wallet2 from tests.conftest import SERVER_ENDPOINT +from tests.helpers import pay_if_regtest async def assert_err(f, msg: Union[str, CashuError]): @@ -147,6 +148,7 @@ async def test_generate_secrets_from_to(wallet3: Wallet): async def test_restore_wallet_after_mint(wallet3: Wallet): await reset_wallet_db(wallet3) invoice = await wallet3.request_mint(64) + pay_if_regtest(invoice.bolt11) await wallet3.mint(64, id=invoice.id) assert wallet3.balance == 64 await reset_wallet_db(wallet3) @@ -177,6 +179,7 @@ async def test_restore_wallet_after_split_to_send(wallet3: Wallet): await reset_wallet_db(wallet3) invoice = await wallet3.request_mint(64) + pay_if_regtest(invoice.bolt11) await wallet3.mint(64, id=invoice.id) assert wallet3.balance == 64 @@ -199,6 +202,7 @@ async def test_restore_wallet_after_send_and_receive(wallet3: Wallet, wallet2: W ) await reset_wallet_db(wallet3) invoice = await wallet3.request_mint(64) + pay_if_regtest(invoice.bolt11) await wallet3.mint(64, id=invoice.id) assert wallet3.balance == 64 @@ -239,6 +243,7 @@ async def test_restore_wallet_after_send_and_self_receive(wallet3: Wallet): await reset_wallet_db(wallet3) invoice = await wallet3.request_mint(64) + pay_if_regtest(invoice.bolt11) await wallet3.mint(64, id=invoice.id) assert wallet3.balance == 64 @@ -265,6 +270,7 @@ async def test_restore_wallet_after_send_twice( await reset_wallet_db(wallet3) invoice = await wallet3.request_mint(2) + pay_if_regtest(invoice.bolt11) await wallet3.mint(2, id=invoice.id) box.add(wallet3.proofs) assert wallet3.balance == 2 @@ -319,6 +325,7 @@ async def test_restore_wallet_after_send_and_self_receive_nonquadratic_value( await reset_wallet_db(wallet3) invoice = await wallet3.request_mint(64) + pay_if_regtest(invoice.bolt11) await wallet3.mint(64, id=invoice.id) box.add(wallet3.proofs) assert wallet3.balance == 64