Setup integration tests for auction module keeper

This commit is contained in:
Prathamesh Musale 2024-02-28 15:40:23 +05:30
parent d2505367aa
commit 3f25325e0f
7 changed files with 165 additions and 4 deletions

View File

@ -81,3 +81,10 @@ lint-fix:
@$(golangci_lint_cmd) run ./... --fix --timeout 15m
.PHONY: lint lint-fix
#################
### Tests ###
#################
test-integration:
$(MAKE) -C tests test-integration

View File

@ -79,7 +79,6 @@ type LaconicApp struct {
AuctionKeeper *auctionkeeper.Keeper // (Use * as per ProvideModule implementation)
BondKeeper *bondkeeper.Keeper
RegistryKeeper registrykeeper.Keeper
// RegistryRecordKeeper registrykeeper.RecordKeeper
// simulation manager
sm *module.SimulationManager
@ -141,7 +140,6 @@ func NewLaconicApp(
&app.ConsensusParamsKeeper,
&app.AuctionKeeper,
&app.BondKeeper,
// &app.RegistryRecordKeeper,
&app.RegistryKeeper,
); err != nil {
return nil, err

4
go.mod
View File

@ -37,11 +37,13 @@ require (
github.com/ipld/go-ipld-prime v0.21.0
github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.17.0
github.com/stretchr/testify v1.8.4
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
google.golang.org/genproto/googleapis/api v0.0.0-20231120223509-83a465c0220f
google.golang.org/grpc v1.60.1
google.golang.org/protobuf v1.32.0
gopkg.in/yaml.v3 v3.0.1
gotest.tools/v3 v3.5.1
)
require (
@ -160,7 +162,6 @@ require (
github.com/spf13/afero v1.10.0 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.8.4 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect
github.com/tendermint/go-amino v0.16.0 // indirect
@ -179,7 +180,6 @@ require (
google.golang.org/genproto/googleapis/rpc v0.0.0-20231212172506-995d672761c0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gotest.tools/v3 v3.5.1 // indirect
lukechampine.com/blake3 v1.1.6 // indirect
nhooyr.io/websocket v1.8.6 // indirect
pgregory.net/rapid v1.1.0 // indirect

2
tests/Makefile Normal file
View File

@ -0,0 +1,2 @@
test-integration:
go test -mod=readonly ./integration/... -test.v -timeout 30m

View File

@ -0,0 +1,120 @@
package keeper_test
import (
"testing"
"cosmossdk.io/core/appmodule"
"cosmossdk.io/log"
storetypes "cosmossdk.io/store/types"
cmtprototypes "github.com/cometbft/cometbft/proto/tendermint/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"github.com/cosmos/cosmos-sdk/codec"
addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
"github.com/cosmos/cosmos-sdk/runtime"
"github.com/cosmos/cosmos-sdk/testutil/integration"
sdk "github.com/cosmos/cosmos-sdk/types"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
"github.com/cosmos/cosmos-sdk/x/auth"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/bank"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
auctionTypes "git.vdb.to/cerc-io/laconic2d/x/auction"
auctionkeeper "git.vdb.to/cerc-io/laconic2d/x/auction/keeper"
auctionmodule "git.vdb.to/cerc-io/laconic2d/x/auction/module"
bondTypes "git.vdb.to/cerc-io/laconic2d/x/bond"
registryTypes "git.vdb.to/cerc-io/laconic2d/x/registry"
)
type KeeperTestSuite struct {
suite.Suite
app *integration.App
sdkCtx sdk.Context
cdc codec.Codec
keys map[string]*storetypes.KVStoreKey
accountKeeper authkeeper.AccountKeeper
bankKeeper bankkeeper.Keeper
auctionKeeper *auctionkeeper.Keeper
}
func (kts *KeeperTestSuite) SetupTest() {
keys := storetypes.NewKVStoreKeys(
authtypes.StoreKey, banktypes.StoreKey, auctionTypes.StoreKey,
)
cdc := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{}, auctionmodule.AppModule{}).Codec
logger := log.NewNopLogger() // Use log.NewTestLogger(kts.T()) for help with debugging
cms := integration.CreateMultiStore(keys, logger)
newCtx := sdk.NewContext(cms, cmtprototypes.Header{}, true, logger)
authority := authtypes.NewModuleAddress("gov")
maccPerms := map[string][]string{
auctionTypes.ModuleName: {},
auctionTypes.AuctionBurnModuleAccountName: {},
bondTypes.ModuleName: {},
registryTypes.ModuleName: {},
registryTypes.RecordRentModuleAccountName: {},
registryTypes.AuthorityRentModuleAccountName: {},
}
accountKeeper := authkeeper.NewAccountKeeper(
cdc,
runtime.NewKVStoreService(keys[authtypes.StoreKey]),
authtypes.ProtoBaseAccount,
maccPerms,
addresscodec.NewBech32Codec(sdk.Bech32MainPrefix),
sdk.Bech32MainPrefix,
authority.String(),
)
blockedAddresses := map[string]bool{
accountKeeper.GetAuthority(): false,
}
bankKeeper := bankkeeper.NewBaseKeeper(
cdc,
runtime.NewKVStoreService(keys[banktypes.StoreKey]),
accountKeeper,
blockedAddresses,
authority.String(),
log.NewNopLogger(),
)
auctionKeeper := auctionkeeper.NewKeeper(cdc, runtime.NewKVStoreService(keys[auctionTypes.StoreKey]), accountKeeper, bankKeeper)
authModule := auth.NewAppModule(cdc, accountKeeper, authsims.RandomGenesisAccounts, nil)
bankModule := bank.NewAppModule(cdc, bankKeeper, accountKeeper, nil)
auctionModule := auctionmodule.NewAppModule(cdc, auctionKeeper)
integrationApp := integration.NewIntegrationApp(newCtx, logger, keys, cdc, map[string]appmodule.AppModule{
authtypes.ModuleName: authModule,
banktypes.ModuleName: bankModule,
auctionTypes.ModuleName: auctionModule,
})
sdkCtx := sdk.UnwrapSDKContext(integrationApp.Context())
// Register MsgServer and QueryServer
auctionTypes.RegisterMsgServer(integrationApp.MsgServiceRouter(), auctionkeeper.NewMsgServerImpl(auctionKeeper))
auctionTypes.RegisterQueryServer(integrationApp.QueryHelper(), auctionkeeper.NewQueryServerImpl(auctionKeeper))
// set default staking params
assert.Nil(kts.T(), auctionKeeper.Params.Set(sdkCtx, auctionTypes.DefaultParams()))
kts.app = integrationApp
kts.sdkCtx, kts.cdc, kts.keys = sdkCtx, cdc, keys
kts.accountKeeper, kts.bankKeeper, kts.auctionKeeper = accountKeeper, bankKeeper, auctionKeeper
}
func TestKeeperTestSuite(t *testing.T) {
suite.Run(t, new(KeeperTestSuite))
}

View File

@ -0,0 +1,31 @@
package keeper_test
import (
"context"
"fmt"
types "git.vdb.to/cerc-io/laconic2d/x/auction"
)
func (kts *KeeperTestSuite) TestGrpcQueryParams() {
qr := kts.app.QueryHelper()
queryClient := types.NewQueryClient(qr)
testCases := []struct {
msg string
req *types.QueryParamsRequest
}{
{
"fetch params",
&types.QueryParamsRequest{},
},
}
for _, test := range testCases {
kts.Run(fmt.Sprintf("Case %s", test.msg), func() {
resp, err := queryClient.Params(context.Background(), test.req)
kts.Require().Nil(err)
kts.Require().Equal(*(resp.Params), types.DefaultParams())
})
}
}

View File

@ -5,6 +5,9 @@ import "cosmossdk.io/collections"
const (
ModuleName = "auction"
// StoreKey defines the primary module store key
StoreKey = ModuleName
// AuctionBurnModuleAccountName is the name of the auction burn module account.
AuctionBurnModuleAccountName = "auction_burn"
)