forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_common.go
40 lines (33 loc) · 1.07 KB
/
test_common.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package subspace
import (
"os"
"testing"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
dbm "github.com/tendermint/tendermint/libs/db"
"github.com/tendermint/tendermint/libs/log"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/store"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// Keys for parameter access
const (
TestParamStore = "ParamsTest"
)
// Returns components for testing
func DefaultTestComponents(t *testing.T) (sdk.Context, Subspace, func() sdk.CommitID) {
cdc := codec.New()
key := sdk.NewKVStoreKey(StoreKey)
tkey := sdk.NewTransientStoreKey(TStoreKey)
db := dbm.NewMemDB()
ms := store.NewCommitMultiStore(db)
ms.SetTracer(os.Stdout)
ms.SetTracingContext(sdk.TraceContext{})
ms.MountStoreWithDB(key, sdk.StoreTypeIAVL, db)
ms.MountStoreWithDB(tkey, sdk.StoreTypeTransient, db)
err := ms.LoadLatestVersion()
require.Nil(t, err)
ctx := sdk.NewContext(ms, abci.Header{}, false, log.NewTMLogger(os.Stdout))
subspace := NewSubspace(cdc, key, tkey, TestParamStore)
return ctx, subspace, ms.Commit
}