diff --git a/x/staking/client/cli/cli_test.go b/x/staking/client/cli/cli_test.go index 2b66da867c..12b4084a4e 100644 --- a/x/staking/client/cli/cli_test.go +++ b/x/staking/client/cli/cli_test.go @@ -381,7 +381,7 @@ func (s *IntegrationTestSuite) TestGetCmdQueryDelegations() { &types.QueryDelegatorDelegationsResponse{}, &types.QueryDelegatorDelegationsResponse{ DelegationResponses: types.DelegationResponses{ - types.NewDelegationResp(val.Address, val.ValAddress, sdk.NewDec(100000000), sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100000000))), + types.NewDelegationResp(val.Address, val.ValAddress, sdk.NewDecFromInt(cli.DefaultTokens), sdk.NewCoin(sdk.DefaultBondDenom, cli.DefaultTokens)), }, Pagination: &query.PageResponse{}, }, @@ -437,7 +437,7 @@ func (s *IntegrationTestSuite) TestGetCmdQueryDelegationsTo() { &types.QueryValidatorDelegationsResponse{}, &types.QueryValidatorDelegationsResponse{ DelegationResponses: types.DelegationResponses{ - types.NewDelegationResp(val.Address, val.ValAddress, sdk.NewDec(100000000), sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100000000))), + types.NewDelegationResp(val.Address, val.ValAddress, sdk.NewDecFromInt(cli.DefaultTokens), sdk.NewCoin(sdk.DefaultBondDenom, cli.DefaultTokens)), }, Pagination: &query.PageResponse{}, }, @@ -891,8 +891,8 @@ func (s *IntegrationTestSuite) TestGetCmdQueryPool() { fmt.Sprintf("--%s=text", tmcli.OutputFlag), fmt.Sprintf("--%s=1", flags.FlagHeight), }, - `bonded_tokens: "200000000" -not_bonded_tokens: "0"`, + fmt.Sprintf(`bonded_tokens: "%s" +not_bonded_tokens: "0"`, cli.DefaultTokens.Mul(sdk.NewInt(2)).String()), }, { "with json", @@ -900,7 +900,7 @@ not_bonded_tokens: "0"`, fmt.Sprintf("--%s=json", tmcli.OutputFlag), fmt.Sprintf("--%s=1", flags.FlagHeight), }, - `{"not_bonded_tokens":"0","bonded_tokens":"200000000"}`, + fmt.Sprintf(`{"not_bonded_tokens":"0","bonded_tokens":"%s"}`, cli.DefaultTokens.Mul(sdk.NewInt(2)).String()), }, } for _, tc := range testCases { diff --git a/x/staking/client/cli/tx.go b/x/staking/client/cli/tx.go index ab486c5a98..b46cef2bf8 100644 --- a/x/staking/client/cli/tx.go +++ b/x/staking/client/cli/tx.go @@ -17,9 +17,10 @@ import ( "github.com/cosmos/cosmos-sdk/x/staking/types" ) +// default values var ( - defaultTokens = sdk.TokensFromConsensusPower(100) - defaultAmount = defaultTokens.String() + sdk.DefaultBondDenom + DefaultTokens = sdk.TokensFromConsensusPower(100) + defaultAmount = DefaultTokens.String() + sdk.DefaultBondDenom defaultCommissionRate = "0.1" defaultCommissionMaxRate = "0.2" defaultCommissionMaxChangeRate = "0.01" diff --git a/x/staking/client/cli/tx_test.go b/x/staking/client/cli/tx_test.go index 78a0a45bcf..9be0ebd94b 100644 --- a/x/staking/client/cli/tx_test.go +++ b/x/staking/client/cli/tx_test.go @@ -33,7 +33,7 @@ func TestPrepareConfigForTxCreateValidator(t *testing.T) { NodeID: nodeID, PubKey: sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, valPubKey), Moniker: moniker, - Amount: "100000000stake", + Amount: defaultAmount, // for power reduction change, do not hardcode value here CommissionRate: "0.1", CommissionMaxRate: "0.2", CommissionMaxChangeRate: "0.01", @@ -69,7 +69,7 @@ func TestPrepareConfigForTxCreateValidator(t *testing.T) { ChainID: chainID, NodeID: nodeID, PubKey: sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, valPubKey), - Amount: "100000000stake", + Amount: defaultAmount, // for power reduction change, do not hardcode value here CommissionRate: "0.54", CommissionMaxRate: "0.2", CommissionMaxChangeRate: "0.01", @@ -87,7 +87,7 @@ func TestPrepareConfigForTxCreateValidator(t *testing.T) { ChainID: chainID, NodeID: nodeID, PubKey: sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, valPubKey), - Amount: "100000000stake", + Amount: defaultAmount, // for power reduction change, do not hardcode value here CommissionRate: "0.1", CommissionMaxRate: "0.89", CommissionMaxChangeRate: "0.01", @@ -105,7 +105,7 @@ func TestPrepareConfigForTxCreateValidator(t *testing.T) { ChainID: chainID, NodeID: nodeID, PubKey: sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, valPubKey), - Amount: "100000000stake", + Amount: defaultAmount, // for power reduction change, do not hardcode value here CommissionRate: "0.1", CommissionMaxRate: "0.2", CommissionMaxChangeRate: "0.55", @@ -123,7 +123,7 @@ func TestPrepareConfigForTxCreateValidator(t *testing.T) { ChainID: chainID, NodeID: nodeID, PubKey: sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, valPubKey), - Amount: "100000000stake", + Amount: defaultAmount, // for power reduction change, do not hardcode value here CommissionRate: "0.1", CommissionMaxRate: "0.2", CommissionMaxChangeRate: "0.01", diff --git a/x/staking/client/rest/grpc_query_test.go b/x/staking/client/rest/grpc_query_test.go index 8383537055..3aa4afdcfe 100644 --- a/x/staking/client/rest/grpc_query_test.go +++ b/x/staking/client/rest/grpc_query_test.go @@ -15,6 +15,7 @@ import ( grpctypes "github.com/cosmos/cosmos-sdk/types/grpc" "github.com/cosmos/cosmos-sdk/types/query" "github.com/cosmos/cosmos-sdk/types/rest" + "github.com/cosmos/cosmos-sdk/x/staking/client/cli" stakingtestutil "github.com/cosmos/cosmos-sdk/x/staking/client/testutil" "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -194,7 +195,7 @@ func (s *IntegrationTestSuite) TestQueryValidatorDelegationsGRPC() { &types.QueryValidatorDelegationsResponse{}, &types.QueryValidatorDelegationsResponse{ DelegationResponses: types.DelegationResponses{ - types.NewDelegationResp(val.Address, val.ValAddress, sdk.NewDec(100000000), sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100000000))), + types.NewDelegationResp(val.Address, val.ValAddress, sdk.NewDecFromInt(cli.DefaultTokens), sdk.NewCoin(sdk.DefaultBondDenom, cli.DefaultTokens)), }, Pagination: &query.PageResponse{Total: 1}, }, @@ -438,7 +439,7 @@ func (s *IntegrationTestSuite) TestQueryDelegatorDelegationsGRPC() { &types.QueryDelegatorDelegationsResponse{}, &types.QueryDelegatorDelegationsResponse{ DelegationResponses: types.DelegationResponses{ - types.NewDelegationResp(val.Address, val.ValAddress, sdk.NewDec(100000000), sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100000000))), + types.NewDelegationResp(val.Address, val.ValAddress, sdk.NewDecFromInt(cli.DefaultTokens), sdk.NewCoin(sdk.DefaultBondDenom, cli.DefaultTokens)), }, Pagination: &query.PageResponse{Total: 1}, }, @@ -775,7 +776,7 @@ func (s *IntegrationTestSuite) TestQueryPoolGRPC() { &types.QueryPoolResponse{ Pool: types.Pool{ NotBondedTokens: sdk.NewInt(10), - BondedTokens: sdk.NewInt(199999990), + BondedTokens: cli.DefaultTokens.Mul(sdk.NewInt(2)).Sub(sdk.NewInt(10)), }, }, }, diff --git a/x/staking/keeper/grpc_query_test.go b/x/staking/keeper/grpc_query_test.go index e144668940..cf3c9e3fe4 100644 --- a/x/staking/keeper/grpc_query_test.go +++ b/x/staking/keeper/grpc_query_test.go @@ -11,6 +11,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/staking/keeper" "github.com/cosmos/cosmos-sdk/x/staking/teststaking" "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/stretchr/testify/require" ) func (suite *KeeperTestSuite) TestGRPCQueryValidators() { @@ -727,7 +728,7 @@ func (suite *KeeperTestSuite) TestGRPCQueryValidatorUnbondingDelegations() { } func createValidators(t *testing.T, ctx sdk.Context, app *simapp.SimApp, powers []int64) ([]sdk.AccAddress, []sdk.ValAddress, []types.Validator) { - addrs := simapp.AddTestAddrsIncremental(app, ctx, 5, sdk.NewInt(300000000)) + addrs := simapp.AddTestAddrsIncremental(app, ctx, 5, sdk.TokensFromConsensusPower(300)) valAddrs := simapp.ConvertAddrsToValAddrs(addrs) pks := simapp.CreateTestPubKeys(5) @@ -751,9 +752,12 @@ func createValidators(t *testing.T, ctx sdk.Context, app *simapp.SimApp, powers app.StakingKeeper.SetNewValidatorByPowerIndex(ctx, val1) app.StakingKeeper.SetNewValidatorByPowerIndex(ctx, val2) - _, _ = app.StakingKeeper.Delegate(ctx, addrs[0], sdk.TokensFromConsensusPower(powers[0]), types.Unbonded, val1, true) - _, _ = app.StakingKeeper.Delegate(ctx, addrs[1], sdk.TokensFromConsensusPower(powers[1]), types.Unbonded, val2, true) - _, _ = app.StakingKeeper.Delegate(ctx, addrs[0], sdk.TokensFromConsensusPower(powers[2]), types.Unbonded, val2, true) + _, err := app.StakingKeeper.Delegate(ctx, addrs[0], sdk.TokensFromConsensusPower(powers[0]), types.Unbonded, val1, true) + require.NoError(t, err) + _, err = app.StakingKeeper.Delegate(ctx, addrs[1], sdk.TokensFromConsensusPower(powers[1]), types.Unbonded, val2, true) + require.NoError(t, err) + _, err = app.StakingKeeper.Delegate(ctx, addrs[0], sdk.TokensFromConsensusPower(powers[2]), types.Unbonded, val2, true) + require.NoError(t, err) applyValidatorSetUpdates(t, ctx, app.StakingKeeper, -1) return addrs, valAddrs, vals