mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-02 14:37:42 -03:00
test: add unit test for keys_to_multisig_script
This commit is contained in:
parent
0c41fc3fa5
commit
0570d2c204
2 changed files with 21 additions and 0 deletions
|
@ -27,6 +27,7 @@ TEST_FRAMEWORK_MODULES = [
|
||||||
"crypto.ripemd160",
|
"crypto.ripemd160",
|
||||||
"crypto.secp256k1",
|
"crypto.secp256k1",
|
||||||
"script",
|
"script",
|
||||||
|
"script_util",
|
||||||
"segwit_addr",
|
"segwit_addr",
|
||||||
"wallet_util",
|
"wallet_util",
|
||||||
]
|
]
|
||||||
|
|
|
@ -3,9 +3,13 @@
|
||||||
# Distributed under the MIT software license, see the accompanying
|
# Distributed under the MIT software license, see the accompanying
|
||||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
"""Useful Script constants and utils."""
|
"""Useful Script constants and utils."""
|
||||||
|
import unittest
|
||||||
|
|
||||||
from test_framework.script import (
|
from test_framework.script import (
|
||||||
CScript,
|
CScript,
|
||||||
OP_0,
|
OP_0,
|
||||||
|
OP_15,
|
||||||
|
OP_16,
|
||||||
OP_CHECKMULTISIG,
|
OP_CHECKMULTISIG,
|
||||||
OP_CHECKSIG,
|
OP_CHECKSIG,
|
||||||
OP_DUP,
|
OP_DUP,
|
||||||
|
@ -122,3 +126,19 @@ def check_script(script):
|
||||||
if isinstance(script, bytes) or isinstance(script, CScript):
|
if isinstance(script, bytes) or isinstance(script, CScript):
|
||||||
return script
|
return script
|
||||||
assert False
|
assert False
|
||||||
|
|
||||||
|
|
||||||
|
class TestFrameworkScriptUtil(unittest.TestCase):
|
||||||
|
def test_multisig(self):
|
||||||
|
fake_pubkey = bytes([0]*33)
|
||||||
|
# check correct encoding of P2MS script with n,k <= 16
|
||||||
|
normal_ms_script = keys_to_multisig_script([fake_pubkey]*16, k=15)
|
||||||
|
self.assertEqual(len(normal_ms_script), 1 + 16*34 + 1 + 1)
|
||||||
|
self.assertTrue(normal_ms_script.startswith(bytes([OP_15])))
|
||||||
|
self.assertTrue(normal_ms_script.endswith(bytes([OP_16, OP_CHECKMULTISIG])))
|
||||||
|
|
||||||
|
# check correct encoding of P2MS script with n,k > 16
|
||||||
|
max_ms_script = keys_to_multisig_script([fake_pubkey]*20, k=19)
|
||||||
|
self.assertEqual(len(max_ms_script), 2 + 20*34 + 2 + 1)
|
||||||
|
self.assertTrue(max_ms_script.startswith(bytes([1, 19]))) # using OP_PUSH1
|
||||||
|
self.assertTrue(max_ms_script.endswith(bytes([1, 20, OP_CHECKMULTISIG])))
|
||||||
|
|
Loading…
Add table
Reference in a new issue