use newQuery...Params
This commit is contained in:
parent
182f111ddc
commit
7dfeb7d27d
|
@ -127,9 +127,7 @@ func GetCmdQueryValidatorUnbondingDelegations(queryRoute string, cdc *codec.Code
|
|||
}
|
||||
|
||||
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
||||
params := stake.QueryValidatorParams{
|
||||
ValidatorAddr: valAddr,
|
||||
}
|
||||
params := stake.NewQueryValidatorParams(valAddr)
|
||||
|
||||
bz, err := cdc.MarshalJSON(params)
|
||||
if err != nil {
|
||||
|
@ -164,9 +162,7 @@ func GetCmdQueryValidatorRedelegations(queryRoute string, cdc *codec.Codec) *cob
|
|||
}
|
||||
|
||||
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
||||
params := stake.QueryValidatorParams{
|
||||
ValidatorAddr: valAddr,
|
||||
}
|
||||
params := stake.NewQueryValidatorParams(valAddr)
|
||||
|
||||
bz, err := cdc.MarshalJSON(params)
|
||||
if err != nil {
|
||||
|
@ -303,9 +299,7 @@ func GetCmdQueryValidatorDelegations(queryRoute string, cdc *codec.Codec) *cobra
|
|||
return err
|
||||
}
|
||||
|
||||
params := stake.QueryValidatorParams{
|
||||
ValidatorAddr: validatorAddr,
|
||||
}
|
||||
params := stake.NewQueryValidatorParams(validatorAddr)
|
||||
|
||||
bz, err := cdc.MarshalJSON(params)
|
||||
if err != nil {
|
||||
|
|
|
@ -62,10 +62,7 @@ func queryBonds(cliCtx context.CLIContext, cdc *codec.Codec, endpoint string) ht
|
|||
return
|
||||
}
|
||||
|
||||
params := stake.QueryBondsParams{
|
||||
DelegatorAddr: delegatorAddr,
|
||||
ValidatorAddr: validatorAddr,
|
||||
}
|
||||
params := stake.NewQueryBondsParams(delegatorAddr, validatorAddr)
|
||||
|
||||
bz, err := cdc.MarshalJSON(params)
|
||||
if err != nil {
|
||||
|
@ -93,9 +90,7 @@ func queryDelegator(cliCtx context.CLIContext, cdc *codec.Codec, endpoint string
|
|||
return
|
||||
}
|
||||
|
||||
params := stake.QueryDelegatorParams{
|
||||
DelegatorAddr: delegatorAddr,
|
||||
}
|
||||
params := stake.NewQueryDelegatorParams(delegatorAddr)
|
||||
|
||||
bz, err := cdc.MarshalJSON(params)
|
||||
if err != nil {
|
||||
|
@ -123,9 +118,7 @@ func queryValidator(cliCtx context.CLIContext, cdc *codec.Codec, endpoint string
|
|||
return
|
||||
}
|
||||
|
||||
params := stake.QueryValidatorParams{
|
||||
ValidatorAddr: validatorAddr,
|
||||
}
|
||||
params := stake.NewQueryValidatorParams(validatorAddr)
|
||||
|
||||
bz, err := cdc.MarshalJSON(params)
|
||||
if err != nil {
|
||||
|
|
|
@ -92,6 +92,28 @@ type QueryBondsParams struct {
|
|||
ValidatorAddr sdk.ValAddress
|
||||
}
|
||||
|
||||
// creates a new QueryDelegatorParams
|
||||
func NewQueryDelegatorParams(delegatorAddr sdk.AccAddress) QueryDelegatorParams {
|
||||
return QueryDelegatorParams{
|
||||
DelegatorAddr: delegatorAddr,
|
||||
}
|
||||
}
|
||||
|
||||
// creates a new QueryValidatorParams
|
||||
func NewQueryValidatorParams(validatorAddr sdk.ValAddress) QueryValidatorParams {
|
||||
return QueryValidatorParams{
|
||||
ValidatorAddr: validatorAddr,
|
||||
}
|
||||
}
|
||||
|
||||
// creates a new QueryBondsParams
|
||||
func NewQueryBondsParams(delegatorAddr sdk.AccAddress, validatorAddr sdk.ValAddress) QueryBondsParams {
|
||||
return QueryBondsParams{
|
||||
DelegatorAddr: delegatorAddr,
|
||||
ValidatorAddr: validatorAddr,
|
||||
}
|
||||
}
|
||||
|
||||
func queryValidators(ctx sdk.Context, cdc *codec.Codec, k keep.Keeper) (res []byte, err sdk.Error) {
|
||||
stakeParams := k.GetParams(ctx)
|
||||
validators := k.GetValidators(ctx, stakeParams.MaxValidators)
|
||||
|
|
|
@ -17,25 +17,6 @@ var (
|
|||
pk1, pk2 = keep.PKs[0], keep.PKs[1]
|
||||
)
|
||||
|
||||
func newTestDelegatorQuery(delegatorAddr sdk.AccAddress) QueryDelegatorParams {
|
||||
return QueryDelegatorParams{
|
||||
DelegatorAddr: delegatorAddr,
|
||||
}
|
||||
}
|
||||
|
||||
func newTestValidatorQuery(validatorAddr sdk.ValAddress) QueryValidatorParams {
|
||||
return QueryValidatorParams{
|
||||
ValidatorAddr: validatorAddr,
|
||||
}
|
||||
}
|
||||
|
||||
func newTestBondQuery(delegatorAddr sdk.AccAddress, validatorAddr sdk.ValAddress) QueryBondsParams {
|
||||
return QueryBondsParams{
|
||||
DelegatorAddr: delegatorAddr,
|
||||
ValidatorAddr: validatorAddr,
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewQuerier(t *testing.T) {
|
||||
cdc := codec.New()
|
||||
ctx, _, keeper := keep.CreateTestInput(t, false, 1000)
|
||||
|
@ -72,7 +53,7 @@ func TestNewQuerier(t *testing.T) {
|
|||
_, err = querier(ctx, []string{"parameters"}, query)
|
||||
require.Nil(t, err)
|
||||
|
||||
queryValParams := newTestValidatorQuery(addrVal1)
|
||||
queryValParams := NewQueryValidatorParams(addrVal1)
|
||||
bz, errRes := cdc.MarshalJSON(queryValParams)
|
||||
require.Nil(t, errRes)
|
||||
|
||||
|
@ -91,7 +72,7 @@ func TestNewQuerier(t *testing.T) {
|
|||
_, err = querier(ctx, []string{"validatorRedelegations"}, query)
|
||||
require.Nil(t, err)
|
||||
|
||||
queryDelParams := newTestDelegatorQuery(addrAcc2)
|
||||
queryDelParams := NewQueryDelegatorParams(addrAcc2)
|
||||
bz, errRes = cdc.MarshalJSON(queryDelParams)
|
||||
require.Nil(t, errRes)
|
||||
|
||||
|
@ -163,7 +144,7 @@ func TestQueryValidators(t *testing.T) {
|
|||
require.ElementsMatch(t, queriedValidators, validatorsResp)
|
||||
|
||||
// Query each validator
|
||||
queryParams := newTestValidatorQuery(addrVal1)
|
||||
queryParams := NewQueryValidatorParams(addrVal1)
|
||||
bz, errRes := cdc.MarshalJSON(queryParams)
|
||||
require.Nil(t, errRes)
|
||||
|
||||
|
@ -203,7 +184,7 @@ func TestQueryDelegation(t *testing.T) {
|
|||
keeper.ApplyAndReturnValidatorSetUpdates(ctx)
|
||||
|
||||
// Query Delegator bonded validators
|
||||
queryParams := newTestDelegatorQuery(addrAcc2)
|
||||
queryParams := NewQueryDelegatorParams(addrAcc2)
|
||||
bz, errRes := cdc.MarshalJSON(queryParams)
|
||||
require.Nil(t, errRes)
|
||||
|
||||
|
@ -231,7 +212,7 @@ func TestQueryDelegation(t *testing.T) {
|
|||
require.NotNil(t, err)
|
||||
|
||||
// Query bonded validator
|
||||
queryBondParams := newTestBondQuery(addrAcc2, addrVal1)
|
||||
queryBondParams := NewQueryBondsParams(addrAcc2, addrVal1)
|
||||
bz, errRes = cdc.MarshalJSON(queryBondParams)
|
||||
require.Nil(t, errRes)
|
||||
|
||||
|
@ -298,7 +279,7 @@ func TestQueryDelegation(t *testing.T) {
|
|||
|
||||
// Query validator delegations
|
||||
|
||||
bz, errRes = cdc.MarshalJSON(newTestValidatorQuery(addrVal1))
|
||||
bz, errRes = cdc.MarshalJSON(NewQueryValidatorParams(addrVal1))
|
||||
require.Nil(t, errRes)
|
||||
|
||||
query = abci.RequestQuery{
|
||||
|
@ -318,7 +299,7 @@ func TestQueryDelegation(t *testing.T) {
|
|||
// Query unbonging delegation
|
||||
keeper.BeginUnbonding(ctx, addrAcc2, val1.OperatorAddr, sdk.NewDec(10))
|
||||
|
||||
queryBondParams = newTestBondQuery(addrAcc2, addrVal1)
|
||||
queryBondParams = NewQueryBondsParams(addrAcc2, addrVal1)
|
||||
bz, errRes = cdc.MarshalJSON(queryBondParams)
|
||||
require.Nil(t, errRes)
|
||||
|
||||
|
@ -387,7 +368,7 @@ func TestQueryRedelegations(t *testing.T) {
|
|||
require.True(t, found)
|
||||
|
||||
// delegator redelegations
|
||||
queryDelegatorParams := newTestDelegatorQuery(addrAcc2)
|
||||
queryDelegatorParams := NewQueryDelegatorParams(addrAcc2)
|
||||
bz, errRes := cdc.MarshalJSON(queryDelegatorParams)
|
||||
require.Nil(t, errRes)
|
||||
|
||||
|
@ -406,7 +387,7 @@ func TestQueryRedelegations(t *testing.T) {
|
|||
require.Equal(t, redelegation, redsRes[0])
|
||||
|
||||
// validator redelegations
|
||||
queryValidatorParams := newTestValidatorQuery(val1.GetOperator())
|
||||
queryValidatorParams := NewQueryValidatorParams(val1.GetOperator())
|
||||
bz, errRes = cdc.MarshalJSON(queryValidatorParams)
|
||||
require.Nil(t, errRes)
|
||||
|
||||
|
|
|
@ -84,7 +84,10 @@ var (
|
|||
NewMsgBeginUnbonding = types.NewMsgBeginUnbonding
|
||||
NewMsgBeginRedelegate = types.NewMsgBeginRedelegate
|
||||
|
||||
NewQuerier = querier.NewQuerier
|
||||
NewQuerier = querier.NewQuerier
|
||||
NewQueryDelegatorParams = querier.NewQueryDelegatorParams
|
||||
NewQueryValidatorParams = querier.NewQueryValidatorParams
|
||||
NewQueryBondsParams = querier.NewQueryBondsParams
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
Loading…
Reference in New Issue