mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 12:02:48 +01:00
Merge #14236: qa: generate --> generatetoaddress change to allow tests run without wallet
0ca4c8b3c6 Changed functional tests which do not require wallets to run without (sanket1729) Pull request description: Addresses #14216 . Changed Changed `get_deterministic_priv_key()` to return named tuple`(address, key)` I have tried to be exhaustive as possible in maximum coverage for non-wallet mode without affecting any coverage for wallet mode. However, I could not check the tests in wallet mode because of timeout issues. Hopefully, travis job checks those. Tests `feature_block.py`, `feature_logging.py` and `feature_reindex.py` were skipping despite having no direct dependency on any wallet functions. So, I have also disabled the `skip_test_no_wallet()` for those files too. Tree-SHA512: 8f84bd8400a732d4266c7518d5cbcf1eb761f623a64a74849e0470142c8ef22cb75364474ddae75d9213c3d16659a52917b5ed979a313695da6abd16c4fd7445
This commit is contained in:
parent
fe03a6f17e
commit
0bb0d89cb3
@ -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()
|
||||
|
||||
# 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()
|
||||
|
||||
|
@ -79,9 +79,6 @@ class FullBlockTest(BitcoinTestFramework):
|
||||
self.add_nodes(self.num_nodes, self.extra_args)
|
||||
self.start_nodes()
|
||||
|
||||
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 @@ class BlocksdirTest(BitcoinTestFramework):
|
||||
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)
|
||||
assert os.path.isdir(os.path.join(self.nodes[0].datadir, "regtest", "blocks"))
|
||||
@ -33,7 +30,7 @@ class BlocksdirTest(BitcoinTestFramework):
|
||||
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, self.chain, "blocks", "blk00000.dat"))
|
||||
assert os.path.isdir(os.path.join(self.nodes[0].datadir, self.chain, "blocks", "index"))
|
||||
|
||||
|
@ -15,9 +15,6 @@ class LoggingTest(BitcoinTestFramework):
|
||||
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, self.chain, name)
|
||||
|
||||
|
@ -31,9 +31,6 @@ class MinimumChainWorkTest(BitcoinTestFramework):
|
||||
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):
|
||||
# Force CanDirectFetch to return false (otherwise nMinimumChainWork is ignored)
|
||||
self.bump_mocktime(21 * 2.6 * 60)
|
||||
@ -56,7 +53,8 @@ class MinimumChainWorkTest(BitcoinTestFramework):
|
||||
|
||||
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'])
|
||||
|
||||
@ -77,7 +75,7 @@ class MinimumChainWorkTest(BitcoinTestFramework):
|
||||
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 @@ class ReindexTest(BitcoinTestFramework):
|
||||
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"]]
|
||||
|
@ -30,9 +30,6 @@ class VersionBitsWarningTest(BitcoinTestFramework):
|
||||
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
|
||||
@ -67,13 +64,14 @@ class VersionBitsWarningTest(BitcoinTestFramework):
|
||||
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"])
|
||||
@ -81,21 +79,21 @@ class VersionBitsWarningTest(BitcoinTestFramework):
|
||||
|
||||
# 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)
|
||||
|
||||
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 dashd 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"]
|
||||
|
@ -39,9 +39,6 @@ class MiningTest(BitcoinTestFramework):
|
||||
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]
|
||||
|
||||
@ -62,7 +59,7 @@ class MiningTest(BitcoinTestFramework):
|
||||
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']
|
||||
@ -231,7 +228,7 @@ class MiningTest(BitcoinTestFramework):
|
||||
assert chain_tip(block.hash, status='active', branchlen=0) in filter_tip_keys(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=CBlockHeader(bad_block_time).serialize().hex()))
|
||||
assert_raises_rpc_error(-25, 'bad-prevblk', lambda: node.submitheader(hexdata=CBlockHeader(bad_block2).serialize().hex()))
|
||||
node.submitheader(hexdata=CBlockHeader(block).serialize().hex())
|
||||
|
@ -30,9 +30,6 @@ class P2PFingerprintTest(BitcoinTestFramework):
|
||||
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 @@ class P2PFingerprintTest(BitcoinTestFramework):
|
||||
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 @@ class P2PFingerprintTest(BitcoinTestFramework):
|
||||
|
||||
# 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
|
||||
|
@ -25,9 +25,6 @@ class InvalidBlockRequestTest(BitcoinTestFramework):
|
||||
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
|
||||
@ -49,7 +46,7 @@ class InvalidBlockRequestTest(BitcoinTestFramework):
|
||||
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 @@ class InvalidLocatorTest(BitcoinTestFramework):
|
||||
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()
|
||||
|
@ -28,9 +28,6 @@ class InvalidTxRequestTest(BitcoinTestFramework):
|
||||
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.
|
||||
|
||||
@ -75,7 +72,7 @@ class InvalidTxRequestTest(BitcoinTestFramework):
|
||||
node.p2p.send_blocks_and_test([block1, block2], 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)
|
||||
|
@ -110,9 +110,6 @@ class P2PLeakTest(BitcoinTestFramework):
|
||||
self.disable_mocktime()
|
||||
self.setup_nodes()
|
||||
|
||||
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)
|
||||
@ -123,7 +120,7 @@ class P2PLeakTest(BitcoinTestFramework):
|
||||
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 @@ class NodeNetworkLimitedTest(BitcoinTestFramework):
|
||||
self.num_nodes = 3
|
||||
self.extra_args = [['-prune=550', '-txindex=0', '-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 @@ class NodeNetworkLimitedTest(BitcoinTestFramework):
|
||||
|
||||
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 @@ class NodeNetworkLimitedTest(BitcoinTestFramework):
|
||||
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)
|
||||
|
@ -206,15 +206,12 @@ class SendHeadersTest(BitcoinTestFramework):
|
||||
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):
|
||||
@ -224,7 +221,8 @@ class SendHeadersTest(BitcoinTestFramework):
|
||||
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)
|
||||
self.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))
|
||||
@ -233,7 +231,7 @@ class SendHeadersTest(BitcoinTestFramework):
|
||||
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
|
||||
self.sync_blocks(self.nodes, wait=0.1)
|
||||
return [int(x, 16) for x in all_hashes]
|
||||
|
||||
@ -252,7 +250,7 @@ class SendHeadersTest(BitcoinTestFramework):
|
||||
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])
|
||||
|
@ -65,9 +65,6 @@ class AcceptBlockTest(BitcoinTestFramework):
|
||||
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
|
||||
@ -84,8 +81,8 @@ class AcceptBlockTest(BitcoinTestFramework):
|
||||
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
|
||||
|
@ -50,9 +50,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', '-txindex=0']) # Set extra args with pruning after rescan is complete
|
||||
|
||||
@ -254,12 +251,12 @@ class BlockchainTest(BitcoinTestFramework):
|
||||
|
||||
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...')
|
||||
|
@ -17,9 +17,6 @@ class GetChainTipsTest (BitcoinTestFramework):
|
||||
def set_test_params(self):
|
||||
self.num_nodes = 4
|
||||
|
||||
def skip_test_if_missing_module(self):
|
||||
self.skip_if_no_wallet()
|
||||
|
||||
def run_test(self):
|
||||
tips = self.nodes[0].getchaintips()
|
||||
assert_equal(len(tips), 1)
|
||||
@ -29,8 +26,8 @@ class GetChainTipsTest (BitcoinTestFramework):
|
||||
|
||||
# Split the network and build two chains of different lengths.
|
||||
self.split_network()
|
||||
self.nodes[0].generate(10)
|
||||
self.nodes[2].generate(20)
|
||||
self.nodes[0].generatetoaddress(10, self.nodes[0].get_deterministic_priv_key().address)
|
||||
self.nodes[2].generatetoaddress(20, self.nodes[2].get_deterministic_priv_key().address)
|
||||
self.sync_all(self.nodes[:2])
|
||||
self.sync_all(self.nodes[2:])
|
||||
|
||||
|
@ -14,21 +14,18 @@ class InvalidateTest(BitcoinTestFramework):
|
||||
self.setup_clean_chain = True
|
||||
self.num_nodes = 3
|
||||
|
||||
def skip_test_if_missing_module(self):
|
||||
self.skip_if_no_wallet()
|
||||
|
||||
def setup_network(self):
|
||||
self.setup_nodes()
|
||||
|
||||
def run_test(self):
|
||||
self.log.info("Make sure we repopulate setBlockIndexCandidates after InvalidateBlock:")
|
||||
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
|
||||
besthash = self.nodes[0].getbestblockhash()
|
||||
|
||||
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
|
||||
|
||||
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))
|
||||
assert self.nodes[2].getblockcount() == 2
|
||||
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")
|
||||
time.sleep(5)
|
||||
assert_equal(self.nodes[2].getblockcount(), 3)
|
||||
|
@ -38,26 +38,24 @@ class PreciousTest(BitcoinTestFramework):
|
||||
self.setup_clean_chain = True
|
||||
self.num_nodes = 3
|
||||
|
||||
def skip_test_if_missing_module(self):
|
||||
self.skip_if_no_wallet()
|
||||
|
||||
def setup_network(self):
|
||||
self.setup_nodes()
|
||||
|
||||
def run_test(self):
|
||||
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)
|
||||
hashZ = self.nodes[1].generate(2)[-1]
|
||||
hashZ = self.nodes[1].generatetoaddress(2, gen_address(1))[-1]
|
||||
assert_equal(self.nodes[1].getblockcount(), 2)
|
||||
node_sync_via_rpc(self.nodes[0:3])
|
||||
assert_equal(self.nodes[0].getbestblockhash(), hashZ)
|
||||
|
||||
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)
|
||||
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 hashC != hashG
|
||||
self.log.info("Connect nodes and check no reorg occurs")
|
||||
@ -86,7 +84,7 @@ class PreciousTest(BitcoinTestFramework):
|
||||
self.nodes[1].preciousblock(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.nodes[0].generate(1)
|
||||
self.nodes[0].generatetoaddress(1, gen_address(0))
|
||||
assert_equal(self.nodes[0].getblockcount(), 6)
|
||||
self.sync_blocks(self.nodes[0:2])
|
||||
hashH = self.nodes[0].getbestblockhash()
|
||||
@ -95,7 +93,7 @@ class PreciousTest(BitcoinTestFramework):
|
||||
self.nodes[1].preciousblock(hashC)
|
||||
assert_equal(self.nodes[1].getbestblockhash(), hashH)
|
||||
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)
|
||||
hashL = self.nodes[2].getbestblockhash()
|
||||
self.log.info("Connect nodes and check no reorg occurs")
|
||||
|
@ -340,7 +340,7 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
|
||||
assert str(e).startswith('Method not found')
|
||||
continue
|
||||
|
||||
n.importprivkey(n.get_deterministic_priv_key()[1])
|
||||
n.importprivkey(n.get_deterministic_priv_key().key)
|
||||
|
||||
def run_test(self):
|
||||
"""Tests must override this method to define test logic"""
|
||||
@ -560,7 +560,7 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
|
||||
for peer in range(4):
|
||||
for j in range(25):
|
||||
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 += 156
|
||||
# Must sync before next peer starts generating blocks
|
||||
self.sync_blocks()
|
||||
|
@ -19,6 +19,7 @@ import time
|
||||
import urllib.parse
|
||||
import shlex
|
||||
import sys
|
||||
import collections
|
||||
|
||||
from .authproxy import JSONRPCException
|
||||
from .util import (
|
||||
@ -117,17 +118,18 @@ class TestNode():
|
||||
|
||||
def get_deterministic_priv_key(self):
|
||||
"""Return a deterministic priv key in base58, that only depends on the node's index"""
|
||||
AddressKeyPair = collections.namedtuple('AddressKeyPair', ['address', 'key'])
|
||||
PRIV_KEYS = [
|
||||
# address , privkey
|
||||
('yYdShjQSptFKitYLksFEUSwHe4hnbar5rf', 'cMfbiEsnG5b8Gwm6vEgfWvZLuXZNC4zsN2y7Es3An9xHRWRjmwgR'),
|
||||
('yfTFJgvq65UZsb9RBbpdYAAzsJoCGXqH2w', 'cStuFACUD1N6JjKQxNLUQ443qJUtSzLitKKEkA8x6utxTPZTLUtA'),
|
||||
('yU3w4VDjKhHiZpWszkUZVnFTS56AfgdfPV', 'cQb5yh2sTiG7dsxxbXHhWSBLMByYT7jY49A1kC7zKhgL9WNHysWW'),
|
||||
('yYhzix2R5LiYnDixsUnF8XwBYGYpyeTgB4', 'cW9Gu6uU4KoZJQcdyUvjULNRg4C8srPJw1adhgdTZMr9YQdKHtcn'),
|
||||
('yiQ3qLx5L1BW9XA6JAG7hC8UQDktcBCeYG', 'cSq7gHVC1QPsswyX2pE5C38UnWZXfCLr7XnkjnDwuZ68NkWp183T'),
|
||||
('yUL8h8mR7aNDRsU5zhcDbpp6YtA6ieUtK2', 'cTk7hiDKgxZX3JSb37vywdYYjjJows4DQjEaxBJDGF6LC6GXvPKo'),
|
||||
('yfy21e12jn3A3uDicNehCq486o9fMwJKMc', 'cMuko9rLDbtxCFWuBSrFgBDRSMxsLWKpJKScRGNuWKbhuQsnsjKT'),
|
||||
('yURgENB3b2YRMWnbhKF7iGs3KoaVRVXsJr', 'cQhdjTMh57MaHCDk9FsWGPtftRMBUuhaYAtouWnetcewmBuSrLSM'),
|
||||
('yYC9AxBEUs3ZZxfcQvj2LUF5PVxxtqaEs7', 'cQFueiiP13mfytV3Svoe4o4Ux79fRJvwuSgHapXsnBwrHod57EeL'),
|
||||
AddressKeyPair('yYdShjQSptFKitYLksFEUSwHe4hnbar5rf', 'cMfbiEsnG5b8Gwm6vEgfWvZLuXZNC4zsN2y7Es3An9xHRWRjmwgR'),
|
||||
AddressKeyPair('yfTFJgvq65UZsb9RBbpdYAAzsJoCGXqH2w', 'cStuFACUD1N6JjKQxNLUQ443qJUtSzLitKKEkA8x6utxTPZTLUtA'),
|
||||
AddressKeyPair('yU3w4VDjKhHiZpWszkUZVnFTS56AfgdfPV', 'cQb5yh2sTiG7dsxxbXHhWSBLMByYT7jY49A1kC7zKhgL9WNHysWW'),
|
||||
AddressKeyPair('yYhzix2R5LiYnDixsUnF8XwBYGYpyeTgB4', 'cW9Gu6uU4KoZJQcdyUvjULNRg4C8srPJw1adhgdTZMr9YQdKHtcn'),
|
||||
AddressKeyPair('yiQ3qLx5L1BW9XA6JAG7hC8UQDktcBCeYG', 'cSq7gHVC1QPsswyX2pE5C38UnWZXfCLr7XnkjnDwuZ68NkWp183T'),
|
||||
AddressKeyPair('yUL8h8mR7aNDRsU5zhcDbpp6YtA6ieUtK2', 'cTk7hiDKgxZX3JSb37vywdYYjjJows4DQjEaxBJDGF6LC6GXvPKo'),
|
||||
AddressKeyPair('yfy21e12jn3A3uDicNehCq486o9fMwJKMc', 'cMuko9rLDbtxCFWuBSrFgBDRSMxsLWKpJKScRGNuWKbhuQsnsjKT'),
|
||||
AddressKeyPair('yURgENB3b2YRMWnbhKF7iGs3KoaVRVXsJr', 'cQhdjTMh57MaHCDk9FsWGPtftRMBUuhaYAtouWnetcewmBuSrLSM'),
|
||||
AddressKeyPair('yYC9AxBEUs3ZZxfcQvj2LUF5PVxxtqaEs7', 'cQFueiiP13mfytV3Svoe4o4Ux79fRJvwuSgHapXsnBwrHod57EeL'),
|
||||
]
|
||||
return PRIV_KEYS[self.index]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user