Skip to content

Commit

Permalink
works
Browse files Browse the repository at this point in the history
  • Loading branch information
ninabarbakadze committed Apr 15, 2024
1 parent 2db9b0e commit 0b97216
Show file tree
Hide file tree
Showing 16 changed files with 1,051 additions and 151 deletions.
790 changes: 790 additions & 0 deletions go.work.sum

Large diffs are not rendered by default.

98 changes: 98 additions & 0 deletions test/e2e/benchmark/throughput.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package main

import (
"context"
"fmt"
"log"
"os"
"time"

"github.com/celestiaorg/celestia-app/v2/pkg/appconsts"
"github.com/celestiaorg/celestia-app/v2/test/e2e/testnets"
"github.com/celestiaorg/celestia-app/v2/test/util/testnode"
)

var latestVersion = "latest"

const seed = 42

func main() {
if err := E2EThroughput(); err != nil {
log.Fatalf("--- ERROR Throughput test: %v", err.Error())
}
}

func E2EThroughput() error {
log.SetFlags(0) // Disable additional information like the date or time
log.SetPrefix(" ")

if os.Getenv("E2E_LATEST_VERSION") != "" {
latestVersion = os.Getenv("E2E_LATEST_VERSION")
_, isSemVer := testnets.ParseVersion(latestVersion)
switch {
case isSemVer:
case latestVersion == "latest":
case len(latestVersion) == 7:
case len(latestVersion) >= 8:
// assume this is a git commit hash (we need to trim the last digit to match the docker image tag)
latestVersion = latestVersion[:7]
default:
return fmt.Errorf("unrecognised version %s", latestVersion)
}
}

log.Println("=== RUN E2EThroughput", "version:", latestVersion)

// create a new testnet
testnet, err := testnets.New("E2EThroughput", seed, testnets.GetGrafanaInfoFromEnvVar())
testnets.NoError("failed to create testnet", err)

log.Println("Cleaning up testnet")
defer testnet.Cleanup()

// add 2 validators
testnets.NoError("failed to create genesis nodes", testnet.CreateGenesisNodes(2, latestVersion, 10000000, 0, testnets.DefaultResources))

// obtain the GRPC endpoints of the validators
gRPCEndpoints, err := testnet.RemoteGRPCEndpoints()
testnets.NoError("failed to get validators GRPC endpoints", err)
log.Println("validators GRPC endpoints", gRPCEndpoints)

// create txsim nodes and point them to the validators
log.Println("Creating txsim nodes")
// version of the txsim docker image to be used
txsimVersion := "a92de72"

err = testnet.CreateTxClients(txsimVersion, 1, "10000-10000", testnets.DefaultResources, gRPCEndpoints)
testnets.NoError("failed to create tx clients", err)

// start the testnet
log.Println("Setting up testnet")
testnets.NoError("failed to setup testnet", testnet.Setup())
log.Println("Starting testnet")
testnets.NoError("failed to start testnet", testnet.Start())

// once the testnet is up, start the txsim
log.Println("Starting txsim nodes")
testnets.NoError("failed to start tx clients", testnet.StartTxClients())

// wait some time for the txsim to submit transactions
time.Sleep(1 * time.Minute)

log.Println("Reading blockchain")
blockchain, err := testnode.ReadBlockchain(context.Background(), testnet.Node(0).AddressRPC())
testnets.NoError("failed to read blockchain", err)

totalTxs := 0
for _, block := range blockchain {
if appconsts.LatestVersion != block.Version.App {
return fmt.Errorf("expected app version %d, got %d", appconsts.LatestVersion, block.Version.App)
}
totalTxs += len(block.Data.Txs)
}
if totalTxs < 10 {
return fmt.Errorf("expected at least 10 transactions, got %d", totalTxs)
}
log.Println("--- PASS ✅: E2EThroughput")
return nil
}
93 changes: 40 additions & 53 deletions test/e2e/check_upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,64 +14,62 @@ import (
"github.com/celestiaorg/celestia-app/v2/app/encoding"
v1 "github.com/celestiaorg/celestia-app/v2/pkg/appconsts/v1"
v2 "github.com/celestiaorg/celestia-app/v2/pkg/appconsts/v2"
"github.com/celestiaorg/celestia-app/v2/test/e2e/pkg"
"github.com/celestiaorg/celestia-app/v2/test/e2e/testnets"
"github.com/celestiaorg/celestia-app/v2/test/txsim"
"github.com/celestiaorg/knuu/pkg/knuu"
"github.com/tendermint/tendermint/rpc/client/http"
)

