Skip to content

Commit

Permalink
qa: bound testing for TapMiniscript
Browse files Browse the repository at this point in the history
Make sure we can spend a maximum-sized Miniscript under Tapscript
context.
  • Loading branch information
darosior committed Sep 26, 2023
1 parent 41b4c59 commit 2d2f4df
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion test/functional/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
'feature_maxuploadtarget.py',
'mempool_updatefromblock.py',
'mempool_persist.py --descriptors',
'wallet_miniscript.py --descriptors',
# vv Tests less than 60s vv
'rpc_psbt.py --legacy-wallet',
'rpc_psbt.py --descriptors',
Expand Down Expand Up @@ -237,7 +238,6 @@
'wallet_keypool.py --legacy-wallet',
'wallet_keypool.py --descriptors',
'wallet_descriptor.py --descriptors',
'wallet_miniscript.py --descriptors',
'p2p_nobloomfilter_messages.py',
'p2p_filter.py',
'rpc_setban.py',
Expand Down
26 changes: 26 additions & 0 deletions test/functional/wallet_miniscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@
class WalletMiniscriptTest(BitcoinTestFramework):
def add_options(self, parser):
self.add_wallet_options(parser, legacy=False)
self.rpc_timeout = 480

def set_test_params(self):
self.num_nodes = 1
Expand Down Expand Up @@ -373,6 +374,31 @@ def run_test(self):
desc.get("sha256_preimages"),
)

# Test we can sign for a max-size TapMiniscript. Recompute the maximum accepted size
# for a TapMiniscript (see cpp file for details). Then pad a simple pubkey check up
# to the maximum size. Make sure we can import and spend this script.
leeway_weight = (4 + 4 + 1 + 36 + 4 + 1 + 1 + 8 + 1 + 1 + 33) * 4 + 2
max_tapmini_size = 400_000 - 2 - (1 + 65) * 1_000 - (33 + 32 * 128) - leeway_weight - 4
padding = max_tapmini_size - 33 - 1
ms = f"pk({TPRVS[0]}/*)"
ms = "n" * padding + ":" + ms
desc = f"tr({PUBKEYS[0]},{ms})"
self.signing_test(desc, None, None, 1, 3, None)
# This was really the maximum size, one more byte and we can't import it.
ms = "n" + ms
desc = f"tr({PUBKEYS[0]},{ms})"
res = self.ms_wo_wallet.importdescriptors(
[
{
"desc": descsum_create(desc),
"active": False,
"timestamp": "now",
}
]
)[0]
assert not res["success"]
assert "is not a valid descriptor function" in res["error"]["message"]


if __name__ == "__main__":
WalletMiniscriptTest().main()

0 comments on commit 2d2f4df

Please sign in to comment.