Changed functional tests which do not require wallets to run without

skipping  .Addreses #14216. Changed get_deterministic_priv_key() to a

named tuple
This commit is contained in:
sanket1729 2018-09-15 04:32:12 -05:00
parent 3832c25f17
commit 0ca4c8b3c6
22 changed files with 58 additions and 107 deletions

View file

@ -85,6 +85,8 @@ class ExampleTest(BitcoinTestFramework):
# self.log.info("I've finished set_test_params") # Oops! Can't run self.log before run_test() # self.log.info("I've finished set_test_params") # Oops! Can't run self.log before run_test()
# Use skip_test_if_missing_module() to skip the test if your test requires certain modules to be present.
# This test uses generate which requires wallet to be compiled
def skip_test_if_missing_module(self): def skip_test_if_missing_module(self):
self.skip_if_no_wallet() self.skip_if_no_wallet()

View file

@ -75,9 +75,6 @@ class FullBlockTest(BitcoinTestFramework):
self.setup_clean_chain = True self.setup_clean_chain = True
self.extra_args = [[]] self.extra_args = [[]]
def skip_test_if_missing_module(self):
self.skip_if_no_wallet()
def run_test(self): def run_test(self):
node = self.nodes[0] # convenience reference to the node node = self.nodes[0] # convenience reference to the node

View file

@ -16,9 +16,6 @@ class BlocksdirTest(BitcoinTestFramework):
self.setup_clean_chain = True self.setup_clean_chain = True
self.num_nodes = 1 self.num_nodes = 1
def skip_test_if_missing_module(self):
self.skip_if_no_wallet()
def run_test(self): def run_test(self):
self.stop_node(0) self.stop_node(0)
shutil.rmtree(self.nodes[0].datadir) shutil.rmtree(self.nodes[0].datadir)
@ -30,7 +27,7 @@ class BlocksdirTest(BitcoinTestFramework):
self.log.info("Starting with existing blocksdir ...") self.log.info("Starting with existing blocksdir ...")
self.start_node(0, ["-blocksdir=" + blocksdir_path]) self.start_node(0, ["-blocksdir=" + blocksdir_path])
self.log.info("mining blocks..") self.log.info("mining blocks..")
self.nodes[0].generate(10) self.nodes[0].generatetoaddress(10, self.nodes[0].get_deterministic_priv_key().address)
assert os.path.isfile(os.path.join(blocksdir_path, "regtest", "blocks", "blk00000.dat")) assert os.path.isfile(os.path.join(blocksdir_path, "regtest", "blocks", "blk00000.dat"))
assert os.path.isdir(os.path.join(self.nodes[0].datadir, "regtest", "blocks", "index")) assert os.path.isdir(os.path.join(self.nodes[0].datadir, "regtest", "blocks", "index"))

View file

@ -15,9 +15,6 @@ class LoggingTest(BitcoinTestFramework):
self.num_nodes = 1 self.num_nodes = 1
self.setup_clean_chain = True self.setup_clean_chain = True
def skip_test_if_missing_module(self):
self.skip_if_no_wallet()
def relative_log_path(self, name): def relative_log_path(self, name):
return os.path.join(self.nodes[0].datadir, "regtest", name) return os.path.join(self.nodes[0].datadir, "regtest", name)

View file

@ -31,9 +31,6 @@ class MinimumChainWorkTest(BitcoinTestFramework):
self.extra_args = [[], ["-minimumchainwork=0x65"], ["-minimumchainwork=0x65"]] self.extra_args = [[], ["-minimumchainwork=0x65"], ["-minimumchainwork=0x65"]]
self.node_min_work = [0, 101, 101] self.node_min_work = [0, 101, 101]
def skip_test_if_missing_module(self):
self.skip_if_no_wallet()
def setup_network(self): def setup_network(self):
# This test relies on the chain setup being: # This test relies on the chain setup being:
# node0 <- node1 <- node2 # node0 <- node1 <- node2
@ -54,7 +51,8 @@ class MinimumChainWorkTest(BitcoinTestFramework):
num_blocks_to_generate = int((self.node_min_work[1] - starting_chain_work) / REGTEST_WORK_PER_BLOCK) num_blocks_to_generate = int((self.node_min_work[1] - starting_chain_work) / REGTEST_WORK_PER_BLOCK)
self.log.info("Generating %d blocks on node0", num_blocks_to_generate) self.log.info("Generating %d blocks on node0", num_blocks_to_generate)
hashes = self.nodes[0].generate(num_blocks_to_generate) hashes = self.nodes[0].generatetoaddress(num_blocks_to_generate,
self.nodes[0].get_deterministic_priv_key().address)
self.log.info("Node0 current chain work: %s", self.nodes[0].getblockheader(hashes[-1])['chainwork']) self.log.info("Node0 current chain work: %s", self.nodes[0].getblockheader(hashes[-1])['chainwork'])
@ -75,7 +73,7 @@ class MinimumChainWorkTest(BitcoinTestFramework):
assert_equal(self.nodes[2].getblockcount(), starting_blockcount) assert_equal(self.nodes[2].getblockcount(), starting_blockcount)
self.log.info("Generating one more block") self.log.info("Generating one more block")
self.nodes[0].generate(1) self.nodes[0].generatetoaddress(1, self.nodes[0].get_deterministic_priv_key().address)
self.log.info("Verifying nodes are all synced") self.log.info("Verifying nodes are all synced")

