-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: set max cap in creating vestings per user * chore: add more unit tests in vesting * chore: update proto buf to do error handling in CLI side * move CLI flag constants declaration in CLI folder * cfix: remove hardcoded gov module name --------- Co-authored-by: Cosmic Vagabond <121588426+cosmic-vagabond@users.noreply.github.com>
- Loading branch information
1 parent
be505a9
commit be3bd0d
Showing
34 changed files
with
1,342 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package cli | ||
|
||
const ( | ||
BaseDenom = "base-denom" | ||
VestingDenom = "vesting-denom" | ||
EpochIdentifier = "epoch-identifier" | ||
NumEpochs = "num-epochs" | ||
VestNowFactor = "vest-now-factor" | ||
NumMaxVestings = "num-max-vestings" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
package cli | ||
|
||
import ( | ||
"errors" | ||
"strconv" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/cosmos/cosmos-sdk/client/tx" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/address" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
"github.com/cosmos/cosmos-sdk/x/gov/client/cli" | ||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" | ||
v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" | ||
"github.com/elys-network/elys/x/commitment/types" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var _ = strconv.Itoa(0) | ||
|
||
func CmdUpdateVestingInfo() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "update-vesting-info", | ||
Short: "Broadcast message update-vesting-info", | ||
Args: cobra.ExactArgs(0), | ||
RunE: func(cmd *cobra.Command, args []string) (err error) { | ||
clientCtx, err := client.GetClientTxContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
title, err := cmd.Flags().GetString(cli.FlagTitle) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
summary, err := cmd.Flags().GetString(cli.FlagSummary) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
metadata, err := cmd.Flags().GetString(cli.FlagMetadata) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
argBaseDenom, err := cmd.Flags().GetString(BaseDenom) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
argVestingDenom, err := cmd.Flags().GetString(VestingDenom) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
argEpochIdentifier, err := cmd.Flags().GetString(EpochIdentifier) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
argNumEpochs, err := cmd.Flags().GetString(NumEpochs) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
argVestNowFactor, err := cmd.Flags().GetString(VestNowFactor) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
argNumMaxVestings, err := cmd.Flags().GetString(NumMaxVestings) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
signer := clientCtx.GetFromAddress() | ||
if signer == nil { | ||
return errors.New("signer address is missing") | ||
} | ||
|
||
numEpochs, err := strconv.ParseInt(argNumEpochs, 10, 64) | ||
if err != nil { | ||
return sdkerrors.Wrapf(govtypes.ErrInvalidProposalMsg, "invalid proposal; %d", argNumEpochs) | ||
} | ||
|
||
vestNowFactor, err := strconv.ParseInt(argVestNowFactor, 10, 64) | ||
if err != nil { | ||
return sdkerrors.Wrapf(govtypes.ErrInvalidProposalMsg, "invalid proposal; %d", argVestNowFactor) | ||
} | ||
|
||
maxVestings, err := strconv.ParseInt(argNumMaxVestings, 10, 64) | ||
if err != nil { | ||
return sdkerrors.Wrapf(govtypes.ErrInvalidProposalMsg, "invalid proposal; %d", argNumMaxVestings) | ||
} | ||
|
||
govAddress := sdk.AccAddress(address.Module(govtypes.ModuleName)) | ||
msg := types.NewMsgUpdateVestingInfo( | ||
govAddress.String(), | ||
argBaseDenom, | ||
argVestingDenom, | ||
argEpochIdentifier, | ||
numEpochs, | ||
vestNowFactor, | ||
maxVestings, | ||
) | ||
if err := msg.ValidateBasic(); err != nil { | ||
return err | ||
} | ||
|
||
depositStr, err := cmd.Flags().GetString(cli.FlagDeposit) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
deposit, err := sdk.ParseCoinsNormalized(depositStr) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
govMsg, err := v1.NewMsgSubmitProposal([]sdk.Msg{msg}, deposit, signer.String(), metadata, title, summary) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), govMsg) | ||
}, | ||
} | ||
|
||
cmd.Flags().String(BaseDenom, "", "base denom") | ||
cmd.Flags().String(VestingDenom, "", "vesting-denom") | ||
cmd.Flags().String(EpochIdentifier, "", "epoch-identifier") | ||
cmd.Flags().String(NumEpochs, "", "num-epochs") | ||
cmd.Flags().String(VestNowFactor, "", "vest-now-factor") | ||
cmd.Flags().String(NumMaxVestings, "", "num-max-vestings") | ||
cmd.Flags().String(cli.FlagTitle, "", "title of proposal") | ||
cmd.Flags().String(cli.FlagSummary, "", "summary of proposal") | ||
cmd.Flags().String(cli.FlagMetadata, "", "metadata of proposal") | ||
cmd.Flags().String(cli.FlagDeposit, "", "deposit of proposal") | ||
_ = cmd.MarkFlagRequired(BaseDenom) | ||
_ = cmd.MarkFlagRequired(VestingDenom) | ||
_ = cmd.MarkFlagRequired(EpochIdentifier) | ||
_ = cmd.MarkFlagRequired(NumEpochs) | ||
_ = cmd.MarkFlagRequired(VestNowFactor) | ||
_ = cmd.MarkFlagRequired(NumMaxVestings) | ||
_ = cmd.MarkFlagRequired(cli.FlagTitle) | ||
_ = cmd.MarkFlagRequired(cli.FlagSummary) | ||
_ = cmd.MarkFlagRequired(cli.FlagMetadata) | ||
_ = cmd.MarkFlagRequired(cli.FlagDeposit) | ||
flags.AddTxFlagsToCmd(cmd) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package cli_test | ||
|
||
import ( | ||
"strconv" | ||
"testing" | ||
|
||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/elys-network/elys/testutil/network" | ||
"github.com/elys-network/elys/x/commitment/client/cli" | ||
) | ||
|
||
// Prevent strconv unused error | ||
var _ = strconv.IntSize | ||
|
||
func setupNetwork(t *testing.T) *network.Network { | ||
t.Helper() | ||
|
||
cfg := network.DefaultConfig() | ||
return network.New(t, cfg) | ||
} | ||
|
||
func TestGovUpdateVestingInfo(t *testing.T) { | ||
net := setupNetwork(t) | ||
ctx := net.Validators[0].ClientCtx | ||
val := net.Validators[0] | ||
|
||
// Use baseURL to make API HTTP requests or use val.RPCClient to make direct | ||
// Tendermint RPC calls. | ||
// ... | ||
|
||
args := []string{ | ||
"--title=test", | ||
"--summary=test", | ||
"--metadata=test", | ||
"--deposit=1000000uelys", | ||
"--base-denom=ueden", | ||
"--vesting-denom=uelys", | ||
"--epoch-identifier=day", | ||
"--num-epochs=100", | ||
"--vest-now-factor=1", | ||
"--num-max-vestings=10", | ||
"--from=" + val.Address.String(), | ||
"-y", | ||
} | ||
|
||
_, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdUpdateVestingInfo(), args) | ||
require.NoError(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.