Skip to content

Commit

Permalink
standardize storetypes imports
Browse files Browse the repository at this point in the history
  • Loading branch information
iverc committed Oct 3, 2021
1 parent c3af1f3 commit 9fc7fd8
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 56 deletions.
23 changes: 11 additions & 12 deletions baseapp/baseapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand All @@ -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))
}
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
46 changes: 23 additions & 23 deletions server/mock/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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")
}

Expand All @@ -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")
}

Expand All @@ -71,43 +71,43 @@ 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)}
}

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")
}

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")
}

Expand Down Expand Up @@ -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")
}

Expand All @@ -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
}

Expand Down Expand Up @@ -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)}
}
12 changes: 6 additions & 6 deletions types/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

/*
Expand Down Expand Up @@ -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(),
}
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions x/gov/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
)

Expand Down
4 changes: 2 additions & 2 deletions x/upgrade/types/storeloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 11 additions & 11 deletions x/upgrade/types/storeloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand All @@ -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()
Expand All @@ -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))
Expand Down Expand Up @@ -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",
}},
Expand All @@ -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))
Expand Down

0 comments on commit 9fc7fd8

Please sign in to comment.