View file

@ -18,11 +18,8 @@ class ReindexTest(BitcoinTestFramework):
self.setup_clean_chain = True self.setup_clean_chain = True
self.num_nodes = 1 self.num_nodes = 1
def skip_test_if_missing_module(self):
self.skip_if_no_wallet()
def reindex(self, justchainstate=False): def reindex(self, justchainstate=False):
self.nodes[0].generate(3) self.nodes[0].generatetoaddress(3, self.nodes[0].get_deterministic_priv_key().address)
blockcount = self.nodes[0].getblockcount() blockcount = self.nodes[0].getblockcount()
self.stop_nodes() self.stop_nodes()
extra_args = [["-reindex-chainstate" if justchainstate else "-reindex"]] extra_args = [["-reindex-chainstate" if justchainstate else "-reindex"]]

View file

@ -31,9 +31,6 @@ class VersionBitsWarningTest(BitcoinTestFramework):
self.setup_clean_chain = True self.setup_clean_chain = True
self.num_nodes = 1 self.num_nodes = 1
def skip_test_if_missing_module(self):
self.skip_if_no_wallet()
def setup_network(self): def setup_network(self):
self.alert_filename = os.path.join(self.options.tmpdir, "alert.txt") self.alert_filename = os.path.join(self.options.tmpdir, "alert.txt")
# Open and close to create zero-length file # Open and close to create zero-length file
@ -68,13 +65,14 @@ class VersionBitsWarningTest(BitcoinTestFramework):
node = self.nodes[0] node = self.nodes[0]
node.add_p2p_connection(P2PInterface()) node.add_p2p_connection(P2PInterface())
node_deterministic_address = node.get_deterministic_priv_key().address
# Mine one period worth of blocks # Mine one period worth of blocks
node.generate(VB_PERIOD) node.generatetoaddress(VB_PERIOD, node_deterministic_address)
self.log.info("Check that there is no warning if previous VB_BLOCKS have <VB_THRESHOLD blocks with unknown versionbits version.") self.log.info("Check that there is no warning if previous VB_BLOCKS have <VB_THRESHOLD blocks with unknown versionbits version.")
# Build one period of blocks with < VB_THRESHOLD blocks signaling some unknown bit # Build one period of blocks with < VB_THRESHOLD blocks signaling some unknown bit
self.send_blocks_with_version(node.p2p, VB_THRESHOLD - 1, VB_UNKNOWN_VERSION) self.send_blocks_with_version(node.p2p, VB_THRESHOLD - 1, VB_UNKNOWN_VERSION)
node.generate(VB_PERIOD - VB_THRESHOLD + 1) node.generatetoaddress(VB_PERIOD - VB_THRESHOLD + 1, node_deterministic_address)
# Check that we're not getting any versionbit-related errors in get*info() # Check that we're not getting any versionbit-related errors in get*info()
assert(not VB_PATTERN.match(node.getmininginfo()["warnings"])) assert(not VB_PATTERN.match(node.getmininginfo()["warnings"]))
@ -83,7 +81,7 @@ class VersionBitsWarningTest(BitcoinTestFramework):
self.log.info("Check that there is a warning if >50 blocks in the last 100 were an unknown version") self.log.info("Check that there is a warning if >50 blocks in the last 100 were an unknown version")
# Build one period of blocks with VB_THRESHOLD blocks signaling some unknown bit # Build one period of blocks with VB_THRESHOLD blocks signaling some unknown bit
self.send_blocks_with_version(node.p2p, VB_THRESHOLD, VB_UNKNOWN_VERSION) self.send_blocks_with_version(node.p2p, VB_THRESHOLD, VB_UNKNOWN_VERSION)
node.generate(VB_PERIOD - VB_THRESHOLD) node.generatetoaddress(VB_PERIOD - VB_THRESHOLD, node_deterministic_address)
# Check that get*info() shows the 51/100 unknown block version error. # Check that get*info() shows the 51/100 unknown block version error.
assert(WARN_UNKNOWN_RULES_MINED in node.getmininginfo()["warnings"]) assert(WARN_UNKNOWN_RULES_MINED in node.getmininginfo()["warnings"])
@ -92,16 +90,16 @@ class VersionBitsWarningTest(BitcoinTestFramework):
self.log.info("Check that there is a warning if previous VB_BLOCKS have >=VB_THRESHOLD blocks with unknown versionbits version.") self.log.info("Check that there is a warning if previous VB_BLOCKS have >=VB_THRESHOLD blocks with unknown versionbits version.")
# Mine a period worth of expected blocks so the generic block-version warning # Mine a period worth of expected blocks so the generic block-version warning
# is cleared. This will move the versionbit state to ACTIVE. # is cleared. This will move the versionbit state to ACTIVE.
node.generate(VB_PERIOD) node.generatetoaddress(VB_PERIOD, node_deterministic_address)
# Stop-start the node. This is required because bitcoind will only warn once about unknown versions or unknown rules activating. # Stop-start the node. This is required because bitcoind will only warn once about unknown versions or unknown rules activating.
self.restart_node(0) self.restart_node(0)
# Generating one block guarantees that we'll get out of IBD # Generating one block guarantees that we'll get out of IBD
node.generate(1) node.generatetoaddress(1, node_deterministic_address)
wait_until(lambda: not node.getblockchaininfo()['initialblockdownload'], timeout=10, lock=mininode_lock) wait_until(lambda: not node.getblockchaininfo()['initialblockdownload'], timeout=10, lock=mininode_lock)
# Generating one more block will be enough to generate an error. # Generating one more block will be enough to generate an error.
node.generate(1) node.generatetoaddress(1, node_deterministic_address)
# Check that get*info() shows the versionbits unknown rules warning # Check that get*info() shows the versionbits unknown rules warning
assert(WARN_UNKNOWN_RULES_ACTIVE in node.getmininginfo()["warnings"]) assert(WARN_UNKNOWN_RULES_ACTIVE in node.getmininginfo()["warnings"])
assert(WARN_UNKNOWN_RULES_ACTIVE in node.getnetworkinfo()["warnings"]) assert(WARN_UNKNOWN_RULES_ACTIVE in node.getnetworkinfo()["warnings"])

