Changeset View
Changeset View
Standalone View
Standalone View
test/functional/wallet_import_rescan.py
Show All 13 Lines | |||||
send transactions. | send transactions. | ||||
In the second part of the test, node 0 sends more BCH to each address, and the | In the second part of the test, node 0 sends more BCH to each address, and the | ||||
test makes more listtransactions and getbalance calls to confirm that the | test makes more listtransactions and getbalance calls to confirm that the | ||||
importing nodes pick up the new transactions regardless of whether rescans | importing nodes pick up the new transactions regardless of whether rescans | ||||
happened previously. | happened previously. | ||||
""" | """ | ||||
from decimal import Decimal | |||||
import collections | import collections | ||||
import enum | import enum | ||||
import itertools | import itertools | ||||
import random | |||||
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, | ||||
connect_nodes, | connect_nodes, | ||||
set_node_times, | set_node_times, | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 90 Lines • ▼ Show 20 Lines | |||||
# track of expected balances and transactions. | # track of expected balances and transactions. | ||||
ImportNode = collections.namedtuple("ImportNode", "prune rescan") | ImportNode = collections.namedtuple("ImportNode", "prune rescan") | ||||
IMPORT_NODES = [ImportNode(*fields) | IMPORT_NODES = [ImportNode(*fields) | ||||
for fields in itertools.product((False, True), repeat=2)] | for fields in itertools.product((False, True), repeat=2)] | ||||
# Rescans start at the earliest block up to 2 hours before the key timestamp. | # Rescans start at the earliest block up to 2 hours before the key timestamp. | ||||
TIMESTAMP_WINDOW = 2 * 60 * 60 | TIMESTAMP_WINDOW = 2 * 60 * 60 | ||||
AMOUNT_DUST = 0.00000546 | |||||
def get_rand_amount(): | |||||
r = random.uniform(AMOUNT_DUST, 1) | |||||
return Decimal(str(round(r, 8))) | |||||
class ImportRescanTest(BitcoinTestFramework): | class ImportRescanTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.num_nodes = 2 + len(IMPORT_NODES) | self.num_nodes = 2 + len(IMPORT_NODES) | ||||
def skip_test_if_missing_module(self): | def skip_test_if_missing_module(self): | ||||
self.skip_if_no_wallet() | self.skip_if_no_wallet() | ||||
Show All 20 Lines | class ImportRescanTest(BitcoinTestFramework): | ||||
def run_test(self): | def run_test(self): | ||||
# Create one transaction on node 0 with a unique amount for | # Create one transaction on node 0 with a unique amount for | ||||
# each possible type of wallet import RPC. | # each possible type of wallet import RPC. | ||||
for i, variant in enumerate(IMPORT_VARIANTS): | for i, variant in enumerate(IMPORT_VARIANTS): | ||||
variant.label = "label {} {}".format(i, variant) | variant.label = "label {} {}".format(i, variant) | ||||
variant.address = self.nodes[1].getaddressinfo( | variant.address = self.nodes[1].getaddressinfo( | ||||
self.nodes[1].getnewaddress(variant.label)) | self.nodes[1].getnewaddress(variant.label)) | ||||
variant.key = self.nodes[1].dumpprivkey(variant.address["address"]) | variant.key = self.nodes[1].dumpprivkey(variant.address["address"]) | ||||
variant.initial_amount = 1 - (i + 1) / 64 | variant.initial_amount = get_rand_amount() | ||||
variant.initial_txid = self.nodes[0].sendtoaddress( | variant.initial_txid = self.nodes[0].sendtoaddress( | ||||
variant.address["address"], variant.initial_amount) | variant.address["address"], variant.initial_amount) | ||||
# Generate one block for each send | # Generate one block for each send | ||||
self.nodes[0].generate(1) | self.nodes[0].generate(1) | ||||
variant.confirmation_height = self.nodes[0].getblockcount() | variant.confirmation_height = self.nodes[0].getblockcount() | ||||
variant.timestamp = self.nodes[0].getblockheader( | variant.timestamp = self.nodes[0].getblockheader( | ||||
self.nodes[0].getbestblockhash())["time"] | self.nodes[0].getbestblockhash())["time"] | ||||
Show All 19 Lines | def run_test(self): | ||||
variant.confirmation_height) | variant.confirmation_height) | ||||
else: | else: | ||||
variant.expected_balance = 0 | variant.expected_balance = 0 | ||||
variant.expected_txs = 0 | variant.expected_txs = 0 | ||||
variant.check() | variant.check() | ||||
# Create new transactions sending to each address. | # Create new transactions sending to each address. | ||||
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 = get_rand_amount() | ||||
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 one block for each send | # Generate one block for each send | ||||
self.nodes[0].generate(1) | self.nodes[0].generate(1) | ||||
variant.confirmation_height = self.nodes[0].getblockcount() | variant.confirmation_height = self.nodes[0].getblockcount() | ||||
assert_equal(self.nodes[0].getrawmempool(), []) | assert_equal(self.nodes[0].getrawmempool(), []) | ||||
self.sync_all() | self.sync_all() | ||||
Show All 12 Lines |