Skip to content

Commit

Permalink
Merge bitcoin#9839: [qa] Make import-rescan.py watchonly check reliable
Browse files Browse the repository at this point in the history
864890a [qa] Make import-rescan.py watchonly check reliable (Russell Yanofsky)

Tree-SHA512: ea0e2b1d4fc8f35174c3d575fb751b428daf6ad3aa944fad4e3ddcc9195e4f17051473acabc54203b1d27cca64cf911b737ab92e986c40ef384410652e2dbea1
  • Loading branch information
laanwj committed Feb 27, 2017
2 parents 6206252 + 864890a commit c7e57ce
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions qa/rpc-tests/import-rescan.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
Test rescan behavior of importaddress, importpubkey, importprivkey, and
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
import RPC call and sends BTC to it. Then other nodes import the addresses,
and the test makes listtransactions and getbalance calls to confirm that the
importing node either did or did not execute rescans picking up the send
transactions.
In the first part of the test, node 1 creates an address for each type of
import RPC call and node 0 sends BTC to it. Then other nodes import the
addresses, and the test makes listtransactions and getbalance calls to confirm
that the importing node either did or did not execute rescans picking up the
send transactions.
In the second part of the test, node 0 sends more BTC to each address, and the
test makes more listtransactions and getbalance calls to confirm that the
Expand Down Expand Up @@ -83,6 +83,12 @@ def check(self, txid=None, amount=None, confirmations=None):
assert_equal(tx["txid"], txid)
assert_equal(tx["confirmations"], confirmations)
assert_equal("trusted" not in tx, True)
# Verify the transaction is correctly marked watchonly depending on
# whether the transaction pays to an imported public key or
# imported private key. The test setup ensures that transaction
# inputs will not be from watchonly keys (important because
# involvesWatchonly will be true if either the transaction output
# or inputs are watchonly).
if self.data != Data.priv:
assert_equal(tx["involvesWatchonly"], True)
else:
Expand All @@ -108,11 +114,11 @@ def check(self, txid=None, amount=None, confirmations=None):
class ImportRescanTest(BitcoinTestFramework):
def __init__(self):
super().__init__()
self.num_nodes = 1 + len(IMPORT_NODES)
self.num_nodes = 2 + len(IMPORT_NODES)

def setup_network(self):
extra_args = [["-debug=1"] for _ in range(self.num_nodes)]
for i, import_node in enumerate(IMPORT_NODES, 1):
for i, import_node in enumerate(IMPORT_NODES, 2):
if import_node.prune:
extra_args[i] += ["-prune=1"]

Expand All @@ -125,9 +131,9 @@ def run_test(self):
# each possible type of wallet import RPC.
for i, variant in enumerate(IMPORT_VARIANTS):
variant.label = "label {} {}".format(i, variant)
variant.address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress(variant.label))
variant.key = self.nodes[0].dumpprivkey(variant.address["address"])
variant.initial_amount = 25 - (i + 1) / 4.0
variant.address = self.nodes[1].validateaddress(self.nodes[1].getnewaddress(variant.label))
variant.key = self.nodes[1].dumpprivkey(variant.address["address"])
variant.initial_amount = 10 - (i + 1) / 4.0
variant.initial_txid = self.nodes[0].sendtoaddress(variant.address["address"], variant.initial_amount)

# Generate a block containing the initial transactions, then another
Expand All @@ -144,7 +150,7 @@ def run_test(self):
for variant in IMPORT_VARIANTS:
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
variant.node = self.nodes[1 + IMPORT_NODES.index(ImportNode(variant.prune, expect_rescan))]
variant.node = self.nodes[2 + IMPORT_NODES.index(ImportNode(variant.prune, expect_rescan))]
variant.do_import(timestamp)
if expect_rescan:
variant.expected_balance = variant.initial_amount
Expand All @@ -158,7 +164,7 @@ def run_test(self):
# Create new transactions sending to each address.
fee = self.nodes[0].getnetworkinfo()["relayfee"]
for i, variant in enumerate(IMPORT_VARIANTS):
variant.sent_amount = 25 - (2 * i + 1) / 8.0
variant.sent_amount = 10 - (2 * i + 1) / 8.0
variant.sent_txid = self.nodes[0].sendtoaddress(variant.address["address"], variant.sent_amount)

# Generate a block containing the new transactions.
Expand Down

0 comments on commit c7e57ce

Please sign in to comment.