0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-10 10:52:31 -05:00

Merge #17387: wallet_importmulti: use addresses of the same type as being imported

b84e776fd1 wallet_importmulti: use addresses of the same type as being imported (Andrew Chow)

Pull request description:

  When constructing an import from the solving data of an address, make sure that the original address is the same type as the one that will be imported.

  See also: https://github.com/bitcoin/bitcoin/pull/17374#issuecomment-550036931

  Part of #17261

ACKs for top commit:
  Sjors:
    Code review ACK b84e776
  meshcollider:
    Tested re-ACK b84e776fd1

Tree-SHA512: 53c49c63af8cbade0116a62beddc77df1a411d8ed76571c3053f6aff096f41a5325421a188bab3dcacfda69bb28fdff6ba921ddd80f29c4abbadb3b58fda884c
This commit is contained in:
Samuel Dobson 2019-11-23 10:19:43 +13:00
commit 4effd67bf4
No known key found for this signature in database
GPG key ID: D300116E1C875A3D

View file

@ -675,7 +675,7 @@ class ImportMultiTest(BitcoinTestFramework):
# Import pubkeys with key origin info # Import pubkeys with key origin info
self.log.info("Addresses should have hd keypath and master key id after import with key origin") self.log.info("Addresses should have hd keypath and master key id after import with key origin")
pub_addr = self.nodes[1].getnewaddress() pub_addr = self.nodes[1].getnewaddress()
pub_addr = self.nodes[1].getnewaddress() pub_addr = self.nodes[1].getnewaddress(address_type="bech32")
info = self.nodes[1].getaddressinfo(pub_addr) info = self.nodes[1].getaddressinfo(pub_addr)
pub = info['pubkey'] pub = info['pubkey']
pub_keypath = info['hdkeypath'] pub_keypath = info['hdkeypath']
@ -693,7 +693,7 @@ class ImportMultiTest(BitcoinTestFramework):
assert_equal(pub_import_info['hdkeypath'], pub_keypath) assert_equal(pub_import_info['hdkeypath'], pub_keypath)
# Import privkeys with key origin info # Import privkeys with key origin info
priv_addr = self.nodes[1].getnewaddress() priv_addr = self.nodes[1].getnewaddress(address_type="bech32")
info = self.nodes[1].getaddressinfo(priv_addr) info = self.nodes[1].getaddressinfo(priv_addr)
priv = self.nodes[1].dumpprivkey(priv_addr) priv = self.nodes[1].dumpprivkey(priv_addr)
priv_keypath = info['hdkeypath'] priv_keypath = info['hdkeypath']
@ -742,8 +742,8 @@ class ImportMultiTest(BitcoinTestFramework):
self.nodes[1].createwallet(wallet_name="noprivkeys", disable_private_keys=True) self.nodes[1].createwallet(wallet_name="noprivkeys", disable_private_keys=True)
wrpc = self.nodes[1].get_wallet_rpc("noprivkeys") wrpc = self.nodes[1].get_wallet_rpc("noprivkeys")
addr1 = self.nodes[0].getnewaddress() addr1 = self.nodes[0].getnewaddress(address_type="bech32")
addr2 = self.nodes[0].getnewaddress() addr2 = self.nodes[0].getnewaddress(address_type="bech32")
pub1 = self.nodes[0].getaddressinfo(addr1)['pubkey'] pub1 = self.nodes[0].getaddressinfo(addr1)['pubkey']
pub2 = self.nodes[0].getaddressinfo(addr2)['pubkey'] pub2 = self.nodes[0].getaddressinfo(addr2)['pubkey']
result = wrpc.importmulti( result = wrpc.importmulti(
@ -761,15 +761,15 @@ class ImportMultiTest(BitcoinTestFramework):
assert result[0]['success'] assert result[0]['success']
assert result[1]['success'] assert result[1]['success']
assert_equal(wrpc.getwalletinfo()["keypoolsize"], 2) assert_equal(wrpc.getwalletinfo()["keypoolsize"], 2)
newaddr1 = wrpc.getnewaddress() newaddr1 = wrpc.getnewaddress(address_type="bech32")
assert_equal(addr1, newaddr1) assert_equal(addr1, newaddr1)
newaddr2 = wrpc.getnewaddress() newaddr2 = wrpc.getnewaddress(address_type="bech32")
assert_equal(addr2, newaddr2) assert_equal(addr2, newaddr2)
# Import some public keys to the internal keypool of a no privkey wallet # Import some public keys to the internal keypool of a no privkey wallet
self.log.info("Adding pubkey to internal keypool of disableprivkey wallet") self.log.info("Adding pubkey to internal keypool of disableprivkey wallet")
addr1 = self.nodes[0].getnewaddress() addr1 = self.nodes[0].getnewaddress(address_type="bech32")
addr2 = self.nodes[0].getnewaddress() addr2 = self.nodes[0].getnewaddress(address_type="bech32")
pub1 = self.nodes[0].getaddressinfo(addr1)['pubkey'] pub1 = self.nodes[0].getaddressinfo(addr1)['pubkey']
pub2 = self.nodes[0].getaddressinfo(addr2)['pubkey'] pub2 = self.nodes[0].getaddressinfo(addr2)['pubkey']
result = wrpc.importmulti( result = wrpc.importmulti(
@ -789,15 +789,15 @@ class ImportMultiTest(BitcoinTestFramework):
assert result[0]['success'] assert result[0]['success']
assert result[1]['success'] assert result[1]['success']
assert_equal(wrpc.getwalletinfo()["keypoolsize_hd_internal"], 2) assert_equal(wrpc.getwalletinfo()["keypoolsize_hd_internal"], 2)
newaddr1 = wrpc.getrawchangeaddress() newaddr1 = wrpc.getrawchangeaddress(address_type="bech32")
assert_equal(addr1, newaddr1) assert_equal(addr1, newaddr1)
newaddr2 = wrpc.getrawchangeaddress() newaddr2 = wrpc.getrawchangeaddress(address_type="bech32")
assert_equal(addr2, newaddr2) assert_equal(addr2, newaddr2)
# Import a multisig and make sure the keys don't go into the keypool # Import a multisig and make sure the keys don't go into the keypool
self.log.info('Imported scripts with pubkeys should not have their pubkeys go into the keypool') self.log.info('Imported scripts with pubkeys should not have their pubkeys go into the keypool')
addr1 = self.nodes[0].getnewaddress() addr1 = self.nodes[0].getnewaddress(address_type="bech32")
addr2 = self.nodes[0].getnewaddress() addr2 = self.nodes[0].getnewaddress(address_type="bech32")
pub1 = self.nodes[0].getaddressinfo(addr1)['pubkey'] pub1 = self.nodes[0].getaddressinfo(addr1)['pubkey']
pub2 = self.nodes[0].getaddressinfo(addr2)['pubkey'] pub2 = self.nodes[0].getaddressinfo(addr2)['pubkey']
result = wrpc.importmulti( result = wrpc.importmulti(