Skip to content

Commit

Permalink
revert 8909 (#8960)
Browse files Browse the repository at this point in the history
* revert 8909

* remove entry from CHANGELOG

* fix test
  • Loading branch information
colin-axner authored and dudong2 committed Mar 11, 2022
1 parent ab4e043 commit 6b41e6c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 23 deletions.
8 changes: 4 additions & 4 deletions x/staking/client/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (s *IntegrationTestSuite) TestNewCreateValidatorCmd() {
val.ClientCtx,
val.Address,
newAddr,
sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10000000))), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(200))), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
)
Expand Down Expand Up @@ -131,7 +131,7 @@ func (s *IntegrationTestSuite) TestNewCreateValidatorCmd() {
{
"invalid transaction (missing pubkey)",
[]string{
fmt.Sprintf("--%s=%dstake", cli.FlagAmount, sdk.PowerReduction.Int64()),
fmt.Sprintf("--%s=%dstake", cli.FlagAmount, 100),
fmt.Sprintf("--%s=AFAF00C4", cli.FlagIdentity),
fmt.Sprintf("--%s=https://newvalidator.io", cli.FlagWebsite),
fmt.Sprintf("--%s=contact@newvalidator.io", cli.FlagSecurityContact),
Expand All @@ -151,7 +151,7 @@ func (s *IntegrationTestSuite) TestNewCreateValidatorCmd() {
"invalid transaction (missing moniker)",
[]string{
fmt.Sprintf("--%s=%s", cli.FlagPubKey, consPubKeyBz),
fmt.Sprintf("--%s=%dstake", cli.FlagAmount, sdk.PowerReduction.Int64()),
fmt.Sprintf("--%s=%dstake", cli.FlagAmount, 100),
fmt.Sprintf("--%s=AFAF00C4", cli.FlagIdentity),
fmt.Sprintf("--%s=https://newvalidator.io", cli.FlagWebsite),
fmt.Sprintf("--%s=contact@newvalidator.io", cli.FlagSecurityContact),
Expand All @@ -171,7 +171,7 @@ func (s *IntegrationTestSuite) TestNewCreateValidatorCmd() {
"valid transaction",
[]string{
fmt.Sprintf("--%s=%s", cli.FlagPubKey, consPubKeyBz),
fmt.Sprintf("--%s=%dstake", cli.FlagAmount, sdk.PowerReduction.Int64()),
fmt.Sprintf("--%s=%dstake", cli.FlagAmount, 100),
fmt.Sprintf("--%s=NewValidator", cli.FlagMoniker),
fmt.Sprintf("--%s=AFAF00C4", cli.FlagIdentity),
fmt.Sprintf("--%s=https://newvalidator.io", cli.FlagWebsite),
Expand Down
13 changes: 1 addition & 12 deletions x/staking/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,22 +112,11 @@ func SimulateMsgCreateValidator(ak types.AccountKeeper, bk types.BankKeeper, k k
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgCreateValidator, "balance is negative"), nil, nil
}

// A validator can only be created if it has at least one consensus power worth of tokens.
// Construct a maximum random value that is reduced by the PowerReduction, allowing
// for a minimum self delegation of the PowerReduction.
max := balance.Sub(sdk.PowerReduction)
if !max.IsPositive() {
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgCreateValidator, "balance doesn't have enough delegation amount"), nil, nil
}

amount, err := simtypes.RandPositiveInt(r, max)
amount, err := simtypes.RandPositiveInt(r, balance)
if err != nil {
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgCreateValidator, "unable to generate positive amount"), nil, err
}

// ensure self delegation meets minimum requirement
amount = amount.Add(sdk.PowerReduction)

selfDelegation := sdk.NewCoin(denom, amount)

account := ak.GetAccount(ctx, simAccount.Address)
Expand Down
5 changes: 0 additions & 5 deletions x/staking/types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,6 @@ func (msg MsgCreateValidator) ValidateBasic() error {
return ErrMinSelfDelegationInvalid
}

// ensure delegation is at least one consensus power
if sdk.TokensToConsensusPower(msg.Value.Amount) <= 0 {
return sdkerrors.Wrapf(ErrBadDelegationAmount, "self delegation amount (%s) must be at least one consensus power (%s)", msg.Value.Amount, sdk.PowerReduction)
}

if msg.Value.Amount.LT(msg.MinSelfDelegation) {
return ErrSelfDelegationBelowMinimum
}
Expand Down
3 changes: 1 addition & 2 deletions x/staking/types/msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

var (
coinPos = sdk.NewInt64Coin(sdk.DefaultBondDenom, sdk.PowerReduction.Int64())
coinPos = sdk.NewInt64Coin(sdk.DefaultBondDenom, 1000)
coinZero = sdk.NewInt64Coin(sdk.DefaultBondDenom, 0)
)

Expand Down Expand Up @@ -75,7 +75,6 @@ func TestMsgCreateValidator(t *testing.T) {
{"zero min self delegation", "a", "b", "c", "d", "e", commission1, sdk.ZeroInt(), valAddr1, pk1, coinPos, false},
{"negative min self delegation", "a", "b", "c", "d", "e", commission1, sdk.NewInt(-1), valAddr1, pk1, coinPos, false},
{"delegation less than min self delegation", "a", "b", "c", "d", "e", commission1, coinPos.Amount.Add(sdk.OneInt()), valAddr1, pk1, coinPos, false},
{"delegation less than one consensus power", "a", "b", "c", "d", "e", commission1, sdk.OneInt(), valAddr1, pk1, sdk.NewInt64Coin(sdk.DefaultBondDenom, 1000), false},
}

for _, tc := range tests {
Expand Down

0 comments on commit 6b41e6c

Please sign in to comment.