Browse Source

e2e: generator ensure p2p modes (#7021)

pull/7028/head
Sam Kleinman 3 years ago
committed by GitHub
parent
commit
b1dfbb8bc3
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 63 additions and 9 deletions
  1. +13
    -3
      test/e2e/generator/generate.go
  2. +41
    -0
      test/e2e/generator/generate_test.go
  3. +1
    -2
      test/e2e/generator/main.go
  4. +8
    -4
      test/e2e/tests/app_test.go

+ 13
- 3
test/e2e/generator/generate.go View File

@ -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


+ 41
- 0
test/e2e/generator/generate_test.go View File

@ -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)
})
}
})
}
})
})
}

+ 1
- 2
test/e2e/generator/main.go View File

@ -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)
}


+ 8
- 4
test/e2e/tests/app_test.go View File

@ -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")
})


Loading…
Cancel
Save