Update wallet_importprunedfunds to avoid dumpprivkey

Removes the use of dumpprivkey so that descriptor wallets can pass on
this. Also does a few descriptor wallet specific changes due to
different IsMine semantics.
pull/18788/head
Andrew Chow 5 years ago
parent f1fcbdea25
commit a357111047

@ -5,11 +5,14 @@
"""Test the importprunedfunds and removeprunedfunds RPCs.""" """Test the importprunedfunds and removeprunedfunds RPCs."""
from decimal import Decimal from decimal import Decimal
from test_framework.address import key_to_p2wpkh
from test_framework.key import ECKey
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_equal, assert_equal,
assert_raises_rpc_error, assert_raises_rpc_error,
) )
from test_framework.wallet_util import bytes_to_wif
class ImportPrunedFundsTest(BitcoinTestFramework): class ImportPrunedFundsTest(BitcoinTestFramework):
def set_test_params(self): def set_test_params(self):
@ -30,8 +33,11 @@ class ImportPrunedFundsTest(BitcoinTestFramework):
# pubkey # pubkey
address2 = self.nodes[0].getnewaddress() address2 = self.nodes[0].getnewaddress()
# privkey # privkey
address3 = self.nodes[0].getnewaddress() eckey = ECKey()
address3_privkey = self.nodes[0].dumpprivkey(address3) # Using privkey eckey.generate()
address3_privkey = bytes_to_wif(eckey.get_bytes())
address3 = key_to_p2wpkh(eckey.get_pubkey().get_bytes())
self.nodes[0].importprivkey(address3_privkey)
# Check only one address # Check only one address
address_info = self.nodes[0].getaddressinfo(address1) address_info = self.nodes[0].getaddressinfo(address1)
@ -80,37 +86,44 @@ class ImportPrunedFundsTest(BitcoinTestFramework):
assert_equal(balance1, Decimal(0)) assert_equal(balance1, Decimal(0))
# Import with affiliated address with no rescan # Import with affiliated address with no rescan
self.nodes[1].importaddress(address=address2, rescan=False) self.nodes[1].createwallet('wwatch', disable_private_keys=True)
self.nodes[1].importprunedfunds(rawtransaction=rawtxn2, txoutproof=proof2) wwatch = self.nodes[1].get_wallet_rpc('wwatch')
assert [tx for tx in self.nodes[1].listtransactions(include_watchonly=True) if tx['txid'] == txnid2] wwatch.importaddress(address=address2, rescan=False)
wwatch.importprunedfunds(rawtransaction=rawtxn2, txoutproof=proof2)
assert [tx for tx in wwatch.listtransactions(include_watchonly=True) if tx['txid'] == txnid2]
# Import with private key with no rescan # Import with private key with no rescan
self.nodes[1].importprivkey(privkey=address3_privkey, rescan=False) w1 = self.nodes[1].get_wallet_rpc(self.default_wallet_name)
self.nodes[1].importprunedfunds(rawtxn3, proof3) w1.importprivkey(privkey=address3_privkey, rescan=False)
assert [tx for tx in self.nodes[1].listtransactions() if tx['txid'] == txnid3] w1.importprunedfunds(rawtxn3, proof3)
balance3 = self.nodes[1].getbalance() assert [tx for tx in w1.listtransactions() if tx['txid'] == txnid3]
balance3 = w1.getbalance()
assert_equal(balance3, Decimal('0.025')) assert_equal(balance3, Decimal('0.025'))
# Addresses Test - after import # Addresses Test - after import
address_info = self.nodes[1].getaddressinfo(address1) address_info = w1.getaddressinfo(address1)
assert_equal(address_info['iswatchonly'], False) assert_equal(address_info['iswatchonly'], False)
assert_equal(address_info['ismine'], False) assert_equal(address_info['ismine'], False)
address_info = self.nodes[1].getaddressinfo(address2) address_info = wwatch.getaddressinfo(address2)
if self.options.descriptors:
assert_equal(address_info['iswatchonly'], False)
assert_equal(address_info['ismine'], True)
else:
assert_equal(address_info['iswatchonly'], True) assert_equal(address_info['iswatchonly'], True)
assert_equal(address_info['ismine'], False) assert_equal(address_info['ismine'], False)
address_info = self.nodes[1].getaddressinfo(address3) address_info = w1.getaddressinfo(address3)
assert_equal(address_info['iswatchonly'], False) assert_equal(address_info['iswatchonly'], False)
assert_equal(address_info['ismine'], True) assert_equal(address_info['ismine'], True)
# Remove transactions # Remove transactions
assert_raises_rpc_error(-8, "Transaction does not exist in wallet.", self.nodes[1].removeprunedfunds, txnid1) assert_raises_rpc_error(-8, "Transaction does not exist in wallet.", w1.removeprunedfunds, txnid1)
assert not [tx for tx in self.nodes[1].listtransactions(include_watchonly=True) if tx['txid'] == txnid1] assert not [tx for tx in w1.listtransactions(include_watchonly=True) if tx['txid'] == txnid1]
self.nodes[1].removeprunedfunds(txnid2) wwatch.removeprunedfunds(txnid2)
assert not [tx for tx in self.nodes[1].listtransactions(include_watchonly=True) if tx['txid'] == txnid2] assert not [tx for tx in wwatch.listtransactions(include_watchonly=True) if tx['txid'] == txnid2]
self.nodes[1].removeprunedfunds(txnid3) w1.removeprunedfunds(txnid3)
assert not [tx for tx in self.nodes[1].listtransactions(include_watchonly=True) if tx['txid'] == txnid3] assert not [tx for tx in w1.listtransactions(include_watchonly=True) if tx['txid'] == txnid3]
if __name__ == '__main__': if __name__ == '__main__':
ImportPrunedFundsTest().main() ImportPrunedFundsTest().main()

Loading…
Cancel
Save