From b1dfbb8bc37e1a90551560e8b09078b49ef133c1 Mon Sep 17 00:00:00 2001 From: Sam Kleinman Date: Tue, 28 Sep 2021 17:04:37 -0400 Subject: [PATCH] e2e: generator ensure p2p modes (#7021) --- test/e2e/generator/generate.go | 16 ++++++++--- test/e2e/generator/generate_test.go | 41 +++++++++++++++++++++++++++++ test/e2e/generator/main.go | 3 +-- test/e2e/tests/app_test.go | 12 ++++++--- 4 files changed, 63 insertions(+), 9 deletions(-) diff --git a/test/e2e/generator/generate.go b/test/e2e/generator/generate.go index 81c1be7ef..deffb533a 100644 --- a/test/e2e/generator/generate.go +++ b/test/e2e/generator/generate.go @@ -81,8 +81,7 @@ func Generate(r *rand.Rand, opts Options) ([]e2e.Manifest, error) { }() testnetCombinations["p2p"] = []interface{}{opts.P2P} - - default: + case MixedP2PMode: testnetCombinations["p2p"] = []interface{}{NewP2PMode, LegacyP2PMode, HybridP2PMode} } @@ -332,9 +331,20 @@ func generateTestnet(r *rand.Rand, opt map[string]interface{}) (e2e.Manifest, er // lastly, set up the light clients for i := 1; i <= numLightClients; i++ { startAt := manifest.InitialHeight + 5 - manifest.Nodes[fmt.Sprintf("light%02d", i)] = generateLightNode( + + node := generateLightNode( r, startAt+(5*int64(i)), lightProviders, ) + + switch p2pMode { + case LegacyP2PMode: + node.UseLegacyP2P = true + case HybridP2PMode: + node.UseLegacyP2P = r.Float64() < legacyP2PFactor + } + + manifest.Nodes[fmt.Sprintf("light%02d", i)] = node + } return manifest, nil diff --git a/test/e2e/generator/generate_test.go b/test/e2e/generator/generate_test.go index b816ba577..c38b6b20b 100644 --- a/test/e2e/generator/generate_test.go +++ b/test/e2e/generator/generate_test.go @@ -47,6 +47,9 @@ func TestGenerator(t *testing.T) { require.NoError(t, err) require.True(t, len(manifests) >= 16, "insufficient combinations: %d", len(manifests)) + // failures map to the test cases that you'd see locally. + e2e.SortManifests(manifests, false /* ascending */) + for idx, m := range manifests { t.Run(fmt.Sprintf("Case%04d", idx), func(t *testing.T) { require.True(t, len(m.Nodes) > 1) @@ -67,4 +70,42 @@ func TestGenerator(t *testing.T) { }) } }) + t.Run("UnmixedP2P", func(t *testing.T) { + t.Run("New", func(t *testing.T) { + manifests, err := Generate(rand.New(rand.NewSource(randomSeed)), Options{P2P: NewP2PMode}) + require.NoError(t, err) + require.True(t, len(manifests) >= 16, "insufficient combinations: %d", len(manifests)) + + // failures map to the test cases that you'd see locally. + e2e.SortManifests(manifests, false /* ascending */) + + for idx, m := range manifests { + t.Run(fmt.Sprintf("Case%04d", idx), func(t *testing.T) { + for name, node := range m.Nodes { + t.Run(name, func(t *testing.T) { + require.False(t, node.UseLegacyP2P) + }) + } + }) + } + }) + t.Run("Legacy", func(t *testing.T) { + manifests, err := Generate(rand.New(rand.NewSource(randomSeed)), Options{P2P: LegacyP2PMode}) + require.NoError(t, err) + require.True(t, len(manifests) >= 16, "insufficient combinations: %d", len(manifests)) + + // failures map to the test cases that you'd see locally. + e2e.SortManifests(manifests, false /* ascending */) + + for idx, m := range manifests { + t.Run(fmt.Sprintf("Case%04d", idx), func(t *testing.T) { + for name, node := range m.Nodes { + t.Run(name, func(t *testing.T) { + require.True(t, node.UseLegacyP2P) + }) + } + }) + } + }) + }) } diff --git a/test/e2e/generator/main.go b/test/e2e/generator/main.go index 6e39be820..4668f6a8f 100644 --- a/test/e2e/generator/main.go +++ b/test/e2e/generator/main.go @@ -38,7 +38,6 @@ func NewCLI() *CLI { SilenceUsage: true, SilenceErrors: true, // we'll output them ourselves in Run() RunE: func(cmd *cobra.Command, args []string) error { - var opts Options var err error p2pMode, err := cmd.Flags().GetString("p2p") @@ -48,7 +47,7 @@ func NewCLI() *CLI { switch mode := P2PMode(p2pMode); mode { case NewP2PMode, LegacyP2PMode, HybridP2PMode, MixedP2PMode: - opts.P2P = mode + cli.opts.P2P = mode default: return fmt.Errorf("p2p mode must be either new, legacy, hybrid or mixed got %s", p2pMode) } diff --git a/test/e2e/tests/app_test.go b/test/e2e/tests/app_test.go index afd4d2d52..ab6f9739e 100644 --- a/test/e2e/tests/app_test.go +++ b/test/e2e/tests/app_test.go @@ -44,13 +44,17 @@ func TestApp_Hash(t *testing.T) { require.NoError(t, err) require.NotEmpty(t, info.Response.LastBlockAppHash, "expected app to return app hash") - block, err := client.Block(ctx, &info.Response.LastBlockHeight) + status, err := client.Status(ctx) require.NoError(t, err) - require.EqualValues(t, info.Response.LastBlockAppHash, block.Block.AppHash.Bytes(), - "app hash does not match last block's app hash") - status, err := client.Status(ctx) + block, err := client.Block(ctx, &info.Response.LastBlockHeight) require.NoError(t, err) + + if info.Response.LastBlockHeight == block.Block.Height { + require.EqualValues(t, info.Response.LastBlockAppHash, block.Block.AppHash.Bytes(), + "app hash does not match last block's app hash") + } + require.True(t, status.SyncInfo.LatestBlockHeight >= info.Response.LastBlockHeight, "status out of sync with application") })