aboutsummaryrefslogtreecommitdiff
path: root/qa/rpc-tests/p2p-versionbits-warning.py
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2016-10-11 11:54:57 +0200
committerMarcoFalke <falke.marco@gmail.com>2016-10-11 11:55:28 +0200
commit94688d8e43e70f0d5c6ce3f5b6e1bb062ee4540a (patch)
tree6dd0c06fde7c8e166ea1bb8f284c6266a72c5767 /qa/rpc-tests/p2p-versionbits-warning.py
parenta916677ace1c214f1c87f3a383cdc0d38dee8831 (diff)
parent5e0dd9e07c02422a263cc14a173d4ee21a7c1393 (diff)
downloadbitcoin-94688d8e43e70f0d5c6ce3f5b6e1bb062ee4540a.tar.xz
Merge #8866: [0.13] Backports
5e0dd9e [Doc] Update bips.md for Segregated Witness (fanquake) d6c83b9 [qa] Fix race condition in sendheaders.py (Suhas Daftuar) b73f065 [qa] Another attempt to fix race condition in p2p-compactblocks.py (Suhas Daftuar) b987348 Bugfix: Trivial: RPC: getblockchaininfo help: pruneheight is the lowest, not highest, block (Luke Dashjr) cbc3fe5 test: Explicitly set encoding to utf8 when opening text files (Wladimir J. van der Laan) 0bee740 [qa] util: Move wait_bitcoinds() into stop_nodes() (MarcoFalke) 794b007 [qa] Add getinfo smoke tests and rework versionbits test (MarcoFalke) 1f60d45 [qa] mininode: Only allow named args in wait_until (MarcoFalke) 624a007 [qa] Fix race condition in p2p-compactblocks test (Suhas Daftuar) 3e4abb5 Fix nulldummy.py test (Johnson Lau) 31ab2f8 test: Avoid ConnectionResetErrors during RPC tests (Wladimir J. van der Laan) eb18cc1 bitcoin-util-test.py should fail if the output file is empty (jnewbery) d87227d [qa] nulldummy: Don't run unused code (MarcoFalke) 1dd1783 [qa] blockstore: Switch to dumb dbm (MarcoFalke) 83ad563 [rpc] throw JSONRPCError when utxo set can not be read (MarcoFalke) 6288659 [Wallet] remove "unused" ThreadFlushWalletDB from removeprunedfunds (Jonas Schnelli) 2a8bca4 Add bitcoin-tx JSON tests (jnewbery) 9bbe66e [qa] Split up slow RPC calls to avoid pruning test timeouts (Suhas Daftuar) 375437c Ping regularly in p2p-segwit.py to keep connection alive (Johnson Lau)
Diffstat (limited to 'qa/rpc-tests/p2p-versionbits-warning.py')
-rwxr-xr-xqa/rpc-tests/p2p-versionbits-warning.py50
1 files changed, 27 insertions, 23 deletions
diff --git a/qa/rpc-tests/p2p-versionbits-warning.py b/qa/rpc-tests/p2p-versionbits-warning.py
index 962cafef0b..fc3eddddee 100755
--- a/qa/rpc-tests/p2p-versionbits-warning.py
+++ b/qa/rpc-tests/p2p-versionbits-warning.py
@@ -6,6 +6,7 @@
from test_framework.mininode import *
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import *
+import re
import time
from test_framework.blocktools import create_block, create_coinbase
@@ -21,6 +22,10 @@ VB_THRESHOLD = 108 # versionbits activation threshold for regtest
VB_TOP_BITS = 0x20000000
VB_UNKNOWN_BIT = 27 # Choose a bit unassigned to any deployment
+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.*versionbit")
+
# TestNode: bare-bones "peer". Used mostly as a conduit for a test to sending
# p2p messages to a node, generating the messages in the main testing logic.
class TestNode(NodeConnCB):
@@ -65,16 +70,12 @@ class VersionBitsWarningTest(BitcoinTestFramework):
self.num_nodes = 1
def setup_network(self):
- self.nodes = []
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') as f:
+ with open(self.alert_filename, 'w', encoding='utf8') as _:
pass
- self.node_options = ["-debug", "-logtimemicros=1", "-alertnotify=echo %s >> \"" + self.alert_filename + "\""]
- self.nodes.append(start_node(0, self.options.tmpdir, self.node_options))
-
- import re
- self.vb_pattern = re.compile("^Warning.*versionbit")
+ self.extra_args = [["-debug", "-logtimemicros=1", "-alertnotify=echo %s >> \"" + self.alert_filename + "\""]]
+ self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, self.extra_args)
# Send numblocks blocks via peer with nVersionToUse set.
def send_blocks_with_version(self, peer, numblocks, nVersionToUse):
@@ -83,7 +84,7 @@ class VersionBitsWarningTest(BitcoinTestFramework):
block_time = self.nodes[0].getblockheader(tip)["time"]+1
tip = int(tip, 16)
- for i in range(numblocks):
+ for _ in range(numblocks):
block = create_block(tip, create_coinbase(height+1), block_time)
block.nVersion = nVersionToUse
block.solve()
@@ -94,9 +95,9 @@ class VersionBitsWarningTest(BitcoinTestFramework):
peer.sync_with_ping()
def test_versionbits_in_alert_file(self):
- with open(self.alert_filename, 'r') as f:
+ with open(self.alert_filename, 'r', encoding='utf8') as f:
alert_text = f.read()
- assert(self.vb_pattern.match(alert_text))
+ assert(VB_PATTERN.match(alert_text))
def run_test(self):
# Setup the p2p connection and start up the network thread.
@@ -122,8 +123,10 @@ class VersionBitsWarningTest(BitcoinTestFramework):
# Fill rest of period with regular version blocks
self.nodes[0].generate(VB_PERIOD - VB_THRESHOLD + 1)
# Check that we're not getting any versionbit-related errors in
- # getinfo()
- assert(not self.vb_pattern.match(self.nodes[0].getinfo()["errors"]))
+ # get*info()
+ assert(not VB_PATTERN.match(self.nodes[0].getinfo()["errors"]))
+ assert(not VB_PATTERN.match(self.nodes[0].getmininginfo()["errors"]))
+ assert(not VB_PATTERN.match(self.nodes[0].getnetworkinfo()["warnings"]))
# 3. Now build one period of blocks with >= VB_THRESHOLD blocks signaling
# some unknown bit
@@ -132,30 +135,31 @@ class VersionBitsWarningTest(BitcoinTestFramework):
# Might not get a versionbits-related alert yet, as we should
# have gotten a different alert due to more than 51/100 blocks
# being of unexpected version.
- # Check that getinfo() shows some kind of error.
- assert(len(self.nodes[0].getinfo()["errors"]) != 0)
+ # Check that get*info() shows some kind of error.
+ assert(WARN_UNKNOWN_RULES_MINED in self.nodes[0].getinfo()["errors"])
+ assert(WARN_UNKNOWN_RULES_MINED in self.nodes[0].getmininginfo()["errors"])
+ assert(WARN_UNKNOWN_RULES_MINED in self.nodes[0].getnetworkinfo()["warnings"])
# Mine a period worth of expected blocks so the generic block-version warning
# is cleared, and restart the node. This should move the versionbit state
# to ACTIVE.
self.nodes[0].generate(VB_PERIOD)
- stop_node(self.nodes[0], 0)
- wait_bitcoinds()
+ stop_nodes(self.nodes)
# Empty out the alert file
- with open(self.alert_filename, 'w') as f:
+ with open(self.alert_filename, 'w', encoding='utf8') as _:
pass
- self.nodes[0] = start_node(0, self.options.tmpdir, ["-debug", "-logtimemicros=1", "-alertnotify=echo %s >> \"" + self.alert_filename + "\""])
+ self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, self.extra_args)
# Connecting one block should be enough to generate an error.
self.nodes[0].generate(1)
- assert(len(self.nodes[0].getinfo()["errors"]) != 0)
- stop_node(self.nodes[0], 0)
- wait_bitcoinds()
+ assert(WARN_UNKNOWN_RULES_ACTIVE in self.nodes[0].getinfo()["errors"])
+ assert(WARN_UNKNOWN_RULES_ACTIVE in self.nodes[0].getmininginfo()["errors"])
+ assert(WARN_UNKNOWN_RULES_ACTIVE in self.nodes[0].getnetworkinfo()["warnings"])
+ stop_nodes(self.nodes)
self.test_versionbits_in_alert_file()
# Test framework expects the node to still be running...
- self.nodes[0] = start_node(0, self.options.tmpdir, ["-debug", "-logtimemicros=1", "-alertnotify=echo %s >> \"" + self.alert_filename + "\""])
-
+ self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, self.extra_args)
if __name__ == '__main__':
VersionBitsWarningTest().main()