-
-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* mint operations * fix spelling * add pending test * fix tag * make htlc tests less likelyto fail
- Loading branch information
Showing
6 changed files
with
90 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import pytest | ||
import pytest_asyncio | ||
|
||
from cashu.mint.ledger import Ledger | ||
from cashu.wallet.wallet import Wallet | ||
from cashu.wallet.wallet import Wallet as Wallet1 | ||
from tests.conftest import SERVER_ENDPOINT | ||
|
||
|
||
@pytest_asyncio.fixture(scope="function") | ||
async def wallet1(mint): | ||
wallet1 = await Wallet1.with_db( | ||
url=SERVER_ENDPOINT, | ||
db="test_data/wallet1", | ||
name="wallet1", | ||
) | ||
await wallet1.load_mint() | ||
wallet1.status() | ||
yield wallet1 | ||
|
||
|
||
@pytest.mark.asyncio | ||
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) | ||
await wallet1.mint(64, hash=invoice.hash) | ||
invoice = await wallet1.request_mint(64) | ||
await wallet1.mint(64, hash=invoice.hash) | ||
assert wallet1.balance == 128 | ||
total_amount, fee_reserve_sat = await wallet1.get_pay_amount_with_fees(invoice.pr) | ||
mint_fees = await ledger.get_melt_fees(invoice.pr) | ||
assert mint_fees == fee_reserve_sat | ||
|
||
keep_proofs, send_proofs = await wallet1.split_to_send(wallet1.proofs, total_amount) | ||
|
||
await ledger.melt(send_proofs, invoice.pr, outputs=None) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_split(wallet1: Wallet, ledger: Ledger): | ||
invoice = await wallet1.request_mint(64) | ||
await wallet1.mint(64, hash=invoice.hash) | ||
|
||
keep_proofs, send_proofs = await wallet1.split_to_send(wallet1.proofs, 10) | ||
secrets, rs, derivation_paths = await wallet1.generate_n_secrets(len(send_proofs)) | ||
outputs, rs = wallet1._construct_outputs( | ||
[p.amount for p in send_proofs], secrets, rs | ||
) | ||
|
||
promises = await ledger.split(proofs=send_proofs, outputs=outputs) | ||
assert len(promises) == len(outputs) | ||
assert [p.amount for p in promises] == [p.amount for p in outputs] | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_check_proof_state(wallet1: Wallet, ledger: Ledger): | ||
invoice = await wallet1.request_mint(64) | ||
await wallet1.mint(64, hash=invoice.hash) | ||
|
||
keep_proofs, send_proofs = await wallet1.split_to_send(wallet1.proofs, 10) | ||
|
||
spendable, pending = await ledger.check_proof_state(proofs=send_proofs) | ||
assert sum(spendable) == len(send_proofs) | ||
assert sum(pending) == 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters