Changeset View
Changeset View
Standalone View
Standalone View
test/functional/rpc_createmultisig.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2015-2019 The Bitcoin Core developers | # Copyright (c) 2015-2019 The Bitcoin Core developers | ||||
# 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. | ||||
"""Test multisig RPCs""" | """Test multisig RPCs""" | ||||
from test_framework.descriptors import descsum_create | |||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import ( | from test_framework.util import ( | ||||
assert_raises_rpc_error, | assert_raises_rpc_error, | ||||
assert_equal, | assert_equal, | ||||
) | ) | ||||
from test_framework.key import ECPubKey | from test_framework.key import ECPubKey | ||||
import binascii | import binascii | ||||
import decimal | import decimal | ||||
import itertools | import itertools | ||||
import json | |||||
import os | |||||
class RpcCreateMultiSigTest(BitcoinTestFramework): | class RpcCreateMultiSigTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.setup_clean_chain = True | self.setup_clean_chain = True | ||||
self.num_nodes = 3 | self.num_nodes = 3 | ||||
def skip_test_if_missing_module(self): | def skip_test_if_missing_module(self): | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | # Test mixed compressed and uncompressed pubkeys | ||||
assert_equal( | assert_equal( | ||||
legacy_addr, node0.addmultisigaddress( | legacy_addr, node0.addmultisigaddress( | ||||
2, keys, '')['address']) | 2, keys, '')['address']) | ||||
# Generate addresses with the segwit types. These should all make | # Generate addresses with the segwit types. These should all make | ||||
# legacy addresses | # legacy addresses | ||||
assert_equal(legacy_addr, node0.createmultisig(2, keys)['address']) | assert_equal(legacy_addr, node0.createmultisig(2, keys)['address']) | ||||
self.log.info( | |||||
'Testing sortedmulti descriptors with BIP 67 test vectors') | |||||
with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data/rpc_bip67.json'), encoding='utf-8') as f: | |||||
vectors = json.load(f) | |||||
for t in vectors: | |||||
key_str = ','.join(t['keys']) | |||||
desc = descsum_create('sh(sortedmulti(2,{}))'.format(key_str)) | |||||
assert_equal(self.nodes[0].deriveaddresses(desc)[0], t['address']) | |||||
sorted_key_str = ','.join(t['sorted_keys']) | |||||
sorted_key_desc = descsum_create( | |||||
'sh(multi(2,{}))'.format(sorted_key_str)) | |||||
assert_equal(self.nodes[0].deriveaddresses( | |||||
sorted_key_desc)[0], t['address']) | |||||
def check_addmultisigaddress_errors(self): | def check_addmultisigaddress_errors(self): | ||||
self.log.info( | self.log.info( | ||||
'Check that addmultisigaddress fails when the private keys are missing') | 'Check that addmultisigaddress fails when the private keys are missing') | ||||
addresses = [self.nodes[1].getnewaddress( | addresses = [self.nodes[1].getnewaddress( | ||||
address_type='legacy') for _ in range(2)] | address_type='legacy') for _ in range(2)] | ||||
assert_raises_rpc_error(-5, | assert_raises_rpc_error(-5, | ||||
'no full public key for address', | 'no full public key for address', | ||||
lambda: self.nodes[0].addmultisigaddress(nrequired=1, | lambda: self.nodes[0].addmultisigaddress(nrequired=1, | ||||
▲ Show 20 Lines • Show All 75 Lines • Show Last 20 Lines |