Ejemplo n.º 1
0
def test_count_blocks(signed_create_tx):
    from bigchaindb.backend import connect, query
    from bigchaindb.models import Block
    conn = connect()

    assert query.count_blocks(conn) == 0

    # create and insert some blocks
    block = Block(transactions=[signed_create_tx])
    conn.db.bigchain.insert_one(block.to_dict())

    assert query.count_blocks(conn) == 1
Ejemplo n.º 2
0
    def test_get_last_block(self, b):
        from bigchaindb.backend import query
        # get the number of blocks
        num_blocks = query.count_blocks(b.connection)

        # get the last block
        last_block = b.get_last_block()

        assert last_block['block']['block_number'] == num_blocks - 1
Ejemplo n.º 3
0
def test_double_create(b, user_pk):
    from bigchaindb.models import Transaction
    from bigchaindb.backend.query import count_blocks
    tx = Transaction.create([b.me], [([user_pk], 1)],
                            metadata={'test': 'test'}).sign([b.me_private])

    b.write_transaction(tx)
    time.sleep(5)
    b.write_transaction(tx)
    time.sleep(5)
    tx_returned = b.get_transaction(tx.id)

    # test that the tx can be queried
    assert tx_returned == tx
    # test the transaction appears only once
    last_voted_block = b.get_last_voted_block()
    assert len(last_voted_block.transactions) == 1
    assert count_blocks(b.connection) == 2