mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-27 07:42:14 +00:00
[indexer] order results by index if height is the same (#2900)
Fixes #2775
This commit is contained in:
parent
9570ac4d3e
commit
94e63be922
@ -37,5 +37,6 @@ program](https://hackerone.com/tendermint).
|
|||||||
- [blockchain] \#2731 Retry both blocks if either is bad to avoid getting stuck during fast sync (@goolAdapter)
|
- [blockchain] \#2731 Retry both blocks if either is bad to avoid getting stuck during fast sync (@goolAdapter)
|
||||||
- [log] \#2868 fix module=main setting overriding all others
|
- [log] \#2868 fix module=main setting overriding all others
|
||||||
- [rpc] \#2808 RPC validators calls IncrementAccum if necessary
|
- [rpc] \#2808 RPC validators calls IncrementAccum if necessary
|
||||||
|
- [kv indexer] \#2775 order results by index if height is the same
|
||||||
- [rpc] \#2759 fix tx.height range queries
|
- [rpc] \#2759 fix tx.height range queries
|
||||||
- [rpc] \#2811 Allow integer IDs in JSON-RPC requests
|
- [rpc] \#2811 Allow integer IDs in JSON-RPC requests
|
@ -207,8 +207,11 @@ func (txi *TxIndex) Search(q *query.Query) ([]*types.TxResult, error) {
|
|||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
|
|
||||||
// sort by height by default
|
// sort by height & index by default
|
||||||
sort.Slice(results, func(i, j int) bool {
|
sort.Slice(results, func(i, j int) bool {
|
||||||
|
if results[i].Height == results[j].Height {
|
||||||
|
return results[i].Index < results[j].Index
|
||||||
|
}
|
||||||
return results[i].Height < results[j].Height
|
return results[i].Height < results[j].Height
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -133,6 +133,7 @@ func TestTxSearchMultipleTxs(t *testing.T) {
|
|||||||
})
|
})
|
||||||
txResult.Tx = types.Tx("Bob's account")
|
txResult.Tx = types.Tx("Bob's account")
|
||||||
txResult.Height = 2
|
txResult.Height = 2
|
||||||
|
txResult.Index = 1
|
||||||
err := indexer.Index(txResult)
|
err := indexer.Index(txResult)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
@ -142,14 +143,26 @@ func TestTxSearchMultipleTxs(t *testing.T) {
|
|||||||
})
|
})
|
||||||
txResult2.Tx = types.Tx("Alice's account")
|
txResult2.Tx = types.Tx("Alice's account")
|
||||||
txResult2.Height = 1
|
txResult2.Height = 1
|
||||||
|
txResult2.Index = 2
|
||||||
|
|
||||||
err = indexer.Index(txResult2)
|
err = indexer.Index(txResult2)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// indexed third (to test the order of transactions)
|
||||||
|
txResult3 := txResultWithTags([]cmn.KVPair{
|
||||||
|
{Key: []byte("account.number"), Value: []byte("3")},
|
||||||
|
})
|
||||||
|
txResult3.Tx = types.Tx("Jack's account")
|
||||||
|
txResult3.Height = 1
|
||||||
|
txResult3.Index = 1
|
||||||
|
err = indexer.Index(txResult3)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
results, err := indexer.Search(query.MustParse("account.number >= 1"))
|
results, err := indexer.Search(query.MustParse("account.number >= 1"))
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
require.Len(t, results, 2)
|
require.Len(t, results, 3)
|
||||||
assert.Equal(t, []*types.TxResult{txResult2, txResult}, results)
|
assert.Equal(t, []*types.TxResult{txResult3, txResult2, txResult}, results)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIndexAllTags(t *testing.T) {
|
func TestIndexAllTags(t *testing.T) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user