func MinorVersionCompatibility(logger *log.Logger) error {
if os.Getenv("KNUU_NAMESPACE") != "test" {
logger.Fatal("skipping e2e test")
return fmt.Errorf("skipping e2e throughput test")
}

if os.Getenv("E2E_VERSIONS") == "" {
logger.Fatal("skipping e2e test: E2E_VERSIONS not set")
}

versionStr := os.Getenv("E2E_VERSIONS")
versions := pkg.ParseVersions(versionStr).FilterMajor(MajorVersion).FilterOutReleaseCandidates()
fmt.Println("versions", len(versions))
versions := testnets.ParseVersions(versionStr).FilterMajor(MajorVersion).FilterOutReleaseCandidates()

if len(versions) == 0 {
logger.Fatal("skipping e2e test: no versions to test")
}
numNodes := 4
r := rand.New(rand.NewSource(seed))
logger.Println("Running minor version compatibility test", "versions", versions)

testnet, err := pkg.New("runMinorVersionCompatibility", seed, pkg.GetGrafanaInfoFromEnvVar())
if err != nil {
return err
}
testnet, err := testnets.New("runMinorVersionCompatibility", seed, testnets.GetGrafanaInfoFromEnvVar())
testnets.NoError("failed to create testnet", err)

defer testnet.Cleanup()

testnet.SetConsensusParams(app.DefaultInitialConsensusParams())

// preload all docker images
preloader, err := knuu.NewPreloader()
if err != nil {
return err
}
testnets.NoError("failed to create preloader", err)

defer func() { _ = preloader.EmptyImages() }()
for _, v := range versions {
err := preloader.AddImage(pkg.DockerImageName(v.String()))
NoError("failed to add image", err)
testnets.NoError("failed to add image", preloader.AddImage(testnets.DockerImageName(v.String())))
}

for i := 0; i < numNodes; i++ {
// each node begins with a random version within the same major version set
v := versions.Random(r).String()
fmt.Println("Starting node", "node", i, "version", v)
err := testnet.CreateGenesisNode(v, 10000000, 0, pkg.DefaultResources)
NoError("failed to create genesis node", err)
testnets.NoError("failed to create genesis node", testnet.CreateGenesisNode(v, 10000000, 0, testnets.DefaultResources))
}

kr, err := testnet.CreateAccount("alice", 1e12, "")
NoError("failed to create account", err)
testnets.NoError("failed to create account", err)

err = testnet.Start()
NoError("failed to start testnet", err)
err = testnet.Start()
NoError("failed to start testnet", err)
// start the testnet
fmt.Println("Setting up testnet")
testnets.NoError("Failed to setup testnet", testnet.Setup())
fmt.Println("Starting testnet")
testnets.NoError("Failed to start testnet", testnet.Start())

// TODO: with upgrade tests we should simulate a far broader range of transactions
sequences := txsim.NewBlobSequence(txsim.NewRange(200, 4000), txsim.NewRange(1, 3)).Clone(5)
Expand All @@ -93,31 +91,24 @@ func MinorVersionCompatibility(logger *log.Logger) error {
continue
}
client, err := testnet.Node(i % numNodes).Client()
if err != nil {
return err
}
testnets.NoError("failed to get client", err)

heightBefore, err := getHeight(ctx, client, time.Second)
NoError("failed to get height", err)
testnets.NoError("failed to get height", err)

newVersion := versions.Random(r).String()
logger.Println("Upgrading node", "node", i%numNodes, "version", newVersion)
err = testnet.Node(i % numNodes).Upgrade(newVersion)
NoError("failed to upgrade node", err)
testnets.NoError("failed to upgrade node", testnet.Node(i%numNodes).Upgrade(newVersion))
// wait for the node to reach two more heights
err = waitForHeight(ctx, client, heightBefore+2, 30*time.Second)
NoError("failed to wait for height", err)
testnets.NoError("failed to wait for height", waitForHeight(ctx, client, heightBefore+2, 30*time.Second))
}

heights := make([]int64, 4)
for i := 0; i < numNodes; i++ {
client, err := testnet.Node(i).Client()
if err != nil {
return err
}
testnets.NoError("failed to get client", err)
heights[i], err = getHeight(ctx, client, time.Second)
if err != nil {
return err
}
testnets.NoError("failed to get height", err)
}

