Пример #1
0
def test_add_get_txns(ledger_no_genesis):
    ledger = ledger_no_genesis
    txns = []
    hashes = [hexlify(h).decode() for h in generateHashes(40)]
    for i in range(20):
        txns.append({
            'identifier': hashes.pop(),
            'reqId': i,
            'op': hashes.pop()
        })

    for txn in txns:
        ledger.add(txn)

    check_ledger_generator(ledger)

    for frm, to in [(1, 20), (3, 8), (5, 17), (6, 10), (3, 3),
                    (3, None), (None, 10), (None, None)]:
        for s, t in ledger.getAllTxn(frm=frm, to=to):
            assert txns[s - 1] == t

    # with pytest.raises(AssertionError):
    #     list(ledger.getAllTxn(frm=3, to=1))

    for frm, to in [(i, j) for i, j in itertools.permutations(range(1, 21),
                                                              2) if i <= j]:
        for s, t in ledger.getAllTxn(frm=frm, to=to):
            assert txns[s - 1] == t
Пример #2
0
def test_add_get_txns(ledger_no_genesis):
    ledger = ledger_no_genesis
    txns = []
    hashes = [hexlify(h).decode() for h in generateHashes(40)]
    for i in range(20):
        txns.append({
            'identifier': hashes.pop(),
            'reqId': i,
            'op': hashes.pop()
        })

    for txn in txns:
        ledger.add(txn)

    check_ledger_generator(ledger)

    for frm, to in [(1, 20), (3, 8), (5, 17), (6, 10), (3, 3), (3, None),
                    (None, 10), (None, None)]:
        for s, t in ledger.getAllTxn(frm=frm, to=to):
            assert txns[s - 1] == t

    # with pytest.raises(AssertionError):
    #     list(ledger.getAllTxn(frm=3, to=1))

    for frm, to in [(i, j) for i, j in itertools.permutations(range(1, 21), 2)
                    if i <= j]:
        for s, t in ledger.getAllTxn(frm=frm, to=to):
            assert txns[s - 1] == t
Пример #3
0
def test_add_txn(ledger, genesis_txns, genesis_txn_file):
    offset = len(genesis_txns) if genesis_txn_file else 0
    txn1 = random_txn(1)
    txn2 = random_txn(2)
    ledger.add(txn1)
    ledger.add(txn2)

    # Check that the transaction is added to the Merkle Tree
    assert ledger.size == 2 + offset

    # Check that the data is appended to the immutable store
    assert sorted(txn1.items()) == sorted(ledger[1 + offset].items())
    assert sorted(txn2.items()) == sorted(ledger[2 + offset].items())
    check_ledger_generator(ledger)
Пример #4
0
def test_add_txn(ledger, genesis_txns, genesis_txn_file):
    offset = len(genesis_txns) if genesis_txn_file else 0
    txn1 = random_txn(1)
    txn2 = random_txn(2)
    ledger.add(txn1)
    ledger.add(txn2)

    # Check that the transaction is added to the Merkle Tree
    assert ledger.size == 2 + offset

    # Check that the data is appended to the immutable store
    assert sorted(txn1.items()) == sorted(ledger[1 + offset].items())
    assert sorted(txn2.items()) == sorted(ledger[2 + offset].items())
    check_ledger_generator(ledger)
Пример #5
0
def testAddTxn(tempdir, ledger):
    txn1 = {'identifier': 'cli1', 'reqId': 1, 'op': 'do something'}
    ledger.add(txn1)

    txn2 = {'identifier': 'cli1', 'reqId': 2, 'op': 'do something else'}
    ledger.add(txn2)

    # Check that the transaction is added to the Merkle Tree
    assert ledger.size == 2

    # Check that the data is appended to the immutable store
    txn1[F.seqNo.name] = 1
    txn2[F.seqNo.name] = 2
    assert txn1 == ledger[1]
    assert txn2 == ledger[2]
    check_ledger_generator(ledger)
Пример #6
0
def test_add_get_txns(tempdir, ledger):
    txns = []
    hashes = [hexlify(h).decode() for h in generateHashes(60)]
    for i in range(20):
        txns.append({
            'a': hashes.pop(),
            'b': hashes.pop(),
            'c': hashes.pop()
        })

    for txn in txns:
        ledger.add(txn)

    check_ledger_generator(ledger)

    for s, t in ledger.getAllTxn(frm=1, to=20):
        assert txns[s-1] == t

    for s, t in ledger.getAllTxn(frm=3, to=8):
        assert txns[s-1] == t

    for s, t in ledger.getAllTxn(frm=5, to=17):
        assert txns[s-1] == t

    for s, t in ledger.getAllTxn(frm=6, to=10):
        assert txns[s-1] == t

    for s, t in ledger.getAllTxn(frm=3, to=3):
        assert txns[s-1] == t

    for s, t in ledger.getAllTxn(frm=3):
        assert txns[s-1] == t

    for s, t in ledger.getAllTxn(to=10):
        assert txns[s-1] == t

    for s, t in ledger.getAllTxn():
        assert txns[s-1] == t

    with pytest.raises(AssertionError):
        list(ledger.getAllTxn(frm=3, to=1))

    for frm, to in [(i, j) for i, j in itertools.permutations(range(1, 21),
                                                              2) if i <= j]:
        for s, t in ledger.getAllTxn(frm=frm, to=to):
            assert txns[s-1] == t
Пример #7
0
def testAddTxn(tempdir, ledger):
    txn1 = {
        'identifier': 'cli1',
        'reqId': 1,
        'op': 'do something'
    }
    ledger.add(txn1)

    txn2 = {
        'identifier': 'cli1',
        'reqId': 2,
        'op': 'do something else'
    }
    ledger.add(txn2)

    # Check that the transaction is added to the Merkle Tree
    assert ledger.size == 2

    # Check that the data is appended to the immutable store
    txn1[F.seqNo.name] = 1
    txn2[F.seqNo.name] = 2
    assert txn1 == ledger[1]
    assert txn2 == ledger[2]
    check_ledger_generator(ledger)