View file

@ -38,9 +38,6 @@ class MiningTest(BitcoinTestFramework):
self.num_nodes = 2 self.num_nodes = 2
self.setup_clean_chain = False self.setup_clean_chain = False
def skip_test_if_missing_module(self):
self.skip_if_no_wallet()
def run_test(self): def run_test(self):
node = self.nodes[0] node = self.nodes[0]
@ -61,7 +58,7 @@ class MiningTest(BitcoinTestFramework):
assert_equal(mining_info['pooledtx'], 0) assert_equal(mining_info['pooledtx'], 0)
# Mine a block to leave initial block download # Mine a block to leave initial block download
node.generate(1) node.generatetoaddress(1, node.get_deterministic_priv_key().address)
tmpl = node.getblocktemplate() tmpl = node.getblocktemplate()
self.log.info("getblocktemplate: Test capability advertised") self.log.info("getblocktemplate: Test capability advertised")
assert 'proposal' in tmpl['capabilities'] assert 'proposal' in tmpl['capabilities']
@ -212,7 +209,7 @@ class MiningTest(BitcoinTestFramework):
assert chain_tip(block.hash, status='active', branchlen=0) in node.getchaintips() assert chain_tip(block.hash, status='active', branchlen=0) in node.getchaintips()
# Building a few blocks should give the same results # Building a few blocks should give the same results
node.generate(10) node.generatetoaddress(10, node.get_deterministic_priv_key().address)
assert_raises_rpc_error(-25, 'time-too-old', lambda: node.submitheader(hexdata=b2x(CBlockHeader(bad_block_time).serialize()))) assert_raises_rpc_error(-25, 'time-too-old', lambda: node.submitheader(hexdata=b2x(CBlockHeader(bad_block_time).serialize())))
assert_raises_rpc_error(-25, 'bad-prevblk', lambda: node.submitheader(hexdata=b2x(CBlockHeader(bad_block2).serialize()))) assert_raises_rpc_error(-25, 'bad-prevblk', lambda: node.submitheader(hexdata=b2x(CBlockHeader(bad_block2).serialize())))
node.submitheader(hexdata=b2x(CBlockHeader(block).serialize())) node.submitheader(hexdata=b2x(CBlockHeader(block).serialize()))

View file

@ -30,9 +30,6 @@ class P2PFingerprintTest(BitcoinTestFramework):
self.setup_clean_chain = True self.setup_clean_chain = True
self.num_nodes = 1 self.num_nodes = 1
def skip_test_if_missing_module(self):
self.skip_if_no_wallet()
# Build a chain of blocks on top of given one # Build a chain of blocks on top of given one
def build_chain(self, nblocks, prev_hash, prev_height, prev_median_time): def build_chain(self, nblocks, prev_hash, prev_height, prev_median_time):
blocks = [] blocks = []
@ -83,7 +80,7 @@ class P2PFingerprintTest(BitcoinTestFramework):
self.nodes[0].setmocktime(int(time.time()) - 60 * 24 * 60 * 60) self.nodes[0].setmocktime(int(time.time()) - 60 * 24 * 60 * 60)
# Generating a chain of 10 blocks # Generating a chain of 10 blocks
block_hashes = self.nodes[0].generate(nblocks=10) block_hashes = self.nodes[0].generatetoaddress(10, self.nodes[0].get_deterministic_priv_key().address)
# Create longer chain starting 2 blocks before current tip # Create longer chain starting 2 blocks before current tip
height = len(block_hashes) - 2 height = len(block_hashes) - 2
@ -114,7 +111,7 @@ class P2PFingerprintTest(BitcoinTestFramework):
# Longest chain is extended so stale is much older than chain tip # Longest chain is extended so stale is much older than chain tip
self.nodes[0].setmocktime(0) self.nodes[0].setmocktime(0)
tip = self.nodes[0].generate(nblocks=1)[0] tip = self.nodes[0].generatetoaddress(1, self.nodes[0].get_deterministic_priv_key().address)[0]
assert_equal(self.nodes[0].getblockcount(), 14) assert_equal(self.nodes[0].getblockcount(), 14)
# Send getdata & getheaders to refresh last received getheader message # Send getdata & getheaders to refresh last received getheader message

View file

