Skip to content

Commit

Permalink
test: Add E2E test for sp descriptor
Browse files Browse the repository at this point in the history
  • Loading branch information
Eunovo committed Jul 22, 2024
1 parent 6d97c18 commit adcfa5d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/wallet/rpc/backup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1483,7 +1483,7 @@ static UniValue ProcessDescriptorImport(CWallet& wallet, const UniValue& data, c
}

// Active descriptors must be ranged
if (active && !parsed_desc->IsRange()) {
if (active && !parsed_desc->IsRange() && parsed_desc->GetOutputType() != OutputType::SILENT_PAYMENT) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Active descriptors must be ranged");
}

Expand Down
65 changes: 41 additions & 24 deletions test/functional/wallet_miniscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
f"tr(4d54bb9928a0683b7e383de72943b214b0716f58aa54c7ba6bcea2328bc9c768,{{{{{P2WSH_MINISCRIPTS[0]},{P2WSH_MINISCRIPTS[1]}}},{P2WSH_MINISCRIPTS[2].replace('multi', 'multi_a')}}})",
# A Taproot with all above scripts in its tree.
f"tr(4d54bb9928a0683b7e383de72943b214b0716f58aa54c7ba6bcea2328bc9c768,{{{{{P2WSH_MINISCRIPTS[0]},{P2WSH_MINISCRIPTS[1]}}},{{{P2WSH_MINISCRIPTS[2].replace('multi', 'multi_a')},{P2WSH_MINISCRIPTS[3]}}}}})",
f"sp({TPRVS[0]},{TPUBS[0]})",
]

DESCS_PRIV = [
Expand Down Expand Up @@ -217,36 +218,48 @@ def skip_test_if_missing_module(self):
def watchonly_test(self, desc):
self.log.info(f"Importing descriptor '{desc}'")
desc = descsum_create(f"{desc}")
assert self.ms_wo_wallet.importdescriptors(
[
{
"desc": desc,
"active": True,
"range": 2,
"next_index": 0,
"timestamp": "now",
}
]
)[0]["success"]
range = None if desc.startswith("sp(") else 2
wallet = self.ms_sp_wallet if desc.startswith("sp(") else self.ms_wo_wallet

import_desc_data = {
"desc": desc,
"active": True,
"next_index": 0,
"timestamp": "now",
}
if range is not None:
import_desc_data["range"] = range
assert wallet.importdescriptors([import_desc_data])[0]["success"]

self.log.info("Testing we derive new addresses for it")
addr_type = "bech32m" if desc.startswith("tr(") else "bech32"
assert_equal(
self.ms_wo_wallet.getnewaddress(address_type=addr_type),
self.funder.deriveaddresses(desc, 0)[0],
)
assert_equal(
self.ms_wo_wallet.getnewaddress(address_type=addr_type),
self.funder.deriveaddresses(desc, 1)[1],
)
addr_type = "bech32"
if desc.startswith("tr("):
addr_type = "bech32m"
elif desc.startswith("sp("):
addr_type = "silent-payment"

if range is not None:
assert_equal(
wallet.getnewaddress(address_type=addr_type),
self.funder.deriveaddresses(desc, 0)[0],
)
assert_equal(
wallet.getnewaddress(address_type=addr_type),
self.funder.deriveaddresses(desc, 1)[1],
)
else:
assert_equal(
wallet.getnewaddress(address_type=addr_type),
self.funder.deriveaddresses(desc)[0],
)

self.log.info("Testing we detect funds sent to one of them")
addr = self.ms_wo_wallet.getnewaddress()
addr = wallet.getnewaddress()
txid = self.funder.sendtoaddress(addr, 0.01)
self.wait_until(
lambda: len(self.ms_wo_wallet.listunspent(minconf=0, addresses=[addr])) == 1
lambda: len(wallet.listunspent(minconf=0, addresses=[addr])) == 1
)
utxo = self.ms_wo_wallet.listunspent(minconf=0, addresses=[addr])[0]
utxo = wallet.listunspent(minconf=0, addresses=[addr])[0]
assert utxo["txid"] == txid and utxo["solvable"]

def signing_test(
Expand Down Expand Up @@ -329,7 +342,11 @@ def run_test(self):
wallet_name="ms_wo", descriptors=True, disable_private_keys=True
)
self.ms_wo_wallet = self.nodes[0].get_wallet_rpc("ms_wo")
self.nodes[0].createwallet(wallet_name="ms_sig", descriptors=True)
self.nodes[0].createwallet(
wallet_name="ms_sp_wallet", descriptors=True, silent_payment=True
)
self.ms_sp_wallet = self.nodes[0].get_wallet_rpc("ms_sp_wallet")
self.nodes[0].createwallet(wallet_name="ms_sig", descriptors=True, silent_payment=True)
self.ms_sig_wallet = self.nodes[0].get_wallet_rpc("ms_sig")

# Sanity check we wouldn't let an insane Miniscript descriptor in
Expand Down

0 comments on commit adcfa5d

Please sign in to comment.