Problem: unhandled error when storing zero utxo

Solution: only execute the query if *unspent_outputs is not empty
This commit is contained in:
Sylvain Bellemare 2018-02-28 23:14:22 +01:00
parent c85c664215
commit aaec67724a
2 changed files with 18 additions and 7 deletions

View File

@ -228,13 +228,17 @@ def delete_transactions(conn, txn_ids):
@register_query(LocalMongoDBConnection)
def store_unspent_outputs(conn, *unspent_outputs):
try:
return conn.run(
conn.collection('utxos')
.insert_many(unspent_outputs, ordered=False))
except DuplicateKeyError:
# TODO log warning at least
pass
if unspent_outputs:
try:
return conn.run(
conn.collection('utxos').insert_many(
unspent_outputs,
ordered=False,
)
)
except DuplicateKeyError:
# TODO log warning at least
pass
@register_query(LocalMongoDBConnection)

View File

@ -240,6 +240,13 @@ def test_delete_unspent_outputs(db_context, utxoset):
{'transaction_id': 'a', 'output_index': 1}).count() == 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
def test_store_one_unspent_output(db_context,
unspent_output_1, utxo_collection):
from bigchaindb.backend import query