/
test_setup.go
61 lines (53 loc) · 1.52 KB
/
test_setup.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
56
57
58
59
60
61
package app
import (
"encoding/json"
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
ibctesting "github.com/cosmos/ibc-go/v3/testing"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
dbm "github.com/tendermint/tm-db"
)
const Bech32Prefix = "stride"
func init() {
config := sdk.GetConfig()
valoper := sdk.PrefixValidator + sdk.PrefixOperator
valoperpub := sdk.PrefixValidator + sdk.PrefixOperator + sdk.PrefixPublic
config.SetBech32PrefixForAccount(Bech32Prefix, Bech32Prefix+sdk.PrefixPublic)
config.SetBech32PrefixForValidator(Bech32Prefix+valoper, Bech32Prefix+valoperpub)
}
// Initializes a new StrideApp without IBC functionality
func InitStrideTestApp(initChain bool) *StrideApp {
db := dbm.NewMemDB()
app := NewStrideApp(
log.NewNopLogger(),
db,
nil,
true,
map[int64]bool{},
DefaultNodeHome,
5,
MakeEncodingConfig(),
simapp.EmptyAppOptions{},
)
if initChain {
genesisState := NewDefaultGenesisState()
stateBytes, err := json.MarshalIndent(genesisState, "", " ")
if err != nil {
panic(err)
}
app.InitChain(
abci.RequestInitChain{
Validators: []abci.ValidatorUpdate{},
ConsensusParams: simapp.DefaultConsensusParams,
AppStateBytes: stateBytes,
},
)
}
return app
}
// Initializes a new Stride App casted as a TestingApp for IBC support
func InitStrideIBCTestingApp() (ibctesting.TestingApp, map[string]json.RawMessage) {
app := InitStrideTestApp(false)
return app, NewDefaultGenesisState()
}