mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Problem: No unique indexes on transaction id and block height (#2492)
Solution: Created unique indexes when setting up the collections
This commit is contained in:
parent
3f7b521809
commit
3cf368aab7
@ -59,6 +59,7 @@ def create_transactions_secondary_index(conn, dbname):
|
||||
|
||||
# to query the transactions for a transaction id, this field is unique
|
||||
conn.conn[dbname]['transactions'].create_index('id',
|
||||
unique=True,
|
||||
name='transaction_id')
|
||||
|
||||
# secondary index for asset uuid, this field is unique
|
||||
@ -93,7 +94,7 @@ def create_assets_secondary_index(conn, dbname):
|
||||
|
||||
def create_blocks_secondary_index(conn, dbname):
|
||||
conn.conn[dbname]['blocks']\
|
||||
.create_index([('height', DESCENDING)], name='height')
|
||||
.create_index([('height', DESCENDING)], name='height', unique=True)
|
||||
|
||||
|
||||
def create_metadata_secondary_index(conn, dbname):
|
||||
|
@ -218,9 +218,9 @@ def test_get_spending_transactions(user_pk, user_sk):
|
||||
tx1 = Transaction.create([user_pk], out * 3)
|
||||
tx1.sign([user_sk])
|
||||
inputs = tx1.to_inputs()
|
||||
tx2 = Transaction.transfer([inputs[0]], out, tx1.id)
|
||||
tx3 = Transaction.transfer([inputs[1]], out, tx1.id)
|
||||
tx4 = Transaction.transfer([inputs[2]], out, tx1.id)
|
||||
tx2 = Transaction.transfer([inputs[0]], out, tx1.id).sign([user_sk])
|
||||
tx3 = Transaction.transfer([inputs[1]], out, tx1.id).sign([user_sk])
|
||||
tx4 = Transaction.transfer([inputs[2]], out, tx1.id).sign([user_sk])
|
||||
txns = [tx.to_dict() for tx in [tx1, tx2, tx3, tx4]]
|
||||
conn.db.transactions.insert_many(txns)
|
||||
|
||||
|
@ -99,12 +99,16 @@ def test_create_secondary_indexes():
|
||||
indexes = conn.conn[dbname]['assets'].index_information().keys()
|
||||
assert set(indexes) == {'_id_', 'asset_id', 'text'}
|
||||
|
||||
indexes = conn.conn[dbname]['transactions'].index_information().keys()
|
||||
index_info = conn.conn[dbname]['transactions'].index_information()
|
||||
indexes = index_info.keys()
|
||||
assert set(indexes) == {
|
||||
'_id_', 'transaction_id', 'asset_id', 'outputs', 'inputs'}
|
||||
assert index_info['transaction_id']['unique']
|
||||
|
||||
indexes = conn.conn[dbname]['blocks'].index_information().keys()
|
||||
index_info = conn.conn[dbname]['blocks'].index_information()
|
||||
indexes = index_info.keys()
|
||||
assert set(indexes) == {'_id_', 'height'}
|
||||
assert index_info['height']['unique']
|
||||
|
||||
index_info = conn.conn[dbname]['utxos'].index_information()
|
||||
assert set(index_info.keys()) == {'_id_', 'utxo'}
|
||||
|
Loading…
x
Reference in New Issue
Block a user