Skip to content

Commit 470b7ba

Browse files
committed
Add test update_spend_taproot
1 parent 1310896 commit 470b7ba

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

tests/test_rpc.py

+76
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
PSBT,
99
PSBT_IN_PARTIAL_SIG,
1010
PSBT_IN_NON_WITNESS_UTXO,
11+
PSBT_IN_TAP_SCRIPT_SIG,
12+
PSBT_IN_TAP_KEY_SIG
1113
)
1214
from test_framework.utils import (
1315
wait_for,
@@ -575,6 +577,80 @@ def test_update_spend(lianad, bitcoind):
575577
assert psbt_merged.i[0].map[PSBT_IN_PARTIAL_SIG][dummy_pk_a] == dummy_sig_a
576578
assert psbt_merged.i[0].map[PSBT_IN_PARTIAL_SIG][dummy_pk_b] == dummy_sig_b
577579

580+
def test_update_spend_taproot(lianad, bitcoind):
581+
# Start by creating a Spend PSBT
582+
addr = lianad.rpc.getnewaddress()["address"]
583+
bitcoind.rpc.sendtoaddress(addr, 0.2567)
584+
wait_for(lambda: len(lianad.rpc.listcoins()["coins"]) > 0)
585+
outpoints = [c["outpoint"] for c in lianad.rpc.listcoins()["coins"]]
586+
destinations = {
587+
bitcoind.rpc.getnewaddress(): 200_000,
588+
}
589+
res = lianad.rpc.createspend(destinations, outpoints, 6)
590+
assert "psbt" in res
591+
592+
# Now update it
593+
assert len(lianad.rpc.listspendtxs()["spend_txs"]) == 0
594+
lianad.rpc.updatespend(res["psbt"])
595+
list_res = lianad.rpc.listspendtxs()["spend_txs"]
596+
assert len(list_res) == 1
597+
assert list_res[0]["psbt"] == res["psbt"]
598+
599+
# We can add a signature and update it
600+
psbt_sig_a = PSBT.from_base64(res["psbt"])
601+
dummy_pk_a = bytes.fromhex(
602+
"0375e00eb72e29da82b89367947f29ef34afb75e8654f6ea368e0acdfd92976b7c"
603+
)
604+
dummy_sig_a = bytes.fromhex(
605+
"304402202b925395cfeaa0171a7a92982bb4891acc4a312cbe7691d8375d36796d5b570a0220378a8ab42832848e15d1aedded5fb360fedbdd6c39226144e527f0f1e19d539801"
606+
)
607+
dummy_tapleaf_hash_a = bytes.fromhex(
608+
"2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824"
609+
)
610+
psbt_sig_a.i[0].map[PSBT_IN_TAP_SCRIPT_SIG] = {dummy_pk_a + dummy_tapleaf_hash_a: dummy_sig_a}
611+
psbt_sig_a_ser = psbt_sig_a.to_base64()
612+
lianad.rpc.updatespend(psbt_sig_a_ser)
613+
614+
# We'll get it when querying
615+
list_res = lianad.rpc.listspendtxs()["spend_txs"]
616+
assert len(list_res) == 1
617+
assert list_res[0]["psbt"] == psbt_sig_a_ser
618+
619+
# We can add another signature to the empty PSBT and update it again
620+
psbt_sig_b = PSBT.from_base64(res["psbt"])
621+
dummy_pk_b = bytes.fromhex(
622+
"03a1b26313f430c4b15bb1fdce663207659d8cac749a0e53d70eff01874496feff"
623+
)
624+
dummy_sig_b = bytes.fromhex(
625+
"3044022005aebcd649fb8965f0591710fb3704931c3e8118ee60dd44917479f63ceba6d4022018b212900e5a80e9452366894de37f0d02fb9c89f1e94f34fb6ed7fd71c15c4101"
626+
)
627+
dummy_tapleaf_hash_b = bytes.fromhex(
628+
"167112362adb3b2041c11f7337437872f9d821e57e8c3edd68d87a1d0babd0f5"
629+
)
630+
psbt_sig_b.i[0].map[PSBT_IN_TAP_SCRIPT_SIG] = {dummy_pk_b + dummy_tapleaf_hash_b: dummy_sig_b}
631+
psbt_sig_b_ser = psbt_sig_b.to_base64()
632+
lianad.rpc.updatespend(psbt_sig_b_ser)
633+
634+
# It will have merged both.
635+
list_res = lianad.rpc.listspendtxs()["spend_txs"]
636+
assert len(list_res) == 1
637+
psbt_merged = PSBT.from_base64(list_res[0]["psbt"])
638+
assert len(psbt_merged.i[0].map[PSBT_IN_TAP_SCRIPT_SIG]) == 2
639+
assert psbt_merged.i[0].map[PSBT_IN_TAP_SCRIPT_SIG][dummy_pk_a + dummy_tapleaf_hash_a] == dummy_sig_a
640+
assert psbt_merged.i[0].map[PSBT_IN_TAP_SCRIPT_SIG][dummy_pk_b + dummy_tapleaf_hash_b] == dummy_sig_b
641+
642+
# Test if the TAP_KEY_SIG is also stored.
643+
dummy_sig_c = bytes.fromhex(
644+
"304402202b925395cfeaa0171a7a92982bb4891acc4a312cbe7691d8375d36796d5b570a0220378a8ab42832848e15d1aedded5fb360fedbdd6c39226144e527f0f1e19d539801"
645+
)
646+
psbt_merged.i[0].map[PSBT_IN_TAP_KEY_SIG] = dummy_sig_c
647+
psbt_key_signed = psbt_merged.to_base64()
648+
lianad.rpc.updatespend(psbt_key_signed)
649+
650+
list_res = lianad.rpc.listspendtxs()["spend_txs"]
651+
assert len(list_res) == 1
652+
assert list_res[0]["psbt"] == psbt_key_signed
653+
578654

579655
def test_broadcast_spend(lianad, bitcoind):
580656
# Create a new coin and a spending tx for it.

0 commit comments

Comments
 (0)