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
7 changed files with 166 additions and 3 deletions
Showing only changes of commit b57ca60277 - Show all commits

View File

@ -88,3 +88,6 @@ lint-fix:
test-integration: test-integration:
$(MAKE) -C tests test-integration $(MAKE) -C tests test-integration
test-e2e:
$(MAKE) -C tests test-e2e

View File

@ -10,11 +10,15 @@ Install and run `laconic2d`:
make init make init
# start the chain # start the chain
laconic2d start laconic2d start --gql-playground --gql-server
``` ```
Run tests: Run tests:
```bash ```bash
# integration tests
make test-integration make test-integration
# e2e tests
make test-e2e
``` ```

View File

@ -16,7 +16,6 @@ for dir in $proto_dirs; do
done done
done done
# TODO: Check if required
echo "Generating pulsar proto code" echo "Generating pulsar proto code"
buf generate --template buf.gen.pulsar.yaml buf generate --template buf.gen.pulsar.yaml

View File

@ -1,2 +1,4 @@
test-integration: test-integration:
go test -mod=readonly ./integration/... -test.v -timeout 10m
test-e2e:
go test ./e2e/... -mod=readonly -test.v -timeout 10m

View File

@ -0,0 +1,16 @@
package auction
import (
"testing"
"github.com/cosmos/cosmos-sdk/testutil/network"
"github.com/stretchr/testify/suite"
"git.vdb.to/cerc-io/laconic2d/tests/e2e"
)
func TestE2ETestSuite(t *testing.T) {
cfg := network.DefaultConfig(e2e.NewTestNetworkFixture)
cfg.NumValidators = 2
suite.Run(t, NewE2ETestSuite(cfg))
}

View File

@ -0,0 +1,76 @@
package auction
import (
"fmt"
"cosmossdk.io/math"
"github.com/stretchr/testify/suite"
"github.com/cosmos/cosmos-sdk/client/flags"
addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
"github.com/cosmos/cosmos-sdk/testutil/network"
sdk "github.com/cosmos/cosmos-sdk/types"
)
var (
ownerAccount = "owner"
bidderAccount = "bidder"
ownerAddress string
bidderAddress string
)
type E2ETestSuite struct {
suite.Suite
cfg network.Config
network *network.Network
}
func NewE2ETestSuite(cfg network.Config) *E2ETestSuite {
return &E2ETestSuite{cfg: cfg}
}
func (s *E2ETestSuite) SetupSuite() { //nolint: all
s.T().Log("setting up e2e test suite")
var err error
s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg)
s.Require().NoError(err)
_, err = s.network.WaitForHeight(1)
s.Require().NoError(err)
// setting up random owner and bidder accounts
s.createAccountWithBalance(ownerAccount, &ownerAddress)
s.createAccountWithBalance(bidderAccount, &bidderAddress)
// s.defaultAuctionID = s.createAuctionAndBid(true, false)
}
func (s *E2ETestSuite) createAccountWithBalance(accountName string, accountAddress *string) {
val := s.network.Validators[0]
sr := s.Require()
info, _, err := val.ClientCtx.Keyring.NewMnemonic(accountName, keyring.English, sdk.FullFundraiserPath, keyring.DefaultBIP39Passphrase, hd.Secp256k1)
sr.NoError(err)
newAddr, _ := info.GetAddress()
_, err = clitestutil.MsgSendExec(
val.ClientCtx,
val.Address,
newAddr,
sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, math.NewInt(200000))),
addresscodec.NewBech32Codec("laconic"),
fmt.Sprintf("--%s=%s", flags.FlagFrom, accountName),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=json", flags.FlagOutput),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10))).String()),
)
sr.NoError(err)
*accountAddress = newAddr.String()
}

63
tests/e2e/common.go Normal file
View File

@ -0,0 +1,63 @@
package e2e
import (
"fmt"
"os"
"cosmossdk.io/log"
pruningtypes "cosmossdk.io/store/pruning/types"
dbm "github.com/cosmos/cosmos-db"
bam "github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client/flags"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
"github.com/cosmos/cosmos-sdk/testutil/network"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
"github.com/cosmos/cosmos-sdk/types/module/testutil"
"github.com/cosmos/cosmos-sdk/x/auth"
laconicApp "git.vdb.to/cerc-io/laconic2d/app"
auctionmodule "git.vdb.to/cerc-io/laconic2d/x/auction/module"
bondmodule "git.vdb.to/cerc-io/laconic2d/x/bond/module"
registrymodule "git.vdb.to/cerc-io/laconic2d/x/registry/module"
)
// NewTestNetworkFixture returns a new simapp AppConstructor for network simulation tests
func NewTestNetworkFixture() network.TestFixture {
dir, err := os.MkdirTemp("", "simapp")
if err != nil {
panic(fmt.Sprintf("failed creating temporary directory: %v", err))
}
defer os.RemoveAll(dir)
app, err := laconicApp.NewLaconicApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, simtestutil.NewAppOptionsWithFlagHome(dir))
if err != nil {
panic(fmt.Sprintf("failed to create laconic app: %v", err))
}
appCtr := func(val network.ValidatorI) servertypes.Application {
app, err := laconicApp.NewLaconicApp(
val.GetCtx().Logger, dbm.NewMemDB(), nil, true,
simtestutil.NewAppOptionsWithFlagHome(val.GetCtx().Config.RootDir),
bam.SetPruning(pruningtypes.NewPruningOptionsFromString(val.GetAppConfig().Pruning)),
bam.SetMinGasPrices(val.GetAppConfig().MinGasPrices),
bam.SetChainID(val.GetCtx().Viper.GetString(flags.FlagChainID)),
)
if err != nil {
panic(fmt.Sprintf("failed creating temporary directory: %v", err))
}
return app
}
return network.TestFixture{
AppConstructor: appCtr,
GenesisState: app.DefaultGenesis(),
EncodingConfig: testutil.MakeTestEncodingConfig(
auth.AppModuleBasic{},
auctionmodule.AppModule{},
bondmodule.AppModule{},
registrymodule.AppModule{},
),
}
}