New creates a new Network for integration tests.
(t *testing.T, cfg Config)
| 231 | |
| 232 | // New creates a new Network for integration tests. |
| 233 | func New(t *testing.T, cfg Config) *Network { |
| 234 | // only one caller/test can create and use a network at a time |
| 235 | t.Log("acquiring test network lock") |
| 236 | lock.Lock() |
| 237 | |
| 238 | baseDir, err := os.MkdirTemp(t.TempDir(), cfg.ChainID) |
| 239 | require.NoError(t, err) |
| 240 | t.Logf("created temporary directory: %s", baseDir) |
| 241 | |
| 242 | network := &Network{ |
| 243 | T: t, |
| 244 | BaseDir: baseDir, |
| 245 | Validators: make([]*Validator, cfg.NumValidators), |
| 246 | Config: cfg, |
| 247 | } |
| 248 | |
| 249 | t.Log("preparing test network...") |
| 250 | |
| 251 | monikers := make([]string, cfg.NumValidators) |
| 252 | nodeIDs := make([]string, cfg.NumValidators) |
| 253 | valPubKeys := make([]cryptotypes.PubKey, cfg.NumValidators) |
| 254 | |
| 255 | var genAccounts []authtypes.GenesisAccount |
| 256 | var genBalances []banktypes.Balance |
| 257 | var genFiles []string |
| 258 | |
| 259 | buf := bufio.NewReader(os.Stdin) |
| 260 | |
| 261 | allocPortsCount := (portsPerValidator * cfg.NumValidators) + 4 |
| 262 | |
| 263 | availablePorts, err := GetFreePorts(allocPortsCount) |
| 264 | require.NoError(t, err) |
| 265 | require.Equal(t, allocPortsCount, len(availablePorts)) |
| 266 | |
| 267 | ports := newFreePorts(availablePorts) |
| 268 | |
| 269 | // generate private keys, node IDs, and initial transactions |
| 270 | for i := 0; i < cfg.NumValidators; i++ { |
| 271 | appCfg := srvconfig.DefaultConfig() |
| 272 | appCfg.Pruning = cfg.PruningStrategy |
| 273 | appCfg.MinGasPrices = cfg.MinGasPrices |
| 274 | appCfg.API.Enable = true |
| 275 | appCfg.API.Swagger = false |
| 276 | appCfg.Telemetry.Enabled = false |
| 277 | appCfg.GRPC.Enable = false |
| 278 | appCfg.GRPCWeb.Enable = false |
| 279 | |
| 280 | ctx := server.NewDefaultContext() |
| 281 | ctx.Viper.Set(cflags.FlagChainID, cfg.ChainID) |
| 282 | |
| 283 | // Only allow the first validator to expose an RPC, API and gRPC |
| 284 | // server/client due to Tendermint in-process constraints. |
| 285 | apiAddr := "" |
| 286 | |
| 287 | tmCfg := ctx.Config |
| 288 | tmCfg.Consensus.TimeoutCommit = cfg.TimeoutCommit |
| 289 | |
| 290 | tmCfg.RPC.ListenAddress = "" |
no test coverage detected