-
Notifications
You must be signed in to change notification settings - Fork 351
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ref: #1256 This commit puts together the base pieces for an e2e testing suite. It includes a CLI that can: - Setup the file directories for multiple nodes, including generating a genesis with several accounts - Start the testnet (with different versions and at different start heights) - Stop the network and cleanup the used resources.
- Loading branch information
Showing
13 changed files
with
1,231 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ coverage.txt | |
tools-stamp | ||
__debug_bin | ||
profile.out | ||
testing/e2e/networks/*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
all: cli docker | ||
|
||
cli: | ||
go build -o build/e2e ./cmd/e2e | ||
|
||
docker: | ||
docker build --tag ghcr.io/celestiaorg/celestia-app:current -f ../../Dockerfile ../.. | ||
|
||
PHONY: all cli docker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# E2E Framework | ||
|
||
## Purpose | ||
|
||
The e2e package provides a framework for integration testing of the Celestia consensus network. | ||
It consists of a simple CLI and a series of TOML testnet files which manage the running of | ||
several instances within the same network. The e2e test suite has the following purposes in mind: | ||
|
||
- **Compatibility testing**: Ensuring that multiple minor versions can operate successfully together within the same network. | ||
- **Upgrade testing**: Ensure upgrades, whether major or minor, can perform seamlessly. | ||
- **Sync testing**: Ensure that the latest version can sync data from the entire chain. | ||
- **Non determinism check**: Ensure that the state machine is free of non-determinism that could compromise replication. | ||
- **Invariant checking**: Ensure that system wide invariants hold. | ||
|
||
The e2e package is designed predominantly for correctness based testing of small clusters of node. | ||
It is designed to be relatively quick and can be used locally. It relies on docker and docker compose | ||
to orchestrate the nodes. | ||
|
||
## Usage | ||
|
||
To get started, run `make` within the e2e package directory. This builds the image referring to the current | ||
branch as well as the cli (To build just the cli run `make cli`). Then, to run the complete suite: | ||
|
||
```bash | ||
./build/e2e -f networks/simple.toml | ||
``` | ||
|
||
You should see something like | ||
|
||
```bash | ||
Setting up network simple-56602 | ||
Spinning up testnet | ||
Starting validator01 on <http://localhost:4202> | ||
Starting validator02 on <http://localhost:4203> | ||
Starting validator03 on <http://localhost:4204> | ||
Starting validator04 on <http://localhost:4205> | ||
Starting full01 on <http://localhost:4201> | ||
Waiting for the network to reach height 20 | ||
Stopping testnet | ||
Finished testnet successfully | ||
``` | ||
|
||
Alternatively you can use the commands: `setup`, `start`, `stop`, and `cleanup`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
|
||
e2e "github.com/celestiaorg/celestia-app/testing/e2e/pkg" | ||
"github.com/rs/zerolog/log" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func main() { | ||
NewCLI().Run() | ||
} | ||
|
||
type CLI struct { | ||
root *cobra.Command | ||
testnet *e2e.Testnet | ||
} | ||
|
||
func NewCLI() *CLI { | ||
cli := &CLI{} | ||
cli.root = &cobra.Command{ | ||
Use: "e2e", | ||
Short: "Command line runner for celestia app e2e framework", | ||
SilenceUsage: true, | ||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error { | ||
file, err := cmd.Flags().GetString("file") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
manifest, err := e2e.LoadManifest(file) | ||
if err != nil { | ||
return fmt.Errorf("loading manifest: %w", err) | ||
} | ||
|
||
testnet, err := e2e.LoadTestnet(manifest, file) | ||
if err != nil { | ||
return fmt.Errorf("building testnet: %w", err) | ||
} | ||
|
||
cli.testnet = testnet | ||
return nil | ||
}, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
ctx := cmd.Context() | ||
if err := e2e.Cleanup(ctx, cli.testnet); err != nil { | ||
return fmt.Errorf("preparing testnet: %w", err) | ||
} | ||
|
||
if err := e2e.Setup(ctx, cli.testnet); err != nil { | ||
return fmt.Errorf("setting up testnet: %w", err) | ||
} | ||
defer func() { _ = e2e.Cleanup(ctx, cli.testnet) }() | ||
|
||
if err := e2e.Start(ctx, cli.testnet); err != nil { | ||
return fmt.Errorf("starting network: %w", err) | ||
} | ||
|
||
if err := e2e.WaitForNBlocks(ctx, cli.testnet, 10); err != nil { | ||
return fmt.Errorf("waiting for the network to produce blocks: %w", err) | ||
} | ||
|
||
if err := e2e.Stop(ctx, cli.testnet); err != nil { | ||
return fmt.Errorf("stopping network: %w", err) | ||
} | ||
|
||
fmt.Println("Finished testnet successfully") | ||
return nil | ||
}, | ||
} | ||
cli.root.PersistentFlags().StringP("file", "f", "", "Testnet TOML manifest") | ||
_ = cli.root.MarkPersistentFlagRequired("file") | ||
|
||
cli.root.AddCommand(&cobra.Command{ | ||
Use: "setup", | ||
Short: "Setups a testnet", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return e2e.Setup(cmd.Context(), cli.testnet) | ||
}, | ||
}) | ||
|
||
cli.root.AddCommand(&cobra.Command{ | ||
Use: "start", | ||
Short: "Starts a testnet", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return e2e.Start(cmd.Context(), cli.testnet) | ||
}, | ||
}) | ||
|
||
cli.root.AddCommand(&cobra.Command{ | ||
Use: "stop", | ||
Short: "Stops a testnet", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return e2e.Stop(cmd.Context(), cli.testnet) | ||
}, | ||
}) | ||
|
||
cli.root.AddCommand(&cobra.Command{ | ||
Use: "cleanup", | ||
Short: "Tears down network and removes all resources", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return e2e.Cleanup(cmd.Context(), cli.testnet) | ||
}, | ||
}) | ||
|
||
return cli | ||
} | ||
|
||
func (cli *CLI) Run() { | ||
ctx, cancel := signal.NotifyContext(context.Background(), | ||
syscall.SIGINT, | ||
syscall.SIGTERM, | ||
) | ||
defer cancel() | ||
if err := cli.root.ExecuteContext(ctx); err != nil { | ||
log.Err(err) | ||
os.Exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[node.validator01] | ||
self_delegation = 1000000 | ||
[node.validator02] | ||
self_delegation = 1000000 | ||
[node.validator03] | ||
self_delegation = 1000000 | ||
[node.validator04] | ||
self_delegation = 1000000 | ||
[node.full01] | ||
start_height = 10 | ||
|
||
[account.user1] | ||
[account.user2] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package e2e | ||
|
||
import ( | ||
"fmt" | ||
osexec "os/exec" | ||
"path/filepath" | ||
) | ||
|
||
// execute executes a shell command. | ||
func exec(args ...string) error { | ||
cmd := osexec.Command(args[0], args[1:]...) | ||
out, err := cmd.CombinedOutput() | ||
switch err := err.(type) { | ||
case nil: | ||
return nil | ||
case *osexec.ExitError: | ||
return fmt.Errorf("failed to run %q:\n%v", args, string(out)) | ||
default: | ||
return err | ||
} | ||
} | ||
|
||
// execCompose runs a Docker Compose command for a testnet. | ||
func execCompose(dir string, args ...string) error { | ||
return exec(append( | ||
[]string{"docker compose", "-f", filepath.Join(dir, "docker-compose.yml")}, | ||
args...)...) | ||
} | ||
|
||
// execDocker runs a Docker command. | ||
func execDocker(args ...string) error { | ||
return exec(append([]string{"docker"}, args...)...) | ||
} |
Oops, something went wrong.