MCPcopy Create free account
hub / github.com/DeAI-Artist/Linkis / TestNodeNewNodeCustomReactors

Function TestNodeNewNodeCustomReactors

node/node_test.go:405–448  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

403}
404
405func TestNodeNewNodeCustomReactors(t *testing.T) {
406 config := cfg.ResetTestRoot("node_new_node_custom_reactors_test")
407 defer os.RemoveAll(config.RootDir)
408
409 cr := p2pmock.NewReactor()
410 cr.Channels = []*conn.ChannelDescriptor{
411 {
412 ID: byte(0x31),
413 Priority: 5,
414 SendQueueCapacity: 100,
415 RecvMessageCapacity: 100,
416 },
417 }
418 customBlockchainReactor := p2pmock.NewReactor()
419
420 nodeKey, err := p2p.LoadOrGenNodeKey(config.NodeKeyFile())
421 require.NoError(t, err)
422
423 n, err := NewNode(config,
424 privval.LoadOrGenFilePV(config.PrivValidatorKeyFile(), config.PrivValidatorStateFile()),
425 nodeKey,
426 proxy.DefaultClientCreator(config.ProxyApp, config.ABCI, config.DBDir()),
427 DefaultGenesisDocProviderFunc(config),
428 DefaultDBProvider,
429 DefaultMetricsProvider(config.Instrumentation),
430 log.TestingLogger(),
431 CustomReactors(map[string]p2p.Reactor{"FOO": cr, "BLOCKCHAIN": customBlockchainReactor}),
432 )
433 require.NoError(t, err)
434
435 err = n.Start()
436 require.NoError(t, err)
437 defer n.Stop() //nolint:errcheck // ignore for tests
438
439 assert.True(t, cr.IsRunning())
440 assert.Equal(t, cr, n.Switch().Reactor("FOO"))
441
442 assert.True(t, customBlockchainReactor.IsRunning())
443 assert.Equal(t, customBlockchainReactor, n.Switch().Reactor("BLOCKCHAIN"))
444
445 channels := n.NodeInfo().(p2p.DefaultNodeInfo).Channels
446 assert.Contains(t, channels, mempl.MempoolChannel)
447 assert.Contains(t, channels, cr.Channels[0].ID)
448}
449
450func state(nVals int, height int64) (sm.State, dbm.DB, []types.PrivValidator) {
451 privVals := make([]types.PrivValidator, nVals)

Callers

nothing calls this directly

Calls 15

SwitchMethod · 0.95
NodeInfoMethod · 0.95
LoadOrGenNodeKeyFunction · 0.92
LoadOrGenFilePVFunction · 0.92
DefaultClientCreatorFunction · 0.92
TestingLoggerFunction · 0.92
NodeKeyFileMethod · 0.80
PrivValidatorKeyFileMethod · 0.80
DBDirMethod · 0.80
ReactorMethod · 0.80
NewNodeFunction · 0.70

Tested by

no test coverage detected