feat: replace the cosmos-db usecases in the tests with core/testing (#21525)
This commit is contained in:
+6
-5
@@ -4,10 +4,11 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
dbm "github.com/cosmos/cosmos-db"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"cosmossdk.io/core/header"
|
||||
corestore "cosmossdk.io/core/store"
|
||||
coretesting "cosmossdk.io/core/testing"
|
||||
"cosmossdk.io/log"
|
||||
"cosmossdk.io/store"
|
||||
"cosmossdk.io/store/metrics"
|
||||
@@ -18,7 +19,7 @@ import (
|
||||
|
||||
// DefaultContext creates a sdk.Context with a fresh MemDB that can be used in tests.
|
||||
func DefaultContext(key, tkey storetypes.StoreKey) sdk.Context {
|
||||
db := dbm.NewMemDB()
|
||||
db := coretesting.NewMemDB()
|
||||
cms := store.NewCommitMultiStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics())
|
||||
cms.MountStoreWithDB(key, storetypes.StoreTypeIAVL, db)
|
||||
cms.MountStoreWithDB(tkey, storetypes.StoreTypeTransient, db)
|
||||
@@ -38,7 +39,7 @@ func DefaultContextWithKeys(
|
||||
transKeys map[string]*storetypes.TransientStoreKey,
|
||||
memKeys map[string]*storetypes.MemoryStoreKey,
|
||||
) sdk.Context {
|
||||
db := dbm.NewMemDB()
|
||||
db := coretesting.NewMemDB()
|
||||
cms := store.NewCommitMultiStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics())
|
||||
|
||||
for _, key := range keys {
|
||||
@@ -63,13 +64,13 @@ func DefaultContextWithKeys(
|
||||
|
||||
type TestContext struct {
|
||||
Ctx sdk.Context
|
||||
DB *dbm.MemDB
|
||||
DB corestore.KVStoreWithBatch
|
||||
CMS store.CommitMultiStore
|
||||
}
|
||||
|
||||
func DefaultContextWithDB(tb testing.TB, key, tkey storetypes.StoreKey) TestContext {
|
||||
tb.Helper()
|
||||
db := dbm.NewMemDB()
|
||||
db := coretesting.NewMemDB()
|
||||
cms := store.NewCommitMultiStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics())
|
||||
cms.MountStoreWithDB(key, storetypes.StoreTypeIAVL, db)
|
||||
cms.MountStoreWithDB(tkey, storetypes.StoreTypeTransient, db)
|
||||
|
||||
@@ -7,12 +7,12 @@ import (
|
||||
cmtabcitypes "github.com/cometbft/cometbft/api/cometbft/abci/v1"
|
||||
cmtproto "github.com/cometbft/cometbft/api/cometbft/types/v1"
|
||||
cmttypes "github.com/cometbft/cometbft/types"
|
||||
dbm "github.com/cosmos/cosmos-db"
|
||||
|
||||
"cosmossdk.io/collections"
|
||||
"cosmossdk.io/core/address"
|
||||
"cosmossdk.io/core/appmodule"
|
||||
corestore "cosmossdk.io/core/store"
|
||||
coretesting "cosmossdk.io/core/testing"
|
||||
"cosmossdk.io/log"
|
||||
"cosmossdk.io/store"
|
||||
"cosmossdk.io/store/metrics"
|
||||
@@ -56,7 +56,7 @@ func NewIntegrationApp(
|
||||
msgRouter *baseapp.MsgServiceRouter,
|
||||
grpcRouter *baseapp.GRPCQueryRouter,
|
||||
) *App {
|
||||
db := dbm.NewMemDB()
|
||||
db := coretesting.NewMemDB()
|
||||
|
||||
interfaceRegistry := codectypes.NewInterfaceRegistry()
|
||||
moduleManager := module.NewManagerFromMap(modules)
|
||||
@@ -201,7 +201,7 @@ func (app *App) QueryHelper() *baseapp.QueryServiceTestHelper {
|
||||
|
||||
// CreateMultiStore is a helper for setting up multiple stores for provided modules.
|
||||
func CreateMultiStore(keys map[string]*storetypes.KVStoreKey, logger log.Logger) storetypes.CommitMultiStore {
|
||||
db := dbm.NewMemDB()
|
||||
db := coretesting.NewMemDB()
|
||||
cms := store.NewCommitMultiStore(db, logger, metrics.NewNoOpMetrics())
|
||||
|
||||
for key := range keys {
|
||||
|
||||
@@ -18,12 +18,12 @@ import (
|
||||
"time"
|
||||
|
||||
cmtcfg "github.com/cometbft/cometbft/config"
|
||||
dbm "github.com/cosmos/cosmos-db"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"cosmossdk.io/core/address"
|
||||
"cosmossdk.io/core/registry"
|
||||
coretesting "cosmossdk.io/core/testing"
|
||||
"cosmossdk.io/depinject"
|
||||
"cosmossdk.io/log"
|
||||
sdkmath "cosmossdk.io/math"
|
||||
@@ -220,7 +220,7 @@ func DefaultConfigWithAppConfig(appConfig depinject.Config, baseappOpts ...func(
|
||||
panic(err)
|
||||
}
|
||||
app := appBuilder.Build(
|
||||
dbm.NewMemDB(),
|
||||
coretesting.NewMemDB(),
|
||||
nil,
|
||||
append(baseappOpts,
|
||||
baseapp.SetPruning(pruningtypes.NewPruningOptionsFromString(val.GetAppConfig().Pruning)),
|
||||
|
||||
@@ -10,10 +10,10 @@ import (
|
||||
cmtproto "github.com/cometbft/cometbft/api/cometbft/types/v1"
|
||||
cmtjson "github.com/cometbft/cometbft/libs/json"
|
||||
cmttypes "github.com/cometbft/cometbft/types"
|
||||
dbm "github.com/cosmos/cosmos-db"
|
||||
|
||||
coreheader "cosmossdk.io/core/header"
|
||||
corestore "cosmossdk.io/core/store"
|
||||
coretesting "cosmossdk.io/core/testing"
|
||||
"cosmossdk.io/depinject"
|
||||
sdkmath "cosmossdk.io/math"
|
||||
banktypes "cosmossdk.io/x/bank/types"
|
||||
@@ -96,7 +96,7 @@ func DefaultStartUpConfig() StartupConfig {
|
||||
ValidatorSet: CreateRandomValidatorSet,
|
||||
AtGenesis: false,
|
||||
GenesisAccounts: []GenesisAccount{ga},
|
||||
DB: dbm.NewMemDB(),
|
||||
DB: coretesting.NewMemDB(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -109,8 +109,13 @@ func CheckExportSimulation(app runtime.AppSimI, config simtypes.Config, params s
|
||||
return nil
|
||||
}
|
||||
|
||||
// DBStatsInterface defines the interface for the app DB statistics.
|
||||
type DBStatsInterface interface {
|
||||
Stats() map[string]string
|
||||
}
|
||||
|
||||
// PrintStats prints the corresponding statistics from the app DB.
|
||||
func PrintStats(db dbm.DB) {
|
||||
func PrintStats(db DBStatsInterface) {
|
||||
fmt.Println("\nLevelDB Stats")
|
||||
fmt.Println(db.Stats()["leveldb.stats"])
|
||||
fmt.Println("LevelDB cached block size", db.Stats()["leveldb.cachedblock"])
|
||||
@@ -216,7 +221,7 @@ func getDiffFromKVPair(kvAs, kvBs []kv.Pair) (diffA, diffB []kv.Pair) {
|
||||
return diffA, diffB
|
||||
}
|
||||
|
||||
func getKVPairs(iter dbm.Iterator, prefixesToSkip [][]byte) (kvs []kv.Pair) {
|
||||
func getKVPairs(iter corestore.Iterator, prefixesToSkip [][]byte) (kvs []kv.Pair) {
|
||||
for iter.Valid() {
|
||||
key, value := iter.Key(), iter.Value()
|
||||
|
||||
|
||||
@@ -4,10 +4,10 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
dbm "github.com/cosmos/cosmos-db"
|
||||
"github.com/stretchr/testify/require"
|
||||
"gotest.tools/v3/assert"
|
||||
|
||||
coretesting "cosmossdk.io/core/testing"
|
||||
"cosmossdk.io/log"
|
||||
"cosmossdk.io/store/metrics"
|
||||
"cosmossdk.io/store/rootmulti"
|
||||
@@ -115,7 +115,7 @@ func checkDiffResults(t *testing.T, store1, store2 storetypes.KVStore, noDiff bo
|
||||
|
||||
func initTestStores(t *testing.T) (storetypes.KVStore, storetypes.KVStore) {
|
||||
t.Helper()
|
||||
db := dbm.NewMemDB()
|
||||
db := coretesting.NewMemDB()
|
||||
ms := rootmulti.NewStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics())
|
||||
|
||||
key1 := storetypes.NewKVStoreKey("store1")
|
||||
|
||||
Reference in New Issue
Block a user