mirror of
https://github.com/aljazceru/nutshell.git
synced 2026-01-04 01:14:21 +01:00
determinstic secrets for multiple tokens
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import time
|
||||
from re import S
|
||||
from cashu.core.helpers import async_unwrap
|
||||
from cashu.core.migrations import migrate_databases
|
||||
from cashu.wallet import migrations
|
||||
@@ -108,11 +110,12 @@ async def run_test():
|
||||
assert wallet2.proof_amounts() == [4, 16]
|
||||
|
||||
# manipulate the proof amount
|
||||
w1_fst_proofs2[0]["amount"] = 123
|
||||
await assert_err(
|
||||
wallet1.split(w1_fst_proofs2, 20),
|
||||
"Error: 123",
|
||||
)
|
||||
# w1_fst_proofs2_manipulated = w1_fst_proofs2.copy()
|
||||
# w1_fst_proofs2_manipulated[0]["amount"] = 123
|
||||
# await assert_err(
|
||||
# wallet1.split(w1_fst_proofs2_manipulated, 20),
|
||||
# "Error: 123",
|
||||
# )
|
||||
|
||||
# try to split an invalid amount
|
||||
await assert_err(
|
||||
@@ -120,6 +123,37 @@ async def run_test():
|
||||
"Error: invalid split amount: -500",
|
||||
)
|
||||
|
||||
# mint with secrets
|
||||
secret = f"asdasd_{time.time()}"
|
||||
w1_fst_proofs, w1_snd_proofs = await wallet1.split(
|
||||
wallet1.proofs, 65, snd_secret=secret
|
||||
)
|
||||
|
||||
# strip away the secrets
|
||||
w1_snd_proofs_manipulated = w1_snd_proofs.copy()
|
||||
for p in w1_snd_proofs_manipulated:
|
||||
p.secret = ""
|
||||
await assert_err(
|
||||
wallet2.redeem(w1_snd_proofs_manipulated),
|
||||
"Error: duplicate proofs or promises.",
|
||||
)
|
||||
|
||||
# redeem with wrong secret
|
||||
await assert_err(
|
||||
wallet2.redeem(w1_snd_proofs_manipulated, f"{secret}_asd"),
|
||||
"Error: could not verify proofs.",
|
||||
)
|
||||
|
||||
# redeem with correct secret
|
||||
await wallet2.redeem(w1_snd_proofs_manipulated, secret)
|
||||
|
||||
# try to redeem them again
|
||||
# NOTE: token indexing suffix _0
|
||||
await assert_err(
|
||||
wallet2.redeem(w1_snd_proofs_manipulated, secret),
|
||||
f"Error: tokens already spent. Secret: {secret}_0",
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
async_unwrap(run_test())
|
||||
|
||||
Reference in New Issue
Block a user