2019-11-06 13:08:02 -08:00
|
|
|
package keeper_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
2020-06-18 13:29:41 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/simapp"
|
2020-04-27 12:40:50 -07:00
|
|
|
|
2019-11-06 13:08:02 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/evidence/exported"
|
2020-02-24 08:05:21 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/evidence/types"
|
2019-11-06 13:08:02 -08:00
|
|
|
|
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
custom = "custom"
|
|
|
|
)
|
|
|
|
|
2020-07-10 06:52:59 -07:00
|
|
|
func (suite *KeeperTestSuite) TestQuerier_QueryEvidence_Existing() {
|
2019-11-06 13:08:02 -08:00
|
|
|
ctx := suite.ctx.WithIsCheckTx(false)
|
|
|
|
numEvidence := 100
|
2021-01-07 13:50:52 -08:00
|
|
|
legacyCdc := simapp.MakeTestEncodingConfig().Amino
|
2019-11-06 13:08:02 -08:00
|
|
|
|
|
|
|
evidence := suite.populateEvidence(ctx, numEvidence)
|
|
|
|
query := abci.RequestQuery{
|
|
|
|
Path: strings.Join([]string{custom, types.QuerierRoute, types.QueryEvidence}, "/"),
|
2021-01-07 13:50:52 -08:00
|
|
|
Data: legacyCdc.MustMarshalJSON(types.NewQueryEvidenceRequest(evidence[0].Hash())),
|
2019-11-06 13:08:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
bz, err := suite.querier(ctx, []string{types.QueryEvidence}, query)
|
|
|
|
suite.Nil(err)
|
|
|
|
suite.NotNil(bz)
|
|
|
|
|
|
|
|
var e exported.Evidence
|
2021-01-07 13:50:52 -08:00
|
|
|
suite.Nil(legacyCdc.UnmarshalJSON(bz, &e))
|
2019-11-06 13:08:02 -08:00
|
|
|
suite.Equal(evidence[0], e)
|
|
|
|
}
|
|
|
|
|
2020-07-10 06:52:59 -07:00
|
|
|
func (suite *KeeperTestSuite) TestQuerier_QueryEvidence_NonExisting() {
|
2019-11-06 13:08:02 -08:00
|
|
|
ctx := suite.ctx.WithIsCheckTx(false)
|
2021-07-01 01:52:38 -07:00
|
|
|
cdc := simapp.MakeTestEncodingConfig().Codec
|
2019-11-06 13:08:02 -08:00
|
|
|
numEvidence := 100
|
|
|
|
|
|
|
|
suite.populateEvidence(ctx, numEvidence)
|
|
|
|
query := abci.RequestQuery{
|
|
|
|
Path: strings.Join([]string{custom, types.QuerierRoute, types.QueryEvidence}, "/"),
|
2020-07-10 06:52:59 -07:00
|
|
|
Data: cdc.MustMarshalJSON(types.NewQueryEvidenceRequest([]byte("0000000000000000000000000000000000000000000000000000000000000000"))),
|
2019-11-06 13:08:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
bz, err := suite.querier(ctx, []string{types.QueryEvidence}, query)
|
|
|
|
suite.NotNil(err)
|
|
|
|
suite.Nil(bz)
|
|
|
|
}
|
|
|
|
|
2020-07-10 06:52:59 -07:00
|
|
|
func (suite *KeeperTestSuite) TestQuerier_QueryAllEvidence() {
|
2019-11-06 13:08:02 -08:00
|
|
|
ctx := suite.ctx.WithIsCheckTx(false)
|
2021-01-07 13:50:52 -08:00
|
|
|
cdc := simapp.MakeTestEncodingConfig().Amino
|
2019-11-06 13:08:02 -08:00
|
|
|
numEvidence := 100
|
|
|
|
|
|
|
|
suite.populateEvidence(ctx, numEvidence)
|
|
|
|
query := abci.RequestQuery{
|
|
|
|
Path: strings.Join([]string{custom, types.QuerierRoute, types.QueryAllEvidence}, "/"),
|
2020-02-24 08:05:21 -08:00
|
|
|
Data: cdc.MustMarshalJSON(types.NewQueryAllEvidenceParams(1, numEvidence)),
|
2019-11-06 13:08:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
bz, err := suite.querier(ctx, []string{types.QueryAllEvidence}, query)
|
|
|
|
suite.Nil(err)
|
|
|
|
suite.NotNil(bz)
|
|
|
|
|
|
|
|
var e []exported.Evidence
|
2020-02-24 08:05:21 -08:00
|
|
|
suite.Nil(cdc.UnmarshalJSON(bz, &e))
|
2019-11-06 13:08:02 -08:00
|
|
|
suite.Len(e, numEvidence)
|
|
|
|
}
|
|
|
|
|
2020-07-10 06:52:59 -07:00
|
|
|
func (suite *KeeperTestSuite) TestQuerier_QueryAllEvidence_InvalidPagination() {
|
2019-11-06 13:08:02 -08:00
|
|
|
ctx := suite.ctx.WithIsCheckTx(false)
|
2021-01-07 13:50:52 -08:00
|
|
|
cdc := simapp.MakeTestEncodingConfig().Amino
|
2019-11-06 13:08:02 -08:00
|
|
|
numEvidence := 100
|
|
|
|
|
|
|
|
suite.populateEvidence(ctx, numEvidence)
|
|
|
|
query := abci.RequestQuery{
|
|
|
|
Path: strings.Join([]string{custom, types.QuerierRoute, types.QueryAllEvidence}, "/"),
|
2020-02-24 08:05:21 -08:00
|
|
|
Data: cdc.MustMarshalJSON(types.NewQueryAllEvidenceParams(0, numEvidence)),
|
2019-11-06 13:08:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
bz, err := suite.querier(ctx, []string{types.QueryAllEvidence}, query)
|
|
|
|
suite.Nil(err)
|
|
|
|
suite.NotNil(bz)
|
|
|
|
|
|
|
|
var e []exported.Evidence
|
2020-02-24 08:05:21 -08:00
|
|
|
suite.Nil(cdc.UnmarshalJSON(bz, &e))
|
2019-11-06 13:08:02 -08:00
|
|
|
suite.Len(e, 0)
|
|
|
|
}
|