-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
151 additions
and
39 deletions.
There are no files selected for viewing
96 changes: 96 additions & 0 deletions
96
integration_testing/connection_controller_routines_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package integration_testing | ||
|
||
import ( | ||
"github.com/deso-protocol/core/bls" | ||
"github.com/deso-protocol/core/cmd" | ||
"github.com/deso-protocol/core/lib" | ||
"github.com/stretchr/testify/require" | ||
"os" | ||
"testing" | ||
) | ||
|
||
func TestConnectionControllerInitiatePersistentConnections(t *testing.T) { | ||
require := require.New(t) | ||
|
||
// NonValidator Node1 will set its --connect-ips to two non-validators node2 and node3, | ||
// and two validators node4 and node5. | ||
node1 := spawnNonValidatorNodeProtocol2(t, 18000, "node1") | ||
node2 := spawnNonValidatorNodeProtocol2(t, 18001, "node2") | ||
node3 := spawnNonValidatorNodeProtocol2(t, 18002, "node3") | ||
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) | ||
|
||
node2 = startNode(t, node2) | ||
node3 = startNode(t, node3) | ||
node4 = startNode(t, node4) | ||
node5 = startNode(t, node5) | ||
defer node2.Stop() | ||
defer node3.Stop() | ||
defer node4.Stop() | ||
defer node5.Stop() | ||
|
||
oldGetActiveValidatorImpl := lib.GetActiveValidatorImpl | ||
defer func() { | ||
setGetActiveValidatorImpl(oldGetActiveValidatorImpl) | ||
}() | ||
setGetActiveValidatorImpl(func() map[bls.SerializedPublicKey]*lib.ValidatorEntry { | ||
return map[bls.SerializedPublicKey]*lib.ValidatorEntry{ | ||
blsPriv4.PublicKey().Serialize(): createSimpleValidatorEntry(node4), | ||
blsPriv5.PublicKey().Serialize(): createSimpleValidatorEntry(node5), | ||
} | ||
}) | ||
|
||
node1.Config.ConnectIPs = []string{ | ||
node2.Listeners[0].Addr().String(), | ||
node3.Listeners[0].Addr().String(), | ||
node4.Listeners[0].Addr().String(), | ||
node5.Listeners[0].Addr().String(), | ||
} | ||
node1 = startNode(t, node1) | ||
defer node1.Stop() | ||
waitForNonValidatorOutboundConnection(t, node1, node2) | ||
waitForNonValidatorOutboundConnection(t, node1, node3) | ||
waitForValidatorConnection(t, node1, node4) | ||
waitForValidatorConnection(t, node1, node5) | ||
} | ||
|
||
func spawnNonValidatorNodeProtocol2(t *testing.T, port uint32, id string) *cmd.Node { | ||
dbDir := getDirectory(t) | ||
t.Cleanup(func() { | ||
os.RemoveAll(dbDir) | ||
}) | ||
config := generateConfig(t, port, dbDir, 10) | ||
config.SyncType = lib.NodeSyncTypeBlockSync | ||
node := cmd.NewNode(config) | ||
node.Params.UserAgent = id | ||
node.Params.ProtocolVersion = lib.ProtocolVersion2 | ||
return node | ||
} | ||
|
||
func spawnValidatorNodeProtocol2(t *testing.T, port uint32, id string, blsPriv *bls.PrivateKey) *cmd.Node { | ||
dbDir := getDirectory(t) | ||
t.Cleanup(func() { | ||
os.RemoveAll(dbDir) | ||
}) | ||
config := generateConfig(t, port, dbDir, 10) | ||
config.SyncType = lib.NodeSyncTypeBlockSync | ||
config.PosValidatorSeed = blsPriv.ToString() | ||
node := cmd.NewNode(config) | ||
node.Params.UserAgent = id | ||
node.Params.ProtocolVersion = lib.ProtocolVersion2 | ||
return node | ||
} | ||
|
||
func setGetActiveValidatorImpl(mapping func() map[bls.SerializedPublicKey]*lib.ValidatorEntry) { | ||
lib.GetActiveValidatorImpl = mapping | ||
} | ||
|
||
func createSimpleValidatorEntry(node *cmd.Node) *lib.ValidatorEntry { | ||
return &lib.ValidatorEntry{ | ||
Domains: [][]byte{[]byte(node.Listeners[0].Addr().String())}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters