Changeset View
Changeset View
Standalone View
Standalone View
test/functional/wallet_import_rescan.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2014-2016 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 wallet import RPCs. | """Test wallet import RPCs. | ||||
Test rescan behavior of importaddress, importpubkey, importprivkey, and | Test rescan behavior of importaddress, importpubkey, importprivkey, and | ||||
importmulti RPCs with different types of keys and rescan options. | importmulti RPCs with different types of keys and rescan options. | ||||
In the first part of the test, node 0 creates an address for each type of | In the first part of the test, node 0 creates an address for each type of | ||||
Show All 13 Lines | |||||
import itertools | import itertools | ||||
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, | ||||
connect_nodes, | connect_nodes, | ||||
set_node_times, | set_node_times, | ||||
sync_blocks, | |||||
) | ) | ||||
Call = enum.Enum("Call", "single multiaddress multiscript") | Call = enum.Enum("Call", "single multiaddress multiscript") | ||||
Data = enum.Enum("Data", "address pub priv") | Data = enum.Enum("Data", "address pub priv") | ||||
Rescan = enum.Enum("Rescan", "no yes late_timestamp") | Rescan = enum.Enum("Rescan", "no yes late_timestamp") | ||||
▲ Show 20 Lines • Show All 145 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
# Generate a block containing the initial transactions, then another | # Generate a block containing the initial transactions, then another | ||||
# block further in the future (past the rescan window). | # block further in the future (past the rescan window). | ||||
self.nodes[0].generate(1) | self.nodes[0].generate(1) | ||||
assert_equal(self.nodes[0].getrawmempool(), []) | assert_equal(self.nodes[0].getrawmempool(), []) | ||||
timestamp = self.nodes[0].getblockheader( | timestamp = self.nodes[0].getblockheader( | ||||
self.nodes[0].getbestblockhash())["time"] | self.nodes[0].getbestblockhash())["time"] | ||||
set_node_times(self.nodes, timestamp + TIMESTAMP_WINDOW + 1) | set_node_times(self.nodes, timestamp + TIMESTAMP_WINDOW + 1) | ||||
self.nodes[0].generate(1) | self.nodes[0].generate(1) | ||||
sync_blocks(self.nodes) | self.sync_blocks() | ||||
# For each variation of wallet key import, invoke the import RPC and | # For each variation of wallet key import, invoke the import RPC and | ||||
# check the results from getbalance and listtransactions. | # check the results from getbalance and listtransactions. | ||||
for variant in IMPORT_VARIANTS: | for variant in IMPORT_VARIANTS: | ||||
variant.expect_disabled = variant.rescan == Rescan.yes and variant.prune and variant.call == Call.single | variant.expect_disabled = variant.rescan == Rescan.yes and variant.prune and variant.call == Call.single | ||||
expect_rescan = variant.rescan == Rescan.yes and not variant.expect_disabled | expect_rescan = variant.rescan == Rescan.yes and not variant.expect_disabled | ||||
variant.node = self.nodes[ | variant.node = self.nodes[ | ||||
2 + IMPORT_NODES.index(ImportNode(variant.prune, expect_rescan))] | 2 + IMPORT_NODES.index(ImportNode(variant.prune, expect_rescan))] | ||||
Show All 11 Lines | def run_test(self): | ||||
for i, variant in enumerate(IMPORT_VARIANTS): | for i, variant in enumerate(IMPORT_VARIANTS): | ||||
variant.sent_amount = 1 - (2 * i + 1) / 128 | variant.sent_amount = 1 - (2 * i + 1) / 128 | ||||
variant.sent_txid = self.nodes[0].sendtoaddress( | variant.sent_txid = self.nodes[0].sendtoaddress( | ||||
variant.address["address"], variant.sent_amount) | variant.address["address"], variant.sent_amount) | ||||
# Generate a block containing the new transactions. | # Generate a block containing the new transactions. | ||||
self.nodes[0].generate(1) | self.nodes[0].generate(1) | ||||
assert_equal(self.nodes[0].getrawmempool(), []) | assert_equal(self.nodes[0].getrawmempool(), []) | ||||
sync_blocks(self.nodes) | self.sync_blocks() | ||||
# Check the latest results from getbalance and listtransactions. | # Check the latest results from getbalance and listtransactions. | ||||
for variant in IMPORT_VARIANTS: | for variant in IMPORT_VARIANTS: | ||||
if not variant.expect_disabled: | if not variant.expect_disabled: | ||||
variant.expected_balance += variant.sent_amount | variant.expected_balance += variant.sent_amount | ||||
variant.expected_txs += 1 | variant.expected_txs += 1 | ||||
variant.check(variant.sent_txid, variant.sent_amount, 1) | variant.check(variant.sent_txid, variant.sent_amount, 1) | ||||
else: | else: | ||||
variant.check() | variant.check() | ||||
if __name__ == "__main__": | if __name__ == "__main__": | ||||
ImportRescanTest().main() | ImportRescanTest().main() |