mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Fix the long list of warnings from test run
- depracated pymongo methods - direct use of fixtures
This commit is contained in:
parent
73352c8793
commit
c431e225fe
@ -234,7 +234,7 @@ def store_unspent_outputs(conn, *unspent_outputs):
|
||||
def delete_unspent_outputs(conn, *unspent_outputs):
|
||||
if unspent_outputs:
|
||||
return conn.run(
|
||||
conn.collection('utxos').remove({
|
||||
conn.collection('utxos').delete_many({
|
||||
'$or': [{
|
||||
'$and': [
|
||||
{'transaction_id': unspent_output['transaction_id']},
|
||||
@ -258,7 +258,7 @@ def store_pre_commit_state(conn, state):
|
||||
commit_id = state['commit_id']
|
||||
return conn.run(
|
||||
conn.collection('pre_commit')
|
||||
.update({'commit_id': commit_id}, state, upsert=True)
|
||||
.replace_one({'commit_id': commit_id}, state, upsert=True)
|
||||
)
|
||||
|
||||
|
||||
|
||||
@ -58,7 +58,7 @@ def test_write_assets():
|
||||
cursor = conn.db.assets.find({}, projection={'_id': False})\
|
||||
.sort('id', pymongo.ASCENDING)
|
||||
|
||||
assert cursor.count() == 3
|
||||
assert cursor.collection.count_documents({}) == 3
|
||||
assert list(cursor) == assets[:-1]
|
||||
|
||||
|
||||
@ -180,7 +180,7 @@ def test_write_metadata():
|
||||
cursor = conn.db.metadata.find({}, projection={'_id': False})\
|
||||
.sort('id', pymongo.ASCENDING)
|
||||
|
||||
assert cursor.count() == 3
|
||||
assert cursor.collection.count_documents({}) == 3
|
||||
assert list(cursor) == metadata
|
||||
|
||||
|
||||
@ -244,7 +244,7 @@ def test_store_block():
|
||||
transactions=[])
|
||||
query.store_block(conn, block._asdict())
|
||||
cursor = conn.db.blocks.find({}, projection={'_id': False})
|
||||
assert cursor.count() == 1
|
||||
assert cursor.collection.count_documents({}) == 1
|
||||
|
||||
|
||||
def test_get_block():
|
||||
@ -267,14 +267,14 @@ def test_delete_zero_unspent_outputs(db_context, utxoset):
|
||||
unspent_outputs, utxo_collection = utxoset
|
||||
delete_res = query.delete_unspent_outputs(db_context.conn)
|
||||
assert delete_res is None
|
||||
assert utxo_collection.count() == 3
|
||||
assert utxo_collection.find(
|
||||
assert utxo_collection.count_documents({}) == 3
|
||||
assert utxo_collection.count_documents(
|
||||
{'$or': [
|
||||
{'transaction_id': 'a', 'output_index': 0},
|
||||
{'transaction_id': 'b', 'output_index': 0},
|
||||
{'transaction_id': 'a', 'output_index': 1},
|
||||
]}
|
||||
).count() == 3
|
||||
) == 3
|
||||
|
||||
|
||||
def test_delete_one_unspent_outputs(db_context, utxoset):
|
||||
@ -282,15 +282,15 @@ def test_delete_one_unspent_outputs(db_context, utxoset):
|
||||
unspent_outputs, utxo_collection = utxoset
|
||||
delete_res = query.delete_unspent_outputs(db_context.conn,
|
||||
unspent_outputs[0])
|
||||
assert delete_res['n'] == 1
|
||||
assert utxo_collection.find(
|
||||
assert delete_res.raw_result['n'] == 1
|
||||
assert utxo_collection.count_documents(
|
||||
{'$or': [
|
||||
{'transaction_id': 'a', 'output_index': 1},
|
||||
{'transaction_id': 'b', 'output_index': 0},
|
||||
]}
|
||||
).count() == 2
|
||||
assert utxo_collection.find(
|
||||
{'transaction_id': 'a', 'output_index': 0}).count() == 0
|
||||
) == 2
|
||||
assert utxo_collection.count_documents(
|
||||
{'transaction_id': 'a', 'output_index': 0}) == 0
|
||||
|
||||
|
||||
def test_delete_many_unspent_outputs(db_context, utxoset):
|
||||
@ -298,22 +298,22 @@ def test_delete_many_unspent_outputs(db_context, utxoset):
|
||||
unspent_outputs, utxo_collection = utxoset
|
||||
delete_res = query.delete_unspent_outputs(db_context.conn,
|
||||
*unspent_outputs[::2])
|
||||
assert delete_res['n'] == 2
|
||||
assert utxo_collection.find(
|
||||
assert delete_res.raw_result['n'] == 2
|
||||
assert utxo_collection.count_documents(
|
||||
{'$or': [
|
||||
{'transaction_id': 'a', 'output_index': 0},
|
||||
{'transaction_id': 'b', 'output_index': 0},
|
||||
]}
|
||||
).count() == 0
|
||||
assert utxo_collection.find(
|
||||
{'transaction_id': 'a', 'output_index': 1}).count() == 1
|
||||
) == 0
|
||||
assert utxo_collection.count_documents(
|
||||
{'transaction_id': 'a', 'output_index': 1}) == 1
|
||||
|
||||
|
||||
def test_store_zero_unspent_output(db_context, utxo_collection):
|
||||
from bigchaindb.backend import query
|
||||
res = query.store_unspent_outputs(db_context.conn)
|
||||
assert res is None
|
||||
assert utxo_collection.count() == 0
|
||||
assert utxo_collection.count_documents({}) == 0
|
||||
|
||||
|
||||
def test_store_one_unspent_output(db_context,
|
||||
@ -322,10 +322,10 @@ def test_store_one_unspent_output(db_context,
|
||||
res = query.store_unspent_outputs(db_context.conn, unspent_output_1)
|
||||
assert res.acknowledged
|
||||
assert len(res.inserted_ids) == 1
|
||||
assert utxo_collection.find(
|
||||
assert utxo_collection.count_documents(
|
||||
{'transaction_id': unspent_output_1['transaction_id'],
|
||||
'output_index': unspent_output_1['output_index']}
|
||||
).count() == 1
|
||||
) == 1
|
||||
|
||||
|
||||
def test_store_many_unspent_outputs(db_context,
|
||||
@ -334,15 +334,15 @@ def test_store_many_unspent_outputs(db_context,
|
||||
res = query.store_unspent_outputs(db_context.conn, *unspent_outputs)
|
||||
assert res.acknowledged
|
||||
assert len(res.inserted_ids) == 3
|
||||
assert utxo_collection.find(
|
||||
assert utxo_collection.count_documents(
|
||||
{'transaction_id': unspent_outputs[0]['transaction_id']}
|
||||
).count() == 3
|
||||
) == 3
|
||||
|
||||
|
||||
def test_get_unspent_outputs(db_context, utxoset):
|
||||
from bigchaindb.backend import query
|
||||
cursor = query.get_unspent_outputs(db_context.conn)
|
||||
assert cursor.count() == 3
|
||||
assert cursor.collection.count_documents({}) == 3
|
||||
retrieved_utxoset = list(cursor)
|
||||
unspent_outputs, utxo_collection = utxoset
|
||||
assert retrieved_utxoset == list(
|
||||
@ -361,7 +361,7 @@ def test_store_pre_commit_state(db_context):
|
||||
query.store_pre_commit_state(db_context.conn, state._asdict())
|
||||
cursor = db_context.conn.db.pre_commit.find({'commit_id': 'test'},
|
||||
projection={'_id': False})
|
||||
assert cursor.count() == 1
|
||||
assert cursor.collection.count_documents({}) == 1
|
||||
|
||||
|
||||
def test_get_pre_commit_state(db_context):
|
||||
@ -372,7 +372,7 @@ def test_get_pre_commit_state(db_context):
|
||||
height=3,
|
||||
transactions=[])
|
||||
|
||||
db_context.conn.db.pre_commit.insert(state._asdict())
|
||||
db_context.conn.db.pre_commit.insert_one(state._asdict())
|
||||
resp = query.get_pre_commit_state(db_context.conn, 'test2')
|
||||
assert resp == state._asdict()
|
||||
|
||||
|
||||
@ -16,7 +16,7 @@ def test_init_creates_db_tables_and_indexes():
|
||||
|
||||
init_database()
|
||||
|
||||
collection_names = conn.conn[dbname].collection_names()
|
||||
collection_names = conn.conn[dbname].list_collection_names()
|
||||
assert set(collection_names) == {
|
||||
'transactions', 'assets', 'metadata', 'blocks', 'utxos', 'pre_commit',
|
||||
'validators', 'elections', 'abci_chains',
|
||||
@ -57,7 +57,7 @@ def test_init_database_is_graceful_if_db_exists():
|
||||
dbname = bigchaindb.config['database']['name']
|
||||
|
||||
# The db is set up by the fixtures
|
||||
assert dbname in conn.conn.database_names()
|
||||
assert dbname in conn.conn.list_database_names()
|
||||
|
||||
init_database()
|
||||
|
||||
@ -75,7 +75,7 @@ def test_create_tables():
|
||||
schema.create_database(conn, dbname)
|
||||
schema.create_tables(conn, dbname)
|
||||
|
||||
collection_names = conn.conn[dbname].collection_names()
|
||||
collection_names = conn.conn[dbname].list_collection_names()
|
||||
assert set(collection_names) == {
|
||||
'transactions', 'assets', 'metadata', 'blocks', 'utxos', 'validators', 'elections',
|
||||
'pre_commit', 'abci_chains',
|
||||
@ -115,6 +115,6 @@ def test_drop(dummy_db):
|
||||
from bigchaindb.backend import schema
|
||||
|
||||
conn = backend.connect()
|
||||
assert dummy_db in conn.conn.database_names()
|
||||
assert dummy_db in conn.conn.list_database_names()
|
||||
schema.drop_database(conn, dummy_db)
|
||||
assert dummy_db not in conn.conn.database_names()
|
||||
assert dummy_db not in conn.conn.list_database_names()
|
||||
|
||||
@ -485,10 +485,8 @@ def test_bigchain_tendermint_version(capsys):
|
||||
|
||||
|
||||
def mock_get_validators(height):
|
||||
keys = node_keys()
|
||||
pub_key = list(keys.keys())[0]
|
||||
return [
|
||||
{'public_key': {'value': pub_key,
|
||||
{'public_key': {'value': "zL/DasvKulXZzhSNFwx4cLRXKkSM9GPK7Y0nZ4FEylM=",
|
||||
'type': 'ed25519-base64'},
|
||||
'voting_power': 10}
|
||||
]
|
||||
|
||||
@ -198,16 +198,6 @@ def alice():
|
||||
return generate_key_pair()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def alice_privkey(alice):
|
||||
return alice.private_key
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def alice_pubkey(alice):
|
||||
return alice.public_key
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def bob():
|
||||
from bigchaindb.common.crypto import generate_key_pair
|
||||
@ -300,10 +290,10 @@ def inputs(user_pk, b, alice):
|
||||
for height in range(1, 4):
|
||||
transactions = [
|
||||
Transaction.create(
|
||||
[alice_pubkey(alice)],
|
||||
[alice.public_key],
|
||||
[([user_pk], 1)],
|
||||
metadata={'msg': random.random()},
|
||||
).sign([alice_privkey(alice)])
|
||||
).sign([alice.private_key])
|
||||
for _ in range(10)
|
||||
]
|
||||
tx_ids = [tx.id for tx in transactions]
|
||||
|
||||
@ -173,12 +173,12 @@ def test_update_utxoset(b, signed_create_tx, signed_transfer_tx, db_context):
|
||||
mongo_client = MongoClient(host=db_context.host, port=db_context.port)
|
||||
b.update_utxoset(signed_create_tx)
|
||||
utxoset = mongo_client[db_context.name]['utxos']
|
||||
assert utxoset.count() == 1
|
||||
assert utxoset.count_documents({}) == 1
|
||||
utxo = utxoset.find_one()
|
||||
assert utxo['transaction_id'] == signed_create_tx.id
|
||||
assert utxo['output_index'] == 0
|
||||
b.update_utxoset(signed_transfer_tx)
|
||||
assert utxoset.count() == 1
|
||||
assert utxoset.count_documents({}) == 1
|
||||
utxo = utxoset.find_one()
|
||||
assert utxo['transaction_id'] == signed_transfer_tx.id
|
||||
assert utxo['output_index'] == 0
|
||||
@ -195,7 +195,7 @@ def test_store_transaction(mocker, b, signed_create_tx,
|
||||
b.store_bulk_transactions([signed_create_tx])
|
||||
# mongo_client = MongoClient(host=db_context.host, port=db_context.port)
|
||||
# utxoset = mongo_client[db_context.name]['utxos']
|
||||
# assert utxoset.count() == 1
|
||||
# assert utxoset.count_documents({}) == 1
|
||||
# utxo = utxoset.find_one()
|
||||
# assert utxo['transaction_id'] == signed_create_tx.id
|
||||
# assert utxo['output_index'] == 0
|
||||
@ -217,7 +217,7 @@ def test_store_transaction(mocker, b, signed_create_tx,
|
||||
mocked_store_metadata.reset_mock()
|
||||
mocked_store_transaction.reset_mock()
|
||||
b.store_bulk_transactions([signed_transfer_tx])
|
||||
# assert utxoset.count() == 1
|
||||
# assert utxoset.count_documents({}) == 1
|
||||
# utxo = utxoset.find_one()
|
||||
# assert utxo['transaction_id'] == signed_transfer_tx.id
|
||||
# assert utxo['output_index'] == 0
|
||||
@ -245,7 +245,7 @@ def test_store_bulk_transaction(mocker, b, signed_create_tx,
|
||||
b.store_bulk_transactions((signed_create_tx,))
|
||||
# mongo_client = MongoClient(host=db_context.host, port=db_context.port)
|
||||
# utxoset = mongo_client[db_context.name]['utxos']
|
||||
# assert utxoset.count() == 1
|
||||
# assert utxoset.count_documents({}) == 1
|
||||
# utxo = utxoset.find_one()
|
||||
# assert utxo['transaction_id'] == signed_create_tx.id
|
||||
# assert utxo['output_index'] == 0
|
||||
@ -266,7 +266,7 @@ def test_store_bulk_transaction(mocker, b, signed_create_tx,
|
||||
mocked_store_metadata.reset_mock()
|
||||
mocked_store_transactions.reset_mock()
|
||||
b.store_bulk_transactions((signed_transfer_tx,))
|
||||
# assert utxoset.count() == 1
|
||||
# assert utxoset.count_documents({}) == 1
|
||||
# utxo = utxoset.find_one()
|
||||
# assert utxo['transaction_id'] == signed_transfer_tx.id
|
||||
# assert utxo['output_index'] == 0
|
||||
@ -288,51 +288,51 @@ def test_delete_zero_unspent_outputs(b, utxoset):
|
||||
unspent_outputs, utxo_collection = utxoset
|
||||
delete_res = b.delete_unspent_outputs()
|
||||
assert delete_res is None
|
||||
assert utxo_collection.count() == 3
|
||||
assert utxo_collection.find(
|
||||
assert utxo_collection.count_documents({}) == 3
|
||||
assert utxo_collection.count_documents(
|
||||
{'$or': [
|
||||
{'transaction_id': 'a', 'output_index': 0},
|
||||
{'transaction_id': 'b', 'output_index': 0},
|
||||
{'transaction_id': 'a', 'output_index': 1},
|
||||
]}
|
||||
).count() == 3
|
||||
) == 3
|
||||
|
||||
|
||||
@pytest.mark.bdb
|
||||
def test_delete_one_unspent_outputs(b, utxoset):
|
||||
unspent_outputs, utxo_collection = utxoset
|
||||
delete_res = b.delete_unspent_outputs(unspent_outputs[0])
|
||||
assert delete_res['n'] == 1
|
||||
assert utxo_collection.find(
|
||||
assert delete_res.raw_result['n'] == 1
|
||||
assert utxo_collection.count_documents(
|
||||
{'$or': [
|
||||
{'transaction_id': 'a', 'output_index': 1},
|
||||
{'transaction_id': 'b', 'output_index': 0},
|
||||
]}
|
||||
).count() == 2
|
||||
assert utxo_collection.find(
|
||||
{'transaction_id': 'a', 'output_index': 0}).count() == 0
|
||||
) == 2
|
||||
assert utxo_collection.count_documents(
|
||||
{'transaction_id': 'a', 'output_index': 0}) == 0
|
||||
|
||||
|
||||
@pytest.mark.bdb
|
||||
def test_delete_many_unspent_outputs(b, utxoset):
|
||||
unspent_outputs, utxo_collection = utxoset
|
||||
delete_res = b.delete_unspent_outputs(*unspent_outputs[::2])
|
||||
assert delete_res['n'] == 2
|
||||
assert utxo_collection.find(
|
||||
assert delete_res.raw_result['n'] == 2
|
||||
assert utxo_collection.count_documents(
|
||||
{'$or': [
|
||||
{'transaction_id': 'a', 'output_index': 0},
|
||||
{'transaction_id': 'b', 'output_index': 0},
|
||||
]}
|
||||
).count() == 0
|
||||
assert utxo_collection.find(
|
||||
{'transaction_id': 'a', 'output_index': 1}).count() == 1
|
||||
) == 0
|
||||
assert utxo_collection.count_documents(
|
||||
{'transaction_id': 'a', 'output_index': 1}) == 1
|
||||
|
||||
|
||||
@pytest.mark.bdb
|
||||
def test_store_zero_unspent_output(b, utxo_collection):
|
||||
res = b.store_unspent_outputs()
|
||||
assert res is None
|
||||
assert utxo_collection.count() == 0
|
||||
assert utxo_collection.count_documents({}) == 0
|
||||
|
||||
|
||||
@pytest.mark.bdb
|
||||
@ -340,10 +340,10 @@ def test_store_one_unspent_output(b, unspent_output_1, utxo_collection):
|
||||
res = b.store_unspent_outputs(unspent_output_1)
|
||||
assert res.acknowledged
|
||||
assert len(res.inserted_ids) == 1
|
||||
assert utxo_collection.find(
|
||||
assert utxo_collection.count_documents(
|
||||
{'transaction_id': unspent_output_1['transaction_id'],
|
||||
'output_index': unspent_output_1['output_index']}
|
||||
).count() == 1
|
||||
) == 1
|
||||
|
||||
|
||||
@pytest.mark.bdb
|
||||
@ -351,9 +351,9 @@ def test_store_many_unspent_outputs(b, unspent_outputs, utxo_collection):
|
||||
res = b.store_unspent_outputs(*unspent_outputs)
|
||||
assert res.acknowledged
|
||||
assert len(res.inserted_ids) == 3
|
||||
assert utxo_collection.find(
|
||||
assert utxo_collection.count_documents(
|
||||
{'transaction_id': unspent_outputs[0]['transaction_id']}
|
||||
).count() == 3
|
||||
) == 3
|
||||
|
||||
|
||||
def test_get_utxoset_merkle_root_when_no_utxo(b):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user