From c8a0cf93eb102f222de543567ecde9e6cf5beb7b Mon Sep 17 00:00:00 2001 From: Marko Jelaca Date: Thu, 5 Oct 2023 13:30:12 +0200 Subject: [PATCH 1/2] Relayer and isValidator are represented as enum flags --- e2e-polybft/e2e/consensus_test.go | 4 ++-- e2e-polybft/e2e/migration_test.go | 2 +- e2e-polybft/framework/test-cluster.go | 26 +++++++++++++++++++------- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/e2e-polybft/e2e/consensus_test.go b/e2e-polybft/e2e/consensus_test.go index 50516d9fee..b65d5d0928 100644 --- a/e2e-polybft/e2e/consensus_test.go +++ b/e2e-polybft/e2e/consensus_test.go @@ -233,10 +233,10 @@ func TestE2E_Consensus_RegisterValidator(t *testing.T) { // start the first and the second validator cluster.InitTestServer(t, cluster.Config.ValidatorPrefix+strconv.Itoa(validatorSetSize+1), - cluster.Bridge.JSONRPCAddr(), true, false) + cluster.Bridge.JSONRPCAddr(), framework.Validator) cluster.InitTestServer(t, cluster.Config.ValidatorPrefix+strconv.Itoa(validatorSetSize+2), - cluster.Bridge.JSONRPCAddr(), true, false) + cluster.Bridge.JSONRPCAddr(), framework.Validator) // collect the first and the second validator from the cluster firstValidator := cluster.Servers[validatorSetSize] diff --git a/e2e-polybft/e2e/migration_test.go b/e2e-polybft/e2e/migration_test.go index caccb2210f..73c3dcf4a5 100644 --- a/e2e-polybft/e2e/migration_test.go +++ b/e2e-polybft/e2e/migration_test.go @@ -204,6 +204,6 @@ func TestE2E_Migration(t *testing.T) { _, err = cluster.InitSecrets("test-chain-8", 1) require.NoError(t, err) - cluster.InitTestServer(t, "test-chain-8", cluster.Bridge.JSONRPCAddr(), false, false) + cluster.InitTestServer(t, "test-chain-8", cluster.Bridge.JSONRPCAddr(), 0 /* no flags */) require.NoError(t, cluster.WaitForBlock(33, time.Minute)) } diff --git a/e2e-polybft/framework/test-cluster.go b/e2e-polybft/framework/test-cluster.go index d34006bafe..6cf90b1fa4 100644 --- a/e2e-polybft/framework/test-cluster.go +++ b/e2e-polybft/framework/test-cluster.go @@ -51,6 +51,15 @@ const ( nonValidatorPrefix = "test-non-validator-" ) +const ( + Validator = 1 << iota + Relayer +) + +func HasFlag(flags int, flag int) bool { + return flags&flag == flag +} + var ( startTime int64 testRewardWalletAddr = types.StringToAddress("0xFFFFFFFF") @@ -639,22 +648,25 @@ func NewTestCluster(t *testing.T, validatorsCount int, opts ...ClusterOption) *T require.NoError(t, err) for i := 1; i <= int(cluster.Config.ValidatorSetSize); i++ { + flags := Validator + if i == 1 { + flags = flags | Relayer + } + dir := cluster.Config.ValidatorPrefix + strconv.Itoa(i) - cluster.InitTestServer(t, dir, cluster.Bridge.JSONRPCAddr(), - true, i == 1 /* relayer */) + cluster.InitTestServer(t, dir, cluster.Bridge.JSONRPCAddr(), flags) } for i := 1; i <= cluster.Config.NonValidatorCount; i++ { dir := nonValidatorPrefix + strconv.Itoa(i) - cluster.InitTestServer(t, dir, cluster.Bridge.JSONRPCAddr(), - false, false /* relayer */) + cluster.InitTestServer(t, dir, cluster.Bridge.JSONRPCAddr(), 0 /* no flags */) } return cluster } func (c *TestCluster) InitTestServer(t *testing.T, - dataDir string, bridgeJSONRPC string, isValidator bool, relayer bool) { + dataDir string, bridgeJSONRPC string, flags int) { t.Helper() logLevel := os.Getenv(envLogLevel) @@ -669,11 +681,11 @@ func (c *TestCluster) InitTestServer(t *testing.T, srv := NewTestServer(t, c.Config, bridgeJSONRPC, func(config *TestServerConfig) { config.DataDir = dataDir - config.Seal = isValidator + config.Seal = HasFlag(flags, Validator) config.Chain = c.Config.Dir("genesis.json") config.P2PPort = c.getOpenPort() config.LogLevel = logLevel - config.Relayer = relayer + config.Relayer = HasFlag(flags, Relayer) config.NumBlockConfirmations = c.Config.NumBlockConfirmations config.BridgeJSONRPC = bridgeJSONRPC config.RelayerTrackerPollInterval = c.Config.RelayerTrackerPollInterval From c92c5f80202ca888e5492865de529652b61ca1dd Mon Sep 17 00:00:00 2001 From: Marko Jelaca Date: Thu, 5 Oct 2023 14:57:00 +0200 Subject: [PATCH 2/2] CR fix --- e2e-polybft/e2e/migration_test.go | 2 +- e2e-polybft/framework/test-cluster.go | 29 +++++++++++++++++---------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/e2e-polybft/e2e/migration_test.go b/e2e-polybft/e2e/migration_test.go index 73c3dcf4a5..04eae9cb40 100644 --- a/e2e-polybft/e2e/migration_test.go +++ b/e2e-polybft/e2e/migration_test.go @@ -204,6 +204,6 @@ func TestE2E_Migration(t *testing.T) { _, err = cluster.InitSecrets("test-chain-8", 1) require.NoError(t, err) - cluster.InitTestServer(t, "test-chain-8", cluster.Bridge.JSONRPCAddr(), 0 /* no flags */) + cluster.InitTestServer(t, "test-chain-8", cluster.Bridge.JSONRPCAddr(), frameworkpolybft.None) require.NoError(t, cluster.WaitForBlock(33, time.Minute)) } diff --git a/e2e-polybft/framework/test-cluster.go b/e2e-polybft/framework/test-cluster.go index 6cf90b1fa4..04aae87b70 100644 --- a/e2e-polybft/framework/test-cluster.go +++ b/e2e-polybft/framework/test-cluster.go @@ -51,13 +51,20 @@ const ( nonValidatorPrefix = "test-non-validator-" ) +type NodeType int + const ( - Validator = 1 << iota - Relayer + None NodeType = 0 + Validator NodeType = 1 << iota + Relayer NodeType = 2 ) -func HasFlag(flags int, flag int) bool { - return flags&flag == flag +func (nt NodeType) IsSet(value NodeType) bool { + return nt&value == value +} + +func (nt *NodeType) Append(value NodeType) { + *nt |= value } var ( @@ -648,25 +655,25 @@ func NewTestCluster(t *testing.T, validatorsCount int, opts ...ClusterOption) *T require.NoError(t, err) for i := 1; i <= int(cluster.Config.ValidatorSetSize); i++ { - flags := Validator + nodeType := Validator if i == 1 { - flags = flags | Relayer + nodeType.Append(Relayer) } dir := cluster.Config.ValidatorPrefix + strconv.Itoa(i) - cluster.InitTestServer(t, dir, cluster.Bridge.JSONRPCAddr(), flags) + cluster.InitTestServer(t, dir, cluster.Bridge.JSONRPCAddr(), nodeType) } for i := 1; i <= cluster.Config.NonValidatorCount; i++ { dir := nonValidatorPrefix + strconv.Itoa(i) - cluster.InitTestServer(t, dir, cluster.Bridge.JSONRPCAddr(), 0 /* no flags */) + cluster.InitTestServer(t, dir, cluster.Bridge.JSONRPCAddr(), None) } return cluster } func (c *TestCluster) InitTestServer(t *testing.T, - dataDir string, bridgeJSONRPC string, flags int) { + dataDir string, bridgeJSONRPC string, nodeType NodeType) { t.Helper() logLevel := os.Getenv(envLogLevel) @@ -681,11 +688,11 @@ func (c *TestCluster) InitTestServer(t *testing.T, srv := NewTestServer(t, c.Config, bridgeJSONRPC, func(config *TestServerConfig) { config.DataDir = dataDir - config.Seal = HasFlag(flags, Validator) + config.Seal = nodeType.IsSet(Validator) config.Chain = c.Config.Dir("genesis.json") config.P2PPort = c.getOpenPort() config.LogLevel = logLevel - config.Relayer = HasFlag(flags, Relayer) + config.Relayer = nodeType.IsSet(Relayer) config.NumBlockConfirmations = c.Config.NumBlockConfirmations config.BridgeJSONRPC = bridgeJSONRPC config.RelayerTrackerPollInterval = c.Config.RelayerTrackerPollInterval