Mint: store Y in db (#412)

* storage y db

* for proofs_pending as well

* pending check with Y

* fix pending table

* test_race_pending

* skip race condition test on github

* skip test on github actions

* move test_cli.py -> test_wallet_cli.py

* get full proof from memory

* add domain separation wallet
This commit is contained in:
callebtc
2024-02-10 22:52:55 +01:00
committed by GitHub
parent 1de7abf032
commit 6db4604f99
12 changed files with 264 additions and 48 deletions

View File

@@ -1,4 +1,5 @@
import asyncio
import importlib
import multiprocessing
import os
import shutil
@@ -45,7 +46,7 @@ assert "test" in settings.cashu_dir
shutil.rmtree(settings.cashu_dir, ignore_errors=True)
Path(settings.cashu_dir).mkdir(parents=True, exist_ok=True)
from cashu.mint.startup import lightning_backend # noqa
# from cashu.mint.startup import lightning_backend # noqa
@pytest.fixture(scope="session")
@@ -99,7 +100,8 @@ async def ledger():
db_file = os.path.join(settings.mint_database, "mint.sqlite3")
if os.path.exists(db_file):
os.remove(db_file)
wallets_module = importlib.import_module("cashu.lightning")
lightning_backend = getattr(wallets_module, settings.mint_lightning_backend)()
backends = {
Method.bolt11: {Unit.sat: lightning_backend},
}

View File

@@ -30,6 +30,7 @@ WALLET = wallet_class()
is_fake: bool = WALLET.__class__.__name__ == "FakeWallet"
is_regtest: bool = not is_fake
is_deprecated_api_only = settings.debug_mint_only_deprecated
is_github_actions = os.getenv("GITHUB_ACTIONS") == "true"
docker_lightning_cli = [
"docker",

View File

@@ -13,7 +13,13 @@ from cashu.wallet.wallet import Wallet
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 get_real_invoice, is_fake, is_regtest, pay_if_regtest
from tests.helpers import (
get_real_invoice,
is_fake,
is_github_actions,
is_regtest,
pay_if_regtest,
)
async def assert_err(f, msg: Union[str, CashuError]):
@@ -349,12 +355,30 @@ async def test_duplicate_proofs_double_spent(wallet1: Wallet):
doublespend = await wallet1.mint(64, id=invoice.id)
await assert_err(
wallet1.split(wallet1.proofs + doublespend, 20),
"Mint Error: proofs already pending.",
"Mint Error: Failed to set proofs pending.",
)
assert wallet1.balance == 64
assert wallet1.available_balance == 64
@pytest.mark.asyncio
@pytest.mark.skipif(is_github_actions, reason="GITHUB_ACTIONS")
async def test_split_race_condition(wallet1: Wallet):
invoice = await wallet1.request_mint(64)
pay_if_regtest(invoice.bolt11)
await wallet1.mint(64, id=invoice.id)
# run two splits in parallel
import asyncio
await assert_err(
asyncio.gather(
wallet1.split(wallet1.proofs, 20),
wallet1.split(wallet1.proofs, 20),
),
"proofs are pending.",
)
@pytest.mark.asyncio
async def test_send_and_redeem(wallet1: Wallet, wallet2: Wallet):
invoice = await wallet1.request_mint(64)