mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 12:02:48 +01:00
Merge #13915: [qa] Add test for max number of entries in locator
fa85c985ed qa: Add p2p_invalid_locator test (MarcoFalke) Pull request description: Should not be merged *before* #13907 Tree-SHA512: a67ca407854c421ed20a184d0b0dc90085aed3e3431d9652a107fa3022244767e67f67e50449b7e95721f56906836b134615875f28a21e8a012eb22cfe6a66a5
This commit is contained in:
parent
20e1f4a8ef
commit
290a23a9e4
43
test/functional/p2p_invalid_locator.py
Executable file
43
test/functional/p2p_invalid_locator.py
Executable file
@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env python3
|
||||
# Copyright (c) 2015-2017 The Bitcoin Core developers
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
"""Test node responses to invalid locators.
|
||||
"""
|
||||
|
||||
from test_framework.messages import msg_getheaders, msg_getblocks, MAX_LOCATOR_SZ
|
||||
from test_framework.mininode import P2PInterface
|
||||
from test_framework.test_framework import BitcoinTestFramework
|
||||
|
||||
|
||||
class InvalidLocatorTest(BitcoinTestFramework):
|
||||
def set_test_params(self):
|
||||
self.num_nodes = 1
|
||||
self.setup_clean_chain = False
|
||||
|
||||
def run_test(self):
|
||||
node = self.nodes[0] # convenience reference to the node
|
||||
node.generate(1) # Get node out of IBD
|
||||
|
||||
self.log.info('Test max locator size')
|
||||
block_count = node.getblockcount()
|
||||
for msg in [msg_getheaders(), msg_getblocks()]:
|
||||
self.log.info('Wait for disconnect when sending {} hashes in locator'.format(MAX_LOCATOR_SZ + 1))
|
||||
node.add_p2p_connection(P2PInterface())
|
||||
msg.locator.vHave = [int(node.getblockhash(i - 1), 16) for i in range(block_count, block_count - (MAX_LOCATOR_SZ + 1), -1)]
|
||||
node.p2p.send_message(msg)
|
||||
node.p2p.wait_for_disconnect()
|
||||
node.disconnect_p2ps()
|
||||
|
||||
self.log.info('Wait for response when sending {} hashes in locator'.format(MAX_LOCATOR_SZ))
|
||||
node.add_p2p_connection(P2PInterface())
|
||||
msg.locator.vHave = [int(node.getblockhash(i - 1), 16) for i in range(block_count, block_count - (MAX_LOCATOR_SZ), -1)]
|
||||
node.p2p.send_message(msg)
|
||||
if type(msg) == msg_getheaders:
|
||||
node.p2p.wait_for_header(int(node.getbestblockhash(), 16))
|
||||
else:
|
||||
node.p2p.wait_for_block(int(node.getbestblockhash(), 16))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
InvalidLocatorTest().main()
|
@ -32,6 +32,7 @@ MY_SUBVERSION = b"/python-mininode-tester:0.0.3%s/"
|
||||
MY_RELAY = 1 # from version 70001 onwards, fRelay should be appended to version messages (BIP37)
|
||||
|
||||
MAX_INV_SZ = 50000
|
||||
MAX_LOCATOR_SZ = 101
|
||||
MAX_BLOCK_SIZE = 1000000
|
||||
|
||||
COIN = 100000000 # 1 btc in satoshis
|
||||
|
@ -387,6 +387,15 @@ class P2PInterface(P2PConnection):
|
||||
test_function = lambda: self.last_message.get("block") and self.last_message["block"].block.rehash() == blockhash
|
||||
wait_until(test_function, timeout=timeout, lock=mininode_lock)
|
||||
|
||||
def wait_for_header(self, blockhash, timeout=60):
|
||||
def test_function():
|
||||
last_headers = self.last_message.get('headers')
|
||||
if not last_headers:
|
||||
return False
|
||||
return last_headers.headers[0].rehash() == blockhash
|
||||
|
||||
wait_until(test_function, timeout=timeout, lock=mininode_lock)
|
||||
|
||||
def wait_for_getdata(self, timeout=60):
|
||||
"""Waits for a getdata message.
|
||||
|
||||
|
@ -136,6 +136,7 @@ BASE_SCRIPTS = [
|
||||
'wallet_keypool_hd.py',
|
||||
'p2p_mempool.py',
|
||||
'mining_prioritisetransaction.py',
|
||||
'p2p_invalid_locator.py',
|
||||
'p2p_invalid_block.py',
|
||||
'p2p_invalid_tx.py',
|
||||
'feature_assumevalid.py',
|
||||
|
Loading…
Reference in New Issue
Block a user