def test_routingtable_neighbours(): table = RoutingTable(NodeFactory().id) for i in range(1000): assert table.add_node(NodeFactory()) is None assert i == len(table) - 1 for _ in range(100): node = NodeFactory() nearest_bucket = table.buckets_by_distance_to(node._id_int)[0] if not nearest_bucket.nodes: continue # Change nodeid to something that is in this bucket's range. node_a = nearest_bucket.nodes[0] node_b = NodeFactory.with_nodeid(node_a._id_int + 1) assert node_a == table.neighbours(node_b.id)[0]
def test_routingtable_add_node_error(): table = RoutingTable(NodeFactory().id) with pytest.raises(ValueError): table.add_node(NodeFactory.with_nodeid(KADEMLIA_MAX_NODE_ID + 1))
def test_binary_get_bucket_for_node_error(bucket_list, node_id): node = NodeFactory.with_nodeid(nodeid=node_id) with pytest.raises(ValueError): binary_get_bucket_for_node(bucket_list, node)
def test_binary_get_bucket_for_node(bucket_list, node_id, correct_position): node = NodeFactory.with_nodeid(nodeid=node_id) assert binary_get_bucket_for_node(bucket_list, node) == bucket_list[correct_position]
def test_routingtable_add_node_error(): table = kademlia.RoutingTable(NodeFactory()) with pytest.raises(ValueError): table.add_node(NodeFactory.with_nodeid(kademlia.k_max_node_id + 1))