@ -24,9 +24,6 @@ class InvalidBlockRequestTest(BitcoinTestFramework):
self.setup_clean_chain = True self.setup_clean_chain = True
self.extra_args = [["-whitelist=127.0.0.1"]] self.extra_args = [["-whitelist=127.0.0.1"]]
def skip_test_if_missing_module(self):
self.skip_if_no_wallet()
def run_test(self): def run_test(self):
# Add p2p connection to node0 # Add p2p connection to node0
node = self.nodes[0] # convenience reference to the node node = self.nodes[0] # convenience reference to the node
@ -48,7 +45,7 @@ class InvalidBlockRequestTest(BitcoinTestFramework):
node.p2p.send_blocks_and_test([block1], node, success=True) node.p2p.send_blocks_and_test([block1], node, success=True)
self.log.info("Mature the block.") self.log.info("Mature the block.")
node.generate(100) node.generatetoaddress(100, node.get_deterministic_priv_key().address)
best_block = node.getblock(node.getbestblockhash()) best_block = node.getblock(node.getbestblockhash())
tip = int(node.getbestblockhash(), 16) tip = int(node.getbestblockhash(), 16)

View file

@ -15,12 +15,9 @@ class InvalidLocatorTest(BitcoinTestFramework):
self.num_nodes = 1 self.num_nodes = 1
self.setup_clean_chain = False self.setup_clean_chain = False
def skip_test_if_missing_module(self):
self.skip_if_no_wallet()
def run_test(self): def run_test(self):
node = self.nodes[0] # convenience reference to the node node = self.nodes[0] # convenience reference to the node
node.generate(1) # Get node out of IBD node.generatetoaddress(1, node.get_deterministic_priv_key().address) # Get node out of IBD
self.log.info('Test max locator size') self.log.info('Test max locator size')
block_count = node.getblockcount() block_count = node.getblockcount()

View file

@ -26,9 +26,6 @@ class InvalidTxRequestTest(BitcoinTestFramework):
self.num_nodes = 1 self.num_nodes = 1
self.setup_clean_chain = True self.setup_clean_chain = True
def skip_test_if_missing_module(self):
self.skip_if_no_wallet()
def bootstrap_p2p(self, *, num_connections=1): def bootstrap_p2p(self, *, num_connections=1):
"""Add a P2P connection to the node. """Add a P2P connection to the node.
@ -64,7 +61,7 @@ class InvalidTxRequestTest(BitcoinTestFramework):
node.p2p.send_blocks_and_test([block], node, success=True) node.p2p.send_blocks_and_test([block], node, success=True)
self.log.info("Mature the block.") self.log.info("Mature the block.")
self.nodes[0].generate(100) self.nodes[0].generatetoaddress(100, self.nodes[0].get_deterministic_priv_key().address)
# b'\x64' is OP_NOTIF # b'\x64' is OP_NOTIF
# Transaction will be rejected with code 16 (REJECT_INVALID) # Transaction will be rejected with code 16 (REJECT_INVALID)

View file

@ -93,9 +93,6 @@ class P2PLeakTest(BitcoinTestFramework):
self.num_nodes = 1 self.num_nodes = 1
self.extra_args = [['-banscore=' + str(banscore)]] self.extra_args = [['-banscore=' + str(banscore)]]
def skip_test_if_missing_module(self):
self.skip_if_no_wallet()
def run_test(self): def run_test(self):
no_version_bannode = self.nodes[0].add_p2p_connection(CNodeNoVersionBan(), send_version=False, wait_for_verack=False) no_version_bannode = self.nodes[0].add_p2p_connection(CNodeNoVersionBan(), send_version=False, wait_for_verack=False)
no_version_idlenode = self.nodes[0].add_p2p_connection(CNodeNoVersionIdle(), send_version=False, wait_for_verack=False) no_version_idlenode = self.nodes[0].add_p2p_connection(CNodeNoVersionIdle(), send_version=False, wait_for_verack=False)
@ -106,7 +103,7 @@ class P2PLeakTest(BitcoinTestFramework):
wait_until(lambda: no_verack_idlenode.version_received, timeout=10, lock=mininode_lock) wait_until(lambda: no_verack_idlenode.version_received, timeout=10, lock=mininode_lock)
# Mine a block and make sure that it's not sent to the connected nodes # Mine a block and make sure that it's not sent to the connected nodes
self.nodes[0].generate(1) self.nodes[0].generatetoaddress(1, self.nodes[0].get_deterministic_priv_key().address)
#Give the node enough time to possibly leak out a message #Give the node enough time to possibly leak out a message
time.sleep(5) time.sleep(5)

View file

@ -34,9 +34,6 @@ class NodeNetworkLimitedTest(BitcoinTestFramework):
self.num_nodes = 3 self.num_nodes = 3
self.extra_args = [['-prune=550', '-addrmantest'], [], []] self.extra_args = [['-prune=550', '-addrmantest'], [], []]
def skip_test_if_missing_module(self):
self.skip_if_no_wallet()
def disconnect_all(self): def disconnect_all(self):
disconnect_nodes(self.nodes[0], 1) disconnect_nodes(self.nodes[0], 1)
disconnect_nodes(self.nodes[1], 0) disconnect_nodes(self.nodes[1], 0)
@ -62,7 +59,7 @@ class NodeNetworkLimitedTest(BitcoinTestFramework):
self.log.info("Mine enough blocks to reach the NODE_NETWORK_LIMITED range.") self.log.info("Mine enough blocks to reach the NODE_NETWORK_LIMITED range.")
connect_nodes_bi(self.nodes, 0, 1) connect_nodes_bi(self.nodes, 0, 1)
blocks = self.nodes[1].generate(292) blocks = self.nodes[1].generatetoaddress(292, self.nodes[1].get_deterministic_priv_key().address)
sync_blocks([self.nodes[0], self.nodes[1]]) sync_blocks([self.nodes[0], self.nodes[1]])
self.log.info("Make sure we can max retrieve block at tip-288.") self.log.info("Make sure we can max retrieve block at tip-288.")
@ -105,7 +102,7 @@ class NodeNetworkLimitedTest(BitcoinTestFramework):
self.disconnect_all() self.disconnect_all()
# mine 10 blocks on node 0 (pruned node) # mine 10 blocks on node 0 (pruned node)
self.nodes[0].generate(10) self.nodes[0].generatetoaddress(10, self.nodes[0].get_deterministic_priv_key().address)
# connect node1 (non pruned) with node0 (pruned) and check if the can sync # connect node1 (non pruned) with node0 (pruned) and check if the can sync
connect_nodes_bi(self.nodes, 0, 1) connect_nodes_bi(self.nodes, 0, 1)

