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,10 +228,14 @@ def delete_transactions(conn, txn_ids):
|
|||||||
|
|
||||||
@register_query(LocalMongoDBConnection)
|
@register_query(LocalMongoDBConnection)
|
||||||
def store_unspent_outputs(conn, *unspent_outputs):
|
def store_unspent_outputs(conn, *unspent_outputs):
|
||||||
|
if unspent_outputs:
|
||||||
try:
|
try:
|
||||||
return conn.run(
|
return conn.run(
|
||||||
conn.collection('utxos')
|
conn.collection('utxos').insert_many(
|
||||||
.insert_many(unspent_outputs, ordered=False))
|
unspent_outputs,
|
||||||
|
ordered=False,
|
||||||
|
)
|
||||||
|
)
|
||||||
except DuplicateKeyError:
|
except DuplicateKeyError:
|
||||||
# TODO log warning at least
|
# TODO log warning at least
|
||||||
pass
|
pass
|
||||||
|
@ -240,6 +240,13 @@ def test_delete_unspent_outputs(db_context, utxoset):
|
|||||||
{'transaction_id': 'a', 'output_index': 1}).count() == 1
|
{'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,
|
def test_store_one_unspent_output(db_context,
|
||||||
unspent_output_1, utxo_collection):
|
unspent_output_1, utxo_collection):
|
||||||
from bigchaindb.backend import query
|
from bigchaindb.backend import query
|
||||||
|
Loading…
x
Reference in New Issue
Block a user