Changeset View
Changeset View
Standalone View
Standalone View
test/functional/example_test.py
Show All 22 Lines | from test_framework.mininode import ( | ||||
mininode_lock, | mininode_lock, | ||||
msg_block, | msg_block, | ||||
msg_getdata, | msg_getdata, | ||||
) | ) | ||||
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, | ||||
p2p_port, | |||||
wait_until, | wait_until, | ||||
) | ) | ||||
# NodeConnCB is a class containing callbacks to be executed when a P2P | # NodeConnCB is a class containing callbacks to be executed when a P2P | ||||
# message is received from the node-under-test. Subclass NodeConnCB and | # message is received from the node-under-test. Subclass NodeConnCB and | ||||
# override the on_*() methods if you need custom behaviour. | # override the on_*() methods if you need custom behaviour. | ||||
▲ Show 20 Lines • Show All 96 Lines • ▼ Show 20 Lines | class ExampleTest(BitcoinTestFramework): | ||||
def run_test(self): | def run_test(self): | ||||
"""Main test logic""" | """Main test logic""" | ||||
# Create a P2P connection to one of the nodes | # Create a P2P connection to one of the nodes | ||||
node0 = BaseNode() | node0 = BaseNode() | ||||
connections = [] | connections = [] | ||||
connections.append( | connections.append( | ||||
NodeConn('127.0.0.1', p2p_port(0), self.nodes[0], node0)) | NodeConn('127.0.0.1', self.p2p_port(0), self.nodes[0], node0)) | ||||
node0.add_connection(connections[0]) | node0.add_connection(connections[0]) | ||||
# Start up network handling in another thread. This needs to be called | # Start up network handling in another thread. This needs to be called | ||||
# after the P2P connections have been created. | # after the P2P connections have been created. | ||||
NetworkThread().start() | NetworkThread().start() | ||||
# wait_for_verack ensures that the P2P connection is fully up. | # wait_for_verack ensures that the P2P connection is fully up. | ||||
node0.wait_for_verack() | node0.wait_for_verack() | ||||
Show All 40 Lines | def run_test(self): | ||||
self.block_time += 1 | self.block_time += 1 | ||||
height += 1 | height += 1 | ||||
self.log.info( | self.log.info( | ||||
"Wait for node1 to reach current tip (height 11) using RPC") | "Wait for node1 to reach current tip (height 11) using RPC") | ||||
self.nodes[1].waitforblockheight(11) | self.nodes[1].waitforblockheight(11) | ||||
self.log.info("Connect node2 and node1") | self.log.info("Connect node2 and node1") | ||||
connect_nodes(self.nodes[1], 2) | connect_nodes(self.nodes[1], self.nodes[2]) | ||||
self.log.info("Add P2P connection to node2") | self.log.info("Add P2P connection to node2") | ||||
node2 = BaseNode() | node2 = BaseNode() | ||||
connections.append( | connections.append( | ||||
NodeConn('127.0.0.1', p2p_port(2), self.nodes[2], node2)) | NodeConn('127.0.0.1', self.p2p_port(2), self.nodes[2], node2)) | ||||
node2.add_connection(connections[1]) | node2.add_connection(connections[1]) | ||||
node2.wait_for_verack() | node2.wait_for_verack() | ||||
self.log.info( | self.log.info( | ||||
"Wait for node2 reach current tip. Test that it has propagated all the blocks to us") | "Wait for node2 reach current tip. Test that it has propagated all the blocks to us") | ||||
getdata_request = msg_getdata() | getdata_request = msg_getdata() | ||||
for block in blocks: | for block in blocks: | ||||
Show All 19 Lines |