View file

@ -208,15 +208,12 @@ class SendHeadersTest(BitcoinTestFramework):
self.setup_clean_chain = True self.setup_clean_chain = True
self.num_nodes = 2 self.num_nodes = 2
def skip_test_if_missing_module(self):
self.skip_if_no_wallet()
def mine_blocks(self, count): def mine_blocks(self, count):
"""Mine count blocks and return the new tip.""" """Mine count blocks and return the new tip."""
# Clear out block announcements from each p2p listener # Clear out block announcements from each p2p listener
[x.clear_block_announcements() for x in self.nodes[0].p2ps] [x.clear_block_announcements() for x in self.nodes[0].p2ps]
self.nodes[0].generate(count) self.nodes[0].generatetoaddress(count, self.nodes[0].get_deterministic_priv_key().address)
return int(self.nodes[0].getbestblockhash(), 16) return int(self.nodes[0].getbestblockhash(), 16)
def mine_reorg(self, length): def mine_reorg(self, length):
@ -226,7 +223,8 @@ class SendHeadersTest(BitcoinTestFramework):
to-be-reorged-out blocks are mined, so that we don't break later tests. to-be-reorged-out blocks are mined, so that we don't break later tests.
return the list of block hashes newly mined.""" return the list of block hashes newly mined."""
self.nodes[0].generate(length) # make sure all invalidated blocks are node0's # make sure all invalidated blocks are node0's
self.nodes[0].generatetoaddress(length, self.nodes[0].get_deterministic_priv_key().address)
sync_blocks(self.nodes, wait=0.1) sync_blocks(self.nodes, wait=0.1)
for x in self.nodes[0].p2ps: for x in self.nodes[0].p2ps:
x.wait_for_block_announcement(int(self.nodes[0].getbestblockhash(), 16)) x.wait_for_block_announcement(int(self.nodes[0].getbestblockhash(), 16))
@ -235,7 +233,7 @@ class SendHeadersTest(BitcoinTestFramework):
tip_height = self.nodes[1].getblockcount() tip_height = self.nodes[1].getblockcount()
hash_to_invalidate = self.nodes[1].getblockhash(tip_height - (length - 1)) hash_to_invalidate = self.nodes[1].getblockhash(tip_height - (length - 1))
self.nodes[1].invalidateblock(hash_to_invalidate) self.nodes[1].invalidateblock(hash_to_invalidate)
all_hashes = self.nodes[1].generate(length + 1) # Must be longer than the orig chain all_hashes = self.nodes[1].generatetoaddress(length + 1, self.nodes[1].get_deterministic_priv_key().address) # Must be longer than the orig chain
sync_blocks(self.nodes, wait=0.1) sync_blocks(self.nodes, wait=0.1)
return [int(x, 16) for x in all_hashes] return [int(x, 16) for x in all_hashes]
@ -254,7 +252,7 @@ class SendHeadersTest(BitcoinTestFramework):
self.test_nonnull_locators(test_node, inv_node) self.test_nonnull_locators(test_node, inv_node)
def test_null_locators(self, test_node, inv_node): def test_null_locators(self, test_node, inv_node):
tip = self.nodes[0].getblockheader(self.nodes[0].generate(1)[0]) tip = self.nodes[0].getblockheader(self.nodes[0].generatetoaddress(1, self.nodes[0].get_deterministic_priv_key().address)[0])
tip_hash = int(tip["hash"], 16) tip_hash = int(tip["hash"], 16)
inv_node.check_last_inv_announcement(inv=[tip_hash]) inv_node.check_last_inv_announcement(inv=[tip_hash])

View file

@ -66,9 +66,6 @@ class AcceptBlockTest(BitcoinTestFramework):
self.num_nodes = 2 self.num_nodes = 2
self.extra_args = [[], ["-minimumchainwork=0x10"]] self.extra_args = [[], ["-minimumchainwork=0x10"]]
def skip_test_if_missing_module(self):
self.skip_if_no_wallet()
def setup_network(self): def setup_network(self):
# Node0 will be used to test behavior of processing unrequested blocks # Node0 will be used to test behavior of processing unrequested blocks
# from peers which are not whitelisted, while Node1 will be used for # from peers which are not whitelisted, while Node1 will be used for
@ -85,8 +82,8 @@ class AcceptBlockTest(BitcoinTestFramework):
min_work_node = self.nodes[1].add_p2p_connection(P2PInterface()) min_work_node = self.nodes[1].add_p2p_connection(P2PInterface())
# 1. Have nodes mine a block (leave IBD) # 1. Have nodes mine a block (leave IBD)
[ n.generate(1) for n in self.nodes ] [n.generatetoaddress(1, n.get_deterministic_priv_key().address) for n in self.nodes]
tips = [ int("0x" + n.getbestblockhash(), 0) for n in self.nodes ] tips = [int("0x" + n.getbestblockhash(), 0) for n in self.nodes]
# 2. Send one block that builds on each tip. # 2. Send one block that builds on each tip.
# This should be accepted by node0 # This should be accepted by node0

