Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qa: generate --> generatetoaddress change to allow tests run without wallet #14236

Merged
merged 1 commit into from Sep 17, 2018
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -85,6 +85,8 @@ def set_test_params(self):

# 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):
self.skip_if_no_wallet()

@@ -75,9 +75,6 @@ def set_test_params(self):
self.setup_clean_chain = True
self.extra_args = [[]]

def skip_test_if_missing_module(self):
self.skip_if_no_wallet()

def run_test(self):
node = self.nodes[0] # convenience reference to the node

@@ -16,9 +16,6 @@ def set_test_params(self):
self.setup_clean_chain = True
self.num_nodes = 1

def skip_test_if_missing_module(self):
self.skip_if_no_wallet()

def run_test(self):
self.stop_node(0)
shutil.rmtree(self.nodes[0].datadir)
@@ -30,7 +27,7 @@ def run_test(self):
self.log.info("Starting with existing blocksdir ...")
self.start_node(0, ["-blocksdir=" + blocksdir_path])
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.isdir(os.path.join(self.nodes[0].datadir, "regtest", "blocks", "index"))

@@ -15,9 +15,6 @@ def set_test_params(self):
self.num_nodes = 1
self.setup_clean_chain = True

def skip_test_if_missing_module(self):
self.skip_if_no_wallet()

def relative_log_path(self, name):
return os.path.join(self.nodes[0].datadir, "regtest", name)

@@ -31,9 +31,6 @@ def set_test_params(self):
self.extra_args = [[], ["-minimumchainwork=0x65"], ["-minimumchainwork=0x65"]]
self.node_min_work = [0, 101, 101]

def skip_test_if_missing_module(self):
self.skip_if_no_wallet()

def setup_network(self):
# This test relies on the chain setup being:
# node0 <- node1 <- node2
@@ -54,7 +51,8 @@ def run_test(self):

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)
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'])

@@ -75,7 +73,7 @@ def run_test(self):
assert_equal(self.nodes[2].getblockcount(), starting_blockcount)

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")

@@ -18,11 +18,8 @@ def set_test_params(self):
self.setup_clean_chain = True
self.num_nodes = 1

def skip_test_if_missing_module(self):
self.skip_if_no_wallet()

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()
self.stop_nodes()
extra_args = [["-reindex-chainstate" if justchainstate else "-reindex"]]
@@ -31,9 +31,6 @@ def set_test_params(self):
self.setup_clean_chain = True
self.num_nodes = 1

def skip_test_if_missing_module(self):
self.skip_if_no_wallet()

def setup_network(self):
self.alert_filename = os.path.join(self.options.tmpdir, "alert.txt")
# Open and close to create zero-length file
@@ -68,13 +65,14 @@ def run_test(self):
node = self.nodes[0]
node.add_p2p_connection(P2PInterface())

node_deterministic_address = node.get_deterministic_priv_key().address
# 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.")
# 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)
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()
assert(not VB_PATTERN.match(node.getmininginfo()["warnings"]))
@@ -83,7 +81,7 @@ def run_test(self):
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
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.
assert(WARN_UNKNOWN_RULES_MINED in node.getmininginfo()["warnings"])
@@ -92,16 +90,16 @@ def run_test(self):
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
# 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.
self.restart_node(0)

# 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)
# 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
assert(WARN_UNKNOWN_RULES_ACTIVE in node.getmininginfo()["warnings"])
assert(WARN_UNKNOWN_RULES_ACTIVE in node.getnetworkinfo()["warnings"])
@@ -38,9 +38,6 @@ def set_test_params(self):
self.num_nodes = 2
self.setup_clean_chain = False

def skip_test_if_missing_module(self):
self.skip_if_no_wallet()

def run_test(self):
node = self.nodes[0]

@@ -61,7 +58,7 @@ def assert_submitblock(block, result_str_1, result_str_2=None):
assert_equal(mining_info['pooledtx'], 0)

# Mine a block to leave initial block download
node.generate(1)
node.generatetoaddress(1, node.get_deterministic_priv_key().address)
tmpl = node.getblocktemplate()
self.log.info("getblocktemplate: Test capability advertised")
assert 'proposal' in tmpl['capabilities']
@@ -212,7 +209,7 @@ def chain_tip(b_hash, *, status='headers-only', branchlen=1):
assert chain_tip(block.hash, status='active', branchlen=0) in node.getchaintips()

# 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, 'bad-prevblk', lambda: node.submitheader(hexdata=b2x(CBlockHeader(bad_block2).serialize())))
node.submitheader(hexdata=b2x(CBlockHeader(block).serialize()))
@@ -30,9 +30,6 @@ def set_test_params(self):
self.setup_clean_chain = True
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
def build_chain(self, nblocks, prev_hash, prev_height, prev_median_time):
blocks = []
@@ -83,7 +80,7 @@ def run_test(self):
self.nodes[0].setmocktime(int(time.time()) - 60 * 24 * 60 * 60)

# 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
height = len(block_hashes) - 2
@@ -114,7 +111,7 @@ def run_test(self):

# Longest chain is extended so stale is much older than chain tip
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)

