forked from cerc-io/laconicd
Add e2e tests for gRPC requests and CLI commands (#13)
- Add E2E tests following pattern suggested in cosmos-sdk docs: https://docs.cosmos.network/v0.50/build/building-modules/testing#end-to-end-tests - Tests for gRPC requests - Tests for manually configured CLI commands - Add a CI workflow to run these E2E tests Reviewed-on: deep-stack/laconic2d#13 Co-authored-by: Prathamesh Musale <prathamesh.musale0@gmail.com> Co-committed-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/version"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
bondtypes "git.vdb.to/cerc-io/laconic2d/x/bond"
|
||||
)
|
||||
|
||||
// GetQueryBondList implements the bond lists query command.
|
||||
func GetQueryBondList() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "List bonds.",
|
||||
Long: strings.TrimSpace(
|
||||
fmt.Sprintf(`Get bond list .
|
||||
|
||||
Example:
|
||||
$ %s query %s list
|
||||
`,
|
||||
version.AppName, bondtypes.ModuleName,
|
||||
),
|
||||
),
|
||||
Args: cobra.ExactArgs(0),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx, err := client.GetClientQueryContext(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
queryClient := bondtypes.NewQueryClient(clientCtx)
|
||||
res, err := queryClient.Bonds(cmd.Context(), &bondtypes.QueryGetBondsRequest{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return clientCtx.PrintProto(res)
|
||||
},
|
||||
}
|
||||
|
||||
flags.AddQueryFlagsToCmd(cmd)
|
||||
|
||||
return cmd
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"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/spf13/cobra"
|
||||
|
||||
bondtypes "git.vdb.to/cerc-io/laconic2d/x/bond"
|
||||
)
|
||||
|
||||
// NewCreateBondCmd is the CLI command for creating a bond.
|
||||
// Used in e2e tests
|
||||
func NewCreateBondCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "create [amount]",
|
||||
Short: "Create bond.",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx, err := client.GetClientTxContext(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
coin, err := sdk.ParseCoinNormalized(args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
msg := bondtypes.NewMsgCreateBond(sdk.NewCoins(coin), clientCtx.GetFromAddress())
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg)
|
||||
},
|
||||
}
|
||||
|
||||
flags.AddTxFlagsToCmd(cmd)
|
||||
|
||||
return cmd
|
||||
}
|
||||
@@ -28,7 +28,6 @@ type GenesisState struct {
|
||||
// params defines all the parameters of the module.
|
||||
Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"`
|
||||
// bonds defines all the bonds
|
||||
// TODO: Add nullable = false ?
|
||||
Bonds []*Bond `protobuf:"bytes,2,rep,name=bonds,proto3" json:"bonds,omitempty" json:"bonds" yaml:"bonds"`
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,8 @@ func (ms msgServer) CreateBond(c context.Context, msg *bond.MsgCreateBond) (*bon
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_, err = ms.k.CreateBond(ctx, signerAddress, msg.Coins)
|
||||
|
||||
resp, err := ms.k.CreateBond(ctx, signerAddress, msg.Coins)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -44,7 +45,7 @@ func (ms msgServer) CreateBond(c context.Context, msg *bond.MsgCreateBond) (*bon
|
||||
),
|
||||
})
|
||||
|
||||
return &bond.MsgCreateBondResponse{}, nil
|
||||
return &bond.MsgCreateBondResponse{Id: resp.Id}, nil
|
||||
}
|
||||
|
||||
// RefillBond implements bond.MsgServer.
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package bond
|
||||
|
||||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
var (
|
||||
_ sdk.Msg = &MsgCreateBond{}
|
||||
)
|
||||
|
||||
// NewMsgCreateBond is the constructor function for MsgCreateBond.
|
||||
func NewMsgCreateBond(coins sdk.Coins, signer sdk.AccAddress) MsgCreateBond {
|
||||
return MsgCreateBond{
|
||||
Coins: coins,
|
||||
Signer: signer.String(),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user