p2sh test

This commit is contained in:
callebtc
2022-10-03 21:19:45 +02:00
parent 570534510e
commit 78e94ecf66
3 changed files with 10 additions and 18 deletions

View File

@@ -12,6 +12,7 @@ if not os.path.isfile(ENV_FILE):
if os.path.isfile(ENV_FILE): if os.path.isfile(ENV_FILE):
env.read_env(ENV_FILE) env.read_env(ENV_FILE)
else: else:
ENV_FILE = None
env.read_env() env.read_env()
DEBUG = env.bool("DEBUG", default=False) DEBUG = env.bool("DEBUG", default=False)

View File

@@ -241,8 +241,6 @@ async def lock(ctx):
wallet: Wallet = ctx.obj["WALLET"] wallet: Wallet = ctx.obj["WALLET"]
p2shscript = await wallet.create_p2sh_lock() p2shscript = await wallet.create_p2sh_lock()
txin_p2sh_address = p2shscript.address txin_p2sh_address = p2shscript.address
txin_redeemScript_b64 = p2shscript.script
txin_signature_b64 = p2shscript.signature
print("---- Pay to script hash (P2SH) ----\n") print("---- Pay to script hash (P2SH) ----\n")
print("Use a lock to receive coins that only you can unlock.") print("Use a lock to receive coins that only you can unlock.")
print("") print("")

View File

@@ -130,6 +130,15 @@ async def run_test():
wallet1.proofs, 65, snd_secret=secret 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 # strip away the secrets
w1_snd_proofs_manipulated = w1_snd_proofs.copy() w1_snd_proofs_manipulated = w1_snd_proofs.copy()
for p in w1_snd_proofs_manipulated: for p in w1_snd_proofs_manipulated:
@@ -139,22 +148,6 @@ async def run_test():
"Mint Error: no secret in proof.", "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__": if __name__ == "__main__":
async_unwrap(run_test()) async_unwrap(run_test())