-
Notifications
You must be signed in to change notification settings - Fork 182
/
test_helpers.go
55 lines (47 loc) · 1.41 KB
/
test_helpers.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package app
import (
"github.com/okex/exchain/libs/cosmos-sdk/codec"
sdk "github.com/okex/exchain/libs/cosmos-sdk/types"
abci "github.com/okex/exchain/libs/tendermint/abci/types"
"github.com/okex/exchain/libs/tendermint/libs/log"
"github.com/okex/exchain/libs/tendermint/types"
dbm "github.com/okex/exchain/libs/tm-db"
"github.com/spf13/viper"
)
type Option func(option *SetupOption)
type SetupOption struct {
chainId string
}
func WithChainId(chainId string) Option {
return func(option *SetupOption) {
option.chainId = chainId
}
}
// Setup initializes a new OKExChainApp. A Nop logger is set in OKExChainApp.
func Setup(isCheckTx bool, options ...Option) *OKExChainApp {
viper.Set(sdk.FlagDBBackend, string(dbm.MemDBBackend))
types.DBBackend = string(dbm.MemDBBackend)
db := dbm.NewMemDB()
app := NewOKExChainApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, 0)
if !isCheckTx {
setupOption := &SetupOption{chainId: ""}
for _, opt := range options {
opt(setupOption)
}
// init chain must be called to stop deliverState from being nil
genesisState := NewDefaultGenesisState()
stateBytes, err := codec.MarshalJSONIndent(app.Codec(), genesisState)
if err != nil {
panic(err)
}
// Initialize the chain
app.InitChain(
abci.RequestInitChain{
Validators: []abci.ValidatorUpdate{},
AppStateBytes: stateBytes,
ChainId: setupOption.chainId,
},
)
}
return app
}