-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathinit.go
140 lines (118 loc) · 4.59 KB
/
init.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package integrationtests
import (
"context"
"flag"
"fmt"
"testing"
"time"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"google.golang.org/grpc"
"github.com/CoreumFoundation/coreum-tools/pkg/logger"
"github.com/CoreumFoundation/coreum/app"
"github.com/CoreumFoundation/coreum/pkg/client"
"github.com/CoreumFoundation/coreum/pkg/config"
"github.com/CoreumFoundation/coreum/pkg/config/constant"
feemodeltypes "github.com/CoreumFoundation/coreum/x/feemodel/types"
)
// stringsFlag allows setting a value multiple times to collect a list, as in -I=val1 -I=val2.
type stringsFlag []string
func (m *stringsFlag) String() string {
if len(*m) == 0 {
return ""
}
return fmt.Sprint(*m)
}
func (m *stringsFlag) Set(val string) error {
*m = append(*m, val)
return nil
}
type testingConfig struct {
GRPCAddress string
NetworkConfig config.NetworkConfig
FundingMnemonic string
StakerMnemonics []string
LogFormat logger.Format
LogVerbose bool
RunUnsafe bool
}
var (
ctx context.Context
cfg testingConfig
chain Chain
)
func init() {
var (
fundingMnemonic, coredAddress, logFormat string
chainID string
stakerMnemonics stringsFlag
runUnsafe bool
)
flag.StringVar(&coredAddress, "cored-address", "localhost:9090", "Address of cored node started by znet")
flag.StringVar(&fundingMnemonic, "funding-mnemonic", "pitch basic bundle cause toe sound warm love town crucial divorce shell olympic convince scene middle garment glimpse narrow during fix fruit suffer honey", "Funding account mnemonic required by tests")
flag.Var(&stakerMnemonics, "staker-mnemonic", "Staker account mnemonics required by tests, supports multiple")
flag.StringVar(&logFormat, "log-format", string(logger.ToolDefaultConfig.Format), "Format of logs produced by tests")
flag.StringVar(&chainID, "chain-id", string(constant.ChainIDDev), "Which chain-id to use (coreum-devnet-1, coreum-testnet-1,...)")
flag.BoolVar(&runUnsafe, "run-unsafe", false, "run unsafe tests for example ones related to governance")
// accept testing flags
testing.Init()
// parse additional flags
flag.Parse()
// set the default staker mnemonic used in the dev znet by default
if len(stakerMnemonics) == 0 {
stakerMnemonics = []string{
"biology rigid design broccoli adult hood modify tissue swallow arctic option improve quiz cliff inject soup ozone suffer fantasy layer negative eagle leader priority",
"enemy fix tribe swift alcohol metal salad edge episode dry tired address bless cloth error useful define rough fold swift confirm century wasp acoustic",
"act electric demand cancel duck invest below once obvious estate interest solution drink mango reason already clean host limit stadium smoke census pattern express",
}
}
networkConfig, err := NewNetworkConfig(constant.ChainID(chainID))
if err != nil {
panic(fmt.Sprintf("can't create network config for the integration tests: %s", err))
}
cfg = testingConfig{
GRPCAddress: coredAddress,
NetworkConfig: networkConfig,
FundingMnemonic: fundingMnemonic,
StakerMnemonics: stakerMnemonics,
LogFormat: logger.Format(logFormat),
LogVerbose: flag.Lookup("test.v").Value.String() == "true",
RunUnsafe: runUnsafe,
}
loggerConfig := logger.Config{
Format: cfg.LogFormat,
Verbose: cfg.LogVerbose,
}
ctx = logger.WithLogger(context.Background(), logger.New(loggerConfig))
cfg.NetworkConfig.SetSDKConfig()
grpcClient, err := grpc.Dial(coredAddress, grpc.WithInsecure())
if err != nil {
panic(err)
}
clientCtx := client.NewContext(client.DefaultContextConfig(), app.ModuleBasics).
WithChainID(string(cfg.NetworkConfig.ChainID())).
WithKeyring(newConcurrentSafeKeyring(keyring.NewInMemory())).
WithBroadcastMode(flags.BroadcastBlock).
WithGRPCClient(grpcClient)
feemodelClient := feemodeltypes.NewQueryClient(clientCtx)
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
_, err = feemodelClient.Params(ctx, &feemodeltypes.QueryParamsRequest{})
if err != nil {
panic(err)
}
chain = NewChain(ChainConfig{
ClientContext: clientCtx,
GRPCAddress: cfg.GRPCAddress,
NetworkConfig: cfg.NetworkConfig,
FeeModelParams: feemodeltypes.DefaultParams(),
FundingMnemonic: cfg.FundingMnemonic,
StakerMnemonics: cfg.StakerMnemonics,
})
}
// NewTestingContext returns the configured chain and new context for the integration tests.
func NewTestingContext(t *testing.T) (context.Context, Chain) {
ctx, cancel := context.WithCancel(ctx)
t.Cleanup(cancel)
return ctx, chain
}