예제 #1
0
def test_json_encoding():
    bcv = BlockChainView()
    j = bcv.as_json()
    assert j == '[]'
    for size in (30, 100, 750):
        bcv = make_bcv(30)
        bcv.winnow()
        j = bcv.as_json()
        bcv1 = BlockChainView.from_json(j)
        assert bcv1.node_tuples == bcv.node_tuples
예제 #2
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)
예제 #3
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)
예제 #4
0
def test1():
    bcv = BlockChainView()
    assert bcv.last_block_index() == -1
    assert bcv.block_locator_hashes() == [b'\0' * 32]

    blocks = make_blocks(20)