34 lines
773 B
Go
34 lines
773 B
Go
|
package orm
|
||
|
|
||
|
import (
|
||
|
"github.com/cosmos/cosmos-sdk/store"
|
||
|
"github.com/cosmos/cosmos-sdk/store/types"
|
||
|
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
||
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||
|
dbm "github.com/tendermint/tm-db"
|
||
|
)
|
||
|
|
||
|
type MockContext struct {
|
||
|
db *dbm.MemDB
|
||
|
store types.CommitMultiStore
|
||
|
}
|
||
|
|
||
|
func NewMockContext() *MockContext {
|
||
|
db := dbm.NewMemDB()
|
||
|
return &MockContext{
|
||
|
db: dbm.NewMemDB(),
|
||
|
store: store.NewCommitMultiStore(db),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (m MockContext) KVStore(key storetypes.StoreKey) sdk.KVStore {
|
||
|
if s := m.store.GetCommitKVStore(key); s != nil {
|
||
|
return s
|
||
|
}
|
||
|
m.store.MountStoreWithDB(key, storetypes.StoreTypeIAVL, m.db)
|
||
|
if err := m.store.LoadLatestVersion(); err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
return m.store.GetCommitKVStore(key)
|
||
|
}
|