diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d201c57aa84..27a48571172e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -122,7 +122,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ * Store pacakge no longer has a dependency on baseapp. * (store) [#14438](https://github.com/cosmos/cosmos-sdk/pull/14438) Pass logger from baseapp to store. * (store) [#14439](https://github.com/cosmos/cosmos-sdk/pull/14439) Remove global metric gatherer from store. - * By default store has a no op metric gatherer, the application developer must set another metric gatherer or us the provided one in `store/metrics`. + * By default store has a no op metric gatherer, the application developer must set another metric gatherer or us the provided one in `store/metrics`. +* [#14406](https://github.com/cosmos/cosmos-sdk/issues/14406) Migrate usage of types/store.go to store/types/.. ### State Machine Breaking diff --git a/UPGRADING.md b/UPGRADING.md index a1cc19ba5234..f11c66d26cd8 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -19,6 +19,12 @@ The SDK is in the process of removing all `gogoproto` annotations. The `gogoproto.goproto_stringer = false` annotation has been removed from most proto files. This means that the `String()` method is being generated for types that previously had this annotation. The generated `String()` method uses `proto.CompactTextString` for _stringifying_ structs. [Verify](https://github.com/cosmos/cosmos-sdk/pull/13850#issuecomment-1328889651) the usage of the modified `String()` methods and double-check that they are not used in state-machine code. +### Types + +#### Store + +References to `types/store.go` which contained aliases for store types have been remapped to point to appropriate store/types, hence the `types/store.go` file is no longer needed and has been removed. + ### SimApp #### Module Assertions diff --git a/baseapp/abci.go b/baseapp/abci.go index aacfcb77ed64..71e1582ee419 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -18,6 +18,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" snapshottypes "github.com/cosmos/cosmos-sdk/store/snapshots/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -69,7 +70,7 @@ func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitC } // add block gas meter for any genesis transactions (allow infinite gas) - app.deliverState.ctx = app.deliverState.ctx.WithBlockGasMeter(sdk.NewInfiniteGasMeter()) + app.deliverState.ctx = app.deliverState.ctx.WithBlockGasMeter(storetypes.NewInfiniteGasMeter()) res = app.initChainer(app.deliverState.ctx, req) @@ -149,7 +150,7 @@ func (app *BaseApp) FilterPeerByID(info string) abci.ResponseQuery { // BeginBlock implements the ABCI application interface. func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeginBlock) { if app.cms.TracingEnabled() { - app.cms.SetTracingContext(sdk.TraceContext( + app.cms.SetTracingContext(storetypes.TraceContext( map[string]interface{}{"blockHeight": req.Header.Height}, )) } @@ -172,11 +173,11 @@ func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeg } // add block gas meter - var gasMeter sdk.GasMeter + var gasMeter storetypes.GasMeter if maxGas := app.GetMaximumBlockGas(app.deliverState.ctx); maxGas > 0 { - gasMeter = sdk.NewGasMeter(maxGas) + gasMeter = storetypes.NewGasMeter(maxGas) } else { - gasMeter = sdk.NewInfiniteGasMeter() + gasMeter = storetypes.NewInfiniteGasMeter() } // NOTE: header hash is not set in NewContext, so we manually set it here @@ -212,7 +213,7 @@ func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeg // EndBlock implements the ABCI interface. func (app *BaseApp) EndBlock(req abci.RequestEndBlock) (res abci.ResponseEndBlock) { if app.deliverState.ms.TracingEnabled() { - app.deliverState.ms = app.deliverState.ms.SetTracingContext(nil).(sdk.CacheMultiStore) + app.deliverState.ms = app.deliverState.ms.SetTracingContext(nil).(storetypes.CacheMultiStore) } if app.endBlocker != nil { @@ -717,7 +718,7 @@ func (app *BaseApp) CreateQueryContext(height int64, prove bool) (sdk.Context, e // use custom query multistore if provided qms := app.qms if qms == nil { - qms = app.cms.(sdk.MultiStore) + qms = app.cms.(storetypes.MultiStore) } lastBlockHeight := qms.LatestVersion() @@ -880,7 +881,7 @@ func handleQueryApp(app *BaseApp, path []string, req abci.RequestQuery) abci.Res func handleQueryStore(app *BaseApp, path []string, req abci.RequestQuery) abci.ResponseQuery { // "/store" prefix for store queries - queryable, ok := app.cms.(sdk.Queryable) + queryable, ok := app.cms.(storetypes.Queryable) if !ok { return sdkerrors.QueryResult(sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "multistore doesn't support queries"), app.trace) } diff --git a/baseapp/abci_test.go b/baseapp/abci_test.go index 3675c3ea2046..bd81ea41e1af 100644 --- a/baseapp/abci_test.go +++ b/baseapp/abci_test.go @@ -8,6 +8,7 @@ import ( "testing" dbm "github.com/cosmos/cosmos-db" + "github.com/cosmos/gogoproto/jsonpb" "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" @@ -18,6 +19,7 @@ import ( pruningtypes "github.com/cosmos/cosmos-sdk/store/pruning/types" "github.com/cosmos/cosmos-sdk/store/snapshots" snapshottypes "github.com/cosmos/cosmos-sdk/store/snapshots/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" @@ -45,8 +47,8 @@ func TestABCI_InitChain(t *testing.T) { logger := defaultLogger() app := baseapp.NewBaseApp(name, logger, db, nil) - capKey := sdk.NewKVStoreKey("main") - capKey2 := sdk.NewKVStoreKey("key2") + capKey := storetypes.NewKVStoreKey("main") + capKey2 := storetypes.NewKVStoreKey("key2") app.MountStores(capKey, capKey2) // set a value in the store on init chain @@ -745,7 +747,7 @@ func TestABCI_Query_SimulateTx(t *testing.T) { gasConsumed := uint64(5) anteOpt := func(bapp *baseapp.BaseApp) { bapp.SetAnteHandler(func(ctx sdk.Context, tx sdk.Tx, simulate bool) (newCtx sdk.Context, err error) { - newCtx = ctx.WithGasMeter(sdk.NewGasMeter(gasConsumed)) + newCtx = ctx.WithGasMeter(storetypes.NewGasMeter(gasConsumed)) return }) } @@ -910,7 +912,7 @@ func TestABCI_TxGasLimits(t *testing.T) { gasGranted := uint64(10) anteOpt := func(bapp *baseapp.BaseApp) { bapp.SetAnteHandler(func(ctx sdk.Context, tx sdk.Tx, simulate bool) (newCtx sdk.Context, err error) { - newCtx = ctx.WithGasMeter(sdk.NewGasMeter(gasGranted)) + newCtx = ctx.WithGasMeter(storetypes.NewGasMeter(gasGranted)) // AnteHandlers must have their own defer/recover in order for the BaseApp // to know how much gas was used! This is because the GasMeter is created in @@ -919,7 +921,7 @@ func TestABCI_TxGasLimits(t *testing.T) { defer func() { if r := recover(); r != nil { switch rType := r.(type) { - case sdk.ErrorOutOfGas: + case storetypes.ErrorOutOfGas: err = sdkerrors.Wrapf(sdkerrors.ErrOutOfGas, "out of gas in location: %v", rType.Descriptor) default: panic(r) @@ -993,12 +995,12 @@ func TestABCI_MaxBlockGasLimits(t *testing.T) { gasGranted := uint64(10) anteOpt := func(bapp *baseapp.BaseApp) { bapp.SetAnteHandler(func(ctx sdk.Context, tx sdk.Tx, simulate bool) (newCtx sdk.Context, err error) { - newCtx = ctx.WithGasMeter(sdk.NewGasMeter(gasGranted)) + newCtx = ctx.WithGasMeter(storetypes.NewGasMeter(gasGranted)) defer func() { if r := recover(); r != nil { switch rType := r.(type) { - case sdk.ErrorOutOfGas: + case storetypes.ErrorOutOfGas: err = sdkerrors.Wrapf(sdkerrors.ErrOutOfGas, "out of gas in location: %v", rType.Descriptor) default: panic(r) @@ -1088,12 +1090,12 @@ func TestABCI_GasConsumptionBadTx(t *testing.T) { gasWanted := uint64(5) anteOpt := func(bapp *baseapp.BaseApp) { bapp.SetAnteHandler(func(ctx sdk.Context, tx sdk.Tx, simulate bool) (newCtx sdk.Context, err error) { - newCtx = ctx.WithGasMeter(sdk.NewGasMeter(gasWanted)) + newCtx = ctx.WithGasMeter(storetypes.NewGasMeter(gasWanted)) defer func() { if r := recover(); r != nil { switch rType := r.(type) { - case sdk.ErrorOutOfGas: + case storetypes.ErrorOutOfGas: log := fmt.Sprintf("out of gas in location: %v", rType.Descriptor) err = sdkerrors.Wrap(sdkerrors.ErrOutOfGas, log) default: diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 1f1181bcd2d3..d8a6feef91e3 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -43,20 +43,20 @@ type ( // from disk. This is useful for state migration, when loading a datastore written with // an older version of the software. In particular, if a module changed the substore key name // (or removed a substore) between two versions of the software. - StoreLoader func(ms sdk.CommitMultiStore) error + StoreLoader func(ms storetypes.CommitMultiStore) error ) // BaseApp reflects the ABCI application implementation. type BaseApp struct { //nolint: maligned // initialized on creation logger log.Logger - name string // application name from abci.Info - db dbm.DB // common DB backend - cms sdk.CommitMultiStore // Main (uncached) state - qms sdk.MultiStore // Optional alternative multistore for querying only. - storeLoader StoreLoader // function to handle store loading, may be overridden with SetStoreLoader() - grpcQueryRouter *GRPCQueryRouter // router for redirecting gRPC query calls - msgServiceRouter *MsgServiceRouter // router for redirecting Msg service messages + name string // application name from abci.Info + db dbm.DB // common DB backend + cms storetypes.CommitMultiStore // Main (uncached) state + qms storetypes.MultiStore // Optional alternative multistore for querying only. + storeLoader StoreLoader // function to handle store loading, may be overridden with SetStoreLoader() + grpcQueryRouter *GRPCQueryRouter // router for redirecting gRPC query calls + msgServiceRouter *MsgServiceRouter // router for redirecting Msg service messages interfaceRegistry codectypes.InterfaceRegistry txDecoder sdk.TxDecoder // unmarshal []byte into sdk.Tx txEncoder sdk.TxEncoder // marshal sdk.Tx into []byte @@ -86,7 +86,7 @@ type BaseApp struct { //nolint: maligned prepareProposalState *state // for PrepareProposal // an inter-block write-through cache provided to the context during deliverState - interBlockCache sdk.MultiStorePersistentCache + interBlockCache storetypes.MultiStorePersistentCache // absent validators from begin block voteInfos []abci.VoteInfo @@ -300,14 +300,14 @@ func (app *BaseApp) LoadLatestVersion() error { } // DefaultStoreLoader will be used by default and loads the latest version -func DefaultStoreLoader(ms sdk.CommitMultiStore) error { +func DefaultStoreLoader(ms storetypes.CommitMultiStore) error { return ms.LoadLatestVersion() } // CommitMultiStore returns the root multi-store. // App constructor can use this to access the `cms`. // UNSAFE: must not be used during the abci life cycle. -func (app *BaseApp) CommitMultiStore() sdk.CommitMultiStore { +func (app *BaseApp) CommitMultiStore() storetypes.CommitMultiStore { return app.cms } @@ -381,7 +381,7 @@ func (app *BaseApp) setMinRetainBlocks(minRetainBlocks uint64) { app.minRetainBlocks = minRetainBlocks } -func (app *BaseApp) setInterBlockCache(cache sdk.MultiStorePersistentCache) { +func (app *BaseApp) setInterBlockCache(cache storetypes.MultiStorePersistentCache) { app.interBlockCache = cache } @@ -576,18 +576,18 @@ func (app *BaseApp) getContextForTx(mode runTxMode, txBytes []byte) sdk.Context // cacheTxContext returns a new context based off of the provided context with // a branched multi-store. -func (app *BaseApp) cacheTxContext(ctx sdk.Context, txBytes []byte) (sdk.Context, sdk.CacheMultiStore) { +func (app *BaseApp) cacheTxContext(ctx sdk.Context, txBytes []byte) (sdk.Context, storetypes.CacheMultiStore) { ms := ctx.MultiStore() // TODO: https://github.com/cosmos/cosmos-sdk/issues/2824 msCache := ms.CacheMultiStore() if msCache.TracingEnabled() { msCache = msCache.SetTracingContext( - sdk.TraceContext( + storetypes.TraceContext( map[string]interface{}{ "txHash": fmt.Sprintf("%X", tmhash.Sum(txBytes)), }, ), - ).(sdk.CacheMultiStore) + ).(storetypes.CacheMultiStore) } return ctx.WithMultiStore(msCache), msCache @@ -657,7 +657,7 @@ func (app *BaseApp) runTx(mode runTxMode, txBytes []byte) (gInfo sdk.GasInfo, re if app.anteHandler != nil { var ( anteCtx sdk.Context - msCache sdk.CacheMultiStore + msCache storetypes.CacheMultiStore ) // Branch context before AnteHandler call in case it aborts. diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index e757dd224885..9e93a81422ef 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -30,8 +30,8 @@ import ( ) var ( - capKey1 = sdk.NewKVStoreKey("key1") - capKey2 = sdk.NewKVStoreKey("key2") + capKey1 = storetypes.NewKVStoreKey("key1") + capKey2 = storetypes.NewKVStoreKey("key2") // testTxPriority is the CheckTx priority that we set in the test // AnteHandler. @@ -221,7 +221,7 @@ func TestSetLoader(t *testing.T) { rs := rootmulti.NewStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics()) rs.SetPruning(pruningtypes.NewPruningOptions(pruningtypes.PruningNothing)) - key := sdk.NewKVStoreKey(storeKey) + key := storetypes.NewKVStoreKey(storeKey) rs.MountStoreWithDB(key, storetypes.StoreTypeIAVL, nil) err := rs.LoadLatestVersion() @@ -241,7 +241,7 @@ func TestSetLoader(t *testing.T) { rs := rootmulti.NewStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics()) rs.SetPruning(pruningtypes.NewPruningOptions(pruningtypes.PruningDefault)) - key := sdk.NewKVStoreKey(storeKey) + key := storetypes.NewKVStoreKey(storeKey) rs.MountStoreWithDB(key, storetypes.StoreTypeIAVL, nil) err := rs.LoadLatestVersion() @@ -285,7 +285,7 @@ func TestSetLoader(t *testing.T) { opts = append(opts, tc.setLoader) } app := baseapp.NewBaseApp(t.Name(), defaultLogger(), db, nil, opts...) - app.MountStores(sdk.NewKVStoreKey(tc.loadStoreKey)) + app.MountStores(storetypes.NewKVStoreKey(tc.loadStoreKey)) err := app.LoadLatestVersion() require.Nil(t, err) @@ -613,7 +613,7 @@ func TestLoadVersionPruning(t *testing.T) { app := baseapp.NewBaseApp(name, logger, db, nil, pruningOpt) // make a cap key and mount the store - capKey := sdk.NewKVStoreKey("key1") + capKey := storetypes.NewKVStoreKey("key1") app.MountStores(capKey) err := app.LoadLatestVersion() // needed to make stores non-nil diff --git a/baseapp/options.go b/baseapp/options.go index e78295917c38..22d3aab19485 100644 --- a/baseapp/options.go +++ b/baseapp/options.go @@ -5,10 +5,8 @@ import ( "io" dbm "github.com/cosmos/cosmos-db" - "github.com/cosmos/cosmos-sdk/codec/types" servertypes "github.com/cosmos/cosmos-sdk/server/types" - "github.com/cosmos/cosmos-sdk/store" "github.com/cosmos/cosmos-sdk/store/metrics" pruningtypes "github.com/cosmos/cosmos-sdk/store/pruning/types" "github.com/cosmos/cosmos-sdk/store/snapshots" @@ -76,7 +74,7 @@ func SetIAVLDisableFastNode(disable bool) func(*BaseApp) { // SetInterBlockCache provides a BaseApp option function that sets the // inter-block cache. -func SetInterBlockCache(cache sdk.MultiStorePersistentCache) func(*BaseApp) { +func SetInterBlockCache(cache storetypes.MultiStorePersistentCache) func(*BaseApp) { return func(app *BaseApp) { app.setInterBlockCache(cache) } } @@ -128,7 +126,7 @@ func (app *BaseApp) SetDB(db dbm.DB) { app.db = db } -func (app *BaseApp) SetCMS(cms store.CommitMultiStore) { +func (app *BaseApp) SetCMS(cms storetypes.CommitMultiStore) { if app.sealed { panic("SetEndBlocker() on sealed BaseApp") } @@ -270,7 +268,7 @@ func (app *BaseApp) SetTxEncoder(txEncoder sdk.TxEncoder) { // SetQueryMultiStore set a alternative MultiStore implementation to support grpc query service. // // Ref: https://github.com/cosmos/cosmos-sdk/issues/13317 -func (app *BaseApp) SetQueryMultiStore(ms sdk.MultiStore) { +func (app *BaseApp) SetQueryMultiStore(ms storetypes.MultiStore) { app.qms = ms } diff --git a/baseapp/recovery.go b/baseapp/recovery.go index 7f0687800c65..00b4d25c9ba8 100644 --- a/baseapp/recovery.go +++ b/baseapp/recovery.go @@ -4,6 +4,7 @@ import ( "fmt" "runtime/debug" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) @@ -47,7 +48,7 @@ func newRecoveryMiddleware(handler RecoveryHandler, next recoveryMiddleware) rec // newOutOfGasRecoveryMiddleware creates a standard OutOfGas recovery middleware for app.runTx method. func newOutOfGasRecoveryMiddleware(gasWanted uint64, ctx sdk.Context, next recoveryMiddleware) recoveryMiddleware { handler := func(recoveryObj interface{}) error { - err, ok := recoveryObj.(sdk.ErrorOutOfGas) + err, ok := recoveryObj.(storetypes.ErrorOutOfGas) if !ok { return nil } diff --git a/baseapp/state.go b/baseapp/state.go index addc89cb342c..da9c588e40e4 100644 --- a/baseapp/state.go +++ b/baseapp/state.go @@ -1,17 +1,18 @@ package baseapp import ( + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" ) type state struct { - ms sdk.CacheMultiStore + ms storetypes.CacheMultiStore ctx sdk.Context } // CacheMultiStore calls and returns a CacheMultiStore on the state's underling // CacheMultiStore. -func (st *state) CacheMultiStore() sdk.CacheMultiStore { +func (st *state) CacheMultiStore() storetypes.CacheMultiStore { return st.ms.CacheMultiStore() } diff --git a/baseapp/utils_test.go b/baseapp/utils_test.go index 4ce4feb0fad9..bdd45d35894a 100644 --- a/baseapp/utils_test.go +++ b/baseapp/utils_test.go @@ -230,14 +230,14 @@ func anteHandlerTxTest(t *testing.T, capKey storetypes.StoreKey, storeKey []byte } } -func incrementingCounter(t *testing.T, store sdk.KVStore, counterKey []byte, counter int64) (*sdk.Result, error) { +func incrementingCounter(t *testing.T, store storetypes.KVStore, counterKey []byte, counter int64) (*sdk.Result, error) { storedCounter := getIntFromStore(t, store, counterKey) require.Equal(t, storedCounter, counter) setIntOnStore(store, counterKey, counter+1) return &sdk.Result{}, nil } -func setIntOnStore(store sdk.KVStore, key []byte, i int64) { +func setIntOnStore(store storetypes.KVStore, key []byte, i int64) { bz := make([]byte, 8) n := binary.PutVarint(bz, i) store.Set(key, bz[:n]) @@ -347,7 +347,7 @@ func newTxCounter(t *testing.T, cfg client.TxConfig, counter int64, msgCounters return builder.GetTx() } -func getIntFromStore(t *testing.T, store sdk.KVStore, key []byte) int64 { +func getIntFromStore(t *testing.T, store storetypes.KVStore, key []byte) int64 { bz := store.Get(key) if len(bz) == 0 { return 0 diff --git a/collections/iter.go b/collections/iter.go index d16bfbd877d5..e45e21cd29f5 100644 --- a/collections/iter.go +++ b/collections/iter.go @@ -222,9 +222,9 @@ func prefixStartEndBytes[K, V any](m Map[K, V], prefix K) (startBytes, endBytes return startBytes, prefixEndBytes(startBytes), nil } -// Iterator defines a generic wrapper around an sdk.Iterator. +// Iterator defines a generic wrapper around an storetypes.Iterator. // This iterator provides automatic key and value encoding, -// it assumes all the keys and values contained within the sdk.Iterator +// it assumes all the keys and values contained within the storetypes.Iterator // range are the same. type Iterator[K, V any] struct { kc KeyCodec[K] @@ -240,7 +240,7 @@ func (i Iterator[K, V]) Value() (V, error) { return i.vc.Decode(i.iter.Value()) } -// Key returns the current sdk.Iterator decoded key. +// Key returns the current storetypes.Iterator decoded key. func (i Iterator[K, V]) Key() (K, error) { bytesKey := i.iter.Key()[i.prefixLength:] // strip prefix namespace diff --git a/go.mod b/go.mod index 722fafd2a259..98c4ccf01b10 100644 --- a/go.mod +++ b/go.mod @@ -60,6 +60,7 @@ require ( google.golang.org/genproto v0.0.0-20221227171554-f9683d7f8bef google.golang.org/grpc v1.51.0 google.golang.org/protobuf v1.28.1 + gotest.tools/v3 v3.4.0 pgregory.net/rapid v0.5.5 sigs.k8s.io/yaml v1.3.0 ) diff --git a/go.sum b/go.sum index 89b07e27b6c1..98223fa343c1 100644 --- a/go.sum +++ b/go.sum @@ -1358,6 +1358,7 @@ gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gotest.tools/v3 v3.4.0 h1:ZazjZUfuVeZGLAmlKKuyv3IKP5orXcwtOwDQH6YVr6o= +gotest.tools/v3 v3.4.0/go.mod h1:CtbdzLSsqVhDgMtKsx03ird5YTGB3ar27v0u/yKBW5g= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/server/mock/app.go b/server/mock/app.go index e6c8aa9680f5..418c1748a58c 100644 --- a/server/mock/app.go +++ b/server/mock/app.go @@ -29,7 +29,7 @@ func NewApp(rootDir string, logger log.Logger) (abci.Application, error) { return nil, err } - capKeyMainStore := sdk.NewKVStoreKey("main") + capKeyMainStore := storetypes.NewKVStoreKey("main") baseApp := bam.NewBaseApp("kvstore", logger, db, decodeTx) baseApp.MountStores(capKeyMainStore) diff --git a/server/mock/store.go b/server/mock/store.go index 6233463973da..7b3eaa417cff 100644 --- a/server/mock/store.go +++ b/server/mock/store.go @@ -10,20 +10,19 @@ import ( pruningtypes "github.com/cosmos/cosmos-sdk/store/pruning/types" snapshottypes "github.com/cosmos/cosmos-sdk/store/snapshots/types" storetypes "github.com/cosmos/cosmos-sdk/store/types" - sdk "github.com/cosmos/cosmos-sdk/types" ) -var _ sdk.MultiStore = multiStore{} +var _ storetypes.MultiStore = multiStore{} type multiStore struct { kv map[storetypes.StoreKey]kvStore } -func (ms multiStore) CacheMultiStore() sdk.CacheMultiStore { +func (ms multiStore) CacheMultiStore() storetypes.CacheMultiStore { panic("not implemented") } -func (ms multiStore) CacheMultiStoreWithVersion(_ int64) (sdk.CacheMultiStore, error) { +func (ms multiStore) CacheMultiStoreWithVersion(_ int64) (storetypes.CacheMultiStore, error) { panic("not implemented") } @@ -31,7 +30,7 @@ func (ms multiStore) CacheWrap() storetypes.CacheWrap { panic("not implemented") } -func (ms multiStore) CacheWrapWithTrace(_ io.Writer, _ sdk.TraceContext) storetypes.CacheWrap { +func (ms multiStore) CacheWrapWithTrace(_ io.Writer, _ storetypes.TraceContext) storetypes.CacheWrap { panic("not implemented") } @@ -43,11 +42,11 @@ func (ms multiStore) TracingEnabled() bool { panic("not implemented") } -func (ms multiStore) SetTracingContext(tc sdk.TraceContext) sdk.MultiStore { +func (ms multiStore) SetTracingContext(tc storetypes.TraceContext) storetypes.MultiStore { panic("not implemented") } -func (ms multiStore) SetTracer(w io.Writer) sdk.MultiStore { +func (ms multiStore) SetTracer(w io.Writer) storetypes.MultiStore { panic("not implemented") } @@ -107,11 +106,11 @@ func (ms multiStore) LoadVersion(ver int64) error { panic("not implemented") } -func (ms multiStore) GetKVStore(key storetypes.StoreKey) sdk.KVStore { +func (ms multiStore) GetKVStore(key storetypes.StoreKey) storetypes.KVStore { return ms.kv[key] } -func (ms multiStore) GetStore(key storetypes.StoreKey) sdk.Store { +func (ms multiStore) GetStore(key storetypes.StoreKey) storetypes.Store { panic("not implemented") } @@ -127,7 +126,7 @@ func (ms multiStore) SetSnapshotInterval(snapshotInterval uint64) { panic("not implemented") } -func (ms multiStore) SetInterBlockCache(_ sdk.MultiStorePersistentCache) { +func (ms multiStore) SetInterBlockCache(_ storetypes.MultiStorePersistentCache) { panic("not implemented") } @@ -161,7 +160,7 @@ func (ms multiStore) LatestVersion() int64 { panic("not implemented") } -var _ sdk.KVStore = kvStore{} +var _ storetypes.KVStore = kvStore{} type kvStore struct { store map[string][]byte @@ -171,7 +170,7 @@ func (kv kvStore) CacheWrap() storetypes.CacheWrap { panic("not implemented") } -func (kv kvStore) CacheWrapWithTrace(w io.Writer, tc sdk.TraceContext) storetypes.CacheWrap { +func (kv kvStore) CacheWrapWithTrace(w io.Writer, tc storetypes.TraceContext) storetypes.CacheWrap { panic("not implemented") } @@ -205,30 +204,30 @@ func (kv kvStore) Delete(key []byte) { delete(kv.store, string(key)) } -func (kv kvStore) Prefix(prefix []byte) sdk.KVStore { +func (kv kvStore) Prefix(prefix []byte) storetypes.KVStore { panic("not implemented") } -func (kv kvStore) Gas(meter sdk.GasMeter, config sdk.GasConfig) sdk.KVStore { +func (kv kvStore) Gas(meter storetypes.GasMeter, config storetypes.GasConfig) storetypes.KVStore { panic("not implmeneted") } -func (kv kvStore) Iterator(start, end []byte) sdk.Iterator { +func (kv kvStore) Iterator(start, end []byte) storetypes.Iterator { panic("not implemented") } -func (kv kvStore) ReverseIterator(start, end []byte) sdk.Iterator { +func (kv kvStore) ReverseIterator(start, end []byte) storetypes.Iterator { panic("not implemented") } -func (kv kvStore) SubspaceIterator(prefix []byte) sdk.Iterator { +func (kv kvStore) SubspaceIterator(prefix []byte) storetypes.Iterator { panic("not implemented") } -func (kv kvStore) ReverseSubspaceIterator(prefix []byte) sdk.Iterator { +func (kv kvStore) ReverseSubspaceIterator(prefix []byte) storetypes.Iterator { panic("not implemented") } -func NewCommitMultiStore() sdk.CommitMultiStore { +func NewCommitMultiStore() storetypes.CommitMultiStore { return multiStore{kv: make(map[storetypes.StoreKey]kvStore)} } diff --git a/server/mock/store_test.go b/server/mock/store_test.go index 33544f8019f5..718bb07139e5 100644 --- a/server/mock/store_test.go +++ b/server/mock/store_test.go @@ -7,7 +7,6 @@ import ( "github.com/stretchr/testify/require" storetypes "github.com/cosmos/cosmos-sdk/store/types" - sdk "github.com/cosmos/cosmos-sdk/types" ) func TestStore(t *testing.T) { @@ -15,7 +14,7 @@ func TestStore(t *testing.T) { cms := NewCommitMultiStore() - key := sdk.NewKVStoreKey("test") + key := storetypes.NewKVStoreKey("test") cms.MountStoreWithDB(key, storetypes.StoreTypeIAVL, db) err := cms.LoadLatestVersion() require.Nil(t, err) diff --git a/server/types/app.go b/server/types/app.go index a022ddf222ee..9e71cfc57df2 100644 --- a/server/types/app.go +++ b/server/types/app.go @@ -6,6 +6,7 @@ import ( "time" dbm "github.com/cosmos/cosmos-db" + "github.com/cosmos/gogoproto/grpc" "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" @@ -16,7 +17,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/server/api" "github.com/cosmos/cosmos-sdk/server/config" - sdk "github.com/cosmos/cosmos-sdk/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" ) // ServerStartTime defines the time duration that the server need to stay running after startup @@ -58,7 +59,7 @@ type ( RegisterNodeService(client.Context) // CommitMultiStore return the multistore instance - CommitMultiStore() sdk.CommitMultiStore + CommitMultiStore() storetypes.CommitMultiStore } // AppCreator is a function that allows us to lazily initialize an diff --git a/server/util.go b/server/util.go index fdbfcc19d960..a455cd9a0d26 100644 --- a/server/util.go +++ b/server/util.go @@ -15,6 +15,7 @@ import ( "time" dbm "github.com/cosmos/cosmos-db" + "github.com/spf13/cast" "github.com/spf13/cobra" "github.com/spf13/pflag" @@ -32,6 +33,7 @@ import ( "github.com/cosmos/cosmos-sdk/store" "github.com/cosmos/cosmos-sdk/store/snapshots" snapshottypes "github.com/cosmos/cosmos-sdk/store/snapshots/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/mempool" "github.com/cosmos/cosmos-sdk/version" @@ -428,7 +430,7 @@ func openTraceWriter(traceWriterFile string) (w io.WriteCloser, err error) { // DefaultBaseappOptions returns the default baseapp options provided by the Cosmos SDK func DefaultBaseappOptions(appOpts types.AppOptions) []func(*baseapp.BaseApp) { - var cache sdk.MultiStorePersistentCache + var cache storetypes.MultiStorePersistentCache if cast.ToBool(appOpts.Get(FlagInterBlockCache)) { cache = store.NewCommitKVStoreCacheManager() diff --git a/simapp/app.go b/simapp/app.go index 1ea3abfb52cb..5bf708ec10db 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -250,7 +250,7 @@ func NewSimApp( bApp.SetInterfaceRegistry(interfaceRegistry) bApp.SetTxEncoder(txConfig.TxEncoder()) - keys := sdk.NewKVStoreKeys( + keys := storetypes.NewKVStoreKeys( authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, crisistypes.StoreKey, minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey, govtypes.StoreKey, paramstypes.StoreKey, consensusparamtypes.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey, @@ -258,10 +258,10 @@ func NewSimApp( authzkeeper.StoreKey, nftkeeper.StoreKey, group.StoreKey, ) - tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey) + tkeys := storetypes.NewTransientStoreKeys(paramstypes.TStoreKey) // NOTE: The testingkey is just mounted for testing purposes. Actual applications should // not include this key. - memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey, "testingkey") + memKeys := storetypes.NewMemoryStoreKeys(capabilitytypes.MemStoreKey, "testingkey") // register the streaming service with the BaseApp if err := bApp.SetStreamingService(appOpts, appCodec, keys); err != nil { diff --git a/simapp/export.go b/simapp/export.go index 96e841064a5a..e63ab63372f9 100644 --- a/simapp/export.go +++ b/simapp/export.go @@ -8,6 +8,7 @@ import ( tmproto "github.com/tendermint/tendermint/proto/tendermint/types" servertypes "github.com/cosmos/cosmos-sdk/server/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/cosmos/cosmos-sdk/x/staking" @@ -158,7 +159,7 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [] // Iterate through validators by power descending, reset bond heights, and // update bond intra-tx counters. store := ctx.KVStore(app.GetKey(stakingtypes.StoreKey)) - iter := sdk.KVStoreReversePrefixIterator(store, stakingtypes.ValidatorsKey) + iter := storetypes.KVStoreReversePrefixIterator(store, stakingtypes.ValidatorsKey) counter := int16(0) for ; iter.Valid(); iter.Next() { diff --git a/simapp/go.mod b/simapp/go.mod index 560cbecf8a25..55b6805befe4 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -189,6 +189,7 @@ replace ( github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0 // Simapp always use the latest version of the cosmos-sdk github.com/cosmos/cosmos-sdk => ../. + github.com/cosmos/cosmos-sdk/x/nft => .././x/nft // Fix upstream GHSA-h395-qcrw-5vmq vulnerability. // TODO Remove it: https://github.com/cosmos/cosmos-sdk/issues/10409 github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.8.1 diff --git a/simapp/sim_test.go b/simapp/sim_test.go index 214adcbbcfe8..a0519f1d3e55 100644 --- a/simapp/sim_test.go +++ b/simapp/sim_test.go @@ -22,7 +22,6 @@ import ( "github.com/cosmos/cosmos-sdk/store" storetypes "github.com/cosmos/cosmos-sdk/store/types" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" - sdk "github.com/cosmos/cosmos-sdk/types" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper" @@ -218,7 +217,7 @@ func TestAppImportExport(t *testing.T) { storeA := ctxA.KVStore(skp.A) storeB := ctxB.KVStore(skp.B) - failedKVAs, failedKVBs := sdk.DiffKVStores(storeA, storeB, skp.Prefixes) + failedKVAs, failedKVBs := simtestutil.DiffKVStores(storeA, storeB, skp.Prefixes) require.Equal(t, len(failedKVAs), len(failedKVBs), "unequal sets of key-values to compare") fmt.Printf("compared %d different key/value pairs between %s and %s\n", len(failedKVAs), skp.A, skp.B) diff --git a/store/types/store.go b/store/types/store.go index f461a8f2c985..3bd6563ea0a3 100644 --- a/store/types/store.go +++ b/store/types/store.go @@ -7,10 +7,10 @@ import ( dbm "github.com/cosmos/cosmos-db" abci "github.com/tendermint/tendermint/abci/types" - "github.com/cosmos/cosmos-sdk/store/internal/kv" "github.com/cosmos/cosmos-sdk/store/metrics" pruningtypes "github.com/cosmos/cosmos-sdk/store/pruning/types" snapshottypes "github.com/cosmos/cosmos-sdk/store/snapshots/types" + "github.com/cosmos/cosmos-sdk/types/kv" ) type Store interface { @@ -486,3 +486,35 @@ type StoreWithInitialVersion interface { // starting a new chain at an arbitrary height. SetInitialVersion(version int64) } + +// NewTransientStoreKeys constructs a new map of TransientStoreKey's +// Must return pointers according to the ocap principle +// The function will panic if there is a potential conflict in names +// see `assertNoCommonPrefix` function for more details. +func NewTransientStoreKeys(names ...string) map[string]*TransientStoreKey { + assertNoCommonPrefix(names) + keys := make(map[string]*TransientStoreKey) + for _, n := range names { + keys[n] = NewTransientStoreKey(n) + } + + return keys +} + +// NewMemoryStoreKeys constructs a new map matching store key names to their +// respective MemoryStoreKey references. +// The function will panic if there is a potential conflict in names (see `assertNoPrefix` +// function for more details). +func NewMemoryStoreKeys(names ...string) map[string]*MemoryStoreKey { + assertNoCommonPrefix(names) + keys := make(map[string]*MemoryStoreKey) + for _, n := range names { + keys[n] = NewMemoryStoreKey(n) + } + + return keys +} + +// StoreDecoderRegistry defines each of the modules store decoders. Used for ImportExport +// simulation. +type StoreDecoderRegistry map[string]func(kvA, kvB kv.Pair) string diff --git a/store/types/store_test.go b/store/types/store_test.go index d5d47de2c9e1..0a46f84fc9bd 100644 --- a/store/types/store_test.go +++ b/store/types/store_test.go @@ -4,8 +4,8 @@ import ( "fmt" "testing" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "gotest.tools/v3/assert" ) func TestStoreUpgrades(t *testing.T) { @@ -224,3 +224,19 @@ func TestTraceContext_Merge(t *testing.T) { }) } } + +func TestNewTransientStoreKeys(t *testing.T) { + assert.DeepEqual(t, map[string]*TransientStoreKey{}, NewTransientStoreKeys()) + assert.DeepEqual(t, 1, len(NewTransientStoreKeys("one"))) +} + +func TestNewInfiniteGasMeter(t *testing.T) { + gm := NewInfiniteGasMeter() + require.NotNil(t, gm) + _, ok := gm.(GasMeter) //nolint:gosimple + require.True(t, ok) +} + +func TestStoreTypes(t *testing.T) { + assert.DeepEqual(t, InclusiveEndBytes([]byte("endbytes")), InclusiveEndBytes([]byte("endbytes"))) +} diff --git a/store/types/utils_test.go b/store/types/utils_test.go index ef73f2f19b23..5f6dcbca6208 100644 --- a/store/types/utils_test.go +++ b/store/types/utils_test.go @@ -1,27 +1,37 @@ package types_test import ( - "bytes" "testing" - "github.com/stretchr/testify/require" + "gotest.tools/v3/assert" "github.com/cosmos/cosmos-sdk/store/types" ) func TestPrefixEndBytes(t *testing.T) { t.Parallel() - bs1 := []byte{0x23, 0xA5, 0x06} - require.True(t, bytes.Equal([]byte{0x23, 0xA5, 0x07}, types.PrefixEndBytes(bs1))) - bs2 := []byte{0x23, 0xA5, 0xFF} - require.True(t, bytes.Equal([]byte{0x23, 0xA6}, types.PrefixEndBytes(bs2))) - require.Nil(t, types.PrefixEndBytes([]byte{0xFF})) - require.Nil(t, types.PrefixEndBytes(nil)) + testCases := []struct { + prefix []byte + expected []byte + }{ + {[]byte{byte(55), byte(255), byte(255), byte(0)}, []byte{byte(55), byte(255), byte(255), byte(1)}}, + {[]byte{byte(55), byte(255), byte(255), byte(15)}, []byte{byte(55), byte(255), byte(255), byte(16)}}, + {[]byte{byte(55), byte(200), byte(255)}, []byte{byte(55), byte(201)}}, + {[]byte{byte(55), byte(255), byte(255)}, []byte{byte(56)}}, + {[]byte{byte(255), byte(255), byte(255)}, nil}, + {[]byte{byte(255)}, nil}, + {nil, nil}, + } + + for _, test := range testCases { + end := types.PrefixEndBytes(test.prefix) + assert.DeepEqual(t, test.expected, end) + } } func TestInclusiveEndBytes(t *testing.T) { t.Parallel() - require.True(t, bytes.Equal([]byte{0x00}, types.InclusiveEndBytes(nil))) + assert.DeepEqual(t, []byte{0x00}, types.InclusiveEndBytes(nil)) bs := []byte("test") - require.True(t, bytes.Equal(append(bs, byte(0x00)), types.InclusiveEndBytes(bs))) + assert.DeepEqual(t, append(bs, byte(0x00)), types.InclusiveEndBytes(bs)) } diff --git a/tests/go.mod b/tests/go.mod index f7cbd3b9c124..3258a8262d37 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -187,4 +187,5 @@ replace ( // Fix upstream GHSA-h395-qcrw-5vmq vulnerability. // TODO Remove it: https://github.com/cosmos/cosmos-sdk/issues/10409 github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.8.1 + github.com/cosmos/cosmos-sdk/x/nft => .././x/nft // todo remove after pr merged ) diff --git a/tests/integration/staking/keeper/determinstic_test.go b/tests/integration/staking/keeper/determinstic_test.go index 7d5e4b8a5df8..900676424411 100644 --- a/tests/integration/staking/keeper/determinstic_test.go +++ b/tests/integration/staking/keeper/determinstic_test.go @@ -60,7 +60,7 @@ func (s *DeterministicTestSuite) SetupTest() { ) s.Require().NoError(err) - // s.ctx = app.BaseApp.NewContext(false, tmproto.Header{Height: 1, Time: time.Now()}).WithGasMeter(sdk.NewInfiniteGasMeter()) + // s.ctx = app.BaseApp.NewContext(false, tmproto.Header{Height: 1, Time: time.Now()}).WithGasMeter(storetypes.NewInfiniteGasMeter()) s.ctx = app.BaseApp.NewContext(false, tmproto.Header{}) queryHelper := baseapp.NewQueryServerTestHelper(s.ctx, interfaceRegistry) diff --git a/testutil/sims/simulation_helpers.go b/testutil/sims/simulation_helpers.go index 65c7eeec3126..6006958ab975 100644 --- a/testutil/sims/simulation_helpers.go +++ b/testutil/sims/simulation_helpers.go @@ -1,18 +1,21 @@ package sims import ( + "bytes" "encoding/json" "fmt" "os" dbm "github.com/cosmos/cosmos-db" + "github.com/tendermint/tendermint/libs/log" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/runtime" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/kv" "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" - "github.com/tendermint/tendermint/libs/log" ) // SetupSimulation creates the config, db (levelDB), temporary directory and logger for the simulation tests. @@ -106,7 +109,7 @@ func PrintStats(db dbm.DB) { // GetSimulationLog unmarshals the KVPair's Value to the corresponding type based on the // each's module store key and the prefix bytes of the KVPair's key. -func GetSimulationLog(storeName string, sdr sdk.StoreDecoderRegistry, kvAs, kvBs []kv.Pair) (log string) { +func GetSimulationLog(storeName string, sdr storetypes.StoreDecoderRegistry, kvAs, kvBs []kv.Pair) (log string) { for i := 0; i < len(kvAs); i++ { if len(kvAs[i].Value) == 0 && len(kvBs[i].Value) == 0 { // skip if the value doesn't have any bytes @@ -123,3 +126,59 @@ func GetSimulationLog(storeName string, sdr sdk.StoreDecoderRegistry, kvAs, kvBs return log } + +// DiffKVStores compares two KVstores and returns all the key/value pairs +// that differ from one another. It also skips value comparison for a set of provided prefixes. +func DiffKVStores(a storetypes.KVStore, b storetypes.KVStore, prefixesToSkip [][]byte) (kvAs, kvBs []kv.Pair) { + iterA := a.Iterator(nil, nil) + + defer iterA.Close() + + iterB := b.Iterator(nil, nil) + + defer iterB.Close() + + for { + if !iterA.Valid() && !iterB.Valid() { + return kvAs, kvBs + } + + var kvA, kvB kv.Pair + if iterA.Valid() { + kvA = kv.Pair{Key: iterA.Key(), Value: iterA.Value()} + + iterA.Next() + } + + if iterB.Valid() { + kvB = kv.Pair{Key: iterB.Key(), Value: iterB.Value()} + } + + compareValue := true + + for _, prefix := range prefixesToSkip { + // Skip value comparison if we matched a prefix + if bytes.HasPrefix(kvA.Key, prefix) { + compareValue = false + break + } + } + + if !compareValue { + // We're skipping this key due to an exclusion prefix. If it's present in B, iterate past it. If it's + // absent don't iterate. + if bytes.Equal(kvA.Key, kvB.Key) { + iterB.Next() + } + continue + } + + // always iterate B when comparing + iterB.Next() + + if !bytes.Equal(kvA.Key, kvB.Key) || !bytes.Equal(kvA.Value, kvB.Value) { + kvAs = append(kvAs, kvA) + kvBs = append(kvBs, kvB) + } + } +} diff --git a/testutil/sims/simulation_helpers_test.go b/testutil/sims/simulation_helpers_test.go index 793fb9947a8d..7cd8643bbf52 100644 --- a/testutil/sims/simulation_helpers_test.go +++ b/testutil/sims/simulation_helpers_test.go @@ -5,16 +5,22 @@ import ( "testing" "github.com/stretchr/testify/require" + "github.com/tendermint/tendermint/libs/log" + "gotest.tools/v3/assert" + dbm "github.com/cosmos/cosmos-db" "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/store/metrics" + "github.com/cosmos/cosmos-sdk/store/rootmulti" + + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/types/kv" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" ) func TestGetSimulationLog(t *testing.T) { legacyAmino := codec.NewLegacyAmino() - decoders := make(sdk.StoreDecoderRegistry) + decoders := make(storetypes.StoreDecoderRegistry) decoders[authtypes.StoreKey] = func(kvAs, kvBs kv.Pair) string { return "10" } tests := []struct { @@ -46,3 +52,58 @@ func TestGetSimulationLog(t *testing.T) { }) } } + +func TestDiffKVStores(t *testing.T) { + store1, store2 := initTestStores(t) + // Two equal stores + k1, v1 := []byte("k1"), []byte("v1") + store1.Set(k1, v1) + store2.Set(k1, v1) + + checkDiffResults(t, store1, store2) + + // delete k1 from store2, which is now empty + store2.Delete(k1) + checkDiffResults(t, store1, store2) + + // set k1 in store2, different value than what store1 holds for k1 + v2 := []byte("v2") + store2.Set(k1, v2) + checkDiffResults(t, store1, store2) + + // add k2 to store2 + k2 := []byte("k2") + store2.Set(k2, v2) + checkDiffResults(t, store1, store2) + + // Reset stores + store1.Delete(k1) + store2.Delete(k1) + store2.Delete(k2) + + // Same keys, different value. Comparisons will be nil as prefixes are skipped. + prefix := []byte("prefix:") + k1Prefixed := append(prefix, k1...) //nolint:gocritic // append is fine here + store1.Set(k1Prefixed, v1) + store2.Set(k1Prefixed, v2) + checkDiffResults(t, store1, store2) +} + +func checkDiffResults(t *testing.T, store1, store2 storetypes.KVStore) { + kvAs1, kvBs1 := DiffKVStores(store1, store2, nil) + kvAs2, kvBs2 := DiffKVStores(store1, store2, nil) + assert.DeepEqual(t, kvAs1, kvAs2) + assert.DeepEqual(t, kvBs1, kvBs2) +} + +func initTestStores(t *testing.T) (storetypes.KVStore, storetypes.KVStore) { + db := dbm.NewMemDB() + ms := rootmulti.NewStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics()) + + key1 := storetypes.NewKVStoreKey("store1") + key2 := storetypes.NewKVStoreKey("store2") + require.NotPanics(t, func() { ms.MountStoreWithDB(key1, storetypes.StoreTypeIAVL, db) }) + require.NotPanics(t, func() { ms.MountStoreWithDB(key2, storetypes.StoreTypeIAVL, db) }) + require.NotPanics(t, func() { ms.LoadLatestVersion() }) + return ms.GetKVStore(key1), ms.GetKVStore(key2) +} diff --git a/types/context.go b/types/context.go index 8fda7c2b4e16..8120fd1ba724 100644 --- a/types/context.go +++ b/types/context.go @@ -24,15 +24,15 @@ and standard additions here would be better just to add to the Context struct */ type Context struct { baseCtx context.Context - ms MultiStore + ms storetypes.MultiStore header tmproto.Header headerHash tmbytes.HexBytes chainID string txBytes []byte logger log.Logger voteInfo []abci.VoteInfo - gasMeter GasMeter - blockGasMeter GasMeter + gasMeter storetypes.GasMeter + blockGasMeter storetypes.GasMeter checkTx bool recheckTx bool // if recheckTx == true, then checkTx must also be true minGasPrice DecCoins @@ -48,15 +48,15 @@ type Request = Context // Read-only accessors func (c Context) Context() context.Context { return c.baseCtx } -func (c Context) MultiStore() MultiStore { return c.ms } +func (c Context) MultiStore() storetypes.MultiStore { return c.ms } func (c Context) BlockHeight() int64 { return c.header.Height } func (c Context) BlockTime() time.Time { return c.header.Time } func (c Context) ChainID() string { return c.chainID } func (c Context) TxBytes() []byte { return c.txBytes } func (c Context) Logger() log.Logger { return c.logger } func (c Context) VoteInfos() []abci.VoteInfo { return c.voteInfo } -func (c Context) GasMeter() GasMeter { return c.gasMeter } -func (c Context) BlockGasMeter() GasMeter { return c.blockGasMeter } +func (c Context) GasMeter() storetypes.GasMeter { return c.gasMeter } +func (c Context) BlockGasMeter() storetypes.GasMeter { return c.blockGasMeter } func (c Context) IsCheckTx() bool { return c.checkTx } func (c Context) IsReCheckTx() bool { return c.recheckTx } func (c Context) MinGasPrices() DecCoins { return c.minGasPrice } @@ -95,7 +95,7 @@ func (c Context) Err() error { } // create a new context -func NewContext(ms MultiStore, header tmproto.Header, isCheckTx bool, logger log.Logger) Context { +func NewContext(ms storetypes.MultiStore, header tmproto.Header, isCheckTx bool, logger log.Logger) Context { // https://github.com/gogo/protobuf/issues/519 header.Time = header.Time.UTC() return Context{ @@ -120,7 +120,7 @@ func (c Context) WithContext(ctx context.Context) Context { } // WithMultiStore returns a Context with an updated MultiStore. -func (c Context) WithMultiStore(ms MultiStore) Context { +func (c Context) WithMultiStore(ms storetypes.MultiStore) Context { c.ms = ms return c } @@ -189,13 +189,13 @@ func (c Context) WithVoteInfos(voteInfo []abci.VoteInfo) Context { } // WithGasMeter returns a Context with an updated transaction GasMeter. -func (c Context) WithGasMeter(meter GasMeter) Context { +func (c Context) WithGasMeter(meter storetypes.GasMeter) Context { c.gasMeter = meter return c } // WithBlockGasMeter returns a Context with an updated block GasMeter -func (c Context) WithBlockGasMeter(meter GasMeter) Context { +func (c Context) WithBlockGasMeter(meter storetypes.GasMeter) Context { c.blockGasMeter = meter return c } @@ -277,12 +277,12 @@ func (c Context) Value(key interface{}) interface{} { // ---------------------------------------------------------------------------- // KVStore fetches a KVStore from the MultiStore. -func (c Context) KVStore(key storetypes.StoreKey) KVStore { +func (c Context) KVStore(key storetypes.StoreKey) storetypes.KVStore { return gaskv.NewStore(c.ms.GetKVStore(key), c.gasMeter, c.kvGasConfig) } // TransientStore fetches a TransientStore from the MultiStore. -func (c Context) TransientStore(key storetypes.StoreKey) KVStore { +func (c Context) TransientStore(key storetypes.StoreKey) storetypes.KVStore { return gaskv.NewStore(c.ms.GetKVStore(key), c.gasMeter, c.transientKVGasConfig) } diff --git a/types/context_test.go b/types/context_test.go index 67b2e251032b..c3ab9a0cca99 100644 --- a/types/context_test.go +++ b/types/context_test.go @@ -26,13 +26,13 @@ func TestContextTestSuite(t *testing.T) { } func (s *contextTestSuite) TestCacheContext() { - key := types.NewKVStoreKey(s.T().Name() + "_TestCacheContext") + key := storetypes.NewKVStoreKey(s.T().Name() + "_TestCacheContext") k1 := []byte("hello") v1 := []byte("world") k2 := []byte("key") v2 := []byte("value") - ctx := testutil.DefaultContext(key, types.NewTransientStoreKey("transient_"+s.T().Name())) + ctx := testutil.DefaultContext(key, storetypes.NewTransientStoreKey("transient_"+s.T().Name())) store := ctx.KVStore(key) store.Set(k1, v1) s.Require().Equal(v1, store.Get(k1)) @@ -58,8 +58,8 @@ func (s *contextTestSuite) TestCacheContext() { } func (s *contextTestSuite) TestLogContext() { - key := types.NewKVStoreKey(s.T().Name()) - ctx := testutil.DefaultContext(key, types.NewTransientStoreKey("transient_"+s.T().Name())) + key := storetypes.NewKVStoreKey(s.T().Name()) + ctx := testutil.DefaultContext(key, storetypes.NewTransientStoreKey("transient_"+s.T().Name())) ctrl := gomock.NewController(s.T()) s.T().Cleanup(ctrl.Finish) @@ -89,8 +89,8 @@ func (s *contextTestSuite) TestContextWithCustom() { txbytes := []byte("txbytes") logger := mock.NewMockLogger(ctrl) voteinfos := []abci.VoteInfo{{}} - meter := types.NewGasMeter(10000) - blockGasMeter := types.NewGasMeter(20000) + meter := storetypes.NewGasMeter(10000) + blockGasMeter := storetypes.NewGasMeter(20000) minGasPrices := types.DecCoins{types.NewInt64DecCoin("feetoken", 1)} headerHash := []byte("headerHash") zeroGasCfg := storetypes.GasConfig{} diff --git a/types/module/module.go b/types/module/module.go index d22a20e755ad..19129e50539f 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -42,6 +42,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) @@ -416,7 +417,8 @@ func (m *Manager) ExportGenesisForModules(ctx sdk.Context, cdc codec.JSONCodec, if module, ok := m.Modules[moduleName].(HasGenesis); ok { channels[moduleName] = make(chan json.RawMessage) go func(module HasGenesis, ch chan json.RawMessage) { - ctx := ctx.WithGasMeter(sdk.NewInfiniteGasMeter()) // avoid race conditions + ctx := ctx.WithGasMeter(storetypes.NewInfiniteGasMeter()) // avoid race conditions + ch <- module.ExportGenesis(ctx, cdc) }(module, channels[moduleName]) } diff --git a/types/module/simulation.go b/types/module/simulation.go index a8d69af129bb..a4494cf5a33e 100644 --- a/types/module/simulation.go +++ b/types/module/simulation.go @@ -7,9 +7,8 @@ import ( "time" sdkmath "cosmossdk.io/math" - "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/types/simulation" ) @@ -23,7 +22,7 @@ type AppModuleSimulation interface { ProposalContents(simState SimulationState) []simulation.WeightedProposalContent // register a func to decode the each module's defined types from their corresponding store key - RegisterStoreDecoder(sdk.StoreDecoderRegistry) + RegisterStoreDecoder(storetypes.StoreDecoderRegistry) // simulation operations (i.e msgs) with their respective weight WeightedOperations(simState SimulationState) []simulation.WeightedOperation @@ -32,8 +31,8 @@ type AppModuleSimulation interface { // SimulationManager defines a simulation manager that provides the high level utility // for managing and executing simulation functionalities for a group of modules type SimulationManager struct { - Modules []AppModuleSimulation // array of app modules; we use an array for deterministic simulation tests - StoreDecoders sdk.StoreDecoderRegistry // functions to decode the key-value pairs from each module's store + Modules []AppModuleSimulation // array of app modules; we use an array for deterministic simulation tests + StoreDecoders storetypes.StoreDecoderRegistry // functions to decode the key-value pairs from each module's store } // NewSimulationManager creates a new SimulationManager object @@ -42,7 +41,7 @@ type SimulationManager struct { func NewSimulationManager(modules ...AppModuleSimulation) *SimulationManager { return &SimulationManager{ Modules: modules, - StoreDecoders: make(sdk.StoreDecoderRegistry), + StoreDecoders: make(storetypes.StoreDecoderRegistry), } } diff --git a/types/query/filtered_pagination_test.go b/types/query/filtered_pagination_test.go index c04a078881a3..05b12ed9004c 100644 --- a/types/query/filtered_pagination_test.go +++ b/types/query/filtered_pagination_test.go @@ -6,6 +6,7 @@ import ( "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store/prefix" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/address" "github.com/cosmos/cosmos-sdk/types/query" @@ -219,7 +220,7 @@ func (s *paginationTestSuite) TestFilteredPaginate() { // balances: pagination: } -func execFilterPaginate(store sdk.KVStore, pageReq *query.PageRequest, appCodec codec.Codec) (balances sdk.Coins, res *query.PageResponse, err error) { +func execFilterPaginate(store storetypes.KVStore, pageReq *query.PageRequest, appCodec codec.Codec) (balances sdk.Coins, res *query.PageResponse, err error) { balancesStore := prefix.NewStore(store, types.BalancesPrefix) accountStore := prefix.NewStore(balancesStore, address.MustLengthPrefix(addr1)) @@ -261,7 +262,7 @@ func (s *paginationTestSuite) TestFilteredPaginationsNextKey() { s.Require().NoError(testutil.FundAccount(s.bankKeeper, s.ctx, addr1, balances)) store := s.ctx.KVStore(s.app.UnsafeFindStoreKey(types.StoreKey)) - execFilterPaginate := func(store sdk.KVStore, pageReq *query.PageRequest, appCodec codec.Codec) (balances sdk.Coins, res *query.PageResponse, err error) { + execFilterPaginate := func(store storetypes.KVStore, pageReq *query.PageRequest, appCodec codec.Codec) (balances sdk.Coins, res *query.PageResponse, err error) { balancesStore := prefix.NewStore(store, types.BalancesPrefix) accountStore := prefix.NewStore(balancesStore, address.MustLengthPrefix(addr1)) diff --git a/types/store.go b/types/store.go deleted file mode 100644 index 2dea5c22ead6..000000000000 --- a/types/store.go +++ /dev/null @@ -1,216 +0,0 @@ -package types - -import ( - "bytes" - fmt "fmt" - "sort" - "strings" - - "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/kv" -) - -type ( - Store = types.Store - Committer = types.Committer - CommitStore = types.CommitStore - Queryable = types.Queryable - MultiStore = types.MultiStore - CacheMultiStore = types.CacheMultiStore - CommitMultiStore = types.CommitMultiStore - MultiStorePersistentCache = types.MultiStorePersistentCache - KVStore = types.KVStore - Iterator = types.Iterator -) - -// StoreDecoderRegistry defines each of the modules store decoders. Used for ImportExport -// simulation. -type StoreDecoderRegistry map[string]func(kvA, kvB kv.Pair) string - -// Iterator over all the keys with a certain prefix in ascending order -func KVStorePrefixIterator(kvs KVStore, prefix []byte) Iterator { - return types.KVStorePrefixIterator(kvs, prefix) -} - -// Iterator over all the keys with a certain prefix in descending order. -func KVStoreReversePrefixIterator(kvs KVStore, prefix []byte) Iterator { - return types.KVStoreReversePrefixIterator(kvs, prefix) -} - -// KVStorePrefixIteratorPaginated returns iterator over items in the selected page. -// Items iterated and skipped in ascending order. -func KVStorePrefixIteratorPaginated(kvs KVStore, prefix []byte, page, limit uint) Iterator { - return types.KVStorePrefixIteratorPaginated(kvs, prefix, page, limit) -} - -// KVStoreReversePrefixIteratorPaginated returns iterator over items in the selected page. -// Items iterated and skipped in descending order. -func KVStoreReversePrefixIteratorPaginated(kvs KVStore, prefix []byte, page, limit uint) Iterator { - return types.KVStoreReversePrefixIteratorPaginated(kvs, prefix, page, limit) -} - -// DiffKVStores compares two KVstores and returns all the key/value pairs -// that differ from one another. It also skips value comparison for a set of provided prefixes. -func DiffKVStores(a KVStore, b KVStore, prefixesToSkip [][]byte) (kvAs, kvBs []kv.Pair) { - iterA := a.Iterator(nil, nil) - - defer iterA.Close() - - iterB := b.Iterator(nil, nil) - - defer iterB.Close() - - for { - if !iterA.Valid() && !iterB.Valid() { - return kvAs, kvBs - } - - var kvA, kvB kv.Pair - if iterA.Valid() { - kvA = kv.Pair{Key: iterA.Key(), Value: iterA.Value()} - - iterA.Next() - } - - if iterB.Valid() { - kvB = kv.Pair{Key: iterB.Key(), Value: iterB.Value()} - } - - compareValue := true - - for _, prefix := range prefixesToSkip { - // Skip value comparison if we matched a prefix - if bytes.HasPrefix(kvA.Key, prefix) { - compareValue = false - break - } - } - - if !compareValue { - // We're skipping this key due to an exclusion prefix. If it's present in B, iterate past it. If it's - // absent don't iterate. - if bytes.Equal(kvA.Key, kvB.Key) { - iterB.Next() - } - continue - } - - // always iterate B when comparing - iterB.Next() - - if !bytes.Equal(kvA.Key, kvB.Key) || !bytes.Equal(kvA.Value, kvB.Value) { - kvAs = append(kvAs, kvA) - kvBs = append(kvBs, kvB) - } - } -} - -// assertNoCommonPrefix will panic if there are two keys: k1 and k2 in keys, such that -// k1 is a prefix of k2 -func assertNoPrefix(keys []string) { - sorted := make([]string, len(keys)) - copy(sorted, keys) - sort.Strings(sorted) - for i := 1; i < len(sorted); i++ { - if strings.HasPrefix(sorted[i], sorted[i-1]) { - panic(fmt.Sprint("Potential key collision between KVStores:", sorted[i], " - ", sorted[i-1])) - } - } -} - -// NewKVStoreKey returns a new pointer to a KVStoreKey. -func NewKVStoreKey(name string) *types.KVStoreKey { - return types.NewKVStoreKey(name) -} - -// NewKVStoreKeys returns a map of new pointers to KVStoreKey's. -// The function will panic if there is a potential conflict in names (see `assertNoPrefix` -// function for more details). -func NewKVStoreKeys(names ...string) map[string]*types.KVStoreKey { - assertNoPrefix(names) - keys := make(map[string]*types.KVStoreKey, len(names)) - for _, n := range names { - keys[n] = NewKVStoreKey(n) - } - - return keys -} - -// Constructs new TransientStoreKey -// Must return a pointer according to the ocap principle -func NewTransientStoreKey(name string) *types.TransientStoreKey { - return types.NewTransientStoreKey(name) -} - -// NewTransientStoreKeys constructs a new map of TransientStoreKey's -// Must return pointers according to the ocap principle -// The function will panic if there is a potential conflict in names (see `assertNoPrefix` -// function for more details). -func NewTransientStoreKeys(names ...string) map[string]*types.TransientStoreKey { - assertNoPrefix(names) - keys := make(map[string]*types.TransientStoreKey) - for _, n := range names { - keys[n] = NewTransientStoreKey(n) - } - - return keys -} - -// NewMemoryStoreKeys constructs a new map matching store key names to their -// respective MemoryStoreKey references. -// The function will panic if there is a potential conflict in names (see `assertNoPrefix` -// function for more details). -func NewMemoryStoreKeys(names ...string) map[string]*types.MemoryStoreKey { - assertNoPrefix(names) - keys := make(map[string]*types.MemoryStoreKey) - for _, n := range names { - keys[n] = types.NewMemoryStoreKey(n) - } - - return keys -} - -// PrefixEndBytes returns the []byte that would end a -// range query for all []byte with a certain prefix -// Deals with last byte of prefix being FF without overflowing -func PrefixEndBytes(prefix []byte) []byte { - return types.PrefixEndBytes(prefix) -} - -// InclusiveEndBytes returns the []byte that would end a -// range query such that the input would be included -func InclusiveEndBytes(inclusiveBytes []byte) (exclusiveBytes []byte) { - return types.InclusiveEndBytes(inclusiveBytes) -} - -//---------------------------------------- - -// key-value result for iterator queries -type KVPair = types.KVPair - -//---------------------------------------- - -// TraceContext contains TraceKVStore context data. It will be written with -// every trace operation. -type TraceContext = types.TraceContext - -// -------------------------------------- - -type ( - Gas = types.Gas - GasMeter = types.GasMeter - GasConfig = types.GasConfig -) - -type ( - ErrorOutOfGas = types.ErrorOutOfGas - ErrorGasOverflow = types.ErrorGasOverflow -) - -func NewGasMeter(limit Gas) GasMeter { - return types.NewGasMeter(limit) -} - -func NewInfiniteGasMeter() GasMeter { - return types.NewInfiniteGasMeter() -} diff --git a/types/store_internal_test.go b/types/store_internal_test.go deleted file mode 100644 index 2ec4c6944cf0..000000000000 --- a/types/store_internal_test.go +++ /dev/null @@ -1,58 +0,0 @@ -package types - -import ( - "testing" - - "github.com/cosmos/cosmos-sdk/store/types" - "github.com/stretchr/testify/suite" -) - -type storeIntSuite struct { - suite.Suite -} - -func TestStoreIntSuite(t *testing.T) { - suite.Run(t, new(storeIntSuite)) -} - -func (s *storeIntSuite) TestAssertNoPrefix() { - testCases := []struct { - keys []string - expectPanic bool - }{ - {[]string{""}, false}, - {[]string{"a"}, false}, - {[]string{"a", "b"}, false}, - {[]string{"a", "b1"}, false}, - {[]string{"b2", "b1"}, false}, - {[]string{"b1", "bb", "b2"}, false}, - - {[]string{"a", ""}, true}, - {[]string{"a", "b", "a"}, true}, - {[]string{"a", "b", "aa"}, true}, - {[]string{"a", "b", "ab"}, true}, - {[]string{"a", "b1", "bb", "b12"}, true}, - } - - require := s.Require() - for _, tc := range testCases { - if tc.expectPanic { - require.Panics(func() { assertNoPrefix(tc.keys) }) - } else { - assertNoPrefix(tc.keys) - } - } -} - -func (s *storeIntSuite) TestNewKVStoreKeys() { - require := s.Require() - require.Panics(func() { NewKVStoreKeys("a1", "a") }, "should fail one key is a prefix of another one") - - require.Equal(map[string]*types.KVStoreKey{}, NewKVStoreKeys()) - require.Equal(1, len(NewKVStoreKeys("one"))) - - key := "baca" - stores := NewKVStoreKeys(key, "a") - require.Len(stores, 2) - require.Equal(key, stores[key].Name()) -} diff --git a/types/store_test.go b/types/store_test.go deleted file mode 100644 index 107b349cb2ea..000000000000 --- a/types/store_test.go +++ /dev/null @@ -1,128 +0,0 @@ -package types_test - -import ( - "testing" - - dbm "github.com/cosmos/cosmos-db" - "github.com/stretchr/testify/suite" - "github.com/tendermint/tendermint/libs/log" - - "github.com/cosmos/cosmos-sdk/store/metrics" - "github.com/cosmos/cosmos-sdk/store/rootmulti" - "github.com/cosmos/cosmos-sdk/store/types" - sdk "github.com/cosmos/cosmos-sdk/types" -) - -type storeTestSuite struct { - suite.Suite -} - -func TestStoreTestSuite(t *testing.T) { - suite.Run(t, new(storeTestSuite)) -} - -func (s *storeTestSuite) SetupSuite() { - s.T().Parallel() -} - -func (s *storeTestSuite) TestPrefixEndBytes() { - testCases := []struct { - prefix []byte - expected []byte - }{ - {[]byte{byte(55), byte(255), byte(255), byte(0)}, []byte{byte(55), byte(255), byte(255), byte(1)}}, - {[]byte{byte(55), byte(255), byte(255), byte(15)}, []byte{byte(55), byte(255), byte(255), byte(16)}}, - {[]byte{byte(55), byte(200), byte(255)}, []byte{byte(55), byte(201)}}, - {[]byte{byte(55), byte(255), byte(255)}, []byte{byte(56)}}, - {[]byte{byte(255), byte(255), byte(255)}, nil}, - {[]byte{byte(255)}, nil}, - {nil, nil}, - } - - for _, test := range testCases { - end := types.PrefixEndBytes(test.prefix) - s.Require().Equal(test.expected, end) - } -} - -func (s *storeTestSuite) TestCommitID() { - var empty types.CommitID - s.Require().True(empty.IsZero()) - - nonempty := types.CommitID{ - Version: 1, - Hash: []byte("testhash"), - } - s.Require().False(nonempty.IsZero()) -} - -func (s *storeTestSuite) TestNewTransientStoreKeys() { - s.Require().Equal(map[string]*types.TransientStoreKey{}, sdk.NewTransientStoreKeys()) - s.Require().Equal(1, len(sdk.NewTransientStoreKeys("one"))) -} - -func (s *storeTestSuite) TestNewInfiniteGasMeter() { - gm := sdk.NewInfiniteGasMeter() - s.Require().NotNil(gm) - _, ok := gm.(types.GasMeter) //nolint:gosimple - s.Require().True(ok) -} - -func (s *storeTestSuite) TestStoreTypes() { - s.Require().Equal(sdk.InclusiveEndBytes([]byte("endbytes")), types.InclusiveEndBytes([]byte("endbytes"))) -} - -func (s *storeTestSuite) TestDiffKVStores() { - store1, store2 := s.initTestStores() - // Two equal stores - k1, v1 := []byte("k1"), []byte("v1") - store1.Set(k1, v1) - store2.Set(k1, v1) - - s.checkDiffResults(store1, store2) - - // delete k1 from store2, which is now empty - store2.Delete(k1) - s.checkDiffResults(store1, store2) - - // set k1 in store2, different value than what store1 holds for k1 - v2 := []byte("v2") - store2.Set(k1, v2) - s.checkDiffResults(store1, store2) - - // add k2 to store2 - k2 := []byte("k2") - store2.Set(k2, v2) - s.checkDiffResults(store1, store2) - - // Reset stores - store1.Delete(k1) - store2.Delete(k1) - store2.Delete(k2) - - // Same keys, different value. Comparisons will be nil as prefixes are skipped. - prefix := []byte("prefix:") - k1Prefixed := append(prefix, k1...) //nolint:gocritic // append is fine here - store1.Set(k1Prefixed, v1) - store2.Set(k1Prefixed, v2) - s.checkDiffResults(store1, store2) -} - -func (s *storeTestSuite) initTestStores() (types.KVStore, types.KVStore) { - db := dbm.NewMemDB() - ms := rootmulti.NewStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics()) - - key1 := types.NewKVStoreKey("store1") - key2 := types.NewKVStoreKey("store2") - s.Require().NotPanics(func() { ms.MountStoreWithDB(key1, types.StoreTypeIAVL, db) }) - s.Require().NotPanics(func() { ms.MountStoreWithDB(key2, types.StoreTypeIAVL, db) }) - s.Require().NoError(ms.LoadLatestVersion()) - return ms.GetKVStore(key1), ms.GetKVStore(key2) -} - -func (s *storeTestSuite) checkDiffResults(store1, store2 types.KVStore) { - kvAs1, kvBs1 := sdk.DiffKVStores(store1, store2, nil) - kvAs2, kvBs2 := sdk.DiffKVStores(store1, store2, nil) - s.Require().Equal(kvAs1, kvAs2) - s.Require().Equal(kvBs1, kvBs2) -} diff --git a/x/auth/ante/ante.go b/x/auth/ante/ante.go index a562e67ee39c..44bffaeae6b2 100644 --- a/x/auth/ante/ante.go +++ b/x/auth/ante/ante.go @@ -1,6 +1,7 @@ package ante import ( + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/tx/signing" @@ -15,7 +16,7 @@ type HandlerOptions struct { ExtensionOptionChecker ExtensionOptionChecker FeegrantKeeper FeegrantKeeper SignModeHandler authsigning.SignModeHandler - SigGasConsumer func(meter sdk.GasMeter, sig signing.SignatureV2, params types.Params) error + SigGasConsumer func(meter storetypes.GasMeter, sig signing.SignatureV2, params types.Params) error TxFeeChecker TxFeeChecker } diff --git a/x/auth/ante/ante_test.go b/x/auth/ante/ante_test.go index c42e792f89d4..c4532c7bd187 100644 --- a/x/auth/ante/ante_test.go +++ b/x/auth/ante/ante_test.go @@ -15,6 +15,7 @@ import ( kmultisig "github.com/cosmos/cosmos-sdk/crypto/keys/multisig" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -1368,7 +1369,7 @@ func TestCustomSignatureVerificationGasConsumer(t *testing.T) { BankKeeper: suite.bankKeeper, FeegrantKeeper: suite.feeGrantKeeper, SignModeHandler: suite.clientCtx.TxConfig.SignModeHandler(), - SigGasConsumer: func(meter sdk.GasMeter, sig signing.SignatureV2, params authtypes.Params) error { + SigGasConsumer: func(meter storetypes.GasMeter, sig signing.SignatureV2, params authtypes.Params) error { switch pubkey := sig.PubKey.(type) { case *ed25519.PubKey: meter.ConsumeGas(params.SigVerifyCostED25519, "ante verify: ed25519") diff --git a/x/auth/ante/basic.go b/x/auth/ante/basic.go index e9f1e0999e50..8bb88135b68a 100644 --- a/x/auth/ante/basic.go +++ b/x/auth/ante/basic.go @@ -4,6 +4,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec/legacy" "github.com/cosmos/cosmos-sdk/crypto/keys/multisig" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/tx/signing" @@ -93,7 +94,7 @@ func (cgts ConsumeTxSizeGasDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim } params := cgts.ak.GetParams(ctx) - ctx.GasMeter().ConsumeGas(params.TxSizeCostPerByte*sdk.Gas(len(ctx.TxBytes())), "txSize") + ctx.GasMeter().ConsumeGas(params.TxSizeCostPerByte*storetypes.Gas(len(ctx.TxBytes())), "txSize") // simulate gas cost for signatures in simulate mode if simulate { @@ -128,7 +129,7 @@ func (cgts ConsumeTxSizeGasDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim } sigBz := legacy.Cdc.MustMarshal(simSig) - cost := sdk.Gas(len(sigBz) + 6) + cost := storetypes.Gas(len(sigBz) + 6) // If the pubkey is a multi-signature pubkey, then we estimate for the maximum // number of signers. diff --git a/x/auth/ante/basic_test.go b/x/auth/ante/basic_test.go index 8bf7b7abbb16..fedc81ed821c 100644 --- a/x/auth/ante/basic_test.go +++ b/x/auth/ante/basic_test.go @@ -6,6 +6,7 @@ import ( cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/crypto/types/multisig" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -129,7 +130,7 @@ func TestConsumeGasForTxSize(t *testing.T) { require.Nil(t, err, "Cannot marshal tx: %v", err) params := suite.accountKeeper.GetParams(suite.ctx) - expectedGas := sdk.Gas(len(txBytes)) * params.TxSizeCostPerByte + expectedGas := storetypes.Gas(len(txBytes)) * params.TxSizeCostPerByte // Set suite.ctx with TxBytes manually suite.ctx = suite.ctx.WithTxBytes(txBytes) diff --git a/x/auth/ante/feegrant_test.go b/x/auth/ante/feegrant_test.go index d14b798df1a1..dc533a76e598 100644 --- a/x/auth/ante/feegrant_test.go +++ b/x/auth/ante/feegrant_test.go @@ -12,8 +12,8 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil/testdata" - sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/simulation" @@ -183,7 +183,7 @@ func TestDeductFeesNoDelegation(t *testing.T) { } // don't consume any gas -func SigGasNoConsumer(meter sdk.GasMeter, sig []byte, pubkey crypto.PubKey, params authtypes.Params) error { +func SigGasNoConsumer(meter storetypes.GasMeter, sig []byte, pubkey crypto.PubKey, params authtypes.Params) error { return nil } diff --git a/x/auth/ante/setup.go b/x/auth/ante/setup.go index 4e9ffe862b9c..edae07882789 100644 --- a/x/auth/ante/setup.go +++ b/x/auth/ante/setup.go @@ -3,6 +3,7 @@ package ante import ( "fmt" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" @@ -47,7 +48,7 @@ func (sud SetUpContextDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate defer func() { if r := recover(); r != nil { switch rType := r.(type) { - case sdk.ErrorOutOfGas: + case storetypes.ErrorOutOfGas: log := fmt.Sprintf( "out of gas in location: %v; gasWanted: %d, gasUsed: %d", rType.Descriptor, gasTx.GetGas(), newCtx.GasMeter().GasConsumed()) @@ -67,8 +68,8 @@ func SetGasMeter(simulate bool, ctx sdk.Context, gasLimit uint64) sdk.Context { // In various cases such as simulation and during the genesis block, we do not // meter any gas utilization. if simulate || ctx.BlockHeight() == 0 { - return ctx.WithGasMeter(sdk.NewInfiniteGasMeter()) + return ctx.WithGasMeter(storetypes.NewInfiniteGasMeter()) } - return ctx.WithGasMeter(sdk.NewGasMeter(gasLimit)) + return ctx.WithGasMeter(storetypes.NewGasMeter(gasLimit)) } diff --git a/x/auth/ante/setup_test.go b/x/auth/ante/setup_test.go index 675deed778f4..c3c6943e4d53 100644 --- a/x/auth/ante/setup_test.go +++ b/x/auth/ante/setup_test.go @@ -4,6 +4,7 @@ import ( "testing" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -34,7 +35,7 @@ func TestSetup(t *testing.T) { antehandler := sdk.ChainAnteDecorators(sud) // Set height to non-zero value for GasMeter to be set - suite.ctx = suite.ctx.WithBlockHeight(1).WithGasMeter(sdk.NewGasMeter(0)) + suite.ctx = suite.ctx.WithBlockHeight(1).WithGasMeter(storetypes.NewGasMeter(0)) // Context GasMeter Limit not set require.Equal(t, uint64(0), suite.ctx.GasMeter().Limit(), "GasMeter set with limit before setup") diff --git a/x/auth/ante/sigverify.go b/x/auth/ante/sigverify.go index 9db289b3d81a..08dfcc01dc2c 100644 --- a/x/auth/ante/sigverify.go +++ b/x/auth/ante/sigverify.go @@ -12,6 +12,7 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keys/secp256r1" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/crypto/types/multisig" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/tx/signing" @@ -39,7 +40,7 @@ func init() { // SignatureVerificationGasConsumer is the type of function that is used to both // consume gas when verifying signatures and also to accept or reject different types of pubkeys // This is where apps can define their own PubKey -type SignatureVerificationGasConsumer = func(meter sdk.GasMeter, sig signing.SignatureV2, params types.Params) error +type SignatureVerificationGasConsumer = func(meter storetypes.GasMeter, sig signing.SignatureV2, params types.Params) error // SetPubKeyDecorator sets PubKeys in context for any signer which does not already have pubkey set // PubKeys must be set in context for all signers before any other sigverify decorators run @@ -388,7 +389,7 @@ func (vscd ValidateSigCountDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim // for signature verification based upon the public key type. The cost is fetched from the given params and is matched // by the concrete type. func DefaultSigVerificationGasConsumer( - meter sdk.GasMeter, sig signing.SignatureV2, params types.Params, + meter storetypes.GasMeter, sig signing.SignatureV2, params types.Params, ) error { pubkey := sig.PubKey switch pubkey := pubkey.(type) { @@ -422,7 +423,7 @@ func DefaultSigVerificationGasConsumer( // ConsumeMultisignatureVerificationGas consumes gas from a GasMeter for verifying a multisig pubkey signature func ConsumeMultisignatureVerificationGas( - meter sdk.GasMeter, sig *signing.MultiSignatureData, pubkey multisig.PubKey, + meter storetypes.GasMeter, sig *signing.MultiSignatureData, pubkey multisig.PubKey, params types.Params, accSeq uint64, ) error { size := sig.BitArray.Count() diff --git a/x/auth/ante/sigverify_test.go b/x/auth/ante/sigverify_test.go index 8155d28a9083..cc1c9f3b0780 100644 --- a/x/auth/ante/sigverify_test.go +++ b/x/auth/ante/sigverify_test.go @@ -12,6 +12,7 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keys/secp256r1" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/crypto/types/multisig" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/tx/signing" @@ -84,7 +85,7 @@ func TestConsumeSignatureVerificationGas(t *testing.T) { } type args struct { - meter sdk.GasMeter + meter storetypes.GasMeter sig signing.SignatureData pubkey cryptotypes.PubKey params types.Params @@ -95,11 +96,11 @@ func TestConsumeSignatureVerificationGas(t *testing.T) { gasConsumed uint64 shouldErr bool }{ - {"PubKeyEd25519", args{sdk.NewInfiniteGasMeter(), nil, ed25519.GenPrivKey().PubKey(), params}, p.SigVerifyCostED25519, true}, - {"PubKeySecp256k1", args{sdk.NewInfiniteGasMeter(), nil, secp256k1.GenPrivKey().PubKey(), params}, p.SigVerifyCostSecp256k1, false}, - {"PubKeySecp256r1", args{sdk.NewInfiniteGasMeter(), nil, skR1.PubKey(), params}, p.SigVerifyCostSecp256r1(), false}, - {"Multisig", args{sdk.NewInfiniteGasMeter(), multisignature1, multisigKey1, params}, expectedCost1, false}, - {"unknown key", args{sdk.NewInfiniteGasMeter(), nil, nil, params}, 0, true}, + {"PubKeyEd25519", args{storetypes.NewInfiniteGasMeter(), nil, ed25519.GenPrivKey().PubKey(), params}, p.SigVerifyCostED25519, true}, + {"PubKeySecp256k1", args{storetypes.NewInfiniteGasMeter(), nil, secp256k1.GenPrivKey().PubKey(), params}, p.SigVerifyCostSecp256k1, false}, + {"PubKeySecp256r1", args{storetypes.NewInfiniteGasMeter(), nil, skR1.PubKey(), params}, p.SigVerifyCostSecp256r1(), false}, + {"Multisig", args{storetypes.NewInfiniteGasMeter(), multisignature1, multisigKey1, params}, expectedCost1, false}, + {"unknown key", args{storetypes.NewInfiniteGasMeter(), nil, nil, params}, 0, true}, } for _, tt := range tests { sigV2 := signing.SignatureV2{ @@ -315,7 +316,7 @@ func TestSigIntegration(t *testing.T) { require.Equal(t, initialSigCost*uint64(len(privs)), doubleCost-initialCost) } -func runSigDecorators(t *testing.T, params types.Params, _ bool, privs ...cryptotypes.PrivKey) (sdk.Gas, error) { +func runSigDecorators(t *testing.T, params types.Params, _ bool, privs ...cryptotypes.PrivKey) (storetypes.Gas, error) { suite := SetupTestSuite(t, true) suite.txBuilder = suite.clientCtx.TxConfig.NewTxBuilder() diff --git a/x/auth/ante/testutil_test.go b/x/auth/ante/testutil_test.go index 38e38b4bad09..900f6bfb7170 100644 --- a/x/auth/ante/testutil_test.go +++ b/x/auth/ante/testutil_test.go @@ -9,16 +9,16 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/tx" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" "github.com/cosmos/cosmos-sdk/types/tx/signing" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/auth/ante" - "github.com/cosmos/cosmos-sdk/x/auth/keeper" - - moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" antetestutil "github.com/cosmos/cosmos-sdk/x/auth/ante/testutil" + "github.com/cosmos/cosmos-sdk/x/auth/keeper" xauthsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" authtestutil "github.com/cosmos/cosmos-sdk/x/auth/testutil" "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -50,8 +50,8 @@ func SetupTestSuite(t *testing.T, isCheckTx bool) *AnteTestSuite { suite.feeGrantKeeper = antetestutil.NewMockFeegrantKeeper(ctrl) - key := sdk.NewKVStoreKey(types.StoreKey) - testCtx := testutil.DefaultContextWithDB(t, key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(types.StoreKey) + testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) suite.ctx = testCtx.Ctx.WithIsCheckTx(isCheckTx).WithBlockHeight(1) // app.BaseApp.NewContext(isCheckTx, tmproto.Header{}).WithBlockHeight(1) suite.encCfg = moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{}) diff --git a/x/auth/keeper/account.go b/x/auth/keeper/account.go index f6f8613de369..99625a81bdd6 100644 --- a/x/auth/keeper/account.go +++ b/x/auth/keeper/account.go @@ -1,6 +1,7 @@ package keeper import ( + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/types" ) @@ -95,7 +96,7 @@ func (ak AccountKeeper) RemoveAccount(ctx sdk.Context, acc sdk.AccountI) { // Stops iteration when callback returns true. func (ak AccountKeeper) IterateAccounts(ctx sdk.Context, cb func(account sdk.AccountI) (stop bool)) { store := ctx.KVStore(ak.storeKey) - iterator := sdk.KVStorePrefixIterator(store, types.AddressStoreKeyPrefix) + iterator := storetypes.KVStorePrefixIterator(store, types.AddressStoreKeyPrefix) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { diff --git a/x/auth/keeper/deterministic_test.go b/x/auth/keeper/deterministic_test.go index 2cf9e73d2ed6..2b83abd8387f 100644 --- a/x/auth/keeper/deterministic_test.go +++ b/x/auth/keeper/deterministic_test.go @@ -46,8 +46,8 @@ func (suite *DeterministicTestSuite) SetupTest() { suite.encCfg = moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{}) suite.Require() - key := sdk.NewKVStoreKey(types.StoreKey) - testCtx := testutil.DefaultContextWithDB(suite.T(), key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(types.StoreKey) + testCtx := testutil.DefaultContextWithDB(suite.T(), key, storetypes.NewTransientStoreKey("transient_test")) suite.ctx = testCtx.Ctx.WithBlockHeader(tmproto.Header{}) maccPerms := map[string][]string{ diff --git a/x/auth/keeper/keeper_test.go b/x/auth/keeper/keeper_test.go index 29dc06efbb72..f19c515978a4 100644 --- a/x/auth/keeper/keeper_test.go +++ b/x/auth/keeper/keeper_test.go @@ -10,6 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -43,8 +44,8 @@ type KeeperTestSuite struct { func (suite *KeeperTestSuite) SetupTest() { suite.encCfg = moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{}) - key := sdk.NewKVStoreKey(types.StoreKey) - testCtx := testutil.DefaultContextWithDB(suite.T(), key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(types.StoreKey) + testCtx := testutil.DefaultContextWithDB(suite.T(), key, storetypes.NewTransientStoreKey("transient_test")) suite.ctx = testCtx.Ctx.WithBlockHeader(tmproto.Header{}) maccPerms := map[string][]string{ diff --git a/x/auth/migrations/v2/store_test.go b/x/auth/migrations/v2/store_test.go index f9cd5f200b3f..12f3ffdad027 100644 --- a/x/auth/migrations/v2/store_test.go +++ b/x/auth/migrations/v2/store_test.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/require" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" @@ -43,8 +44,8 @@ func TestMigrateVestingAccounts(t *testing.T) { encCfg := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{}) cdc := encCfg.Codec - storeKey := sdk.NewKVStoreKey(v1.ModuleName) - tKey := sdk.NewTransientStoreKey("transient_test") + storeKey := storetypes.NewKVStoreKey(v1.ModuleName) + tKey := storetypes.NewTransientStoreKey("transient_test") ctx := testutil.DefaultContext(storeKey, tKey) store := ctx.KVStore(storeKey) diff --git a/x/auth/migrations/v3/store.go b/x/auth/migrations/v3/store.go index b8b87646d223..c38a0e291e65 100644 --- a/x/auth/migrations/v3/store.go +++ b/x/auth/migrations/v3/store.go @@ -9,7 +9,7 @@ import ( func mapAccountAddressToAccountID(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.BinaryCodec) error { store := ctx.KVStore(storeKey) - iterator := sdk.KVStorePrefixIterator(store, types.AddressStoreKeyPrefix) + iterator := storetypes.KVStorePrefixIterator(store, types.AddressStoreKeyPrefix) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { diff --git a/x/auth/migrations/v3/store_test.go b/x/auth/migrations/v3/store_test.go index d47d7ce2f782..57da1362be28 100644 --- a/x/auth/migrations/v3/store_test.go +++ b/x/auth/migrations/v3/store_test.go @@ -9,6 +9,7 @@ import ( tmproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" @@ -39,8 +40,8 @@ func TestMigrateMapAccAddressToAccNumberKey(t *testing.T) { encCfg := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{}) cdc := encCfg.Codec - storeKey := sdk.NewKVStoreKey(v1.ModuleName) - tKey := sdk.NewTransientStoreKey("transient_test") + storeKey := storetypes.NewKVStoreKey(v1.ModuleName) + tKey := storetypes.NewTransientStoreKey("transient_test") ctx := testutil.DefaultContext(storeKey, tKey) store := ctx.KVStore(storeKey) diff --git a/x/auth/migrations/v4/migrate.go b/x/auth/migrations/v4/migrate.go index 93b8658408c8..04bd5b14b172 100644 --- a/x/auth/migrations/v4/migrate.go +++ b/x/auth/migrations/v4/migrate.go @@ -2,6 +2,7 @@ package v4 import ( "github.com/cosmos/cosmos-sdk/codec" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/exported" "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -13,7 +14,7 @@ var ParamsKey = []byte{0x01} // version 4. Specifically, it takes the parameters that are currently stored // and managed by the x/params modules and stores them directly into the x/auth // module state. -func Migrate(ctx sdk.Context, store sdk.KVStore, legacySubspace exported.Subspace, cdc codec.BinaryCodec) error { +func Migrate(ctx sdk.Context, store storetypes.KVStore, legacySubspace exported.Subspace, cdc codec.BinaryCodec) error { var currParams types.Params legacySubspace.GetParamSet(ctx, &currParams) diff --git a/x/auth/migrations/v4/migrator_test.go b/x/auth/migrations/v4/migrator_test.go index e3dd3b1d5573..fa1ba5ec598e 100644 --- a/x/auth/migrations/v4/migrator_test.go +++ b/x/auth/migrations/v4/migrator_test.go @@ -5,6 +5,7 @@ import ( "github.com/stretchr/testify/require" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -31,8 +32,8 @@ func TestMigrate(t *testing.T) { encCfg := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{}) cdc := encCfg.Codec - storeKey := sdk.NewKVStoreKey(v1.ModuleName) - tKey := sdk.NewTransientStoreKey("transient_test") + storeKey := storetypes.NewKVStoreKey(v1.ModuleName) + tKey := storetypes.NewTransientStoreKey("transient_test") ctx := testutil.DefaultContext(storeKey, tKey) store := ctx.KVStore(storeKey) diff --git a/x/auth/module.go b/x/auth/module.go index ca849b2eb581..089d919ec17d 100644 --- a/x/auth/module.go +++ b/x/auth/module.go @@ -184,7 +184,7 @@ func (AppModule) ProposalContents(simState module.SimulationState) []simtypes.We } // RegisterStoreDecoder registers a decoder for auth module's types -func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { +func (am AppModule) RegisterStoreDecoder(sdr store.StoreDecoderRegistry) { sdr[types.StoreKey] = simulation.NewDecodeStore(am.accountKeeper) } diff --git a/x/auth/signing/verify_test.go b/x/auth/signing/verify_test.go index ecedbcee23bc..4336fdf25a32 100644 --- a/x/auth/signing/verify_test.go +++ b/x/auth/signing/verify_test.go @@ -8,13 +8,13 @@ import ( kmultisig "github.com/cosmos/cosmos-sdk/crypto/keys/multisig" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/crypto/types/multisig" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/auth/ante" - - "github.com/cosmos/cosmos-sdk/testutil" - moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" "github.com/cosmos/cosmos-sdk/x/auth/keeper" "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" "github.com/cosmos/cosmos-sdk/x/auth/signing" @@ -32,7 +32,7 @@ func TestVerifySignature(t *testing.T) { ) encCfg := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{}) - key := sdk.NewKVStoreKey(types.StoreKey) + key := storetypes.NewKVStoreKey(types.StoreKey) maccPerms := map[string][]string{ "fee_collector": nil, @@ -52,7 +52,7 @@ func TestVerifySignature(t *testing.T) { types.NewModuleAddress("gov").String(), ) - testCtx := testutil.DefaultContextWithDB(t, key, sdk.NewTransientStoreKey("transient_test")) + testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) ctx := testCtx.Ctx.WithBlockHeader(tmproto.Header{}) encCfg.Amino.RegisterConcrete(testdata.TestMsg{}, "cosmos-sdk/Test", nil) diff --git a/x/auth/vesting/msg_server_test.go b/x/auth/vesting/msg_server_test.go index 300d48c995dc..1b43d26e01a7 100644 --- a/x/auth/vesting/msg_server_test.go +++ b/x/auth/vesting/msg_server_test.go @@ -9,6 +9,7 @@ import ( tmproto "github.com/tendermint/tendermint/proto/tendermint/types" tmtime "github.com/tendermint/tendermint/types/time" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -38,8 +39,8 @@ type VestingTestSuite struct { } func (s *VestingTestSuite) SetupTest() { - key := sdk.NewKVStoreKey(authtypes.StoreKey) - testCtx := testutil.DefaultContextWithDB(s.T(), key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(authtypes.StoreKey) + testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) s.ctx = testCtx.Ctx.WithBlockHeader(tmproto.Header{Time: tmtime.Now()}) encCfg := moduletestutil.MakeTestEncodingConfig() diff --git a/x/auth/vesting/types/vesting_account_test.go b/x/auth/vesting/types/vesting_account_test.go index 0e40211b79d1..3d37a6c56d4b 100644 --- a/x/auth/vesting/types/vesting_account_test.go +++ b/x/auth/vesting/types/vesting_account_test.go @@ -10,6 +10,7 @@ import ( tmtime "github.com/tendermint/tendermint/types/time" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" @@ -35,8 +36,8 @@ type VestingAccountTestSuite struct { func (s *VestingAccountTestSuite) SetupTest() { encCfg := moduletestutil.MakeTestEncodingConfig(vesting.AppModuleBasic{}) - key := sdk.NewKVStoreKey(authtypes.StoreKey) - testCtx := testutil.DefaultContextWithDB(s.T(), key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(authtypes.StoreKey) + testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) s.ctx = testCtx.Ctx.WithBlockHeader(tmproto.Header{}) maccPerms := map[string][]string{ diff --git a/x/authz/keeper/genesis_test.go b/x/authz/keeper/genesis_test.go index f474fef54067..9ab0056a4a1a 100644 --- a/x/authz/keeper/genesis_test.go +++ b/x/authz/keeper/genesis_test.go @@ -10,6 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -31,8 +32,8 @@ type GenesisTestSuite struct { } func (suite *GenesisTestSuite) SetupTest() { - key := sdk.NewKVStoreKey(keeper.StoreKey) - testCtx := testutil.DefaultContextWithDB(suite.T(), key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(keeper.StoreKey) + testCtx := testutil.DefaultContextWithDB(suite.T(), key, storetypes.NewTransientStoreKey("transient_test")) suite.ctx = testCtx.Ctx.WithBlockHeader(tmproto.Header{Height: 1}) suite.encCfg = moduletestutil.MakeTestEncodingConfig(authzmodule.AppModuleBasic{}) diff --git a/x/authz/keeper/keeper.go b/x/authz/keeper/keeper.go index 22edf8f2218f..729df792fdf5 100644 --- a/x/authz/keeper/keeper.go +++ b/x/authz/keeper/keeper.go @@ -231,7 +231,7 @@ func (k Keeper) DeleteGrant(ctx sdk.Context, grantee sdk.AccAddress, granter sdk func (k Keeper) GetAuthorizations(ctx sdk.Context, grantee sdk.AccAddress, granter sdk.AccAddress) ([]authz.Authorization, error) { store := ctx.KVStore(k.storeKey) key := grantStoreKey(grantee, granter, "") - iter := sdk.KVStorePrefixIterator(store, key) + iter := storetypes.KVStorePrefixIterator(store, key) defer iter.Close() var authorization authz.Grant @@ -279,7 +279,7 @@ func (k Keeper) IterateGrants(ctx sdk.Context, handler func(granterAddr sdk.AccAddress, granteeAddr sdk.AccAddress, grant authz.Grant) bool, ) { store := ctx.KVStore(k.storeKey) - iter := sdk.KVStorePrefixIterator(store, GrantKey) + iter := storetypes.KVStorePrefixIterator(store, GrantKey) defer iter.Close() for ; iter.Valid(); iter.Next() { var grant authz.Grant @@ -378,7 +378,7 @@ func (k Keeper) removeFromGrantQueue(ctx sdk.Context, grantKey []byte, granter, func (k Keeper) DequeueAndDeleteExpiredGrants(ctx sdk.Context) error { store := ctx.KVStore(k.storeKey) - iterator := store.Iterator(GrantQueuePrefix, sdk.InclusiveEndBytes(GrantQueueTimePrefix(ctx.BlockTime()))) + iterator := store.Iterator(GrantQueuePrefix, storetypes.InclusiveEndBytes(GrantQueueTimePrefix(ctx.BlockTime()))) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { diff --git a/x/authz/keeper/keeper_test.go b/x/authz/keeper/keeper_test.go index 9925871df279..8be75734cef1 100644 --- a/x/authz/keeper/keeper_test.go +++ b/x/authz/keeper/keeper_test.go @@ -10,6 +10,7 @@ import ( tmtime "github.com/tendermint/tendermint/types/time" "github.com/cosmos/cosmos-sdk/baseapp" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" @@ -44,8 +45,8 @@ type TestSuite struct { } func (s *TestSuite) SetupTest() { - key := sdk.NewKVStoreKey(authzkeeper.StoreKey) - testCtx := testutil.DefaultContextWithDB(s.T(), key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(authzkeeper.StoreKey) + testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) s.ctx = testCtx.Ctx.WithBlockHeader(tmproto.Header{Time: tmtime.Now()}) s.encCfg = moduletestutil.MakeTestEncodingConfig(authzmodule.AppModuleBasic{}) diff --git a/x/authz/migrations/v2/store_test.go b/x/authz/migrations/v2/store_test.go index 52fbf4f08eab..66d42e15af33 100644 --- a/x/authz/migrations/v2/store_test.go +++ b/x/authz/migrations/v2/store_test.go @@ -8,6 +8,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/authz" @@ -22,8 +23,8 @@ func TestMigration(t *testing.T) { var cdc codec.Codec depinject.Inject(authztestutil.AppConfig, &cdc) - authzKey := sdk.NewKVStoreKey("authz") - ctx := testutil.DefaultContext(authzKey, sdk.NewTransientStoreKey("transient_test")) + authzKey := storetypes.NewKVStoreKey("authz") + ctx := testutil.DefaultContext(authzKey, storetypes.NewTransientStoreKey("transient_test")) granter1 := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address()) grantee1 := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address()) granter2 := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address()) diff --git a/x/authz/module/abci_test.go b/x/authz/module/abci_test.go index e3dd57ae8312..e94e638fbb37 100644 --- a/x/authz/module/abci_test.go +++ b/x/authz/module/abci_test.go @@ -5,6 +5,7 @@ import ( "time" "github.com/cosmos/cosmos-sdk/baseapp" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" @@ -15,16 +16,17 @@ import ( authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module" authztestutil "github.com/cosmos/cosmos-sdk/x/authz/testutil" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" - "github.com/tendermint/tendermint/libs/log" + "github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/proto/tendermint/types" ) func TestExpiredGrantsQueue(t *testing.T) { - key := sdk.NewKVStoreKey(keeper.StoreKey) - testCtx := testutil.DefaultContextWithDB(t, key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(keeper.StoreKey) + testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(authzmodule.AppModuleBasic{}) ctx := testCtx.Ctx.WithBlockHeader(types.Header{}) diff --git a/x/authz/module/module.go b/x/authz/module/module.go index a76ca3c9dd18..f674d16b6cb6 100644 --- a/x/authz/module/module.go +++ b/x/authz/module/module.go @@ -213,7 +213,7 @@ func (am AppModule) ProposalContents(simState module.SimulationState) []simtypes } // RegisterStoreDecoder registers a decoder for authz module's types -func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { +func (am AppModule) RegisterStoreDecoder(sdr store.StoreDecoderRegistry) { sdr[keeper.StoreKey] = simulation.NewDecodeStore(am.cdc) } diff --git a/x/bank/keeper/keeper_test.go b/x/bank/keeper/keeper_test.go index a4ee759b318e..2b90955c338c 100644 --- a/x/bank/keeper/keeper_test.go +++ b/x/bank/keeper/keeper_test.go @@ -14,6 +14,7 @@ import ( tmtime "github.com/tendermint/tendermint/types/time" "github.com/cosmos/cosmos-sdk/baseapp" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -85,8 +86,8 @@ func TestKeeperTestSuite(t *testing.T) { } func (suite *KeeperTestSuite) SetupTest() { - key := sdk.NewKVStoreKey(banktypes.StoreKey) - testCtx := testutil.DefaultContextWithDB(suite.T(), key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(banktypes.StoreKey) + testCtx := testutil.DefaultContextWithDB(suite.T(), key, storetypes.NewTransientStoreKey("transient_test")) ctx := testCtx.Ctx.WithBlockHeader(tmproto.Header{Time: tmtime.Now()}) encCfg := moduletestutil.MakeTestEncodingConfig() @@ -199,7 +200,7 @@ func (suite *KeeperTestSuite) TestGetAuthority() { NewKeeperWithAuthority := func(authority string) keeper.BaseKeeper { return keeper.NewBaseKeeper( moduletestutil.MakeTestEncodingConfig().Codec, - sdk.NewKVStoreKey(banktypes.StoreKey), + storetypes.NewKVStoreKey(banktypes.StoreKey), nil, nil, authority, diff --git a/x/bank/keeper/send.go b/x/bank/keeper/send.go index 95f14fe7fa40..28263d7af320 100644 --- a/x/bank/keeper/send.go +++ b/x/bank/keeper/send.go @@ -431,7 +431,7 @@ func (k BaseSendKeeper) SetAllSendEnabled(ctx sdk.Context, entries []*types.Send } // setSendEnabledEntry sets SendEnabled for the given denom to the give value in the provided store. -func (k BaseSendKeeper) setSendEnabledEntry(store sdk.KVStore, denom string, value bool) { +func (k BaseSendKeeper) setSendEnabledEntry(store storetypes.KVStore, denom string, value bool) { key := types.CreateSendEnabledKey(denom) bz := k.cdc.MustMarshal(&gogotypes.BoolValue{Value: value}) @@ -448,7 +448,7 @@ func (k BaseSendKeeper) DeleteSendEnabled(ctx sdk.Context, denoms ...string) { } // getSendEnabledPrefixStore gets a prefix store for the SendEnabled entries. -func (k BaseSendKeeper) getSendEnabledPrefixStore(ctx sdk.Context) sdk.KVStore { +func (k BaseSendKeeper) getSendEnabledPrefixStore(ctx sdk.Context) storetypes.KVStore { return prefix.NewStore(ctx.KVStore(k.storeKey), types.SendEnabledPrefix) } @@ -493,7 +493,7 @@ func (k BaseSendKeeper) GetAllSendEnabledEntries(ctx sdk.Context) []types.SendEn // if !found { // sendEnabled = DefaultSendEnabled // } -func (k BaseSendKeeper) getSendEnabled(store sdk.KVStore, denom string) (bool, bool) { +func (k BaseSendKeeper) getSendEnabled(store storetypes.KVStore, denom string) (bool, bool) { key := types.CreateSendEnabledKey(denom) if !store.Has(key) { return false, false @@ -512,7 +512,7 @@ func (k BaseSendKeeper) getSendEnabled(store sdk.KVStore, denom string) (bool, b // getSendEnabledOrDefault gets the SendEnabled value for a denom. If it's not // in the store, this will return defaultVal. -func (k BaseSendKeeper) getSendEnabledOrDefault(store sdk.KVStore, denom string, defaultVal bool) bool { +func (k BaseSendKeeper) getSendEnabledOrDefault(store storetypes.KVStore, denom string, defaultVal bool) bool { sendEnabled, found := k.getSendEnabled(store, denom) if found { return sendEnabled diff --git a/x/bank/migrations/v2/store.go b/x/bank/migrations/v2/store.go index 50042a61c0ee..1fe8575e5730 100644 --- a/x/bank/migrations/v2/store.go +++ b/x/bank/migrations/v2/store.go @@ -15,7 +15,7 @@ import ( // migrateSupply migrates the supply to be stored by denom key instead in a // single blob. // ref: https://github.com/cosmos/cosmos-sdk/issues/7092 -func migrateSupply(store sdk.KVStore, cdc codec.BinaryCodec) error { +func migrateSupply(store storetypes.KVStore, cdc codec.BinaryCodec) error { // Old supply was stored as a single blob under the SupplyKey. var oldSupplyI v1.SupplyI err := cdc.UnmarshalInterface(store.Get(v1.SupplyKey), &oldSupplyI) @@ -51,7 +51,7 @@ func migrateSupply(store sdk.KVStore, cdc codec.BinaryCodec) error { // migrateBalanceKeys migrate the balances keys to cater for variable-length // addresses. -func migrateBalanceKeys(store sdk.KVStore, logger log.Logger) { +func migrateBalanceKeys(store storetypes.KVStore, logger log.Logger) { // old key is of format: // prefix ("balances") || addrBytes (20 bytes) || denomBytes // new key is of format @@ -95,7 +95,7 @@ func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.Binar } // pruneZeroBalances removes the zero balance addresses from balances store. -func pruneZeroBalances(store sdk.KVStore, cdc codec.BinaryCodec) error { +func pruneZeroBalances(store storetypes.KVStore, cdc codec.BinaryCodec) error { balancesStore := prefix.NewStore(store, BalancesPrefix) iterator := balancesStore.Iterator(nil, nil) defer iterator.Close() @@ -114,7 +114,7 @@ func pruneZeroBalances(store sdk.KVStore, cdc codec.BinaryCodec) error { } // pruneZeroSupply removes zero balance denom from supply store. -func pruneZeroSupply(store sdk.KVStore) error { +func pruneZeroSupply(store storetypes.KVStore) error { supplyStore := prefix.NewStore(store, SupplyKey) iterator := supplyStore.Iterator(nil, nil) defer iterator.Close() diff --git a/x/bank/migrations/v2/store_test.go b/x/bank/migrations/v2/store_test.go index 4cb1feadf7ad..344024eba088 100644 --- a/x/bank/migrations/v2/store_test.go +++ b/x/bank/migrations/v2/store_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/require" "github.com/cosmos/cosmos-sdk/store/prefix" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" @@ -18,8 +19,8 @@ import ( func TestSupplyMigration(t *testing.T) { encCfg := moduletestutil.MakeTestEncodingConfig() - bankKey := sdk.NewKVStoreKey("bank") - ctx := testutil.DefaultContext(bankKey, sdk.NewTransientStoreKey("transient_test")) + bankKey := storetypes.NewKVStoreKey("bank") + ctx := testutil.DefaultContext(bankKey, storetypes.NewTransientStoreKey("transient_test")) store := ctx.KVStore(bankKey) v1bank.RegisterInterfaces(encCfg.InterfaceRegistry) @@ -68,8 +69,8 @@ func TestSupplyMigration(t *testing.T) { func TestBalanceKeysMigration(t *testing.T) { encCfg := moduletestutil.MakeTestEncodingConfig() - bankKey := sdk.NewKVStoreKey("bank") - ctx := testutil.DefaultContext(bankKey, sdk.NewTransientStoreKey("transient_test")) + bankKey := storetypes.NewKVStoreKey("bank") + ctx := testutil.DefaultContext(bankKey, storetypes.NewTransientStoreKey("transient_test")) store := ctx.KVStore(bankKey) _, _, addr := testdata.KeyTestPubAddr() diff --git a/x/bank/migrations/v3/store.go b/x/bank/migrations/v3/store.go index c5db8553d2b7..8baa6093a791 100644 --- a/x/bank/migrations/v3/store.go +++ b/x/bank/migrations/v3/store.go @@ -27,7 +27,7 @@ func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.Binar return migrateDenomMetadata(store, ctx.Logger()) } -func addDenomReverseIndex(store sdk.KVStore, cdc codec.BinaryCodec, logger log.Logger) error { +func addDenomReverseIndex(store storetypes.KVStore, cdc codec.BinaryCodec, logger log.Logger) error { oldBalancesStore := prefix.NewStore(store, v2.BalancesPrefix) oldBalancesIter := oldBalancesStore.Iterator(nil, nil) @@ -73,7 +73,7 @@ func addDenomReverseIndex(store sdk.KVStore, cdc codec.BinaryCodec, logger log.L return nil } -func migrateDenomMetadata(store sdk.KVStore, logger log.Logger) error { +func migrateDenomMetadata(store storetypes.KVStore, logger log.Logger) error { oldDenomMetaDataStore := prefix.NewStore(store, v2.DenomMetadataPrefix) oldDenomMetaDataIter := oldDenomMetaDataStore.Iterator(nil, nil) diff --git a/x/bank/migrations/v3/store_test.go b/x/bank/migrations/v3/store_test.go index 932547614484..02011b370ae4 100644 --- a/x/bank/migrations/v3/store_test.go +++ b/x/bank/migrations/v3/store_test.go @@ -3,11 +3,11 @@ package v3_test import ( "testing" - "github.com/stretchr/testify/require" - "cosmossdk.io/math" + "github.com/stretchr/testify/require" "github.com/cosmos/cosmos-sdk/store/prefix" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/address" @@ -19,8 +19,8 @@ import ( func TestMigrateStore(t *testing.T) { encCfg := moduletestutil.MakeTestEncodingConfig() - bankKey := sdk.NewKVStoreKey("bank") - ctx := testutil.DefaultContext(bankKey, sdk.NewTransientStoreKey("transient_test")) + bankKey := storetypes.NewKVStoreKey("bank") + ctx := testutil.DefaultContext(bankKey, storetypes.NewTransientStoreKey("transient_test")) store := ctx.KVStore(bankKey) addr := sdk.AccAddress([]byte("addr________________")) @@ -57,8 +57,8 @@ func TestMigrateStore(t *testing.T) { func TestMigrateDenomMetaData(t *testing.T) { encCfg := moduletestutil.MakeTestEncodingConfig() - bankKey := sdk.NewKVStoreKey("bank") - ctx := testutil.DefaultContext(bankKey, sdk.NewTransientStoreKey("transient_test")) + bankKey := storetypes.NewKVStoreKey("bank") + ctx := testutil.DefaultContext(bankKey, storetypes.NewTransientStoreKey("transient_test")) store := ctx.KVStore(bankKey) metaData := []types.Metadata{ { diff --git a/x/bank/migrations/v4/store_test.go b/x/bank/migrations/v4/store_test.go index b9d2c035c25b..84da6c6dd184 100644 --- a/x/bank/migrations/v4/store_test.go +++ b/x/bank/migrations/v4/store_test.go @@ -3,6 +3,7 @@ package v4_test import ( "testing" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -29,8 +30,8 @@ func TestMigrate(t *testing.T) { encCfg := moduletestutil.MakeTestEncodingConfig(bank.AppModuleBasic{}) cdc := encCfg.Codec - storeKey := sdk.NewKVStoreKey(v4.ModuleName) - tKey := sdk.NewTransientStoreKey("transient_test") + storeKey := storetypes.NewKVStoreKey(v4.ModuleName) + tKey := storetypes.NewTransientStoreKey("transient_test") ctx := testutil.DefaultContext(storeKey, tKey) store := ctx.KVStore(storeKey) diff --git a/x/bank/module.go b/x/bank/module.go index 1cd522fa0882..f633ae40ecaf 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -188,7 +188,7 @@ func (AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedP } // RegisterStoreDecoder registers a decoder for supply module's types -func (am AppModule) RegisterStoreDecoder(_ sdk.StoreDecoderRegistry) {} +func (am AppModule) RegisterStoreDecoder(_ store.StoreDecoderRegistry) {} // WeightedOperations returns the all the gov module operations with their respective weights. func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { diff --git a/x/bank/types/send_authorization_test.go b/x/bank/types/send_authorization_test.go index 6ee517769c76..f32e3a465ea8 100644 --- a/x/bank/types/send_authorization_test.go +++ b/x/bank/types/send_authorization_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/require" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/bank/types" @@ -21,7 +22,7 @@ var ( ) func TestSendAuthorization(t *testing.T) { - ctx := testutil.DefaultContextWithDB(t, sdk.NewKVStoreKey(types.StoreKey), sdk.NewTransientStoreKey("transient_test")).Ctx.WithBlockHeader(tmproto.Header{}) + ctx := testutil.DefaultContextWithDB(t, storetypes.NewKVStoreKey(types.StoreKey), storetypes.NewTransientStoreKey("transient_test")).Ctx.WithBlockHeader(tmproto.Header{}) allowList := make([]sdk.AccAddress, 1) allowList[0] = toAddr authorization := types.NewSendAuthorization(coins1000, nil) diff --git a/x/capability/capability_test.go b/x/capability/capability_test.go index e2789ae589e5..c28ba74b2d2e 100644 --- a/x/capability/capability_test.go +++ b/x/capability/capability_test.go @@ -68,7 +68,7 @@ func (suite *CapabilityTestSuite) TestInitializeMemStore() { suite.Require().False(newKeeper.IsInitialized(ctx), "memstore initialized flag set before BeginBlock") // Mock app beginblock and ensure that no gas has been consumed and memstore is initialized - ctx = suite.app.BaseApp.NewContext(false, tmproto.Header{}).WithBlockGasMeter(sdk.NewGasMeter(50)) + ctx = suite.app.BaseApp.NewContext(false, tmproto.Header{}).WithBlockGasMeter(storetypes.NewGasMeter(50)) prevGas := ctx.BlockGasMeter().GasConsumed() restartedModule := capability.NewAppModule(suite.cdc, *newKeeper, true) restartedModule.BeginBlock(ctx, abci.RequestBeginBlock{}) diff --git a/x/capability/genesis_test.go b/x/capability/genesis_test.go index 00009fd94414..486388561ab2 100644 --- a/x/capability/genesis_test.go +++ b/x/capability/genesis_test.go @@ -3,8 +3,8 @@ package capability_test import ( tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" - sdk "github.com/cosmos/cosmos-sdk/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/capability" "github.com/cosmos/cosmos-sdk/x/capability/keeper" @@ -37,7 +37,7 @@ func (suite *CapabilityTestSuite) TestGenesis() { newSk1 := newKeeper.ScopeToModule(banktypes.ModuleName) newSk2 := newKeeper.ScopeToModule(stakingtypes.ModuleName) - deliverCtx, _ := newApp.BaseApp.NewUncachedContext(false, tmproto.Header{}).WithBlockGasMeter(sdk.NewInfiniteGasMeter()).CacheContext() + deliverCtx, _ := newApp.BaseApp.NewUncachedContext(false, tmproto.Header{}).WithBlockGasMeter(storetypes.NewInfiniteGasMeter()).CacheContext() capability.InitGenesis(deliverCtx, *newKeeper, *genState) diff --git a/x/capability/keeper/keeper.go b/x/capability/keeper/keeper.go index fe791d53ffc8..06fd1bacfe56 100644 --- a/x/capability/keeper/keeper.go +++ b/x/capability/keeper/keeper.go @@ -119,12 +119,12 @@ func (k *Keeper) InitMemStore(ctx sdk.Context) { } // create context with no block gas meter to ensure we do not consume gas during local initialization logic. - noGasCtx := ctx.WithBlockGasMeter(sdk.NewInfiniteGasMeter()) + noGasCtx := ctx.WithBlockGasMeter(storetypes.NewInfiniteGasMeter()) // check if memory store has not been initialized yet by checking if initialized flag is nil. if !k.IsInitialized(noGasCtx) { prefixStore := prefix.NewStore(noGasCtx.KVStore(k.storeKey), types.KeyPrefixIndexCapability) - iterator := sdk.KVStorePrefixIterator(prefixStore, nil) + iterator := storetypes.KVStorePrefixIterator(prefixStore, nil) // initialize the in-memory store for all persisted capabilities defer iterator.Close() diff --git a/x/capability/keeper/keeper_test.go b/x/capability/keeper/keeper_test.go index db948e642a34..7269fc897978 100644 --- a/x/capability/keeper/keeper_test.go +++ b/x/capability/keeper/keeper_test.go @@ -6,6 +6,7 @@ import ( "github.com/stretchr/testify/suite" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -27,8 +28,8 @@ type KeeperTestSuite struct { } func (suite *KeeperTestSuite) SetupTest() { - key := sdk.NewKVStoreKey(types.StoreKey) - testCtx := testutil.DefaultContextWithDB(suite.T(), key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(types.StoreKey) + testCtx := testutil.DefaultContextWithDB(suite.T(), key, storetypes.NewTransientStoreKey("transient_test")) suite.ctx = testCtx.Ctx encCfg := moduletestutil.MakeTestEncodingConfig(capability.AppModuleBasic{}) suite.keeper = keeper.NewKeeper(encCfg.Codec, key, key) diff --git a/x/capability/module.go b/x/capability/module.go index b6cfda874b6d..99cd79e38d64 100644 --- a/x/capability/module.go +++ b/x/capability/module.go @@ -168,7 +168,7 @@ func (am AppModule) ProposalContents(simState module.SimulationState) []simtypes } // RegisterStoreDecoder registers a decoder for capability module's types -func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { +func (am AppModule) RegisterStoreDecoder(sdr store.StoreDecoderRegistry) { sdr[types.StoreKey] = simulation.NewDecodeStore(am.cdc) } diff --git a/x/consensus/keeper/keeper_test.go b/x/consensus/keeper/keeper_test.go index 1cb94f24fa8e..211fb7905cc2 100644 --- a/x/consensus/keeper/keeper_test.go +++ b/x/consensus/keeper/keeper_test.go @@ -7,6 +7,7 @@ import ( tmproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/baseapp" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -26,8 +27,8 @@ type KeeperTestSuite struct { } func (s *KeeperTestSuite) SetupTest() { - key := sdk.NewKVStoreKey(consensusparamtypes.StoreKey) - testCtx := testutil.DefaultContextWithDB(s.T(), key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(consensusparamtypes.StoreKey) + testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) ctx := testCtx.Ctx.WithBlockHeader(tmproto.Header{}) encCfg := moduletestutil.MakeTestEncodingConfig() diff --git a/x/crisis/keeper/genesis_test.go b/x/crisis/keeper/genesis_test.go index 5a85b11afadf..bb832a7b16d0 100644 --- a/x/crisis/keeper/genesis_test.go +++ b/x/crisis/keeper/genesis_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/suite" "github.com/cosmos/cosmos-sdk/codec" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -29,8 +30,8 @@ func TestGenesisTestSuite(t *testing.T) { } func (s *GenesisTestSuite) SetupTest() { - key := sdk.NewKVStoreKey(types.StoreKey) - testCtx := testutil.DefaultContextWithDB(s.T(), key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(types.StoreKey) + testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(crisis.AppModuleBasic{}) // gomock initializations diff --git a/x/crisis/keeper/keeper_test.go b/x/crisis/keeper/keeper_test.go index ecfa81967b62..314ad00fcc00 100644 --- a/x/crisis/keeper/keeper_test.go +++ b/x/crisis/keeper/keeper_test.go @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -19,8 +20,8 @@ func TestLogger(t *testing.T) { ctrl := gomock.NewController(t) supplyKeeper := crisistestutil.NewMockSupplyKeeper(ctrl) - key := sdk.NewKVStoreKey(types.StoreKey) - testCtx := testutil.DefaultContextWithDB(t, key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(types.StoreKey) + testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(crisis.AppModuleBasic{}) keeper := keeper.NewKeeper(encCfg.Codec, key, 5, supplyKeeper, "", "") @@ -33,7 +34,7 @@ func TestInvariants(t *testing.T) { ctrl := gomock.NewController(t) supplyKeeper := crisistestutil.NewMockSupplyKeeper(ctrl) - key := sdk.NewKVStoreKey(types.StoreKey) + key := storetypes.NewKVStoreKey(types.StoreKey) encCfg := moduletestutil.MakeTestEncodingConfig(crisis.AppModuleBasic{}) keeper := keeper.NewKeeper(encCfg.Codec, key, 5, supplyKeeper, "", "") require.Equal(t, keeper.InvCheckPeriod(), uint(5)) @@ -48,8 +49,8 @@ func TestAssertInvariants(t *testing.T) { ctrl := gomock.NewController(t) supplyKeeper := crisistestutil.NewMockSupplyKeeper(ctrl) - key := sdk.NewKVStoreKey(types.StoreKey) - testCtx := testutil.DefaultContextWithDB(t, key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(types.StoreKey) + testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(crisis.AppModuleBasic{}) keeper := keeper.NewKeeper(encCfg.Codec, key, 5, supplyKeeper, "", "") diff --git a/x/crisis/keeper/msg_server_test.go b/x/crisis/keeper/msg_server_test.go index 07f4f5f61fa9..15c37897f276 100644 --- a/x/crisis/keeper/msg_server_test.go +++ b/x/crisis/keeper/msg_server_test.go @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/suite" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -28,8 +29,8 @@ func (s *KeeperTestSuite) SetupTest() { ctrl := gomock.NewController(s.T()) supplyKeeper := crisistestutil.NewMockSupplyKeeper(ctrl) - key := sdk.NewKVStoreKey(types.StoreKey) - testCtx := testutil.DefaultContextWithDB(s.T(), key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(types.StoreKey) + testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(crisis.AppModuleBasic{}) keeper := keeper.NewKeeper(encCfg.Codec, key, 5, supplyKeeper, "", "") diff --git a/x/crisis/migrations/v2/migrate_test.go b/x/crisis/migrations/v2/migrate_test.go index 40bf8885591c..ffb9609f6655 100644 --- a/x/crisis/migrations/v2/migrate_test.go +++ b/x/crisis/migrations/v2/migrate_test.go @@ -5,6 +5,7 @@ import ( "github.com/stretchr/testify/require" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -27,8 +28,8 @@ func (ms mockSubspace) Get(ctx sdk.Context, key []byte, ptr interface{}) { func TestMigrate(t *testing.T) { cdc := moduletestutil.MakeTestEncodingConfig(crisis.AppModuleBasic{}).Codec - storeKey := sdk.NewKVStoreKey(v2.ModuleName) - tKey := sdk.NewTransientStoreKey("transient_test") + storeKey := storetypes.NewKVStoreKey(v2.ModuleName) + tKey := storetypes.NewTransientStoreKey("transient_test") ctx := testutil.DefaultContext(storeKey, tKey) store := ctx.KVStore(storeKey) diff --git a/x/distribution/keeper/allocation_test.go b/x/distribution/keeper/allocation_test.go index a747ce98ccb9..faffe33b4e1c 100644 --- a/x/distribution/keeper/allocation_test.go +++ b/x/distribution/keeper/allocation_test.go @@ -10,6 +10,7 @@ import ( abci "github.com/tendermint/tendermint/abci/types" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -23,8 +24,8 @@ import ( func TestAllocateTokensToValidatorWithCommission(t *testing.T) { ctrl := gomock.NewController(t) - key := sdk.NewKVStoreKey(disttypes.StoreKey) - testCtx := testutil.DefaultContextWithDB(t, key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(disttypes.StoreKey) + testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}) ctx := testCtx.Ctx.WithBlockHeader(tmproto.Header{Time: time.Now()}) @@ -68,8 +69,8 @@ func TestAllocateTokensToValidatorWithCommission(t *testing.T) { func TestAllocateTokensToManyValidators(t *testing.T) { ctrl := gomock.NewController(t) - key := sdk.NewKVStoreKey(disttypes.StoreKey) - testCtx := testutil.DefaultContextWithDB(t, key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(disttypes.StoreKey) + testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}) ctx := testCtx.Ctx.WithBlockHeader(tmproto.Header{Time: time.Now()}) @@ -166,8 +167,8 @@ func TestAllocateTokensToManyValidators(t *testing.T) { func TestAllocateTokensTruncation(t *testing.T) { ctrl := gomock.NewController(t) - key := sdk.NewKVStoreKey(disttypes.StoreKey) - testCtx := testutil.DefaultContextWithDB(t, key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(disttypes.StoreKey) + testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}) ctx := testCtx.Ctx.WithBlockHeader(tmproto.Header{Time: time.Now()}) diff --git a/x/distribution/keeper/delegation_test.go b/x/distribution/keeper/delegation_test.go index f31bb371466e..3d4b09dfd13a 100644 --- a/x/distribution/keeper/delegation_test.go +++ b/x/distribution/keeper/delegation_test.go @@ -8,7 +8,7 @@ import ( tmproto "github.com/tendermint/tendermint/proto/tendermint/types" "cosmossdk.io/math" - + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -22,8 +22,8 @@ import ( func TestCalculateRewardsBasic(t *testing.T) { ctrl := gomock.NewController(t) - key := sdk.NewKVStoreKey(disttypes.StoreKey) - testCtx := testutil.DefaultContextWithDB(t, key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(disttypes.StoreKey) + testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}) ctx := testCtx.Ctx.WithBlockHeader(tmproto.Header{Height: 1}) @@ -100,8 +100,8 @@ func TestCalculateRewardsBasic(t *testing.T) { func TestCalculateRewardsAfterSlash(t *testing.T) { ctrl := gomock.NewController(t) - key := sdk.NewKVStoreKey(disttypes.StoreKey) - testCtx := testutil.DefaultContextWithDB(t, key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(disttypes.StoreKey) + testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}) ctx := testCtx.Ctx.WithBlockHeader(tmproto.Header{Height: 1}) @@ -195,8 +195,8 @@ func TestCalculateRewardsAfterSlash(t *testing.T) { func TestCalculateRewardsAfterManySlashes(t *testing.T) { ctrl := gomock.NewController(t) - key := sdk.NewKVStoreKey(disttypes.StoreKey) - testCtx := testutil.DefaultContextWithDB(t, key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(disttypes.StoreKey) + testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}) ctx := testCtx.Ctx.WithBlockHeader(tmproto.Header{Height: 1}) @@ -310,8 +310,8 @@ func TestCalculateRewardsAfterManySlashes(t *testing.T) { func TestCalculateRewardsMultiDelegator(t *testing.T) { ctrl := gomock.NewController(t) - key := sdk.NewKVStoreKey(disttypes.StoreKey) - testCtx := testutil.DefaultContextWithDB(t, key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(disttypes.StoreKey) + testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}) ctx := testCtx.Ctx.WithBlockHeader(tmproto.Header{Height: 1}) @@ -400,8 +400,8 @@ func TestCalculateRewardsMultiDelegator(t *testing.T) { func TestWithdrawDelegationRewardsBasic(t *testing.T) { ctrl := gomock.NewController(t) - key := sdk.NewKVStoreKey(disttypes.StoreKey) - testCtx := testutil.DefaultContextWithDB(t, key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(disttypes.StoreKey) + testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}) ctx := testCtx.Ctx.WithBlockHeader(tmproto.Header{Height: 1}) @@ -472,8 +472,8 @@ func TestWithdrawDelegationRewardsBasic(t *testing.T) { func TestCalculateRewardsAfterManySlashesInSameBlock(t *testing.T) { ctrl := gomock.NewController(t) - key := sdk.NewKVStoreKey(disttypes.StoreKey) - testCtx := testutil.DefaultContextWithDB(t, key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(disttypes.StoreKey) + testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}) ctx := testCtx.Ctx.WithBlockHeader(tmproto.Header{Height: 1}) @@ -579,8 +579,8 @@ func TestCalculateRewardsAfterManySlashesInSameBlock(t *testing.T) { func TestCalculateRewardsMultiDelegatorMultiSlash(t *testing.T) { ctrl := gomock.NewController(t) - key := sdk.NewKVStoreKey(disttypes.StoreKey) - testCtx := testutil.DefaultContextWithDB(t, key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(disttypes.StoreKey) + testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}) ctx := testCtx.Ctx.WithBlockHeader(tmproto.Header{Height: 1}) @@ -706,8 +706,8 @@ func TestCalculateRewardsMultiDelegatorMultiSlash(t *testing.T) { func TestCalculateRewardsMultiDelegatorMultWithdraw(t *testing.T) { ctrl := gomock.NewController(t) - key := sdk.NewKVStoreKey(disttypes.StoreKey) - testCtx := testutil.DefaultContextWithDB(t, key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(disttypes.StoreKey) + testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}) ctx := testCtx.Ctx.WithBlockHeader(tmproto.Header{Height: 1}) @@ -889,8 +889,8 @@ func TestCalculateRewardsMultiDelegatorMultWithdraw(t *testing.T) { func Test100PercentCommissionReward(t *testing.T) { ctrl := gomock.NewController(t) - key := sdk.NewKVStoreKey(disttypes.StoreKey) - testCtx := testutil.DefaultContextWithDB(t, key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(disttypes.StoreKey) + testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}) ctx := testCtx.Ctx.WithBlockHeader(tmproto.Header{Height: 1}) diff --git a/x/distribution/keeper/keeper_test.go b/x/distribution/keeper/keeper_test.go index 18d1870d0a45..95e9ff2c7781 100644 --- a/x/distribution/keeper/keeper_test.go +++ b/x/distribution/keeper/keeper_test.go @@ -9,6 +9,7 @@ import ( "github.com/stretchr/testify/require" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" @@ -22,8 +23,8 @@ import ( func TestSetWithdrawAddr(t *testing.T) { ctrl := gomock.NewController(t) - key := sdk.NewKVStoreKey(types.StoreKey) - testCtx := testutil.DefaultContextWithDB(t, key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(types.StoreKey) + testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}) ctx := testCtx.Ctx.WithBlockHeader(tmproto.Header{Time: time.Now()}) addrs := simtestutil.CreateIncrementalAccounts(2) @@ -68,8 +69,8 @@ func TestSetWithdrawAddr(t *testing.T) { func TestWithdrawValidatorCommission(t *testing.T) { ctrl := gomock.NewController(t) - key := sdk.NewKVStoreKey(types.StoreKey) - testCtx := testutil.DefaultContextWithDB(t, key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(types.StoreKey) + testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}) ctx := testCtx.Ctx.WithBlockHeader(tmproto.Header{Time: time.Now()}) addrs := simtestutil.CreateIncrementalAccounts(1) @@ -123,8 +124,8 @@ func TestWithdrawValidatorCommission(t *testing.T) { func TestGetTotalRewards(t *testing.T) { ctrl := gomock.NewController(t) - key := sdk.NewKVStoreKey(types.StoreKey) - testCtx := testutil.DefaultContextWithDB(t, key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(types.StoreKey) + testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}) ctx := testCtx.Ctx.WithBlockHeader(tmproto.Header{Time: time.Now()}) addrs := simtestutil.CreateIncrementalAccounts(2) @@ -164,8 +165,8 @@ func TestGetTotalRewards(t *testing.T) { func TestFundCommunityPool(t *testing.T) { ctrl := gomock.NewController(t) - key := sdk.NewKVStoreKey(types.StoreKey) - testCtx := testutil.DefaultContextWithDB(t, key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(types.StoreKey) + testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}) ctx := testCtx.Ctx.WithBlockHeader(tmproto.Header{Time: time.Now()}) addrs := simtestutil.CreateIncrementalAccounts(1) diff --git a/x/distribution/keeper/params_test.go b/x/distribution/keeper/params_test.go index af4b40b68740..5f4a65032c12 100644 --- a/x/distribution/keeper/params_test.go +++ b/x/distribution/keeper/params_test.go @@ -3,6 +3,7 @@ package keeper_test import ( "testing" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -18,8 +19,8 @@ import ( func TestParams(t *testing.T) { ctrl := gomock.NewController(t) - key := sdk.NewKVStoreKey(types.StoreKey) - testCtx := testutil.DefaultContextWithDB(t, key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(types.StoreKey) + testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}) ctx := testCtx.Ctx.WithBlockHeader(tmproto.Header{Height: 1}) diff --git a/x/distribution/keeper/store.go b/x/distribution/keeper/store.go index 940d92c6e84a..b8c897d155de 100644 --- a/x/distribution/keeper/store.go +++ b/x/distribution/keeper/store.go @@ -3,6 +3,7 @@ package keeper import ( gogotypes "github.com/cosmos/gogoproto/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/distribution/types" ) @@ -32,7 +33,7 @@ func (k Keeper) DeleteDelegatorWithdrawAddr(ctx sdk.Context, delAddr, withdrawAd // iterate over delegator withdraw addrs func (k Keeper) IterateDelegatorWithdrawAddrs(ctx sdk.Context, handler func(del sdk.AccAddress, addr sdk.AccAddress) (stop bool)) { store := ctx.KVStore(k.storeKey) - iter := sdk.KVStorePrefixIterator(store, types.DelegatorWithdrawAddrPrefix) + iter := storetypes.KVStorePrefixIterator(store, types.DelegatorWithdrawAddrPrefix) defer iter.Close() for ; iter.Valid(); iter.Next() { addr := sdk.AccAddress(iter.Value()) @@ -112,7 +113,7 @@ func (k Keeper) DeleteDelegatorStartingInfo(ctx sdk.Context, val sdk.ValAddress, // iterate over delegator starting infos func (k Keeper) IterateDelegatorStartingInfos(ctx sdk.Context, handler func(val sdk.ValAddress, del sdk.AccAddress, info types.DelegatorStartingInfo) (stop bool)) { store := ctx.KVStore(k.storeKey) - iter := sdk.KVStorePrefixIterator(store, types.DelegatorStartingInfoPrefix) + iter := storetypes.KVStorePrefixIterator(store, types.DelegatorStartingInfoPrefix) defer iter.Close() for ; iter.Valid(); iter.Next() { var info types.DelegatorStartingInfo @@ -142,7 +143,7 @@ func (k Keeper) SetValidatorHistoricalRewards(ctx sdk.Context, val sdk.ValAddres // iterate over historical rewards func (k Keeper) IterateValidatorHistoricalRewards(ctx sdk.Context, handler func(val sdk.ValAddress, period uint64, rewards types.ValidatorHistoricalRewards) (stop bool)) { store := ctx.KVStore(k.storeKey) - iter := sdk.KVStorePrefixIterator(store, types.ValidatorHistoricalRewardsPrefix) + iter := storetypes.KVStorePrefixIterator(store, types.ValidatorHistoricalRewardsPrefix) defer iter.Close() for ; iter.Valid(); iter.Next() { var rewards types.ValidatorHistoricalRewards @@ -163,7 +164,7 @@ func (k Keeper) DeleteValidatorHistoricalReward(ctx sdk.Context, val sdk.ValAddr // delete historical rewards for a validator func (k Keeper) DeleteValidatorHistoricalRewards(ctx sdk.Context, val sdk.ValAddress) { store := ctx.KVStore(k.storeKey) - iter := sdk.KVStorePrefixIterator(store, types.GetValidatorHistoricalRewardsPrefix(val)) + iter := storetypes.KVStorePrefixIterator(store, types.GetValidatorHistoricalRewardsPrefix(val)) defer iter.Close() for ; iter.Valid(); iter.Next() { store.Delete(iter.Key()) @@ -173,7 +174,7 @@ func (k Keeper) DeleteValidatorHistoricalRewards(ctx sdk.Context, val sdk.ValAdd // delete all historical rewards func (k Keeper) DeleteAllValidatorHistoricalRewards(ctx sdk.Context) { store := ctx.KVStore(k.storeKey) - iter := sdk.KVStorePrefixIterator(store, types.ValidatorHistoricalRewardsPrefix) + iter := storetypes.KVStorePrefixIterator(store, types.ValidatorHistoricalRewardsPrefix) defer iter.Close() for ; iter.Valid(); iter.Next() { store.Delete(iter.Key()) @@ -183,7 +184,7 @@ func (k Keeper) DeleteAllValidatorHistoricalRewards(ctx sdk.Context) { // historical reference count (used for testcases) func (k Keeper) GetValidatorHistoricalReferenceCount(ctx sdk.Context) (count uint64) { store := ctx.KVStore(k.storeKey) - iter := sdk.KVStorePrefixIterator(store, types.ValidatorHistoricalRewardsPrefix) + iter := storetypes.KVStorePrefixIterator(store, types.ValidatorHistoricalRewardsPrefix) defer iter.Close() for ; iter.Valid(); iter.Next() { var rewards types.ValidatorHistoricalRewards @@ -217,7 +218,7 @@ func (k Keeper) DeleteValidatorCurrentRewards(ctx sdk.Context, val sdk.ValAddres // iterate over current rewards func (k Keeper) IterateValidatorCurrentRewards(ctx sdk.Context, handler func(val sdk.ValAddress, rewards types.ValidatorCurrentRewards) (stop bool)) { store := ctx.KVStore(k.storeKey) - iter := sdk.KVStorePrefixIterator(store, types.ValidatorCurrentRewardsPrefix) + iter := storetypes.KVStorePrefixIterator(store, types.ValidatorCurrentRewardsPrefix) defer iter.Close() for ; iter.Valid(); iter.Next() { var rewards types.ValidatorCurrentRewards @@ -263,7 +264,7 @@ func (k Keeper) DeleteValidatorAccumulatedCommission(ctx sdk.Context, val sdk.Va // iterate over accumulated commissions func (k Keeper) IterateValidatorAccumulatedCommissions(ctx sdk.Context, handler func(val sdk.ValAddress, commission types.ValidatorAccumulatedCommission) (stop bool)) { store := ctx.KVStore(k.storeKey) - iter := sdk.KVStorePrefixIterator(store, types.ValidatorAccumulatedCommissionPrefix) + iter := storetypes.KVStorePrefixIterator(store, types.ValidatorAccumulatedCommissionPrefix) defer iter.Close() for ; iter.Valid(); iter.Next() { var commission types.ValidatorAccumulatedCommission @@ -299,7 +300,7 @@ func (k Keeper) DeleteValidatorOutstandingRewards(ctx sdk.Context, val sdk.ValAd // iterate validator outstanding rewards func (k Keeper) IterateValidatorOutstandingRewards(ctx sdk.Context, handler func(val sdk.ValAddress, rewards types.ValidatorOutstandingRewards) (stop bool)) { store := ctx.KVStore(k.storeKey) - iter := sdk.KVStorePrefixIterator(store, types.ValidatorOutstandingRewardsPrefix) + iter := storetypes.KVStorePrefixIterator(store, types.ValidatorOutstandingRewardsPrefix) defer iter.Close() for ; iter.Valid(); iter.Next() { rewards := types.ValidatorOutstandingRewards{} @@ -352,7 +353,7 @@ func (k Keeper) IterateValidatorSlashEventsBetween(ctx sdk.Context, val sdk.ValA // iterate over all slash events func (k Keeper) IterateValidatorSlashEvents(ctx sdk.Context, handler func(val sdk.ValAddress, height uint64, event types.ValidatorSlashEvent) (stop bool)) { store := ctx.KVStore(k.storeKey) - iter := sdk.KVStorePrefixIterator(store, types.ValidatorSlashEventPrefix) + iter := storetypes.KVStorePrefixIterator(store, types.ValidatorSlashEventPrefix) defer iter.Close() for ; iter.Valid(); iter.Next() { var event types.ValidatorSlashEvent @@ -367,7 +368,7 @@ func (k Keeper) IterateValidatorSlashEvents(ctx sdk.Context, handler func(val sd // delete slash events for a particular validator func (k Keeper) DeleteValidatorSlashEvents(ctx sdk.Context, val sdk.ValAddress) { store := ctx.KVStore(k.storeKey) - iter := sdk.KVStorePrefixIterator(store, types.GetValidatorSlashEventPrefix(val)) + iter := storetypes.KVStorePrefixIterator(store, types.GetValidatorSlashEventPrefix(val)) defer iter.Close() for ; iter.Valid(); iter.Next() { store.Delete(iter.Key()) @@ -377,7 +378,7 @@ func (k Keeper) DeleteValidatorSlashEvents(ctx sdk.Context, val sdk.ValAddress) // delete all slash events func (k Keeper) DeleteAllValidatorSlashEvents(ctx sdk.Context) { store := ctx.KVStore(k.storeKey) - iter := sdk.KVStorePrefixIterator(store, types.ValidatorSlashEventPrefix) + iter := storetypes.KVStorePrefixIterator(store, types.ValidatorSlashEventPrefix) defer iter.Close() for ; iter.Valid(); iter.Next() { store.Delete(iter.Key()) diff --git a/x/distribution/migrations/v2/helpers.go b/x/distribution/migrations/v2/helpers.go index fb9ccfbe73d6..91c8ab0c6ab4 100644 --- a/x/distribution/migrations/v2/helpers.go +++ b/x/distribution/migrations/v2/helpers.go @@ -2,7 +2,7 @@ package v2 import ( "github.com/cosmos/cosmos-sdk/store/prefix" - sdk "github.com/cosmos/cosmos-sdk/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/types/address" v1auth "github.com/cosmos/cosmos-sdk/x/auth/migrations/v1" ) @@ -11,7 +11,7 @@ import ( // prefix_bytes | address_bytes // into format: // prefix_bytes | address_len (1 byte) | address_bytes -func MigratePrefixAddress(store sdk.KVStore, prefixBz []byte) { +func MigratePrefixAddress(store storetypes.KVStore, prefixBz []byte) { oldStore := prefix.NewStore(store, prefixBz) oldStoreIter := oldStore.Iterator(nil, nil) @@ -32,7 +32,7 @@ func MigratePrefixAddress(store sdk.KVStore, prefixBz []byte) { // prefix_bytes | address_bytes | arbitrary_bytes // into format: // prefix_bytes | address_len (1 byte) | address_bytes | arbitrary_bytes -func MigratePrefixAddressBytes(store sdk.KVStore, prefixBz []byte) { +func MigratePrefixAddressBytes(store storetypes.KVStore, prefixBz []byte) { oldStore := prefix.NewStore(store, prefixBz) oldStoreIter := oldStore.Iterator(nil, nil) @@ -53,7 +53,7 @@ func MigratePrefixAddressBytes(store sdk.KVStore, prefixBz []byte) { // prefix_bytes | address_1_bytes | address_2_bytes // into format: // prefix_bytes | address_1_len (1 byte) | address_1_bytes | address_2_len (1 byte) | address_2_bytes -func MigratePrefixAddressAddress(store sdk.KVStore, prefixBz []byte) { +func MigratePrefixAddressAddress(store storetypes.KVStore, prefixBz []byte) { oldStore := prefix.NewStore(store, prefixBz) oldStoreIter := oldStore.Iterator(nil, nil) diff --git a/x/distribution/migrations/v2/store_test.go b/x/distribution/migrations/v2/store_test.go index b67d194842c4..2931709206e7 100644 --- a/x/distribution/migrations/v2/store_test.go +++ b/x/distribution/migrations/v2/store_test.go @@ -6,6 +6,7 @@ import ( "github.com/stretchr/testify/require" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" @@ -15,8 +16,8 @@ import ( ) func TestStoreMigration(t *testing.T) { - distributionKey := sdk.NewKVStoreKey("distribution") - ctx := testutil.DefaultContext(distributionKey, sdk.NewTransientStoreKey("transient_test")) + distributionKey := storetypes.NewKVStoreKey("distribution") + ctx := testutil.DefaultContext(distributionKey, storetypes.NewTransientStoreKey("transient_test")) store := ctx.KVStore(distributionKey) _, _, addr1 := testdata.KeyTestPubAddr() diff --git a/x/distribution/migrations/v3/migrate_test.go b/x/distribution/migrations/v3/migrate_test.go index 3a485ebf2d7d..0b92a0d59a44 100644 --- a/x/distribution/migrations/v3/migrate_test.go +++ b/x/distribution/migrations/v3/migrate_test.go @@ -5,6 +5,7 @@ import ( "github.com/stretchr/testify/require" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -28,8 +29,8 @@ func (ms mockSubspace) GetParamSet(ctx sdk.Context, ps exported.ParamSet) { func TestMigrate(t *testing.T) { cdc := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}).Codec - storeKey := sdk.NewKVStoreKey(v3.ModuleName) - tKey := sdk.NewTransientStoreKey("transient_test") + storeKey := storetypes.NewKVStoreKey(v3.ModuleName) + tKey := storetypes.NewTransientStoreKey("transient_test") ctx := testutil.DefaultContext(storeKey, tKey) store := ctx.KVStore(storeKey) diff --git a/x/distribution/module.go b/x/distribution/module.go index 432e3a851f91..2514ef9714ba 100644 --- a/x/distribution/module.go +++ b/x/distribution/module.go @@ -191,7 +191,7 @@ func (am AppModule) ProposalContents(simState module.SimulationState) []simtypes } // RegisterStoreDecoder registers a decoder for distribution module's types -func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { +func (am AppModule) RegisterStoreDecoder(sdr store.StoreDecoderRegistry) { sdr[types.StoreKey] = simulation.NewDecodeStore(am.cdc) } diff --git a/x/evidence/keeper/keeper.go b/x/evidence/keeper/keeper.go index 7f374b094e9f..2def7b896d52 100644 --- a/x/evidence/keeper/keeper.go +++ b/x/evidence/keeper/keeper.go @@ -124,7 +124,7 @@ func (k Keeper) GetEvidence(ctx sdk.Context, hash tmbytes.HexBytes) (exported.Ev // will close and stop. func (k Keeper) IterateEvidence(ctx sdk.Context, cb func(exported.Evidence) bool) { store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixEvidence) - iterator := sdk.KVStorePrefixIterator(store, nil) + iterator := storetypes.KVStorePrefixIterator(store, nil) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { diff --git a/x/evidence/keeper/keeper_test.go b/x/evidence/keeper/keeper_test.go index d66d5c02850a..5d7bf3a9fdb7 100644 --- a/x/evidence/keeper/keeper_test.go +++ b/x/evidence/keeper/keeper_test.go @@ -12,6 +12,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -82,8 +83,8 @@ type KeeperTestSuite struct { func (suite *KeeperTestSuite) SetupTest() { encCfg := moduletestutil.MakeTestEncodingConfig(evidence.AppModuleBasic{}) - key := sdk.NewKVStoreKey(types.StoreKey) - tkey := sdk.NewTransientStoreKey("evidence_transient_store") + key := storetypes.NewKVStoreKey(types.StoreKey) + tkey := storetypes.NewTransientStoreKey("evidence_transient_store") testCtx := testutil.DefaultContextWithDB(suite.T(), key, tkey) suite.ctx = testCtx.Ctx diff --git a/x/evidence/module.go b/x/evidence/module.go index d5a8c2cb0bef..8d684ddd1ce6 100644 --- a/x/evidence/module.go +++ b/x/evidence/module.go @@ -183,7 +183,7 @@ func (am AppModule) ProposalContents(simState module.SimulationState) []simtypes } // RegisterStoreDecoder registers a decoder for evidence module's types -func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { +func (am AppModule) RegisterStoreDecoder(sdr store.StoreDecoderRegistry) { sdr[types.StoreKey] = simulation.NewDecodeStore(am.keeper) } diff --git a/x/feegrant/basic_fee_test.go b/x/feegrant/basic_fee_test.go index a6c66c8ae982..e2a11d039496 100644 --- a/x/feegrant/basic_fee_test.go +++ b/x/feegrant/basic_fee_test.go @@ -8,14 +8,15 @@ import ( "github.com/stretchr/testify/require" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/feegrant" ) func TestBasicFeeValidAllow(t *testing.T) { - key := sdk.NewKVStoreKey(feegrant.StoreKey) - testCtx := testutil.DefaultContextWithDB(t, key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(feegrant.StoreKey) + testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) ctx := testCtx.Ctx.WithBlockHeader(tmproto.Header{Height: 1}) diff --git a/x/feegrant/filtered_fee_test.go b/x/feegrant/filtered_fee_test.go index 0f33cb2fd8cf..e06579f1ecb7 100644 --- a/x/feegrant/filtered_fee_test.go +++ b/x/feegrant/filtered_fee_test.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/require" ocproto "github.com/tendermint/tendermint/proto/tendermint/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -17,8 +18,8 @@ import ( ) func TestFilteredFeeValidAllow(t *testing.T) { - key := sdk.NewKVStoreKey(feegrant.StoreKey) - testCtx := testutil.DefaultContextWithDB(t, key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(feegrant.StoreKey) + testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(module.AppModuleBasic{}) ctx := testCtx.Ctx.WithBlockHeader(ocproto.Header{Time: time.Now()}) diff --git a/x/feegrant/grant_test.go b/x/feegrant/grant_test.go index 2d945c6bb73a..df9e05958684 100644 --- a/x/feegrant/grant_test.go +++ b/x/feegrant/grant_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/require" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -15,8 +16,8 @@ import ( ) func TestGrant(t *testing.T) { - key := sdk.NewKVStoreKey(feegrant.StoreKey) - testCtx := testutil.DefaultContextWithDB(t, key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(feegrant.StoreKey) + testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(module.AppModuleBasic{}) ctx := testCtx.Ctx.WithBlockHeader(tmproto.Header{Time: time.Now()}) diff --git a/x/feegrant/keeper/genesis_test.go b/x/feegrant/keeper/genesis_test.go index 9acc77f5e981..f5c0e8ec58c5 100644 --- a/x/feegrant/keeper/genesis_test.go +++ b/x/feegrant/keeper/genesis_test.go @@ -8,6 +8,7 @@ import ( codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" @@ -26,8 +27,8 @@ type GenesisTestSuite struct { } func (suite *GenesisTestSuite) SetupTest() { - key := sdk.NewKVStoreKey(feegrant.StoreKey) - testCtx := testutil.DefaultContextWithDB(suite.T(), key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(feegrant.StoreKey) + testCtx := testutil.DefaultContextWithDB(suite.T(), key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(module.AppModuleBasic{}) ctrl := gomock.NewController(suite.T()) diff --git a/x/feegrant/keeper/keeper.go b/x/feegrant/keeper/keeper.go index 5442b609682f..4f84e94b037e 100644 --- a/x/feegrant/keeper/keeper.go +++ b/x/feegrant/keeper/keeper.go @@ -6,9 +6,8 @@ import ( "github.com/tendermint/tendermint/libs/log" - storetypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/codec" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/auth/ante" @@ -183,7 +182,7 @@ func (k Keeper) getGrant(ctx sdk.Context, granter sdk.AccAddress, grantee sdk.Ac // Calling this without pagination is very expensive and only designed for export genesis func (k Keeper) IterateAllFeeAllowances(ctx sdk.Context, cb func(grant feegrant.Grant) bool) error { store := ctx.KVStore(k.storeKey) - iter := sdk.KVStorePrefixIterator(store, feegrant.FeeAllowanceKeyPrefix) + iter := storetypes.KVStorePrefixIterator(store, feegrant.FeeAllowanceKeyPrefix) defer iter.Close() stop := false @@ -293,7 +292,7 @@ func (k Keeper) addToFeeAllowanceQueue(ctx sdk.Context, grantKey []byte, exp *ti func (k Keeper) RemoveExpiredAllowances(ctx sdk.Context) { exp := ctx.BlockTime() store := ctx.KVStore(k.storeKey) - iterator := store.Iterator(feegrant.FeeAllowanceQueueKeyPrefix, sdk.InclusiveEndBytes(feegrant.AllowanceByExpTimeKey(&exp))) + iterator := store.Iterator(feegrant.FeeAllowanceQueueKeyPrefix, storetypes.InclusiveEndBytes(feegrant.AllowanceByExpTimeKey(&exp))) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { diff --git a/x/feegrant/keeper/keeper_test.go b/x/feegrant/keeper/keeper_test.go index 6daeaec04b7d..bf308dae80f4 100644 --- a/x/feegrant/keeper/keeper_test.go +++ b/x/feegrant/keeper/keeper_test.go @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/suite" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" @@ -34,8 +35,8 @@ func TestKeeperTestSuite(t *testing.T) { func (suite *KeeperTestSuite) SetupTest() { suite.addrs = simtestutil.CreateIncrementalAccounts(4) - key := sdk.NewKVStoreKey(feegrant.StoreKey) - testCtx := testutil.DefaultContextWithDB(suite.T(), key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(feegrant.StoreKey) + testCtx := testutil.DefaultContextWithDB(suite.T(), key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(module.AppModuleBasic{}) // setup gomock and initialize some globally expected executions diff --git a/x/feegrant/migrations/v2/store_test.go b/x/feegrant/migrations/v2/store_test.go index 746cf0386506..b9a713307b34 100644 --- a/x/feegrant/migrations/v2/store_test.go +++ b/x/feegrant/migrations/v2/store_test.go @@ -7,11 +7,13 @@ import ( "cosmossdk.io/depinject" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/feegrant" v2 "github.com/cosmos/cosmos-sdk/x/feegrant/migrations/v2" feegranttestutil "github.com/cosmos/cosmos-sdk/x/feegrant/testutil" + "github.com/stretchr/testify/require" ) @@ -19,8 +21,8 @@ func TestMigration(t *testing.T) { var cdc codec.Codec depinject.Inject(feegranttestutil.AppConfig, &cdc) - feegrantKey := sdk.NewKVStoreKey(v2.ModuleName) - ctx := testutil.DefaultContext(feegrantKey, sdk.NewTransientStoreKey("transient_test")) + feegrantKey := storetypes.NewKVStoreKey(v2.ModuleName) + ctx := testutil.DefaultContext(feegrantKey, storetypes.NewTransientStoreKey("transient_test")) granter1 := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address()) grantee1 := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address()) granter2 := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address()) diff --git a/x/feegrant/module/abci_test.go b/x/feegrant/module/abci_test.go index 30a0a4cc3918..fc874ba28ef4 100644 --- a/x/feegrant/module/abci_test.go +++ b/x/feegrant/module/abci_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/cosmos/cosmos-sdk/baseapp" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" @@ -18,8 +19,8 @@ import ( ) func TestFeegrantPruning(t *testing.T) { - key := sdk.NewKVStoreKey(feegrant.StoreKey) - testCtx := testutil.DefaultContextWithDB(t, key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(feegrant.StoreKey) + testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(module.AppModuleBasic{}) addrs := simtestutil.CreateIncrementalAccounts(4) diff --git a/x/feegrant/module/module.go b/x/feegrant/module/module.go index f9c462fcafb2..d330d031a280 100644 --- a/x/feegrant/module/module.go +++ b/x/feegrant/module/module.go @@ -214,7 +214,7 @@ func (AppModule) ProposalContents(simState module.SimulationState) []simtypes.We } // RegisterStoreDecoder registers a decoder for feegrant module's types -func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { +func (am AppModule) RegisterStoreDecoder(sdr store.StoreDecoderRegistry) { sdr[feegrant.StoreKey] = simulation.NewDecodeStore(am.cdc) } diff --git a/x/feegrant/periodic_fee_test.go b/x/feegrant/periodic_fee_test.go index 1ac45b312a6c..7c7130abc89a 100644 --- a/x/feegrant/periodic_fee_test.go +++ b/x/feegrant/periodic_fee_test.go @@ -8,14 +8,15 @@ import ( "github.com/stretchr/testify/require" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/feegrant" ) func TestPeriodicFeeValidAllow(t *testing.T) { - key := sdk.NewKVStoreKey(feegrant.StoreKey) - testCtx := testutil.DefaultContextWithDB(t, key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(feegrant.StoreKey) + testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) ctx := testCtx.Ctx.WithBlockHeader(tmproto.Header{Time: time.Now()}) diff --git a/x/genutil/gentx_test.go b/x/genutil/gentx_test.go index 20b3d07a1912..4a67b27b5250 100644 --- a/x/genutil/gentx_test.go +++ b/x/genutil/gentx_test.go @@ -10,12 +10,12 @@ import ( "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/genutil" genutiltestutil "github.com/cosmos/cosmos-sdk/x/genutil/testutil" @@ -50,8 +50,8 @@ type GenTxTestSuite struct { func (suite *GenTxTestSuite) SetupTest() { suite.encodingConfig = moduletestutil.MakeTestEncodingConfig(genutil.AppModuleBasic{}) - key := sdk.NewKVStoreKey("a_Store_Key") - tkey := sdk.NewTransientStoreKey("a_transient_store") + key := storetypes.NewKVStoreKey("a_Store_Key") + tkey := storetypes.NewTransientStoreKey("a_transient_store") suite.ctx = testutil.DefaultContext(key, tkey) ctrl := gomock.NewController(suite.T()) diff --git a/x/gov/keeper/common_test.go b/x/gov/keeper/common_test.go index a586e7fd71e2..195355d69e84 100644 --- a/x/gov/keeper/common_test.go +++ b/x/gov/keeper/common_test.go @@ -10,6 +10,7 @@ import ( tmtime "github.com/tendermint/tendermint/types/time" "github.com/cosmos/cosmos-sdk/baseapp" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" @@ -52,8 +53,8 @@ func setupGovKeeper(t *testing.T) ( moduletestutil.TestEncodingConfig, sdk.Context, ) { - key := sdk.NewKVStoreKey(types.StoreKey) - testCtx := testutil.DefaultContextWithDB(t, key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(types.StoreKey) + testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) ctx := testCtx.Ctx.WithBlockHeader(tmproto.Header{Time: tmtime.Now()}) encCfg := moduletestutil.MakeTestEncodingConfig() v1.RegisterInterfaces(encCfg.InterfaceRegistry) diff --git a/x/gov/keeper/deposit.go b/x/gov/keeper/deposit.go index 62b90bd46d5f..8beb64a5ef92 100644 --- a/x/gov/keeper/deposit.go +++ b/x/gov/keeper/deposit.go @@ -3,6 +3,7 @@ package keeper import ( "fmt" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/gov/types" @@ -71,7 +72,7 @@ func (keeper Keeper) DeleteAndBurnDeposits(ctx sdk.Context, proposalID uint64) { // IterateAllDeposits iterates over all the stored deposits and performs a callback function. func (keeper Keeper) IterateAllDeposits(ctx sdk.Context, cb func(deposit v1.Deposit) (stop bool)) { store := ctx.KVStore(keeper.storeKey) - iterator := sdk.KVStorePrefixIterator(store, types.DepositsKeyPrefix) + iterator := storetypes.KVStorePrefixIterator(store, types.DepositsKeyPrefix) defer iterator.Close() @@ -89,7 +90,7 @@ func (keeper Keeper) IterateAllDeposits(ctx sdk.Context, cb func(deposit v1.Depo // IterateDeposits iterates over all the proposals deposits and performs a callback function func (keeper Keeper) IterateDeposits(ctx sdk.Context, proposalID uint64, cb func(deposit v1.Deposit) (stop bool)) { store := ctx.KVStore(keeper.storeKey) - iterator := sdk.KVStorePrefixIterator(store, types.DepositsKey(proposalID)) + iterator := storetypes.KVStorePrefixIterator(store, types.DepositsKey(proposalID)) defer iterator.Close() diff --git a/x/gov/keeper/keeper.go b/x/gov/keeper/keeper.go index 3cf98a29fd1d..2af72d8ec7cc 100644 --- a/x/gov/keeper/keeper.go +++ b/x/gov/keeper/keeper.go @@ -206,16 +206,16 @@ func (k Keeper) IterateInactiveProposalsQueue(ctx sdk.Context, endTime time.Time } } -// ActiveProposalQueueIterator returns an sdk.Iterator for all the proposals in the Active Queue that expire by endTime -func (k Keeper) ActiveProposalQueueIterator(ctx sdk.Context, endTime time.Time) sdk.Iterator { +// ActiveProposalQueueIterator returns an storetypes.Iterator for all the proposals in the Active Queue that expire by endTime +func (k Keeper) ActiveProposalQueueIterator(ctx sdk.Context, endTime time.Time) storetypes.Iterator { store := ctx.KVStore(k.storeKey) - return store.Iterator(types.ActiveProposalQueuePrefix, sdk.PrefixEndBytes(types.ActiveProposalByTimeKey(endTime))) + return store.Iterator(types.ActiveProposalQueuePrefix, storetypes.PrefixEndBytes(types.ActiveProposalByTimeKey(endTime))) } -// InactiveProposalQueueIterator returns an sdk.Iterator for all the proposals in the Inactive Queue that expire by endTime -func (k Keeper) InactiveProposalQueueIterator(ctx sdk.Context, endTime time.Time) sdk.Iterator { +// InactiveProposalQueueIterator returns an storetypes.Iterator for all the proposals in the Inactive Queue that expire by endTime +func (k Keeper) InactiveProposalQueueIterator(ctx sdk.Context, endTime time.Time) storetypes.Iterator { store := ctx.KVStore(k.storeKey) - return store.Iterator(types.InactiveProposalQueuePrefix, sdk.PrefixEndBytes(types.InactiveProposalByTimeKey(endTime))) + return store.Iterator(types.InactiveProposalQueuePrefix, storetypes.PrefixEndBytes(types.InactiveProposalByTimeKey(endTime))) } // assertMetadataLength returns an error if given metadata length diff --git a/x/gov/keeper/proposal.go b/x/gov/keeper/proposal.go index 6b260248c844..8c72b315a0b7 100644 --- a/x/gov/keeper/proposal.go +++ b/x/gov/keeper/proposal.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/cosmos/cosmos-sdk/client" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/gov/types" @@ -168,7 +169,7 @@ func (keeper Keeper) DeleteProposal(ctx sdk.Context, proposalID uint64) { func (keeper Keeper) IterateProposals(ctx sdk.Context, cb func(proposal v1.Proposal) (stop bool)) { store := ctx.KVStore(keeper.storeKey) - iterator := sdk.KVStorePrefixIterator(store, types.ProposalsKeyPrefix) + iterator := storetypes.KVStorePrefixIterator(store, types.ProposalsKeyPrefix) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { diff --git a/x/gov/keeper/vote.go b/x/gov/keeper/vote.go index 7f43bec1266d..c98e9024be40 100644 --- a/x/gov/keeper/vote.go +++ b/x/gov/keeper/vote.go @@ -3,6 +3,7 @@ package keeper import ( "fmt" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/gov/types" @@ -88,7 +89,7 @@ func (keeper Keeper) SetVote(ctx sdk.Context, vote v1.Vote) { // IterateAllVotes iterates over all the stored votes and performs a callback function func (keeper Keeper) IterateAllVotes(ctx sdk.Context, cb func(vote v1.Vote) (stop bool)) { store := ctx.KVStore(keeper.storeKey) - iterator := sdk.KVStorePrefixIterator(store, types.VotesKeyPrefix) + iterator := storetypes.KVStorePrefixIterator(store, types.VotesKeyPrefix) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -104,7 +105,7 @@ func (keeper Keeper) IterateAllVotes(ctx sdk.Context, cb func(vote v1.Vote) (sto // IterateVotes iterates over all the proposals votes and performs a callback function func (keeper Keeper) IterateVotes(ctx sdk.Context, proposalID uint64, cb func(vote v1.Vote) (stop bool)) { store := ctx.KVStore(keeper.storeKey) - iterator := sdk.KVStorePrefixIterator(store, types.VotesKey(proposalID)) + iterator := storetypes.KVStorePrefixIterator(store, types.VotesKey(proposalID)) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { diff --git a/x/gov/migrations/v2/store.go b/x/gov/migrations/v2/store.go index 25c78308e709..2554cf50009f 100644 --- a/x/gov/migrations/v2/store.go +++ b/x/gov/migrations/v2/store.go @@ -18,7 +18,7 @@ const proposalIDLen = 8 // // into format: // -func migratePrefixProposalAddress(store sdk.KVStore, prefixBz []byte) { +func migratePrefixProposalAddress(store storetypes.KVStore, prefixBz []byte) { oldStore := prefix.NewStore(store, prefixBz) oldStoreIter := oldStore.Iterator(nil, nil) @@ -47,8 +47,8 @@ func migrateVote(oldVote v1beta1.Vote) v1beta1.Vote { } // migrateStoreWeightedVotes migrates in-place all legacy votes to ADR-037 weighted votes. -func migrateStoreWeightedVotes(store sdk.KVStore, cdc codec.BinaryCodec) error { - iterator := sdk.KVStorePrefixIterator(store, types.VotesKeyPrefix) +func migrateStoreWeightedVotes(store storetypes.KVStore, cdc codec.BinaryCodec) error { + iterator := storetypes.KVStorePrefixIterator(store, types.VotesKeyPrefix) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { diff --git a/x/gov/migrations/v2/store_test.go b/x/gov/migrations/v2/store_test.go index 42ee6eb7dd83..791aeee79dff 100644 --- a/x/gov/migrations/v2/store_test.go +++ b/x/gov/migrations/v2/store_test.go @@ -8,9 +8,9 @@ import ( "cosmossdk.io/math" "github.com/stretchr/testify/require" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/testutil/testdata" - sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" v1 "github.com/cosmos/cosmos-sdk/x/gov/migrations/v1" v2 "github.com/cosmos/cosmos-sdk/x/gov/migrations/v2" @@ -20,8 +20,8 @@ import ( func TestMigrateStore(t *testing.T) { cdc := moduletestutil.MakeTestEncodingConfig().Codec - govKey := sdk.NewKVStoreKey("gov") - ctx := testutil.DefaultContext(govKey, sdk.NewTransientStoreKey("transient_test")) + govKey := storetypes.NewKVStoreKey("gov") + ctx := testutil.DefaultContext(govKey, storetypes.NewTransientStoreKey("transient_test")) store := ctx.KVStore(govKey) _, _, addr1 := testdata.KeyTestPubAddr() diff --git a/x/gov/migrations/v3/store.go b/x/gov/migrations/v3/store.go index 7f3cfe76c66e..a6f294cd19d3 100644 --- a/x/gov/migrations/v3/store.go +++ b/x/gov/migrations/v3/store.go @@ -12,7 +12,7 @@ import ( // migrateProposals migrates all legacy proposals into MsgExecLegacyContent // proposals. -func migrateProposals(store sdk.KVStore, cdc codec.BinaryCodec) error { +func migrateProposals(store storetypes.KVStore, cdc codec.BinaryCodec) error { propStore := prefix.NewStore(store, v1.ProposalsKeyPrefix) iter := propStore.Iterator(nil, nil) @@ -43,7 +43,7 @@ func migrateProposals(store sdk.KVStore, cdc codec.BinaryCodec) error { // migrateVotes migrates all v1beta1 weighted votes (with sdk.Dec as weight) // to v1 weighted votes (with string as weight) -func migrateVotes(store sdk.KVStore, cdc codec.BinaryCodec) error { +func migrateVotes(store storetypes.KVStore, cdc codec.BinaryCodec) error { votesStore := prefix.NewStore(store, v1.VotesKeyPrefix) iter := votesStore.Iterator(nil, nil) diff --git a/x/gov/migrations/v3/store_test.go b/x/gov/migrations/v3/store_test.go index 95612a718547..c5cbac0ab25b 100644 --- a/x/gov/migrations/v3/store_test.go +++ b/x/gov/migrations/v3/store_test.go @@ -6,6 +6,7 @@ import ( "github.com/stretchr/testify/require" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -20,8 +21,8 @@ import ( func TestMigrateStore(t *testing.T) { cdc := moduletestutil.MakeTestEncodingConfig(upgrade.AppModuleBasic{}, gov.AppModuleBasic{}).Codec - govKey := sdk.NewKVStoreKey("gov") - ctx := testutil.DefaultContext(govKey, sdk.NewTransientStoreKey("transient_test")) + govKey := storetypes.NewKVStoreKey("gov") + ctx := testutil.DefaultContext(govKey, storetypes.NewTransientStoreKey("transient_test")) store := ctx.KVStore(govKey) propTime := time.Unix(1e9, 0) diff --git a/x/gov/migrations/v4/store_test.go b/x/gov/migrations/v4/store_test.go index 92f2601af7a0..c99b4caabc3d 100644 --- a/x/gov/migrations/v4/store_test.go +++ b/x/gov/migrations/v4/store_test.go @@ -6,6 +6,7 @@ import ( "github.com/stretchr/testify/require" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" @@ -64,8 +65,8 @@ func (ms mockSubspace) Get(ctx sdk.Context, key []byte, ptr interface{}) { func TestMigrateStore(t *testing.T) { cdc := moduletestutil.MakeTestEncodingConfig(upgrade.AppModuleBasic{}, gov.AppModuleBasic{}, bank.AppModuleBasic{}).Codec - govKey := sdk.NewKVStoreKey("gov") - ctx := testutil.DefaultContext(govKey, sdk.NewTransientStoreKey("transient_test")) + govKey := storetypes.NewKVStoreKey("gov") + ctx := testutil.DefaultContext(govKey, storetypes.NewTransientStoreKey("transient_test")) store := ctx.KVStore(govKey) legacySubspace := newMockSubspace(v1.DefaultParams()) diff --git a/x/gov/module.go b/x/gov/module.go index d49c3cea89ef..3fae0e6888d8 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -336,7 +336,7 @@ func (AppModule) ProposalContents(simState module.SimulationState) []simtypes.We } // RegisterStoreDecoder registers a decoder for gov module's types -func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { +func (am AppModule) RegisterStoreDecoder(sdr store.StoreDecoderRegistry) { sdr[govtypes.StoreKey] = simulation.NewDecodeStore(am.cdc) } diff --git a/x/group/internal/orm/auto_uint64.go b/x/group/internal/orm/auto_uint64.go index f085a3dd1300..9dc807b0347e 100644 --- a/x/group/internal/orm/auto_uint64.go +++ b/x/group/internal/orm/auto_uint64.go @@ -4,7 +4,7 @@ import ( "github.com/cosmos/gogoproto/proto" "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/types/errors" ) @@ -36,7 +36,7 @@ func NewAutoUInt64Table(prefixData [2]byte, prefixSeq byte, model proto.Message, // // Create iterates through the registered callbacks that may add secondary index // keys. -func (a AutoUInt64Table) Create(store sdk.KVStore, obj proto.Message) (uint64, error) { +func (a AutoUInt64Table) Create(store storetypes.KVStore, obj proto.Message) (uint64, error) { autoIncID := a.seq.NextVal(store) err := a.table.Create(store, EncodeSequence(autoIncID), obj) if err != nil { @@ -52,7 +52,7 @@ func (a AutoUInt64Table) Create(store sdk.KVStore, obj proto.Message) (uint64, e // // Update iterates through the registered callbacks that may add or remove // secondary index keys. -func (a AutoUInt64Table) Update(store sdk.KVStore, rowID uint64, newValue proto.Message) error { +func (a AutoUInt64Table) Update(store storetypes.KVStore, rowID uint64, newValue proto.Message) error { return a.table.Update(store, EncodeSequence(rowID), newValue) } @@ -61,18 +61,18 @@ func (a AutoUInt64Table) Update(store sdk.KVStore, rowID uint64, newValue proto. // is fulfilled. // // Delete iterates though the registered callbacks and removes secondary index keys by them. -func (a AutoUInt64Table) Delete(store sdk.KVStore, rowID uint64) error { +func (a AutoUInt64Table) Delete(store storetypes.KVStore, rowID uint64) error { return a.table.Delete(store, EncodeSequence(rowID)) } // Has checks if a rowID exists. -func (a AutoUInt64Table) Has(store sdk.KVStore, rowID uint64) bool { +func (a AutoUInt64Table) Has(store storetypes.KVStore, rowID uint64) bool { return a.table.Has(store, EncodeSequence(rowID)) } // GetOne load the object persisted for the given RowID into the dest parameter. // If none exists `ErrNotFound` is returned instead. Parameters must not be nil. -func (a AutoUInt64Table) GetOne(store sdk.KVStore, rowID uint64, dest proto.Message) (RowID, error) { +func (a AutoUInt64Table) GetOne(store storetypes.KVStore, rowID uint64, dest proto.Message) (RowID, error) { rawRowID := EncodeSequence(rowID) if err := a.table.GetOne(store, rawRowID, dest); err != nil { return nil, err @@ -97,7 +97,7 @@ func (a AutoUInt64Table) GetOne(store sdk.KVStore, rowID uint64, dest proto.Mess // it = LimitIterator(it, defaultLimit) // // CONTRACT: No writes may happen within a domain while an iterator exists over it. -func (a AutoUInt64Table) PrefixScan(store sdk.KVStore, start, end uint64) (Iterator, error) { +func (a AutoUInt64Table) PrefixScan(store storetypes.KVStore, start, end uint64) (Iterator, error) { return a.table.PrefixScan(store, EncodeSequence(start), EncodeSequence(end)) } @@ -110,7 +110,7 @@ func (a AutoUInt64Table) PrefixScan(store sdk.KVStore, start, end uint64) (Itera // this as an endpoint to the public without further limits. See `LimitIterator` // // CONTRACT: No writes may happen within a domain while an iterator exists over it. -func (a AutoUInt64Table) ReversePrefixScan(store sdk.KVStore, start uint64, end uint64) (Iterator, error) { +func (a AutoUInt64Table) ReversePrefixScan(store storetypes.KVStore, start uint64, end uint64) (Iterator, error) { return a.table.ReversePrefixScan(store, EncodeSequence(start), EncodeSequence(end)) } @@ -121,7 +121,7 @@ func (a AutoUInt64Table) Sequence() Sequence { // Export stores all the values in the table in the passed ModelSlicePtr and // returns the current value of the associated sequence. -func (a AutoUInt64Table) Export(store sdk.KVStore, dest ModelSlicePtr) (uint64, error) { +func (a AutoUInt64Table) Export(store storetypes.KVStore, dest ModelSlicePtr) (uint64, error) { _, err := a.table.Export(store, dest) if err != nil { return 0, err @@ -131,7 +131,7 @@ func (a AutoUInt64Table) Export(store sdk.KVStore, dest ModelSlicePtr) (uint64, // Import clears the table and initializes it from the given data interface{}. // data should be a slice of structs that implement PrimaryKeyed. -func (a AutoUInt64Table) Import(store sdk.KVStore, data interface{}, seqValue uint64) error { +func (a AutoUInt64Table) Import(store storetypes.KVStore, data interface{}, seqValue uint64) error { if err := a.seq.InitVal(store, seqValue); err != nil { return errors.Wrap(err, "sequence") } diff --git a/x/group/internal/orm/auto_uint64_test.go b/x/group/internal/orm/auto_uint64_test.go index 345a846509e2..dcbb59f7e345 100644 --- a/x/group/internal/orm/auto_uint64_test.go +++ b/x/group/internal/orm/auto_uint64_test.go @@ -6,8 +6,8 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil/testdata" - sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/group/errors" "github.com/stretchr/testify/assert" @@ -22,7 +22,7 @@ func TestAutoUInt64PrefixScan(t *testing.T) { require.NoError(t, err) ctx := NewMockContext() - store := ctx.KVStore(sdk.NewKVStoreKey("test")) + store := ctx.KVStore(storetypes.NewKVStoreKey("test")) metadata := []byte("metadata") t1 := testdata.TableModel{ @@ -51,7 +51,7 @@ func TestAutoUInt64PrefixScan(t *testing.T) { expResult []testdata.TableModel expRowIDs []RowID expError *sdkerrors.Error //nolint:staticcheck // SA1019: sdkerrors.Error is deprecated: the type has been moved to cosmossdk.io/errors module. Please use the above module instead of this package - method func(store sdk.KVStore, start uint64, end uint64) (Iterator, error) + method func(store storetypes.KVStore, start uint64, end uint64) (Iterator, error) }{ "first element": { start: 1, diff --git a/x/group/internal/orm/genesis.go b/x/group/internal/orm/genesis.go index 60a4c3ec78df..425354a4b2ab 100644 --- a/x/group/internal/orm/genesis.go +++ b/x/group/internal/orm/genesis.go @@ -1,19 +1,17 @@ package orm -import ( - sdk "github.com/cosmos/cosmos-sdk/types" -) +import storetypes "github.com/cosmos/cosmos-sdk/store/types" // TableExportable defines the methods to import and export a table. type TableExportable interface { // Export stores all the values in the table in the passed // ModelSlicePtr. If the table has an associated sequence, then its // current value is returned, otherwise 0 is returned by default. - Export(store sdk.KVStore, dest ModelSlicePtr) (uint64, error) + Export(store storetypes.KVStore, dest ModelSlicePtr) (uint64, error) // Import clears the table and initializes it from the given data // interface{}. data should be a slice of structs that implement // PrimaryKeyed. The seqValue is optional and only // used with tables that have an associated sequence. - Import(store sdk.KVStore, data interface{}, seqValue uint64) error + Import(store storetypes.KVStore, data interface{}, seqValue uint64) error } diff --git a/x/group/internal/orm/genesis_test.go b/x/group/internal/orm/genesis_test.go index 5b350092bf8e..0b7511530695 100644 --- a/x/group/internal/orm/genesis_test.go +++ b/x/group/internal/orm/genesis_test.go @@ -5,8 +5,8 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil/testdata" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" ) @@ -18,7 +18,7 @@ func TestImportExportTableData(t *testing.T) { require.NoError(t, err) ctx := NewMockContext() - store := ctx.KVStore(sdk.NewKVStoreKey("test")) + store := ctx.KVStore(storetypes.NewKVStoreKey("test")) tms := []*testdata.TableModel{ { diff --git a/x/group/internal/orm/index.go b/x/group/internal/orm/index.go index 7239f4aafbab..29264c7093fd 100644 --- a/x/group/internal/orm/index.go +++ b/x/group/internal/orm/index.go @@ -7,7 +7,6 @@ import ( "github.com/cosmos/cosmos-sdk/store/prefix" "github.com/cosmos/cosmos-sdk/store/types" - sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/query" "github.com/cosmos/cosmos-sdk/x/group/errors" @@ -15,9 +14,9 @@ import ( // indexer creates and modifies the second MultiKeyIndex based on the operations and changes on the primary object. type indexer interface { - OnCreate(store sdk.KVStore, rowID RowID, value interface{}) error - OnDelete(store sdk.KVStore, rowID RowID, value interface{}) error - OnUpdate(store sdk.KVStore, rowID RowID, newValue, oldValue interface{}) error + OnCreate(store types.KVStore, rowID RowID, value interface{}) error + OnDelete(store types.KVStore, rowID RowID, value interface{}) error + OnUpdate(store types.KVStore, rowID RowID, newValue, oldValue interface{}) error } var _ Index = &MultiKeyIndex{} @@ -72,7 +71,7 @@ func newIndex(tb Indexable, prefix byte, indexer *Indexer, indexerF IndexerFunc, } // Has checks if a key exists. Returns an error on nil key. -func (i MultiKeyIndex) Has(store sdk.KVStore, key interface{}) (bool, error) { +func (i MultiKeyIndex) Has(store types.KVStore, key interface{}) (bool, error) { pStore := prefix.NewStore(store, []byte{i.prefix}) encodedKey, err := keyPartBytes(key, false) if err != nil { @@ -84,7 +83,7 @@ func (i MultiKeyIndex) Has(store sdk.KVStore, key interface{}) (bool, error) { } // Get returns a result iterator for the searchKey. Parameters must not be nil. -func (i MultiKeyIndex) Get(store sdk.KVStore, searchKey interface{}) (Iterator, error) { +func (i MultiKeyIndex) Get(store types.KVStore, searchKey interface{}) (Iterator, error) { pStore := prefix.NewStore(store, []byte{i.prefix}) encodedKey, err := keyPartBytes(searchKey, false) if err != nil { @@ -97,7 +96,7 @@ func (i MultiKeyIndex) Get(store sdk.KVStore, searchKey interface{}) (Iterator, // GetPaginated creates an iterator for the searchKey // starting from pageRequest.Key if provided. // The pageRequest.Key is the rowID while searchKey is a MultiKeyIndex key. -func (i MultiKeyIndex) GetPaginated(store sdk.KVStore, searchKey interface{}, pageRequest *query.PageRequest) (Iterator, error) { +func (i MultiKeyIndex) GetPaginated(store types.KVStore, searchKey interface{}, pageRequest *query.PageRequest) (Iterator, error) { pStore := prefix.NewStore(store, []byte{i.prefix}) encodedKey, err := keyPartBytes(searchKey, false) if err != nil { @@ -133,7 +132,7 @@ func (i MultiKeyIndex) GetPaginated(store sdk.KVStore, searchKey interface{}, pa // it = LimitIterator(it, defaultLimit) // // CONTRACT: No writes may happen within a domain while an iterator exists over it. -func (i MultiKeyIndex) PrefixScan(store sdk.KVStore, startI interface{}, endI interface{}) (Iterator, error) { +func (i MultiKeyIndex) PrefixScan(store types.KVStore, startI interface{}, endI interface{}) (Iterator, error) { start, end, err := getStartEndBz(startI, endI) if err != nil { return nil, err @@ -153,7 +152,7 @@ func (i MultiKeyIndex) PrefixScan(store sdk.KVStore, startI interface{}, endI in // this as an endpoint to the public without further limits. See `LimitIterator` // // CONTRACT: No writes may happen within a domain while an iterator exists over it. -func (i MultiKeyIndex) ReversePrefixScan(store sdk.KVStore, startI interface{}, endI interface{}) (Iterator, error) { +func (i MultiKeyIndex) ReversePrefixScan(store types.KVStore, startI interface{}, endI interface{}) (Iterator, error) { start, end, err := getStartEndBz(startI, endI) if err != nil { return nil, err @@ -199,7 +198,7 @@ func getPrefixScanKeyBytes(keyI interface{}) ([]byte, error) { return key, nil } -func (i MultiKeyIndex) onSet(store sdk.KVStore, rowID RowID, newValue, oldValue proto.Message) error { +func (i MultiKeyIndex) onSet(store types.KVStore, rowID RowID, newValue, oldValue proto.Message) error { pStore := prefix.NewStore(store, []byte{i.prefix}) if oldValue == nil { return i.indexer.OnCreate(pStore, rowID, newValue) @@ -207,7 +206,7 @@ func (i MultiKeyIndex) onSet(store sdk.KVStore, rowID RowID, newValue, oldValue return i.indexer.OnUpdate(pStore, rowID, newValue, oldValue) } -func (i MultiKeyIndex) onDelete(store sdk.KVStore, rowID RowID, oldValue proto.Message) error { +func (i MultiKeyIndex) onDelete(store types.KVStore, rowID RowID, oldValue proto.Message) error { pStore := prefix.NewStore(store, []byte{i.prefix}) return i.indexer.OnDelete(pStore, rowID, oldValue) } @@ -233,7 +232,7 @@ func NewUniqueIndex(tb Indexable, prefix byte, uniqueIndexerFunc UniqueIndexerFu // indexIterator uses rowGetter to lazy load new model values on request. type indexIterator struct { - store sdk.KVStore + store types.KVStore rowGetter RowGetter it types.Iterator indexKey interface{} diff --git a/x/group/internal/orm/index_test.go b/x/group/internal/orm/index_test.go index 1172de745ab4..604fe3f14829 100644 --- a/x/group/internal/orm/index_test.go +++ b/x/group/internal/orm/index_test.go @@ -5,8 +5,8 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil/testdata" - sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/query" "github.com/cosmos/cosmos-sdk/x/group/errors" @@ -101,7 +101,7 @@ func TestIndexPrefixScan(t *testing.T) { require.NoError(t, err) ctx := NewMockContext() - store := ctx.KVStore(sdk.NewKVStoreKey("test")) + store := ctx.KVStore(storetypes.NewKVStoreKey("test")) g1 := testdata.TableModel{ Id: 1, @@ -129,7 +129,7 @@ func TestIndexPrefixScan(t *testing.T) { expResult []testdata.TableModel expRowIDs []RowID expError *sdkerrors.Error //nolint:staticcheck // SA1019: sdkerrors.Error is deprecated: the type has been moved to cosmossdk.io/errors module. Please use the above module instead of this package - method func(store sdk.KVStore, start, end interface{}) (Iterator, error) + method func(store storetypes.KVStore, start, end interface{}) (Iterator, error) }{ "exact match with a single result": { start: []byte("metadata-a"), @@ -301,7 +301,7 @@ func TestUniqueIndex(t *testing.T) { require.NoError(t, err) ctx := NewMockContext() - store := ctx.KVStore(sdk.NewKVStoreKey("test")) + store := ctx.KVStore(storetypes.NewKVStoreKey("test")) m := testdata.TableModel{ Id: 1, diff --git a/x/group/internal/orm/indexer.go b/x/group/internal/orm/indexer.go index a2dc8e6fed95..9df1825e03bc 100644 --- a/x/group/internal/orm/indexer.go +++ b/x/group/internal/orm/indexer.go @@ -1,7 +1,7 @@ package orm import ( - sdk "github.com/cosmos/cosmos-sdk/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/group/errors" ) @@ -15,7 +15,7 @@ type UniqueIndexerFunc func(value interface{}) (interface{}, error) // Indexer manages the persistence of an Index based on searchable keys and operations. type Indexer struct { indexerFunc IndexerFunc - addFunc func(store sdk.KVStore, secondaryIndexKey interface{}, rowID RowID) error + addFunc func(store storetypes.KVStore, secondaryIndexKey interface{}, rowID RowID) error } // NewIndexer returns an indexer that supports multiple reference keys for an entity. @@ -55,7 +55,7 @@ func (i Indexer) IndexerFunc() IndexerFunc { } // OnCreate persists the secondary index entries for the new object. -func (i Indexer) OnCreate(store sdk.KVStore, rowID RowID, value interface{}) error { +func (i Indexer) OnCreate(store storetypes.KVStore, rowID RowID, value interface{}) error { secondaryIndexKeys, err := i.indexerFunc(value) if err != nil { return err @@ -70,7 +70,7 @@ func (i Indexer) OnCreate(store sdk.KVStore, rowID RowID, value interface{}) err } // OnDelete removes the secondary index entries for the deleted object. -func (i Indexer) OnDelete(store sdk.KVStore, rowID RowID, value interface{}) error { +func (i Indexer) OnDelete(store storetypes.KVStore, rowID RowID, value interface{}) error { secondaryIndexKeys, err := i.indexerFunc(value) if err != nil { return err @@ -87,7 +87,7 @@ func (i Indexer) OnDelete(store sdk.KVStore, rowID RowID, value interface{}) err } // OnUpdate rebuilds the secondary index entries for the updated object. -func (i Indexer) OnUpdate(store sdk.KVStore, rowID RowID, newValue, oldValue interface{}) error { +func (i Indexer) OnUpdate(store storetypes.KVStore, rowID RowID, newValue, oldValue interface{}) error { oldSecIdxKeys, err := i.indexerFunc(oldValue) if err != nil { return err @@ -120,7 +120,7 @@ func (i Indexer) OnUpdate(store sdk.KVStore, rowID RowID, newValue, oldValue int } // uniqueKeysAddFunc enforces keys to be unique -func uniqueKeysAddFunc(store sdk.KVStore, secondaryIndexKey interface{}, rowID RowID) error { +func uniqueKeysAddFunc(store storetypes.KVStore, secondaryIndexKey interface{}, rowID RowID) error { secondaryIndexKeyBytes, err := keyPartBytes(secondaryIndexKey, false) if err != nil { return err @@ -143,7 +143,7 @@ func uniqueKeysAddFunc(store sdk.KVStore, secondaryIndexKey interface{}, rowID R } // checkUniqueIndexKey checks that the given secondary index key is unique -func checkUniqueIndexKey(store sdk.KVStore, secondaryIndexKeyBytes []byte) error { +func checkUniqueIndexKey(store storetypes.KVStore, secondaryIndexKeyBytes []byte) error { it := store.Iterator(PrefixRange(secondaryIndexKeyBytes)) defer it.Close() if it.Valid() { @@ -153,7 +153,7 @@ func checkUniqueIndexKey(store sdk.KVStore, secondaryIndexKeyBytes []byte) error } // multiKeyAddFunc allows multiple entries for a key -func multiKeyAddFunc(store sdk.KVStore, secondaryIndexKey interface{}, rowID RowID) error { +func multiKeyAddFunc(store storetypes.KVStore, secondaryIndexKey interface{}, rowID RowID) error { secondaryIndexKeyBytes, err := keyPartBytes(secondaryIndexKey, false) if err != nil { return err diff --git a/x/group/internal/orm/indexer_test.go b/x/group/internal/orm/indexer_test.go index 8b4707f2f82d..3b5d68154461 100644 --- a/x/group/internal/orm/indexer_test.go +++ b/x/group/internal/orm/indexer_test.go @@ -6,7 +6,7 @@ import ( "testing" "github.com/cosmos/cosmos-sdk/store/prefix" - sdk "github.com/cosmos/cosmos-sdk/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/group/errors" "github.com/stretchr/testify/assert" @@ -163,7 +163,7 @@ func TestIndexerOnDelete(t *testing.T) { var multiKeyIndex MultiKeyIndex ctx := NewMockContext() - storeKey := sdk.NewKVStoreKey("test") + storeKey := storetypes.NewKVStoreKey("test") store := prefix.NewStore(ctx.KVStore(storeKey), []byte{multiKeyIndex.prefix}) specs := map[string]struct { @@ -245,7 +245,7 @@ func TestIndexerOnUpdate(t *testing.T) { var multiKeyIndex MultiKeyIndex ctx := NewMockContext() - storeKey := sdk.NewKVStoreKey("test") + storeKey := storetypes.NewKVStoreKey("test") store := prefix.NewStore(ctx.KVStore(storeKey), []byte{multiKeyIndex.prefix}) specs := map[string]struct { @@ -253,7 +253,7 @@ func TestIndexerOnUpdate(t *testing.T) { expAddedKeys []RowID expDeletedKeys []RowID expErr error - addFunc func(sdk.KVStore, interface{}, RowID) error + addFunc func(storetypes.KVStore, interface{}, RowID) error }{ "single key - same key, no update": { srcFunc: func(value interface{}) ([]interface{}, error) { @@ -333,7 +333,7 @@ func TestIndexerOnUpdate(t *testing.T) { keys := []uint64{1, 2} return []interface{}{keys[value.(int)]}, nil }, - addFunc: func(_ sdk.KVStore, _ interface{}, _ RowID) error { + addFunc: func(_ storetypes.KVStore, _ interface{}, _ RowID) error { return stdErrors.New("test") }, expErr: stdErrors.New("test"), @@ -397,7 +397,7 @@ func TestUniqueKeyAddFunc(t *testing.T) { } for msg, spec := range specs { t.Run(msg, func(t *testing.T) { - storeKey := sdk.NewKVStoreKey("test") + storeKey := storetypes.NewKVStoreKey("test") store := NewMockContext().KVStore(storeKey) store.Set(presetKey, []byte{}) @@ -440,7 +440,7 @@ func TestMultiKeyAddFunc(t *testing.T) { } for msg, spec := range specs { t.Run(msg, func(t *testing.T) { - storeKey := sdk.NewKVStoreKey("test") + storeKey := storetypes.NewKVStoreKey("test") store := NewMockContext().KVStore(storeKey) store.Set(presetKey, []byte{}) @@ -561,7 +561,7 @@ type addFuncRecorder struct { called bool } -func (c *addFuncRecorder) add(_ sdk.KVStore, key interface{}, rowID RowID) error { +func (c *addFuncRecorder) add(_ storetypes.KVStore, key interface{}, rowID RowID) error { c.secondaryIndexKeys = append(c.secondaryIndexKeys, key) c.rowIDs = append(c.rowIDs, rowID) c.called = true diff --git a/x/group/internal/orm/iterator_test.go b/x/group/internal/orm/iterator_test.go index 96c4072dcd2e..b29ae86572ee 100644 --- a/x/group/internal/orm/iterator_test.go +++ b/x/group/internal/orm/iterator_test.go @@ -9,6 +9,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -208,7 +209,7 @@ func TestPaginate(t *testing.T) { require.NoError(t, err) ctx := NewMockContext() - store := ctx.KVStore(sdk.NewKVStoreKey("test")) + store := ctx.KVStore(storetypes.NewKVStoreKey("test")) metadata := []byte("metadata") t1 := testdata.TableModel{ diff --git a/x/group/internal/orm/orm_scenario_test.go b/x/group/internal/orm/orm_scenario_test.go index f35f1fccfddf..1b2fa95b0f27 100644 --- a/x/group/internal/orm/orm_scenario_test.go +++ b/x/group/internal/orm/orm_scenario_test.go @@ -8,12 +8,11 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" - sdk "github.com/cosmos/cosmos-sdk/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + "github.com/cosmos/cosmos-sdk/testutil/testdata" "github.com/cosmos/cosmos-sdk/x/group/errors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - - "github.com/cosmos/cosmos-sdk/testutil/testdata" ) // Testing ORM with arbitrary metadata length @@ -24,7 +23,7 @@ func TestKeeperEndToEndWithAutoUInt64Table(t *testing.T) { cdc := codec.NewProtoCodec(interfaceRegistry) ctx := NewMockContext() - store := ctx.KVStore(sdk.NewKVStoreKey("test")) + store := ctx.KVStore(storetypes.NewKVStoreKey("test")) k := NewTestKeeper(cdc) @@ -102,7 +101,7 @@ func TestKeeperEndToEndWithPrimaryKeyTable(t *testing.T) { cdc := codec.NewProtoCodec(interfaceRegistry) ctx := NewMockContext() - store := ctx.KVStore(sdk.NewKVStoreKey("test")) + store := ctx.KVStore(storetypes.NewKVStoreKey("test")) k := NewTestKeeper(cdc) @@ -188,7 +187,7 @@ func TestGasCostsPrimaryKeyTable(t *testing.T) { cdc := codec.NewProtoCodec(interfaceRegistry) ctx := NewMockContext() - store := ctx.KVStore(sdk.NewKVStoreKey("test")) + store := ctx.KVStore(storetypes.NewKVStoreKey("test")) k := NewTestKeeper(cdc) @@ -286,7 +285,7 @@ func TestExportImportStateAutoUInt64Table(t *testing.T) { cdc := codec.NewProtoCodec(interfaceRegistry) ctx := NewMockContext() - store := ctx.KVStore(sdk.NewKVStoreKey("test")) + store := ctx.KVStore(storetypes.NewKVStoreKey("test")) k := NewTestKeeper(cdc) @@ -309,7 +308,7 @@ func TestExportImportStateAutoUInt64Table(t *testing.T) { // when a new db seeded ctx = NewMockContext() - store = ctx.KVStore(sdk.NewKVStoreKey("test")) + store = ctx.KVStore(storetypes.NewKVStoreKey("test")) err = k.autoUInt64Table.Import(store, tms, seqVal) require.NoError(t, err) @@ -346,7 +345,7 @@ func TestExportImportStatePrimaryKeyTable(t *testing.T) { cdc := codec.NewProtoCodec(interfaceRegistry) ctx := NewMockContext() - store := ctx.KVStore(sdk.NewKVStoreKey("test")) + store := ctx.KVStore(storetypes.NewKVStoreKey("test")) k := NewTestKeeper(cdc) @@ -370,7 +369,7 @@ func TestExportImportStatePrimaryKeyTable(t *testing.T) { // when a new db seeded ctx = NewMockContext() - store = ctx.KVStore(sdk.NewKVStoreKey("test")) + store = ctx.KVStore(storetypes.NewKVStoreKey("test")) err = k.primaryKeyTable.Import(store, tms, 0) require.NoError(t, err) @@ -394,7 +393,7 @@ func TestExportImportStatePrimaryKeyTable(t *testing.T) { } } -func assertIndex(t *testing.T, store sdk.KVStore, index Index, v testdata.TableModel, searchKey interface{}) { +func assertIndex(t *testing.T, store storetypes.KVStore, index Index, v testdata.TableModel, searchKey interface{}) { it, err := index.Get(store, searchKey) require.NoError(t, err) diff --git a/x/group/internal/orm/primary_key.go b/x/group/internal/orm/primary_key.go index 324b7f61b550..3b5f28386ca5 100644 --- a/x/group/internal/orm/primary_key.go +++ b/x/group/internal/orm/primary_key.go @@ -1,10 +1,9 @@ package orm import ( - "github.com/cosmos/gogoproto/proto" - "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + "github.com/cosmos/gogoproto/proto" ) var ( @@ -63,7 +62,7 @@ func PrimaryKey(obj PrimaryKeyed) []byte { // // Create iterates through the registered callbacks that may add secondary // index keys. -func (a PrimaryKeyTable) Create(store sdk.KVStore, obj PrimaryKeyed) error { +func (a PrimaryKeyTable) Create(store storetypes.KVStore, obj PrimaryKeyed) error { rowID := PrimaryKey(obj) return a.table.Create(store, rowID, obj) } @@ -75,7 +74,7 @@ func (a PrimaryKeyTable) Create(store sdk.KVStore, obj PrimaryKeyed) error { // // Update iterates through the registered callbacks that may add or remove // secondary index keys. -func (a PrimaryKeyTable) Update(store sdk.KVStore, newValue PrimaryKeyed) error { +func (a PrimaryKeyTable) Update(store storetypes.KVStore, newValue PrimaryKeyed) error { return a.table.Update(store, PrimaryKey(newValue), newValue) } @@ -84,7 +83,7 @@ func (a PrimaryKeyTable) Update(store sdk.KVStore, newValue PrimaryKeyed) error // // Set iterates through the registered callbacks that may add secondary index // keys. -func (a PrimaryKeyTable) Set(store sdk.KVStore, newValue PrimaryKeyed) error { +func (a PrimaryKeyTable) Set(store storetypes.KVStore, newValue PrimaryKeyed) error { return a.table.Set(store, PrimaryKey(newValue), newValue) } @@ -94,17 +93,17 @@ func (a PrimaryKeyTable) Set(store sdk.KVStore, newValue PrimaryKeyed) error { // // Delete iterates through the registered callbacks that remove secondary index // keys. -func (a PrimaryKeyTable) Delete(store sdk.KVStore, obj PrimaryKeyed) error { +func (a PrimaryKeyTable) Delete(store storetypes.KVStore, obj PrimaryKeyed) error { return a.table.Delete(store, PrimaryKey(obj)) } // Has checks if a key exists. Always returns false on nil or empty key. -func (a PrimaryKeyTable) Has(store sdk.KVStore, primaryKey RowID) bool { +func (a PrimaryKeyTable) Has(store storetypes.KVStore, primaryKey RowID) bool { return a.table.Has(store, primaryKey) } // Contains returns true when an object with same type and primary key is persisted in this table. -func (a PrimaryKeyTable) Contains(store sdk.KVStore, obj PrimaryKeyed) bool { +func (a PrimaryKeyTable) Contains(store storetypes.KVStore, obj PrimaryKeyed) bool { if err := assertCorrectType(a.table.model, obj); err != nil { return false } @@ -113,7 +112,7 @@ func (a PrimaryKeyTable) Contains(store sdk.KVStore, obj PrimaryKeyed) bool { // GetOne loads the object persisted for the given primary Key into the dest parameter. // If none exists `ErrNotFound` is returned instead. Parameters must not be nil. -func (a PrimaryKeyTable) GetOne(store sdk.KVStore, primKey RowID, dest proto.Message) error { +func (a PrimaryKeyTable) GetOne(store storetypes.KVStore, primKey RowID, dest proto.Message) error { return a.table.GetOne(store, primKey, dest) } @@ -134,7 +133,7 @@ func (a PrimaryKeyTable) GetOne(store sdk.KVStore, primKey RowID, dest proto.Mes // it = LimitIterator(it, defaultLimit) // // CONTRACT: No writes may happen within a domain while an iterator exists over it. -func (a PrimaryKeyTable) PrefixScan(store sdk.KVStore, start, end []byte) (Iterator, error) { +func (a PrimaryKeyTable) PrefixScan(store storetypes.KVStore, start, end []byte) (Iterator, error) { return a.table.PrefixScan(store, start, end) } @@ -147,17 +146,17 @@ func (a PrimaryKeyTable) PrefixScan(store sdk.KVStore, start, end []byte) (Itera // this as an endpoint to the public without further limits. See `LimitIterator` // // CONTRACT: No writes may happen within a domain while an iterator exists over it. -func (a PrimaryKeyTable) ReversePrefixScan(store sdk.KVStore, start, end []byte) (Iterator, error) { +func (a PrimaryKeyTable) ReversePrefixScan(store storetypes.KVStore, start, end []byte) (Iterator, error) { return a.table.ReversePrefixScan(store, start, end) } // Export stores all the values in the table in the passed ModelSlicePtr. -func (a PrimaryKeyTable) Export(store sdk.KVStore, dest ModelSlicePtr) (uint64, error) { +func (a PrimaryKeyTable) Export(store storetypes.KVStore, dest ModelSlicePtr) (uint64, error) { return a.table.Export(store, dest) } // Import clears the table and initializes it from the given data interface{}. // data should be a slice of structs that implement PrimaryKeyed. -func (a PrimaryKeyTable) Import(store sdk.KVStore, data interface{}, seqValue uint64) error { +func (a PrimaryKeyTable) Import(store storetypes.KVStore, data interface{}, seqValue uint64) error { return a.table.Import(store, data, seqValue) } diff --git a/x/group/internal/orm/primary_key_property_test.go b/x/group/internal/orm/primary_key_property_test.go index ff5bb4826c8f..b74c68ba0598 100644 --- a/x/group/internal/orm/primary_key_property_test.go +++ b/x/group/internal/orm/primary_key_property_test.go @@ -6,11 +6,11 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" - sdk "github.com/cosmos/cosmos-sdk/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + "github.com/cosmos/cosmos-sdk/testutil/testdata" + "github.com/stretchr/testify/require" "pgregory.net/rapid" - - "github.com/cosmos/cosmos-sdk/testutil/testdata" ) func TestPrimaryKeyTable(t *testing.T) { @@ -20,7 +20,7 @@ func TestPrimaryKeyTable(t *testing.T) { // primaryKeyMachine is a state machine model of the PrimaryKeyTable. The state // is modelled as a map of strings to TableModels. type primaryKeyMachine struct { - store sdk.KVStore + store storetypes.KVStore table *PrimaryKeyTable state map[string]*testdata.TableModel } @@ -57,7 +57,7 @@ func (m *primaryKeyMachine) genTableModel() *rapid.Generator[*testdata.TableMode func (m *primaryKeyMachine) Init(t *rapid.T) { // Create context ctx := NewMockContext() - m.store = ctx.KVStore(sdk.NewKVStoreKey("test")) + m.store = ctx.KVStore(storetypes.NewKVStoreKey("test")) // Create primary key table interfaceRegistry := types.NewInterfaceRegistry() diff --git a/x/group/internal/orm/primary_key_test.go b/x/group/internal/orm/primary_key_test.go index 898f13282b77..c80b96b5d398 100644 --- a/x/group/internal/orm/primary_key_test.go +++ b/x/group/internal/orm/primary_key_test.go @@ -3,9 +3,10 @@ package orm import ( "testing" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" - sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/group/errors" "github.com/stretchr/testify/assert" @@ -22,7 +23,7 @@ func TestPrimaryKeyTablePrefixScan(t *testing.T) { require.NoError(t, err) ctx := NewMockContext() - store := ctx.KVStore(sdk.NewKVStoreKey("test")) + store := ctx.KVStore(storetypes.NewKVStoreKey("test")) metadata := []byte("metadata") t1 := testdata.TableModel{ @@ -50,7 +51,7 @@ func TestPrimaryKeyTablePrefixScan(t *testing.T) { expResult []testdata.TableModel expRowIDs []RowID expError *sdkerrors.Error //nolint:staticcheck // SA1019: sdkerrors.Error is deprecated: the type has been moved to cosmossdk.io/errors module. Please use the above module instead of this package. - method func(store sdk.KVStore, start, end []byte) (Iterator, error) + method func(store storetypes.KVStore, start, end []byte) (Iterator, error) }{ "exact match with a single result": { start: EncodeSequence(1), // == PrimaryKey(&t1) @@ -208,7 +209,7 @@ func TestContains(t *testing.T) { cdc := codec.NewProtoCodec(interfaceRegistry) ctx := NewMockContext() - store := ctx.KVStore(sdk.NewKVStoreKey("test")) + store := ctx.KVStore(storetypes.NewKVStoreKey("test")) tb, err := NewPrimaryKeyTable(PrimaryKeyTablePrefix, &testdata.TableModel{}, cdc) require.NoError(t, err) diff --git a/x/group/internal/orm/sequence.go b/x/group/internal/orm/sequence.go index 5e7e986ae167..20cb63f9f142 100644 --- a/x/group/internal/orm/sequence.go +++ b/x/group/internal/orm/sequence.go @@ -4,7 +4,7 @@ import ( "encoding/binary" "github.com/cosmos/cosmos-sdk/store/prefix" - sdk "github.com/cosmos/cosmos-sdk/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/group/errors" ) @@ -24,7 +24,7 @@ func NewSequence(prefix byte) Sequence { } // NextVal increments and persists the counter by one and returns the value. -func (s Sequence) NextVal(store sdk.KVStore) uint64 { +func (s Sequence) NextVal(store storetypes.KVStore) uint64 { pStore := prefix.NewStore(store, []byte{s.prefix}) v := pStore.Get(sequenceStorageKey) seq := DecodeSequence(v) @@ -34,14 +34,14 @@ func (s Sequence) NextVal(store sdk.KVStore) uint64 { } // CurVal returns the last value used. 0 if none. -func (s Sequence) CurVal(store sdk.KVStore) uint64 { +func (s Sequence) CurVal(store storetypes.KVStore) uint64 { pStore := prefix.NewStore(store, []byte{s.prefix}) v := pStore.Get(sequenceStorageKey) return DecodeSequence(v) } // PeekNextVal returns the CurVal + increment step. Not persistent. -func (s Sequence) PeekNextVal(store sdk.KVStore) uint64 { +func (s Sequence) PeekNextVal(store storetypes.KVStore) uint64 { pStore := prefix.NewStore(store, []byte{s.prefix}) v := pStore.Get(sequenceStorageKey) return DecodeSequence(v) + 1 @@ -53,7 +53,7 @@ func (s Sequence) PeekNextVal(store sdk.KVStore) uint64 { // // It is recommended to call this method only for a sequence start value other than `1` as the // method consumes unnecessary gas otherwise. A scenario would be an import from genesis. -func (s Sequence) InitVal(store sdk.KVStore, seq uint64) error { +func (s Sequence) InitVal(store storetypes.KVStore, seq uint64) error { pStore := prefix.NewStore(store, []byte{s.prefix}) if pStore.Has(sequenceStorageKey) { return sdkerrors.Wrap(errors.ErrORMUniqueConstraint, "already initialized") diff --git a/x/group/internal/orm/sequence_property_test.go b/x/group/internal/orm/sequence_property_test.go index 3525f890d320..066ad25dfd7b 100644 --- a/x/group/internal/orm/sequence_property_test.go +++ b/x/group/internal/orm/sequence_property_test.go @@ -4,7 +4,8 @@ package orm import ( "testing" - sdk "github.com/cosmos/cosmos-sdk/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + "github.com/stretchr/testify/require" "pgregory.net/rapid" ) @@ -16,7 +17,7 @@ func TestSequence(t *testing.T) { // sequenceMachine is a state machine model of Sequence. It simply uses a uint64 // as the model of the sequence. type sequenceMachine struct { - store sdk.KVStore + store storetypes.KVStore seq *Sequence state uint64 } @@ -26,7 +27,7 @@ type sequenceMachine struct { func (m *sequenceMachine) Init(t *rapid.T) { // Create context and KV store ctx := NewMockContext() - m.store = ctx.KVStore(sdk.NewKVStoreKey("test")) + m.store = ctx.KVStore(storetypes.NewKVStoreKey("test")) // Create primary key table seq := NewSequence(0x1) diff --git a/x/group/internal/orm/sequence_test.go b/x/group/internal/orm/sequence_test.go index a1a3ddef20ca..579ba4b14d77 100644 --- a/x/group/internal/orm/sequence_test.go +++ b/x/group/internal/orm/sequence_test.go @@ -3,7 +3,7 @@ package orm import ( "testing" - sdk "github.com/cosmos/cosmos-sdk/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/x/group/errors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -11,7 +11,7 @@ import ( func TestSequenceUniqueConstraint(t *testing.T) { ctx := NewMockContext() - store := ctx.KVStore(sdk.NewKVStoreKey("test")) + store := ctx.KVStore(storetypes.NewKVStoreKey("test")) seq := NewSequence(0x1) err := seq.InitVal(store, 2) @@ -22,7 +22,7 @@ func TestSequenceUniqueConstraint(t *testing.T) { func TestSequenceIncrements(t *testing.T) { ctx := NewMockContext() - store := ctx.KVStore(sdk.NewKVStoreKey("test")) + store := ctx.KVStore(storetypes.NewKVStoreKey("test")) seq := NewSequence(0x1) var i uint64 diff --git a/x/group/internal/orm/table.go b/x/group/internal/orm/table.go index 4209cfb134f0..7d21f05fb707 100644 --- a/x/group/internal/orm/table.go +++ b/x/group/internal/orm/table.go @@ -9,7 +9,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store/prefix" "github.com/cosmos/cosmos-sdk/store/types" - sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/group/errors" ) @@ -73,7 +72,7 @@ func (a *table) AddAfterDeleteInterceptor(interceptor AfterDeleteInterceptor) { // // Create iterates through the registered callbacks that may add secondary index // keys. -func (a table) Create(store sdk.KVStore, rowID RowID, obj proto.Message) error { +func (a table) Create(store types.KVStore, rowID RowID, obj proto.Message) error { if a.Has(store, rowID) { return errors.ErrORMUniqueConstraint } @@ -87,7 +86,7 @@ func (a table) Create(store sdk.KVStore, rowID RowID, obj proto.Message) error { // nil. // // Update triggers all "after set" hooks that may add or remove secondary index keys. -func (a table) Update(store sdk.KVStore, rowID RowID, newValue proto.Message) error { +func (a table) Update(store types.KVStore, rowID RowID, newValue proto.Message) error { if !a.Has(store, rowID) { return sdkerrors.ErrNotFound } @@ -100,7 +99,7 @@ func (a table) Update(store sdk.KVStore, rowID RowID, newValue proto.Message) er // // Set iterates through the registered callbacks that may add secondary index // keys. -func (a table) Set(store sdk.KVStore, rowID RowID, newValue proto.Message) error { +func (a table) Set(store types.KVStore, rowID RowID, newValue proto.Message) error { if len(rowID) == 0 { return errors.ErrORMEmptyKey } @@ -148,7 +147,7 @@ func assertValid(obj proto.Message) error { // // Delete iterates through the registered callbacks that remove secondary index // keys. -func (a table) Delete(store sdk.KVStore, rowID RowID) error { +func (a table) Delete(store types.KVStore, rowID RowID) error { pStore := prefix.NewStore(store, a.prefix[:]) oldValue := reflect.New(a.model).Interface().(proto.Message) @@ -167,7 +166,7 @@ func (a table) Delete(store sdk.KVStore, rowID RowID) error { // Has checks if a key exists. Returns false when the key is empty or nil // because we don't allow creation of values without a key. -func (a table) Has(store sdk.KVStore, key RowID) bool { +func (a table) Has(store types.KVStore, key RowID) bool { if len(key) == 0 { return false } @@ -178,7 +177,7 @@ func (a table) Has(store sdk.KVStore, key RowID) bool { // GetOne load the object persisted for the given RowID into the dest parameter. // If none exists or `rowID==nil` then `sdkerrors.ErrNotFound` is returned instead. // Parameters must not be nil - we don't allow creation of values with empty keys. -func (a table) GetOne(store sdk.KVStore, rowID RowID, dest proto.Message) error { +func (a table) GetOne(store types.KVStore, rowID RowID, dest proto.Message) error { if len(rowID) == 0 { return sdkerrors.ErrNotFound } @@ -203,7 +202,7 @@ func (a table) GetOne(store sdk.KVStore, rowID RowID, dest proto.Message) error // it = LimitIterator(it, defaultLimit) // // CONTRACT: No writes may happen within a domain while an iterator exists over it. -func (a table) PrefixScan(store sdk.KVStore, start, end RowID) (Iterator, error) { +func (a table) PrefixScan(store types.KVStore, start, end RowID) (Iterator, error) { if start != nil && end != nil && bytes.Compare(start, end) >= 0 { return NewInvalidIterator(), sdkerrors.Wrap(errors.ErrORMInvalidArgument, "start must be before end") } @@ -224,7 +223,7 @@ func (a table) PrefixScan(store sdk.KVStore, start, end RowID) (Iterator, error) // this as an endpoint to the public without further limits. See `LimitIterator` // // CONTRACT: No writes may happen within a domain while an iterator exists over it. -func (a table) ReversePrefixScan(store sdk.KVStore, start, end RowID) (Iterator, error) { +func (a table) ReversePrefixScan(store types.KVStore, start, end RowID) (Iterator, error) { if start != nil && end != nil && bytes.Compare(start, end) >= 0 { return NewInvalidIterator(), sdkerrors.Wrap(errors.ErrORMInvalidArgument, "start must be before end") } @@ -237,7 +236,7 @@ func (a table) ReversePrefixScan(store sdk.KVStore, start, end RowID) (Iterator, } // Export stores all the values in the table in the passed ModelSlicePtr. -func (a table) Export(store sdk.KVStore, dest ModelSlicePtr) (uint64, error) { +func (a table) Export(store types.KVStore, dest ModelSlicePtr) (uint64, error) { it, err := a.PrefixScan(store, nil, nil) if err != nil { return 0, sdkerrors.Wrap(err, "table Export failure when exporting table data") @@ -251,7 +250,7 @@ func (a table) Export(store sdk.KVStore, dest ModelSlicePtr) (uint64, error) { // Import clears the table and initializes it from the given data interface{}. // data should be a slice of structs that implement PrimaryKeyed. -func (a table) Import(store sdk.KVStore, data interface{}, _ uint64) error { +func (a table) Import(store types.KVStore, data interface{}, _ uint64) error { // Clear all data keys := a.keys(store) for _, key := range keys { @@ -281,7 +280,7 @@ func (a table) Import(store sdk.KVStore, data interface{}, _ uint64) error { return nil } -func (a table) keys(store sdk.KVStore) [][]byte { +func (a table) keys(store types.KVStore) [][]byte { pStore := prefix.NewStore(store, a.prefix[:]) it := pStore.Iterator(nil, nil) defer it.Close() @@ -295,7 +294,7 @@ func (a table) keys(store sdk.KVStore) [][]byte { // typeSafeIterator is initialized with a type safe RowGetter only. type typeSafeIterator struct { - store sdk.KVStore + store types.KVStore rowGetter RowGetter it types.Iterator } diff --git a/x/group/internal/orm/table_test.go b/x/group/internal/orm/table_test.go index 27633a0cc0a6..6dd363ae64ed 100644 --- a/x/group/internal/orm/table_test.go +++ b/x/group/internal/orm/table_test.go @@ -10,8 +10,8 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil/testdata" - sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/group/errors" ) @@ -97,7 +97,7 @@ func TestCreate(t *testing.T) { cdc := codec.NewProtoCodec(interfaceRegistry) ctx := NewMockContext() - store := ctx.KVStore(sdk.NewKVStoreKey("test")) + store := ctx.KVStore(storetypes.NewKVStoreKey("test")) anyPrefix := [2]byte{0x10} myTable, err := newTable(anyPrefix, &testdata.TableModel{}, cdc) @@ -154,7 +154,7 @@ func TestUpdate(t *testing.T) { cdc := codec.NewProtoCodec(interfaceRegistry) ctx := NewMockContext() - store := ctx.KVStore(sdk.NewKVStoreKey("test")) + store := ctx.KVStore(storetypes.NewKVStoreKey("test")) anyPrefix := [2]byte{0x10} myTable, err := newTable(anyPrefix, &testdata.TableModel{}, cdc) @@ -203,7 +203,7 @@ func TestDelete(t *testing.T) { cdc := codec.NewProtoCodec(interfaceRegistry) ctx := NewMockContext() - store := ctx.KVStore(sdk.NewKVStoreKey("test")) + store := ctx.KVStore(storetypes.NewKVStoreKey("test")) anyPrefix := [2]byte{0x10} myTable, err := newTable(anyPrefix, &testdata.TableModel{}, cdc) diff --git a/x/group/internal/orm/testsupport.go b/x/group/internal/orm/testsupport.go index f13ddd899e5f..557f6a97fc40 100644 --- a/x/group/internal/orm/testsupport.go +++ b/x/group/internal/orm/testsupport.go @@ -10,7 +10,6 @@ import ( "github.com/cosmos/cosmos-sdk/store/gaskv" "github.com/cosmos/cosmos-sdk/store/metrics" storetypes "github.com/cosmos/cosmos-sdk/store/types" - sdk "github.com/cosmos/cosmos-sdk/types" ) type MockContext struct { @@ -26,7 +25,7 @@ func NewMockContext() *MockContext { } } -func (m MockContext) KVStore(key storetypes.StoreKey) sdk.KVStore { +func (m MockContext) KVStore(key storetypes.StoreKey) storetypes.KVStore { if s := m.store.GetCommitKVStore(key); s != nil { return s } @@ -79,16 +78,16 @@ func (d debuggingGasMeter) String() string { } type GasCountingMockContext struct { - GasMeter sdk.GasMeter + GasMeter storetypes.GasMeter } func NewGasCountingMockContext() *GasCountingMockContext { return &GasCountingMockContext{ - GasMeter: &debuggingGasMeter{sdk.NewInfiniteGasMeter()}, + GasMeter: &debuggingGasMeter{storetypes.NewInfiniteGasMeter()}, } } -func (g GasCountingMockContext) KVStore(store sdk.KVStore) sdk.KVStore { +func (g GasCountingMockContext) KVStore(store storetypes.KVStore) storetypes.KVStore { return gaskv.NewStore(store, g.GasMeter, storetypes.KVGasConfig()) } @@ -101,5 +100,5 @@ func (g GasCountingMockContext) GasRemaining() storetypes.Gas { } func (g *GasCountingMockContext) ResetGasMeter() { - g.GasMeter = sdk.NewInfiniteGasMeter() + g.GasMeter = storetypes.NewInfiniteGasMeter() } diff --git a/x/group/internal/orm/types.go b/x/group/internal/orm/types.go index ffc43bf97816..bdb32a4f2377 100644 --- a/x/group/internal/orm/types.go +++ b/x/group/internal/orm/types.go @@ -11,7 +11,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store/prefix" - sdk "github.com/cosmos/cosmos-sdk/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/query" "github.com/cosmos/cosmos-sdk/x/group/errors" @@ -36,15 +36,15 @@ type Validateable interface { // variable length and scanned iteratively. type Index interface { // Has checks if a key exists. Panics on nil key. - Has(store sdk.KVStore, key interface{}) (bool, error) + Has(store storetypes.KVStore, key interface{}) (bool, error) // Get returns a result iterator for the searchKey. // searchKey must not be nil. - Get(store sdk.KVStore, searchKey interface{}) (Iterator, error) + Get(store storetypes.KVStore, searchKey interface{}) (Iterator, error) // GetPaginated returns a result iterator for the searchKey and optional pageRequest. // searchKey must not be nil. - GetPaginated(store sdk.KVStore, searchKey interface{}, pageRequest *query.PageRequest) (Iterator, error) + GetPaginated(store storetypes.KVStore, searchKey interface{}, pageRequest *query.PageRequest) (Iterator, error) // PrefixScan returns an Iterator over a domain of keys in ascending order. End is exclusive. // Start is an MultiKeyIndex key or prefix. It must be less than end, or the Iterator is invalid and error is returned. @@ -62,7 +62,7 @@ type Index interface { // it = LimitIterator(it, defaultLimit) // // CONTRACT: No writes may happen within a domain while an iterator exists over it. - PrefixScan(store sdk.KVStore, startI interface{}, endI interface{}) (Iterator, error) + PrefixScan(store storetypes.KVStore, startI interface{}, endI interface{}) (Iterator, error) // ReversePrefixScan returns an Iterator over a domain of keys in descending order. End is exclusive. // Start is an MultiKeyIndex key or prefix. It must be less than end, or the Iterator is invalid and error is returned. @@ -73,7 +73,7 @@ type Index interface { // this as an endpoint to the public without further limits. See `LimitIterator` // // CONTRACT: No writes may happen within a domain while an iterator exists over it. - ReversePrefixScan(store sdk.KVStore, startI interface{}, endI interface{}) (Iterator, error) + ReversePrefixScan(store storetypes.KVStore, startI interface{}, endI interface{}) (Iterator, error) } // Iterator allows iteration through a sequence of key value pairs @@ -95,18 +95,18 @@ type Indexable interface { } // AfterSetInterceptor defines a callback function to be called on Create + Update. -type AfterSetInterceptor func(store sdk.KVStore, rowID RowID, newValue, oldValue proto.Message) error +type AfterSetInterceptor func(store storetypes.KVStore, rowID RowID, newValue, oldValue proto.Message) error // AfterDeleteInterceptor defines a callback function to be called on Delete operations. -type AfterDeleteInterceptor func(store sdk.KVStore, rowID RowID, value proto.Message) error +type AfterDeleteInterceptor func(store storetypes.KVStore, rowID RowID, value proto.Message) error // RowGetter loads a persistent object by row ID into the destination object. The dest parameter must therefore be a pointer. // Any implementation must return `sdkerrors.ErrNotFound` when no object for the rowID exists -type RowGetter func(store sdk.KVStore, rowID RowID, dest proto.Message) error +type RowGetter func(store storetypes.KVStore, rowID RowID, dest proto.Message) error // NewTypeSafeRowGetter returns a `RowGetter` with type check on the dest parameter. func NewTypeSafeRowGetter(prefixKey [2]byte, model reflect.Type, cdc codec.Codec) RowGetter { - return func(store sdk.KVStore, rowID RowID, dest proto.Message) error { + return func(store storetypes.KVStore, rowID RowID, dest proto.Message) error { if len(rowID) == 0 { return sdkerrors.Wrap(errors.ErrORMEmptyKey, "key must not be nil") } diff --git a/x/group/internal/orm/types_test.go b/x/group/internal/orm/types_test.go index 94c05d0c4314..6d5aa80ce7f7 100644 --- a/x/group/internal/orm/types_test.go +++ b/x/group/internal/orm/types_test.go @@ -7,8 +7,8 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/store/prefix" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil/testdata" - sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/group/errors" "github.com/stretchr/testify/assert" @@ -16,7 +16,7 @@ import ( ) func TestTypeSafeRowGetter(t *testing.T) { - storeKey := sdk.NewKVStoreKey("test") + storeKey := storetypes.NewKVStoreKey("test") ctx := NewMockContext() prefixKey := [2]byte{0x2} store := prefix.NewStore(ctx.KVStore(storeKey), prefixKey[:]) diff --git a/x/group/keeper/genesis_test.go b/x/group/keeper/genesis_test.go index a5f27fba960c..442997d99d03 100644 --- a/x/group/keeper/genesis_test.go +++ b/x/group/keeper/genesis_test.go @@ -13,9 +13,9 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" - moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" @@ -46,8 +46,8 @@ var ( ) func (s *GenesisTestSuite) SetupTest() { - key := sdk.NewKVStoreKey(group.StoreKey) - testCtx := testutil.DefaultContextWithDB(s.T(), key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(group.StoreKey) + testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(module.AppModuleBasic{}) ctrl := gomock.NewController(s.T()) diff --git a/x/group/keeper/grpc_query_test.go b/x/group/keeper/grpc_query_test.go index e71b8df51c9c..8e0b0375de70 100644 --- a/x/group/keeper/grpc_query_test.go +++ b/x/group/keeper/grpc_query_test.go @@ -4,24 +4,22 @@ import ( "context" "testing" + "github.com/golang/mock/gomock" + "github.com/stretchr/testify/require" + "github.com/tendermint/tendermint/libs/log" + "github.com/cosmos/cosmos-sdk/baseapp" codectypes "github.com/cosmos/cosmos-sdk/codec/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + "github.com/cosmos/cosmos-sdk/testutil" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" - sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/group" groupkeeper "github.com/cosmos/cosmos-sdk/x/group/keeper" "github.com/cosmos/cosmos-sdk/x/group/module" - "github.com/golang/mock/gomock" - "github.com/tendermint/tendermint/libs/log" - grouptestutil "github.com/cosmos/cosmos-sdk/x/group/testutil" - - "github.com/stretchr/testify/require" - - "github.com/cosmos/cosmos-sdk/testutil" ) func TestQueryGroupsByMember(t *testing.T) { @@ -30,8 +28,8 @@ func TestQueryGroupsByMember(t *testing.T) { interfaceRegistry codectypes.InterfaceRegistry ) - key := sdk.NewKVStoreKey(group.StoreKey) - testCtx := testutil.DefaultContextWithDB(t, key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(group.StoreKey) + testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(module.AppModuleBasic{}) ctx := testCtx.Ctx diff --git a/x/group/keeper/invariants_test.go b/x/group/keeper/invariants_test.go index 8e189574327e..f93b12eba227 100644 --- a/x/group/keeper/invariants_test.go +++ b/x/group/keeper/invariants_test.go @@ -12,7 +12,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/store" - "github.com/cosmos/cosmos-sdk/store/metrics" storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil/testdata" @@ -38,7 +37,7 @@ func (s *invariantTestSuite) SetupSuite() { interfaceRegistry := types.NewInterfaceRegistry() group.RegisterInterfaces(interfaceRegistry) cdc := codec.NewProtoCodec(interfaceRegistry) - key := sdk.NewKVStoreKey(group.ModuleName) + key := storetypes.NewKVStoreKey(group.ModuleName) db := dbm.NewMemDB() cms := store.NewCommitMultiStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics()) cms.MountStoreWithDB(key, storetypes.StoreTypeIAVL, db) diff --git a/x/group/keeper/keeper_test.go b/x/group/keeper/keeper_test.go index 0cf53ab3ccf8..e4e28bd867be 100644 --- a/x/group/keeper/keeper_test.go +++ b/x/group/keeper/keeper_test.go @@ -16,6 +16,7 @@ import ( tmtime "github.com/tendermint/tendermint/types/time" "github.com/cosmos/cosmos-sdk/baseapp" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" "github.com/cosmos/cosmos-sdk/testutil/testdata" @@ -51,9 +52,9 @@ type TestSuite struct { func (s *TestSuite) SetupTest() { s.blockTime = tmtime.Now() - key := sdk.NewKVStoreKey(group.StoreKey) + key := storetypes.NewKVStoreKey(group.StoreKey) - testCtx := testutil.DefaultContextWithDB(s.T(), key, sdk.NewTransientStoreKey("transient_test")) + testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(module.AppModuleBasic{}, bank.AppModuleBasic{}) s.addrs = simtestutil.CreateIncrementalAccounts(6) diff --git a/x/group/migrations/v2/migrate_test.go b/x/group/migrations/v2/migrate_test.go index 97730216796d..2627ba46540e 100644 --- a/x/group/migrations/v2/migrate_test.go +++ b/x/group/migrations/v2/migrate_test.go @@ -30,8 +30,8 @@ var ( func TestMigrate(t *testing.T) { cdc := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{}, groupmodule.AppModuleBasic{}).Codec - storeKey := sdk.NewKVStoreKey(v2.ModuleName) - tKey := sdk.NewTransientStoreKey("transient_test") + storeKey := storetypes.NewKVStoreKey(v2.ModuleName) + tKey := storetypes.NewTransientStoreKey("transient_test") ctx := testutil.DefaultContext(storeKey, tKey) accountKeeper := createOldPolicyAccount(ctx, storeKey, cdc) diff --git a/x/group/module/module.go b/x/group/module/module.go index 4d42e0dbf1f6..4dda150725a3 100644 --- a/x/group/module/module.go +++ b/x/group/module/module.go @@ -179,7 +179,7 @@ func (am AppModule) ProposalContents(simState module.SimulationState) []simtypes } // RegisterStoreDecoder registers a decoder for group module's types -func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { +func (am AppModule) RegisterStoreDecoder(sdr store.StoreDecoderRegistry) { sdr[group.StoreKey] = simulation.NewDecodeStore(am.cdc) } diff --git a/x/mint/keeper/genesis_test.go b/x/mint/keeper/genesis_test.go index 5a88558613c4..1bf8bcffc3a5 100644 --- a/x/mint/keeper/genesis_test.go +++ b/x/mint/keeper/genesis_test.go @@ -36,8 +36,8 @@ func TestGenesisTestSuite(t *testing.T) { } func (s *GenesisTestSuite) SetupTest() { - key := sdk.NewKVStoreKey(types.StoreKey) - testCtx := testutil.DefaultContextWithDB(s.T(), key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(types.StoreKey) + testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(mint.AppModuleBasic{}) // gomock initializations @@ -73,7 +73,7 @@ func (s *GenesisTestSuite) TestImportExportGenesis() { minter := s.keeper.GetMinter(s.sdkCtx) s.Require().Equal(genesisState.Minter, minter) - invalidCtx := testutil.DefaultContextWithDB(s.T(), s.key, sdk.NewTransientStoreKey("transient_test")) + invalidCtx := testutil.DefaultContextWithDB(s.T(), s.key, storetypes.NewTransientStoreKey("transient_test")) s.Require().Panics(func() { s.keeper.GetMinter(invalidCtx.Ctx) }, "stored minter should not have been nil") params := s.keeper.GetParams(s.sdkCtx) s.Require().Equal(genesisState.Params, params) diff --git a/x/mint/keeper/grpc_query_test.go b/x/mint/keeper/grpc_query_test.go index 34c7751f3099..50536da48eb8 100644 --- a/x/mint/keeper/grpc_query_test.go +++ b/x/mint/keeper/grpc_query_test.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/suite" "github.com/cosmos/cosmos-sdk/baseapp" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -29,8 +30,8 @@ type MintTestSuite struct { func (suite *MintTestSuite) SetupTest() { encCfg := moduletestutil.MakeTestEncodingConfig(mint.AppModuleBasic{}) - key := sdk.NewKVStoreKey(types.StoreKey) - testCtx := testutil.DefaultContextWithDB(suite.T(), key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(types.StoreKey) + testCtx := testutil.DefaultContextWithDB(suite.T(), key, storetypes.NewTransientStoreKey("transient_test")) suite.ctx = testCtx.Ctx // gomock initializations diff --git a/x/mint/keeper/keeper_test.go b/x/mint/keeper/keeper_test.go index 3f39387eede4..4a9fb4a9eccf 100644 --- a/x/mint/keeper/keeper_test.go +++ b/x/mint/keeper/keeper_test.go @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/suite" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -33,8 +34,8 @@ func TestKeeperTestSuite(t *testing.T) { func (s *IntegrationTestSuite) SetupTest() { encCfg := moduletestutil.MakeTestEncodingConfig(mint.AppModuleBasic{}) - key := sdk.NewKVStoreKey(types.StoreKey) - testCtx := testutil.DefaultContextWithDB(s.T(), key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(types.StoreKey) + testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) s.ctx = testCtx.Ctx // gomock initializations diff --git a/x/mint/migrations/v2/migrate.go b/x/mint/migrations/v2/migrate.go index 22f814ffc6d5..2a56461611e4 100644 --- a/x/mint/migrations/v2/migrate.go +++ b/x/mint/migrations/v2/migrate.go @@ -2,6 +2,7 @@ package v2 import ( "github.com/cosmos/cosmos-sdk/codec" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/mint/exported" "github.com/cosmos/cosmos-sdk/x/mint/types" @@ -19,7 +20,7 @@ var ParamsKey = []byte{0x01} // module state. func Migrate( ctx sdk.Context, - store sdk.KVStore, + store storetypes.KVStore, legacySubspace exported.Subspace, cdc codec.BinaryCodec, ) error { diff --git a/x/mint/migrations/v2/migrator_test.go b/x/mint/migrations/v2/migrator_test.go index 86f27ee2e679..f4991c427eab 100644 --- a/x/mint/migrations/v2/migrator_test.go +++ b/x/mint/migrations/v2/migrator_test.go @@ -5,6 +5,7 @@ import ( "github.com/stretchr/testify/require" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -30,8 +31,8 @@ func TestMigrate(t *testing.T) { encCfg := moduletestutil.MakeTestEncodingConfig(mint.AppModuleBasic{}) cdc := encCfg.Codec - storeKey := sdk.NewKVStoreKey(v2.ModuleName) - tKey := sdk.NewTransientStoreKey("transient_test") + storeKey := storetypes.NewKVStoreKey(v2.ModuleName) + tKey := storetypes.NewTransientStoreKey("transient_test") ctx := testutil.DefaultContext(storeKey, tKey) store := ctx.KVStore(storeKey) diff --git a/x/mint/module.go b/x/mint/module.go index 74ce26995aa1..46beaa7b16c0 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -196,7 +196,7 @@ func (AppModule) ProposalContents(simState module.SimulationState) []simtypes.We } // RegisterStoreDecoder registers a decoder for mint module's types. -func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { +func (am AppModule) RegisterStoreDecoder(sdr store.StoreDecoderRegistry) { sdr[types.StoreKey] = simulation.NewDecodeStore(am.cdc) } diff --git a/x/nft/go.mod b/x/nft/go.mod index c0f61e3d5777..556a04946861 100644 --- a/x/nft/go.mod +++ b/x/nft/go.mod @@ -141,10 +141,12 @@ require ( gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect nhooyr.io/websocket v1.8.6 // indirect - pgregory.net/rapid v0.5.3 // indirect + pgregory.net/rapid v0.5.5 // indirect sigs.k8s.io/yaml v1.3.0 // indirect ) // Fix upstream GHSA-h395-qcrw-5vmq vulnerability. // TODO Remove it: https://github.com/cosmos/cosmos-sdk/issues/10409 replace github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.8.1 + +replace github.com/cosmos/cosmos-sdk => ../.. diff --git a/x/nft/go.sum b/x/nft/go.sum index d3c0926569fa..69ca752fbb9f 100644 --- a/x/nft/go.sum +++ b/x/nft/go.sum @@ -172,8 +172,6 @@ github.com/cosmos/cosmos-db v0.0.0-20221226095112-f3c38ecb5e32 h1:zlCp9n3uwQieEL github.com/cosmos/cosmos-db v0.0.0-20221226095112-f3c38ecb5e32/go.mod h1:kwMlEC4wWvB48zAShGKVqboJL6w4zCLesaNQ3YLU2BQ= github.com/cosmos/cosmos-proto v1.0.0-beta.1 h1:iDL5qh++NoXxG8hSy93FdYJut4XfgbShIocllGaXx/0= github.com/cosmos/cosmos-proto v1.0.0-beta.1/go.mod h1:8k2GNZghi5sDRFw/scPL8gMSowT1vDA+5ouxL8GjaUE= -github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230109172818-c9acb1bd72b3 h1:Kk0SfHabO8FLJpstdrvh7AhwMLwGCrLUbTnU/Z6oyLk= -github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230109172818-c9acb1bd72b3/go.mod h1:/XgmiZsL/GbKAZpmEJ/WeVWXmZXw5jUuBEyXnVyIltU= github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y= github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY= github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw= @@ -1293,8 +1291,8 @@ honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9 honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= nhooyr.io/websocket v1.8.6 h1:s+C3xAMLwGmlI31Nyn/eAehUlZPwfYZu2JXM621Q5/k= nhooyr.io/websocket v1.8.6/go.mod h1:B70DZP8IakI65RVQ51MsWP/8jndNma26DVA/nFSCgW0= -pgregory.net/rapid v0.5.3 h1:163N50IHFqr1phZens4FQOdPgfJscR7a562mjQqeo4M= -pgregory.net/rapid v0.5.3/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04= +pgregory.net/rapid v0.5.5 h1:jkgx1TjbQPD/feRoK+S/mXw9e1uj6WilpHrXJowi6oA= +pgregory.net/rapid v0.5.5/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= diff --git a/x/nft/keeper/class.go b/x/nft/keeper/class.go index 00bbd90e1639..70f6555ef6f3 100644 --- a/x/nft/keeper/class.go +++ b/x/nft/keeper/class.go @@ -1,6 +1,7 @@ package keeper import ( + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/nft" @@ -50,7 +51,7 @@ func (k Keeper) GetClass(ctx sdk.Context, classID string) (nft.Class, bool) { // GetClasses defines a method for returning all classes information func (k Keeper) GetClasses(ctx sdk.Context) (classes []*nft.Class) { store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, ClassKey) + iterator := storetypes.KVStorePrefixIterator(store, ClassKey) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { var class nft.Class diff --git a/x/nft/keeper/keeper_test.go b/x/nft/keeper/keeper_test.go index 831541ee6bb2..3540cc74f74c 100644 --- a/x/nft/keeper/keeper_test.go +++ b/x/nft/keeper/keeper_test.go @@ -9,6 +9,7 @@ import ( tmtime "github.com/tendermint/tendermint/types/time" "github.com/cosmos/cosmos-sdk/baseapp" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" @@ -47,8 +48,8 @@ func (s *TestSuite) SetupTest() { s.addrs = simtestutil.CreateIncrementalAccounts(3) s.encCfg = moduletestutil.MakeTestEncodingConfig(module.AppModuleBasic{}) - key := sdk.NewKVStoreKey(nft.StoreKey) - testCtx := testutil.DefaultContextWithDB(s.T(), key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(nft.StoreKey) + testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) ctx := testCtx.Ctx.WithBlockHeader(tmproto.Header{Time: tmtime.Now()}) // gomock initializations diff --git a/x/nft/module/module.go b/x/nft/module/module.go index d4036f55faaa..7017bc0fd89d 100644 --- a/x/nft/module/module.go +++ b/x/nft/module/module.go @@ -168,7 +168,7 @@ func (am AppModule) ProposalContents(simState module.SimulationState) []simtypes } // RegisterStoreDecoder registers a decoder for nft module's types -func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { +func (am AppModule) RegisterStoreDecoder(sdr store.StoreDecoderRegistry) { sdr[keeper.StoreKey] = simulation.NewDecodeStore(am.cdc) } diff --git a/x/params/keeper/common_test.go b/x/params/keeper/common_test.go index 27b6295a65b1..0c2e821f6d8a 100644 --- a/x/params/keeper/common_test.go +++ b/x/params/keeper/common_test.go @@ -17,8 +17,8 @@ func testComponents() (*codec.LegacyAmino, sdk.Context, storetypes.StoreKey, sto } legacyAmino := createTestCodec() - mkey := sdk.NewKVStoreKey("test") - tkey := sdk.NewTransientStoreKey("transient_test") + mkey := storetypes.NewKVStoreKey("test") + tkey := storetypes.NewTransientStoreKey("transient_test") ctx := sdktestutil.DefaultContext(mkey, tkey) keeper := paramskeeper.NewKeeper(cdc, legacyAmino, mkey, tkey) diff --git a/x/params/keeper/keeper_test.go b/x/params/keeper/keeper_test.go index 367123d6ddf7..015be7f4120a 100644 --- a/x/params/keeper/keeper_test.go +++ b/x/params/keeper/keeper_test.go @@ -10,6 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/store/prefix" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -29,8 +30,8 @@ type KeeperTestSuite struct { func (suite *KeeperTestSuite) SetupTest() { encodingCfg := moduletestutil.MakeTestEncodingConfig(params.AppModuleBasic{}) - key := sdk.NewKVStoreKey(types.StoreKey) - tkey := sdk.NewTransientStoreKey("params_transient_test") + key := storetypes.NewKVStoreKey(types.StoreKey) + tkey := storetypes.NewTransientStoreKey("params_transient_test") suite.ctx = testutil.DefaultContext(key, tkey) suite.paramsKeeper = keeper.NewKeeper(encodingCfg.Codec, encodingCfg.Amino, key, tkey) diff --git a/x/params/module.go b/x/params/module.go index 4e4f09589804..a4dab2ba70e8 100644 --- a/x/params/module.go +++ b/x/params/module.go @@ -120,7 +120,7 @@ func (am AppModule) ProposalContents(simState module.SimulationState) []simtypes } // RegisterStoreDecoder doesn't register any type. -func (AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) {} +func (AppModule) RegisterStoreDecoder(sdr store.StoreDecoderRegistry) {} // WeightedOperations returns the all the gov module operations with their respective weights. func (am AppModule) WeightedOperations(_ module.SimulationState) []simtypes.WeightedOperation { diff --git a/x/params/proposal_handler_test.go b/x/params/proposal_handler_test.go index 63a2a5c2beb7..d1ae692af4f1 100644 --- a/x/params/proposal_handler_test.go +++ b/x/params/proposal_handler_test.go @@ -3,11 +3,10 @@ package params_test import ( "testing" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/golang/mock/gomock" "github.com/stretchr/testify/suite" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -17,6 +16,7 @@ import ( paramstestutil "github.com/cosmos/cosmos-sdk/x/params/testutil" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/cosmos/cosmos-sdk/x/params/types/proposal" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) // StakingKeeper defines the expected staking keeper @@ -34,8 +34,8 @@ type HandlerTestSuite struct { func (suite *HandlerTestSuite) SetupTest() { encodingCfg := moduletestutil.MakeTestEncodingConfig(params.AppModuleBasic{}) - key := sdk.NewKVStoreKey(paramtypes.StoreKey) - tkey := sdk.NewTransientStoreKey("params_transient_test") + key := storetypes.NewKVStoreKey(paramtypes.StoreKey) + tkey := storetypes.NewTransientStoreKey("params_transient_test") ctx := testutil.DefaultContext(key, tkey) paramsKeeper := keeper.NewKeeper(encodingCfg.Codec, encodingCfg.Amino, key, tkey) diff --git a/x/params/types/common_test.go b/x/params/types/common_test.go index 1228aeb8c015..d4d98b05a388 100644 --- a/x/params/types/common_test.go +++ b/x/params/types/common_test.go @@ -5,7 +5,7 @@ import ( "fmt" "time" - sdk "github.com/cosmos/cosmos-sdk/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/x/params/types" ) @@ -15,8 +15,8 @@ var ( keyBondDenom = []byte("BondDenom") keyMaxRedelegationEntries = []byte("MaxRedelegationEntries") - key = sdk.NewKVStoreKey("storekey") - tkey = sdk.NewTransientStoreKey("transientstorekey") + key = storetypes.NewKVStoreKey("storekey") + tkey = storetypes.NewTransientStoreKey("transientstorekey") ) type params struct { diff --git a/x/params/types/subspace.go b/x/params/types/subspace.go index f90914f3a62a..3f6d04083064 100644 --- a/x/params/types/subspace.go +++ b/x/params/types/subspace.go @@ -70,14 +70,14 @@ func (s Subspace) WithKeyTable(table KeyTable) Subspace { } // Returns a KVStore identical with ctx.KVStore(s.key).Prefix() -func (s Subspace) kvStore(ctx sdk.Context) sdk.KVStore { +func (s Subspace) kvStore(ctx sdk.Context) storetypes.KVStore { // append here is safe, appends within a function won't cause // weird side effects when its singlethreaded return prefix.NewStore(ctx.KVStore(s.key), append(s.name, '/')) } // Returns a transient store for modification -func (s Subspace) transientStore(ctx sdk.Context) sdk.KVStore { +func (s Subspace) transientStore(ctx sdk.Context) storetypes.KVStore { // append here is safe, appends within a function won't cause // weird side effects when its singlethreaded return prefix.NewStore(ctx.TransientStore(s.tkey), append(s.name, '/')) @@ -134,7 +134,7 @@ func (s Subspace) GetIfExists(ctx sdk.Context, key []byte, ptr interface{}) { func (s Subspace) IterateKeys(ctx sdk.Context, cb func(key []byte) bool) { store := s.kvStore(ctx) - iter := sdk.KVStorePrefixIterator(store, nil) + iter := storetypes.KVStorePrefixIterator(store, nil) defer iter.Close() for ; iter.Valid(); iter.Next() { diff --git a/x/slashing/keeper/keeper.go b/x/slashing/keeper/keeper.go index a3dad9ea1fb0..4b6196c18117 100644 --- a/x/slashing/keeper/keeper.go +++ b/x/slashing/keeper/keeper.go @@ -3,11 +3,11 @@ package keeper import ( "fmt" - storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/tendermint/tendermint/libs/log" "github.com/cosmos/cosmos-sdk/codec" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" diff --git a/x/slashing/keeper/keeper_test.go b/x/slashing/keeper/keeper_test.go index 10f9d980f9ee..324b941ca8c6 100644 --- a/x/slashing/keeper/keeper_test.go +++ b/x/slashing/keeper/keeper_test.go @@ -10,6 +10,7 @@ import ( tmtime "github.com/tendermint/tendermint/types/time" "github.com/cosmos/cosmos-sdk/baseapp" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdktestutil "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" @@ -35,8 +36,8 @@ type KeeperTestSuite struct { } func (s *KeeperTestSuite) SetupTest() { - key := sdk.NewKVStoreKey(slashingtypes.StoreKey) - testCtx := sdktestutil.DefaultContextWithDB(s.T(), key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(slashingtypes.StoreKey) + testCtx := sdktestutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) ctx := testCtx.Ctx.WithBlockHeader(tmproto.Header{Time: tmtime.Now()}) encCfg := moduletestutil.MakeTestEncodingConfig() diff --git a/x/slashing/keeper/signing_info.go b/x/slashing/keeper/signing_info.go index 3201526ea853..d8deb518168d 100644 --- a/x/slashing/keeper/signing_info.go +++ b/x/slashing/keeper/signing_info.go @@ -5,6 +5,7 @@ import ( gogotypes "github.com/cosmos/gogoproto/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/slashing/types" ) @@ -42,7 +43,7 @@ func (k Keeper) IterateValidatorSigningInfos(ctx sdk.Context, handler func(address sdk.ConsAddress, info types.ValidatorSigningInfo) (stop bool), ) { store := ctx.KVStore(k.storeKey) - iter := sdk.KVStorePrefixIterator(store, types.ValidatorSigningInfoKeyPrefix) + iter := storetypes.KVStorePrefixIterator(store, types.ValidatorSigningInfoKeyPrefix) defer iter.Close() for ; iter.Valid(); iter.Next() { address := types.ValidatorSigningInfoAddress(iter.Key()) @@ -150,7 +151,7 @@ func (k Keeper) SetValidatorMissedBlockBitArray(ctx sdk.Context, address sdk.Con // clearValidatorMissedBlockBitArray deletes every instance of ValidatorMissedBlockBitArray in the store func (k Keeper) clearValidatorMissedBlockBitArray(ctx sdk.Context, address sdk.ConsAddress) { store := ctx.KVStore(k.storeKey) - iter := sdk.KVStorePrefixIterator(store, types.ValidatorMissedBlockBitArrayPrefixKey(address)) + iter := storetypes.KVStorePrefixIterator(store, types.ValidatorMissedBlockBitArrayPrefixKey(address)) defer iter.Close() for ; iter.Valid(); iter.Next() { store.Delete(iter.Key()) diff --git a/x/slashing/migrations/v2/store_test.go b/x/slashing/migrations/v2/store_test.go index d6bd71501fde..0e3dc9fc8b1f 100644 --- a/x/slashing/migrations/v2/store_test.go +++ b/x/slashing/migrations/v2/store_test.go @@ -6,6 +6,7 @@ import ( "github.com/stretchr/testify/require" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" @@ -15,8 +16,8 @@ import ( ) func TestStoreMigration(t *testing.T) { - slashingKey := sdk.NewKVStoreKey("slashing") - ctx := testutil.DefaultContext(slashingKey, sdk.NewTransientStoreKey("transient_test")) + slashingKey := storetypes.NewKVStoreKey("slashing") + ctx := testutil.DefaultContext(slashingKey, storetypes.NewTransientStoreKey("transient_test")) store := ctx.KVStore(slashingKey) _, _, addr1 := testdata.KeyTestPubAddr() diff --git a/x/slashing/migrations/v3/migrate.go b/x/slashing/migrations/v3/migrate.go index f7db99e31826..dc014d9b5ecf 100644 --- a/x/slashing/migrations/v3/migrate.go +++ b/x/slashing/migrations/v3/migrate.go @@ -2,6 +2,7 @@ package v3 import ( "github.com/cosmos/cosmos-sdk/codec" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/slashing/exported" "github.com/cosmos/cosmos-sdk/x/slashing/types" @@ -17,7 +18,7 @@ var ParamsKey = []byte{0x00} // version 3. Specifically, it takes the parameters that are currently stored // and managed by the x/params modules and stores them directly into the x/slashing // module state. -func Migrate(ctx sdk.Context, store sdk.KVStore, legacySubspace exported.Subspace, cdc codec.BinaryCodec) error { +func Migrate(ctx sdk.Context, store storetypes.KVStore, legacySubspace exported.Subspace, cdc codec.BinaryCodec) error { var currParams types.Params legacySubspace.GetParamSet(ctx, &currParams) diff --git a/x/slashing/migrations/v3/migrator_test.go b/x/slashing/migrations/v3/migrator_test.go index b57000766651..67536c0b9e38 100644 --- a/x/slashing/migrations/v3/migrator_test.go +++ b/x/slashing/migrations/v3/migrator_test.go @@ -5,6 +5,7 @@ import ( "github.com/stretchr/testify/require" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -28,8 +29,8 @@ func (ms mockSubspace) GetParamSet(ctx sdk.Context, ps exported.ParamSet) { func TestMigrate(t *testing.T) { cdc := moduletestutil.MakeTestEncodingConfig(slashing.AppModuleBasic{}).Codec - storeKey := sdk.NewKVStoreKey(v3.ModuleName) - tKey := sdk.NewTransientStoreKey("transient_test") + storeKey := storetypes.NewKVStoreKey(v3.ModuleName) + tKey := storetypes.NewTransientStoreKey("transient_test") ctx := testutil.DefaultContext(storeKey, tKey) store := ctx.KVStore(storeKey) diff --git a/x/slashing/module.go b/x/slashing/module.go index 49cb4233c639..f87b4109f1bf 100644 --- a/x/slashing/module.go +++ b/x/slashing/module.go @@ -187,7 +187,7 @@ func (AppModule) ProposalContents(simState module.SimulationState) []simtypes.We } // RegisterStoreDecoder registers a decoder for slashing module's types -func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { +func (am AppModule) RegisterStoreDecoder(sdr store.StoreDecoderRegistry) { sdr[types.StoreKey] = simulation.NewDecodeStore(am.cdc) } diff --git a/x/staking/keeper/alias_functions.go b/x/staking/keeper/alias_functions.go index 59c4d23be2e8..f9b41009e538 100644 --- a/x/staking/keeper/alias_functions.go +++ b/x/staking/keeper/alias_functions.go @@ -3,6 +3,7 @@ package keeper import ( "fmt" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -13,7 +14,7 @@ import ( func (k Keeper) IterateValidators(ctx sdk.Context, fn func(index int64, validator types.ValidatorI) (stop bool)) { store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, types.ValidatorsKey) + iterator := storetypes.KVStorePrefixIterator(store, types.ValidatorsKey) defer iterator.Close() i := int64(0) @@ -34,7 +35,7 @@ func (k Keeper) IterateBondedValidatorsByPower(ctx sdk.Context, fn func(index in store := ctx.KVStore(k.storeKey) maxValidators := k.MaxValidators(ctx) - iterator := sdk.KVStoreReversePrefixIterator(store, types.ValidatorsByPowerIndexKey) + iterator := storetypes.KVStoreReversePrefixIterator(store, types.ValidatorsByPowerIndexKey) defer iterator.Close() i := int64(0) @@ -119,7 +120,7 @@ func (k Keeper) IterateDelegations(ctx sdk.Context, delAddr sdk.AccAddress, store := ctx.KVStore(k.storeKey) delegatorPrefixKey := types.GetDelegationsKey(delAddr) - iterator := sdk.KVStorePrefixIterator(store, delegatorPrefixKey) // smallest to largest + iterator := storetypes.KVStorePrefixIterator(store, delegatorPrefixKey) // smallest to largest defer iterator.Close() for i := int64(0); iterator.Valid(); iterator.Next() { @@ -138,7 +139,7 @@ func (k Keeper) IterateDelegations(ctx sdk.Context, delAddr sdk.AccAddress, func (k Keeper) GetAllSDKDelegations(ctx sdk.Context) (delegations []types.Delegation) { store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, types.DelegationKey) + iterator := storetypes.KVStorePrefixIterator(store, types.DelegationKey) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { diff --git a/x/staking/keeper/delegation.go b/x/staking/keeper/delegation.go index 23cb929099e8..502ed468ca35 100644 --- a/x/staking/keeper/delegation.go +++ b/x/staking/keeper/delegation.go @@ -6,6 +6,7 @@ import ( "time" "cosmossdk.io/math" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/staking/types" @@ -30,7 +31,7 @@ func (k Keeper) GetDelegation(ctx sdk.Context, delAddr sdk.AccAddress, valAddr s func (k Keeper) IterateAllDelegations(ctx sdk.Context, cb func(delegation types.Delegation) (stop bool)) { store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, types.DelegationKey) + iterator := storetypes.KVStorePrefixIterator(store, types.DelegationKey) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -56,7 +57,7 @@ func (k Keeper) GetAllDelegations(ctx sdk.Context) (delegations []types.Delegati func (k Keeper) GetValidatorDelegations(ctx sdk.Context, valAddr sdk.ValAddress) (delegations []types.Delegation) { //nolint:interfacer store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, types.DelegationKey) + iterator := storetypes.KVStorePrefixIterator(store, types.DelegationKey) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -76,7 +77,7 @@ func (k Keeper) GetDelegatorDelegations(ctx sdk.Context, delegator sdk.AccAddres store := ctx.KVStore(k.storeKey) delegatorPrefixKey := types.GetDelegationsKey(delegator) - iterator := sdk.KVStorePrefixIterator(store, delegatorPrefixKey) + iterator := storetypes.KVStorePrefixIterator(store, delegatorPrefixKey) defer iterator.Close() i := 0 @@ -119,7 +120,7 @@ func (k Keeper) GetUnbondingDelegations(ctx sdk.Context, delegator sdk.AccAddres store := ctx.KVStore(k.storeKey) delegatorPrefixKey := types.GetUBDsKey(delegator) - iterator := sdk.KVStorePrefixIterator(store, delegatorPrefixKey) + iterator := storetypes.KVStorePrefixIterator(store, delegatorPrefixKey) defer iterator.Close() i := 0 @@ -152,7 +153,7 @@ func (k Keeper) GetUnbondingDelegation(ctx sdk.Context, delAddr sdk.AccAddress, func (k Keeper) GetUnbondingDelegationsFromValidator(ctx sdk.Context, valAddr sdk.ValAddress) (ubds []types.UnbondingDelegation) { store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, types.GetUBDsByValIndexKey(valAddr)) + iterator := storetypes.KVStorePrefixIterator(store, types.GetUBDsByValIndexKey(valAddr)) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -169,7 +170,7 @@ func (k Keeper) GetUnbondingDelegationsFromValidator(ctx sdk.Context, valAddr sd func (k Keeper) IterateUnbondingDelegations(ctx sdk.Context, fn func(index int64, ubd types.UnbondingDelegation) (stop bool)) { store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, types.UnbondingDelegationKey) + iterator := storetypes.KVStorePrefixIterator(store, types.UnbondingDelegationKey) defer iterator.Close() for i := int64(0); iterator.Valid(); iterator.Next() { @@ -197,7 +198,7 @@ func (k Keeper) GetDelegatorUnbonding(ctx sdk.Context, delegator sdk.AccAddress) func (k Keeper) IterateDelegatorUnbondingDelegations(ctx sdk.Context, delegator sdk.AccAddress, cb func(ubd types.UnbondingDelegation) (stop bool)) { store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, types.GetUBDsKey(delegator)) + iterator := storetypes.KVStorePrefixIterator(store, types.GetUBDsKey(delegator)) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -232,7 +233,7 @@ func (k Keeper) GetDelegatorBonded(ctx sdk.Context, delegator sdk.AccAddress) ma func (k Keeper) IterateDelegatorDelegations(ctx sdk.Context, delegator sdk.AccAddress, cb func(delegation types.Delegation) (stop bool)) { store := ctx.KVStore(k.storeKey) delegatorPrefixKey := types.GetDelegationsKey(delegator) - iterator := sdk.KVStorePrefixIterator(store, delegatorPrefixKey) + iterator := storetypes.KVStorePrefixIterator(store, delegatorPrefixKey) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -248,7 +249,7 @@ func (k Keeper) IterateDelegatorRedelegations(ctx sdk.Context, delegator sdk.Acc store := ctx.KVStore(k.storeKey) delegatorPrefixKey := types.GetREDsKey(delegator) - iterator := sdk.KVStorePrefixIterator(store, delegatorPrefixKey) + iterator := storetypes.KVStorePrefixIterator(store, delegatorPrefixKey) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -365,10 +366,10 @@ func (k Keeper) InsertUBDQueue(ctx sdk.Context, ubd types.UnbondingDelegation, c } // UBDQueueIterator returns all the unbonding queue timeslices from time 0 until endTime. -func (k Keeper) UBDQueueIterator(ctx sdk.Context, endTime time.Time) sdk.Iterator { +func (k Keeper) UBDQueueIterator(ctx sdk.Context, endTime time.Time) storetypes.Iterator { store := ctx.KVStore(k.storeKey) return store.Iterator(types.UnbondingQueueKey, - sdk.InclusiveEndBytes(types.GetUnbondingDelegationTimeKey(endTime))) + storetypes.InclusiveEndBytes(types.GetUnbondingDelegationTimeKey(endTime))) } // DequeueAllMatureUBDQueue returns a concatenated list of all the timeslices inclusively previous to @@ -400,7 +401,7 @@ func (k Keeper) GetRedelegations(ctx sdk.Context, delegator sdk.AccAddress, maxR store := ctx.KVStore(k.storeKey) delegatorPrefixKey := types.GetREDsKey(delegator) - iterator := sdk.KVStorePrefixIterator(store, delegatorPrefixKey) + iterator := storetypes.KVStorePrefixIterator(store, delegatorPrefixKey) defer iterator.Close() i := 0 @@ -433,7 +434,7 @@ func (k Keeper) GetRedelegation(ctx sdk.Context, delAddr sdk.AccAddress, valSrcA func (k Keeper) GetRedelegationsFromSrcValidator(ctx sdk.Context, valAddr sdk.ValAddress) (reds []types.Redelegation) { store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, types.GetREDsFromValSrcIndexKey(valAddr)) + iterator := storetypes.KVStorePrefixIterator(store, types.GetREDsFromValSrcIndexKey(valAddr)) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -451,7 +452,7 @@ func (k Keeper) HasReceivingRedelegation(ctx sdk.Context, delAddr sdk.AccAddress store := ctx.KVStore(k.storeKey) prefix := types.GetREDsByDelToValDstIndexKey(delAddr, valDstAddr) - iterator := sdk.KVStorePrefixIterator(store, prefix) + iterator := storetypes.KVStorePrefixIterator(store, prefix) defer iterator.Close() return iterator.Valid() @@ -520,7 +521,7 @@ func (k Keeper) SetRedelegationEntry(ctx sdk.Context, func (k Keeper) IterateRedelegations(ctx sdk.Context, fn func(index int64, red types.Redelegation) (stop bool)) { store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, types.RedelegationKey) + iterator := storetypes.KVStorePrefixIterator(store, types.RedelegationKey) defer iterator.Close() for i := int64(0); iterator.Valid(); iterator.Next() { @@ -597,9 +598,9 @@ func (k Keeper) InsertRedelegationQueue(ctx sdk.Context, red types.Redelegation, // RedelegationQueueIterator returns all the redelegation queue timeslices from // time 0 until endTime. -func (k Keeper) RedelegationQueueIterator(ctx sdk.Context, endTime time.Time) sdk.Iterator { +func (k Keeper) RedelegationQueueIterator(ctx sdk.Context, endTime time.Time) storetypes.Iterator { store := ctx.KVStore(k.storeKey) - return store.Iterator(types.RedelegationQueueKey, sdk.InclusiveEndBytes(types.GetRedelegationTimeKey(endTime))) + return store.Iterator(types.RedelegationQueueKey, storetypes.InclusiveEndBytes(types.GetRedelegationTimeKey(endTime))) } // DequeueAllMatureRedelegationQueue returns a concatenated list of all the diff --git a/x/staking/keeper/grpc_query.go b/x/staking/keeper/grpc_query.go index 2ff23e2f4cf0..039920749ec2 100644 --- a/x/staking/keeper/grpc_query.go +++ b/x/staking/keeper/grpc_query.go @@ -8,6 +8,7 @@ import ( "google.golang.org/grpc/status" "github.com/cosmos/cosmos-sdk/store/prefix" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" "github.com/cosmos/cosmos-sdk/x/staking/types" @@ -492,7 +493,7 @@ func queryRedelegation(ctx sdk.Context, k Querier, req *types.QueryRedelegations return redels, err } -func queryRedelegationsFromSrcValidator(store sdk.KVStore, k Querier, req *types.QueryRedelegationsRequest) (redels types.Redelegations, res *query.PageResponse, err error) { +func queryRedelegationsFromSrcValidator(store storetypes.KVStore, k Querier, req *types.QueryRedelegationsRequest) (redels types.Redelegations, res *query.PageResponse, err error) { valAddr, err := sdk.ValAddressFromBech32(req.SrcValidatorAddr) if err != nil { return nil, nil, err @@ -514,7 +515,7 @@ func queryRedelegationsFromSrcValidator(store sdk.KVStore, k Querier, req *types return redels, res, err } -func queryAllRedelegations(store sdk.KVStore, k Querier, req *types.QueryRedelegationsRequest) (redels types.Redelegations, res *query.PageResponse, err error) { +func queryAllRedelegations(store storetypes.KVStore, k Querier, req *types.QueryRedelegationsRequest) (redels types.Redelegations, res *query.PageResponse, err error) { delAddr, err := sdk.AccAddressFromBech32(req.DelegatorAddr) if err != nil { return nil, nil, err diff --git a/x/staking/keeper/historical_info.go b/x/staking/keeper/historical_info.go index 243612d38743..d67491d2f644 100644 --- a/x/staking/keeper/historical_info.go +++ b/x/staking/keeper/historical_info.go @@ -1,6 +1,7 @@ package keeper import ( + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -42,7 +43,7 @@ func (k Keeper) DeleteHistoricalInfo(ctx sdk.Context, height int64) { func (k Keeper) IterateHistoricalInfo(ctx sdk.Context, cb func(types.HistoricalInfo) bool) { store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, types.HistoricalInfoKey) + iterator := storetypes.KVStorePrefixIterator(store, types.HistoricalInfoKey) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { diff --git a/x/staking/keeper/keeper.go b/x/staking/keeper/keeper.go index 952a48dc7d41..6590f57ded24 100644 --- a/x/staking/keeper/keeper.go +++ b/x/staking/keeper/keeper.go @@ -3,11 +3,10 @@ package keeper import ( "fmt" + "cosmossdk.io/math" abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/libs/log" - "cosmossdk.io/math" - "github.com/cosmos/cosmos-sdk/codec" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" diff --git a/x/staking/keeper/keeper_test.go b/x/staking/keeper/keeper_test.go index a114c6a2bcdf..d471cbba8af1 100644 --- a/x/staking/keeper/keeper_test.go +++ b/x/staking/keeper/keeper_test.go @@ -3,14 +3,14 @@ package keeper_test import ( "testing" + "cosmossdk.io/math" "github.com/golang/mock/gomock" "github.com/stretchr/testify/suite" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" tmtime "github.com/tendermint/tendermint/types/time" - "cosmossdk.io/math" - "github.com/cosmos/cosmos-sdk/baseapp" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" @@ -40,8 +40,8 @@ type KeeperTestSuite struct { } func (s *KeeperTestSuite) SetupTest() { - key := sdk.NewKVStoreKey(stakingtypes.StoreKey) - testCtx := testutil.DefaultContextWithDB(s.T(), key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(stakingtypes.StoreKey) + testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) ctx := testCtx.Ctx.WithBlockHeader(tmproto.Header{Time: tmtime.Now()}) encCfg := moduletestutil.MakeTestEncodingConfig() diff --git a/x/staking/keeper/query_utils.go b/x/staking/keeper/query_utils.go index d757522f6dd7..d23ad2c52252 100644 --- a/x/staking/keeper/query_utils.go +++ b/x/staking/keeper/query_utils.go @@ -1,6 +1,7 @@ package keeper import ( + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -14,7 +15,7 @@ func (k Keeper) GetDelegatorValidators( store := ctx.KVStore(k.storeKey) delegatorPrefixKey := types.GetDelegationsKey(delegatorAddr) - iterator := sdk.KVStorePrefixIterator(store, delegatorPrefixKey) // smallest to largest + iterator := storetypes.KVStorePrefixIterator(store, delegatorPrefixKey) // smallest to largest defer iterator.Close() i := 0 @@ -57,7 +58,7 @@ func (k Keeper) GetAllDelegatorDelegations(ctx sdk.Context, delegator sdk.AccAdd store := ctx.KVStore(k.storeKey) delegatorPrefixKey := types.GetDelegationsKey(delegator) - iterator := sdk.KVStorePrefixIterator(store, delegatorPrefixKey) // smallest to largest + iterator := storetypes.KVStorePrefixIterator(store, delegatorPrefixKey) // smallest to largest defer iterator.Close() i := 0 @@ -78,7 +79,7 @@ func (k Keeper) GetAllUnbondingDelegations(ctx sdk.Context, delegator sdk.AccAdd store := ctx.KVStore(k.storeKey) delegatorPrefixKey := types.GetUBDsKey(delegator) - iterator := sdk.KVStorePrefixIterator(store, delegatorPrefixKey) // smallest to largest + iterator := storetypes.KVStorePrefixIterator(store, delegatorPrefixKey) // smallest to largest defer iterator.Close() for i := 0; iterator.Valid(); iterator.Next() { @@ -97,7 +98,7 @@ func (k Keeper) GetAllRedelegations( store := ctx.KVStore(k.storeKey) delegatorPrefixKey := types.GetREDsKey(delegator) - iterator := sdk.KVStorePrefixIterator(store, delegatorPrefixKey) // smallest to largest + iterator := storetypes.KVStorePrefixIterator(store, delegatorPrefixKey) // smallest to largest defer iterator.Close() srcValFilter := !(srcValAddress.Empty()) diff --git a/x/staking/keeper/test_common.go b/x/staking/keeper/test_common.go index d31ae06ba7f6..edf9b19f22ad 100644 --- a/x/staking/keeper/test_common.go +++ b/x/staking/keeper/test_common.go @@ -3,6 +3,7 @@ package keeper // noalias import ( "bytes" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -21,7 +22,7 @@ func TestingUpdateValidator(keeper *Keeper, ctx sdk.Context, validator types.Val store := ctx.KVStore(keeper.storeKey) deleted := false - iterator := sdk.KVStorePrefixIterator(store, types.ValidatorsByPowerIndexKey) + iterator := storetypes.KVStorePrefixIterator(store, types.ValidatorsByPowerIndexKey) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { diff --git a/x/staking/keeper/validator.go b/x/staking/keeper/validator.go index d1315ed7793f..55e60e5917f6 100644 --- a/x/staking/keeper/validator.go +++ b/x/staking/keeper/validator.go @@ -7,6 +7,7 @@ import ( gogotypes "github.com/cosmos/gogoproto/types" "cosmossdk.io/math" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -193,7 +194,7 @@ func (k Keeper) RemoveValidator(ctx sdk.Context, address sdk.ValAddress) { func (k Keeper) GetAllValidators(ctx sdk.Context) (validators []types.Validator) { store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, types.ValidatorsKey) + iterator := storetypes.KVStorePrefixIterator(store, types.ValidatorsKey) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -209,7 +210,7 @@ func (k Keeper) GetValidators(ctx sdk.Context, maxRetrieve uint32) (validators [ store := ctx.KVStore(k.storeKey) validators = make([]types.Validator, maxRetrieve) - iterator := sdk.KVStorePrefixIterator(store, types.ValidatorsKey) + iterator := storetypes.KVStorePrefixIterator(store, types.ValidatorsKey) defer iterator.Close() i := 0 @@ -245,9 +246,9 @@ func (k Keeper) GetBondedValidatorsByPower(ctx sdk.Context) []types.Validator { } // returns an iterator for the current validator power store -func (k Keeper) ValidatorsPowerStoreIterator(ctx sdk.Context) sdk.Iterator { +func (k Keeper) ValidatorsPowerStoreIterator(ctx sdk.Context) storetypes.Iterator { store := ctx.KVStore(k.storeKey) - return sdk.KVStoreReversePrefixIterator(store, types.ValidatorsByPowerIndexKey) + return storetypes.KVStoreReversePrefixIterator(store, types.ValidatorsByPowerIndexKey) } // Last Validator Index @@ -282,9 +283,9 @@ func (k Keeper) DeleteLastValidatorPower(ctx sdk.Context, operator sdk.ValAddres } // returns an iterator for the consensus validators in the last block -func (k Keeper) LastValidatorsIterator(ctx sdk.Context) (iterator sdk.Iterator) { +func (k Keeper) LastValidatorsIterator(ctx sdk.Context) (iterator storetypes.Iterator) { store := ctx.KVStore(k.storeKey) - iterator = sdk.KVStorePrefixIterator(store, types.LastValidatorPowerKey) + iterator = storetypes.KVStorePrefixIterator(store, types.LastValidatorPowerKey) return iterator } @@ -293,7 +294,7 @@ func (k Keeper) LastValidatorsIterator(ctx sdk.Context) (iterator sdk.Iterator) func (k Keeper) IterateLastValidatorPowers(ctx sdk.Context, handler func(operator sdk.ValAddress, power int64) (stop bool)) { store := ctx.KVStore(k.storeKey) - iter := sdk.KVStorePrefixIterator(store, types.LastValidatorPowerKey) + iter := storetypes.KVStorePrefixIterator(store, types.LastValidatorPowerKey) defer iter.Close() for ; iter.Valid(); iter.Next() { @@ -316,7 +317,7 @@ func (k Keeper) GetLastValidators(ctx sdk.Context) (validators []types.Validator maxValidators := k.MaxValidators(ctx) validators = make([]types.Validator, maxValidators) - iterator := sdk.KVStorePrefixIterator(store, types.LastValidatorPowerKey) + iterator := storetypes.KVStorePrefixIterator(store, types.LastValidatorPowerKey) defer iterator.Close() i := 0 @@ -408,9 +409,9 @@ func (k Keeper) DeleteValidatorQueue(ctx sdk.Context, val types.Validator) { // ValidatorQueueIterator returns an interator ranging over validators that are // unbonding whose unbonding completion occurs at the given height and time. -func (k Keeper) ValidatorQueueIterator(ctx sdk.Context, endTime time.Time, endHeight int64) sdk.Iterator { +func (k Keeper) ValidatorQueueIterator(ctx sdk.Context, endTime time.Time, endHeight int64) storetypes.Iterator { store := ctx.KVStore(k.storeKey) - return store.Iterator(types.ValidatorQueueKey, sdk.InclusiveEndBytes(types.GetValidatorQueueKey(endTime, endHeight))) + return store.Iterator(types.ValidatorQueueKey, storetypes.InclusiveEndBytes(types.GetValidatorQueueKey(endTime, endHeight))) } // UnbondAllMatureValidators unbonds all the mature unbonding validators that diff --git a/x/staking/migrations/v2/store.go b/x/staking/migrations/v2/store.go index a376190df1d0..00355893e5cc 100644 --- a/x/staking/migrations/v2/store.go +++ b/x/staking/migrations/v2/store.go @@ -15,7 +15,7 @@ import ( // prefix_bytes | address_1_bytes | address_2_bytes | address_3_bytes // into format: // prefix_bytes | address_1_len (1 byte) | address_1_bytes | address_2_len (1 byte) | address_2_bytes | address_3_len (1 byte) | address_3_bytes -func migratePrefixAddressAddressAddress(store sdk.KVStore, prefixBz []byte) { +func migratePrefixAddressAddressAddress(store storetypes.KVStore, prefixBz []byte) { oldStore := prefix.NewStore(store, prefixBz) oldStoreIter := oldStore.Iterator(nil, nil) @@ -38,7 +38,7 @@ func migratePrefixAddressAddressAddress(store sdk.KVStore, prefixBz []byte) { const powerBytesLen = 8 -func migrateValidatorsByPowerIndexKey(store sdk.KVStore) { +func migrateValidatorsByPowerIndexKey(store storetypes.KVStore) { oldStore := prefix.NewStore(store, v1.ValidatorsByPowerIndexKey) oldStoreIter := oldStore.Iterator(nil, nil) diff --git a/x/staking/migrations/v2/store_test.go b/x/staking/migrations/v2/store_test.go index 8039ed477a4e..7edc63464f62 100644 --- a/x/staking/migrations/v2/store_test.go +++ b/x/staking/migrations/v2/store_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/require" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdktestuil "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" @@ -17,8 +18,8 @@ import ( ) func TestStoreMigration(t *testing.T) { - stakingKey := sdk.NewKVStoreKey("staking") - tStakingKey := sdk.NewTransientStoreKey("transient_test") + stakingKey := storetypes.NewKVStoreKey("staking") + tStakingKey := storetypes.NewTransientStoreKey("transient_test") ctx := sdktestuil.DefaultContext(stakingKey, tStakingKey) store := ctx.KVStore(stakingKey) diff --git a/x/staking/migrations/v3/store_test.go b/x/staking/migrations/v3/store_test.go index 24c37b595cf1..4c22b9669543 100644 --- a/x/staking/migrations/v3/store_test.go +++ b/x/staking/migrations/v3/store_test.go @@ -5,8 +5,8 @@ import ( "github.com/stretchr/testify/require" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" - sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" v3 "github.com/cosmos/cosmos-sdk/x/staking/migrations/v3" @@ -15,8 +15,8 @@ import ( func TestStoreMigration(t *testing.T) { encCfg := moduletestutil.MakeTestEncodingConfig() - stakingKey := sdk.NewKVStoreKey("staking") - tStakingKey := sdk.NewTransientStoreKey("transient_test") + stakingKey := storetypes.NewKVStoreKey("staking") + tStakingKey := storetypes.NewTransientStoreKey("transient_test") ctx := testutil.DefaultContext(stakingKey, tStakingKey) paramstore := paramtypes.NewSubspace(encCfg.Codec, encCfg.Amino, stakingKey, tStakingKey, "staking") diff --git a/x/staking/migrations/v4/migrations_test.go b/x/staking/migrations/v4/migrations_test.go index 1b1ff95f01a3..2d0e85094de1 100644 --- a/x/staking/migrations/v4/migrations_test.go +++ b/x/staking/migrations/v4/migrations_test.go @@ -33,8 +33,8 @@ func (ms mockSubspace) GetParamSet(ctx sdk.Context, ps paramtypes.ParamSet) { func TestMigrate(t *testing.T) { cdc := moduletestutil.MakeTestEncodingConfig(staking.AppModuleBasic{}).Codec - storeKey := sdk.NewKVStoreKey(v4.ModuleName) - tKey := sdk.NewTransientStoreKey("transient_test") + storeKey := storetypes.NewKVStoreKey(v4.ModuleName) + tKey := storetypes.NewTransientStoreKey("transient_test") ctx := testutil.DefaultContext(storeKey, tKey) store := ctx.KVStore(storeKey) duplicateCreationHeight := int64(1) diff --git a/x/staking/migrations/v4/store.go b/x/staking/migrations/v4/store.go index 9c09ddf60361..79ee94683d3b 100644 --- a/x/staking/migrations/v4/store.go +++ b/x/staking/migrations/v4/store.go @@ -44,7 +44,7 @@ func migrateParams(ctx sdk.Context, store storetypes.KVStore, cdc codec.BinaryCo // migrateUBDEntries will remove the ubdEntries with same creation_height // and create a new ubdEntry with updated balance and initial_balance func migrateUBDEntries(ctx sdk.Context, store storetypes.KVStore, cdc codec.BinaryCodec, legacySubspace exported.Subspace) error { - iterator := sdk.KVStorePrefixIterator(store, types.UnbondingDelegationKey) + iterator := storetypes.KVStorePrefixIterator(store, types.UnbondingDelegationKey) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { diff --git a/x/staking/module.go b/x/staking/module.go index 68ce56c30520..19a81a26dbad 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -294,7 +294,7 @@ func (AppModule) ProposalContents(simState module.SimulationState) []simtypes.We } // RegisterStoreDecoder registers a decoder for staking module's types -func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { +func (am AppModule) RegisterStoreDecoder(sdr store.StoreDecoderRegistry) { sdr[types.StoreKey] = simulation.NewDecodeStore(am.cdc) } diff --git a/x/staking/types/authz_test.go b/x/staking/types/authz_test.go index ca9672d91bb6..e9119df80e4a 100644 --- a/x/staking/types/authz_test.go +++ b/x/staking/types/authz_test.go @@ -5,6 +5,7 @@ import ( "github.com/stretchr/testify/require" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" @@ -22,8 +23,8 @@ var ( ) func TestAuthzAuthorizations(t *testing.T) { - key := sdk.NewKVStoreKey(stakingtypes.StoreKey) - testCtx := testutil.DefaultContextWithDB(t, key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(stakingtypes.StoreKey) + testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) ctx := testCtx.Ctx.WithBlockHeader(tmproto.Header{}) // verify ValidateBasic returns error for the AUTHORIZATION_TYPE_UNSPECIFIED authorization type diff --git a/x/upgrade/abci.go b/x/upgrade/abci.go index 7fc5e11c1e9c..9e71815830c4 100644 --- a/x/upgrade/abci.go +++ b/x/upgrade/abci.go @@ -6,6 +6,7 @@ import ( abci "github.com/tendermint/tendermint/abci/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" @@ -80,7 +81,7 @@ func BeginBlocker(k *keeper.Keeper, ctx sdk.Context, _ abci.RequestBeginBlock) { // We have an upgrade handler for this upgrade name, so apply the upgrade ctx.Logger().Info(fmt.Sprintf("applying upgrade \"%s\" at %s", plan.Name, plan.DueAt())) - ctx = ctx.WithBlockGasMeter(sdk.NewInfiniteGasMeter()) + ctx = ctx.WithBlockGasMeter(storetypes.NewInfiniteGasMeter()) k.ApplyUpgrade(ctx, plan) return } diff --git a/x/upgrade/abci_test.go b/x/upgrade/abci_test.go index 68107259613c..bfdf74285dd6 100644 --- a/x/upgrade/abci_test.go +++ b/x/upgrade/abci_test.go @@ -12,6 +12,7 @@ import ( tmproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/baseapp" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -22,9 +23,8 @@ import ( govtypesv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" "github.com/cosmos/cosmos-sdk/x/upgrade" "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" - "github.com/tendermint/tendermint/libs/log" - "github.com/cosmos/cosmos-sdk/x/upgrade/types" + "github.com/tendermint/tendermint/libs/log" ) type TestSuite struct { @@ -42,8 +42,8 @@ var s TestSuite func setupTest(t *testing.T, height int64, skip map[int64]bool) TestSuite { s.encCfg = moduletestutil.MakeTestEncodingConfig(upgrade.AppModuleBasic{}) - key := sdk.NewKVStoreKey(types.StoreKey) - testCtx := testutil.DefaultContextWithDB(s.T(), key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(types.StoreKey) + testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) s.baseApp = baseapp.NewBaseApp( "upgrade", @@ -480,8 +480,8 @@ func TestDowngradeVerification(t *testing.T) { // could not use setupTest() here, because we have to use the same key // for the two keepers. encCfg := moduletestutil.MakeTestEncodingConfig(upgrade.AppModuleBasic{}) - key := sdk.NewKVStoreKey(types.StoreKey) - testCtx := testutil.DefaultContextWithDB(s.T(), key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(types.StoreKey) + testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) ctx := testCtx.Ctx.WithBlockHeader(tmproto.Header{Time: time.Now(), Height: 10}) skip := map[int64]bool{} diff --git a/x/upgrade/keeper/grpc_query_test.go b/x/upgrade/keeper/grpc_query_test.go index 1cd07ca4bdb8..557d61a3cb45 100644 --- a/x/upgrade/keeper/grpc_query_test.go +++ b/x/upgrade/keeper/grpc_query_test.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/suite" "github.com/cosmos/cosmos-sdk/baseapp" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" @@ -15,7 +16,6 @@ import ( authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" "github.com/cosmos/cosmos-sdk/x/upgrade" - "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" "github.com/cosmos/cosmos-sdk/x/upgrade/types" ) @@ -31,8 +31,8 @@ type UpgradeTestSuite struct { func (suite *UpgradeTestSuite) SetupTest() { suite.encCfg = moduletestutil.MakeTestEncodingConfig(upgrade.AppModuleBasic{}) - key := sdk.NewKVStoreKey(types.StoreKey) - testCtx := testutil.DefaultContextWithDB(suite.T(), key, sdk.NewTransientStoreKey("transient_test")) + key := storetypes.NewKVStoreKey(types.StoreKey) + testCtx := testutil.DefaultContextWithDB(suite.T(), key, storetypes.NewTransientStoreKey("transient_test")) suite.ctx = testCtx.Ctx skipUpgradeHeights := make(map[int64]bool) diff --git a/x/upgrade/keeper/keeper.go b/x/upgrade/keeper/keeper.go index 8ae041cb3cf1..a5a27e7c1b18 100644 --- a/x/upgrade/keeper/keeper.go +++ b/x/upgrade/keeper/keeper.go @@ -136,7 +136,7 @@ func (k Keeper) SetModuleVersionMap(ctx sdk.Context, vm module.VersionMap) { // as defined in ADR-041. func (k Keeper) GetModuleVersionMap(ctx sdk.Context) module.VersionMap { store := ctx.KVStore(k.storeKey) - it := sdk.KVStorePrefixIterator(store, []byte{types.VersionMapByte}) + it := storetypes.KVStorePrefixIterator(store, []byte{types.VersionMapByte}) vm := make(module.VersionMap) defer it.Close() @@ -154,7 +154,7 @@ func (k Keeper) GetModuleVersionMap(ctx sdk.Context) module.VersionMap { // GetModuleVersions gets a slice of module consensus versions func (k Keeper) GetModuleVersions(ctx sdk.Context) []*types.ModuleVersion { store := ctx.KVStore(k.storeKey) - it := sdk.KVStorePrefixIterator(store, []byte{types.VersionMapByte}) + it := storetypes.KVStorePrefixIterator(store, []byte{types.VersionMapByte}) defer it.Close() mv := make([]*types.ModuleVersion, 0) @@ -173,7 +173,7 @@ func (k Keeper) GetModuleVersions(ctx sdk.Context) []*types.ModuleVersion { // getModuleVersion gets the version for a given module, and returns true if it exists, false otherwise func (k Keeper) getModuleVersion(ctx sdk.Context, name string) (uint64, bool) { store := ctx.KVStore(k.storeKey) - it := sdk.KVStorePrefixIterator(store, []byte{types.VersionMapByte}) + it := storetypes.KVStorePrefixIterator(store, []byte{types.VersionMapByte}) defer it.Close() for ; it.Valid(); it.Next() { @@ -258,7 +258,7 @@ func (k Keeper) GetUpgradedConsensusState(ctx sdk.Context, lastHeight int64) ([] // GetLastCompletedUpgrade returns the last applied upgrade name and height. func (k Keeper) GetLastCompletedUpgrade(ctx sdk.Context) (string, int64) { - iter := sdk.KVStoreReversePrefixIterator(ctx.KVStore(k.storeKey), []byte{types.DoneByte}) + iter := storetypes.KVStoreReversePrefixIterator(ctx.KVStore(k.storeKey), []byte{types.DoneByte}) defer iter.Close() if iter.Valid() { @@ -287,7 +287,7 @@ func encodeDoneKey(name string, height int64) []byte { // GetDoneHeight returns the height at which the given upgrade was executed func (k Keeper) GetDoneHeight(ctx sdk.Context, name string) int64 { - iter := sdk.KVStorePrefixIterator(ctx.KVStore(k.storeKey), []byte{types.DoneByte}) + iter := storetypes.KVStorePrefixIterator(ctx.KVStore(k.storeKey), []byte{types.DoneByte}) defer iter.Close() for ; iter.Valid(); iter.Next() { diff --git a/x/upgrade/keeper/keeper_test.go b/x/upgrade/keeper/keeper_test.go index a7002f6edd9d..032c65a013b7 100644 --- a/x/upgrade/keeper/keeper_test.go +++ b/x/upgrade/keeper/keeper_test.go @@ -38,9 +38,9 @@ type KeeperTestSuite struct { func (s *KeeperTestSuite) SetupTest() { s.encCfg = moduletestutil.MakeTestEncodingConfig(upgrade.AppModuleBasic{}) - key := sdk.NewKVStoreKey(types.StoreKey) + key := storetypes.NewKVStoreKey(types.StoreKey) s.key = key - testCtx := testutil.DefaultContextWithDB(s.T(), key, sdk.NewTransientStoreKey("transient_test")) + testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) s.baseApp = baseapp.NewBaseApp( "upgrade", diff --git a/x/upgrade/keeper/migrations_test.go b/x/upgrade/keeper/migrations_test.go index 2e1be7454845..8e69f9cbc5e5 100644 --- a/x/upgrade/keeper/migrations_test.go +++ b/x/upgrade/keeper/migrations_test.go @@ -4,8 +4,8 @@ import ( "encoding/binary" "testing" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/upgrade/types" "github.com/stretchr/testify/require" ) @@ -20,8 +20,8 @@ func encodeOldDoneKey(upgrade storedUpgrade) []byte { } func TestMigrateDoneUpgradeKeys(t *testing.T) { - upgradeKey := sdk.NewKVStoreKey("upgrade") - ctx := testutil.DefaultContext(upgradeKey, sdk.NewTransientStoreKey("transient_test")) + upgradeKey := storetypes.NewKVStoreKey("upgrade") + ctx := testutil.DefaultContext(upgradeKey, storetypes.NewTransientStoreKey("transient_test")) store := ctx.KVStore(upgradeKey) testCases := []struct { diff --git a/x/upgrade/types/storeloader.go b/x/upgrade/types/storeloader.go index 3911effbed30..811ceaaeeef0 100644 --- a/x/upgrade/types/storeloader.go +++ b/x/upgrade/types/storeloader.go @@ -3,13 +3,12 @@ package types import ( "github.com/cosmos/cosmos-sdk/baseapp" storetypes "github.com/cosmos/cosmos-sdk/store/types" - sdk "github.com/cosmos/cosmos-sdk/types" ) // UpgradeStoreLoader is used to prepare baseapp with a fixed StoreLoader // pattern. This is useful for custom upgrade loading logic. func UpgradeStoreLoader(upgradeHeight int64, storeUpgrades *storetypes.StoreUpgrades) baseapp.StoreLoader { - return func(ms sdk.CommitMultiStore) error { + return func(ms storetypes.CommitMultiStore) error { if upgradeHeight == ms.LastCommitID().Version+1 { // Check if the current commit version and upgrade height matches if len(storeUpgrades.Renamed) > 0 || len(storeUpgrades.Deleted) > 0 || len(storeUpgrades.Added) > 0 { diff --git a/x/upgrade/types/storeloader_test.go b/x/upgrade/types/storeloader_test.go index c0649f1c361b..e2e961baad50 100644 --- a/x/upgrade/types/storeloader_test.go +++ b/x/upgrade/types/storeloader_test.go @@ -17,7 +17,6 @@ import ( pruningtypes "github.com/cosmos/cosmos-sdk/store/pruning/types" "github.com/cosmos/cosmos-sdk/store/rootmulti" storetypes "github.com/cosmos/cosmos-sdk/store/types" - sdk "github.com/cosmos/cosmos-sdk/types" ) func useUpgradeLoader(height int64, upgrades *storetypes.StoreUpgrades) func(*baseapp.BaseApp) { @@ -33,7 +32,7 @@ func defaultLogger() log.Logger { func initStore(t *testing.T, db dbm.DB, storeKey string, k, v []byte) { rs := rootmulti.NewStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics()) rs.SetPruning(pruningtypes.NewPruningOptions(pruningtypes.PruningNothing)) - key := sdk.NewKVStoreKey(storeKey) + key := storetypes.NewKVStoreKey(storeKey) rs.MountStoreWithDB(key, storetypes.StoreTypeIAVL, nil) err := rs.LoadLatestVersion() require.Nil(t, err) @@ -50,7 +49,7 @@ func initStore(t *testing.T, db dbm.DB, storeKey string, k, v []byte) { func checkStore(t *testing.T, db dbm.DB, ver int64, storeKey string, k, v []byte) { rs := rootmulti.NewStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics()) rs.SetPruning(pruningtypes.NewPruningOptions(pruningtypes.PruningNothing)) - key := sdk.NewKVStoreKey(storeKey) + key := storetypes.NewKVStoreKey(storeKey) rs.MountStoreWithDB(key, storetypes.StoreTypeIAVL, nil) err := rs.LoadLatestVersion() require.Nil(t, err) @@ -122,7 +121,7 @@ func TestSetLoader(t *testing.T) { opts := []func(*baseapp.BaseApp){baseapp.SetPruning(pruningtypes.NewPruningOptions(pruningtypes.PruningNothing))} origapp := baseapp.NewBaseApp(t.Name(), defaultLogger(), db, nil, opts...) - origapp.MountStores(sdk.NewKVStoreKey(tc.origStoreKey)) + origapp.MountStores(storetypes.NewKVStoreKey(tc.origStoreKey)) err := origapp.LoadLatestVersion() require.Nil(t, err) @@ -138,7 +137,7 @@ func TestSetLoader(t *testing.T) { // load the new app with the original app db app := baseapp.NewBaseApp(t.Name(), defaultLogger(), db, nil, opts...) - app.MountStores(sdk.NewKVStoreKey(tc.loadStoreKey)) + app.MountStores(storetypes.NewKVStoreKey(tc.loadStoreKey)) err = app.LoadLatestVersion() require.Nil(t, err)