Add a CLI tests for create and list bond commands
All checks were successful
Integration Tests / test-integration (pull_request) Successful in 2m4s

This commit is contained in:
Prathamesh Musale 2024-03-02 12:53:50 +05:30
parent 19da88254e
commit a763d53a3c
4 changed files with 115 additions and 3 deletions

49
tests/e2e/bond/query.go Normal file
View File

@ -0,0 +1,49 @@
package bond
import (
"fmt"
"github.com/cosmos/cosmos-sdk/client/flags"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
bondtypes "git.vdb.to/cerc-io/laconic2d/x/bond"
"git.vdb.to/cerc-io/laconic2d/x/bond/client/cli"
)
func (ets *E2ETestSuite) TestGetQueryBondList() {
val := ets.network.Validators[0]
sr := ets.Require()
testCases := []struct {
name string
args []string
createBond bool
preRun func()
}{
{
"create and get bond lists",
[]string{fmt.Sprintf("--%s=json", flags.FlagOutput)},
true,
func() {
ets.createBond()
},
},
}
for _, tc := range testCases {
ets.Run(fmt.Sprintf("Case %s", tc.name), func() {
clientCtx := val.ClientCtx
if tc.createBond {
tc.preRun()
}
cmd := cli.GetQueryBondList()
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
sr.NoError(err)
var queryResponse bondtypes.QueryGetBondsResponse
err = clientCtx.Codec.UnmarshalJSON(out.Bytes(), &queryResponse)
sr.NoError(err)
sr.NotZero(len(queryResponse.GetBonds()))
})
}
}

View File

@ -107,7 +107,7 @@ func (ets *E2ETestSuite) createBond() string {
// getting the bonds list and returning the bond-id // getting the bonds list and returning the bond-id
clientCtx := val.ClientCtx clientCtx := val.ClientCtx
cmd := cli.GetQueryBondLists() cmd := cli.GetQueryBondList()
args = []string{ args = []string{
fmt.Sprintf("--%s=json", flags.FlagOutput), fmt.Sprintf("--%s=json", flags.FlagOutput),
} }

63
tests/e2e/bond/tx.go Normal file
View File

@ -0,0 +1,63 @@
package bond
import (
"fmt"
"github.com/cosmos/cosmos-sdk/client/flags"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
sdk "github.com/cosmos/cosmos-sdk/types"
"git.vdb.to/cerc-io/laconic2d/x/bond/client/cli"
)
func (ets *E2ETestSuite) TestTxCreateBond() {
val := ets.network.Validators[0]
sr := ets.Require()
testCases := []struct {
name string
args []string
err bool
}{
{
"without deposit",
[]string{
fmt.Sprintf("--%s=%s", flags.FlagFrom, ets.accountName),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
fmt.Sprintf("--%s=%s", flags.FlagFees, fmt.Sprintf("3%s", ets.cfg.BondDenom)),
},
true,
},
{
"create bond",
[]string{
fmt.Sprintf("10%s", ets.cfg.BondDenom),
fmt.Sprintf("--%s=%s", flags.FlagFrom, ets.accountName),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
fmt.Sprintf("--%s=json", flags.FlagOutput),
fmt.Sprintf("--%s=%s", flags.FlagFees, fmt.Sprintf("3%s", ets.cfg.BondDenom)),
},
false,
},
}
for _, tc := range testCases {
ets.Run(fmt.Sprintf("Case %s", tc.name), func() {
clientCtx := val.ClientCtx
cmd := cli.NewCreateBondCmd()
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
if tc.err {
sr.Error(err)
} else {
sr.NoError(err)
var d sdk.TxResponse
err = val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &d)
sr.Nil(err)
sr.NoError(err)
sr.Zero(d.Code)
}
})
}
}

View File

@ -12,8 +12,8 @@ import (
bondtypes "git.vdb.to/cerc-io/laconic2d/x/bond" bondtypes "git.vdb.to/cerc-io/laconic2d/x/bond"
) )
// GetQueryBondLists implements the bond lists query command. // GetQueryBondList implements the bond lists query command.
func GetQueryBondLists() *cobra.Command { func GetQueryBondList() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "list", Use: "list",
Short: "List bonds.", Short: "List bonds.",