refactor: Remove store type aliases (#10295)
<!-- The default pull request template is for types feat, fix, or refactor. For other templates, add one of the following parameters to the url: - template=docs.md - template=other.md --> ## Description Closes: #9362 <!-- Add a description of the changes that this PR introduces and the files that are the most critical to review. --> --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [X] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [X] added `!` to the type prefix if API or client breaking change - [X] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [X] provided a link to the relevant issue or specification - [X] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [X] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [X] added a changelog entry to `CHANGELOG.md` - [X] included comments for [documenting Go code](https://blog.golang.org/godoc) - [X] updated the relevant documentation or specification - [X] reviewed "Files changed" and left comments if necessary - [X] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
This commit is contained in:
+16
-15
@@ -15,6 +15,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/snapshots"
|
||||
"github.com/cosmos/cosmos-sdk/store"
|
||||
"github.com/cosmos/cosmos-sdk/store/rootmulti"
|
||||
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/tx"
|
||||
)
|
||||
@@ -185,20 +186,20 @@ func (app *BaseApp) Trace() bool {
|
||||
|
||||
// MountStores mounts all IAVL or DB stores to the provided keys in the BaseApp
|
||||
// multistore.
|
||||
func (app *BaseApp) MountStores(keys ...sdk.StoreKey) {
|
||||
func (app *BaseApp) MountStores(keys ...storetypes.StoreKey) {
|
||||
for _, key := range keys {
|
||||
switch key.(type) {
|
||||
case *sdk.KVStoreKey:
|
||||
case *storetypes.KVStoreKey:
|
||||
if !app.fauxMerkleMode {
|
||||
app.MountStore(key, sdk.StoreTypeIAVL)
|
||||
app.MountStore(key, storetypes.StoreTypeIAVL)
|
||||
} else {
|
||||
// StoreTypeDB doesn't do anything upon commit, and it doesn't
|
||||
// retain history, but it's useful for faster simulation.
|
||||
app.MountStore(key, sdk.StoreTypeDB)
|
||||
app.MountStore(key, storetypes.StoreTypeDB)
|
||||
}
|
||||
|
||||
case *sdk.TransientStoreKey:
|
||||
app.MountStore(key, sdk.StoreTypeTransient)
|
||||
case *storetypes.TransientStoreKey:
|
||||
app.MountStore(key, storetypes.StoreTypeTransient)
|
||||
|
||||
default:
|
||||
panic("Unrecognized store key type " + reflect.TypeOf(key).Name())
|
||||
@@ -208,37 +209,37 @@ func (app *BaseApp) MountStores(keys ...sdk.StoreKey) {
|
||||
|
||||
// MountKVStores mounts all IAVL or DB stores to the provided keys in the
|
||||
// BaseApp multistore.
|
||||
func (app *BaseApp) MountKVStores(keys map[string]*sdk.KVStoreKey) {
|
||||
func (app *BaseApp) MountKVStores(keys map[string]*storetypes.KVStoreKey) {
|
||||
for _, key := range keys {
|
||||
if !app.fauxMerkleMode {
|
||||
app.MountStore(key, sdk.StoreTypeIAVL)
|
||||
app.MountStore(key, storetypes.StoreTypeIAVL)
|
||||
} else {
|
||||
// StoreTypeDB doesn't do anything upon commit, and it doesn't
|
||||
// retain history, but it's useful for faster simulation.
|
||||
app.MountStore(key, sdk.StoreTypeDB)
|
||||
app.MountStore(key, storetypes.StoreTypeDB)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MountTransientStores mounts all transient stores to the provided keys in
|
||||
// the BaseApp multistore.
|
||||
func (app *BaseApp) MountTransientStores(keys map[string]*sdk.TransientStoreKey) {
|
||||
func (app *BaseApp) MountTransientStores(keys map[string]*storetypes.TransientStoreKey) {
|
||||
for _, key := range keys {
|
||||
app.MountStore(key, sdk.StoreTypeTransient)
|
||||
app.MountStore(key, storetypes.StoreTypeTransient)
|
||||
}
|
||||
}
|
||||
|
||||
// MountMemoryStores mounts all in-memory KVStores with the BaseApp's internal
|
||||
// commit multi-store.
|
||||
func (app *BaseApp) MountMemoryStores(keys map[string]*sdk.MemoryStoreKey) {
|
||||
func (app *BaseApp) MountMemoryStores(keys map[string]*storetypes.MemoryStoreKey) {
|
||||
for _, memKey := range keys {
|
||||
app.MountStore(memKey, sdk.StoreTypeMemory)
|
||||
app.MountStore(memKey, storetypes.StoreTypeMemory)
|
||||
}
|
||||
}
|
||||
|
||||
// MountStore mounts a store to the provided key in the BaseApp multistore,
|
||||
// using the default DB.
|
||||
func (app *BaseApp) MountStore(key sdk.StoreKey, typ sdk.StoreType) {
|
||||
func (app *BaseApp) MountStore(key storetypes.StoreKey, typ storetypes.StoreType) {
|
||||
app.cms.MountStoreWithDB(key, typ, nil)
|
||||
}
|
||||
|
||||
@@ -270,7 +271,7 @@ func (app *BaseApp) LoadVersion(version int64) error {
|
||||
}
|
||||
|
||||
// LastCommitID returns the last CommitID of the multistore.
|
||||
func (app *BaseApp) LastCommitID() sdk.CommitID {
|
||||
func (app *BaseApp) LastCommitID() storetypes.CommitID {
|
||||
return app.cms.LastCommitID()
|
||||
}
|
||||
|
||||
|
||||
+22
-22
@@ -27,7 +27,7 @@ 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"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
@@ -234,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)
|
||||
@@ -243,7 +243,7 @@ func TestLoadVersion(t *testing.T) {
|
||||
err := app.LoadLatestVersion() // needed to make stores non-nil
|
||||
require.Nil(t, err)
|
||||
|
||||
emptyCommitID := sdk.CommitID{}
|
||||
emptyCommitID := storetypes.CommitID{}
|
||||
|
||||
// fresh store has zero/empty last commit
|
||||
lastHeight := app.LastBlockHeight()
|
||||
@@ -255,13 +255,13 @@ func TestLoadVersion(t *testing.T) {
|
||||
header := tmproto.Header{Height: 1}
|
||||
app.BeginBlock(abci.RequestBeginBlock{Header: header})
|
||||
res := app.Commit()
|
||||
commitID1 := sdk.CommitID{Version: 1, Hash: res.Data}
|
||||
commitID1 := storetypes.CommitID{Version: 1, Hash: res.Data}
|
||||
|
||||
// execute a block, collect commit ID
|
||||
header = tmproto.Header{Height: 2}
|
||||
app.BeginBlock(abci.RequestBeginBlock{Header: header})
|
||||
res = app.Commit()
|
||||
commitID2 := sdk.CommitID{Version: 2, Hash: res.Data}
|
||||
commitID2 := storetypes.CommitID{Version: 2, Hash: res.Data}
|
||||
|
||||
// reload with LoadLatestVersion
|
||||
app = baseapp.NewBaseApp(name, logger, db, nil, pruningOpt)
|
||||
@@ -287,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()
|
||||
@@ -304,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))
|
||||
}
|
||||
@@ -347,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)
|
||||
}
|
||||
@@ -370,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)
|
||||
@@ -390,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)
|
||||
@@ -405,7 +405,7 @@ func TestLoadVersionInvalid(t *testing.T) {
|
||||
header := tmproto.Header{Height: 1}
|
||||
app.BeginBlock(abci.RequestBeginBlock{Header: header})
|
||||
res := app.Commit()
|
||||
commitID1 := sdk.CommitID{Version: 1, Hash: res.Data}
|
||||
commitID1 := storetypes.CommitID{Version: 1, Hash: res.Data}
|
||||
|
||||
// create a new app with the stores mounted under the same cap key
|
||||
app = baseapp.NewBaseApp(name, logger, db, nil, pruningOpt)
|
||||
@@ -422,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,
|
||||
@@ -439,7 +439,7 @@ func TestLoadVersionPruning(t *testing.T) {
|
||||
err := app.LoadLatestVersion() // needed to make stores non-nil
|
||||
require.Nil(t, err)
|
||||
|
||||
emptyCommitID := sdk.CommitID{}
|
||||
emptyCommitID := storetypes.CommitID{}
|
||||
|
||||
// fresh store has zero/empty last commit
|
||||
lastHeight := app.LastBlockHeight()
|
||||
@@ -447,14 +447,14 @@ func TestLoadVersionPruning(t *testing.T) {
|
||||
require.Equal(t, int64(0), lastHeight)
|
||||
require.Equal(t, emptyCommitID, lastID)
|
||||
|
||||
var lastCommitID sdk.CommitID
|
||||
var lastCommitID storetypes.CommitID
|
||||
|
||||
// Commit seven blocks, of which 7 (latest) is kept in addition to 6, 5
|
||||
// (keep recent) and 3 (keep every).
|
||||
for i := int64(1); i <= 7; i++ {
|
||||
app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: i}})
|
||||
res := app.Commit()
|
||||
lastCommitID = sdk.CommitID{Version: i, Hash: res.Data}
|
||||
lastCommitID = storetypes.CommitID{Version: i, Hash: res.Data}
|
||||
}
|
||||
|
||||
for _, v := range []int64{1, 2, 4} {
|
||||
@@ -476,7 +476,7 @@ func TestLoadVersionPruning(t *testing.T) {
|
||||
testLoadVersionHelper(t, app, int64(7), lastCommitID)
|
||||
}
|
||||
|
||||
func testLoadVersionHelper(t *testing.T, app *baseapp.BaseApp, expectedHeight int64, expectedID sdk.CommitID) {
|
||||
func testLoadVersionHelper(t *testing.T, app *baseapp.BaseApp, expectedHeight int64, expectedID storetypes.CommitID) {
|
||||
lastHeight := app.LastBlockHeight()
|
||||
lastID := app.LastCommitID()
|
||||
require.Equal(t, expectedHeight, lastHeight)
|
||||
@@ -845,7 +845,7 @@ func testTxDecoder(cdc *codec.LegacyAmino) sdk.TxDecoder {
|
||||
}
|
||||
}
|
||||
|
||||
func customHandlerTxTest(t *testing.T, capKey sdk.StoreKey, storeKey []byte) handlerFun {
|
||||
func customHandlerTxTest(t *testing.T, capKey storetypes.StoreKey, storeKey []byte) handlerFun {
|
||||
return func(ctx sdk.Context, tx sdk.Tx, simulate bool) (sdk.Context, error) {
|
||||
store := ctx.KVStore(capKey)
|
||||
txTest := tx.(txTest)
|
||||
@@ -876,7 +876,7 @@ func counterEvent(evType string, msgCount int64) sdk.Events {
|
||||
}
|
||||
}
|
||||
|
||||
func handlerMsgCounter(t *testing.T, capKey sdk.StoreKey, deliverKey []byte) sdk.Handler {
|
||||
func handlerMsgCounter(t *testing.T, capKey storetypes.StoreKey, deliverKey []byte) sdk.Handler {
|
||||
return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) {
|
||||
ctx = ctx.WithEventManager(sdk.NewEventManager())
|
||||
store := ctx.KVStore(capKey)
|
||||
|
||||
Reference in New Issue
Block a user