* wip

* wip

* model

* refactor wallet transactions

* refactor wallet

* sending with fees works and outputs fill up the wallet

* wip work

* ok

* comments

* receive with amount=0

* correctly import postmeltrequest

* fix melt amount

* tests working

* remove mint_loaded decorator in deprecated wallet api

* wallet works with units

* refactor: melt_quote

* fix fees

* add file

* fees for melt inputs

* set default input fee for internal quotes to 0

* fix coinselect

* coin selection working

* yo

* fix all tests

* clean up

* last commit added fees for inputs for melt transactions - this commit adds a blanace too low exception

* fix fee return and melt quote max allowed amount check during creation of melt quote

* clean up code

* add tests for fees

* add melt tests

* update wallet fee information
This commit is contained in:
callebtc
2024-06-15 16:22:41 +02:00
committed by GitHub
parent d80280e35d
commit d30b1a2777
47 changed files with 2446 additions and 1554 deletions

View File

@@ -1,8 +1,8 @@
import pytest
import pytest_asyncio
from cashu.core.base import PostMeltQuoteRequest, PostMintQuoteRequest
from cashu.core.helpers import sum_proofs
from cashu.core.models import PostMeltQuoteRequest, PostMintQuoteRequest
from cashu.mint.ledger import Ledger
from cashu.wallet.wallet import Wallet
from cashu.wallet.wallet import Wallet as Wallet1
@@ -155,6 +155,18 @@ 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_no_outputs(wallet1: Wallet, ledger: Ledger):
invoice = await wallet1.request_mint(64)
pay_if_regtest(invoice.bolt11)
await wallet1.mint(64, id=invoice.id)
_, send_proofs = await wallet1.split_to_send(wallet1.proofs, 10, set_reserved=False)
await assert_err(
ledger.split(proofs=send_proofs, outputs=[]),
"no outputs provided",
)
@pytest.mark.asyncio
async def test_split_with_input_less_than_outputs(wallet1: Wallet, ledger: Ledger):
invoice = await wallet1.request_mint(64)
@@ -165,19 +177,19 @@ async def test_split_with_input_less_than_outputs(wallet1: Wallet, ledger: Ledge
wallet1.proofs, 10, set_reserved=False
)
all_send_proofs = send_proofs + keep_proofs
too_many_proofs = send_proofs + send_proofs
# generate outputs for all proofs, not only the sent ones
# generate more outputs than inputs
secrets, rs, derivation_paths = await wallet1.generate_n_secrets(
len(all_send_proofs)
len(too_many_proofs)
)
outputs, rs = wallet1._construct_outputs(
[p.amount for p in all_send_proofs], secrets, rs
[p.amount for p in too_many_proofs], secrets, rs
)
await assert_err(
ledger.split(proofs=send_proofs, outputs=outputs),
"inputs do not have same amount as outputs.",
"are not balanced",
)
# make sure we can still spend our tokens
@@ -201,7 +213,7 @@ async def test_split_with_input_more_than_outputs(wallet1: Wallet, ledger: Ledge
await assert_err(
ledger.split(proofs=inputs, outputs=outputs),
"inputs do not have same amount as outputs",
"are not balanced",
)
# make sure we can still spend our tokens
@@ -216,6 +228,9 @@ async def test_split_twice_with_same_outputs(wallet1: Wallet, ledger: Ledger):
inputs1 = wallet1.proofs[:1]
inputs2 = wallet1.proofs[1:]
assert inputs1[0].amount == 64
assert inputs2[0].amount == 64
output_amounts = [64]
secrets, rs, derivation_paths = await wallet1.generate_n_secrets(
len(output_amounts)