View file

@ -48,9 +48,6 @@ class BlockchainTest(BitcoinTestFramework):
def set_test_params(self): def set_test_params(self):
self.num_nodes = 1 self.num_nodes = 1
def skip_test_if_missing_module(self):
self.skip_if_no_wallet()
def run_test(self): def run_test(self):
self.restart_node(0, extra_args=['-stopatheight=207', '-prune=1']) # Set extra args with pruning after rescan is complete self.restart_node(0, extra_args=['-stopatheight=207', '-prune=1']) # Set extra args with pruning after rescan is complete
@ -242,12 +239,12 @@ class BlockchainTest(BitcoinTestFramework):
def _test_stopatheight(self): def _test_stopatheight(self):
assert_equal(self.nodes[0].getblockcount(), 200) assert_equal(self.nodes[0].getblockcount(), 200)
self.nodes[0].generate(6) self.nodes[0].generatetoaddress(6, self.nodes[0].get_deterministic_priv_key().address)
assert_equal(self.nodes[0].getblockcount(), 206) assert_equal(self.nodes[0].getblockcount(), 206)
self.log.debug('Node should not stop at this height') self.log.debug('Node should not stop at this height')
assert_raises(subprocess.TimeoutExpired, lambda: self.nodes[0].process.wait(timeout=3)) assert_raises(subprocess.TimeoutExpired, lambda: self.nodes[0].process.wait(timeout=3))
try: try:
self.nodes[0].generate(1) self.nodes[0].generatetoaddress(1, self.nodes[0].get_deterministic_priv_key().address)
except (ConnectionError, http.client.BadStatusLine): except (ConnectionError, http.client.BadStatusLine):
pass # The node already shut down before response pass # The node already shut down before response
self.log.debug('Node should stop at this height...') self.log.debug('Node should stop at this height...')

View file

@ -17,9 +17,6 @@ class GetChainTipsTest (BitcoinTestFramework):
def set_test_params(self): def set_test_params(self):
self.num_nodes = 4 self.num_nodes = 4
def skip_test_if_missing_module(self):
self.skip_if_no_wallet()
def run_test(self): def run_test(self):
tips = self.nodes[0].getchaintips() tips = self.nodes[0].getchaintips()
assert_equal(len(tips), 1) assert_equal(len(tips), 1)
@ -29,8 +26,8 @@ class GetChainTipsTest (BitcoinTestFramework):
# Split the network and build two chains of different lengths. # Split the network and build two chains of different lengths.
self.split_network() self.split_network()
self.nodes[0].generate(10) self.nodes[0].generatetoaddress(10, self.nodes[0].get_deterministic_priv_key().address)
self.nodes[2].generate(20) self.nodes[2].generatetoaddress(20, self.nodes[2].get_deterministic_priv_key().address)
self.sync_all([self.nodes[:2], self.nodes[2:]]) self.sync_all([self.nodes[:2], self.nodes[2:]])
tips = self.nodes[1].getchaintips () tips = self.nodes[1].getchaintips ()

View file

@ -14,21 +14,18 @@ class InvalidateTest(BitcoinTestFramework):
self.setup_clean_chain = True self.setup_clean_chain = True
self.num_nodes = 3 self.num_nodes = 3
def skip_test_if_missing_module(self):
self.skip_if_no_wallet()
def setup_network(self): def setup_network(self):
self.setup_nodes() self.setup_nodes()
def run_test(self): def run_test(self):
self.log.info("Make sure we repopulate setBlockIndexCandidates after InvalidateBlock:") self.log.info("Make sure we repopulate setBlockIndexCandidates after InvalidateBlock:")
self.log.info("Mine 4 blocks on Node 0") self.log.info("Mine 4 blocks on Node 0")
self.nodes[0].generate(4) self.nodes[0].generatetoaddress(4, self.nodes[0].get_deterministic_priv_key().address)
assert(self.nodes[0].getblockcount() == 4) assert(self.nodes[0].getblockcount() == 4)
besthash = self.nodes[0].getbestblockhash() besthash = self.nodes[0].getbestblockhash()
self.log.info("Mine competing 6 blocks on Node 1") self.log.info("Mine competing 6 blocks on Node 1")
self.nodes[1].generate(6) self.nodes[1].generatetoaddress(6, self.nodes[1].get_deterministic_priv_key().address)
assert(self.nodes[1].getblockcount() == 6) assert(self.nodes[1].getblockcount() == 6)
self.log.info("Connect nodes to force a reorg") self.log.info("Connect nodes to force a reorg")
@ -56,7 +53,7 @@ class InvalidateTest(BitcoinTestFramework):
self.nodes[2].invalidateblock(self.nodes[2].getblockhash(3)) self.nodes[2].invalidateblock(self.nodes[2].getblockhash(3))
assert(self.nodes[2].getblockcount() == 2) assert(self.nodes[2].getblockcount() == 2)
self.log.info("..and then mine a block") self.log.info("..and then mine a block")
self.nodes[2].generate(1) self.nodes[2].generatetoaddress(1, self.nodes[2].get_deterministic_priv_key().address)
self.log.info("Verify all nodes are at the right height") self.log.info("Verify all nodes are at the right height")
time.sleep(5) time.sleep(5)
assert_equal(self.nodes[2].getblockcount(), 3) assert_equal(self.nodes[2].getblockcount(), 3)

