コード例 #1
0
ファイル: test_kademlia.py プロジェクト: jonnycrunch/trinity
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]
コード例 #2
0
ファイル: test_kademlia.py プロジェクト: jonnycrunch/trinity
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))
コード例 #3
0
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)
コード例 #4
0
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]
コード例 #5
0
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))