mirror of
https://github.com/aljazceru/nutshell.git
synced 2025-12-20 10:34:20 +01:00
p2sh test
This commit is contained in:
@@ -12,6 +12,7 @@ if not os.path.isfile(ENV_FILE):
|
||||
if os.path.isfile(ENV_FILE):
|
||||
env.read_env(ENV_FILE)
|
||||
else:
|
||||
ENV_FILE = None
|
||||
env.read_env()
|
||||
|
||||
DEBUG = env.bool("DEBUG", default=False)
|
||||
|
||||
@@ -241,8 +241,6 @@ async def lock(ctx):
|
||||
wallet: Wallet = ctx.obj["WALLET"]
|
||||
p2shscript = await wallet.create_p2sh_lock()
|
||||
txin_p2sh_address = p2shscript.address
|
||||
txin_redeemScript_b64 = p2shscript.script
|
||||
txin_signature_b64 = p2shscript.signature
|
||||
print("---- Pay to script hash (P2SH) ----\n")
|
||||
print("Use a lock to receive coins that only you can unlock.")
|
||||
print("")
|
||||
|
||||
@@ -130,6 +130,15 @@ async def run_test():
|
||||
wallet1.proofs, 65, snd_secret=secret
|
||||
)
|
||||
|
||||
# p2sh test
|
||||
p2shscript = await wallet2.create_p2sh_lock()
|
||||
txin_p2sh_address = p2shscript.address
|
||||
lock = f"P2SH:{txin_p2sh_address}"
|
||||
_, send_proofs = await wallet1.split_to_send(wallet1.proofs, 8, lock)
|
||||
_, _ = await wallet2.redeem(
|
||||
send_proofs, snd_script=p2shscript.script, snd_siganture=p2shscript.signature
|
||||
)
|
||||
|
||||
# strip away the secrets
|
||||
w1_snd_proofs_manipulated = w1_snd_proofs.copy()
|
||||
for p in w1_snd_proofs_manipulated:
|
||||
@@ -139,22 +148,6 @@ async def run_test():
|
||||
"Mint Error: no secret in proof.",
|
||||
)
|
||||
|
||||
# redeem with wrong secret
|
||||
await assert_err(
|
||||
wallet2.redeem(w1_snd_proofs_manipulated, f"{secret}_asd"),
|
||||
"Mint 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"Mint Error: tokens already spent. Secret: 0:{secret}",
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
async_unwrap(run_test())
|
||||
|
||||
Reference in New Issue
Block a user