From 9fc7fd8ee7c61ebf2a3307c8bf2c9b77fe36c171 Mon Sep 17 00:00:00 2001 From: Ivan Date: Sun, 3 Oct 2021 09:14:14 +0300 Subject: [PATCH] standardize storetypes imports --- baseapp/baseapp_test.go | 23 +++++++-------- server/mock/store.go | 46 ++++++++++++++--------------- types/context.go | 12 ++++---- x/gov/keeper/msg_server.go | 4 +-- x/upgrade/types/storeloader.go | 4 +-- x/upgrade/types/storeloader_test.go | 22 +++++++------- 6 files changed, 55 insertions(+), 56 deletions(-) diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 1242ad4034e8..5d77a16469ce 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -27,7 +27,6 @@ import ( "github.com/cosmos/cosmos-sdk/snapshots" snapshottypes "github.com/cosmos/cosmos-sdk/snapshots/types" "github.com/cosmos/cosmos-sdk/store/rootmulti" - store "github.com/cosmos/cosmos-sdk/store/types" storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" @@ -235,7 +234,7 @@ func TestMountStores(t *testing.T) { // Test that LoadLatestVersion actually does. func TestLoadVersion(t *testing.T) { logger := defaultLogger() - pruningOpt := baseapp.SetPruning(store.PruneNothing) + pruningOpt := baseapp.SetPruning(storetypes.PruneNothing) db := dbm.NewMemDB() name := t.Name() app := baseapp.NewBaseApp(name, logger, db, nil, pruningOpt) @@ -288,15 +287,15 @@ func useDefaultLoader(app *baseapp.BaseApp) { func initStore(t *testing.T, db dbm.DB, storeKey string, k, v []byte) { rs := rootmulti.NewStore(db) - rs.SetPruning(store.PruneNothing) + rs.SetPruning(storetypes.PruneNothing) key := sdk.NewKVStoreKey(storeKey) - rs.MountStoreWithDB(key, store.StoreTypeIAVL, nil) + rs.MountStoreWithDB(key, storetypes.StoreTypeIAVL, nil) err := rs.LoadLatestVersion() require.Nil(t, err) require.Equal(t, int64(0), rs.LastCommitID().Version) // write some data in substore - kv, _ := rs.GetStore(key).(store.KVStore) + kv, _ := rs.GetStore(key).(storetypes.KVStore) require.NotNil(t, kv) kv.Set(k, v) commitID := rs.Commit() @@ -305,15 +304,15 @@ 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) - rs.SetPruning(store.PruneDefault) + rs.SetPruning(storetypes.PruneDefault) key := sdk.NewKVStoreKey(storeKey) - rs.MountStoreWithDB(key, store.StoreTypeIAVL, nil) + rs.MountStoreWithDB(key, storetypes.StoreTypeIAVL, nil) err := rs.LoadLatestVersion() require.Nil(t, err) require.Equal(t, ver, rs.LastCommitID().Version) // query data in substore - kv, _ := rs.GetStore(key).(store.KVStore) + kv, _ := rs.GetStore(key).(storetypes.KVStore) require.NotNil(t, kv) require.Equal(t, v, kv.Get(k)) } @@ -348,7 +347,7 @@ func TestSetLoader(t *testing.T) { initStore(t, db, tc.origStoreKey, k, v) // load the app with the existing db - opts := []func(*baseapp.BaseApp){baseapp.SetPruning(store.PruneNothing)} + opts := []func(*baseapp.BaseApp){baseapp.SetPruning(storetypes.PruneNothing)} if tc.setLoader != nil { opts = append(opts, tc.setLoader) } @@ -371,7 +370,7 @@ func TestSetLoader(t *testing.T) { func TestVersionSetterGetter(t *testing.T) { logger := defaultLogger() - pruningOpt := baseapp.SetPruning(store.PruneDefault) + pruningOpt := baseapp.SetPruning(storetypes.PruneDefault) db := dbm.NewMemDB() name := t.Name() app := baseapp.NewBaseApp(name, logger, db, nil, pruningOpt) @@ -391,7 +390,7 @@ func TestVersionSetterGetter(t *testing.T) { func TestLoadVersionInvalid(t *testing.T) { logger := log.NewNopLogger() - pruningOpt := baseapp.SetPruning(store.PruneNothing) + pruningOpt := baseapp.SetPruning(storetypes.PruneNothing) db := dbm.NewMemDB() name := t.Name() app := baseapp.NewBaseApp(name, logger, db, nil, pruningOpt) @@ -423,7 +422,7 @@ func TestLoadVersionInvalid(t *testing.T) { func TestLoadVersionPruning(t *testing.T) { logger := log.NewNopLogger() - pruningOptions := store.PruningOptions{ + pruningOptions := storetypes.PruningOptions{ KeepRecent: 2, KeepEvery: 3, Interval: 1, diff --git a/server/mock/store.go b/server/mock/store.go index 7829ca58c68e..91596337f964 100644 --- a/server/mock/store.go +++ b/server/mock/store.go @@ -5,14 +5,14 @@ import ( dbm "github.com/tendermint/tm-db" - store "github.com/cosmos/cosmos-sdk/store/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" ) var _ sdk.MultiStore = multiStore{} type multiStore struct { - kv map[store.StoreKey]kvStore + kv map[storetypes.StoreKey]kvStore } func (ms multiStore) CacheMultiStore() sdk.CacheMultiStore { @@ -23,15 +23,15 @@ func (ms multiStore) CacheMultiStoreWithVersion(_ int64) (sdk.CacheMultiStore, e panic("not implemented") } -func (ms multiStore) CacheWrap() store.CacheWrap { +func (ms multiStore) CacheWrap() storetypes.CacheWrap { panic("not implemented") } -func (ms multiStore) CacheWrapWithTrace(_ io.Writer, _ sdk.TraceContext) store.CacheWrap { +func (ms multiStore) CacheWrapWithTrace(_ io.Writer, _ sdk.TraceContext) storetypes.CacheWrap { panic("not implemented") } -func (ms multiStore) CacheWrapWithListeners(_ store.StoreKey, _ []store.WriteListener) store.CacheWrap { +func (ms multiStore) CacheWrapWithListeners(_ storetypes.StoreKey, _ []storetypes.WriteListener) storetypes.CacheWrap { panic("not implemented") } @@ -47,19 +47,19 @@ func (ms multiStore) SetTracer(w io.Writer) sdk.MultiStore { panic("not implemented") } -func (ms multiStore) AddListeners(key store.StoreKey, listeners []store.WriteListener) { +func (ms multiStore) AddListeners(key storetypes.StoreKey, listeners []storetypes.WriteListener) { panic("not implemented") } -func (ms multiStore) ListeningEnabled(key store.StoreKey) bool { +func (ms multiStore) ListeningEnabled(key storetypes.StoreKey) bool { panic("not implemented") } -func (ms multiStore) Commit() store.CommitID { +func (ms multiStore) Commit() storetypes.CommitID { panic("not implemented") } -func (ms multiStore) LastCommitID() store.CommitID { +func (ms multiStore) LastCommitID() storetypes.CommitID { panic("not implemented") } @@ -71,15 +71,15 @@ func (ms multiStore) GetPruning() sdk.PruningOptions { panic("not implemented") } -func (ms multiStore) GetCommitKVStore(key store.StoreKey) store.CommitKVStore { +func (ms multiStore) GetCommitKVStore(key storetypes.StoreKey) storetypes.CommitKVStore { panic("not implemented") } -func (ms multiStore) GetCommitStore(key store.StoreKey) store.CommitStore { +func (ms multiStore) GetCommitStore(key storetypes.StoreKey) storetypes.CommitStore { panic("not implemented") } -func (ms multiStore) MountStoreWithDB(key store.StoreKey, typ store.StoreType, db dbm.DB) { +func (ms multiStore) MountStoreWithDB(key storetypes.StoreKey, typ storetypes.StoreType, db dbm.DB) { ms.kv[key] = kvStore{store: make(map[string][]byte)} } @@ -87,11 +87,11 @@ func (ms multiStore) LoadLatestVersion() error { return nil } -func (ms multiStore) LoadLatestVersionAndUpgrade(upgrades *store.StoreUpgrades) error { +func (ms multiStore) LoadLatestVersionAndUpgrade(upgrades *storetypes.StoreUpgrades) error { return nil } -func (ms multiStore) LoadVersionAndUpgrade(ver int64, upgrades *store.StoreUpgrades) error { +func (ms multiStore) LoadVersionAndUpgrade(ver int64, upgrades *storetypes.StoreUpgrades) error { panic("not implemented") } @@ -99,15 +99,15 @@ func (ms multiStore) LoadVersion(ver int64) error { panic("not implemented") } -func (ms multiStore) GetKVStore(key store.StoreKey) sdk.KVStore { +func (ms multiStore) GetKVStore(key storetypes.StoreKey) sdk.KVStore { return ms.kv[key] } -func (ms multiStore) GetStore(key store.StoreKey) sdk.Store { +func (ms multiStore) GetStore(key storetypes.StoreKey) sdk.Store { panic("not implemented") } -func (ms multiStore) GetStoreType() store.StoreType { +func (ms multiStore) GetStoreType() storetypes.StoreType { panic("not implemented") } @@ -135,19 +135,19 @@ type kvStore struct { store map[string][]byte } -func (kv kvStore) CacheWrap() store.CacheWrap { +func (kv kvStore) CacheWrap() storetypes.CacheWrap { panic("not implemented") } -func (kv kvStore) CacheWrapWithTrace(w io.Writer, tc sdk.TraceContext) store.CacheWrap { +func (kv kvStore) CacheWrapWithTrace(w io.Writer, tc sdk.TraceContext) storetypes.CacheWrap { panic("not implemented") } -func (kv kvStore) CacheWrapWithListeners(_ store.StoreKey, _ []store.WriteListener) store.CacheWrap { +func (kv kvStore) CacheWrapWithListeners(_ storetypes.StoreKey, _ []storetypes.WriteListener) storetypes.CacheWrap { panic("not implemented") } -func (kv kvStore) GetStoreType() store.StoreType { +func (kv kvStore) GetStoreType() storetypes.StoreType { panic("not implemented") } @@ -165,7 +165,7 @@ func (kv kvStore) Has(key []byte) bool { } func (kv kvStore) Set(key, value []byte) { - store.AssertValidKey(key) + storetypes.AssertValidKey(key) kv.store[string(key)] = value } @@ -198,5 +198,5 @@ func (kv kvStore) ReverseSubspaceIterator(prefix []byte) sdk.Iterator { } func NewCommitMultiStore() sdk.CommitMultiStore { - return multiStore{kv: make(map[store.StoreKey]kvStore)} + return multiStore{kv: make(map[storetypes.StoreKey]kvStore)} } diff --git a/types/context.go b/types/context.go index 9e9edbf2e24b..b802070a3b82 100644 --- a/types/context.go +++ b/types/context.go @@ -11,7 +11,7 @@ import ( tmproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/store/gaskv" - stypes "github.com/cosmos/cosmos-sdk/store/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" ) /* @@ -87,7 +87,7 @@ func NewContext(ms MultiStore, header tmproto.Header, isCheckTx bool, logger log chainID: header.ChainID, checkTx: isCheckTx, logger: logger, - gasMeter: stypes.NewInfiniteGasMeter(), + gasMeter: storetypes.NewInfiniteGasMeter(), minGasPrice: DecCoins{}, eventManager: NewEventManager(), } @@ -243,13 +243,13 @@ func (c Context) Value(key interface{}) interface{} { // ---------------------------------------------------------------------------- // KVStore fetches a KVStore from the MultiStore. -func (c Context) KVStore(key stypes.StoreKey) KVStore { - return gaskv.NewStore(c.MultiStore().GetKVStore(key), c.GasMeter(), stypes.KVGasConfig()) +func (c Context) KVStore(key storetypes.StoreKey) KVStore { + return gaskv.NewStore(c.MultiStore().GetKVStore(key), c.GasMeter(), storetypes.KVGasConfig()) } // TransientStore fetches a TransientStore from the MultiStore. -func (c Context) TransientStore(key stypes.StoreKey) KVStore { - return gaskv.NewStore(c.MultiStore().GetKVStore(key), c.GasMeter(), stypes.TransientGasConfig()) +func (c Context) TransientStore(key storetypes.StoreKey) KVStore { + return gaskv.NewStore(c.MultiStore().GetKVStore(key), c.GasMeter(), storetypes.TransientGasConfig()) } // CacheContext returns a new Context with the multi-store cached and a new diff --git a/x/gov/keeper/msg_server.go b/x/gov/keeper/msg_server.go index 89876271336e..a3b42b9b3a39 100644 --- a/x/gov/keeper/msg_server.go +++ b/x/gov/keeper/msg_server.go @@ -7,7 +7,7 @@ import ( "github.com/armon/go-metrics" - store "github.com/cosmos/cosmos-sdk/store/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/gov/types" @@ -39,7 +39,7 @@ func (k msgServer) SubmitProposal(goCtx context.Context, msg *types.MsgSubmitPro // ref: https://github.com/cosmos/cosmos-sdk/issues/9683 ctx.GasMeter().ConsumeGas( - 3*store.KVGasConfig().WriteCostPerByte*uint64(len(bytes)), + 3*storetypes.KVGasConfig().WriteCostPerByte*uint64(len(bytes)), "submit proposal", ) diff --git a/x/upgrade/types/storeloader.go b/x/upgrade/types/storeloader.go index 00538e07152a..3911effbed30 100644 --- a/x/upgrade/types/storeloader.go +++ b/x/upgrade/types/storeloader.go @@ -2,13 +2,13 @@ package types import ( "github.com/cosmos/cosmos-sdk/baseapp" - store "github.com/cosmos/cosmos-sdk/store/types" + 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 *store.StoreUpgrades) baseapp.StoreLoader { +func UpgradeStoreLoader(upgradeHeight int64, storeUpgrades *storetypes.StoreUpgrades) baseapp.StoreLoader { return func(ms sdk.CommitMultiStore) error { if upgradeHeight == ms.LastCommitID().Version+1 { // Check if the current commit version and upgrade height matches diff --git a/x/upgrade/types/storeloader_test.go b/x/upgrade/types/storeloader_test.go index b06678fc2a56..20e28888ed33 100644 --- a/x/upgrade/types/storeloader_test.go +++ b/x/upgrade/types/storeloader_test.go @@ -15,11 +15,11 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/store/rootmulti" - store "github.com/cosmos/cosmos-sdk/store/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" ) -func useUpgradeLoader(height int64, upgrades *store.StoreUpgrades) func(*baseapp.BaseApp) { +func useUpgradeLoader(height int64, upgrades *storetypes.StoreUpgrades) func(*baseapp.BaseApp) { return func(app *baseapp.BaseApp) { app.SetStoreLoader(UpgradeStoreLoader(height, upgrades)) } @@ -31,15 +31,15 @@ func defaultLogger() log.Logger { func initStore(t *testing.T, db dbm.DB, storeKey string, k, v []byte) { rs := rootmulti.NewStore(db) - rs.SetPruning(store.PruneNothing) + rs.SetPruning(storetypes.PruneNothing) key := sdk.NewKVStoreKey(storeKey) - rs.MountStoreWithDB(key, store.StoreTypeIAVL, nil) + rs.MountStoreWithDB(key, storetypes.StoreTypeIAVL, nil) err := rs.LoadLatestVersion() require.Nil(t, err) require.Equal(t, int64(0), rs.LastCommitID().Version) // write some data in substore - kv, _ := rs.GetStore(key).(store.KVStore) + kv, _ := rs.GetStore(key).(storetypes.KVStore) require.NotNil(t, kv) kv.Set(k, v) commitID := rs.Commit() @@ -48,15 +48,15 @@ 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) - rs.SetPruning(store.PruneNothing) + rs.SetPruning(storetypes.PruneNothing) key := sdk.NewKVStoreKey(storeKey) - rs.MountStoreWithDB(key, store.StoreTypeIAVL, nil) + rs.MountStoreWithDB(key, storetypes.StoreTypeIAVL, nil) err := rs.LoadLatestVersion() require.Nil(t, err) require.Equal(t, ver, rs.LastCommitID().Version) // query data in substore - kv, _ := rs.GetStore(key).(store.KVStore) + kv, _ := rs.GetStore(key).(storetypes.KVStore) require.NotNil(t, kv) require.Equal(t, v, kv.Get(k)) @@ -95,8 +95,8 @@ func TestSetLoader(t *testing.T) { loadStoreKey: "foo", }, "rename with inline opts": { - setLoader: useUpgradeLoader(upgradeHeight, &store.StoreUpgrades{ - Renamed: []store.StoreRename{{ + setLoader: useUpgradeLoader(upgradeHeight, &storetypes.StoreUpgrades{ + Renamed: []storetypes.StoreRename{{ OldKey: "foo", NewKey: "bar", }}, @@ -118,7 +118,7 @@ func TestSetLoader(t *testing.T) { initStore(t, db, tc.origStoreKey, k, v) // load the app with the existing db - opts := []func(*baseapp.BaseApp){baseapp.SetPruning(store.PruneNothing)} + opts := []func(*baseapp.BaseApp){baseapp.SetPruning(storetypes.PruneNothing)} origapp := baseapp.NewBaseApp(t.Name(), defaultLogger(), db, nil, opts...) origapp.MountStores(sdk.NewKVStoreKey(tc.origStoreKey))