Skip to content

Commit 725b79a

Browse files
ryanofskyTheBlueMatt
authored andcommitted
[test] Verify node doesn't send headers that haven't been fully validated
1 parent 3788a84 commit 725b79a

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

test/functional/sendheaders.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@
1010
receive inv's (omitted from testing description below, this is our control).
1111
Second node is used for creating reorgs.
1212
13+
test_null_locators
14+
==================
15+
16+
Sends two getheaders requests with null locator values. First request's hashstop
17+
value refers to validated block, while second request's hashstop value refers to
18+
a block which hasn't been validated. Verifies only the first request returns
19+
headers.
20+
21+
test_nonnull_locators
22+
=====================
23+
1324
Part 1: No headers announcements before "sendheaders"
1425
a. node mines a block [expect: inv]
1526
send getdata for the block [expect: block]
@@ -229,6 +240,29 @@ def run_test(self):
229240
inv_node.sync_with_ping()
230241
test_node.sync_with_ping()
231242

243+
self.test_null_locators(test_node)
244+
self.test_nonnull_locators(test_node, inv_node)
245+
246+
def test_null_locators(self, test_node):
247+
tip = self.nodes[0].getblockheader(self.nodes[0].generate(1)[0])
248+
tip_hash = int(tip["hash"], 16)
249+
250+
self.log.info("Verify getheaders with null locator and valid hashstop returns headers.")
251+
test_node.clear_last_announcement()
252+
test_node.get_headers(locator=[], hashstop=tip_hash)
253+
assert_equal(test_node.check_last_announcement(headers=[tip_hash]), True)
254+
255+
self.log.info("Verify getheaders with null locator and invalid hashstop does not return headers.")
256+
block = create_block(int(tip["hash"], 16), create_coinbase(tip["height"] + 1), tip["mediantime"] + 1)
257+
block.solve()
258+
test_node.send_header_for_blocks([block])
259+
test_node.clear_last_announcement()
260+
test_node.get_headers(locator=[], hashstop=int(block.hash, 16))
261+
test_node.sync_with_ping()
262+
assert_equal(test_node.block_announced, False)
263+
test_node.send_message(msg_block(block))
264+
265+
def test_nonnull_locators(self, test_node, inv_node):
232266
tip = int(self.nodes[0].getbestblockhash(), 16)
233267

234268
# PART 1

0 commit comments

Comments
 (0)