View file

@ -38,26 +38,24 @@ class PreciousTest(BitcoinTestFramework):
self.setup_clean_chain = True self.setup_clean_chain = True
self.num_nodes = 3 self.num_nodes = 3
def skip_test_if_missing_module(self):
self.skip_if_no_wallet()
def setup_network(self): def setup_network(self):
self.setup_nodes() self.setup_nodes()
def run_test(self): def run_test(self):
self.log.info("Ensure submitblock can in principle reorg to a competing chain") self.log.info("Ensure submitblock can in principle reorg to a competing chain")
self.nodes[0].generate(1) gen_address = lambda i: self.nodes[i].get_deterministic_priv_key().address # A non-wallet address to mine to
self.nodes[0].generatetoaddress(1, gen_address(0))
assert_equal(self.nodes[0].getblockcount(), 1) assert_equal(self.nodes[0].getblockcount(), 1)
hashZ = self.nodes[1].generate(2)[-1] hashZ = self.nodes[1].generatetoaddress(2, gen_address(1))[-1]
assert_equal(self.nodes[1].getblockcount(), 2) assert_equal(self.nodes[1].getblockcount(), 2)
node_sync_via_rpc(self.nodes[0:3]) node_sync_via_rpc(self.nodes[0:3])
assert_equal(self.nodes[0].getbestblockhash(), hashZ) assert_equal(self.nodes[0].getbestblockhash(), hashZ)
self.log.info("Mine blocks A-B-C on Node 0") self.log.info("Mine blocks A-B-C on Node 0")
hashC = self.nodes[0].generate(3)[-1] hashC = self.nodes[0].generatetoaddress(3, gen_address(0))[-1]
assert_equal(self.nodes[0].getblockcount(), 5) assert_equal(self.nodes[0].getblockcount(), 5)
self.log.info("Mine competing blocks E-F-G on Node 1") self.log.info("Mine competing blocks E-F-G on Node 1")
hashG = self.nodes[1].generate(3)[-1] hashG = self.nodes[1].generatetoaddress(3, gen_address(1))[-1]
assert_equal(self.nodes[1].getblockcount(), 5) assert_equal(self.nodes[1].getblockcount(), 5)
assert(hashC != hashG) assert(hashC != hashG)
self.log.info("Connect nodes and check no reorg occurs") self.log.info("Connect nodes and check no reorg occurs")
@ -86,7 +84,7 @@ class PreciousTest(BitcoinTestFramework):
self.nodes[1].preciousblock(hashC) self.nodes[1].preciousblock(hashC)
assert_equal(self.nodes[1].getbestblockhash(), hashC) assert_equal(self.nodes[1].getbestblockhash(), hashC)
self.log.info("Mine another block (E-F-G-)H on Node 0 and reorg Node 1") self.log.info("Mine another block (E-F-G-)H on Node 0 and reorg Node 1")
self.nodes[0].generate(1) self.nodes[0].generatetoaddress(1, gen_address(0))
assert_equal(self.nodes[0].getblockcount(), 6) assert_equal(self.nodes[0].getblockcount(), 6)
sync_blocks(self.nodes[0:2]) sync_blocks(self.nodes[0:2])
hashH = self.nodes[0].getbestblockhash() hashH = self.nodes[0].getbestblockhash()
@ -95,7 +93,7 @@ class PreciousTest(BitcoinTestFramework):
self.nodes[1].preciousblock(hashC) self.nodes[1].preciousblock(hashC)
assert_equal(self.nodes[1].getbestblockhash(), hashH) assert_equal(self.nodes[1].getbestblockhash(), hashH)
self.log.info("Mine competing blocks I-J-K-L on Node 2") self.log.info("Mine competing blocks I-J-K-L on Node 2")
self.nodes[2].generate(4) self.nodes[2].generatetoaddress(4, gen_address(2))
assert_equal(self.nodes[2].getblockcount(), 6) assert_equal(self.nodes[2].getblockcount(), 6)
hashL = self.nodes[2].getbestblockhash() hashL = self.nodes[2].getbestblockhash()
self.log.info("Connect nodes and check no reorg occurs") self.log.info("Connect nodes and check no reorg occurs")

View file

@ -271,7 +271,7 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
assert str(e).startswith('Method not found') assert str(e).startswith('Method not found')
continue continue
n.importprivkey(n.get_deterministic_priv_key()[1]) n.importprivkey(n.get_deterministic_priv_key().key)
def run_test(self): def run_test(self):
"""Tests must override this method to define test logic""" """Tests must override this method to define test logic"""
@ -465,7 +465,7 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
for peer in range(4): for peer in range(4):
for j in range(25): for j in range(25):
set_node_times(self.nodes, block_time) set_node_times(self.nodes, block_time)
self.nodes[peer].generatetoaddress(1, self.nodes[peer].get_deterministic_priv_key()[0]) self.nodes[peer].generatetoaddress(1, self.nodes[peer].get_deterministic_priv_key().address)
block_time += 10 * 60 block_time += 10 * 60
# Must sync before next peer starts generating blocks # Must sync before next peer starts generating blocks
sync_blocks(self.nodes) sync_blocks(self.nodes)

