Example #1
0
def test_improve_path():
    size = 100
    headers = make_headers(size)
    bcv = make_bcv(0)
    assert bcv.last_block_index() == -1
    for count in range(100):
        report = bcv.do_headers_improve_path([headers[count]])
        assert report == count
        assert bcv.last_block_index() == count
    # let's try to extend from 95
    headers = make_headers(10, headers[95])

    for count in range(96, 100):
        report = bcv.do_headers_improve_path(headers[0:count-95])
        assert report == False
    count = 100
    report = bcv.do_headers_improve_path(headers[0:count-95])
    assert report == 96

    report = bcv.do_headers_improve_path(headers[5:])
    assert report == 101
Example #2
0
def test_improve_path():
    size = 100
    headers = make_headers(size)
    bcv = make_bcv(0)
    assert bcv.last_block_index() == -1
    for count in range(100):
        report = bcv.do_headers_improve_path([headers[count]])
        assert report == count
        assert bcv.last_block_index() == count
    # let's try to extend from 95
    headers = make_headers(10, headers[95])

    for count in range(96, 100):
        report = bcv.do_headers_improve_path(headers[0:count - 95])
        assert report == False
    count = 100
    report = bcv.do_headers_improve_path(headers[0:count - 95])
    assert report == 96

    report = bcv.do_headers_improve_path(headers[5:])
    assert report == 101
Example #3
0
def test_block_locator_hashes():
    for size in [100, 500, 720, 1000]:
        headers = make_headers(size)
        nodes = [(i, headers[i].hash(), i) for i in range(size)]
        bcv = BlockChainView(nodes)
        blh = bcv.block_locator_hashes()
        tuples = [bcv.tuple_for_hash(h) for h in blh]
        indices = [t[0] for t in tuples]
        indices.sort()
        assert indices == sorted(bcv.key_index_generator())

        bcv.winnow()
        blh = bcv.block_locator_hashes()
        tuples = [bcv.tuple_for_hash(h) for h in blh]
        indices = [t[0] for t in tuples]
        indices.sort()
        assert indices == list(t[0] for t in bcv.node_tuples)
Example #4
0
def test_block_locator_hashes():
    for size in [100, 500, 720, 1000]:
        headers = make_headers(size)
        nodes = [(i, headers[i].hash(), i) for i in range(size)]
        bcv = BlockChainView(nodes)
        blh = bcv.block_locator_hashes()
        tuples = [bcv.tuple_for_hash(h) for h in blh]
        indices = [t[0] for t in tuples]
        indices.sort()
        assert indices == sorted(bcv.key_index_generator())

        bcv.winnow()
        blh = bcv.block_locator_hashes()
        tuples = [bcv.tuple_for_hash(h) for h in blh]
        indices = [t[0] for t in tuples]
        indices.sort()
        assert indices == list(t[0] for t in bcv.node_tuples)
Example #5
0
def test_tuple_for_hash():
    for size in [100, 500, 720, 1000]:
        bcv = make_bcv(size)
        headers = make_headers(size)
        for idx, header in enumerate(headers):
            the_hash = header.hash()
            the_tuple = bcv.tuple_for_hash(the_hash)
            assert the_tuple[0] == idx
            assert the_tuple[1] == the_hash
        bcv.winnow()
        items = BlockChainView._halsies_indices(size - 1)
        for idx, header in enumerate(headers):
            the_hash = header.hash()
            the_tuple = bcv.tuple_for_hash(the_hash)
            if idx in items:
                assert the_tuple[0] == idx
                assert the_tuple[1] == the_hash
            else:
                assert the_tuple == None
Example #6
0
def test_tuple_for_hash():
    for size in [100, 500, 720, 1000]:
        bcv = make_bcv(size)
        headers = make_headers(size)
        for idx, header in enumerate(headers):
            the_hash = header.hash()
            the_tuple = bcv.tuple_for_hash(the_hash)
            assert the_tuple[0] == idx
            assert the_tuple[1] == the_hash
        bcv.winnow()
        items = BlockChainView._halsies_indices(size-1)
        for idx, header in enumerate(headers):
            the_hash = header.hash()
            the_tuple = bcv.tuple_for_hash(the_hash)
            if idx in items:
                assert the_tuple[0] == idx
                assert the_tuple[1] == the_hash
            else:
                assert the_tuple == None
Example #7
0
def make_bcv(node_count):
    headers = make_headers(node_count)
    nodes = ((i, header.hash(), i) for i, header in enumerate(headers))
    return BlockChainView(nodes)
Example #8
0
def make_bcv(node_count):
    headers = make_headers(node_count)
    nodes = ((i, header.hash(), i) for i, header in enumerate(headers))
    return BlockChainView(nodes)