From 2e1c54491e96fda79b3831dc0c079c59250fabe0 Mon Sep 17 00:00:00 2001 From: Antoine Poinsot Date: Tue, 24 Oct 2023 16:15:52 +0200 Subject: [PATCH] qa: test der paths in PSBT when desc has duplicate signer --- tests/fixtures.py | 35 +++++++++++++++++++++++++++++++++++ tests/test_rpc.py | 6 ++++++ 2 files changed, 41 insertions(+) diff --git a/tests/fixtures.py b/tests/fixtures.py index ee8d5b7c..8827abf6 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -156,6 +156,41 @@ def lianad(bitcoind, directory): lianad.cleanup() +@pytest.fixture +def lianad_same_signer(bitcoind, directory): + """A simple lianad but the same signer is used for primary and recovery.""" + datadir = os.path.join(directory, "lianad") + os.makedirs(datadir, exist_ok=True) + bitcoind_cookie = os.path.join(bitcoind.bitcoin_dir, "regtest", ".cookie") + + # We use the same xpub for both paths, but /0/<0;1>/* for the primary and /1/<0;1>/* + # for the recovery. + signer = SingleSigner() + fingerprint = xpub_fingerprint(signer.primary_hd) + xpub = signer.primary_hd.get_xpub() + csv_value = 10 + main_desc = Descriptor.from_str( + f"wsh(or_d(pk([{fingerprint}]{xpub}/0/<0;1>/*),and_v(v:pkh([{fingerprint}]{xpub}/1/<0;1>/*),older({csv_value}))))" + ) + + lianad = Lianad( + datadir, + signer, + main_desc, + bitcoind.rpcport, + bitcoind_cookie, + ) + + try: + lianad.start() + yield lianad + except Exception: + lianad.cleanup() + raise + + lianad.cleanup() + + def multi_expression(thresh, keys): exp = f"multi({thresh}," for i, key in enumerate(keys): diff --git a/tests/test_rpc.py b/tests/test_rpc.py index 3bb82c3a..4e420ca9 100644 --- a/tests/test_rpc.py +++ b/tests/test_rpc.py @@ -410,6 +410,12 @@ def test_create_spend(lianad, bitcoind): assert res_spend_keys.intersection(res_reco_keys) == set() +def test_create_spend_duplicate_signer(lianad_same_signer, bitcoind): + """Test spend creation (esp. around what bip32 derivations are added to the PSBT) but + with a Liana setup where a single signer is repeated between paths.""" + test_create_spend(lianad_same_signer, bitcoind) + + def test_list_spend(lianad, bitcoind): # Start by creating two conflicting Spend PSBTs. The first one will have a change # output but not the second one.