def test_write_metadata(): from bigchaindb.backend import connect, query conn = connect() metadata = [ {'id': 1, 'data': '1'}, {'id': 2, 'data': '2'}, {'id': 3, 'data': '3'} ] # write the assets query.store_metadatas(conn, deepcopy(metadata)) # check that 3 assets were written to the database cursor = conn.db.metadata.find({}, projection={'_id': False})\ .sort('id', pymongo.ASCENDING) assert cursor.count() == 3 assert list(cursor) == metadata
def test_delete_zombie_transactions(signed_create_tx, signed_transfer_tx): from bigchaindb.backend import connect, query from bigchaindb.tendermint.lib import Block conn = connect() conn.db.transactions.insert_one(signed_create_tx.to_dict()) query.store_asset(conn, {'id': signed_create_tx.id}) block = Block(app_hash='random_utxo', height=3, transactions=[signed_create_tx.id]) query.store_block(conn, block._asdict()) conn.db.transactions.insert_one(signed_transfer_tx.to_dict()) query.store_metadatas(conn, [{'id': signed_transfer_tx.id}]) query.delete_zombie_transactions(conn) assert query.get_transaction(conn, signed_transfer_tx.id) is None assert query.get_asset(conn, signed_transfer_tx.id) is None assert list(query.get_metadata(conn, [signed_transfer_tx.id])) == [] assert query.get_transaction(conn, signed_create_tx.id) is not None assert query.get_asset(conn, signed_create_tx.id) is not None