Changeset View
Changeset View
Standalone View
Standalone View
test/functional/wallet_importprunedfunds.py
Show All 32 Lines | def run_test(self): | ||||
eckey = ECKey() | eckey = ECKey() | ||||
eckey.generate() | eckey.generate() | ||||
address3_privkey = bytes_to_wif(eckey.get_bytes()) | address3_privkey = bytes_to_wif(eckey.get_bytes()) | ||||
address3 = key_to_p2pkh(eckey.get_pubkey().get_bytes()) | address3 = key_to_p2pkh(eckey.get_pubkey().get_bytes()) | ||||
self.nodes[0].importprivkey(address3_privkey) | 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) | ||||
assert_equal(address_info['ismine'], True) | assert_equal(address_info["ismine"], True) | ||||
self.sync_all() | self.sync_all() | ||||
# Node 1 sync test | # Node 1 sync test | ||||
assert_equal(self.nodes[1].getblockcount(), 101) | assert_equal(self.nodes[1].getblockcount(), 101) | ||||
# Address Test - before import | # Address Test - before import | ||||
address_info = self.nodes[1].getaddressinfo(address1) | address_info = self.nodes[1].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 = self.nodes[1].getaddressinfo(address2) | ||||
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(address3) | address_info = self.nodes[1].getaddressinfo(address3) | ||||
assert_equal(address_info['iswatchonly'], False) | assert_equal(address_info["iswatchonly"], False) | ||||
assert_equal(address_info['ismine'], False) | assert_equal(address_info["ismine"], False) | ||||
# Send funds to self | # Send funds to self | ||||
txnid1 = self.nodes[0].sendtoaddress(address1, 100000) | txnid1 = self.nodes[0].sendtoaddress(address1, 100000) | ||||
self.generate(self.nodes[0], 1) | self.generate(self.nodes[0], 1) | ||||
rawtxn1 = self.nodes[0].gettransaction(txnid1)['hex'] | rawtxn1 = self.nodes[0].gettransaction(txnid1)["hex"] | ||||
proof1 = self.nodes[0].gettxoutproof([txnid1]) | proof1 = self.nodes[0].gettxoutproof([txnid1]) | ||||
txnid2 = self.nodes[0].sendtoaddress(address2, 50000) | txnid2 = self.nodes[0].sendtoaddress(address2, 50000) | ||||
self.generate(self.nodes[0], 1) | self.generate(self.nodes[0], 1) | ||||
rawtxn2 = self.nodes[0].gettransaction(txnid2)['hex'] | rawtxn2 = self.nodes[0].gettransaction(txnid2)["hex"] | ||||
proof2 = self.nodes[0].gettxoutproof([txnid2]) | proof2 = self.nodes[0].gettxoutproof([txnid2]) | ||||
txnid3 = self.nodes[0].sendtoaddress(address3, 25000) | txnid3 = self.nodes[0].sendtoaddress(address3, 25000) | ||||
self.generate(self.nodes[0], 1) | self.generate(self.nodes[0], 1) | ||||
rawtxn3 = self.nodes[0].gettransaction(txnid3)['hex'] | rawtxn3 = self.nodes[0].gettransaction(txnid3)["hex"] | ||||
proof3 = self.nodes[0].gettxoutproof([txnid3]) | proof3 = self.nodes[0].gettxoutproof([txnid3]) | ||||
self.sync_all() | self.sync_all() | ||||
# Import with no affiliated address | # Import with no affiliated address | ||||
assert_raises_rpc_error( | assert_raises_rpc_error( | ||||
-5, "No addresses", self.nodes[1].importprunedfunds, rawtxn1, proof1) | -5, "No addresses", self.nodes[1].importprunedfunds, rawtxn1, proof1 | ||||
) | |||||
balance1 = self.nodes[1].getbalance() | balance1 = self.nodes[1].getbalance() | ||||
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].createwallet('wwatch', disable_private_keys=True) | self.nodes[1].createwallet("wwatch", disable_private_keys=True) | ||||
wwatch = self.nodes[1].get_wallet_rpc('wwatch') | wwatch = self.nodes[1].get_wallet_rpc("wwatch") | ||||
wwatch.importaddress(address=address2, rescan=False) | wwatch.importaddress(address=address2, rescan=False) | ||||
wwatch.importprunedfunds(rawtransaction=rawtxn2, txoutproof=proof2) | wwatch.importprunedfunds(rawtransaction=rawtxn2, txoutproof=proof2) | ||||
assert [tx for tx in wwatch.listtransactions(include_watchonly=True) | assert [ | ||||
if tx['txid'] == txnid2] | 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 | ||||
w1 = self.nodes[1].get_wallet_rpc(self.default_wallet_name) | w1 = self.nodes[1].get_wallet_rpc(self.default_wallet_name) | ||||
w1.importprivkey(privkey=address3_privkey, rescan=False) | w1.importprivkey(privkey=address3_privkey, rescan=False) | ||||
w1.importprunedfunds(rawtxn3, proof3) | w1.importprunedfunds(rawtxn3, proof3) | ||||
assert [tx for tx in w1.listtransactions() if tx['txid'] == txnid3] | assert [tx for tx in w1.listtransactions() if tx["txid"] == txnid3] | ||||
balance3 = w1.getbalance() | balance3 = w1.getbalance() | ||||
assert_equal(balance3, Decimal('25000')) | assert_equal(balance3, Decimal("25000")) | ||||
# Addresses Test - after import | # Addresses Test - after import | ||||
address_info = w1.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 = wwatch.getaddressinfo(address2) | address_info = wwatch.getaddressinfo(address2) | ||||
if self.options.descriptors: | if self.options.descriptors: | ||||
assert_equal(address_info['iswatchonly'], False) | assert_equal(address_info["iswatchonly"], False) | ||||
assert_equal(address_info['ismine'], True) | assert_equal(address_info["ismine"], True) | ||||
else: | 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 = w1.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( | assert_raises_rpc_error( | ||||
-8, "Transaction does not exist in wallet.", w1.removeprunedfunds, txnid1) | -8, "Transaction does not exist in wallet.", w1.removeprunedfunds, txnid1 | ||||
) | |||||
assert not [tx for tx in w1.listtransactions( | assert not [ | ||||
include_watchonly=True) if tx['txid'] == txnid1] | tx | ||||
for tx in w1.listtransactions(include_watchonly=True) | |||||
if tx["txid"] == txnid1 | |||||
] | |||||
wwatch.removeprunedfunds(txnid2) | wwatch.removeprunedfunds(txnid2) | ||||
assert not [tx for tx in wwatch.listtransactions( | assert not [ | ||||
include_watchonly=True) if tx['txid'] == txnid2] | tx | ||||
for tx in wwatch.listtransactions(include_watchonly=True) | |||||
if tx["txid"] == txnid2 | |||||
] | |||||
w1.removeprunedfunds(txnid3) | w1.removeprunedfunds(txnid3) | ||||
assert not [tx for tx in w1.listtransactions( | assert not [ | ||||
include_watchonly=True) if tx['txid'] == txnid3] | tx | ||||
for tx in w1.listtransactions(include_watchonly=True) | |||||
if tx["txid"] == txnid3 | |||||
] | |||||
if __name__ == '__main__': | if __name__ == "__main__": | ||||
ImportPrunedFundsTest().main() | ImportPrunedFundsTest().main() |