Skip to content

Commit

Permalink
added missing cmd tests
Browse files Browse the repository at this point in the history
Signed-off-by: Riccardo Montagnin <riccardo.montagnin@gmail.com>
  • Loading branch information
RiccardoM committed Feb 15, 2022
1 parent b9e8769 commit 6c6e53b
Showing 1 changed file with 99 additions and 0 deletions.
99 changes: 99 additions & 0 deletions x/subspaces/client/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,105 @@ func (s *IntegrationTestSuite) TestCmdCreateUserGroup() {
}
}

func (s *IntegrationTestSuite) TestCmdEditUserGroup() {
val := s.network.Validators[0]
testCases := []struct {
name string
args []string
shouldErr bool
respType proto.Message
}{
{
name: "invalid subspace id returns error",
args: []string{"0", "1"},
shouldErr: true,
},
{
name: "invalid group id returns error",
args: []string{"1", "0"},
shouldErr: true,
},
{
name: "valid data returns no error",
args: []string{
"1", "1",
fmt.Sprintf("--%s=%s", flags.FlagName, "This is my new group name"),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
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()),
},
shouldErr: false,
respType: &sdk.TxResponse{},
},
}

for _, tc := range testCases {
tc := tc
s.Run(tc.name, func() {
cmd := cli.GetCmdEditUserGroup()
clientCtx := val.ClientCtx

out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
if tc.shouldErr {
s.Require().Error(err)
} else {
s.Require().NoError(err)
s.Require().NoError(clientCtx.JSONCodec.UnmarshalJSON(out.Bytes(), tc.respType), out.String())
}
})
}
}

func (s *IntegrationTestSuite) TestCmdSetUserGroupPermissions() {
val := s.network.Validators[0]
testCases := []struct {
name string
args []string
shouldErr bool
respType proto.Message
}{
{
name: "invalid subspace id returns error",
args: []string{"0", "1"},
shouldErr: true,
},
{
name: "invalid group id returns error",
args: []string{"1", "0"},
shouldErr: true,
},
{
name: "valid data returns no error",
args: []string{
"1", "1", types.SerializePermission(types.PermissionWrite),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
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()),
},
shouldErr: false,
respType: &sdk.TxResponse{},
},
}

for _, tc := range testCases {
tc := tc
s.Run(tc.name, func() {
cmd := cli.GetCmdSetUserGroupPermissions()
clientCtx := val.ClientCtx

out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
if tc.shouldErr {
s.Require().Error(err)
} else {
s.Require().NoError(err)
s.Require().NoError(clientCtx.JSONCodec.UnmarshalJSON(out.Bytes(), tc.respType), out.String())
}
})
}
}

func (s *IntegrationTestSuite) TestCmdDeleteUserGroup() {
val := s.network.Validators[0]
testCases := []struct {
Expand Down

0 comments on commit 6c6e53b

Please sign in to comment.