From 70c03b360634288805329873e134af182ac709b5 Mon Sep 17 00:00:00 2001 From: mossid Date: Mon, 17 Sep 2018 00:02:03 +0900 Subject: [PATCH] test passes --- .../democoin/x/assoc/validator_set_test.go | 5 +- examples/democoin/x/cool/keeper_test.go | 2 +- examples/democoin/x/oracle/oracle_test.go | 2 +- examples/democoin/x/pow/keeper_test.go | 2 +- .../democoin/x/simplestake/keeper_test.go | 4 +- server/mock/store.go | 154 ------------------ server/mock/store_test.go | 33 ---- store/gas/store_test.go | 2 +- store/transient/store.go | 8 +- types/lib/linear_test.go | 2 +- x/bank/keeper_test.go | 2 +- x/ibc/ibc_test.go | 2 +- 12 files changed, 19 insertions(+), 199 deletions(-) delete mode 100644 server/mock/store.go delete mode 100644 server/mock/store_test.go diff --git a/examples/democoin/x/assoc/validator_set_test.go b/examples/democoin/x/assoc/validator_set_test.go index 9fc6526f8d3e..2215c51187c8 100644 --- a/examples/democoin/x/assoc/validator_set_test.go +++ b/examples/democoin/x/assoc/validator_set_test.go @@ -12,13 +12,14 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/examples/democoin/mock" "github.com/cosmos/cosmos-sdk/store" + "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" ) func defaultContext(key sdk.StoreKey) sdk.Context { db := dbm.NewMemDB() cms := store.NewCommitMultiStore(db) - cms.MountStoreWithDB(key, sdk.StoreTypeIAVL, db) + cms.MountStoreWithDB(key, db) cms.LoadLatestVersion() ctx := sdk.NewContext(cms, abci.Header{}, false, nil) return ctx @@ -36,7 +37,7 @@ func TestValidatorSet(t *testing.T) { {addr2, sdk.NewDec(2)}, }} - valset := NewValidatorSet(codec.New(), ctx.KVStore(key).Prefix([]byte("assoc")), base, 1, 5) + valset := NewValidatorSet(codec.New(), prefix.NewStore(ctx.KVStore(key), []byte("assoc")), base, 1, 5) require.Equal(t, base.Validator(ctx, addr1), valset.Validator(ctx, addr1)) require.Equal(t, base.Validator(ctx, addr2), valset.Validator(ctx, addr2)) diff --git a/examples/democoin/x/cool/keeper_test.go b/examples/democoin/x/cool/keeper_test.go index e3af7790e4b2..823d2575bf5b 100644 --- a/examples/democoin/x/cool/keeper_test.go +++ b/examples/democoin/x/cool/keeper_test.go @@ -19,7 +19,7 @@ func setupMultiStore() (sdk.MultiStore, *sdk.KVStoreKey) { db := dbm.NewMemDB() capKey := sdk.NewKVStoreKey("capkey") ms := store.NewCommitMultiStore(db) - ms.MountStoreWithDB(capKey, sdk.StoreTypeIAVL, db) + ms.MountStoreWithDB(capKey, db) ms.LoadLatestVersion() return ms, capKey } diff --git a/examples/democoin/x/oracle/oracle_test.go b/examples/democoin/x/oracle/oracle_test.go index 416d933f2d25..471bf1dd972c 100644 --- a/examples/democoin/x/oracle/oracle_test.go +++ b/examples/democoin/x/oracle/oracle_test.go @@ -19,7 +19,7 @@ func defaultContext(keys ...sdk.StoreKey) sdk.Context { db := dbm.NewMemDB() cms := store.NewCommitMultiStore(db) for _, key := range keys { - cms.MountStoreWithDB(key, sdk.StoreTypeIAVL, db) + cms.MountStoreWithDB(key, db) } cms.LoadLatestVersion() ctx := sdk.NewContext(cms, abci.Header{}, false, nil) diff --git a/examples/democoin/x/pow/keeper_test.go b/examples/democoin/x/pow/keeper_test.go index dbd974c4d076..441ebdd00f1e 100644 --- a/examples/democoin/x/pow/keeper_test.go +++ b/examples/democoin/x/pow/keeper_test.go @@ -21,7 +21,7 @@ func setupMultiStore() (sdk.MultiStore, *sdk.KVStoreKey) { db := dbm.NewMemDB() capKey := sdk.NewKVStoreKey("capkey") ms := store.NewCommitMultiStore(db) - ms.MountStoreWithDB(capKey, sdk.StoreTypeIAVL, db) + ms.MountStoreWithDB(capKey, db) ms.LoadLatestVersion() return ms, capKey diff --git a/examples/democoin/x/simplestake/keeper_test.go b/examples/democoin/x/simplestake/keeper_test.go index 68f28bd91b07..4084527b99be 100644 --- a/examples/democoin/x/simplestake/keeper_test.go +++ b/examples/democoin/x/simplestake/keeper_test.go @@ -24,8 +24,8 @@ func setupMultiStore() (sdk.MultiStore, *sdk.KVStoreKey, *sdk.KVStoreKey) { authKey := sdk.NewKVStoreKey("authkey") capKey := sdk.NewKVStoreKey("capkey") ms := store.NewCommitMultiStore(db) - ms.MountStoreWithDB(capKey, sdk.StoreTypeIAVL, db) - ms.MountStoreWithDB(authKey, sdk.StoreTypeIAVL, db) + ms.MountStoreWithDB(capKey, db) + ms.MountStoreWithDB(authKey, db) ms.LoadLatestVersion() return ms, authKey, capKey } diff --git a/server/mock/store.go b/server/mock/store.go deleted file mode 100644 index ec963a1bc22c..000000000000 --- a/server/mock/store.go +++ /dev/null @@ -1,154 +0,0 @@ -package mock - -import ( - "io" - - dbm "github.com/tendermint/tendermint/libs/db" - - sdk "github.com/cosmos/cosmos-sdk/types" -) - -var _ sdk.MultiStore = multiStore{} - -type multiStore struct { - kv map[sdk.StoreKey]kvStore -} - -func (ms multiStore) CacheMultiStore() sdk.CacheMultiStore { - panic("not implemented") -} - -func (ms multiStore) CacheWrap() sdk.CacheWrap { - panic("not implemented") -} - -func (ms multiStore) CacheWrapWithTrace(_ io.Writer, _ sdk.TraceContext) sdk.CacheWrap { - panic("not implemented") -} - -func (ms multiStore) ResetTraceContext() sdk.MultiStore { - panic("not implemented") -} - -func (ms multiStore) TracingEnabled() bool { - panic("not implemented") -} - -func (ms multiStore) WithTracingContext(tc sdk.TraceContext) sdk.MultiStore { - panic("not implemented") -} - -func (ms multiStore) WithTracer(w io.Writer) sdk.MultiStore { - panic("not implemented") -} - -func (ms multiStore) Commit() sdk.CommitID { - panic("not implemented") -} - -func (ms multiStore) LastCommitID() sdk.CommitID { - panic("not implemented") -} - -func (ms multiStore) SetPruning(s sdk.PruningStrategy) { - panic("not implemented") -} - -func (ms multiStore) GetCommitKVStore(key sdk.StoreKey) sdk.CommitKVStore { - panic("not implemented") -} - -func (ms multiStore) GetCommitStore(key sdk.StoreKey) sdk.CommitStore { - panic("not implemented") -} - -func (ms multiStore) MountStoreWithDB(key sdk.StoreKey, typ sdk.StoreType, db dbm.DB) { - ms.kv[key] = kvStore{store: make(map[string][]byte)} -} - -func (ms multiStore) LoadLatestVersion() error { - return nil -} - -func (ms multiStore) LoadVersion(ver int64) error { - panic("not implemented") -} - -func (ms multiStore) GetKVStore(key sdk.StoreKey) sdk.KVStore { - return ms.kv[key] -} - -func (ms multiStore) GetStore(key sdk.StoreKey) sdk.Store { - panic("not implemented") -} - -func (ms multiStore) GetStoreType() sdk.StoreType { - panic("not implemented") -} - -var _ sdk.KVStore = kvStore{} - -type kvStore struct { - store map[string][]byte -} - -func (kv kvStore) CacheWrap() sdk.CacheWrap { - panic("not implemented") -} - -func (kv kvStore) CacheWrapWithTrace(w io.Writer, tc sdk.TraceContext) sdk.CacheWrap { - panic("not implemented") -} - -func (kv kvStore) GetStoreType() sdk.StoreType { - panic("not implemented") -} - -func (kv kvStore) Get(key []byte) []byte { - v, ok := kv.store[string(key)] - if !ok { - return nil - } - return v -} - -func (kv kvStore) Has(key []byte) bool { - _, ok := kv.store[string(key)] - return ok -} - -func (kv kvStore) Set(key, value []byte) { - kv.store[string(key)] = value -} - -func (kv kvStore) Delete(key []byte) { - delete(kv.store, string(key)) -} - -func (kv kvStore) Prefix(prefix []byte) sdk.KVStore { - panic("not implemented") -} - -func (kv kvStore) Gas(meter sdk.GasMeter, config sdk.GasConfig) sdk.KVStore { - panic("not implmeneted") -} - -func (kv kvStore) Iterator(start, end []byte) sdk.Iterator { - panic("not implemented") -} - -func (kv kvStore) ReverseIterator(start, end []byte) sdk.Iterator { - panic("not implemented") -} - -func (kv kvStore) SubspaceIterator(prefix []byte) sdk.Iterator { - panic("not implemented") -} - -func (kv kvStore) ReverseSubspaceIterator(prefix []byte) sdk.Iterator { - panic("not implemented") -} - -func NewCommitMultiStore() sdk.CommitMultiStore { - return multiStore{kv: make(map[sdk.StoreKey]kvStore)} -} diff --git a/server/mock/store_test.go b/server/mock/store_test.go deleted file mode 100644 index 0ea5ffd2c7a0..000000000000 --- a/server/mock/store_test.go +++ /dev/null @@ -1,33 +0,0 @@ -package mock - -import ( - "testing" - - "github.com/stretchr/testify/require" - - dbm "github.com/tendermint/tendermint/libs/db" - - sdk "github.com/cosmos/cosmos-sdk/types" -) - -func TestStore(t *testing.T) { - db := dbm.NewMemDB() - cms := NewCommitMultiStore() - - key := sdk.NewKVStoreKey("test") - cms.MountStoreWithDB(key, sdk.StoreTypeIAVL, db) - err := cms.LoadLatestVersion() - require.Nil(t, err) - - store := cms.GetKVStore(key) - require.NotNil(t, store) - - k := []byte("hello") - v := []byte("world") - require.False(t, store.Has(k)) - store.Set(k, v) - require.True(t, store.Has(k)) - require.Equal(t, v, store.Get(k)) - store.Delete(k) - require.False(t, store.Has(k)) -} diff --git a/store/gas/store_test.go b/store/gas/store_test.go index 95f05092b4e6..1d4d3baa8699 100644 --- a/store/gas/store_test.go +++ b/store/gas/store_test.go @@ -13,7 +13,7 @@ import ( ) func newGasTank(limit types.Gas) *types.GasTank { - return types.NewGasTank(limit, types.DefaultGasConfig()) + return types.NewGasTank(limit, types.DefaultKVGasConfig()) } func newGasKVStore() types.KVStore { diff --git a/store/transient/store.go b/store/transient/store.go index 4cf1e3c60fce..32040a50b1a0 100644 --- a/store/transient/store.go +++ b/store/transient/store.go @@ -7,7 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/store/dbadapter" ) -var _ types.KVStore = (*Store)(nil) +var _ types.CommitKVStore = (*Store)(nil) // transientStore is a wrapper for a MemDB with Commiter implementation type Store struct { @@ -21,6 +21,12 @@ func NewStore() *Store { return &Store{dbadapter.Store{dbm.NewMemDB()}, new(types.GasTank)} } +// Implements CommitKVStore +func (ts *Store) LoadKVStoreVersion(db dbm.DB, id types.CommitID) error { + *ts = *NewStore() + return nil +} + // Implements CommitStore // Commit cleans up transientStore. func (ts *Store) Commit() (id types.CommitID) { diff --git a/types/lib/linear_test.go b/types/lib/linear_test.go index d19c0406136c..0d729a8b587a 100644 --- a/types/lib/linear_test.go +++ b/types/lib/linear_test.go @@ -24,7 +24,7 @@ type S struct { func defaultComponents(key sdk.StoreKey) (sdk.Context, *codec.Codec) { db := dbm.NewMemDB() cms := store.NewCommitMultiStore(db) - cms.MountStoreWithDB(key, sdk.StoreTypeIAVL, db) + cms.MountStoreWithDB(key, db) cms.LoadLatestVersion() ctx := sdk.NewContext(cms, abci.Header{}, false, log.NewNopLogger()) cdc := codec.New() diff --git a/x/bank/keeper_test.go b/x/bank/keeper_test.go index c48410c154e3..e7f76929e95d 100644 --- a/x/bank/keeper_test.go +++ b/x/bank/keeper_test.go @@ -21,7 +21,7 @@ func setupMultiStore() (sdk.MultiStore, *sdk.KVStoreKey) { db := dbm.NewMemDB() authKey := sdk.NewKVStoreKey("authkey") ms := store.NewCommitMultiStore(db) - ms.MountStoreWithDB(authKey, sdk.StoreTypeIAVL, db) + ms.MountStoreWithDB(authKey, db) ms.LoadLatestVersion() return ms, authKey } diff --git a/x/ibc/ibc_test.go b/x/ibc/ibc_test.go index c8e7492be7f1..ec28ec6c9f69 100644 --- a/x/ibc/ibc_test.go +++ b/x/ibc/ibc_test.go @@ -22,7 +22,7 @@ import ( func defaultContext(key sdk.StoreKey) sdk.Context { db := dbm.NewMemDB() cms := store.NewCommitMultiStore(db) - cms.MountStoreWithDB(key, sdk.StoreTypeIAVL, db) + cms.MountStoreWithDB(key, db) cms.LoadLatestVersion() ctx := sdk.NewContext(cms, abci.Header{}, false, log.NewNopLogger()) return ctx