Skip to content

Commit

Permalink
Test NetworkManager NonValidator Connector Inbound
Browse files Browse the repository at this point in the history
  • Loading branch information
AeonSw4n committed Jan 25, 2024
1 parent 822f4c7 commit 9f306c8
Showing 1 changed file with 80 additions and 1 deletion.
81 changes: 80 additions & 1 deletion integration_testing/connection_controller_routines_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ func TestConnectionControllerValidatorInboundDeduplication(t *testing.T) {
t.Logf("Test #1 passed | Successfully run non-validator node1; validators node2, node3 with duplicate public key")
}

func TestConnectionControllerNonValidatorConnector(t *testing.T) {
func TestConnectionControllerNonValidatorConnectorOutbound(t *testing.T) {
require := require.New(t)

// Spawn 6 non-validators node1, node2, node3, node4, node5, node6. Set node1's targetOutboundPeers to 3. Then make
Expand Down Expand Up @@ -419,6 +419,85 @@ func TestConnectionControllerNonValidatorConnector(t *testing.T) {
waitForNonValidatorOutboundConnection(t, node1, node4)
}

func TestConnectionControllerNonValidatorConnectorInbound(t *testing.T) {
require := require.New(t)

// Spawn validators node1, node2, node3, node4, node5, node6. Also spawn non-validators node7, node8, node9, node10.
// Set node1's targetOutboundPeers to 0 and targetInboundPeers to 1. Then make node1 create outbound connections to
// node2, node3, and make node4, node5, node6 create inbound connections to node1. Then make node1 create outbound
// connections to node7, node8, and make node9, node10 create inbound connections to node1.
blsPriv1, err := bls.NewPrivateKey()
require.NoError(err)
node1 := spawnValidatorNodeProtocol2(t, 18000, "node1", blsPriv1)
node1.Config.TargetOutboundPeers = 0
node1.Config.MaxInboundPeers = 1

blsPriv2, err := bls.NewPrivateKey()
require.NoError(err)
node2 := spawnValidatorNodeProtocol2(t, 18001, "node2", blsPriv2)
blsPriv3, err := bls.NewPrivateKey()
require.NoError(err)
node3 := spawnValidatorNodeProtocol2(t, 18002, "node3", blsPriv3)
blsPriv4, err := bls.NewPrivateKey()
require.NoError(err)
node4 := spawnValidatorNodeProtocol2(t, 18003, "node4", blsPriv4)
blsPriv5, err := bls.NewPrivateKey()
require.NoError(err)
node5 := spawnValidatorNodeProtocol2(t, 18004, "node5", blsPriv5)
blsPriv6, err := bls.NewPrivateKey()
require.NoError(err)
node6 := spawnValidatorNodeProtocol2(t, 18005, "node6", blsPriv6)

node7 := spawnNonValidatorNodeProtocol2(t, 18006, "node7")
node8 := spawnNonValidatorNodeProtocol2(t, 18007, "node8")
node9 := spawnNonValidatorNodeProtocol2(t, 18008, "node9")
node10 := spawnNonValidatorNodeProtocol2(t, 18009, "node10")

node1 = startNode(t, node1)
defer node1.Stop()
node2 = startNode(t, node2)
defer node2.Stop()
node3 = startNode(t, node3)
defer node3.Stop()
node4 = startNode(t, node4)
defer node4.Stop()
node5 = startNode(t, node5)
defer node5.Stop()
node6 = startNode(t, node6)
defer node6.Stop()
node7 = startNode(t, node7)
defer node7.Stop()
node8 = startNode(t, node8)
defer node8.Stop()
node9 = startNode(t, node9)
defer node9.Stop()
node10 = startNode(t, node10)
defer node10.Stop()

// Connect node1 to node2, node3, node7, and node8.
cc1 := node1.Server.GetConnectionController()
require.NoError(cc1.CreateNonValidatorOutboundConnection(node2.Listeners[0].Addr().String()))
require.NoError(cc1.CreateNonValidatorOutboundConnection(node3.Listeners[0].Addr().String()))
require.NoError(cc1.CreateNonValidatorOutboundConnection(node7.Listeners[0].Addr().String()))
require.NoError(cc1.CreateNonValidatorOutboundConnection(node8.Listeners[0].Addr().String()))
// Connect node4, node5, node6 to node1.
cc4 := node4.Server.GetConnectionController()
require.NoError(cc4.CreateNonValidatorOutboundConnection(node1.Listeners[0].Addr().String()))
cc5 := node5.Server.GetConnectionController()
require.NoError(cc5.CreateNonValidatorOutboundConnection(node1.Listeners[0].Addr().String()))
cc6 := node6.Server.GetConnectionController()
require.NoError(cc6.CreateNonValidatorOutboundConnection(node1.Listeners[0].Addr().String()))

// Connect node9, node10 to node1.
cc9 := node9.Server.GetConnectionController()
require.NoError(cc9.CreateNonValidatorOutboundConnection(node1.Listeners[0].Addr().String()))
cc10 := node10.Server.GetConnectionController()
require.NoError(cc10.CreateNonValidatorOutboundConnection(node1.Listeners[0].Addr().String()))

setGetActiveValidatorImplWithValidatorNodes(t, node1, node2, node3, node4, node5, node6)
waitForCountRemoteNodeIndexer(t, node1, 6, 5, 0, 1)
}

func setGetActiveValidatorImplWithValidatorNodes(t *testing.T, validators ...*cmd.Node) {
require := require.New(t)

Expand Down

0 comments on commit 9f306c8

Please sign in to comment.