rename and temp commit
This commit is contained in:
parent
7f8d0e6047
commit
cdcbecb2f4
|
@ -202,215 +202,218 @@ func TestQueryValidators(t *testing.T) {
|
||||||
require.Equal(t, queriedValidators[0], validator)
|
require.Equal(t, queriedValidators[0], validator)
|
||||||
}
|
}
|
||||||
|
|
||||||
//func TestQueryDelegation(t *testing.T) {
|
func TestQueryDelegation(t *testing.T) {
|
||||||
// cdc := codec.New()
|
cdc := codec.New()
|
||||||
// app := simapp.Setup(false)
|
app := simapp.Setup(false)
|
||||||
// ctx := app.BaseApp.NewContext(false, abci.Header{})
|
ctx := app.BaseApp.NewContext(false, abci.Header{})
|
||||||
// params := app.StakingKeeper.GetParams(ctx)
|
params := app.StakingKeeper.GetParams(ctx)
|
||||||
// querier := staking.NewQuerier(app.StakingKeeper)
|
querier := staking.NewQuerier(app.StakingKeeper)
|
||||||
//
|
|
||||||
// // Create Validators and Delegation
|
addrs := simapp.AddTestAddrs(app, ctx, 500, sdk.NewInt(10000))
|
||||||
// val1 := types.NewValidator(addrVal1, pk1, types.Description{})
|
|
||||||
// app.StakingKeeper.SetValidator(ctx, val1)
|
|
||||||
// app.StakingKeeper.SetValidatorByPowerIndex(ctx, val1)
|
// Create Validators and Delegation
|
||||||
//
|
val1 := types.NewValidator(addrVal1, pk1, types.Description{})
|
||||||
// val2 := types.NewValidator(addrVal2, pk2, types.Description{})
|
app.StakingKeeper.SetValidator(ctx, val1)
|
||||||
// app.StakingKeeper.SetValidator(ctx, val2)
|
app.StakingKeeper.SetValidatorByPowerIndex(ctx, val1)
|
||||||
// app.StakingKeeper.SetValidatorByPowerIndex(ctx, val2)
|
|
||||||
//
|
val2 := types.NewValidator(addrVal2, pk2, types.Description{})
|
||||||
// delTokens := sdk.TokensFromConsensusPower(20)
|
app.StakingKeeper.SetValidator(ctx, val2)
|
||||||
// app.StakingKeeper.Delegate(ctx, addrAcc2, delTokens, sdk.Unbonded, val1, true)
|
app.StakingKeeper.SetValidatorByPowerIndex(ctx, val2)
|
||||||
//
|
|
||||||
// // apply TM updates
|
delTokens := sdk.TokensFromConsensusPower(20)
|
||||||
// app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx)
|
app.StakingKeeper.Delegate(ctx, addrAcc2, delTokens, sdk.Unbonded, val1, true)
|
||||||
//
|
|
||||||
// // Query Delegator bonded validators
|
// apply TM updates
|
||||||
// queryParams := types.NewQueryDelegatorParams(addrAcc2)
|
app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx)
|
||||||
// bz, errRes := cdc.MarshalJSON(queryParams)
|
|
||||||
// require.NoError(t, errRes)
|
// Query Delegator bonded validators
|
||||||
//
|
queryParams := types.NewQueryDelegatorParams(addrAcc2)
|
||||||
// query := abci.RequestQuery{
|
bz, errRes := cdc.MarshalJSON(queryParams)
|
||||||
// Path: "/custom/staking/delegatorValidators",
|
require.NoError(t, errRes)
|
||||||
// Data: bz,
|
|
||||||
// }
|
query := abci.RequestQuery{
|
||||||
//
|
Path: "/custom/staking/delegatorValidators",
|
||||||
// delValidators := app.StakingKeeper.GetDelegatorValidators(ctx, addrAcc2, params.MaxValidators)
|
Data: bz,
|
||||||
//
|
}
|
||||||
// res, err := querier(ctx, []string{types.QueryDelegatorValidators}, query)
|
|
||||||
// require.NoError(t, err)
|
delValidators := app.StakingKeeper.GetDelegatorValidators(ctx, addrAcc2, params.MaxValidators)
|
||||||
//
|
|
||||||
// var validatorsResp []types.Validator
|
res, err := querier(ctx, []string{types.QueryDelegatorValidators}, query)
|
||||||
// errRes = cdc.UnmarshalJSON(res, &validatorsResp)
|
require.NoError(t, err)
|
||||||
// require.NoError(t, errRes)
|
|
||||||
//
|
var validatorsResp []types.Validator
|
||||||
// require.Equal(t, len(delValidators), len(validatorsResp))
|
errRes = cdc.UnmarshalJSON(res, &validatorsResp)
|
||||||
// require.ElementsMatch(t, delValidators, validatorsResp)
|
require.NoError(t, errRes)
|
||||||
//
|
|
||||||
// // error unknown request
|
require.Equal(t, len(delValidators), len(validatorsResp))
|
||||||
// query.Data = bz[:len(bz)-1]
|
require.ElementsMatch(t, delValidators, validatorsResp)
|
||||||
//
|
|
||||||
// res, err = querier(ctx, []string{types.QueryDelegatorValidators}, query)
|
// error unknown request
|
||||||
// require.Error(t, err)
|
query.Data = bz[:len(bz)-1]
|
||||||
//
|
|
||||||
// // Query bonded validator
|
res, err = querier(ctx, []string{types.QueryDelegatorValidators}, query)
|
||||||
// queryBondParams := types.NewQueryBondsParams(addrAcc2, addrVal1)
|
require.Error(t, err)
|
||||||
// bz, errRes = cdc.MarshalJSON(queryBondParams)
|
|
||||||
// require.NoError(t, errRes)
|
// Query bonded validator
|
||||||
//
|
queryBondParams := types.NewQueryBondsParams(addrAcc2, addrVal1)
|
||||||
// query = abci.RequestQuery{
|
bz, errRes = cdc.MarshalJSON(queryBondParams)
|
||||||
// Path: "/custom/staking/delegatorValidator",
|
require.NoError(t, errRes)
|
||||||
// Data: bz,
|
|
||||||
// }
|
query = abci.RequestQuery{
|
||||||
//
|
Path: "/custom/staking/delegatorValidator",
|
||||||
// res, err = querier(ctx, []string{types.QueryDelegatorValidator}, query)
|
Data: bz,
|
||||||
// require.NoError(t, err)
|
}
|
||||||
//
|
|
||||||
// var validator types.Validator
|
res, err = querier(ctx, []string{types.QueryDelegatorValidator}, query)
|
||||||
// errRes = cdc.UnmarshalJSON(res, &validator)
|
require.NoError(t, err)
|
||||||
// require.NoError(t, errRes)
|
|
||||||
//
|
var validator types.Validator
|
||||||
// require.Equal(t, delValidators[0], validator)
|
errRes = cdc.UnmarshalJSON(res, &validator)
|
||||||
//
|
require.NoError(t, errRes)
|
||||||
// // error unknown request
|
|
||||||
// query.Data = bz[:len(bz)-1]
|
require.Equal(t, delValidators[0], validator)
|
||||||
//
|
|
||||||
// res, err = querier(ctx, []string{types.QueryDelegatorValidator}, query)
|
// error unknown request
|
||||||
// require.Error(t, err)
|
query.Data = bz[:len(bz)-1]
|
||||||
//
|
|
||||||
// // Query delegation
|
res, err = querier(ctx, []string{types.QueryDelegatorValidator}, query)
|
||||||
//
|
require.Error(t, err)
|
||||||
// query = abci.RequestQuery{
|
|
||||||
// Path: "/custom/staking/delegation",
|
// Query delegation
|
||||||
// Data: bz,
|
|
||||||
// }
|
query = abci.RequestQuery{
|
||||||
//
|
Path: "/custom/staking/delegation",
|
||||||
// delegation, found := app.StakingKeeper.GetDelegation(ctx, addrAcc2, addrVal1)
|
Data: bz,
|
||||||
// require.True(t, found)
|
}
|
||||||
//
|
|
||||||
// res, err = querier(ctx, []string{types.QueryDelegation}, query)
|
delegation, found := app.StakingKeeper.GetDelegation(ctx, addrAcc2, addrVal1)
|
||||||
// require.NoError(t, err)
|
require.True(t, found)
|
||||||
//
|
|
||||||
// var delegationRes types.DelegationResponse
|
res, err = querier(ctx, []string{types.QueryDelegation}, query)
|
||||||
// errRes = cdc.UnmarshalJSON(res, &delegationRes)
|
require.NoError(t, err)
|
||||||
// require.NoError(t, errRes)
|
|
||||||
//
|
var delegationRes types.DelegationResponse
|
||||||
// require.Equal(t, delegation.ValidatorAddress, delegationRes.ValidatorAddress)
|
errRes = cdc.UnmarshalJSON(res, &delegationRes)
|
||||||
// require.Equal(t, delegation.DelegatorAddress, delegationRes.DelegatorAddress)
|
require.NoError(t, errRes)
|
||||||
// require.Equal(t, sdk.NewCoin(sdk.DefaultBondDenom, delegation.Shares.TruncateInt()), delegationRes.Balance)
|
|
||||||
//
|
require.Equal(t, delegation.ValidatorAddress, delegationRes.ValidatorAddress)
|
||||||
// // Query Delegator Delegations
|
require.Equal(t, delegation.DelegatorAddress, delegationRes.DelegatorAddress)
|
||||||
// query = abci.RequestQuery{
|
require.Equal(t, sdk.NewCoin(sdk.DefaultBondDenom, delegation.Shares.TruncateInt()), delegationRes.Balance)
|
||||||
// Path: "/custom/staking/delegatorDelegations",
|
|
||||||
// Data: bz,
|
// Query Delegator Delegations
|
||||||
// }
|
query = abci.RequestQuery{
|
||||||
//
|
Path: "/custom/staking/delegatorDelegations",
|
||||||
// res, err = querier(ctx, []string{types.QueryDelegatorDelegations}, query)
|
Data: bz,
|
||||||
// require.NoError(t, err)
|
}
|
||||||
//
|
|
||||||
// var delegatorDelegations types.DelegationResponses
|
res, err = querier(ctx, []string{types.QueryDelegatorDelegations}, query)
|
||||||
// errRes = cdc.UnmarshalJSON(res, &delegatorDelegations)
|
require.NoError(t, err)
|
||||||
// require.NoError(t, errRes)
|
|
||||||
// require.Len(t, delegatorDelegations, 1)
|
var delegatorDelegations types.DelegationResponses
|
||||||
// require.Equal(t, delegation.ValidatorAddress, delegatorDelegations[0].ValidatorAddress)
|
errRes = cdc.UnmarshalJSON(res, &delegatorDelegations)
|
||||||
// require.Equal(t, delegation.DelegatorAddress, delegatorDelegations[0].DelegatorAddress)
|
require.NoError(t, errRes)
|
||||||
// require.Equal(t, sdk.NewCoin(sdk.DefaultBondDenom, delegation.Shares.TruncateInt()), delegatorDelegations[0].Balance)
|
require.Len(t, delegatorDelegations, 1)
|
||||||
//
|
require.Equal(t, delegation.ValidatorAddress, delegatorDelegations[0].ValidatorAddress)
|
||||||
// // error unknown request
|
require.Equal(t, delegation.DelegatorAddress, delegatorDelegations[0].DelegatorAddress)
|
||||||
// query.Data = bz[:len(bz)-1]
|
require.Equal(t, sdk.NewCoin(sdk.DefaultBondDenom, delegation.Shares.TruncateInt()), delegatorDelegations[0].Balance)
|
||||||
//
|
|
||||||
// res, err = querier(ctx, []string{types.QueryDelegation}, query)
|
// error unknown request
|
||||||
// require.Error(t, err)
|
query.Data = bz[:len(bz)-1]
|
||||||
//
|
|
||||||
// // Query validator delegations
|
res, err = querier(ctx, []string{types.QueryDelegation}, query)
|
||||||
//
|
require.Error(t, err)
|
||||||
// bz, errRes = cdc.MarshalJSON(types.NewQueryValidatorParams(addrVal1))
|
|
||||||
// require.NoError(t, errRes)
|
// Query validator delegations
|
||||||
//
|
|
||||||
// query = abci.RequestQuery{
|
bz, errRes = cdc.MarshalJSON(types.NewQueryValidatorParams(addrVal1))
|
||||||
// Path: "custom/staking/validatorDelegations",
|
require.NoError(t, errRes)
|
||||||
// Data: bz,
|
|
||||||
// }
|
query = abci.RequestQuery{
|
||||||
//
|
Path: "custom/staking/validatorDelegations",
|
||||||
// res, err = querier(ctx, []string{types.QueryValidatorDelegations}, query)
|
Data: bz,
|
||||||
// require.NoError(t, err)
|
}
|
||||||
//
|
|
||||||
// var delegationsRes types.DelegationResponses
|
res, err = querier(ctx, []string{types.QueryValidatorDelegations}, query)
|
||||||
// errRes = cdc.UnmarshalJSON(res, &delegationsRes)
|
require.NoError(t, err)
|
||||||
// require.NoError(t, errRes)
|
|
||||||
// require.Len(t, delegatorDelegations, 1)
|
var delegationsRes types.DelegationResponses
|
||||||
// require.Equal(t, delegation.ValidatorAddress, delegationsRes[0].ValidatorAddress)
|
errRes = cdc.UnmarshalJSON(res, &delegationsRes)
|
||||||
// require.Equal(t, delegation.DelegatorAddress, delegationsRes[0].DelegatorAddress)
|
require.NoError(t, errRes)
|
||||||
// require.Equal(t, sdk.NewCoin(sdk.DefaultBondDenom, delegation.Shares.TruncateInt()), delegationsRes[0].Balance)
|
require.Len(t, delegatorDelegations, 1)
|
||||||
//
|
require.Equal(t, delegation.ValidatorAddress, delegationsRes[0].ValidatorAddress)
|
||||||
// // Query unbonging delegation
|
require.Equal(t, delegation.DelegatorAddress, delegationsRes[0].DelegatorAddress)
|
||||||
// unbondingTokens := sdk.TokensFromConsensusPower(10)
|
require.Equal(t, sdk.NewCoin(sdk.DefaultBondDenom, delegation.Shares.TruncateInt()), delegationsRes[0].Balance)
|
||||||
// _, err = app.StakingKeeper.Undelegate(ctx, addrAcc2, val1.OperatorAddress, unbondingTokens.ToDec())
|
|
||||||
// require.NoError(t, err)
|
// Query unbonging delegation
|
||||||
//
|
unbondingTokens := sdk.TokensFromConsensusPower(10)
|
||||||
// queryBondParams = types.NewQueryBondsParams(addrAcc2, addrVal1)
|
_, err = app.StakingKeeper.Undelegate(ctx, addrAcc2, val1.OperatorAddress, unbondingTokens.ToDec())
|
||||||
// bz, errRes = cdc.MarshalJSON(queryBondParams)
|
require.NoError(t, err)
|
||||||
// require.NoError(t, errRes)
|
|
||||||
//
|
queryBondParams = types.NewQueryBondsParams(addrAcc2, addrVal1)
|
||||||
// query = abci.RequestQuery{
|
bz, errRes = cdc.MarshalJSON(queryBondParams)
|
||||||
// Path: "/custom/staking/unbondingDelegation",
|
require.NoError(t, errRes)
|
||||||
// Data: bz,
|
|
||||||
// }
|
query = abci.RequestQuery{
|
||||||
//
|
Path: "/custom/staking/unbondingDelegation",
|
||||||
// unbond, found := app.StakingKeeper.GetUnbondingDelegation(ctx, addrAcc2, addrVal1)
|
Data: bz,
|
||||||
// require.True(t, found)
|
}
|
||||||
//
|
|
||||||
// res, err = querier(ctx, []string{types.QueryUnbondingDelegation}, query)
|
unbond, found := app.StakingKeeper.GetUnbondingDelegation(ctx, addrAcc2, addrVal1)
|
||||||
// require.NoError(t, err)
|
require.True(t, found)
|
||||||
//
|
|
||||||
// var unbondRes types.UnbondingDelegation
|
res, err = querier(ctx, []string{types.QueryUnbondingDelegation}, query)
|
||||||
// errRes = cdc.UnmarshalJSON(res, &unbondRes)
|
require.NoError(t, err)
|
||||||
// require.NoError(t, errRes)
|
|
||||||
//
|
var unbondRes types.UnbondingDelegation
|
||||||
// require.Equal(t, unbond, unbondRes)
|
errRes = cdc.UnmarshalJSON(res, &unbondRes)
|
||||||
//
|
require.NoError(t, errRes)
|
||||||
// // error unknown request
|
|
||||||
// query.Data = bz[:len(bz)-1]
|
require.Equal(t, unbond, unbondRes)
|
||||||
//
|
|
||||||
// _, err = querier(ctx, []string{types.QueryUnbondingDelegation}, query)
|
// error unknown request
|
||||||
// require.Error(t, err)
|
query.Data = bz[:len(bz)-1]
|
||||||
//
|
|
||||||
// // Query Delegator Delegations
|
_, err = querier(ctx, []string{types.QueryUnbondingDelegation}, query)
|
||||||
//
|
require.Error(t, err)
|
||||||
// query = abci.RequestQuery{
|
|
||||||
// Path: "/custom/staking/delegatorUnbondingDelegations",
|
// Query Delegator Delegations
|
||||||
// Data: bz,
|
|
||||||
// }
|
query = abci.RequestQuery{
|
||||||
//
|
Path: "/custom/staking/delegatorUnbondingDelegations",
|
||||||
// res, err = querier(ctx, []string{types.QueryDelegatorUnbondingDelegations}, query)
|
Data: bz,
|
||||||
// require.NoError(t, err)
|
}
|
||||||
//
|
|
||||||
// var delegatorUbds []types.UnbondingDelegation
|
res, err = querier(ctx, []string{types.QueryDelegatorUnbondingDelegations}, query)
|
||||||
// errRes = cdc.UnmarshalJSON(res, &delegatorUbds)
|
require.NoError(t, err)
|
||||||
// require.NoError(t, errRes)
|
|
||||||
// require.Equal(t, unbond, delegatorUbds[0])
|
var delegatorUbds []types.UnbondingDelegation
|
||||||
//
|
errRes = cdc.UnmarshalJSON(res, &delegatorUbds)
|
||||||
// // error unknown request
|
require.NoError(t, errRes)
|
||||||
// query.Data = bz[:len(bz)-1]
|
require.Equal(t, unbond, delegatorUbds[0])
|
||||||
//
|
|
||||||
// _, err = querier(ctx, []string{types.QueryDelegatorUnbondingDelegations}, query)
|
// error unknown request
|
||||||
// require.Error(t, err)
|
query.Data = bz[:len(bz)-1]
|
||||||
//
|
|
||||||
// // Query redelegation
|
_, err = querier(ctx, []string{types.QueryDelegatorUnbondingDelegations}, query)
|
||||||
// redelegationTokens := sdk.TokensFromConsensusPower(10)
|
require.Error(t, err)
|
||||||
// _, err = app.StakingKeeper.BeginRedelegation(ctx, addrAcc2, val1.OperatorAddress,
|
|
||||||
// val2.OperatorAddress, redelegationTokens.ToDec())
|
// Query redelegation
|
||||||
// require.NoError(t, err)
|
redelegationTokens := sdk.TokensFromConsensusPower(10)
|
||||||
// redel, found := app.StakingKeeper.GetRedelegation(ctx, addrAcc2, val1.OperatorAddress, val2.OperatorAddress)
|
_, err = app.StakingKeeper.BeginRedelegation(ctx, addrAcc2, val1.OperatorAddress,
|
||||||
// require.True(t, found)
|
val2.OperatorAddress, redelegationTokens.ToDec())
|
||||||
//
|
require.NoError(t, err)
|
||||||
// bz, errRes = cdc.MarshalJSON(types.NewQueryRedelegationParams(addrAcc2, val1.OperatorAddress, val2.OperatorAddress))
|
redel, found := app.StakingKeeper.GetRedelegation(ctx, addrAcc2, val1.OperatorAddress, val2.OperatorAddress)
|
||||||
// require.NoError(t, errRes)
|
require.True(t, found)
|
||||||
//
|
|
||||||
// query = abci.RequestQuery{
|
bz, errRes = cdc.MarshalJSON(types.NewQueryRedelegationParams(addrAcc2, val1.OperatorAddress, val2.OperatorAddress))
|
||||||
// Path: "/custom/staking/redelegations",
|
require.NoError(t, errRes)
|
||||||
// Data: bz,
|
|
||||||
// }
|
query = abci.RequestQuery{
|
||||||
//
|
Path: "/custom/staking/redelegations",
|
||||||
|
Data: bz,
|
||||||
|
}
|
||||||
|
|
||||||
// res, err = querier(ctx, []string{types.QueryRedelegations}, query)
|
// res, err = querier(ctx, []string{types.QueryRedelegations}, query)
|
||||||
// require.NoError(t, err)
|
// require.NoError(t, err)
|
||||||
//
|
//
|
||||||
|
|
|
@ -59,6 +59,7 @@ func createTestPubKeys(numPubKeys int) []crypto.PubKey {
|
||||||
publicKeys = append(publicKeys, NewPubKey(buffer.String()))
|
publicKeys = append(publicKeys, NewPubKey(buffer.String()))
|
||||||
buffer.Reset()
|
buffer.Reset()
|
||||||
}
|
}
|
||||||
|
|
||||||
return publicKeys
|
return publicKeys
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,11 +76,11 @@ func NewPubKey(pk string) (res crypto.PubKey) {
|
||||||
|
|
||||||
// for incode address generation
|
// for incode address generation
|
||||||
func CreateTestAddr(addr string, bech string) sdk.AccAddress {
|
func CreateTestAddr(addr string, bech string) sdk.AccAddress {
|
||||||
|
|
||||||
res, err := sdk.AccAddressFromHex(addr)
|
res, err := sdk.AccAddressFromHex(addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
bechexpected := res.String()
|
bechexpected := res.String()
|
||||||
if bech != bechexpected {
|
if bech != bechexpected {
|
||||||
panic("Bech encoding doesn't match reference")
|
panic("Bech encoding doesn't match reference")
|
Loading…
Reference in New Issue