Changeset View
Changeset View
Standalone View
Standalone View
test/functional/example_test.py
Show All 9 Lines | |||||
is testing and *how* it's being tested | is testing and *how* it's being tested | ||||
""" | """ | ||||
# Imports should be in PEP8 ordering (std library first, then third party | # Imports should be in PEP8 ordering (std library first, then third party | ||||
# libraries then local imports). | # libraries then local imports). | ||||
from collections import defaultdict | from collections import defaultdict | ||||
# Avoid wildcard * imports if possible | # Avoid wildcard * imports if possible | ||||
from test_framework.blocktools import (create_block, create_coinbase) | from test_framework.blocktools import (create_block, create_coinbase) | ||||
from test_framework.messages import (CInv, msg_block, msg_getdata) | from test_framework.messages import ( | ||||
CInv, | |||||
MSG_BLOCK, | |||||
msg_block, | |||||
msg_getdata | |||||
) | |||||
from test_framework.mininode import ( | from test_framework.mininode import ( | ||||
P2PInterface, | P2PInterface, | ||||
mininode_lock, | mininode_lock, | ||||
) | ) | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import ( | from test_framework.util import ( | ||||
assert_equal, | assert_equal, | ||||
connect_nodes, | connect_nodes, | ||||
▲ Show 20 Lines • Show All 175 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
self.nodes[0].disconnect_p2ps() | self.nodes[0].disconnect_p2ps() | ||||
self.nodes[2].add_p2p_connection(BaseNode()) | self.nodes[2].add_p2p_connection(BaseNode()) | ||||
self.log.info("Test that node2 propagates all the blocks to us") | self.log.info("Test that node2 propagates all the blocks to us") | ||||
getdata_request = msg_getdata() | getdata_request = msg_getdata() | ||||
for block in blocks: | for block in blocks: | ||||
getdata_request.inv.append(CInv(2, block)) | getdata_request.inv.append(CInv(MSG_BLOCK, block)) | ||||
self.nodes[2].p2p.send_message(getdata_request) | self.nodes[2].p2p.send_message(getdata_request) | ||||
# wait_until() will loop until a predicate condition is met. Use it to test properties of the | # wait_until() will loop until a predicate condition is met. Use it to test properties of the | ||||
# P2PInterface objects. | # P2PInterface objects. | ||||
wait_until(lambda: sorted(blocks) == sorted( | wait_until(lambda: sorted(blocks) == sorted( | ||||
list(self.nodes[2].p2p.block_receive_map.keys())), timeout=5, lock=mininode_lock) | list(self.nodes[2].p2p.block_receive_map.keys())), timeout=5, lock=mininode_lock) | ||||
self.log.info("Check that each block was received only once") | self.log.info("Check that each block was received only once") | ||||
Show All 11 Lines |