Skip to content

Commit 459a290

Browse files
authored
tests: add testutils for integration testing (#132)
* tests: add testutils for integration testing * update util * fix config * more updates * rand chain-id * add rpc client integration test example * makefile * rename * updates to makefile
1 parent 61260df commit 459a290

21 files changed

Lines changed: 1938 additions & 2428 deletions

File tree

Makefile

Lines changed: 168 additions & 145 deletions
Large diffs are not rendered by default.
File renamed without changes.

client/docs/statik/statik.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/docs/swagger-ui/swagger.yaml

Lines changed: 485 additions & 1843 deletions
Large diffs are not rendered by default.

cmd/ethermintd/config/config.go

Lines changed: 30 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,11 @@ import (
88

99
"github.com/cosmos/cosmos-sdk/telemetry"
1010

11-
serverconfig "github.com/cosmos/cosmos-sdk/server/config"
12-
storetypes "github.com/cosmos/cosmos-sdk/store/types"
11+
"github.com/cosmos/cosmos-sdk/server/config"
1312
sdk "github.com/cosmos/cosmos-sdk/types"
1413
)
1514

1615
const (
17-
defaultMinGasPrices = ""
18-
1916
// DefaultGRPCAddress is the default address the gRPC server binds to.
2017
DefaultGRPCAddress = "0.0.0.0:9900"
2118

@@ -26,67 +23,6 @@ const (
2623
DefaultEVMWSAddress = "0.0.0.0:1318"
2724
)
2825

29-
// BaseConfig defines the server's basic configuration
30-
type BaseConfig struct {
31-
// The minimum gas prices a validator is willing to accept for processing a
32-
// transaction. A transaction's fees must meet the minimum of any denomination
33-
// specified in this config (e.g. 0.25token1;0.0001token2).
34-
MinGasPrices string `mapstructure:"minimum-gas-prices"`
35-
36-
Pruning string `mapstructure:"pruning"`
37-
PruningKeepRecent string `mapstructure:"pruning-keep-recent"`
38-
PruningKeepEvery string `mapstructure:"pruning-keep-every"`
39-
PruningInterval string `mapstructure:"pruning-interval"`
40-
41-
// HaltHeight contains a non-zero block height at which a node will gracefully
42-
// halt and shutdown that can be used to assist upgrades and testing.
43-
//
44-
// Note: Commitment of state will be attempted on the corresponding block.
45-
HaltHeight uint64 `mapstructure:"halt-height"`
46-
47-
// HaltTime contains a non-zero minimum block time (in Unix seconds) at which
48-
// a node will gracefully halt and shutdown that can be used to assist
49-
// upgrades and testing.
50-
//
51-
// Note: Commitment of state will be attempted on the corresponding block.
52-
HaltTime uint64 `mapstructure:"halt-time"`
53-
54-
// MinRetainBlocks defines the minimum block height offset from the current
55-
// block being committed, such that blocks past this offset may be pruned
56-
// from Tendermint. It is used as part of the process of determining the
57-
// ResponseCommit.RetainHeight value during ABCI Commit. A value of 0 indicates
58-
// that no blocks should be pruned.
59-
//
60-
// This configuration value is only responsible for pruning Tendermint blocks.
61-
// It has no bearing on application state pruning which is determined by the
62-
// "pruning-*" configurations.
63-
//
64-
// Note: Tendermint block pruning is dependant on this parameter in conunction
65-
// with the unbonding (safety threshold) period, state pruning and state sync
66-
// snapshot parameters to determine the correct minimum value of
67-
// ResponseCommit.RetainHeight.
68-
MinRetainBlocks uint64 `mapstructure:"min-retain-blocks"`
69-
70-
// InterBlockCache enables inter-block caching.
71-
InterBlockCache bool `mapstructure:"inter-block-cache"`
72-
73-
// IndexEvents defines the set of events in the form {eventType}.{attributeKey},
74-
// which informs Tendermint what to index. If empty, all events will be indexed.
75-
IndexEvents []string `mapstructure:"index-events"`
76-
}
77-
78-
// APIConfig defines the API listener configuration.
79-
type APIConfig = serverconfig.APIConfig
80-
81-
// GRPCConfig defines configuration for the gRPC server.
82-
type GRPCConfig struct {
83-
// Enable defines if the gRPC server should be enabled.
84-
Enable bool `mapstructure:"enable"`
85-
86-
// Address defines the API server to listen on
87-
Address string `mapstructure:"address"`
88-
}
89-
9026
// EVMRPCConfig defines configuration for the EVM RPC server.
9127
type EVMRPCConfig struct {
9228
// Enable defines if the EVM RPC server should be enabled.
@@ -97,27 +33,26 @@ type EVMRPCConfig struct {
9733
WsAddress string `mapstructure:"ws-address"`
9834
}
9935

100-
// StateSyncConfig defines the state sync snapshot configuration.
101-
type StateSyncConfig struct {
102-
// SnapshotInterval sets the interval at which state sync snapshots are taken.
103-
// 0 disables snapshots. Must be a multiple of PruningKeepEvery.
104-
SnapshotInterval uint64 `mapstructure:"snapshot-interval"`
105-
106-
// SnapshotKeepRecent sets the number of recent state sync snapshots to keep.
107-
// 0 keeps all snapshots.
108-
SnapshotKeepRecent uint32 `mapstructure:"snapshot-keep-recent"`
109-
}
110-
11136
// Config defines the server's top level configuration
11237
type Config struct {
113-
BaseConfig `mapstructure:",squash"`
38+
config.BaseConfig `mapstructure:",squash"`
11439

11540
// Telemetry defines the application telemetry configuration
116-
Telemetry telemetry.Config `mapstructure:"telemetry"`
117-
API APIConfig `mapstructure:"api"`
118-
GRPC GRPCConfig `mapstructure:"grpc"`
119-
EVMRPC EVMRPCConfig `mapstructure:"evm-rpc"`
120-
StateSync StateSyncConfig `mapstructure:"state-sync"`
41+
Telemetry telemetry.Config `mapstructure:"telemetry"`
42+
API config.APIConfig `mapstructure:"api"`
43+
GRPC config.GRPCConfig `mapstructure:"grpc"`
44+
EVMRPC EVMRPCConfig `mapstructure:"evm-rpc"`
45+
StateSync config.StateSyncConfig `mapstructure:"state-sync"`
46+
}
47+
48+
func (c *Config) ToSDKConfig() *config.Config {
49+
return &config.Config{
50+
BaseConfig: c.BaseConfig,
51+
Telemetry: c.Telemetry,
52+
API: c.API,
53+
GRPC: c.GRPC,
54+
StateSync: c.StateSync,
55+
}
12156
}
12257

12358
// SetMinGasPrices sets the validator's minimum gas prices.
@@ -149,95 +84,36 @@ func (c *Config) GetMinGasPrices() sdk.DecCoins {
14984

15085
// DefaultConfig returns server's default configuration.
15186
func DefaultConfig() *Config {
152-
87+
cfg := config.DefaultConfig()
15388
return &Config{
154-
BaseConfig: BaseConfig{
155-
MinGasPrices: defaultMinGasPrices,
156-
InterBlockCache: true,
157-
Pruning: storetypes.PruningOptionNothing,
158-
PruningKeepRecent: "0",
159-
PruningKeepEvery: "0",
160-
PruningInterval: "0",
161-
MinRetainBlocks: 0,
162-
IndexEvents: make([]string, 0),
163-
},
164-
Telemetry: telemetry.Config{
165-
Enabled: false,
166-
GlobalLabels: [][]string{},
167-
},
168-
API: APIConfig{
169-
Enable: true,
170-
Swagger: true,
171-
Address: "tcp://0.0.0.0:10337",
172-
MaxOpenConnections: 1000,
173-
RPCReadTimeout: 10,
174-
RPCMaxBodyBytes: 1000000,
175-
},
176-
GRPC: GRPCConfig{
177-
Enable: true,
178-
Address: DefaultGRPCAddress,
179-
},
89+
BaseConfig: cfg.BaseConfig,
90+
Telemetry: cfg.Telemetry,
91+
API: cfg.API,
92+
GRPC: cfg.GRPC,
18093
EVMRPC: EVMRPCConfig{
18194
Enable: true,
18295
RPCAddress: DefaultEVMAddress,
18396
WsAddress: DefaultEVMWSAddress,
18497
},
185-
StateSync: StateSyncConfig{
186-
SnapshotInterval: 0,
187-
SnapshotKeepRecent: 2,
188-
},
98+
StateSync: cfg.StateSync,
18999
}
190100
}
191101

192102
// GetConfig returns a fully parsed Config object.
193103
func GetConfig(v *viper.Viper) Config {
194-
globalLabelsRaw := v.Get("telemetry.global-labels").([]interface{})
195-
globalLabels := make([][]string, 0, len(globalLabelsRaw))
104+
105+
cfg := config.GetConfig(v)
196106

197107
return Config{
198-
BaseConfig: BaseConfig{
199-
MinGasPrices: v.GetString("minimum-gas-prices"),
200-
InterBlockCache: v.GetBool("inter-block-cache"),
201-
Pruning: v.GetString("pruning"),
202-
PruningKeepRecent: v.GetString("pruning-keep-recent"),
203-
PruningKeepEvery: v.GetString("pruning-keep-every"),
204-
PruningInterval: v.GetString("pruning-interval"),
205-
HaltHeight: v.GetUint64("halt-height"),
206-
HaltTime: v.GetUint64("halt-time"),
207-
IndexEvents: v.GetStringSlice("index-events"),
208-
MinRetainBlocks: v.GetUint64("min-retain-blocks"),
209-
},
210-
Telemetry: telemetry.Config{
211-
ServiceName: v.GetString("telemetry.service-name"),
212-
Enabled: v.GetBool("telemetry.enabled"),
213-
EnableHostname: v.GetBool("telemetry.enable-hostname"),
214-
EnableHostnameLabel: v.GetBool("telemetry.enable-hostname-label"),
215-
EnableServiceLabel: v.GetBool("telemetry.enable-service-label"),
216-
PrometheusRetentionTime: v.GetInt64("telemetry.prometheus-retention-time"),
217-
GlobalLabels: globalLabels,
218-
},
219-
API: APIConfig{
220-
Enable: v.GetBool("api.enable"),
221-
Swagger: v.GetBool("api.swagger"),
222-
Address: v.GetString("api.address"),
223-
MaxOpenConnections: v.GetUint("api.max-open-connections"),
224-
RPCReadTimeout: v.GetUint("api.rpc-read-timeout"),
225-
RPCWriteTimeout: v.GetUint("api.rpc-write-timeout"),
226-
RPCMaxBodyBytes: v.GetUint("api.rpc-max-body-bytes"),
227-
EnableUnsafeCORS: v.GetBool("api.enabled-unsafe-cors"),
228-
},
229-
GRPC: GRPCConfig{
230-
Enable: v.GetBool("grpc.enable"),
231-
Address: v.GetString("grpc.address"),
232-
},
108+
BaseConfig: cfg.BaseConfig,
109+
Telemetry: cfg.Telemetry,
110+
API: cfg.API,
111+
GRPC: cfg.GRPC,
233112
EVMRPC: EVMRPCConfig{
234113
Enable: v.GetBool("evm-rpc.enable"),
235114
RPCAddress: v.GetString("evm-rpc.address"),
236115
WsAddress: v.GetString("evm-rpc.ws-address"),
237116
},
238-
StateSync: StateSyncConfig{
239-
SnapshotInterval: v.GetUint64("state-sync.snapshot-interval"),
240-
SnapshotKeepRecent: v.GetUint32("state-sync.snapshot-keep-recent"),
241-
},
117+
StateSync: cfg.StateSync,
242118
}
243119
}

cmd/ethermintd/start.go

Lines changed: 6 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
pvm "github.com/tendermint/tendermint/privval"
2525
"github.com/tendermint/tendermint/proxy"
2626
"github.com/tendermint/tendermint/rpc/client/local"
27-
rpcclient "github.com/tendermint/tendermint/rpc/jsonrpc/client"
2827
dbm "github.com/tendermint/tm-db"
2928

3029
"github.com/cosmos/cosmos-sdk/client"
@@ -42,6 +41,7 @@ import (
4241

4342
"github.com/tharsis/ethermint/cmd/ethermintd/config"
4443
"github.com/tharsis/ethermint/ethereum/rpc"
44+
ethsrv "github.com/tharsis/ethermint/server"
4545
)
4646

4747
// Tendermint full-node start flags
@@ -230,6 +230,7 @@ func startInProcess(ctx *server.Context, clientCtx client.Context, appCreator ty
230230
grpcSrv, err = servergrpc.StartGRPCServer(clientCtx, app, config.GRPC.Address)
231231
if err != nil {
232232
log.WithError(err).Errorln("failed to boot GRPC server")
233+
return err
233234
}
234235
}
235236

@@ -242,7 +243,7 @@ func startInProcess(ctx *server.Context, clientCtx client.Context, appCreator ty
242243
tmEndpoint := "/websocket"
243244
tmRPCAddr := cfg.RPC.ListenAddress
244245
log.Infoln("EVM RPC Connecting to Tendermint WebSocket at", tmRPCAddr+tmEndpoint)
245-
tmWsClient := connectTmWS(tmRPCAddr, tmEndpoint)
246+
tmWsClient := ethsrv.ConnectTmWS(tmRPCAddr, tmEndpoint)
246247

247248
rpcServer := ethrpc.NewServer()
248249
apis := rpc.GetRPCAPIs(clientCtx, tmWsClient)
@@ -253,14 +254,15 @@ func startInProcess(ctx *server.Context, clientCtx client.Context, appCreator ty
253254
"namespace": api.Namespace,
254255
"service": api.Service,
255256
}).WithError(err).Fatalln("failed to register service in EVM RPC namespace")
257+
return err
256258
}
257259
}
258260

259261
r := mux.NewRouter()
260262
r.HandleFunc("/", rpcServer.ServeHTTP).Methods("POST")
261263
if grpcSrv != nil {
262264
grpcWeb := grpcweb.WrapServer(grpcSrv)
263-
mountGrpcWebServices(r, grpcWeb, grpcweb.ListGRPCResources(grpcSrv))
265+
ethsrv.MountGRPCWebServices(r, grpcWeb, grpcweb.ListGRPCResources(grpcSrv))
264266
}
265267

266268
handlerWithCors := cors.New(cors.Options{
@@ -308,7 +310,7 @@ func startInProcess(ctx *server.Context, clientCtx client.Context, appCreator ty
308310
_, port, _ := net.SplitHostPort(config.EVMRPC.RPCAddress)
309311

310312
// allocate separate WS connection to Tendermint
311-
tmWsClient = connectTmWS(tmRPCAddr, tmEndpoint)
313+
tmWsClient = ethsrv.ConnectTmWS(tmRPCAddr, tmEndpoint)
312314
wsSrv = rpc.NewWebsocketsServer(tmWsClient, "localhost:"+port, config.EVMRPC.WsAddress)
313315
go wsSrv.Start()
314316
}
@@ -391,50 +393,6 @@ func startInProcess(ctx *server.Context, clientCtx client.Context, appCreator ty
391393
return nil
392394
}
393395

394-
func connectTmWS(tmRPCAddr, tmEndpoint string) *rpcclient.WSClient {
395-
tmWsClient, err := rpcclient.NewWS(tmRPCAddr, tmEndpoint,
396-
rpcclient.MaxReconnectAttempts(256),
397-
rpcclient.ReadWait(120*time.Second),
398-
rpcclient.WriteWait(120*time.Second),
399-
rpcclient.PingPeriod(50*time.Second),
400-
rpcclient.OnReconnect(func() {
401-
log.WithField("tendermint_rpc", tmRPCAddr+tmEndpoint).
402-
Debugln("EVM RPC reconnects to Tendermint WS")
403-
}),
404-
)
405-
406-
if err != nil {
407-
log.WithError(err).Fatalln("Tendermint WS client could not be created for ", tmRPCAddr+tmEndpoint)
408-
} else if err := tmWsClient.OnStart(); err != nil {
409-
log.WithError(err).Fatalln("Tendermint WS client could not start for ", tmRPCAddr+tmEndpoint)
410-
}
411-
412-
return tmWsClient
413-
}
414-
415-
func mountGrpcWebServices(
416-
router *mux.Router,
417-
grpcWeb *grpcweb.WrappedGrpcServer,
418-
grpcResources []string,
419-
) {
420-
for _, res := range grpcResources {
421-
log.Printf("[GRPC Web] HTTP POST mounted on %s", res)
422-
423-
s := router.Methods("POST").Subrouter()
424-
s.HandleFunc(res, func(resp http.ResponseWriter, req *http.Request) {
425-
if grpcWeb.IsGrpcWebSocketRequest(req) {
426-
grpcWeb.HandleGrpcWebsocketRequest(resp, req)
427-
return
428-
}
429-
430-
if grpcWeb.IsGrpcWebRequest(req) {
431-
grpcWeb.HandleGrpcWebRequest(resp, req)
432-
return
433-
}
434-
})
435-
}
436-
}
437-
438396
func openDB(rootDir string) (dbm.DB, error) {
439397
dataDir := filepath.Join(rootDir, "data")
440398
return sdk.NewLevelDB("application", dataDir)

crypto/ethsecp256k1/keys.pb.go

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

encoding/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
evmtypes "github.com/tharsis/ethermint/x/evm/types"
1616
)
1717

18-
// MakeEncodingConfig creates an EncodingConfig for testing
18+
// MakeConfig creates an EncodingConfig for testing
1919
func MakeConfig(mb module.BasicManager) params.EncodingConfig {
2020
cdc := amino.NewLegacyAmino()
2121
interfaceRegistry := types.NewInterfaceRegistry()

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ require (
4545
github.com/tyler-smith/go-bip39 v1.1.0
4646
github.com/xlab/closer v0.0.0-20190328110542-03326addb7c2
4747
github.com/xlab/suplog v1.3.0
48-
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a // indirect
49-
google.golang.org/genproto v0.0.0-20210607140030-00d4fb20b1ae
48+
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e // indirect
49+
google.golang.org/genproto v0.0.0-20210624195500-8bfb893ecb84
5050
google.golang.org/grpc v1.38.0
5151
gopkg.in/yaml.v2 v2.4.0
5252
nhooyr.io/websocket v1.8.7 // indirect

0 commit comments

Comments
 (0)