# Send getdata & getheaders to refresh last received getheader message
@@ -24,9 +24,6 @@ def set_test_params(self):
self.setup_clean_chain = True
self.extra_args = [["-whitelist=127.0.0.1"]]

def skip_test_if_missing_module(self):
self.skip_if_no_wallet()

def run_test(self):
# Add p2p connection to node0
node = self.nodes[0] # convenience reference to the node
@@ -48,7 +45,7 @@ def run_test(self):
node.p2p.send_blocks_and_test([block1], node, success=True)

self.log.info("Mature the block.")
node.generate(100)
node.generatetoaddress(100, node.get_deterministic_priv_key().address)

best_block = node.getblock(node.getbestblockhash())
tip = int(node.getbestblockhash(), 16)
@@ -15,12 +15,9 @@ def set_test_params(self):
self.num_nodes = 1
self.setup_clean_chain = False

def skip_test_if_missing_module(self):
self.skip_if_no_wallet()

def run_test(self):
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')
block_count = node.getblockcount()
@@ -26,9 +26,6 @@ def set_test_params(self):
self.num_nodes = 1
self.setup_clean_chain = True

def skip_test_if_missing_module(self):
self.skip_if_no_wallet()

def bootstrap_p2p(self, *, num_connections=1):
"""Add a P2P connection to the node.
@@ -64,7 +61,7 @@ def run_test(self):
node.p2p.send_blocks_and_test([block], node, success=True)

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
# Transaction will be rejected with code 16 (REJECT_INVALID)
@@ -93,9 +93,6 @@ def set_test_params(self):
self.num_nodes = 1
self.extra_args = [['-banscore=' + str(banscore)]]

def skip_test_if_missing_module(self):
self.skip_if_no_wallet()

def run_test(self):
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)
@@ -106,7 +103,7 @@ def run_test(self):
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
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
time.sleep(5)
@@ -34,9 +34,6 @@ def set_test_params(self):
self.num_nodes = 3
self.extra_args = [['-prune=550', '-addrmantest'], [], []]

def skip_test_if_missing_module(self):
self.skip_if_no_wallet()

def disconnect_all(self):
disconnect_nodes(self.nodes[0], 1)
disconnect_nodes(self.nodes[1], 0)
@@ -62,7 +59,7 @@ def run_test(self):

self.log.info("Mine enough blocks to reach the NODE_NETWORK_LIMITED range.")
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]])

self.log.info("Make sure we can max retrieve block at tip-288.")
@@ -105,7 +102,7 @@ def run_test(self):
self.disconnect_all()

# 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_nodes_bi(self.nodes, 0, 1)
@@ -208,15 +208,12 @@ def set_test_params(self):
self.setup_clean_chain = True
self.num_nodes = 2

def skip_test_if_missing_module(self):
self.skip_if_no_wallet()

def mine_blocks(self, count):
"""Mine count blocks and return the new tip."""

# Clear out block announcements from each p2p listener
[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)

def mine_reorg(self, length):
@@ -226,7 +223,8 @@ def mine_reorg(self, length):
to-be-reorged-out blocks are mined, so that we don't break later tests.
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)
for x in self.nodes[0].p2ps:
x.wait_for_block_announcement(int(self.nodes[0].getbestblockhash(), 16))
@@ -235,7 +233,7 @@ def mine_reorg(self, length):
tip_height = self.nodes[1].getblockcount()
hash_to_invalidate = self.nodes[1].getblockhash(tip_height - (length - 1))
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)
return [int(x, 16) for x in all_hashes]

@@ -254,7 +252,7 @@ def run_test(self):
self.test_nonnull_locators(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)

inv_node.check_last_inv_announcement(inv=[tip_hash])
@@ -66,9 +66,6 @@ def set_test_params(self):
self.num_nodes = 2
self.extra_args = [[], ["-minimumchainwork=0x10"]]

def skip_test_if_missing_module(self):
self.skip_if_no_wallet()

def setup_network(self):
# Node0 will be used to test behavior of processing unrequested blocks
# from peers which are not whitelisted, while Node1 will be used for
@@ -85,8 +82,8 @@ def run_test(self):
min_work_node = self.nodes[1].add_p2p_connection(P2PInterface())

# 1. Have nodes mine a block (leave IBD)
[ n.generate(1) for n in self.nodes ]
tips = [ int("0x" + n.getbestblockhash(), 0) 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]

# 2. Send one block that builds on each tip.
# This should be accepted by node0
@@ -48,9 +48,6 @@ class BlockchainTest(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 1

def skip_test_if_missing_module(self):
self.skip_if_no_wallet()

def run_test(self):
self.restart_node(0, extra_args=['-stopatheight=207', '-prune=1']) # Set extra args with pruning after rescan is complete

@@ -242,12 +239,12 @@ def _test_getnetworkhashps(self):

def _test_stopatheight(self):
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)
self.log.debug('Node should not stop at this height')
assert_raises(subprocess.TimeoutExpired, lambda: self.nodes[0].process.wait(timeout=3))
try:
self.nodes[0].generate(1)
self.nodes[0].generatetoaddress(1, self.nodes[0].get_deterministic_priv_key().address)
except (ConnectionError, http.client.BadStatusLine):
pass # The node already shut down before response
self.log.debug('Node should stop at this height...')
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.