Exemplo n.º 1
0
def test_trie_is_empty():
    # the char set under test is string.hexdigits
    from node_tools import ctlr_data as ct

    res = trie_is_empty(ct.id_trie)
    assert res is True

    ct.id_trie.setdefault(u'f00b', 42)
    with pytest.raises(AssertionError):
        res = trie_is_empty(ct.id_trie)

    ct.id_trie.clear()
Exemplo n.º 2
0
def test_make_cfg_msg():
    # the char set used for trie keys is string.hexdigits
    import json
    from node_tools import ctlr_data as ct
    assert trie_is_empty(ct.id_trie) is True

    node_id = '02beefdead'
    needs = [False, True]
    net_list = ['7ac4235ec5d3d938']
    ct.id_trie[node_id] = (net_list, needs)
    cfg_msg = '{"node_id": "02beefdead", "networks": ["7ac4235ec5d3d938"]}'

    res = make_cfg_msg(ct.id_trie, node_id)
    assert type(res) is str
    assert json.loads(res) == json.loads(cfg_msg)
    assert valid_cfg_msg(res)
    ct.id_trie.clear()
    assert trie_is_empty(ct.id_trie) is True
Exemplo n.º 3
0
def test_load_id_from_net_trie():
    from node_tools import ctlr_data as ct

    NODE_SETTINGS['use_exitnode'].append('beefea68e6')
    dead_key = 'dead99dead'

    res = trie_is_empty(ct.net_trie)
    assert res is True

    load_net_trie_data(ct.net_trie)
    assert len(list(ct.net_trie)) == 8

    for net_id in ['beafde52b4296ea5', 'beafde52b4a5f7ba', 'beafde52b4a5e8ab']:
        load_id_trie(ct.net_trie, ct.id_trie, [net_id], [], nw=True)
    for node_id in ['beefea68e6', 'ee2eedb2e1', 'ff2ffdb2e1', dead_key]:
        load_id_trie(ct.net_trie, ct.id_trie, [], [node_id])

    for key in [
            'beafde52b4296ea5', 'beafde52b4a5f7ba', 'ee2eedb2e1', 'ff2ffdb2e1'
    ]:
        links, needs = ct.id_trie[key]
        for item in [links, needs]:
            assert isinstance(item, list)
        assert len(links) == 2
        assert len(needs) == 2

    assert ct.id_trie['beefea68e6'] == (['beafde52b4296ea5'], [False, False])
    assert ct.id_trie['beafde52b4a5f7ba'] == (['ee2eedb2e1',
                                               'ff2ffdb2e1'], [False, False])
    assert ct.id_trie['beafde52b4a5e8ab'] == (['ff2ffdb2e1'], [False, True])

    res = find_exit_net(ct.id_trie)
    assert isinstance(res, list)
    assert res == ['beafde52b4296ea5']
    exit_net = find_exit_net(ct.id_trie)[0]
    assert exit_net == res[0]
    # print(ct.id_trie.items())

    node_id = 'beefea68e6'
    with pytest.raises(AssertionError):
        load_id_trie(ct.net_trie, ct.id_trie, [], [node_id], needs=[True])
    with pytest.raises(AssertionError):
        load_id_trie(ct.net_trie, ct.id_trie, [], [node_id, node_id, node_id])
    with pytest.raises(AssertionError):
        load_id_trie(ct.net_trie, ct.id_trie, [], node_id)
    with pytest.raises(AssertionError):
        load_id_trie(ct.net_trie, ct.id_trie, [], [])

    NODE_SETTINGS['use_exitnode'].clear()