View file

@ -17,6 +17,7 @@ import subprocess
import tempfile import tempfile
import time import time
import urllib.parse import urllib.parse
import collections
from .authproxy import JSONRPCException from .authproxy import JSONRPCException
from .util import ( from .util import (
@ -99,17 +100,18 @@ class TestNode():
def get_deterministic_priv_key(self): def get_deterministic_priv_key(self):
"""Return a deterministic priv key in base58, that only depends on the node's index""" """Return a deterministic priv key in base58, that only depends on the node's index"""
AddressKeyPair = collections.namedtuple('AddressKeyPair', ['address', 'key'])
PRIV_KEYS = [ PRIV_KEYS = [
# address , privkey # address , privkey
('mjTkW3DjgyZck4KbiRusZsqTgaYTxdSz6z', 'cVpF924EspNh8KjYsfhgY96mmxvT6DgdWiTYMtMjuM74hJaU5psW'), AddressKeyPair('mjTkW3DjgyZck4KbiRusZsqTgaYTxdSz6z', 'cVpF924EspNh8KjYsfhgY96mmxvT6DgdWiTYMtMjuM74hJaU5psW'),
('msX6jQXvxiNhx3Q62PKeLPrhrqZQdSimTg', 'cUxsWyKyZ9MAQTaAhUQWJmBbSvHMwSmuv59KgxQV7oZQU3PXN3KE'), AddressKeyPair('msX6jQXvxiNhx3Q62PKeLPrhrqZQdSimTg', 'cUxsWyKyZ9MAQTaAhUQWJmBbSvHMwSmuv59KgxQV7oZQU3PXN3KE'),
('mnonCMyH9TmAsSj3M59DsbH8H63U3RKoFP', 'cTrh7dkEAeJd6b3MRX9bZK8eRmNqVCMH3LSUkE3dSFDyzjU38QxK'), AddressKeyPair('mnonCMyH9TmAsSj3M59DsbH8H63U3RKoFP', 'cTrh7dkEAeJd6b3MRX9bZK8eRmNqVCMH3LSUkE3dSFDyzjU38QxK'),
('mqJupas8Dt2uestQDvV2NH3RU8uZh2dqQR', 'cVuKKa7gbehEQvVq717hYcbE9Dqmq7KEBKqWgWrYBa2CKKrhtRim'), AddressKeyPair('mqJupas8Dt2uestQDvV2NH3RU8uZh2dqQR', 'cVuKKa7gbehEQvVq717hYcbE9Dqmq7KEBKqWgWrYBa2CKKrhtRim'),
('msYac7Rvd5ywm6pEmkjyxhbCDKqWsVeYws', 'cQDCBuKcjanpXDpCqacNSjYfxeQj8G6CAtH1Dsk3cXyqLNC4RPuh'), AddressKeyPair('msYac7Rvd5ywm6pEmkjyxhbCDKqWsVeYws', 'cQDCBuKcjanpXDpCqacNSjYfxeQj8G6CAtH1Dsk3cXyqLNC4RPuh'),
('n2rnuUnwLgXqf9kk2kjvVm8R5BZK1yxQBi', 'cQakmfPSLSqKHyMFGwAqKHgWUiofJCagVGhiB4KCainaeCSxeyYq'), AddressKeyPair('n2rnuUnwLgXqf9kk2kjvVm8R5BZK1yxQBi', 'cQakmfPSLSqKHyMFGwAqKHgWUiofJCagVGhiB4KCainaeCSxeyYq'),
('myzuPxRwsf3vvGzEuzPfK9Nf2RfwauwYe6', 'cQMpDLJwA8DBe9NcQbdoSb1BhmFxVjWD5gRyrLZCtpuF9Zi3a9RK'), AddressKeyPair('myzuPxRwsf3vvGzEuzPfK9Nf2RfwauwYe6', 'cQMpDLJwA8DBe9NcQbdoSb1BhmFxVjWD5gRyrLZCtpuF9Zi3a9RK'),
('mumwTaMtbxEPUswmLBBN3vM9oGRtGBrys8', 'cSXmRKXVcoouhNNVpcNKFfxsTsToY5pvB9DVsFksF1ENunTzRKsy'), AddressKeyPair('mumwTaMtbxEPUswmLBBN3vM9oGRtGBrys8', 'cSXmRKXVcoouhNNVpcNKFfxsTsToY5pvB9DVsFksF1ENunTzRKsy'),
('mpV7aGShMkJCZgbW7F6iZgrvuPHjZjH9qg', 'cSoXt6tm3pqy43UMabY6eUTmR3eSUYFtB2iNQDGgb3VUnRsQys2k'), AddressKeyPair('mpV7aGShMkJCZgbW7F6iZgrvuPHjZjH9qg', 'cSoXt6tm3pqy43UMabY6eUTmR3eSUYFtB2iNQDGgb3VUnRsQys2k'),
] ]
return PRIV_KEYS[self.index] return PRIV_KEYS[self.index]