mirror of
https://github.com/tendermint/tendermint.git
synced 2026-08-22 07:06:14 +00:00
test: add end-to-end testing framework (#5435)
Partial fix for #5291. For details, see [README.md](https://github.com/tendermint/tendermint/blob/erik/e2e-tests/test/e2e/README.md) and [RFC-001](https://github.com/tendermint/tendermint/blob/master/docs/rfc/rfc-001-end-to-end-testing.md). This only includes a single test case under `test/e2e/tests/`, as a proof of concept - additional test cases will be submitted separately. A randomized testnet generator will also be submitted separately, there a currently just a handful of static testnets under `test/e2e/networks/`. This will eventually replace the current P2P tests and run in CI.
This commit is contained in:
committed by
Erik Grinaker
parent
1b733ea28d
commit
a58454e788
@@ -0,0 +1,30 @@
|
||||
package e2e_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
e2e "github.com/tendermint/tendermint/test/e2e/pkg"
|
||||
)
|
||||
|
||||
// Tests that any initial state given in genesis has made it into the app.
|
||||
func TestApp_InitialState(t *testing.T) {
|
||||
testNode(t, func(t *testing.T, node e2e.Node) {
|
||||
switch {
|
||||
case node.Mode == e2e.ModeSeed:
|
||||
return
|
||||
case len(node.Testnet.InitialState) == 0:
|
||||
return
|
||||
}
|
||||
|
||||
client, err := node.Client()
|
||||
require.NoError(t, err)
|
||||
for k, v := range node.Testnet.InitialState {
|
||||
resp, err := client.ABCIQuery(ctx, "", []byte(k))
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, k, string(resp.Response.Key))
|
||||
assert.Equal(t, v, string(resp.Response.Value))
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package e2e_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
e2e "github.com/tendermint/tendermint/test/e2e/pkg"
|
||||
)
|
||||
|
||||
func init() {
|
||||
// This can be used to manually specify a testnet manifest and/or node to
|
||||
// run tests against. The testnet must have been started by the runner first.
|
||||
//os.Setenv("E2E_MANIFEST", "networks/simple.toml")
|
||||
//os.Setenv("E2E_NODE", "validator01")
|
||||
}
|
||||
|
||||
var (
|
||||
ctx = context.Background()
|
||||
)
|
||||
|
||||
// testNode runs tests for testnet nodes. The callback function is given a
|
||||
// single node to test, running as a subtest in parallel with other subtests.
|
||||
//
|
||||
// The testnet manifest must be given as the envvar E2E_MANIFEST. If not set,
|
||||
// these tests are skipped so that they're not picked up during normal unit
|
||||
// test runs. If E2E_NODE is also set, only the specified node is tested,
|
||||
// otherwise all nodes are tested.
|
||||
func testNode(t *testing.T, testFunc func(*testing.T, e2e.Node)) {
|
||||
manifest := os.Getenv("E2E_MANIFEST")
|
||||
if manifest == "" {
|
||||
t.Skip("E2E_MANIFEST not set, not an end-to-end test run")
|
||||
}
|
||||
if !filepath.IsAbs(manifest) {
|
||||
manifest = filepath.Join("..", manifest)
|
||||
}
|
||||
|
||||
testnet, err := e2e.LoadTestnet(manifest)
|
||||
require.NoError(t, err)
|
||||
nodes := testnet.Nodes
|
||||
|
||||
if name := os.Getenv("E2E_NODE"); name != "" {
|
||||
node := testnet.LookupNode(name)
|
||||
require.NotNil(t, node, "node %q not found in testnet %q", name, testnet.Name)
|
||||
nodes = []*e2e.Node{node}
|
||||
}
|
||||
|
||||
for _, node := range nodes {
|
||||
node := *node
|
||||
t.Run(node.Name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
testFunc(t, node)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user