Skip to content

Commit 794b007

Browse files
author
MarcoFalke
committed
[qa] Add getinfo smoke tests and rework versionbits test
Github-Pull: #8780 Rebased-From: fa6e71b
1 parent 1f60d45 commit 794b007

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed

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

Lines changed: 24 additions & 18 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.
@@ -122,8 +123,10 @@ def run_test(self):
122123
# Fill rest of period with regular version blocks
123124
self.nodes[0].generate(VB_PERIOD - VB_THRESHOLD + 1)
124125
# Check that we're not getting any versionbit-related errors in
125-
# getinfo()
126-
assert(not self.vb_pattern.match(self.nodes[0].getinfo()["errors"]))
126+
# get*info()
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"]))
127130

128131
# 3. Now build one period of blocks with >= VB_THRESHOLD blocks signaling
129132
# some unknown bit
@@ -132,8 +135,10 @@ def run_test(self):
132135
# Might not get a versionbits-related alert yet, as we should
133136
# have gotten a different alert due to more than 51/100 blocks
134137
# being of unexpected version.
135-
# Check that getinfo() shows some kind of error.
136-
assert(len(self.nodes[0].getinfo()["errors"]) != 0)
138+
# Check that get*info() shows some kind of error.
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"])
137142

138143
# Mine a period worth of expected blocks so the generic block-version warning
139144
# is cleared, and restart the node. This should move the versionbit state
@@ -142,20 +147,21 @@ def run_test(self):
142147
stop_node(self.nodes[0], 0)
143148
wait_bitcoinds()
144149
# Empty out the alert file
145-
with open(self.alert_filename, 'w') as f:
150+
with open(self.alert_filename, 'w') as _:
146151
pass
147-
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)
148153

149154
# Connecting one block should be enough to generate an error.
150155
self.nodes[0].generate(1)
151-
assert(len(self.nodes[0].getinfo()["errors"]) != 0)
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"])
152159
stop_node(self.nodes[0], 0)
153160
wait_bitcoinds()
154161
self.test_versionbits_in_alert_file()
155162

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

160166
if __name__ == '__main__':
161167
VersionBitsWarningTest().main()

qa/rpc-tests/rpcbind_test.py

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

4747
def run_allowip_test(self, allow_ips, rpchost, rpcport):
4848
'''
49-
Start a node with rpcwallow IP, and request getinfo
49+
Start a node with rpcallow IP, and request getinfo
5050
at a non-localhost IP.
5151
'''
5252
base_args = ['-disablewallet', '-nolisten'] + ['-rpcallowip='+x for x in allow_ips]

0 commit comments

Comments
 (0)