Beispiel #1
0
def testSimpleReadWrite(nodesLeaves, tempdir):
    nodes, leaves = nodesLeaves
    fhs = FileHashStore(tempdir)

    for leaf in leaves:
        fhs.writeLeaf(leaf)
    for i, leaf in enumerate(leaves):
        assert leaf == fhs.readLeaf(i + 1)

    for node in nodes:
        fhs.writeNode(node)
    for i, node in enumerate(nodes):
        assert node[2] == fhs.readNode(i + 1)

    lvs = fhs.readLeafs(1, len(leaves))
    for i, l in enumerate(lvs):
        assert leaves[i] == l

    nds = fhs.readNodes(1, len(nodes))
    for i, n in enumerate(nds):
        assert nodes[i][2] == n

    # Check that hash store can be closed and re-opened and the contents remain same
    leaf_count = fhs.leafCount
    node_count = fhs.nodeCount
    fhs.close()
    reopened_hash_store = FileHashStore(tempdir)
    assert reopened_hash_store.leafCount == leaf_count
    assert reopened_hash_store.nodeCount == node_count
def writtenFhs(tempdir, nodes, leaves):
    fhs = FileHashStore(tempdir)
    for leaf in leaves:
        fhs.writeLeaf(leaf)
    for node in nodes:
        fhs.writeNode(node)
    return fhs
Beispiel #3
0
def testIncorrectWrites(tempdir):
    fhs = FileHashStore(tempdir, leafSize=50, nodeSize=50)

    with pytest.raises(ValueError):
        fhs.writeLeaf(b"less than 50")
    with pytest.raises(ValueError):
        fhs.writeNode((8, 1, b"also less than 50"))

    with pytest.raises(ValueError):
        fhs.writeLeaf(b"more than 50" + b'1' * 50)
    with pytest.raises(ValueError):
        fhs.writeNode((4, 1, b"also more than 50" + b'1' * 50))
Beispiel #4
0
def testIncorrectWrites(tempdir):
    fhs = FileHashStore(tempdir, leafSize=50, nodeSize=50)

    with pytest.raises(ValueError):
        fhs.writeLeaf(b"less than 50")
    with pytest.raises(ValueError):
        fhs.writeNode((8, 1, b"also less than 50"))

    with pytest.raises(ValueError):
        fhs.writeLeaf(b"more than 50" + b'1'*50)
    with pytest.raises(ValueError):
        fhs.writeNode((4, 1, b"also more than 50" + b'1'*50))
Beispiel #5
0
def testConsistencyVerificationOnStartupCase1(tempdir):
    """
    One more node was added to nodes file
    """
    fhs = FileHashStore(tempdir)
    tree = CompactMerkleTree(hashStore=fhs)
    ledger = Ledger(tree=tree, dataDir=tempdir)
    tranzNum = 10
    for d in range(tranzNum):
        ledger.add(str(d).encode())
    ledger.stop()

    # Writing one more node without adding of it to leaf and transaction logs
    badNode = (None, None, ('X' * 32))
    fhs.writeNode(badNode)

    with pytest.raises(ConsistencyVerificationFailed):
        tree = CompactMerkleTree(hashStore=fhs)
        ledger = NoTransactionRecoveryLedger(tree=tree, dataDir=tempdir)
        ledger.recoverTreeFromHashStore()
    ledger.stop()
Beispiel #6
0
def testConsistencyVerificationOnStartupCase1(tempdir):
    """
    One more node was added to nodes file
    """
    fhs = FileHashStore(tempdir)
    tree = CompactMerkleTree(hashStore=fhs)
    ledger = Ledger(tree=tree, dataDir=tempdir)
    tranzNum = 10
    for d in range(tranzNum):
        ledger.add(str(d).encode())
    ledger.stop()

    # Writing one more node without adding of it to leaf and transaction logs
    badNode = (None, None, ('X' * 32))
    fhs.writeNode(badNode)

    with pytest.raises(ConsistencyVerificationFailed):
        tree = CompactMerkleTree(hashStore=fhs)
        ledger = NoTransactionRecoveryLedger(tree=tree, dataDir=tempdir)
        ledger.recoverTreeFromHashStore()
    ledger.stop()
def testSimpleReadWrite(nodesLeaves, tempdir):
    nodes, leaves = nodesLeaves
    fhs = FileHashStore(tempdir)

    for leaf in leaves:
        fhs.writeLeaf(leaf)
    for i, leaf in enumerate(leaves):
        assert leaf == fhs.readLeaf(i + 1)

    for node in nodes:
        fhs.writeNode(node)
    for i, node in enumerate(nodes):
        assert node[2] == fhs.readNode(i + 1)

    lvs = fhs.readLeafs(1, len(leaves))
    for i, l in enumerate(lvs):
        assert leaves[i] == l

    nds = fhs.readNodes(1, len(nodes))
    for i, n in enumerate(nds):
        assert nodes[i][2] == n