[qa] Add getinfo smoke tests and rework versionbits test
This commit is contained in:
parent
ddddaafa4a
commit
fa6e71b27d
2 changed files with 23 additions and 20 deletions
|
@ -6,6 +6,7 @@
|
||||||
from test_framework.mininode import *
|
from test_framework.mininode import *
|
||||||
from test_framework.test_framework import BitcoinTestFramework
|
from test_framework.test_framework import BitcoinTestFramework
|
||||||
from test_framework.util import *
|
from test_framework.util import *
|
||||||
|
import re
|
||||||
import time
|
import time
|
||||||
from test_framework.blocktools import create_block, create_coinbase
|
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_TOP_BITS = 0x20000000
|
||||||
VB_UNKNOWN_BIT = 27 # Choose a bit unassigned to any deployment
|
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
|
# 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.
|
# p2p messages to a node, generating the messages in the main testing logic.
|
||||||
class TestNode(NodeConnCB):
|
class TestNode(NodeConnCB):
|
||||||
|
@ -65,16 +70,12 @@ class VersionBitsWarningTest(BitcoinTestFramework):
|
||||||
self.num_nodes = 1
|
self.num_nodes = 1
|
||||||
|
|
||||||
def setup_network(self):
|
def setup_network(self):
|
||||||
self.nodes = []
|
|
||||||
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
|
||||||
with open(self.alert_filename, 'w') as f:
|
with open(self.alert_filename, 'w') as _:
|
||||||
pass
|
pass
|
||||||
self.node_options = ["-debug", "-logtimemicros=1", "-alertnotify=echo %s >> \"" + self.alert_filename + "\""]
|
self.extra_args = [["-debug", "-logtimemicros=1", "-alertnotify=echo %s >> \"" + self.alert_filename + "\""]]
|
||||||
self.nodes.append(start_node(0, self.options.tmpdir, self.node_options))
|
self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, self.extra_args)
|
||||||
|
|
||||||
import re
|
|
||||||
self.vb_pattern = re.compile("^Warning.*versionbit")
|
|
||||||
|
|
||||||
# Send numblocks blocks via peer with nVersionToUse set.
|
# Send numblocks blocks via peer with nVersionToUse set.
|
||||||
def send_blocks_with_version(self, peer, numblocks, nVersionToUse):
|
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
|
block_time = self.nodes[0].getblockheader(tip)["time"]+1
|
||||||
tip = int(tip, 16)
|
tip = int(tip, 16)
|
||||||
|
|
||||||
for i in range(numblocks):
|
for _ in range(numblocks):
|
||||||
block = create_block(tip, create_coinbase(height+1), block_time)
|
block = create_block(tip, create_coinbase(height+1), block_time)
|
||||||
block.nVersion = nVersionToUse
|
block.nVersion = nVersionToUse
|
||||||
block.solve()
|
block.solve()
|
||||||
|
@ -96,7 +97,7 @@ class VersionBitsWarningTest(BitcoinTestFramework):
|
||||||
def test_versionbits_in_alert_file(self):
|
def test_versionbits_in_alert_file(self):
|
||||||
with open(self.alert_filename, 'r') as f:
|
with open(self.alert_filename, 'r') as f:
|
||||||
alert_text = f.read()
|
alert_text = f.read()
|
||||||
assert(self.vb_pattern.match(alert_text))
|
assert(VB_PATTERN.match(alert_text))
|
||||||
|
|
||||||
def run_test(self):
|
def run_test(self):
|
||||||
# Setup the p2p connection and start up the network thread.
|
# Setup the p2p connection and start up the network thread.
|
||||||
|
@ -123,8 +124,9 @@ class VersionBitsWarningTest(BitcoinTestFramework):
|
||||||
self.nodes[0].generate(VB_PERIOD - VB_THRESHOLD + 1)
|
self.nodes[0].generate(VB_PERIOD - VB_THRESHOLD + 1)
|
||||||
# Check that we're not getting any versionbit-related errors in
|
# Check that we're not getting any versionbit-related errors in
|
||||||
# get*info()
|
# get*info()
|
||||||
assert(not self.vb_pattern.match(self.nodes[0].getmininginfo()["errors"]))
|
assert(not VB_PATTERN.match(self.nodes[0].getinfo()["errors"]))
|
||||||
assert(not self.vb_pattern.match(self.nodes[0].getnetworkinfo()["warnings"]))
|
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
|
# 3. Now build one period of blocks with >= VB_THRESHOLD blocks signaling
|
||||||
# some unknown bit
|
# some unknown bit
|
||||||
|
@ -134,8 +136,9 @@ class VersionBitsWarningTest(BitcoinTestFramework):
|
||||||
# have gotten a different alert due to more than 51/100 blocks
|
# have gotten a different alert due to more than 51/100 blocks
|
||||||
# being of unexpected version.
|
# being of unexpected version.
|
||||||
# Check that get*info() shows some kind of error.
|
# Check that get*info() shows some kind of error.
|
||||||
assert("Unknown block versions" in self.nodes[0].getmininginfo()["errors"])
|
assert(WARN_UNKNOWN_RULES_MINED in self.nodes[0].getinfo()["errors"])
|
||||||
assert("Unknown block versions" in self.nodes[0].getnetworkinfo()["warnings"])
|
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
|
# 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
|
# is cleared, and restart the node. This should move the versionbit state
|
||||||
|
@ -144,21 +147,21 @@ class VersionBitsWarningTest(BitcoinTestFramework):
|
||||||
stop_node(self.nodes[0], 0)
|
stop_node(self.nodes[0], 0)
|
||||||
wait_bitcoinds()
|
wait_bitcoinds()
|
||||||
# Empty out the alert file
|
# Empty out the alert file
|
||||||
with open(self.alert_filename, 'w') as f:
|
with open(self.alert_filename, 'w') as _:
|
||||||
pass
|
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.
|
# Connecting one block should be enough to generate an error.
|
||||||
self.nodes[0].generate(1)
|
self.nodes[0].generate(1)
|
||||||
assert("unknown new rules" in self.nodes[0].getmininginfo()["errors"])
|
assert(WARN_UNKNOWN_RULES_ACTIVE in self.nodes[0].getinfo()["errors"])
|
||||||
assert("unknown new rules" in self.nodes[0].getnetworkinfo()["warnings"])
|
assert(WARN_UNKNOWN_RULES_ACTIVE in self.nodes[0].getmininginfo()["errors"])
|
||||||
|
assert(WARN_UNKNOWN_RULES_ACTIVE in self.nodes[0].getnetworkinfo()["warnings"])
|
||||||
stop_node(self.nodes[0], 0)
|
stop_node(self.nodes[0], 0)
|
||||||
wait_bitcoinds()
|
wait_bitcoinds()
|
||||||
self.test_versionbits_in_alert_file()
|
self.test_versionbits_in_alert_file()
|
||||||
|
|
||||||
# Test framework expects the node to still be running...
|
# 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__':
|
if __name__ == '__main__':
|
||||||
VersionBitsWarningTest().main()
|
VersionBitsWarningTest().main()
|
||||||
|
|
|
@ -44,7 +44,7 @@ class RPCBindTest(BitcoinTestFramework):
|
||||||
|
|
||||||
def run_allowip_test(self, allow_ips, rpchost, rpcport):
|
def run_allowip_test(self, allow_ips, rpchost, rpcport):
|
||||||
'''
|
'''
|
||||||
Start a node with rpcwallow IP, and request getnetworkinfo
|
Start a node with rpcallow IP, and request getnetworkinfo
|
||||||
at a non-localhost IP.
|
at a non-localhost IP.
|
||||||
'''
|
'''
|
||||||
base_args = ['-disablewallet', '-nolisten'] + ['-rpcallowip='+x for x in allow_ips]
|
base_args = ['-disablewallet', '-nolisten'] + ['-rpcallowip='+x for x in allow_ips]
|
||||||
|
|
Loading…
Reference in a new issue