Skip to content

Commit 0570d2c

Browse files
committed
test: add unit test for keys_to_multisig_script
1 parent 0c41fc3 commit 0570d2c

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

test/functional/feature_framework_unit_tests.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"crypto.ripemd160",
2828
"crypto.secp256k1",
2929
"script",
30+
"script_util",
3031
"segwit_addr",
3132
"wallet_util",
3233
]

test/functional/test_framework/script_util.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
# Distributed under the MIT software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Useful Script constants and utils."""
6+
import unittest
7+
68
from test_framework.script import (
79
CScript,
810
OP_0,
11+
OP_15,
12+
OP_16,
913
OP_CHECKMULTISIG,
1014
OP_CHECKSIG,
1115
OP_DUP,
@@ -122,3 +126,19 @@ def check_script(script):
122126
if isinstance(script, bytes) or isinstance(script, CScript):
123127
return script
124128
assert False
129+
130+
131+
class TestFrameworkScriptUtil(unittest.TestCase):
132+
def test_multisig(self):
133+
fake_pubkey = bytes([0]*33)
134+
# check correct encoding of P2MS script with n,k <= 16
135+
normal_ms_script = keys_to_multisig_script([fake_pubkey]*16, k=15)
136+
self.assertEqual(len(normal_ms_script), 1 + 16*34 + 1 + 1)
137+
self.assertTrue(normal_ms_script.startswith(bytes([OP_15])))
138+
self.assertTrue(normal_ms_script.endswith(bytes([OP_16, OP_CHECKMULTISIG])))
139+
140+
# check correct encoding of P2MS script with n,k > 16
141+
max_ms_script = keys_to_multisig_script([fake_pubkey]*20, k=19)
142+
self.assertEqual(len(max_ms_script), 2 + 20*34 + 2 + 1)
143+
self.assertTrue(max_ms_script.startswith(bytes([1, 19]))) # using OP_PUSH1
144+
self.assertTrue(max_ms_script.endswith(bytes([1, 20, OP_CHECKMULTISIG])))

0 commit comments

Comments
 (0)