Skip to content

Commit

Permalink
feat: add clawback vesting account (cosmos#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
czarcas7ic committed Oct 30, 2023
1 parent 5450211 commit 09e0036
Show file tree
Hide file tree
Showing 14 changed files with 1,356 additions and 0 deletions.
230 changes: 230 additions & 0 deletions tests/e2e/auth/vesting/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,233 @@ func (s *E2ETestSuite) TestNewMsgCreatePermanentLockedAccountCmd() {
s.T().Logf("Height now: %d", height)
}
}

func (s *E2ETestSuite) TestNewMsgCreateClawbackVestingAccountCmd() {
val := s.network.Validators[0]
for _, tc := range []struct {
name string
args []string
expectErr bool
expectedCode uint32
respType proto.Message
}{
{
name: "basic",
args: []string{
sdk.AccAddress("addr10______________").String(),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address),
fmt.Sprintf("--%s=%s", cli.FlagLockup, "testdata/periods1.json"),
fmt.Sprintf("--%s=%s", cli.FlagVesting, "testdata/periods1.json"),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
},
expectErr: false,
expectedCode: 0,
respType: &sdk.TxResponse{},
},
{
name: "defaultLockup",
args: []string{
sdk.AccAddress("addr11______________").String(),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address),
fmt.Sprintf("--%s=%s", cli.FlagVesting, "testdata/periods1.json"),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
},
expectErr: false,
expectedCode: 0,
respType: &sdk.TxResponse{},
},
{
name: "defaultVesting",
args: []string{
sdk.AccAddress("addr12______________").String(),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address),
fmt.Sprintf("--%s=%s", cli.FlagLockup, "testdata/periods1.json"),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
},
expectErr: false,
expectedCode: 0,
respType: &sdk.TxResponse{},
},
{
name: "merge",
args: []string{
sdk.AccAddress("addr10______________").String(),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address),
fmt.Sprintf("--%s=%s", cli.FlagLockup, "testdata/periods1.json"),
fmt.Sprintf("--%s=%s", cli.FlagVesting, "testdata/periods1.json"),
fmt.Sprintf("--%s=%s", cli.FlagMerge, "true"),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
},
expectErr: false,
expectedCode: 0,
respType: &sdk.TxResponse{},
},
{
name: "bad vesting addr",
args: []string{
"foo",
},
expectErr: true,
},
{
name: "no files",
args: []string{
sdk.AccAddress("addr13______________").String(),
},
expectErr: true,
},
{
name: "bad lockup filename",
args: []string{
sdk.AccAddress("addr13______________").String(),
fmt.Sprintf("--%s=%s", cli.FlagLockup, "testdata/noexist"),
},
expectErr: true,
},
{
name: "bad lockup json",
args: []string{
sdk.AccAddress("addr13______________").String(),
fmt.Sprintf("--%s=%s", cli.FlagLockup, "testdata/badjson"),
},
expectErr: true,
},
{
name: "bad lockup periods",
args: []string{
sdk.AccAddress("addr13______________").String(),
fmt.Sprintf("--%s=%s", cli.FlagLockup, "testdata/badperiod.json"),
},
expectErr: true,
},
{
name: "bad vesting filename",
args: []string{
sdk.AccAddress("addr13______________").String(),
fmt.Sprintf("--%s=%s", cli.FlagVesting, "testdata/noexist"),
},
expectErr: true,
},
{
name: "bad vesting json",
args: []string{
sdk.AccAddress("addr13______________").String(),
fmt.Sprintf("--%s=%s", cli.FlagVesting, "testdata/badjson"),
},
expectErr: true,
},
{
name: "bad vesting periods",
args: []string{
sdk.AccAddress("addr13______________").String(),
fmt.Sprintf("--%s=%s", cli.FlagVesting, "testdata/badperiod.json"),
},
expectErr: true,
},
} {
s.Run(tc.name, func() {
clientCtx := val.ClientCtx

bw, err := clitestutil.ExecTestCLICmd(clientCtx, cli.NewMsgCreateClawbackVestingAccountCmd(), tc.args)
if tc.expectErr {
s.Require().Error(err)
} else {
s.Require().NoError(err)
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(bw.Bytes(), tc.respType), bw.String())

txResp := tc.respType.(*sdk.TxResponse)
s.Require().Equal(tc.expectedCode, txResp.Code)
}
})
}
}

func (s *E2ETestSuite) TestNewMsgClawbackCmd() {
val := s.network.Validators[0]
addr := sdk.AccAddress("addr30______________")

_, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cli.NewMsgCreateClawbackVestingAccountCmd(), []string{
addr.String(),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address),
fmt.Sprintf("--%s=%s", cli.FlagLockup, "testdata/periods1.json"),
fmt.Sprintf("--%s=%s", cli.FlagVesting, "testdata/periods1.json"),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
})
s.Require().NoError(err)

for _, tc := range []struct {
name string
args []string
expectErr bool
expectedCode uint32
respType proto.Message
}{
{
name: "basic",
args: []string{
addr.String(),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address),
fmt.Sprintf("--%s=%s", cli.FlagDest, sdk.AccAddress("addr32______________").String()),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
},
expectErr: false,
expectedCode: 0,
respType: &sdk.TxResponse{},
},
{
name: "bad vesting addr",
args: []string{
"foo",
},
expectErr: true,
},
{
name: "bad dest addr",
args: []string{
addr.String(),
fmt.Sprintf("--%s=%s", cli.FlagDest, "bar"),
},
expectErr: true,
},
{
name: "default dest",
args: []string{
addr.String(),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
},
expectErr: false,
expectedCode: 0,
respType: &sdk.TxResponse{},
},
} {
s.Run(tc.name, func() {
clientCtx := val.ClientCtx

bw, err := clitestutil.ExecTestCLICmd(clientCtx, cli.NewMsgClawbackCmd(), tc.args)
if tc.expectErr {
s.Require().Error(err)
} else {
s.Require().NoError(err)
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(bw.Bytes(), tc.respType), bw.String())

txResp := tc.respType.(*sdk.TxResponse)
s.Require().Equal(tc.expectedCode, txResp.Code)
}
})
}
}
Loading

0 comments on commit 09e0036

Please sign in to comment.