Skip to content

Commit fa6e71b

Browse files
author
MarcoFalke
committed
[qa] Add getinfo smoke tests and rework versionbits test
1 parent ddddaaf commit fa6e71b

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

qa/rpc-tests/p2p-versionbits-warning.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from test_framework.mininode import *
77
from test_framework.test_framework import BitcoinTestFramework
88
from test_framework.util import *
9+
import re
910
import time
1011
from test_framework.blocktools import create_block, create_coinbase
1112

@@ -21,6 +22,10 @@
2122
VB_TOP_BITS = 0x20000000
2223
VB_UNKNOWN_BIT = 27 # Choose a bit unassigned to any deployment
2324

25+
WARN_UNKNOWN_RULES_MINED = "Unknown block versions being mined! It's possible unknown rules are in effect"
26+
WARN_UNKNOWN_RULES_ACTIVE = "unknown new rules activated (versionbit {})".format(VB_UNKNOWN_BIT)
27+
VB_PATTERN = re.compile("^Warning.*versionbit")
28+
2429
# TestNode: bare-bones "peer". Used mostly as a conduit for a test to sending
2530
# p2p messages to a node, generating the messages in the main testing logic.
2631
class TestNode(NodeConnCB):
@@ -65,16 +70,12 @@ def __init__(self):
6570
self.num_nodes = 1
6671

6772
def setup_network(self):
68-
self.nodes = []
6973
self.alert_filename = os.path.join(self.options.tmpdir, "alert.txt")
7074
# Open and close to create zero-length file
71-
with open(self.alert_filename, 'w') as f:
75+
with open(self.alert_filename, 'w') as _:
7276
pass
73-
self.node_options = ["-debug", "-logtimemicros=1", "-alertnotify=echo %s >> \"" + self.alert_filename + "\""]
74-
self.nodes.append(start_node(0, self.options.tmpdir, self.node_options))
75-
76-
import re
77-
self.vb_pattern = re.compile("^Warning.*versionbit")
77+
self.extra_args = [["-debug", "-logtimemicros=1", "-alertnotify=echo %s >> \"" + self.alert_filename + "\""]]
78+
self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, self.extra_args)
7879

7980
# Send numblocks blocks via peer with nVersionToUse set.
8081
def send_blocks_with_version(self, peer, numblocks, nVersionToUse):
@@ -83,7 +84,7 @@ def send_blocks_with_version(self, peer, numblocks, nVersionToUse):
8384
block_time = self.nodes[0].getblockheader(tip)["time"]+1
8485
tip = int(tip, 16)
8586

86-
for i in range(numblocks):
87+
for _ in range(numblocks):
8788
block = create_block(tip, create_coinbase(height+1), block_time)
8889
block.nVersion = nVersionToUse
8990
block.solve()
@@ -96,7 +97,7 @@ def send_blocks_with_version(self, peer, numblocks, nVersionToUse):
9697
def test_versionbits_in_alert_file(self):
9798
with open(self.alert_filename, 'r') as f:
9899
alert_text = f.read()
99-
assert(self.vb_pattern.match(alert_text))
100+
assert(VB_PATTERN.match(alert_text))
100101

101102
def run_test(self):
102103
# Setup the p2p connection and start up the network thread.
@@ -123,8 +124,9 @@ def run_test(self):
123124
self.nodes[0].generate(VB_PERIOD - VB_THRESHOLD + 1)
124125
# Check that we're not getting any versionbit-related errors in
125126
# get*info()
126-
assert(not self.vb_pattern.match(self.nodes[0].getmininginfo()["errors"]))
127-
assert(not self.vb_pattern.match(self.nodes[0].getnetworkinfo()["warnings"]))
127+
assert(not VB_PATTERN.match(self.nodes[0].getinfo()["errors"]))
128+
assert(not VB_PATTERN.match(self.nodes[0].getmininginfo()["errors"]))
129+
assert(not VB_PATTERN.match(self.nodes[0].getnetworkinfo()["warnings"]))
128130

129131
# 3. Now build one period of blocks with >= VB_THRESHOLD blocks signaling
130132
# some unknown bit
@@ -134,8 +136,9 @@ def run_test(self):
134136
# have gotten a different alert due to more than 51/100 blocks
135137
# being of unexpected version.
136138
# Check that get*info() shows some kind of error.
137-
assert("Unknown block versions" in self.nodes[0].getmininginfo()["errors"])
138-
assert("Unknown block versions" in self.nodes[0].getnetworkinfo()["warnings"])
139+
assert(WARN_UNKNOWN_RULES_MINED in self.nodes[0].getinfo()["errors"])
140+
assert(WARN_UNKNOWN_RULES_MINED in self.nodes[0].getmininginfo()["errors"])
141+
assert(WARN_UNKNOWN_RULES_MINED in self.nodes[0].getnetworkinfo()["warnings"])
139142

140143
# Mine a period worth of expected blocks so the generic block-version warning
141144
# is cleared, and restart the node. This should move the versionbit state
@@ -144,21 +147,21 @@ def run_test(self):
144147
stop_node(self.nodes[0], 0)
145148
wait_bitcoinds()
146149
# Empty out the alert file
147-
with open(self.alert_filename, 'w') as f:
150+
with open(self.alert_filename, 'w') as _:
148151
pass
149-
self.nodes[0] = start_node(0, self.options.tmpdir, ["-debug", "-logtimemicros=1", "-alertnotify=echo %s >> \"" + self.alert_filename + "\""])
152+
self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, self.extra_args)
150153

151154
# Connecting one block should be enough to generate an error.
152155
self.nodes[0].generate(1)
153-
assert("unknown new rules" in self.nodes[0].getmininginfo()["errors"])
154-
assert("unknown new rules" in self.nodes[0].getnetworkinfo()["warnings"])
156+
assert(WARN_UNKNOWN_RULES_ACTIVE in self.nodes[0].getinfo()["errors"])
157+
assert(WARN_UNKNOWN_RULES_ACTIVE in self.nodes[0].getmininginfo()["errors"])
158+
assert(WARN_UNKNOWN_RULES_ACTIVE in self.nodes[0].getnetworkinfo()["warnings"])
155159
stop_node(self.nodes[0], 0)
156160
wait_bitcoinds()
157161
self.test_versionbits_in_alert_file()
158162

159163
# Test framework expects the node to still be running...
160-
self.nodes[0] = start_node(0, self.options.tmpdir, ["-debug", "-logtimemicros=1", "-alertnotify=echo %s >> \"" + self.alert_filename + "\""])
161-
164+
self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, self.extra_args)
162165

163166
if __name__ == '__main__':
164167
VersionBitsWarningTest().main()

qa/rpc-tests/rpcbind_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def run_bind_test(self, allow_ips, connect_to, addresses, expected):
4444

4545
def run_allowip_test(self, allow_ips, rpchost, rpcport):
4646
'''
47-
Start a node with rpcwallow IP, and request getnetworkinfo
47+
Start a node with rpcallow IP, and request getnetworkinfo
4848
at a non-localhost IP.
4949
'''
5050
base_args = ['-disablewallet', '-nolisten'] + ['-rpcallowip='+x for x in allow_ips]

0 commit comments

Comments
 (0)