mirror of
https://github.com/aljazceru/nutshell.git
synced 2025-12-21 19:14:19 +01:00
tests failing? (#369)
This commit is contained in:
@@ -56,6 +56,7 @@ class MintSettings(CashuSettings):
|
||||
mint_peg_out_only: bool = Field(default=False)
|
||||
mint_max_peg_in: int = Field(default=None)
|
||||
mint_max_peg_out: int = Field(default=None)
|
||||
mint_max_balance: int = Field(default=None)
|
||||
|
||||
mint_lnbits_endpoint: str = Field(default=None)
|
||||
mint_lnbits_key: str = Field(default=None)
|
||||
|
||||
@@ -158,6 +158,16 @@ class LedgerCrud:
|
||||
conn=conn,
|
||||
)
|
||||
|
||||
async def get_balance(
|
||||
self,
|
||||
db: Database,
|
||||
conn: Optional[Connection] = None,
|
||||
) -> int:
|
||||
return await get_balance(
|
||||
db=db,
|
||||
conn=conn,
|
||||
)
|
||||
|
||||
|
||||
async def store_promise(
|
||||
*,
|
||||
@@ -394,3 +404,14 @@ async def get_keyset(
|
||||
tuple(values),
|
||||
)
|
||||
return [MintKeyset(**row) for row in rows]
|
||||
|
||||
|
||||
async def get_balance(
|
||||
db: Database,
|
||||
conn: Optional[Connection] = None,
|
||||
) -> int:
|
||||
row = await (conn or db).fetchone(f"""
|
||||
SELECT * from {table_with_schema(db, 'balance')}
|
||||
""")
|
||||
assert row, "Balance not found"
|
||||
return int(row[0])
|
||||
|
||||
@@ -146,6 +146,10 @@ class Ledger(LedgerVerification, LedgerSpendingConditions, LedgerLightning):
|
||||
assert keyset.public_keys, KeysetError("no public keys for this keyset")
|
||||
return {a: p.serialize().hex() for a, p in keyset.public_keys.items()}
|
||||
|
||||
async def get_balance(self) -> int:
|
||||
"""Returns the balance of the mint."""
|
||||
return await self.crud.get_balance(db=self.db)
|
||||
|
||||
# ------- ECASH -------
|
||||
|
||||
async def _invalidate_proofs(self, proofs: List[Proof]) -> None:
|
||||
@@ -245,6 +249,10 @@ class Ledger(LedgerVerification, LedgerSpendingConditions, LedgerLightning):
|
||||
)
|
||||
if settings.mint_peg_out_only:
|
||||
raise NotAllowedError("Mint does not allow minting new tokens.")
|
||||
if settings.mint_max_balance:
|
||||
balance = await self.get_balance()
|
||||
if balance + amount > settings.mint_max_balance:
|
||||
raise NotAllowedError("Mint has reached maximum balance.")
|
||||
|
||||
logger.trace(f"requesting invoice for {amount} satoshis")
|
||||
invoice_response = await self._request_lightning_invoice(amount)
|
||||
|
||||
@@ -32,6 +32,7 @@ settings.mint_lightning_backend = settings.mint_lightning_backend or "FakeWallet
|
||||
settings.mint_database = "./test_data/test_mint"
|
||||
settings.mint_derivation_path = "0/0/0/0"
|
||||
settings.mint_private_key = "TEST_PRIVATE_KEY"
|
||||
settings.mint_max_balance = 0
|
||||
|
||||
shutil.rmtree(settings.cashu_dir, ignore_errors=True)
|
||||
Path(settings.cashu_dir).mkdir(parents=True, exist_ok=True)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import asyncio
|
||||
from typing import Tuple
|
||||
|
||||
import pytest
|
||||
from click.testing import CliRunner
|
||||
@@ -15,7 +16,7 @@ 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):
|
||||
def get_bolt11_and_invoice_id_from_invoice_command(output: str) -> Tuple[str, str]:
|
||||
invoice = [
|
||||
line.split(" ")[1] for line in output.split("\n") if line.startswith("Invoice")
|
||||
][0]
|
||||
|
||||
@@ -182,3 +182,20 @@ async def test_generate_change_promises_returns_empty_if_no_outputs(ledger: Ledg
|
||||
total_provided, invoice_amount, actual_fee_msat, outputs
|
||||
)
|
||||
assert len(promises) == 0
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_balance(ledger: Ledger):
|
||||
balance = await ledger.get_balance()
|
||||
assert balance == 0
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_maximum_balance(ledger: Ledger):
|
||||
settings.mint_max_balance = 1000
|
||||
invoice, id = await ledger.request_mint(8)
|
||||
await assert_err(
|
||||
ledger.request_mint(8000),
|
||||
"Mint has reached maximum balance.",
|
||||
)
|
||||
settings.mint_max_balance = 0
|
||||
|
||||
Reference in New Issue
Block a user