MCPcopy Create free account
hub / github.com/akash-network/node / New

Function New

testutil/network/network.go:233–455  ·  view source on GitHub ↗

New creates a new Network for integration tests.

(t *testing.T, cfg Config)

Source from the content-addressed store, hash-verified

231
232// New creates a new Network for integration tests.
233func 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 = ""

Callers 1

SetupSuiteMethod · 0.92

Calls 9

GetFreePortsFunction · 0.85
newFreePortsFunction · 0.85
startInProcessFunction · 0.85
trapSignalFunction · 0.85
mustGetPortMethod · 0.80
writeFileFunction · 0.70
initGenFilesFunction · 0.70
collectGenFilesFunction · 0.70
StringMethod · 0.45

Tested by

no test coverage detected