mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-25 06:42:16 +00:00
Hotfix/validating query result length (#3053)
* Validating that there are txs in the query results before loop throught the array * Created tests to validate the error has been fixed * Added comments * Fixing misspeling * check if the variable "skipCount" is bigger than zero. If it is not, we set it to 0. If it, we do not do anything. * using function that validates the skipCount variable * undo Gopkg.lock changes
This commit is contained in:
parent
a6011c007d
commit
be00cd1add
@ -33,6 +33,8 @@ Special thanks to external contributors on this release:
|
|||||||
- [rpc] \#3047 Include peer's remote IP in `/net_info`
|
- [rpc] \#3047 Include peer's remote IP in `/net_info`
|
||||||
|
|
||||||
### BUG FIXES:
|
### BUG FIXES:
|
||||||
|
|
||||||
- [types] \#2926 do not panic if retrieving the private validator's public key fails
|
- [types] \#2926 do not panic if retrieving the private validator's public key fails
|
||||||
|
- [rpc] \#3080 check if the variable "skipCount" is bigger than zero. If it is not, we set it to 0. If it, we do not do anything.
|
||||||
- [crypto/multisig] \#3102 fix multisig keys address length
|
- [crypto/multisig] \#3102 fix multisig keys address length
|
||||||
- [crypto/encoding] \#3101 Fix `PubKeyMultisigThreshold` unmarshalling into `crypto.PubKey` interface
|
- [crypto/encoding] \#3101 Fix `PubKeyMultisigThreshold` unmarshalling into `crypto.PubKey` interface
|
||||||
|
@ -428,5 +428,10 @@ func TestTxSearch(t *testing.T) {
|
|||||||
if len(result.Txs) == 0 {
|
if len(result.Txs) == 0 {
|
||||||
t.Fatal("expected a lot of transactions")
|
t.Fatal("expected a lot of transactions")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// query a non existing tx with page 1 and txsPerPage 1
|
||||||
|
result, err = c.TxSearch("app.creator='Cosmoshi Neetowoko'", true, 1, 1)
|
||||||
|
require.Nil(t, err, "%+v", err)
|
||||||
|
require.Len(t, result.Txs, 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -154,3 +154,12 @@ func validatePerPage(perPage int) int {
|
|||||||
}
|
}
|
||||||
return perPage
|
return perPage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func validateSkipCount(page, perPage int) int {
|
||||||
|
skipCount := (page - 1) * perPage
|
||||||
|
if skipCount < 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
return skipCount
|
||||||
|
}
|
||||||
|
@ -201,10 +201,11 @@ func TxSearch(query string, prove bool, page, perPage int) (*ctypes.ResultTxSear
|
|||||||
totalCount := len(results)
|
totalCount := len(results)
|
||||||
perPage = validatePerPage(perPage)
|
perPage = validatePerPage(perPage)
|
||||||
page = validatePage(page, perPage, totalCount)
|
page = validatePage(page, perPage, totalCount)
|
||||||
skipCount := (page - 1) * perPage
|
skipCount := validateSkipCount(page, perPage)
|
||||||
|
|
||||||
apiResults := make([]*ctypes.ResultTx, cmn.MinInt(perPage, totalCount-skipCount))
|
apiResults := make([]*ctypes.ResultTx, cmn.MinInt(perPage, totalCount-skipCount))
|
||||||
var proof types.TxProof
|
var proof types.TxProof
|
||||||
|
// if there's no tx in the results array, we don't need to loop through the apiResults array
|
||||||
for i := 0; i < len(apiResults); i++ {
|
for i := 0; i < len(apiResults); i++ {
|
||||||
r := results[skipCount+i]
|
r := results[skipCount+i]
|
||||||
height := r.Height
|
height := r.Height
|
||||||
|
Loading…
x
Reference in New Issue
Block a user