mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 04:22:55 +01:00
b07a7b810c
* Merge #11796: [tests] Functional test naming convention5fecd84
[tests] Remove redundant import in blocktools.py test (Anthony Towns)9b20bb4
[tests] Check tests conform to naming convention (Anthony Towns)7250b4e
[tests] README.md nit fixes (Anthony Towns)82b2712
[tests] move witness util functions to blocktools.py (John Newbery)1e10854
[tests] [docs] update README for new test naming scheme (John Newbery) Pull request description: Splitting #11774 into two parts -- this part updates the README with the proposed naming convention, and adds some checks to test_runner.py that the number of tests violating the naming convention doesn't increase too much. Idea is this part of the change should not introduce merge conflicts or require much rebasing, so reviews of the complicated bits won't become invalidated too often; while the second part will just be file renames, which will require regular rebasing and will introduce merge conflicts with pending PRs, but can be merged later, and should also be much easier to review, since it will only include relatively trivial changes. Tree-SHA512: b96557d41714addbbfe2aed62fb5a48639eaeb1eb3aba30ac1b3a86bb3cb8d796c6247f9c414c4695c4bf54c0ec9968ac88e2f88fb62483bc1a2f89368f7fc80 * update violation count Signed-off-by: pasta <pasta@dashboost.org> * Merge #11774: [tests] Rename functional tests6f881cc880
[tests] Remove EXPECTED_VIOLATION_COUNT (Anthony Towns)3150b3fea7
[tests] Rename misc functional tests. (Anthony Towns)81b79f2c39
[tests] Rename rpc_* functional tests. (Anthony Towns)61b8f7f273
[tests] Rename p2p_* functional tests. (Anthony Towns)90600bc7db
[tests] Rename wallet_* functional tests. (Anthony Towns)ca6523d0c8
[tests] Rename feature_* functional tests. (Anthony Towns) Pull request description: This PR changes the functional tests to have a consistent naming scheme: tests for individual RPC methods are named rpc_... tests for interfaces (REST, ZMQ, RPC features) are named interface_... tests that explicitly test the p2p interface are named p2p_... tests for wallet features are named wallet_... tests for mining features are named mining_... tests for mempool behaviour are named mempool_... tests for full features that aren't wallet/mining/mempool are named feature_... Rationale: it's sometimes difficult for new contributors to know what's already covered by existing tests and where new tests should be added. Naming in a consistent fashion makes it easier to see what's already covered at a glance. Tree-SHA512: 4246790552d42bbd95f6d5bdf67702b81b3b2c583ce7eaf1fe6d8e254721279b47315973c6e9ae82dad6e4c747f12188160764bf2624c0f8f3b4d39330ec8b16 * rename tests and edit associated strings to align test-suite with test name standards Signed-off-by: pasta <pasta@dashboost.org> * fix grammar in test/functional/test_runner.py Co-authored-by: dustinface <35775977+xdustinface@users.noreply.github.com> * ci: Fix excluded test names * rename feature_privatesend.py to rpc_privatesend.py Signed-off-by: pasta <pasta@dashboost.org> Co-authored-by: Wladimir J. van der Laan <laanwj@gmail.com> Co-authored-by: MarcoFalke <falke.marco@gmail.com> Co-authored-by: dustinface <35775977+xdustinface@users.noreply.github.com> Co-authored-by: xdustinface <xdustinfacex@gmail.com>
113 lines
5.2 KiB
Python
Executable File
113 lines
5.2 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# Copyright (c) 2016 The Bitcoin Core developers
|
|
# Distributed under the MIT software license, see the accompanying
|
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
"""Test version bits warning system.
|
|
|
|
Generate chains with block versions that appear to be signalling unknown
|
|
soft-forks, and test that warning alerts are generated.
|
|
"""
|
|
import os
|
|
import re
|
|
|
|
from test_framework.blocktools import create_block, create_coinbase
|
|
from test_framework.messages import msg_block
|
|
from test_framework.mininode import P2PInterface, network_thread_start, mininode_lock
|
|
from test_framework.test_framework import BitcoinTestFramework
|
|
from test_framework.util import wait_until
|
|
|
|
VB_PERIOD = 144 # versionbits period length for regtest
|
|
VB_THRESHOLD = 108 # versionbits activation threshold for regtest
|
|
VB_TOP_BITS = 0x20000000
|
|
VB_UNKNOWN_BIT = 27 # Choose a bit unassigned to any deployment
|
|
VB_UNKNOWN_VERSION = VB_TOP_BITS | (1 << VB_UNKNOWN_BIT)
|
|
|
|
WARN_UNKNOWN_RULES_MINED = "Unknown block versions being mined! It's possible unknown rules are in effect"
|
|
WARN_UNKNOWN_RULES_ACTIVE = "unknown new rules activated (versionbit {})".format(VB_UNKNOWN_BIT)
|
|
VB_PATTERN = re.compile("Warning: unknown new rules activated.*versionbit")
|
|
|
|
class VersionBitsWarningTest(BitcoinTestFramework):
|
|
def set_test_params(self):
|
|
self.setup_clean_chain = True
|
|
self.num_nodes = 1
|
|
|
|
def setup_network(self):
|
|
self.alert_filename = os.path.join(self.options.tmpdir, "alert.txt")
|
|
# Open and close to create zero-length file
|
|
with open(self.alert_filename, 'w', encoding='utf8'):
|
|
pass
|
|
self.extra_args = [["-alertnotify=echo %s >> \"" + self.alert_filename + "\""]]
|
|
self.setup_nodes()
|
|
|
|
def send_blocks_with_version(self, peer, numblocks, version):
|
|
"""Send numblocks blocks to peer with version set"""
|
|
tip = self.nodes[0].getbestblockhash()
|
|
height = self.nodes[0].getblockcount()
|
|
block_time = self.nodes[0].getblockheader(tip)["time"] + 1
|
|
tip = int(tip, 16)
|
|
|
|
for _ in range(numblocks):
|
|
block = create_block(tip, create_coinbase(height + 1), block_time)
|
|
block.nVersion = version
|
|
block.solve()
|
|
peer.send_message(msg_block(block))
|
|
block_time += 1
|
|
height += 1
|
|
tip = block.sha256
|
|
peer.sync_with_ping()
|
|
|
|
def versionbits_in_alert_file(self):
|
|
"""Test that the versionbits warning has been written to the alert file."""
|
|
alert_text = open(self.alert_filename, 'r', encoding='utf8').read()
|
|
return VB_PATTERN.search(alert_text) is not None
|
|
|
|
def run_test(self):
|
|
# Handy alias
|
|
node = self.nodes[0]
|
|
node.add_p2p_connection(P2PInterface())
|
|
network_thread_start()
|
|
node.p2p.wait_for_verack()
|
|
|
|
# Mine one period worth of blocks
|
|
node.generate(VB_PERIOD)
|
|
|
|
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)
|
|
|
|
# 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.getnetworkinfo()["warnings"]))
|
|
|
|
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)
|
|
|
|
# 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.getnetworkinfo()["warnings"])
|
|
|
|
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)
|
|
|
|
# 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)
|
|
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)
|
|
# 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"])
|
|
# Check that the alert file shows the versionbits unknown rules warning
|
|
wait_until(lambda: self.versionbits_in_alert_file(), timeout=60)
|
|
|
|
if __name__ == '__main__':
|
|
VersionBitsWarningTest().main()
|