mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 04:52:59 +01:00
[tests] fix flake8 warnings in sendheaders.py
This commit is contained in:
parent
99bc0b428b
commit
2613c545f5
@ -83,16 +83,32 @@ d. Announce 49 headers that don't connect.
|
||||
e. Announce one more that doesn't connect.
|
||||
Expect: disconnect.
|
||||
"""
|
||||
|
||||
from test_framework.mininode import *
|
||||
from test_framework.test_framework import BitcoinTestFramework
|
||||
from test_framework.util import *
|
||||
from test_framework.blocktools import create_block, create_coinbase
|
||||
from test_framework.mininode import (
|
||||
CBlockHeader,
|
||||
CInv,
|
||||
NODE_WITNESS,
|
||||
NetworkThread,
|
||||
NodeConnCB,
|
||||
mininode_lock,
|
||||
msg_block,
|
||||
msg_getblocks,
|
||||
msg_getdata,
|
||||
msg_getheaders,
|
||||
msg_headers,
|
||||
msg_inv,
|
||||
msg_sendheaders,
|
||||
)
|
||||
from test_framework.test_framework import BitcoinTestFramework
|
||||
from test_framework.util import (
|
||||
assert_equal,
|
||||
sync_blocks,
|
||||
wait_until,
|
||||
)
|
||||
|
||||
DIRECT_FETCH_RESPONSE_TIME = 0.05
|
||||
|
||||
direct_fetch_response_time = 0.05
|
||||
|
||||
class TestNode(NodeConnCB):
|
||||
class BaseNode(NodeConnCB):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.block_announced = False
|
||||
@ -136,8 +152,8 @@ class TestNode(NodeConnCB):
|
||||
# right header or the right inv
|
||||
# inv and headers should be lists of block hashes
|
||||
def check_last_announcement(self, headers=None, inv=None):
|
||||
expect_headers = headers if headers != None else []
|
||||
expect_inv = inv if inv != None else []
|
||||
expect_headers = headers if headers is not None else []
|
||||
expect_inv = inv if inv is not None else []
|
||||
test_function = lambda: self.block_announced
|
||||
wait_until(test_function, timeout=60, lock=mininode_lock)
|
||||
with mininode_lock:
|
||||
@ -217,10 +233,10 @@ class SendHeadersTest(BitcoinTestFramework):
|
||||
|
||||
def run_test(self):
|
||||
# Setup the p2p connections and start up the network thread.
|
||||
inv_node = self.nodes[0].add_p2p_connection(TestNode())
|
||||
inv_node = self.nodes[0].add_p2p_connection(BaseNode())
|
||||
# Set nServices to 0 for test_node, so no block download will occur outside of
|
||||
# direct fetching
|
||||
test_node = self.nodes[0].add_p2p_connection(TestNode(), services=NODE_WITNESS)
|
||||
test_node = self.nodes[0].add_p2p_connection(BaseNode(), services=NODE_WITNESS)
|
||||
|
||||
NetworkThread().start() # Start up network handling in another thread
|
||||
|
||||
@ -453,7 +469,7 @@ class SendHeadersTest(BitcoinTestFramework):
|
||||
|
||||
test_node.send_header_for_blocks(blocks)
|
||||
test_node.sync_with_ping()
|
||||
test_node.wait_for_getdata([x.sha256 for x in blocks], timeout=direct_fetch_response_time)
|
||||
test_node.wait_for_getdata([x.sha256 for x in blocks], timeout=DIRECT_FETCH_RESPONSE_TIME)
|
||||
|
||||
[test_node.send_message(msg_block(x)) for x in blocks]
|
||||
|
||||
@ -484,13 +500,13 @@ class SendHeadersTest(BitcoinTestFramework):
|
||||
# both blocks (same work as tip)
|
||||
test_node.send_header_for_blocks(blocks[1:2])
|
||||
test_node.sync_with_ping()
|
||||
test_node.wait_for_getdata([x.sha256 for x in blocks[0:2]], timeout=direct_fetch_response_time)
|
||||
test_node.wait_for_getdata([x.sha256 for x in blocks[0:2]], timeout=DIRECT_FETCH_RESPONSE_TIME)
|
||||
|
||||
# Announcing 16 more headers should trigger direct fetch for 14 more
|
||||
# blocks
|
||||
test_node.send_header_for_blocks(blocks[2:18])
|
||||
test_node.sync_with_ping()
|
||||
test_node.wait_for_getdata([x.sha256 for x in blocks[2:16]], timeout=direct_fetch_response_time)
|
||||
test_node.wait_for_getdata([x.sha256 for x in blocks[2:16]], timeout=DIRECT_FETCH_RESPONSE_TIME)
|
||||
|
||||
# Announcing 1 more header should not trigger any response
|
||||
test_node.last_message.pop("getdata", None)
|
||||
|
Loading…
Reference in New Issue
Block a user