Skip to content

Commit

Permalink
add lending to testutil
Browse files Browse the repository at this point in the history
  • Loading branch information
keithsue committed Jan 8, 2025
1 parent 8e73032 commit d8deef7
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions testutil/keeper/lending.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package keeper

import (
"testing"

"github.com/stretchr/testify/require"

"cosmossdk.io/log"
"cosmossdk.io/store"
"cosmossdk.io/store/metrics"
storetypes "cosmossdk.io/store/types"
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
dbm "github.com/cosmos/cosmos-db"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"

"github.com/sideprotocol/side/app"
"github.com/sideprotocol/side/x/lending/keeper"
"github.com/sideprotocol/side/x/lending/types"
)

func LendingKeeper(t testing.TB) (keeper.Keeper, sdk.Context) {
db := dbm.NewMemDB()

app := app.New(log.NewNopLogger(), db, nil, true, simtestutil.EmptyAppOptions{})

storeKey := storetypes.NewKVStoreKey(types.StoreKey)
memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey)

stateStore := store.NewCommitMultiStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics())
stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db)
stateStore.MountStoreWithDB(memStoreKey, storetypes.StoreTypeMemory, nil)
require.NoError(t, stateStore.LoadLatestVersion())

registry := codectypes.NewInterfaceRegistry()
cdc := codec.NewProtoCodec(registry)

authority := authtypes.NewModuleAddress(govtypes.ModuleName).String()

k := keeper.NewKeeper(
cdc,
storeKey,
memStoreKey,
app.BankKeeper,
authority,
)

ctx := sdk.NewContext(stateStore, cmtproto.Header{}, false, log.NewNopLogger())

// Initialize params
k.SetParams(ctx, types.DefaultParams())

return k, ctx
}

0 comments on commit d8deef7

Please # to comment.