Store Refactor 1 (#2985)
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/store"
|
||||
"github.com/cosmos/cosmos-sdk/store/prefix"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
@@ -71,7 +72,7 @@ func TestKeeper(t *testing.T) {
|
||||
ctx := defaultContext(skey, tkey)
|
||||
keeper := NewKeeper(cdc, skey, tkey)
|
||||
space := keeper.Subspace("test").WithTypeTable(table)
|
||||
store := ctx.KVStore(skey).Prefix([]byte("test/"))
|
||||
store := prefix.NewStore(ctx.KVStore(skey), []byte("test/"))
|
||||
|
||||
// Set params
|
||||
for i, kv := range kvs {
|
||||
@@ -177,7 +178,7 @@ func TestSubspace(t *testing.T) {
|
||||
[]byte("struct"), s{},
|
||||
)
|
||||
|
||||
store := ctx.KVStore(key).Prefix([]byte("test/"))
|
||||
store := prefix.NewStore(ctx.KVStore(key), []byte("test/"))
|
||||
space := keeper.Subspace("test").WithTypeTable(table)
|
||||
|
||||
// Test space.Set, space.Modified
|
||||
|
||||
@@ -5,6 +5,8 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/store/prefix"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -69,14 +71,14 @@ func (s Subspace) WithTypeTable(table TypeTable) Subspace {
|
||||
func (s Subspace) kvStore(ctx sdk.Context) sdk.KVStore {
|
||||
// append here is safe, appends within a function won't cause
|
||||
// weird side effects when its singlethreaded
|
||||
return ctx.KVStore(s.key).Prefix(append(s.name, '/'))
|
||||
return prefix.NewStore(ctx.KVStore(s.key), append(s.name, '/'))
|
||||
}
|
||||
|
||||
// Returns a KVStore identical with ctx.TransientStore(s.tkey).Prefix()
|
||||
func (s Subspace) transientStore(ctx sdk.Context) sdk.KVStore {
|
||||
// append here is safe, appends within a function won't cause
|
||||
// weird side effects when its singlethreaded
|
||||
return ctx.TransientStore(s.tkey).Prefix(append(s.name, '/'))
|
||||
return prefix.NewStore(ctx.TransientStore(s.tkey), append(s.name, '/'))
|
||||
}
|
||||
|
||||
// Get parameter from store
|
||||
|
||||
@@ -27,8 +27,8 @@ func DefaultTestComponents(t *testing.T, table TypeTable) (sdk.Context, Subspace
|
||||
tkey := sdk.NewTransientStoreKey(TStoreKey)
|
||||
db := dbm.NewMemDB()
|
||||
ms := store.NewCommitMultiStore(db)
|
||||
ms.WithTracer(os.Stdout)
|
||||
ms.WithTracingContext(sdk.TraceContext{})
|
||||
ms.SetTracer(os.Stdout)
|
||||
ms.SetTracingContext(sdk.TraceContext{})
|
||||
ms.MountStoreWithDB(key, sdk.StoreTypeIAVL, db)
|
||||
ms.MountStoreWithDB(tkey, sdk.StoreTypeTransient, db)
|
||||
err := ms.LoadLatestVersion()
|
||||
|
||||
Reference in New Issue
Block a user