Skip to content

Commit fa7da06

Browse files
author
MarcoFalke
committed
qa: Check specific reject reasons in feature_block
1 parent 5d605b2 commit fa7da06

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

test/functional/feature_block.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -579,14 +579,14 @@ def run_test(self):
579579
while b47.sha256 < target:
580580
b47.nNonce += 1
581581
b47.rehash()
582-
self.sync_blocks([b47], False, request_block=False)
582+
self.sync_blocks([b47], False, force_send=True, reject_reason='high-hash')
583583

584584
self.log.info("Reject a block with a timestamp >2 hours in the future")
585585
self.move_tip(44)
586586
b48 = self.next_block(48, solve=False)
587587
b48.nTime = int(time.time()) + 60 * 60 * 3
588588
b48.solve()
589-
self.sync_blocks([b48], False, request_block=False)
589+
self.sync_blocks([b48], False, force_send=True, reject_reason='time-too-new')
590590

591591
self.log.info("Reject a block with invalid merkle hash")
592592
self.move_tip(44)
@@ -600,7 +600,7 @@ def run_test(self):
600600
b50 = self.next_block(50)
601601
b50.nBits = b50.nBits - 1
602602
b50.solve()
603-
self.sync_blocks([b50], False, request_block=False, reconnect=True)
603+
self.sync_blocks([b50], False, force_send=True, reject_reason='bad-diffbits', reconnect=True)
604604

605605
self.log.info("Reject a block with two coinbase transactions")
606606
self.move_tip(44)
@@ -630,7 +630,7 @@ def run_test(self):
630630
b54 = self.next_block(54, spend=out[15])
631631
b54.nTime = b35.nTime - 1
632632
b54.solve()
633-
self.sync_blocks([b54], False, request_block=False)
633+
self.sync_blocks([b54], False, force_send=True, reject_reason='time-too-old')
634634

635635
# valid timestamp
636636
self.move_tip(53)
@@ -1078,11 +1078,11 @@ def run_test(self):
10781078

10791079
self.move_tip(77)
10801080
b80 = self.next_block(80, spend=out[25])
1081-
self.sync_blocks([b80], False, request_block=False)
1081+
self.sync_blocks([b80], False, force_send=True)
10821082
self.save_spendable_output()
10831083

10841084
b81 = self.next_block(81, spend=out[26])
1085-
self.sync_blocks([b81], False, request_block=False) # other chain is same length
1085+
self.sync_blocks([b81], False, force_send=True) # other chain is same length
10861086
self.save_spendable_output()
10871087

10881088
b82 = self.next_block(82, spend=out[27])
@@ -1189,7 +1189,7 @@ def run_test(self):
11891189
blocks2 = []
11901190
for i in range(89, LARGE_REORG_SIZE + 89):
11911191
blocks2.append(self.next_block("alt" + str(i)))
1192-
self.sync_blocks(blocks2, False, request_block=False)
1192+
self.sync_blocks(blocks2, False, force_send=True)
11931193

11941194
# extend alt chain to trigger re-org
11951195
block = self.next_block("alt" + str(chain1_tip + 1))
@@ -1198,7 +1198,7 @@ def run_test(self):
11981198
# ... and re-org back to the first chain
11991199
self.move_tip(chain1_tip)
12001200
block = self.next_block(chain1_tip + 1)
1201-
self.sync_blocks([block], False, request_block=False)
1201+
self.sync_blocks([block], False, force_send=True)
12021202
block = self.next_block(chain1_tip + 2)
12031203
self.sync_blocks([block], True, timeout=180)
12041204

@@ -1309,14 +1309,15 @@ def reconnect_p2p(self):
13091309
self.nodes[0].disconnect_p2ps()
13101310
self.bootstrap_p2p()
13111311

1312-
def sync_blocks(self, blocks, success=True, reject_reason=None, request_block=True, reconnect=False, timeout=60):
1312+
def sync_blocks(self, blocks, success=True, reject_reason=None, force_send=False, reconnect=False, timeout=60):
13131313
"""Sends blocks to test node. Syncs and verifies that tip has advanced to most recent block.
13141314
13151315
Call with success = False if the tip shouldn't advance to the most recent block."""
1316-
self.nodes[0].p2p.send_blocks_and_test(blocks, self.nodes[0], success=success, reject_reason=reject_reason, request_block=request_block, timeout=timeout, expect_disconnect=reconnect)
1316+
self.nodes[0].p2p.send_blocks_and_test(blocks, self.nodes[0], success=success, reject_reason=reject_reason, force_send=force_send, timeout=timeout, expect_disconnect=reconnect)
13171317

13181318
if reconnect:
13191319
self.reconnect_p2p()
13201320

1321+
13211322
if __name__ == '__main__':
13221323
FullBlockTest().main()

test/functional/test_framework/mininode.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -511,14 +511,14 @@ def on_getheaders(self, message):
511511
if response is not None:
512512
self.send_message(response)
513513

514-
def send_blocks_and_test(self, blocks, node, *, success=True, request_block=True, reject_reason=None, expect_disconnect=False, timeout=60):
514+
def send_blocks_and_test(self, blocks, node, *, success=True, force_send=False, reject_reason=None, expect_disconnect=False, timeout=60):
515515
"""Send blocks to test node and test whether the tip advances.
516516
517517
- add all blocks to our block_store
518518
- send a headers message for the final block
519519
- the on_getheaders handler will ensure that any getheaders are responded to
520-
- if request_block is True: wait for getdata for each of the blocks. The on_getdata handler will
521-
ensure that any getdata messages are responded to
520+
- if force_send is False: wait for getdata for each of the blocks. The on_getdata handler will
521+
ensure that any getdata messages are responded to. Otherwise send the full block unsolicited.
522522
- if success is True: assert that the node's tip advances to the most recent block
523523
- if success is False: assert that the node's tip doesn't advance
524524
- if reject_reason is set: assert that the correct reject message is logged"""
@@ -530,9 +530,11 @@ def send_blocks_and_test(self, blocks, node, *, success=True, request_block=True
530530

531531
reject_reason = [reject_reason] if reject_reason else []
532532
with node.assert_debug_log(expected_msgs=reject_reason):
533-
self.send_message(msg_headers([CBlockHeader(blocks[-1])]))
534-
535-
if request_block:
533+
if force_send:
534+
for b in blocks:
535+
self.send_message(msg_block(block=b))
536+
else:
537+
self.send_message(msg_headers([CBlockHeader(blocks[-1])]))
536538
wait_until(lambda: blocks[-1].sha256 in self.getdata_requests, timeout=timeout, lock=mininode_lock)
537539

538540
if expect_disconnect:

0 commit comments

Comments
 (0)