mirror of
https://github.com/aljazceru/nutshell.git
synced 2025-12-20 18:44:20 +01:00
Test/mint_add_verification_balance (#373)
* add verification balance * verify input and outputs amounts before flow * adjust tests
This commit is contained in:
@@ -8,6 +8,17 @@ from tests.conftest import SERVER_ENDPOINT
|
||||
from tests.helpers import pay_if_regtest
|
||||
|
||||
|
||||
async def assert_err(f, msg):
|
||||
"""Compute f() and expect an error message 'msg'."""
|
||||
try:
|
||||
await f
|
||||
except Exception as exc:
|
||||
if msg not in str(exc.args[0]):
|
||||
raise Exception(f"Expected error: {msg}, got: {exc.args[0]}")
|
||||
return
|
||||
raise Exception(f"Expected error: {msg}, got no error")
|
||||
|
||||
|
||||
@pytest_asyncio.fixture(scope="function")
|
||||
async def wallet1(mint):
|
||||
wallet1 = await Wallet1.with_db(
|
||||
@@ -58,6 +69,60 @@ async def test_split(wallet1: Wallet, ledger: Ledger):
|
||||
assert [p.amount for p in promises] == [p.amount for p in outputs]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_split_with_input_less_than_outputs(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, set_reserved=False
|
||||
)
|
||||
|
||||
all_send_proofs = send_proofs + keep_proofs
|
||||
|
||||
# generate outputs for all proofs, not only the sent ones
|
||||
secrets, rs, derivation_paths = await wallet1.generate_n_secrets(
|
||||
len(all_send_proofs)
|
||||
)
|
||||
outputs, rs = wallet1._construct_outputs(
|
||||
[p.amount for p in all_send_proofs], secrets, rs
|
||||
)
|
||||
|
||||
await assert_err(
|
||||
ledger.split(proofs=send_proofs, outputs=outputs),
|
||||
"inputs do not have same amount as outputs.",
|
||||
)
|
||||
|
||||
# make sure we can still spend our tokens
|
||||
keep_proofs, send_proofs = await wallet1.split(wallet1.proofs, 10)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_split_with_input_more_than_outputs(wallet1: Wallet, ledger: Ledger):
|
||||
invoice = await wallet1.request_mint(128)
|
||||
pay_if_regtest(invoice.bolt11)
|
||||
await wallet1.mint(128, id=invoice.id)
|
||||
|
||||
inputs = wallet1.proofs
|
||||
|
||||
# less outputs than inputs
|
||||
output_amounts = [8]
|
||||
secrets, rs, derivation_paths = await wallet1.generate_n_secrets(
|
||||
len(output_amounts)
|
||||
)
|
||||
outputs, rs = wallet1._construct_outputs(output_amounts, secrets, rs)
|
||||
|
||||
await assert_err(
|
||||
ledger.split(proofs=inputs, outputs=outputs),
|
||||
"inputs do not have same amount as outputs",
|
||||
)
|
||||
|
||||
# make sure we can still spend our tokens
|
||||
keep_proofs, send_proofs = await wallet1.split(inputs, 10)
|
||||
print(keep_proofs, send_proofs)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_check_proof_state(wallet1: Wallet, ledger: Ledger):
|
||||
invoice = await wallet1.request_mint(64)
|
||||
|
||||
Reference in New Issue
Block a user