Skip to content

Commit

Permalink
Review
Browse files Browse the repository at this point in the history
  • Loading branch information
AeonSw4n committed Jan 28, 2024
1 parent f08bb3a commit c865fe2
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 121 deletions.
37 changes: 0 additions & 37 deletions integration_testing/connection_controller_routines_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,9 @@ func TestConnectionControllerInitiatePersistentConnections(t *testing.T) {
node5 := spawnValidatorNodeProtocol2(t, 18004, "node5", blsPriv5)

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()

node1.Config.ConnectIPs = []string{
node2.Listeners[0].Addr().String(),
Expand Down Expand Up @@ -69,7 +65,6 @@ func TestConnectionControllerInitiatePersistentConnections(t *testing.T) {
node5.Listeners[0].Addr().String(),
}
node6 = startNode(t, node6)
defer node6.Stop()
activeValidatorsMap = getActiveValidatorsMapWithValidatorNodes(t, node4, node5, node6)
setActiveValidators(activeValidatorsMap, node1, node2, node3, node4, node5, node6)
waitForNonValidatorOutboundConnection(t, node6, node2)
Expand All @@ -94,8 +89,6 @@ func TestConnectionControllerNonValidatorCircularConnectIps(t *testing.T) {

node1 = startNode(t, node1)
node2 = startNode(t, node2)
defer node1.Stop()
defer node2.Stop()

waitForCountRemoteNodeIndexerHandshakeCompleted(t, node1, 2, 0, 1, 1)
waitForCountRemoteNodeIndexerHandshakeCompleted(t, node2, 2, 0, 1, 1)
Expand Down Expand Up @@ -154,9 +147,6 @@ func TestNetworkManagerPersistentConnectorReconnect(t *testing.T) {
waitForValidatorConnection(t, node1, node3)
waitForCountRemoteNodeIndexer(t, node1, 3, 1, 2, 0)
t.Logf("Test #2 passed | Successfully run reconnect test with non-validator node1 with --connect-ips for node3")
node1.Stop()
node2.Stop()
node3.Stop()
}

func TestConnectionControllerValidatorConnector(t *testing.T) {
Expand Down Expand Up @@ -187,15 +177,10 @@ func TestConnectionControllerValidatorConnector(t *testing.T) {
node7 := spawnNonValidatorNodeProtocol2(t, 18006, "node7")

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.Config.ConnectIPs = []string{
node1.Listeners[0].Addr().String(),
Expand All @@ -206,9 +191,7 @@ func TestConnectionControllerValidatorConnector(t *testing.T) {
}
node7.Config.ConnectIPs = node6.Config.ConnectIPs
node6 = startNode(t, node6)
defer node6.Stop()
node7 = startNode(t, node7)
defer node7.Stop()
activeValidatorsMap := getActiveValidatorsMapWithValidatorNodes(t, node1, node2, node3, node4, node5)
setActiveValidators(activeValidatorsMap, node1, node2, node3, node4, node5, node6, node7)

Expand Down Expand Up @@ -344,11 +327,8 @@ func TestConnectionControllerValidatorInboundDeduplication(t *testing.T) {
node3 := spawnValidatorNodeProtocol2(t, 18002, "node3", blsPriv2)

node1 = startNode(t, node1)
defer node1.Stop()
node2 = startNode(t, node2)
defer node2.Stop()
node3 = startNode(t, node3)
defer node3.Stop()

cc2 := node2.Server.GetConnectionController()
require.NoError(cc2.CreateNonValidatorOutboundConnection(node1.Listeners[0].Addr().String()))
Expand Down Expand Up @@ -390,23 +370,17 @@ func TestConnectionControllerNonValidatorConnectorOutbound(t *testing.T) {
node6 := spawnNonValidatorNodeProtocol2(t, 18005, "node6")

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()

node1.Config.ConnectIPs = []string{
node2.Listeners[0].Addr().String(),
node3.Listeners[0].Addr().String(),
node4.Listeners[0].Addr().String(),
}
node1 = startNode(t, node1)
defer node1.Stop()

cc := node1.Server.GetConnectionController()
require.NoError(cc.CreateNonValidatorOutboundConnection(node5.Listeners[0].Addr().String()))
Expand Down Expand Up @@ -461,25 +435,15 @@ func TestConnectionControllerNonValidatorConnectorInbound(t *testing.T) {
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()
Expand Down Expand Up @@ -521,7 +485,6 @@ func TestConnectionControllerNonValidatorConnectorAddressMgr(t *testing.T) {
node1.Config.MaxInboundPeers = 0

node1 = startNode(t, node1)
defer node1.Stop()
cc := node1.Server.GetConnectionController()
na1, err := cc.ConvertIPStringToNetAddress("deso-seed-2.io:17000")
na2, err := cc.ConvertIPStringToNetAddress("deso-seed-3.io:17000")
Expand Down
45 changes: 7 additions & 38 deletions integration_testing/connection_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ import (
)

func TestConnectionControllerNonValidator(t *testing.T) {
t.Cleanup(ResetDisableNetworkManagerRoutines)
SetDisableNetworkManagerRoutines()
SetDisableNetworkManagerRoutines(t)
require := require.New(t)

node1 := spawnNonValidatorNodeProtocol2(t, 18000, "node1")
node1 = startNode(t, node1)
defer node1.Stop()

// Make sure NonValidator Node1 can create an outbound connection to NonValidator Node2
node2 := spawnNonValidatorNodeProtocol2(t, 18001, "node2")
Expand Down Expand Up @@ -49,7 +47,6 @@ func TestConnectionControllerNonValidator(t *testing.T) {
require.NoError(err)
node4 := spawnValidatorNodeProtocol2(t, 18003, "node4", blsPriv4)
node4 = startNode(t, node4)
defer node4.Stop()

cc = node1.Server.GetConnectionController()
require.NoError(cc.CreateNonValidatorOutboundConnection(node4.Listeners[0].Addr().String()))
Expand All @@ -59,15 +56,13 @@ func TestConnectionControllerNonValidator(t *testing.T) {
}

func TestConnectionControllerValidator(t *testing.T) {
t.Cleanup(ResetDisableNetworkManagerRoutines)
SetDisableNetworkManagerRoutines()
SetDisableNetworkManagerRoutines(t)
require := require.New(t)

blsPriv1, err := bls.NewPrivateKey()
require.NoError(err)
node1 := spawnValidatorNodeProtocol2(t, 18000, "node1", blsPriv1)
node1 = startNode(t, node1)
defer node1.Stop()

// Make sure Validator Node1 can create an outbound connection to Validator Node2
blsPriv2, err := bls.NewPrivateKey()
Expand Down Expand Up @@ -103,7 +98,6 @@ func TestConnectionControllerValidator(t *testing.T) {
require.NoError(err)
node4 := spawnValidatorNodeProtocol2(t, 18003, "node4", blsPriv4)
node4 = startNode(t, node4)
defer node4.Stop()

cc = node1.Server.GetConnectionController()
require.NoError(cc.CreateNonValidatorOutboundConnection(node4.Listeners[0].Addr().String()))
Expand All @@ -113,8 +107,7 @@ func TestConnectionControllerValidator(t *testing.T) {
}

func TestConnectionControllerHandshakeDataErrors(t *testing.T) {
t.Cleanup(ResetDisableNetworkManagerRoutines)
SetDisableNetworkManagerRoutines()
SetDisableNetworkManagerRoutines(t)
require := require.New(t)

blsPriv1, err := bls.NewPrivateKey()
Expand All @@ -129,8 +122,6 @@ func TestConnectionControllerHandshakeDataErrors(t *testing.T) {

node1 = startNode(t, node1)
node2 = startNode(t, node2)
defer node1.Stop()
defer node2.Stop()

cc := node2.Server.GetConnectionController()
require.NoError(cc.CreateNonValidatorOutboundConnection(node1.Listeners[0].Addr().String()))
Expand All @@ -144,7 +135,6 @@ func TestConnectionControllerHandshakeDataErrors(t *testing.T) {
node3 := spawnValidatorNodeProtocol2(t, 18002, "node3", blsPriv3)
node3.Params.ProtocolVersion = lib.ProtocolVersionType(3)
node3 = startNode(t, node3)
defer node3.Stop()

cc = node1.Server.GetConnectionController()
require.NoError(cc.CreateNonValidatorOutboundConnection(node3.Listeners[0].Addr().String()))
Expand All @@ -156,7 +146,6 @@ func TestConnectionControllerHandshakeDataErrors(t *testing.T) {
node4 := spawnNonValidatorNodeProtocol2(t, 18003, "node4")
node4.Params.ProtocolVersion = lib.ProtocolVersion0
node4 = startNode(t, node4)
defer node4.Stop()

cc = node1.Server.GetConnectionController()
require.NoError(cc.CreateNonValidatorOutboundConnection(node4.Listeners[0].Addr().String()))
Expand All @@ -171,7 +160,6 @@ func TestConnectionControllerHandshakeDataErrors(t *testing.T) {
require.NoError(err)
node5 := spawnValidatorNodeProtocol2(t, 18004, "node5", blsPriv5)
node5 = startNode(t, node5)
defer node5.Stop()

cc = node1.Server.GetConnectionController()
require.NoError(cc.CreateValidatorConnection(node5.Listeners[0].Addr().String(), blsPriv5Wrong.PublicKey()))
Expand All @@ -184,7 +172,6 @@ func TestConnectionControllerHandshakeDataErrors(t *testing.T) {
require.NoError(err)
node6 := spawnNonValidatorNodeProtocol2(t, 18005, "node6")
node6 = startNode(t, node6)
defer node6.Stop()

cc = node1.Server.GetConnectionController()
require.NoError(cc.CreateValidatorConnection(node6.Listeners[0].Addr().String(), blsPriv6.PublicKey()))
Expand All @@ -196,7 +183,6 @@ func TestConnectionControllerHandshakeDataErrors(t *testing.T) {
node7 := spawnNonValidatorNodeProtocol2(t, 18006, "node7")
node7.Params.ProtocolVersion = lib.ProtocolVersion1
node7 = startNode(t, node7)
defer node7.Stop()

cc = node1.Server.GetConnectionController()
require.NoError(cc.CreateNonValidatorOutboundConnection(node7.Listeners[0].Addr().String()))
Expand All @@ -206,19 +192,16 @@ func TestConnectionControllerHandshakeDataErrors(t *testing.T) {
}

func TestConnectionControllerHandshakeTimeouts(t *testing.T) {
t.Cleanup(ResetDisableNetworkManagerRoutines)
SetDisableNetworkManagerRoutines()
SetDisableNetworkManagerRoutines(t)
require := require.New(t)

// Set version negotiation timeout to 0 to make sure that the node will be disconnected
node1 := spawnNonValidatorNodeProtocol2(t, 18000, "node1")
node1.Params.VersionNegotiationTimeout = 0
node1 = startNode(t, node1)
defer node1.Stop()

node2 := spawnNonValidatorNodeProtocol2(t, 18001, "node2")
node2 = startNode(t, node2)
defer node2.Stop()

cc := node1.Server.GetConnectionController()
require.NoError(cc.CreateNonValidatorOutboundConnection(node2.Listeners[0].Addr().String()))
Expand All @@ -231,7 +214,6 @@ func TestConnectionControllerHandshakeTimeouts(t *testing.T) {
node3 := spawnNonValidatorNodeProtocol2(t, 18002, "node3")
node3.Params.VerackNegotiationTimeout = 0
node3 = startNode(t, node3)
defer node3.Stop()

cc = node3.Server.GetConnectionController()
require.NoError(cc.CreateNonValidatorOutboundConnection(node1.Listeners[0].Addr().String()))
Expand All @@ -245,13 +227,11 @@ func TestConnectionControllerHandshakeTimeouts(t *testing.T) {
node4 := spawnValidatorNodeProtocol2(t, 18003, "node4", blsPriv4)
node4.Params.HandshakeTimeoutMicroSeconds = 0
node4 = startNode(t, node4)
defer node4.Stop()

blsPriv5, err := bls.NewPrivateKey()
require.NoError(err)
node5 := spawnValidatorNodeProtocol2(t, 18004, "node5", blsPriv5)
node5 = startNode(t, node5)
defer node5.Stop()

cc = node4.Server.GetConnectionController()
require.NoError(cc.CreateValidatorConnection(node5.Listeners[0].Addr().String(), blsPriv5.PublicKey()))
Expand All @@ -261,13 +241,11 @@ func TestConnectionControllerHandshakeTimeouts(t *testing.T) {
}

func TestConnectionControllerValidatorDuplication(t *testing.T) {
t.Cleanup(ResetDisableNetworkManagerRoutines)
SetDisableNetworkManagerRoutines()
SetDisableNetworkManagerRoutines(t)
require := require.New(t)

node1 := spawnNonValidatorNodeProtocol2(t, 18000, "node1")
node1 = startNode(t, node1)
defer node1.Stop()

// Create a validator Node2
blsPriv2, err := bls.NewPrivateKey()
Expand Down Expand Up @@ -304,11 +282,9 @@ func TestConnectionControllerValidatorDuplication(t *testing.T) {
require.NoError(err)
node4 := spawnValidatorNodeProtocol2(t, 18003, "node4", blsPriv4)
node4 = startNode(t, node4)
defer node4.Stop()

node5 := spawnValidatorNodeProtocol2(t, 18004, "node5", blsPriv4)
node5 = startNode(t, node5)
defer node5.Stop()

// Create validator connections from Node4 to Node1 and from Node5 to Node1
cc4 := node4.Server.GetConnectionController()
Expand All @@ -323,15 +299,13 @@ func TestConnectionControllerValidatorDuplication(t *testing.T) {
}

func TestConnectionControllerProtocolDifference(t *testing.T) {
t.Cleanup(ResetDisableNetworkManagerRoutines)
SetDisableNetworkManagerRoutines()
SetDisableNetworkManagerRoutines(t)
require := require.New(t)

// Create a ProtocolVersion1 Node1
node1 := spawnNonValidatorNodeProtocol2(t, 18000, "node1")
node1.Params.ProtocolVersion = lib.ProtocolVersion1
node1 = startNode(t, node1)
defer node1.Stop()

// Create a ProtocolVersion2 NonValidator Node2
node2 := spawnNonValidatorNodeProtocol2(t, 18001, "node2")
Expand Down Expand Up @@ -365,7 +339,6 @@ func TestConnectionControllerProtocolDifference(t *testing.T) {
require.NoError(err)
node4 := spawnValidatorNodeProtocol2(t, 18003, "node4", blsPriv4)
node4 = startNode(t, node4)
defer node4.Stop()

// Attempt to create non-validator connection from Node4 to Node1
cc = node4.Server.GetConnectionController()
Expand All @@ -383,7 +356,6 @@ func TestConnectionControllerProtocolDifference(t *testing.T) {
// Create a ProtocolVersion2 non-validator Node5
node5 := spawnNonValidatorNodeProtocol2(t, 18004, "node5")
node5 = startNode(t, node5)
defer node5.Stop()

// Attempt to create non-validator connection from Node5 to Node1
cc = node5.Server.GetConnectionController()
Expand All @@ -394,8 +366,7 @@ func TestConnectionControllerProtocolDifference(t *testing.T) {
}

func TestConnectionControllerPersistentConnection(t *testing.T) {
t.Cleanup(ResetDisableNetworkManagerRoutines)
SetDisableNetworkManagerRoutines()
SetDisableNetworkManagerRoutines(t)
require := require.New(t)

// Create a NonValidator Node1
Expand Down Expand Up @@ -437,7 +408,6 @@ func TestConnectionControllerPersistentConnection(t *testing.T) {
require.NoError(err)
node4 := spawnValidatorNodeProtocol2(t, 18003, "node4", blsPriv4)
node4 = startNode(t, node4)
defer node4.Stop()

// Create a non-validator Node5
node5 := spawnNonValidatorNodeProtocol2(t, 18004, "node5")
Expand All @@ -458,7 +428,6 @@ func TestConnectionControllerPersistentConnection(t *testing.T) {
require.NoError(err)
node6 := spawnValidatorNodeProtocol2(t, 18005, "node6", blsPriv6)
node6 = startNode(t, node6)
defer node6.Stop()

// Create a persistent connection from Node4 to Node6
_, err = cc.CreateNonValidatorPersistentOutboundConnection(node6.Listeners[0].Addr().String())
Expand Down
Loading

0 comments on commit c865fe2

Please sign in to comment.