mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Problem: unhandled error when deleting zero utxo
Solution: only execute the query if *unspent_outputs is not empty
This commit is contained in:
parent
aaec67724a
commit
2d2182dd19
@ -243,17 +243,17 @@ def store_unspent_outputs(conn, *unspent_outputs):
|
|||||||
|
|
||||||
@register_query(LocalMongoDBConnection)
|
@register_query(LocalMongoDBConnection)
|
||||||
def delete_unspent_outputs(conn, *unspent_outputs):
|
def delete_unspent_outputs(conn, *unspent_outputs):
|
||||||
cursor = conn.run(
|
if unspent_outputs:
|
||||||
conn.collection('utxos').remove(
|
return conn.run(
|
||||||
{'$or': [
|
conn.collection('utxos').remove({
|
||||||
{'$and': [
|
'$or': [{
|
||||||
|
'$and': [
|
||||||
{'transaction_id': unspent_output['transaction_id']},
|
{'transaction_id': unspent_output['transaction_id']},
|
||||||
{'output_index': unspent_output['output_index']}
|
{'output_index': unspent_output['output_index']},
|
||||||
]}
|
],
|
||||||
for unspent_output in unspent_outputs
|
} for unspent_output in unspent_outputs]
|
||||||
]}
|
})
|
||||||
))
|
)
|
||||||
return cursor
|
|
||||||
|
|
||||||
|
|
||||||
@register_query(LocalMongoDBConnection)
|
@register_query(LocalMongoDBConnection)
|
||||||
|
@ -224,7 +224,38 @@ def test_delete_latest_block(signed_create_tx, signed_transfer_tx):
|
|||||||
assert query.get_block(conn, 51) is None
|
assert query.get_block(conn, 51) is None
|
||||||
|
|
||||||
|
|
||||||
def test_delete_unspent_outputs(db_context, utxoset):
|
def test_delete_zero_unspent_outputs(db_context, utxoset):
|
||||||
|
from bigchaindb.backend import query
|
||||||
|
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(
|
||||||
|
{'$or': [
|
||||||
|
{'transaction_id': 'a', 'output_index': 0},
|
||||||
|
{'transaction_id': 'b', 'output_index': 0},
|
||||||
|
{'transaction_id': 'a', 'output_index': 1},
|
||||||
|
]}
|
||||||
|
).count() == 3
|
||||||
|
|
||||||
|
|
||||||
|
def test_delete_one_unspent_outputs(db_context, utxoset):
|
||||||
|
from bigchaindb.backend import query
|
||||||
|
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(
|
||||||
|
{'$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
|
||||||
|
|
||||||
|
|
||||||
|
def test_delete_many_unspent_outputs(db_context, utxoset):
|
||||||
from bigchaindb.backend import query
|
from bigchaindb.backend import query
|
||||||
unspent_outputs, utxo_collection = utxoset
|
unspent_outputs, utxo_collection = utxoset
|
||||||
delete_res = query.delete_unspent_outputs(db_context.conn,
|
delete_res = query.delete_unspent_outputs(db_context.conn,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user