Changeset View
Changeset View
Standalone View
Standalone View
test/functional/wallet_importmulti.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2014-2019 The Bitcoin Core developers | # Copyright (c) 2014-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 the importmulti RPC. | """Test the importmulti RPC. | ||||
Test importmulti by generating keys on node0, importing the scriptPubKeys and | Test importmulti by generating keys on node0, importing the scriptPubKeys and | ||||
addresses on node1 and then testing the address info for the different address | addresses on node1 and then testing the address info for the different address | ||||
variants. | variants. | ||||
- `get_key()` and `get_multisig()` are called to generate keys on node0 and | - `get_key()` and `get_multisig()` are called to generate keys on node0 and | ||||
return the privkeys, pubkeys and all variants of scriptPubKey and address. | return the privkeys, pubkeys and all variants of scriptPubKey and address. | ||||
- `test_importmulti()` is called to send an importmulti call to node1, test | - `test_importmulti()` is called to send an importmulti call to node1, test | ||||
success, and (if unsuccessful) test the error code and error message returned. | success, and (if unsuccessful) test the error code and error message returned. | ||||
- `test_address()` is called to call getaddressinfo for an address on node1 | - `test_address()` is called to call getaddressinfo for an address on node1 | ||||
and test the values returned.""" | and test the values returned.""" | ||||
from test_framework.script import ( | from test_framework.script import ( | ||||
CScript, | CScript, | ||||
OP_NOP, | OP_NOP, | ||||
) | ) | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.descriptors import descsum_create | from test_framework.descriptors import descsum_create | ||||
from test_framework.util import ( | from test_framework.util import ( | ||||
assert_equal, | assert_equal, | ||||
▲ Show 20 Lines • Show All 471 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
success=False, error_code=-8, error_message='End of range is too high') | success=False, error_code=-8, error_message='End of range is too high') | ||||
self.test_importmulti({"desc": descsum_create(desc), "timestamp": "now", "range": [2, 1]}, | self.test_importmulti({"desc": descsum_create(desc), "timestamp": "now", "range": [2, 1]}, | ||||
success=False, error_code=-8, error_message='Range specified as [begin,end] must not have begin after end') | success=False, error_code=-8, error_message='Range specified as [begin,end] must not have begin after end') | ||||
self.test_importmulti({"desc": descsum_create(desc), "timestamp": "now", "range": [0, 1000001]}, | self.test_importmulti({"desc": descsum_create(desc), "timestamp": "now", "range": [0, 1000001]}, | ||||
success=False, error_code=-8, error_message='Range is too large') | success=False, error_code=-8, error_message='Range is too large') | ||||
# Test importing a descriptor containing a WIF private key | |||||
wif_priv = "cVu1jApSBCSaDJ5JCxMu5CKfTLndSKckPUswjmiPLLM1brJ9Ht3Q" | |||||
address = "2NDcYJpP57PjFtzJFYVGCWLNkvtpBx1zjEh" | |||||
desc = "sh(pkh(" + wif_priv + "))" | |||||
self.log.info( | |||||
"Should import a descriptor with a WIF private key as spendable") | |||||
self.test_importmulti({"desc": descsum_create(desc), | |||||
"timestamp": "now"}, | |||||
success=True) | |||||
test_address(self.nodes[1], | |||||
address, | |||||
solvable=True, | |||||
ismine=True) | |||||
# dump the private key to ensure it matches what was imported | |||||
privkey = self.nodes[1].dumpprivkey(address) | |||||
assert_equal(privkey, wif_priv) | |||||
# Test importing of a P2PKH address via descriptor | # Test importing of a P2PKH address via descriptor | ||||
key = get_key(self.nodes[0]) | key = get_key(self.nodes[0]) | ||||
p2pkh_label = "P2PKH descriptor import" | p2pkh_label = "P2PKH descriptor import" | ||||
self.log.info("Should import a p2pkh address from descriptor") | self.log.info("Should import a p2pkh address from descriptor") | ||||
self.test_importmulti({"desc": descsum_create("pkh(" + key.pubkey + ")"), | self.test_importmulti({"desc": descsum_create("pkh(" + key.pubkey + ")"), | ||||
"timestamp": "now", | "timestamp": "now", | ||||
"label": p2pkh_label}, | "label": p2pkh_label}, | ||||
success=True, | success=True, | ||||
▲ Show 20 Lines • Show All 233 Lines • Show Last 20 Lines |