Changeset View
Changeset View
Standalone View
Standalone View
test/functional/p2p-acceptblock.py
Show First 20 Lines • Show All 90 Lines • ▼ Show 20 Lines | class AcceptBlockTest(BitcoinTestFramework): | ||||
def run_test(self): | def run_test(self): | ||||
# Setup the p2p connections and start up the network thread. | # Setup the p2p connections and start up the network thread. | ||||
test_node = NodeConnCB() # connects to node0 (not whitelisted) | test_node = NodeConnCB() # connects to node0 (not whitelisted) | ||||
white_node = NodeConnCB() # connects to node1 (whitelisted) | white_node = NodeConnCB() # connects to node1 (whitelisted) | ||||
min_work_node = NodeConnCB() # connects to node2 (not whitelisted) | min_work_node = NodeConnCB() # connects to node2 (not whitelisted) | ||||
connections = [] | connections = [] | ||||
connections.append( | connections.append( | ||||
NodeConn('127.0.0.1', p2p_port(0), self.nodes[0], test_node)) | NodeConn('127.0.0.1', self.p2p_port(0), self.nodes[0], test_node)) | ||||
connections.append( | connections.append( | ||||
NodeConn('127.0.0.1', p2p_port(1), self.nodes[1], white_node)) | NodeConn('127.0.0.1', self.p2p_port(1), self.nodes[1], white_node)) | ||||
connections.append(NodeConn('127.0.0.1', p2p_port(2), | connections.append(NodeConn('127.0.0.1', self.p2p_port(2), | ||||
self.nodes[2], min_work_node)) | self.nodes[2], min_work_node)) | ||||
test_node.add_connection(connections[0]) | test_node.add_connection(connections[0]) | ||||
white_node.add_connection(connections[1]) | white_node.add_connection(connections[1]) | ||||
min_work_node.add_connection(connections[2]) | min_work_node.add_connection(connections[2]) | ||||
NetworkThread().start() # Start up network handling in another thread | NetworkThread().start() # Start up network handling in another thread | ||||
# Test logic begins here | # Test logic begins here | ||||
▲ Show 20 Lines • Show All 148 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
test_node.sync_with_ping() | test_node.sync_with_ping() | ||||
assert_equal(self.nodes[0].getblockcount(), 290) | assert_equal(self.nodes[0].getblockcount(), 290) | ||||
self.log.info( | self.log.info( | ||||
"Successfully reorged to longer chain from non-whitelisted peer") | "Successfully reorged to longer chain from non-whitelisted peer") | ||||
[c.disconnect_node() for c in connections] | [c.disconnect_node() for c in connections] | ||||
# 8. Connect node2 to node0 and ensure it is able to sync | # 8. Connect node2 to node0 and ensure it is able to sync | ||||
connect_nodes(self.nodes[0], 2) | connect_nodes(self.nodes[0], self.nodes[2]) | ||||
sync_blocks([self.nodes[0], self.nodes[2]]) | sync_blocks([self.nodes[0], self.nodes[2]]) | ||||
self.log.info("Successfully synced nodes 2 and 0") | self.log.info("Successfully synced nodes 2 and 0") | ||||
[c.disconnect_node() for c in connections] | [c.disconnect_node() for c in connections] | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
AcceptBlockTest().main() | AcceptBlockTest().main() |