Merge PR #4466: Lazy commission validation
This commit is contained in:
parent
59ac148061
commit
9c049321a1
|
@ -0,0 +1 @@
|
|||
#4466 Commission validation added to validate basic of MsgCreateValidator by changing CommissionMsg to CommissionRates
|
|
@ -15,7 +15,7 @@ func TestAllocateTokensToValidatorWithCommission(t *testing.T) {
|
|||
sh := staking.NewHandler(sk)
|
||||
|
||||
// create validator with 50% commission
|
||||
commission := staking.NewCommissionMsg(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
|
||||
commission := staking.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
|
||||
msg := staking.NewMsgCreateValidator(valOpAddr1, valConsPk1,
|
||||
sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)), staking.Description{}, commission, sdk.OneInt())
|
||||
require.True(t, sh(ctx, msg).IsOK())
|
||||
|
@ -42,13 +42,13 @@ func TestAllocateTokensToManyValidators(t *testing.T) {
|
|||
sh := staking.NewHandler(sk)
|
||||
|
||||
// create validator with 50% commission
|
||||
commission := staking.NewCommissionMsg(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
|
||||
commission := staking.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
|
||||
msg := staking.NewMsgCreateValidator(valOpAddr1, valConsPk1,
|
||||
sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)), staking.Description{}, commission, sdk.OneInt())
|
||||
require.True(t, sh(ctx, msg).IsOK())
|
||||
|
||||
// create second validator with 0% commission
|
||||
commission = staking.NewCommissionMsg(sdk.NewDec(0), sdk.NewDec(0), sdk.NewDec(0))
|
||||
commission = staking.NewCommissionRates(sdk.NewDec(0), sdk.NewDec(0), sdk.NewDec(0))
|
||||
msg = staking.NewMsgCreateValidator(valOpAddr2, valConsPk2,
|
||||
sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)), staking.Description{}, commission, sdk.OneInt())
|
||||
require.True(t, sh(ctx, msg).IsOK())
|
||||
|
@ -109,19 +109,19 @@ func TestAllocateTokensTruncation(t *testing.T) {
|
|||
sh := staking.NewHandler(sk)
|
||||
|
||||
// create validator with 10% commission
|
||||
commission := staking.NewCommissionMsg(sdk.NewDecWithPrec(1, 1), sdk.NewDecWithPrec(1, 1), sdk.NewDec(0))
|
||||
commission := staking.NewCommissionRates(sdk.NewDecWithPrec(1, 1), sdk.NewDecWithPrec(1, 1), sdk.NewDec(0))
|
||||
msg := staking.NewMsgCreateValidator(valOpAddr1, valConsPk1,
|
||||
sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(110)), staking.Description{}, commission, sdk.OneInt())
|
||||
require.True(t, sh(ctx, msg).IsOK())
|
||||
|
||||
// create second validator with 10% commission
|
||||
commission = staking.NewCommissionMsg(sdk.NewDecWithPrec(1, 1), sdk.NewDecWithPrec(1, 1), sdk.NewDec(0))
|
||||
commission = staking.NewCommissionRates(sdk.NewDecWithPrec(1, 1), sdk.NewDecWithPrec(1, 1), sdk.NewDec(0))
|
||||
msg = staking.NewMsgCreateValidator(valOpAddr2, valConsPk2,
|
||||
sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)), staking.Description{}, commission, sdk.OneInt())
|
||||
require.True(t, sh(ctx, msg).IsOK())
|
||||
|
||||
// create third validator with 10% commission
|
||||
commission = staking.NewCommissionMsg(sdk.NewDecWithPrec(1, 1), sdk.NewDecWithPrec(1, 1), sdk.NewDec(0))
|
||||
commission = staking.NewCommissionRates(sdk.NewDecWithPrec(1, 1), sdk.NewDecWithPrec(1, 1), sdk.NewDec(0))
|
||||
msg = staking.NewMsgCreateValidator(valOpAddr3, valConsPk3,
|
||||
sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)), staking.Description{}, commission, sdk.OneInt())
|
||||
require.True(t, sh(ctx, msg).IsOK())
|
||||
|
|
|
@ -14,7 +14,7 @@ func TestCalculateRewardsBasic(t *testing.T) {
|
|||
sh := staking.NewHandler(sk)
|
||||
|
||||
// create validator with 50% commission
|
||||
commission := staking.NewCommissionMsg(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
|
||||
commission := staking.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
|
||||
msg := staking.NewMsgCreateValidator(valOpAddr1, valConsPk1,
|
||||
sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)), staking.Description{}, commission, sdk.OneInt())
|
||||
require.True(t, sh(ctx, msg).IsOK())
|
||||
|
@ -67,7 +67,7 @@ func TestCalculateRewardsAfterSlash(t *testing.T) {
|
|||
sh := staking.NewHandler(sk)
|
||||
|
||||
// create validator with 50% commission
|
||||
commission := staking.NewCommissionMsg(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
|
||||
commission := staking.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
|
||||
valPower := int64(100)
|
||||
valTokens := sdk.TokensFromTendermintPower(valPower)
|
||||
msg := staking.NewMsgCreateValidator(valOpAddr1, valConsPk1,
|
||||
|
@ -132,7 +132,7 @@ func TestCalculateRewardsAfterManySlashes(t *testing.T) {
|
|||
// create validator with 50% commission
|
||||
power := int64(100)
|
||||
valTokens := sdk.TokensFromTendermintPower(power)
|
||||
commission := staking.NewCommissionMsg(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
|
||||
commission := staking.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
|
||||
msg := staking.NewMsgCreateValidator(valOpAddr1, valConsPk1,
|
||||
sdk.NewCoin(sdk.DefaultBondDenom, valTokens), staking.Description{}, commission, sdk.OneInt())
|
||||
require.True(t, sh(ctx, msg).IsOK())
|
||||
|
@ -204,7 +204,7 @@ func TestCalculateRewardsMultiDelegator(t *testing.T) {
|
|||
sh := staking.NewHandler(sk)
|
||||
|
||||
// create validator with 50% commission
|
||||
commission := staking.NewCommissionMsg(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
|
||||
commission := staking.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
|
||||
msg := staking.NewMsgCreateValidator(valOpAddr1, valConsPk1,
|
||||
sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)), staking.Description{}, commission, sdk.OneInt())
|
||||
require.True(t, sh(ctx, msg).IsOK())
|
||||
|
@ -269,7 +269,7 @@ func TestWithdrawDelegationRewardsBasic(t *testing.T) {
|
|||
// create validator with 50% commission
|
||||
power := int64(100)
|
||||
valTokens := sdk.TokensFromTendermintPower(power)
|
||||
commission := staking.NewCommissionMsg(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
|
||||
commission := staking.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
|
||||
msg := staking.NewMsgCreateValidator(
|
||||
valOpAddr1, valConsPk1,
|
||||
sdk.NewCoin(sdk.DefaultBondDenom, valTokens),
|
||||
|
@ -335,7 +335,7 @@ func TestCalculateRewardsAfterManySlashesInSameBlock(t *testing.T) {
|
|||
// create validator with 50% commission
|
||||
power := int64(100)
|
||||
valTokens := sdk.TokensFromTendermintPower(power)
|
||||
commission := staking.NewCommissionMsg(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
|
||||
commission := staking.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
|
||||
msg := staking.NewMsgCreateValidator(valOpAddr1, valConsPk1,
|
||||
sdk.NewCoin(sdk.DefaultBondDenom, valTokens), staking.Description{}, commission, sdk.OneInt())
|
||||
require.True(t, sh(ctx, msg).IsOK())
|
||||
|
@ -400,7 +400,7 @@ func TestCalculateRewardsMultiDelegatorMultiSlash(t *testing.T) {
|
|||
sh := staking.NewHandler(sk)
|
||||
|
||||
// create validator with 50% commission
|
||||
commission := staking.NewCommissionMsg(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
|
||||
commission := staking.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
|
||||
power := int64(100)
|
||||
valTokens := sdk.TokensFromTendermintPower(power)
|
||||
msg := staking.NewMsgCreateValidator(valOpAddr1, valConsPk1,
|
||||
|
@ -479,7 +479,7 @@ func TestCalculateRewardsMultiDelegatorMultWithdraw(t *testing.T) {
|
|||
tokens := sdk.DecCoins{sdk.NewDecCoinFromDec(sdk.DefaultBondDenom, sdk.NewDec(initial))}
|
||||
|
||||
// create validator with 50% commission
|
||||
commission := staking.NewCommissionMsg(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
|
||||
commission := staking.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
|
||||
msg := staking.NewMsgCreateValidator(valOpAddr1, valConsPk1,
|
||||
sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)), staking.Description{}, commission, sdk.OneInt())
|
||||
require.True(t, sh(ctx, msg).IsOK())
|
||||
|
|
|
@ -186,7 +186,7 @@ func TestQueries(t *testing.T) {
|
|||
|
||||
// test delegation rewards query
|
||||
sh := staking.NewHandler(sk)
|
||||
comm := staking.NewCommissionMsg(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
|
||||
comm := staking.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
|
||||
msg := staking.NewMsgCreateValidator(valOpAddr1, valConsPk1,
|
||||
sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)), staking.Description{}, comm, sdk.OneInt())
|
||||
require.True(t, sh(ctx, msg).IsOK())
|
||||
|
|
|
@ -18,7 +18,7 @@ var (
|
|||
func TestValidateGenesisMultipleMessages(t *testing.T) {
|
||||
|
||||
desc := staking.NewDescription("testname", "", "", "")
|
||||
comm := staking.CommissionMsg{}
|
||||
comm := staking.CommissionRates{}
|
||||
|
||||
msg1 := staking.NewMsgCreateValidator(sdk.ValAddress(pk1.Address()), pk1,
|
||||
sdk.NewInt64Coin(sdk.DefaultBondDenom, 50), desc, comm, sdk.OneInt())
|
||||
|
|
|
@ -502,19 +502,19 @@ func TestTallyDelgatorMultipleInherit(t *testing.T) {
|
|||
|
||||
valTokens1 := sdk.TokensFromTendermintPower(25)
|
||||
val1CreateMsg := staking.NewMsgCreateValidator(
|
||||
sdk.ValAddress(input.addrs[0]), ed25519.GenPrivKey().PubKey(), sdk.NewCoin(sdk.DefaultBondDenom, valTokens1), testDescription, testCommissionMsg, sdk.OneInt(),
|
||||
sdk.ValAddress(input.addrs[0]), ed25519.GenPrivKey().PubKey(), sdk.NewCoin(sdk.DefaultBondDenom, valTokens1), testDescription, testCommissionRates, sdk.OneInt(),
|
||||
)
|
||||
stakingHandler(ctx, val1CreateMsg)
|
||||
|
||||
valTokens2 := sdk.TokensFromTendermintPower(6)
|
||||
val2CreateMsg := staking.NewMsgCreateValidator(
|
||||
sdk.ValAddress(input.addrs[1]), ed25519.GenPrivKey().PubKey(), sdk.NewCoin(sdk.DefaultBondDenom, valTokens2), testDescription, testCommissionMsg, sdk.OneInt(),
|
||||
sdk.ValAddress(input.addrs[1]), ed25519.GenPrivKey().PubKey(), sdk.NewCoin(sdk.DefaultBondDenom, valTokens2), testDescription, testCommissionRates, sdk.OneInt(),
|
||||
)
|
||||
stakingHandler(ctx, val2CreateMsg)
|
||||
|
||||
valTokens3 := sdk.TokensFromTendermintPower(7)
|
||||
val3CreateMsg := staking.NewMsgCreateValidator(
|
||||
sdk.ValAddress(input.addrs[2]), ed25519.GenPrivKey().PubKey(), sdk.NewCoin(sdk.DefaultBondDenom, valTokens3), testDescription, testCommissionMsg, sdk.OneInt(),
|
||||
sdk.ValAddress(input.addrs[2]), ed25519.GenPrivKey().PubKey(), sdk.NewCoin(sdk.DefaultBondDenom, valTokens3), testDescription, testCommissionRates, sdk.OneInt(),
|
||||
)
|
||||
stakingHandler(ctx, val3CreateMsg)
|
||||
|
||||
|
|
|
@ -192,7 +192,7 @@ var (
|
|||
}
|
||||
|
||||
testDescription = staking.NewDescription("T", "E", "S", "T")
|
||||
testCommissionMsg = staking.NewCommissionMsg(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec())
|
||||
testCommissionRates = staking.NewCommissionRates(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec())
|
||||
)
|
||||
|
||||
func createValidators(t *testing.T, stakingHandler sdk.Handler, ctx sdk.Context, addrs []sdk.ValAddress, powerAmt []int64) {
|
||||
|
@ -203,7 +203,7 @@ func createValidators(t *testing.T, stakingHandler sdk.Handler, ctx sdk.Context,
|
|||
valTokens := sdk.TokensFromTendermintPower(powerAmt[i])
|
||||
valCreateMsg := staking.NewMsgCreateValidator(
|
||||
addrs[i], pubkeys[i], sdk.NewCoin(sdk.DefaultBondDenom, valTokens),
|
||||
testDescription, testCommissionMsg, sdk.OneInt(),
|
||||
testDescription, testCommissionRates, sdk.OneInt(),
|
||||
)
|
||||
|
||||
res := stakingHandler(ctx, valCreateMsg)
|
||||
|
|
|
@ -103,7 +103,7 @@ func TestSlashingMsgs(t *testing.T) {
|
|||
mock.SetGenesis(mapp, accs)
|
||||
|
||||
description := staking.NewDescription("foo_moniker", "", "", "")
|
||||
commission := staking.NewCommissionMsg(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec())
|
||||
commission := staking.NewCommissionRates(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec())
|
||||
|
||||
createValidatorMsg := staking.NewMsgCreateValidator(
|
||||
sdk.ValAddress(addr1), priv1.PubKey(), bondCoin, description, commission, sdk.OneInt(),
|
||||
|
|
|
@ -111,7 +111,7 @@ func testAddr(addr string) sdk.AccAddress {
|
|||
}
|
||||
|
||||
func NewTestMsgCreateValidator(address sdk.ValAddress, pubKey crypto.PubKey, amt sdk.Int) staking.MsgCreateValidator {
|
||||
commission := staking.NewCommissionMsg(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec())
|
||||
commission := staking.NewCommissionRates(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec())
|
||||
return staking.NewMsgCreateValidator(
|
||||
address, pubKey, sdk.NewCoin(sdk.DefaultBondDenom, amt),
|
||||
staking.Description{}, commission, sdk.OneInt(),
|
||||
|
|
|
@ -78,7 +78,7 @@ var (
|
|||
NewQueryRedelegationParams = querier.NewQueryRedelegationParams
|
||||
NewQueryValidatorsParams = querier.NewQueryValidatorsParams
|
||||
RegisterCodec = types.RegisterCodec
|
||||
NewCommissionMsg = types.NewCommissionMsg
|
||||
NewCommissionRates = types.NewCommissionRates
|
||||
NewCommission = types.NewCommission
|
||||
NewCommissionWithTime = types.NewCommissionWithTime
|
||||
NewDelegation = types.NewDelegation
|
||||
|
@ -222,7 +222,7 @@ type (
|
|||
QueryRedelegationParams = querier.QueryRedelegationParams
|
||||
QueryValidatorsParams = querier.QueryValidatorsParams
|
||||
Commission = types.Commission
|
||||
CommissionMsg = types.CommissionMsg
|
||||
CommissionRates = types.CommissionRates
|
||||
DVPair = types.DVPair
|
||||
DVVTriplet = types.DVVTriplet
|
||||
Delegation = types.Delegation
|
||||
|
|
|
@ -116,7 +116,7 @@ func TestStakingMsgs(t *testing.T) {
|
|||
// create validator
|
||||
description := NewDescription("foo_moniker", "", "", "")
|
||||
createValidatorMsg := NewMsgCreateValidator(
|
||||
sdk.ValAddress(addr1), priv1.PubKey(), bondCoin, description, commissionMsg, sdk.OneInt(),
|
||||
sdk.ValAddress(addr1), priv1.PubKey(), bondCoin, description, commissionRates, sdk.OneInt(),
|
||||
)
|
||||
|
||||
header := abci.Header{Height: mApp.LastBlockHeight() + 1}
|
||||
|
|
|
@ -346,7 +346,7 @@ func BuildCreateValidatorMsg(cliCtx context.CLIContext, txBldr authtxb.TxBuilder
|
|||
rateStr := viper.GetString(FlagCommissionRate)
|
||||
maxRateStr := viper.GetString(FlagCommissionMaxRate)
|
||||
maxChangeRateStr := viper.GetString(FlagCommissionMaxChangeRate)
|
||||
commissionMsg, err := buildCommissionMsg(rateStr, maxRateStr, maxChangeRateStr)
|
||||
commissionRates, err := buildCommissionRates(rateStr, maxRateStr, maxChangeRateStr)
|
||||
if err != nil {
|
||||
return txBldr, nil, err
|
||||
}
|
||||
|
@ -359,7 +359,7 @@ func BuildCreateValidatorMsg(cliCtx context.CLIContext, txBldr authtxb.TxBuilder
|
|||
}
|
||||
|
||||
msg := types.NewMsgCreateValidator(
|
||||
sdk.ValAddress(valAddr), pk, amount, description, commissionMsg, minSelfDelegation,
|
||||
sdk.ValAddress(valAddr), pk, amount, description, commissionRates, minSelfDelegation,
|
||||
)
|
||||
|
||||
if viper.GetBool(client.FlagGenerateOnly) {
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
"github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
||||
func buildCommissionMsg(rateStr, maxRateStr, maxChangeRateStr string) (commission types.CommissionMsg, err error) {
|
||||
func buildCommissionRates(rateStr, maxRateStr, maxChangeRateStr string) (commission types.CommissionRates, err error) {
|
||||
if rateStr == "" || maxRateStr == "" || maxChangeRateStr == "" {
|
||||
return commission, errors.New("must specify all validator commission parameters")
|
||||
}
|
||||
|
@ -27,6 +27,6 @@ func buildCommissionMsg(rateStr, maxRateStr, maxChangeRateStr string) (commissio
|
|||
return commission, err
|
||||
}
|
||||
|
||||
commission = types.NewCommissionMsg(rate, maxRate, maxChangeRate)
|
||||
commission = types.NewCommissionRates(rate, maxRate, maxChangeRate)
|
||||
return commission, nil
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ func SimulateMsgCreateValidator(m auth.AccountKeeper, k staking.Keeper) simulati
|
|||
}
|
||||
|
||||
maxCommission := sdk.NewDecWithPrec(r.Int63n(1000), 3)
|
||||
commission := staking.NewCommissionMsg(
|
||||
commission := staking.NewCommissionRates(
|
||||
simulation.RandomDecAmount(r, maxCommission),
|
||||
maxCommission,
|
||||
simulation.RandomDecAmount(r, maxCommission),
|
||||
|
|
|
@ -23,19 +23,19 @@ var (
|
|||
sdk.Coins{sdk.NewCoin("foocoin", sdk.NewInt(0))},
|
||||
)
|
||||
|
||||
commissionMsg = NewCommissionMsg(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec())
|
||||
commissionRates = NewCommissionRates(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec())
|
||||
)
|
||||
|
||||
func NewTestMsgCreateValidator(address sdk.ValAddress, pubKey crypto.PubKey, amt sdk.Int) MsgCreateValidator {
|
||||
return types.NewMsgCreateValidator(
|
||||
address, pubKey, sdk.NewCoin(sdk.DefaultBondDenom, amt), Description{}, commissionMsg, sdk.OneInt(),
|
||||
address, pubKey, sdk.NewCoin(sdk.DefaultBondDenom, amt), Description{}, commissionRates, sdk.OneInt(),
|
||||
)
|
||||
}
|
||||
|
||||
func NewTestMsgCreateValidatorWithCommission(address sdk.ValAddress, pubKey crypto.PubKey,
|
||||
amt sdk.Int, commissionRate sdk.Dec) MsgCreateValidator {
|
||||
|
||||
commission := NewCommissionMsg(commissionRate, sdk.OneDec(), sdk.ZeroDec())
|
||||
commission := NewCommissionRates(commissionRate, sdk.OneDec(), sdk.ZeroDec())
|
||||
|
||||
return types.NewMsgCreateValidator(
|
||||
address, pubKey, sdk.NewCoin(sdk.DefaultBondDenom, amt), Description{}, commission, sdk.OneInt(),
|
||||
|
@ -46,7 +46,7 @@ func NewTestMsgCreateValidatorWithMinSelfDelegation(address sdk.ValAddress, pubK
|
|||
amt sdk.Int, minSelfDelegation sdk.Int) MsgCreateValidator {
|
||||
|
||||
return types.NewMsgCreateValidator(
|
||||
address, pubKey, sdk.NewCoin(sdk.DefaultBondDenom, amt), Description{}, commissionMsg, minSelfDelegation,
|
||||
address, pubKey, sdk.NewCoin(sdk.DefaultBondDenom, amt), Description{}, commissionRates, minSelfDelegation,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -10,24 +10,22 @@ import (
|
|||
type (
|
||||
// Commission defines a commission parameters for a given validator.
|
||||
Commission struct {
|
||||
Rate sdk.Dec `json:"rate"` // the commission rate charged to delegators, as a fraction
|
||||
MaxRate sdk.Dec `json:"max_rate"` // maximum commission rate which this validator can ever charge, as a fraction
|
||||
MaxChangeRate sdk.Dec `json:"max_change_rate"` // maximum daily increase of the validator commission, as a fraction
|
||||
CommissionRates
|
||||
UpdateTime time.Time `json:"update_time"` // the last time the commission rate was changed
|
||||
}
|
||||
|
||||
// CommissionMsg defines a commission message to be used for creating a
|
||||
// CommissionRates defines the initial commission rates to be used for creating a
|
||||
// validator.
|
||||
CommissionMsg struct {
|
||||
CommissionRates struct {
|
||||
Rate sdk.Dec `json:"rate"` // the commission rate charged to delegators, as a fraction
|
||||
MaxRate sdk.Dec `json:"max_rate"` // maximum commission rate which validator can ever charge, as a fraction
|
||||
MaxChangeRate sdk.Dec `json:"max_change_rate"` // maximum daily increase of the validator commission, as a fraction
|
||||
}
|
||||
)
|
||||
|
||||
// NewCommissionMsg returns an initialized validator commission message.
|
||||
func NewCommissionMsg(rate, maxRate, maxChangeRate sdk.Dec) CommissionMsg {
|
||||
return CommissionMsg{
|
||||
// NewCommissionRates returns an initialized validator commission rates.
|
||||
func NewCommissionRates(rate, maxRate, maxChangeRate sdk.Dec) CommissionRates {
|
||||
return CommissionRates{
|
||||
Rate: rate,
|
||||
MaxRate: maxRate,
|
||||
MaxChangeRate: maxChangeRate,
|
||||
|
@ -37,9 +35,7 @@ func NewCommissionMsg(rate, maxRate, maxChangeRate sdk.Dec) CommissionMsg {
|
|||
// NewCommission returns an initialized validator commission.
|
||||
func NewCommission(rate, maxRate, maxChangeRate sdk.Dec) Commission {
|
||||
return Commission{
|
||||
Rate: rate,
|
||||
MaxRate: maxRate,
|
||||
MaxChangeRate: maxChangeRate,
|
||||
CommissionRates: NewCommissionRates(rate, maxRate, maxChangeRate),
|
||||
UpdateTime: time.Unix(0, 0).UTC(),
|
||||
}
|
||||
}
|
||||
|
@ -48,9 +44,7 @@ func NewCommission(rate, maxRate, maxChangeRate sdk.Dec) Commission {
|
|||
// update time which should be the current block BFT time.
|
||||
func NewCommissionWithTime(rate, maxRate, maxChangeRate sdk.Dec, updatedAt time.Time) Commission {
|
||||
return Commission{
|
||||
Rate: rate,
|
||||
MaxRate: maxRate,
|
||||
MaxChangeRate: maxChangeRate,
|
||||
CommissionRates: NewCommissionRates(rate, maxRate, maxChangeRate),
|
||||
UpdateTime: updatedAt,
|
||||
}
|
||||
}
|
||||
|
@ -73,7 +67,7 @@ func (c Commission) String() string {
|
|||
|
||||
// Validate performs basic sanity validation checks of initial commission
|
||||
// parameters. If validation fails, an SDK error is returned.
|
||||
func (c Commission) Validate() sdk.Error {
|
||||
func (c CommissionRates) Validate() sdk.Error {
|
||||
switch {
|
||||
case c.MaxRate.LT(sdk.ZeroDec()):
|
||||
// max rate cannot be negative
|
||||
|
|
|
@ -23,7 +23,7 @@ var (
|
|||
// MsgCreateValidator - struct for bonding transactions
|
||||
type MsgCreateValidator struct {
|
||||
Description Description `json:"description"`
|
||||
Commission CommissionMsg `json:"commission"`
|
||||
Commission CommissionRates `json:"commission"`
|
||||
MinSelfDelegation sdk.Int `json:"min_self_delegation"`
|
||||
DelegatorAddress sdk.AccAddress `json:"delegator_address"`
|
||||
ValidatorAddress sdk.ValAddress `json:"validator_address"`
|
||||
|
@ -33,7 +33,7 @@ type MsgCreateValidator struct {
|
|||
|
||||
type msgCreateValidatorJSON struct {
|
||||
Description Description `json:"description"`
|
||||
Commission CommissionMsg `json:"commission"`
|
||||
Commission CommissionRates `json:"commission"`
|
||||
MinSelfDelegation sdk.Int `json:"min_self_delegation"`
|
||||
DelegatorAddress sdk.AccAddress `json:"delegator_address"`
|
||||
ValidatorAddress sdk.ValAddress `json:"validator_address"`
|
||||
|
@ -44,7 +44,7 @@ type msgCreateValidatorJSON struct {
|
|||
// Default way to create validator. Delegator address and validator address are the same
|
||||
func NewMsgCreateValidator(
|
||||
valAddr sdk.ValAddress, pubKey crypto.PubKey, selfDelegation sdk.Coin,
|
||||
description Description, commission CommissionMsg, minSelfDelegation sdk.Int,
|
||||
description Description, commission CommissionRates, minSelfDelegation sdk.Int,
|
||||
) MsgCreateValidator {
|
||||
|
||||
return MsgCreateValidator{
|
||||
|
@ -136,9 +136,12 @@ func (msg MsgCreateValidator) ValidateBasic() sdk.Error {
|
|||
if msg.Description == (Description{}) {
|
||||
return sdk.NewError(DefaultCodespace, CodeInvalidInput, "description must be included")
|
||||
}
|
||||
if msg.Commission == (CommissionMsg{}) {
|
||||
if msg.Commission == (CommissionRates{}) {
|
||||
return sdk.NewError(DefaultCodespace, CodeInvalidInput, "commission must be included")
|
||||
}
|
||||
if err := msg.Commission.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
if !msg.MinSelfDelegation.GT(sdk.ZeroInt()) {
|
||||
return ErrMinSelfDelegationInvalid(DefaultCodespace)
|
||||
}
|
||||
|
|
|
@ -16,12 +16,12 @@ var (
|
|||
|
||||
// test ValidateBasic for MsgCreateValidator
|
||||
func TestMsgCreateValidator(t *testing.T) {
|
||||
commission1 := NewCommissionMsg(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec())
|
||||
commission2 := NewCommissionMsg(sdk.NewDec(5), sdk.NewDec(5), sdk.NewDec(5))
|
||||
commission1 := NewCommissionRates(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec())
|
||||
commission2 := NewCommissionRates(sdk.NewDec(5), sdk.NewDec(5), sdk.NewDec(5))
|
||||
|
||||
tests := []struct {
|
||||
name, moniker, identity, website, details string
|
||||
commissionMsg CommissionMsg
|
||||
CommissionRates CommissionRates
|
||||
minSelfDelegation sdk.Int
|
||||
validatorAddr sdk.ValAddress
|
||||
pubkey crypto.PubKey
|
||||
|
@ -41,7 +41,7 @@ func TestMsgCreateValidator(t *testing.T) {
|
|||
|
||||
for _, tc := range tests {
|
||||
description := NewDescription(tc.moniker, tc.identity, tc.website, tc.details)
|
||||
msg := NewMsgCreateValidator(tc.validatorAddr, tc.pubkey, tc.bond, description, tc.commissionMsg, tc.minSelfDelegation)
|
||||
msg := NewMsgCreateValidator(tc.validatorAddr, tc.pubkey, tc.bond, description, tc.CommissionRates, tc.minSelfDelegation)
|
||||
if tc.expectPass {
|
||||
require.Nil(t, msg.ValidateBasic(), "test: %v", tc.name)
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue