Add e2e tests for gRPC requests and CLI commands #13

Merged
ashwin merged 14 commits from pm-cli-tests into main 2024-03-04 11:16:11 +00:00
4 changed files with 115 additions and 3 deletions
Showing only changes of commit a763d53a3c - Show all commits

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
clientCtx := val.ClientCtx
cmd := cli.GetQueryBondLists()
cmd := cli.GetQueryBondList()
args = []string{
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"
)
// GetQueryBondLists implements the bond lists query command.
func GetQueryBondLists() *cobra.Command {
// GetQueryBondList implements the bond lists query command.
func GetQueryBondList() *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Short: "List bonds.",