From 0c41fc3fa52ad16923afbd0ec18b9c1b3ded8036 Mon Sep 17 00:00:00 2001 From: Sebastian Falbesoner Date: Tue, 22 Aug 2023 03:06:15 +0200 Subject: [PATCH] test: fix `keys_to_multisig_script` (P2MS) helper for n/k > 16 The helper assumes that the n and k values have to be provided as a single byte push operation, which is only possible for values up to 16. Fix that by passing the numbers directly to the CScript list, where it's automatically converted to minimally-encoded pushes (see class method `CScript.__coerce_instance`, branch `isinstance(other, int)`). In case of 17..20, this means that the data-pushes are done with two bytes using OP_PUSH1 (0x01), e.g. for n=20: 0x01,0x14 --- test/functional/test_framework/script_util.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/functional/test_framework/script_util.py b/test/functional/test_framework/script_util.py index 62894cc0f4..ee8199c2da 100755 --- a/test/functional/test_framework/script_util.py +++ b/test/functional/test_framework/script_util.py @@ -5,7 +5,6 @@ """Useful Script constants and utils.""" from test_framework.script import ( CScript, - CScriptOp, OP_0, OP_CHECKMULTISIG, OP_CHECKSIG, @@ -49,10 +48,8 @@ def keys_to_multisig_script(keys, *, k=None): if k is None: # n-of-n multisig by default k = n assert k <= n - op_k = CScriptOp.encode_op_n(k) - op_n = CScriptOp.encode_op_n(n) checked_keys = [check_key(key) for key in keys] - return CScript([op_k] + checked_keys + [op_n, OP_CHECKMULTISIG]) + return CScript([k] + checked_keys + [n, OP_CHECKMULTISIG]) def keyhash_to_p2pkh_script(hash):