Merge pull request #1827 from cosmos/sunny/fix-do-not-modify
ready-for-review: fixed donotmodify bug
This commit is contained in:
commit
9e0f5ac241
|
@ -2,6 +2,8 @@ package cli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
flag "github.com/spf13/pflag"
|
flag "github.com/spf13/pflag"
|
||||||
|
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/stake/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// nolint
|
// nolint
|
||||||
|
@ -23,13 +25,14 @@ const (
|
||||||
|
|
||||||
// common flagsets to add to various functions
|
// common flagsets to add to various functions
|
||||||
var (
|
var (
|
||||||
fsPk = flag.NewFlagSet("", flag.ContinueOnError)
|
fsPk = flag.NewFlagSet("", flag.ContinueOnError)
|
||||||
fsAmount = flag.NewFlagSet("", flag.ContinueOnError)
|
fsAmount = flag.NewFlagSet("", flag.ContinueOnError)
|
||||||
fsShares = flag.NewFlagSet("", flag.ContinueOnError)
|
fsShares = flag.NewFlagSet("", flag.ContinueOnError)
|
||||||
fsDescription = flag.NewFlagSet("", flag.ContinueOnError)
|
fsDescriptionCreate = flag.NewFlagSet("", flag.ContinueOnError)
|
||||||
fsValidator = flag.NewFlagSet("", flag.ContinueOnError)
|
fsDescriptionEdit = flag.NewFlagSet("", flag.ContinueOnError)
|
||||||
fsDelegator = flag.NewFlagSet("", flag.ContinueOnError)
|
fsValidator = flag.NewFlagSet("", flag.ContinueOnError)
|
||||||
fsRedelegation = flag.NewFlagSet("", flag.ContinueOnError)
|
fsDelegator = flag.NewFlagSet("", flag.ContinueOnError)
|
||||||
|
fsRedelegation = flag.NewFlagSet("", flag.ContinueOnError)
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -37,10 +40,14 @@ func init() {
|
||||||
fsAmount.String(FlagAmount, "1steak", "Amount of coins to bond")
|
fsAmount.String(FlagAmount, "1steak", "Amount of coins to bond")
|
||||||
fsShares.String(FlagSharesAmount, "", "Amount of source-shares to either unbond or redelegate as a positive integer or decimal")
|
fsShares.String(FlagSharesAmount, "", "Amount of source-shares to either unbond or redelegate as a positive integer or decimal")
|
||||||
fsShares.String(FlagSharesPercent, "", "Percent of source-shares to either unbond or redelegate as a positive integer or decimal >0 and <=1")
|
fsShares.String(FlagSharesPercent, "", "Percent of source-shares to either unbond or redelegate as a positive integer or decimal >0 and <=1")
|
||||||
fsDescription.String(FlagMoniker, "[do-not-modify]", "validator name")
|
fsDescriptionCreate.String(FlagMoniker, "", "validator name")
|
||||||
fsDescription.String(FlagIdentity, "[do-not-modify]", "optional identity signature (ex. UPort or Keybase)")
|
fsDescriptionCreate.String(FlagIdentity, "", "optional identity signature (ex. UPort or Keybase)")
|
||||||
fsDescription.String(FlagWebsite, "[do-not-modify]", "optional website")
|
fsDescriptionCreate.String(FlagWebsite, "", "optional website")
|
||||||
fsDescription.String(FlagDetails, "[do-not-modify]", "optional details")
|
fsDescriptionCreate.String(FlagDetails, "", "optional details")
|
||||||
|
fsDescriptionEdit.String(FlagMoniker, types.DoNotModifyDesc, "validator name")
|
||||||
|
fsDescriptionEdit.String(FlagIdentity, types.DoNotModifyDesc, "optional identity signature (ex. UPort or Keybase)")
|
||||||
|
fsDescriptionEdit.String(FlagWebsite, types.DoNotModifyDesc, "optional website")
|
||||||
|
fsDescriptionEdit.String(FlagDetails, types.DoNotModifyDesc, "optional details")
|
||||||
fsValidator.String(FlagAddressValidator, "", "hex address of the validator")
|
fsValidator.String(FlagAddressValidator, "", "hex address of the validator")
|
||||||
fsDelegator.String(FlagAddressDelegator, "", "hex address of the delegator")
|
fsDelegator.String(FlagAddressDelegator, "", "hex address of the delegator")
|
||||||
fsRedelegation.String(FlagAddressValidatorSrc, "", "hex address of the source validator")
|
fsRedelegation.String(FlagAddressValidatorSrc, "", "hex address of the source validator")
|
||||||
|
|
|
@ -73,7 +73,7 @@ func GetCmdCreateValidator(cdc *wire.Codec) *cobra.Command {
|
||||||
|
|
||||||
cmd.Flags().AddFlagSet(fsPk)
|
cmd.Flags().AddFlagSet(fsPk)
|
||||||
cmd.Flags().AddFlagSet(fsAmount)
|
cmd.Flags().AddFlagSet(fsAmount)
|
||||||
cmd.Flags().AddFlagSet(fsDescription)
|
cmd.Flags().AddFlagSet(fsDescriptionCreate)
|
||||||
cmd.Flags().AddFlagSet(fsDelegator)
|
cmd.Flags().AddFlagSet(fsDelegator)
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,7 @@ func GetCmdEditValidator(cdc *wire.Codec) *cobra.Command {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.Flags().AddFlagSet(fsDescription)
|
cmd.Flags().AddFlagSet(fsDescriptionEdit)
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,8 +13,6 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/wire"
|
"github.com/cosmos/cosmos-sdk/wire"
|
||||||
)
|
)
|
||||||
|
|
||||||
const doNotModifyDescVal = "[do-not-modify]"
|
|
||||||
|
|
||||||
// Validator defines the total amount of bond shares and their exchange rate to
|
// Validator defines the total amount of bond shares and their exchange rate to
|
||||||
// coins. Accumulation of interest is modelled as an in increase in the
|
// coins. Accumulation of interest is modelled as an in increase in the
|
||||||
// exchange rate, and slashing as a decrease. When coins are delegated to this
|
// exchange rate, and slashing as a decrease. When coins are delegated to this
|
||||||
|
@ -250,6 +248,9 @@ func (v Validator) Equal(c2 Validator) bool {
|
||||||
v.LastBondedTokens.Equal(c2.LastBondedTokens)
|
v.LastBondedTokens.Equal(c2.LastBondedTokens)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// constant used in flags to indicate that description field should not be updated
|
||||||
|
const DoNotModifyDesc = "[do-not-modify]"
|
||||||
|
|
||||||
// Description - description fields for a validator
|
// Description - description fields for a validator
|
||||||
type Description struct {
|
type Description struct {
|
||||||
Moniker string `json:"moniker"` // name
|
Moniker string `json:"moniker"` // name
|
||||||
|
@ -271,16 +272,16 @@ func NewDescription(moniker, identity, website, details string) Description {
|
||||||
// UpdateDescription updates the fields of a given description. An error is
|
// UpdateDescription updates the fields of a given description. An error is
|
||||||
// returned if the resulting description contains an invalid length.
|
// returned if the resulting description contains an invalid length.
|
||||||
func (d Description) UpdateDescription(d2 Description) (Description, sdk.Error) {
|
func (d Description) UpdateDescription(d2 Description) (Description, sdk.Error) {
|
||||||
if d.Moniker == doNotModifyDescVal {
|
if d2.Moniker == DoNotModifyDesc {
|
||||||
d2.Moniker = d.Moniker
|
d2.Moniker = d.Moniker
|
||||||
}
|
}
|
||||||
if d.Identity == doNotModifyDescVal {
|
if d2.Identity == DoNotModifyDesc {
|
||||||
d2.Identity = d.Identity
|
d2.Identity = d.Identity
|
||||||
}
|
}
|
||||||
if d.Website == doNotModifyDescVal {
|
if d2.Website == DoNotModifyDesc {
|
||||||
d2.Website = d.Website
|
d2.Website = d.Website
|
||||||
}
|
}
|
||||||
if d.Details == doNotModifyDescVal {
|
if d2.Details == DoNotModifyDesc {
|
||||||
d2.Details = d.Details
|
d2.Details = d.Details
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,19 +25,31 @@ func TestValidatorEqual(t *testing.T) {
|
||||||
|
|
||||||
func TestUpdateDescription(t *testing.T) {
|
func TestUpdateDescription(t *testing.T) {
|
||||||
d1 := Description{
|
d1 := Description{
|
||||||
Moniker: doNotModifyDescVal,
|
|
||||||
Identity: doNotModifyDescVal,
|
|
||||||
Website: doNotModifyDescVal,
|
|
||||||
Details: doNotModifyDescVal,
|
|
||||||
}
|
|
||||||
d2 := Description{
|
|
||||||
Website: "https://validator.cosmos",
|
Website: "https://validator.cosmos",
|
||||||
Details: "Test validator",
|
Details: "Test validator",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
d2 := Description{
|
||||||
|
Moniker: DoNotModifyDesc,
|
||||||
|
Identity: DoNotModifyDesc,
|
||||||
|
Website: DoNotModifyDesc,
|
||||||
|
Details: DoNotModifyDesc,
|
||||||
|
}
|
||||||
|
|
||||||
|
d3 := Description{
|
||||||
|
Moniker: "",
|
||||||
|
Identity: "",
|
||||||
|
Website: "",
|
||||||
|
Details: "",
|
||||||
|
}
|
||||||
|
|
||||||
d, err := d1.UpdateDescription(d2)
|
d, err := d1.UpdateDescription(d2)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
require.Equal(t, d, d1)
|
require.Equal(t, d, d1)
|
||||||
|
|
||||||
|
d, err = d1.UpdateDescription(d3)
|
||||||
|
require.Nil(t, err)
|
||||||
|
require.Equal(t, d, d3)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestABCIValidator(t *testing.T) {
|
func TestABCIValidator(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue