|
3 | 3 | # Distributed under the MIT software license, see the accompanying |
4 | 4 | # file COPYING or http://www.opensource.org/licenses/mit-license.php. |
5 | 5 | """Useful Script constants and utils.""" |
| 6 | +import unittest |
| 7 | + |
6 | 8 | from test_framework.script import ( |
7 | 9 | CScript, |
8 | 10 | OP_0, |
| 11 | + OP_15, |
| 12 | + OP_16, |
9 | 13 | OP_CHECKMULTISIG, |
10 | 14 | OP_CHECKSIG, |
11 | 15 | OP_DUP, |
@@ -122,3 +126,19 @@ def check_script(script): |
122 | 126 | if isinstance(script, bytes) or isinstance(script, CScript): |
123 | 127 | return script |
124 | 128 | 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