e2e: generator ensure p2p modes (#7021)

This commit is contained in:
Sam Kleinman
2021-09-28 17:04:37 -04:00
committed by GitHub
parent c18470a5f1
commit b1dfbb8bc3
4 changed files with 64 additions and 10 deletions

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

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

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

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)
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)
require.NoError(t, err)
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")
})