-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge PR #7209: Create Vesting Account Message
- Loading branch information
1 parent
fcf5186
commit 325be6f
Showing
19 changed files
with
1,234 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
syntax = "proto3"; | ||
package cosmos.vesting.v1beta1; | ||
|
||
import "gogoproto/gogo.proto"; | ||
import "cosmos/base/v1beta1/coin.proto"; | ||
|
||
option go_package = "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"; | ||
|
||
// MsgCreateVestingAccount defines a message that enables creating a vesting | ||
// account. | ||
message MsgCreateVestingAccount { | ||
option (gogoproto.equal) = true; | ||
|
||
bytes from_address = 1 [ | ||
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress", | ||
(gogoproto.moretags) = "yaml:\"from_address\"" | ||
]; | ||
bytes to_address = 2 [ | ||
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress", | ||
(gogoproto.moretags) = "yaml:\"to_address\"" | ||
]; | ||
repeated cosmos.base.v1beta1.Coin amount = 3 | ||
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"]; | ||
|
||
int64 end_time = 4 [(gogoproto.moretags) = "yaml:\"end_time\""]; | ||
bool delayed = 5; | ||
} |
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,137 @@ | ||
package cli_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/gogo/protobuf/proto" | ||
"github.com/stretchr/testify/suite" | ||
|
||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" | ||
"github.com/cosmos/cosmos-sdk/testutil/network" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/x/auth/vesting/client/cli" | ||
) | ||
|
||
type IntegrationTestSuite struct { | ||
suite.Suite | ||
|
||
cfg network.Config | ||
network *network.Network | ||
} | ||
|
||
func (s *IntegrationTestSuite) SetupSuite() { | ||
s.T().Log("setting up integration test suite") | ||
|
||
cfg := network.DefaultConfig() | ||
cfg.NumValidators = 1 | ||
|
||
s.cfg = cfg | ||
s.network = network.New(s.T(), cfg) | ||
|
||
_, err := s.network.WaitForHeight(1) | ||
s.Require().NoError(err) | ||
} | ||
|
||
func (s *IntegrationTestSuite) TearDownSuite() { | ||
s.T().Log("tearing down integration test suite") | ||
s.network.Cleanup() | ||
} | ||
|
||
func (s *IntegrationTestSuite) TestNewMsgCreateVestingAccountCmd() { | ||
val := s.network.Validators[0] | ||
|
||
testCases := map[string]struct { | ||
args []string | ||
expectErr bool | ||
respType proto.Message | ||
expectedCode uint32 | ||
}{ | ||
"create a continuous vesting account": { | ||
args: []string{ | ||
sdk.AccAddress("addr2_______________").String(), | ||
sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String(), | ||
"4070908800", | ||
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address), | ||
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()), | ||
}, | ||
expectErr: false, | ||
respType: &sdk.TxResponse{}, | ||
expectedCode: 0, | ||
}, | ||
"create a delayed vesting account": { | ||
args: []string{ | ||
sdk.AccAddress("addr3_______________").String(), | ||
sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String(), | ||
"4070908800", | ||
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address), | ||
fmt.Sprintf("--%s=true", cli.FlagDelayed), | ||
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()), | ||
}, | ||
expectErr: false, | ||
respType: &sdk.TxResponse{}, | ||
expectedCode: 0, | ||
}, | ||
"invalid address": { | ||
args: []string{ | ||
sdk.AccAddress("addr4").String(), | ||
sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String(), | ||
"4070908800", | ||
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address), | ||
}, | ||
expectErr: true, | ||
respType: &sdk.TxResponse{}, | ||
expectedCode: 0, | ||
}, | ||
"invalid coins": { | ||
args: []string{ | ||
sdk.AccAddress("addr4_______________").String(), | ||
"fooo", | ||
"4070908800", | ||
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address), | ||
}, | ||
expectErr: true, | ||
respType: &sdk.TxResponse{}, | ||
expectedCode: 0, | ||
}, | ||
"invalid end time": { | ||
args: []string{ | ||
sdk.AccAddress("addr4_______________").String(), | ||
sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String(), | ||
"-4070908800", | ||
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address), | ||
}, | ||
expectErr: true, | ||
respType: &sdk.TxResponse{}, | ||
expectedCode: 0, | ||
}, | ||
} | ||
|
||
for name, tc := range testCases { | ||
tc := tc | ||
|
||
s.Run(name, func() { | ||
clientCtx := val.ClientCtx | ||
|
||
bw, err := clitestutil.ExecTestCLICmd(clientCtx, cli.NewMsgCreateVestingAccountCmd(), tc.args) | ||
if tc.expectErr { | ||
s.Require().Error(err) | ||
} else { | ||
s.Require().NoError(err) | ||
s.Require().NoError(clientCtx.JSONMarshaler.UnmarshalJSON(bw.Bytes(), tc.respType), bw.String()) | ||
|
||
txResp := tc.respType.(*sdk.TxResponse) | ||
s.Require().Equal(tc.expectedCode, txResp.Code) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestIntegrationTestSuite(t *testing.T) { | ||
suite.Run(t, new(IntegrationTestSuite)) | ||
} |
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,86 @@ | ||
package cli | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"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/x/auth/vesting/types" | ||
) | ||
|
||
// Transaction command flags | ||
const ( | ||
FlagDelayed = "delayed" | ||
) | ||
|
||
// GetTxCmd returns vesting module's transaction commands. | ||
func GetTxCmd() *cobra.Command { | ||
txCmd := &cobra.Command{ | ||
Use: types.ModuleName, | ||
Short: "Vesting transaction subcommands", | ||
DisableFlagParsing: true, | ||
SuggestionsMinimumDistance: 2, | ||
RunE: client.ValidateCmd, | ||
} | ||
|
||
txCmd.AddCommand( | ||
NewMsgCreateVestingAccountCmd(), | ||
) | ||
|
||
return txCmd | ||
} | ||
|
||
// NewMsgCreateVestingAccountCmd returns a CLI command handler for creating a | ||
// MsgCreateVestingAccount transaction. | ||
func NewMsgCreateVestingAccountCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "create-vesting-account [to_address] [amount] [end_time]", | ||
Short: "Create a new vesting account funded with an allocation of tokens.", | ||
Long: `Create a new vesting account funded with an allocation of tokens. The | ||
account can either be a delayed or continuous vesting account, which is determined | ||
by the '--delayed' flag. All vesting accouts created will have their start time | ||
set by the committed block's time. The end_time must be provided as a UNIX epoch | ||
timestamp.`, | ||
Args: cobra.ExactArgs(3), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
clientCtx := client.GetClientContextFromCmd(cmd) | ||
clientCtx, err := client.ReadTxCommandFlags(clientCtx, cmd.Flags()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
toAddr, err := sdk.AccAddressFromBech32(args[0]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
amount, err := sdk.ParseCoins(args[1]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
endTime, err := strconv.ParseInt(args[2], 10, 64) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
delayed, _ := cmd.Flags().GetBool(FlagDelayed) | ||
|
||
msg := types.NewMsgCreateVestingAccount(clientCtx.GetFromAddress(), toAddr, amount, endTime, delayed) | ||
if err := msg.ValidateBasic(); err != nil { | ||
return err | ||
} | ||
|
||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) | ||
}, | ||
} | ||
|
||
cmd.Flags().Bool(FlagDelayed, false, "Create a delayed vesting account if true") | ||
flags.AddTxFlagsToCmd(cmd) | ||
|
||
return cmd | ||
} |
Oops, something went wrong.