Setup keeper integration tests for registry module

This commit is contained in:
Prathamesh Musale 2024-02-28 19:27:32 +05:30
parent 6d764319ce
commit 5e47fae17e
4 changed files with 87 additions and 10 deletions

View File

@ -30,6 +30,8 @@ import (
bondkeeper "git.vdb.to/cerc-io/laconic2d/x/bond/keeper"
bondmodule "git.vdb.to/cerc-io/laconic2d/x/bond/module"
registryTypes "git.vdb.to/cerc-io/laconic2d/x/registry"
registrykeeper "git.vdb.to/cerc-io/laconic2d/x/registry/keeper"
registrymodule "git.vdb.to/cerc-io/laconic2d/x/registry/module"
)
type TestFixture struct {
@ -44,20 +46,21 @@ type TestFixture struct {
AuctionKeeper *auctionkeeper.Keeper
BondKeeper *bondkeeper.Keeper
// RegistryKeeper
RegistryKeeper registrykeeper.Keeper
}
func (tf *TestFixture) Setup() error {
keys := storetypes.NewKVStoreKeys(
authtypes.StoreKey, banktypes.StoreKey, auctionTypes.StoreKey, bondTypes.StoreKey,
authtypes.StoreKey, banktypes.StoreKey, auctionTypes.StoreKey, bondTypes.StoreKey, registryTypes.StoreKey,
)
cdc := moduletestutil.MakeTestEncodingConfig(
auth.AppModuleBasic{},
auctionmodule.AppModule{},
bondmodule.AppModule{},
registrymodule.AppModule{},
).Codec
logger := log.NewNopLogger() // Use log.NewTestLogger(tf.T()) for help with debugging
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)
@ -100,16 +103,20 @@ func (tf *TestFixture) Setup() error {
bondKeeper := bondkeeper.NewKeeper(cdc, runtime.NewKVStoreService(keys[bondTypes.StoreKey]), accountKeeper, bankKeeper)
registryKeeper := registrykeeper.NewKeeper(cdc, runtime.NewKVStoreService(keys[registryTypes.StoreKey]), accountKeeper, bankKeeper, bondKeeper, auctionKeeper)
authModule := auth.NewAppModule(cdc, accountKeeper, authsims.RandomGenesisAccounts, nil)
bankModule := bank.NewAppModule(cdc, bankKeeper, accountKeeper, nil)
auctionModule := auctionmodule.NewAppModule(cdc, auctionKeeper)
bondModule := bondmodule.NewAppModule(cdc, bondKeeper)
registryModule := registrymodule.NewAppModule(cdc, registryKeeper)
integrationApp := integration.NewIntegrationApp(newCtx, logger, keys, cdc, map[string]appmodule.AppModule{
authtypes.ModuleName: authModule,
banktypes.ModuleName: bankModule,
auctionTypes.ModuleName: auctionModule,
bondTypes.ModuleName: bondModule,
registryTypes.ModuleName: registryModule,
})
sdkCtx := sdk.UnwrapSDKContext(integrationApp.Context())
@ -121,6 +128,9 @@ func (tf *TestFixture) Setup() error {
bondTypes.RegisterMsgServer(integrationApp.MsgServiceRouter(), bondkeeper.NewMsgServerImpl(bondKeeper))
bondTypes.RegisterQueryServer(integrationApp.QueryHelper(), bondkeeper.NewQueryServerImpl(bondKeeper))
registryTypes.RegisterMsgServer(integrationApp.MsgServiceRouter(), registrykeeper.NewMsgServerImpl(registryKeeper))
registryTypes.RegisterQueryServer(integrationApp.QueryHelper(), registrykeeper.NewQueryServerImpl(registryKeeper))
// set default params
if err := auctionKeeper.Params.Set(sdkCtx, auctionTypes.DefaultParams()); err != nil {
return err
@ -128,10 +138,14 @@ func (tf *TestFixture) Setup() error {
if err := bondKeeper.Params.Set(sdkCtx, bondTypes.DefaultParams()); err != nil {
return err
}
if err := registryKeeper.Params.Set(sdkCtx, registryTypes.DefaultParams()); err != nil {
return err
}
tf.App = integrationApp
tf.SdkCtx, tf.cdc, tf.keys = sdkCtx, cdc, keys
tf.AccountKeeper, tf.BankKeeper, tf.AuctionKeeper, tf.BondKeeper = accountKeeper, bankKeeper, auctionKeeper, bondKeeper
tf.AccountKeeper, tf.BankKeeper = accountKeeper, bankKeeper
tf.AuctionKeeper, tf.BondKeeper, tf.RegistryKeeper = auctionKeeper, bondKeeper, registryKeeper
return nil
}

View File

@ -0,0 +1,33 @@
package keeper_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
integrationTest "git.vdb.to/cerc-io/laconic2d/tests/integration"
types "git.vdb.to/cerc-io/laconic2d/x/registry"
)
type KeeperTestSuite struct {
suite.Suite
integrationTest.TestFixture
queryClient types.QueryClient
}
func (kts *KeeperTestSuite) SetupTest() {
kts.TestFixture.Setup()
// set default params
err := kts.RegistryKeeper.Params.Set(kts.SdkCtx, types.DefaultParams())
assert.Nil(kts.T(), err)
qr := kts.App.QueryHelper()
kts.queryClient = types.NewQueryClient(qr)
}
func TestRegistryKeeperTestSuite(t *testing.T) {
suite.Run(t, new(KeeperTestSuite))
}

View File

@ -0,0 +1,27 @@
package keeper_test
import (
"context"
"fmt"
registrytypes "git.vdb.to/cerc-io/laconic2d/x/registry"
)
func (kts *KeeperTestSuite) TestGrpcQueryParams() {
testCases := []struct {
msg string
req *registrytypes.QueryParamsRequest
}{
{
"Get Params",
&registrytypes.QueryParamsRequest{},
},
}
for _, test := range testCases {
kts.Run(fmt.Sprintf("Case %s ", test.msg), func() {
resp, _ := kts.queryClient.Params(context.Background(), test.req)
defaultParams := registrytypes.DefaultParams()
kts.Require().Equal(defaultParams.String(), resp.GetParams().String())
})
}
}

View File

@ -6,6 +6,9 @@ const (
// ModuleName is the name of the registry module
ModuleName = "registry"
// StoreKey defines the primary module store key
StoreKey = ModuleName
// RecordRentModuleAccountName is the name of the module account that keeps track of record rents paid.
RecordRentModuleAccountName = "record_rent"