mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Problem: unhandled error when storing zero utxo
Solution: only execute the query if *unspent_outputs is not empty
This commit is contained in:
parent
c85c664215
commit
aaec67724a
@ -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)
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user