logger.Println("checking that all nodes are at the same height")
Expand All @@ -126,7 +117,7 @@ func MinorVersionCompatibility(logger *log.Logger) error {
for j := i + 1; j < len(heights); j++ {
diff := heights[i] - heights[j]
if diff > maxPermissableDiff {
logger.Fatal("node %d is behind node %d by %d blocks", j, i, diff)
logger.Fatalf("node %d is behind node %d by %d blocks", j, i, diff)
}
}
}
Expand All @@ -149,7 +140,7 @@ func MajorUpgradeToV2(logger *log.Logger) error {

if os.Getenv("E2E_LATEST_VERSION") != "" {
latestVersion = os.Getenv("E2E_LATEST_VERSION")
_, isSemVer := pkg.ParseVersion(latestVersion)
_, isSemVer := testnets.ParseVersion(latestVersion)
switch {
case isSemVer:
case latestVersion == "latest":
Expand All @@ -167,31 +158,28 @@ func MajorUpgradeToV2(logger *log.Logger) error {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

testnet, err := pkg.New("runMajorUpgradeToV2", seed, pkg.GetGrafanaInfoFromEnvVar())
NoError("failed to create testnet", err)
testnet, err := testnets.New("runMajorUpgradeToV2", seed, testnets.GetGrafanaInfoFromEnvVar())
testnets.NoError("failed to create testnet", err)

defer testnet.Cleanup()

preloader, err := knuu.NewPreloader()
NoError("failed to create preloader", err)
testnets.NoError("failed to create preloader", err)

defer func() { _ = preloader.EmptyImages() }()
err = preloader.AddImage(pkg.DockerImageName(latestVersion))
NoError("failed to add image", err)
testnets.NoError("failed to add image", preloader.AddImage(testnets.DockerImageName(latestVersion)))

for i := 0; i < numNodes; i++ {
err := testnet.CreateGenesisNode(latestVersion, 10000000, upgradeHeight, pkg.DefaultResources)
NoError("failed to create genesis node", err)
err := testnet.CreateGenesisNode(latestVersion, 10000000, upgradeHeight, testnets.DefaultResources)
testnets.NoError("failed to create genesis node", err)
}

kr, err := testnet.CreateAccount("alice", 1e12, "")
NoError("failed to create account", err)
testnets.NoError("failed to create account", err)

err = testnet.Setup()
NoError("failed to setup testnet", err)
testnets.NoError("failed to setup testnet", testnet.Setup())

err = testnet.Start()
NoError("failed to start testnet", err)
testnets.NoError("failed to start testnet", testnet.Start())

errCh := make(chan error)
encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...)
Expand All @@ -206,19 +194,18 @@ func MajorUpgradeToV2(logger *log.Logger) error {
heightBefore := upgradeHeight - 1
for i := 0; i < numNodes; i++ {
client, err := testnet.Node(i).Client()
NoError("failed to get client", err)
testnets.NoError("failed to get client", err)

err = waitForHeight(ctx, client, upgradeHeight, time.Minute)
NoError("failed to wait for height", err)
testnets.NoError("failed to wait for height", waitForHeight(ctx, client, upgradeHeight, time.Minute))

resp, err := client.Header(ctx, &heightBefore)
NoError("failed to get header", err)
testnets.NoError("failed to get header", err)
if resp.Header.Version.App != v1.Version {
return fmt.Errorf("version mismatch before upgrade: expected %d, got %d", v1.Version, resp.Header.Version.App)
}

resp, err = client.Header(ctx, &upgradeHeight)
NoError("failed to get header", err)
testnets.NoError("failed to get header", err)
if resp.Header.Version.App != v2.Version {
return fmt.Errorf("version mismatch before upgrade: expected %d, got %d", v2.Version, resp.Header.Version.App)
}
Expand Down
58 changes: 36 additions & 22 deletions test/e2e/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,49 @@ const (

var latestVersion = "latest"

type TestFunc func(*log.Logger) error

type Test struct {
Name string
Func TestFunc
}

func main() {
logger := log.New(os.Stdout, "test", log.LstdFlags)
// FIXME: This test currently panics in InitGenesis
// it's currently not running
if os.Getenv("RUN_MINOR_VERSION_COMPATIBILITY") == "true" {
logger.Println("Running minor version compatibility test")
err := MinorVersionCompatibility(logger)
if err != nil {
logger.Fatalf("Error running minor version compatibility: %v", err)
}
log.SetFlags(0) // Disable additional information like the date or time
log.SetPrefix(" ")

logger := log.New(os.Stdout, "test-e2e", log.LstdFlags)

tests := []Test{
{"MinorVersionCompatibility", MinorVersionCompatibility},
{"MajorUpgradeToV2", MajorUpgradeToV2},
{"E2ESimple", E2ESimple},
}

logger.Println("====== Running major upgrade to v2 e2e test ======")
// err := MajorUpgradeToV2(logger)
// if err != nil {
// logger.Fatalf("Error running minor version compatibility: %v", err)
// }
testName := os.Getenv("TEST")

logger.Println("====== Running simple e2e test ======")
err := E2ESimple(logger)
if err != nil {
logger.Fatalf("Error running simple e2e test: %v", err)
if testName != "" {
for _, test := range tests {
fmt.Println(test.Name)
fmt.Println(testName)
if test.Name == testName {
runTest(logger, test)
return
}
}
logger.Fatalf("Unknown test: %s", testName)
} else {
for _, test := range tests {
runTest(logger, test)
}
}
}

// helper function to wrap errors
func NoError(message string, err error) error {
func runTest(logger *log.Logger, test Test) {
logger.Printf("=== RUN %s", test.Name)
err := test.Func(logger)
if err != nil {
return fmt.Errorf("%s: %w", message, err)
logger.Fatalf("--- ERROR %s: %v", test.Name, err)
}
return nil
logger.Printf("--- ✅ PASS: %s", test.Name)
}
Loading

0 comments on commit 0b97216

Please sign in to comment.