diff --git a/test/e2e/benchmark/benchmark.go b/test/e2e/benchmark/benchmark.go index 83843549ea..bc4503d61d 100644 --- a/test/e2e/benchmark/benchmark.go +++ b/test/e2e/benchmark/benchmark.go @@ -12,22 +12,41 @@ import ( "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" "github.com/celestiaorg/celestia-app/v3/test/e2e/testnet" "github.com/celestiaorg/celestia-app/v3/test/util/testnode" + "github.com/celestiaorg/knuu/pkg/knuu" ) +const timeFormat = "20060102_150405" + type BenchmarkTest struct { *testnet.Testnet manifest *Manifest } func NewBenchmarkTest(name string, manifest *Manifest) (*BenchmarkTest, error) { - // create a new testnet - testNet, err := testnet.New(context.Background(), name, seed, - testnet.GetGrafanaInfoFromEnvVar(), manifest.ChainID, - manifest.GetGenesisModifiers()...) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + scope := fmt.Sprintf("%s_%s", name, time.Now().Format(timeFormat)) + kn, err := knuu.New(ctx, knuu.Options{ + Scope: scope, + ProxyEnabled: true, + }) if err != nil { return nil, err } + // context.Background() is used to allow the stopSignal to be functional even after this function returns + kn.HandleStopSignal(context.Background()) + + log.Printf("Knuu initialized with scope %s", kn.Scope) + + testNet, err := testnet.New(kn, testnet.Options{ + Grafana: testnet.GetGrafanaInfoFromEnvVar(), + ChainID: manifest.ChainID, + GenesisModifiers: manifest.GetGenesisModifiers(), + }) + testnet.NoError("failed to create testnet", err) + testNet.SetConsensusParams(manifest.GetConsensusParams()) return &BenchmarkTest{Testnet: testNet, manifest: manifest}, nil } diff --git a/test/e2e/benchmark/throughput.go b/test/e2e/benchmark/throughput.go index 337d700525..75bf1bdf6c 100644 --- a/test/e2e/benchmark/throughput.go +++ b/test/e2e/benchmark/throughput.go @@ -10,10 +10,6 @@ import ( "k8s.io/apimachinery/pkg/api/resource" ) -const ( - seed = 42 -) - var bigBlockManifest = Manifest{ ChainID: "test", Validators: 2, diff --git a/test/e2e/main.go b/test/e2e/main.go index f58cd67526..768907e2cf 100644 --- a/test/e2e/main.go +++ b/test/e2e/main.go @@ -7,7 +7,7 @@ import ( ) const ( - seed = 42 + timeFormat = "20060102_150405" ) type TestFunc func(logger *log.Logger) error diff --git a/test/e2e/major_upgrade_v2.go b/test/e2e/major_upgrade_v2.go index de4fd79709..3e44eb0bc3 100644 --- a/test/e2e/major_upgrade_v2.go +++ b/test/e2e/major_upgrade_v2.go @@ -12,20 +12,30 @@ import ( v1 "github.com/celestiaorg/celestia-app/v3/pkg/appconsts/v1" v2 "github.com/celestiaorg/celestia-app/v3/pkg/appconsts/v2" "github.com/celestiaorg/celestia-app/v3/test/e2e/testnet" + "github.com/celestiaorg/knuu/pkg/knuu" "github.com/tendermint/tendermint/rpc/client/http" ) func MajorUpgradeToV2(logger *log.Logger) error { - var ( - numNodes = 4 - upgradeHeight = int64(10) - ) + testName := "MajorUpgradeToV2" + numNodes := 4 + upgradeHeight := int64(10) ctx, cancel := context.WithCancel(context.Background()) defer cancel() + scope := fmt.Sprintf("%s_%s", testName, time.Now().Format(timeFormat)) + kn, err := knuu.New(ctx, knuu.Options{ + Scope: scope, + ProxyEnabled: true, + }) + testnet.NoError("failed to initialize Knuu", err) + + kn.HandleStopSignal(ctx) + logger.Printf("Knuu initialized with scope %s", kn.Scope) + logger.Println("Creating testnet") - testNet, err := testnet.New(ctx, "MajorUpgradeToV2", seed, nil, "test") + testNet, err := testnet.New(kn, testnet.Options{}) testnet.NoError("failed to create testnet", err) defer testNet.Cleanup(ctx) @@ -33,7 +43,7 @@ func MajorUpgradeToV2(logger *log.Logger) error { latestVersion, err := testnet.GetLatestVersion() testnet.NoError("failed to get latest version", err) - logger.Println("Running major upgrade to v2 test", "version", latestVersion) + logger.Printf("Running %s test with version %s", testName, latestVersion) testNet.SetConsensusParams(app.DefaultInitialConsensusParams()) diff --git a/test/e2e/major_upgrade_v3.go b/test/e2e/major_upgrade_v3.go index 22723125f2..f82fae2804 100644 --- a/test/e2e/major_upgrade_v3.go +++ b/test/e2e/major_upgrade_v3.go @@ -10,16 +10,29 @@ import ( v2 "github.com/celestiaorg/celestia-app/v3/pkg/appconsts/v2" v3 "github.com/celestiaorg/celestia-app/v3/pkg/appconsts/v3" "github.com/celestiaorg/celestia-app/v3/test/e2e/testnet" + "github.com/celestiaorg/knuu/pkg/knuu" ) func MajorUpgradeToV3(logger *log.Logger) error { + testName := "MajorUpgradeToV3" numNodes := 4 - upgradeHeightV3 := int64(20) + upgradeHeightV3 := int64(10) + ctx, cancel := context.WithCancel(context.Background()) defer cancel() + scope := fmt.Sprintf("%s_%s", testName, time.Now().Format(timeFormat)) + kn, err := knuu.New(ctx, knuu.Options{ + Scope: scope, + ProxyEnabled: true, + }) + testnet.NoError("failed to initialize Knuu", err) + + kn.HandleStopSignal(ctx) + logger.Printf("Knuu initialized with scope %s", kn.Scope) + logger.Println("Creating testnet") - testNet, err := testnet.New(ctx, "MajorUpgradeToV3", seed, nil, "test") + testNet, err := testnet.New(kn, testnet.Options{}) testnet.NoError("failed to create testnet", err) defer testNet.Cleanup(ctx) diff --git a/test/e2e/minor_version_compatibility.go b/test/e2e/minor_version_compatibility.go index fbd7fb971f..bb81d5e021 100644 --- a/test/e2e/minor_version_compatibility.go +++ b/test/e2e/minor_version_compatibility.go @@ -15,10 +15,14 @@ import ( v1 "github.com/celestiaorg/celestia-app/v3/pkg/appconsts/v1" v2 "github.com/celestiaorg/celestia-app/v3/pkg/appconsts/v2" "github.com/celestiaorg/celestia-app/v3/test/e2e/testnet" + "github.com/celestiaorg/knuu/pkg/knuu" ) func MinorVersionCompatibility(logger *log.Logger) error { - const numNodes = 4 + const ( + testName = "MinorVersionCompatibility" + numNodes = 4 + ) versionStr, err := getAllVersions() testnet.NoError("failed to get versions", err) @@ -29,13 +33,24 @@ func MinorVersionCompatibility(logger *log.Logger) error { if len(versions) == 0 { logger.Fatal("no versions to test") } + seed := testnet.DefaultSeed r := rand.New(rand.NewSource(seed)) - logger.Println("Running minor version compatibility test", "versions", versions) + logger.Printf("Running %s test with versions %s", testName, versions) ctx, cancel := context.WithCancel(context.Background()) defer cancel() - testNet, err := testnet.New(ctx, "MinorVersionCompatibility", seed, nil, "test") + identifier := fmt.Sprintf("%s_%s", testName, time.Now().Format(timeFormat)) + kn, err := knuu.New(ctx, knuu.Options{ + Scope: identifier, + ProxyEnabled: true, + }) + testnet.NoError("failed to initialize Knuu", err) + + kn.HandleStopSignal(ctx) + logger.Printf("Knuu initialized with scope %s", kn.Scope) + + testNet, err := testnet.New(kn, testnet.Options{Seed: seed}) testnet.NoError("failed to create testnet", err) defer testNet.Cleanup(ctx) diff --git a/test/e2e/simple.go b/test/e2e/simple.go index 242c4ecde2..2a25c46e2b 100644 --- a/test/e2e/simple.go +++ b/test/e2e/simple.go @@ -9,24 +9,35 @@ import ( "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" "github.com/celestiaorg/celestia-app/v3/test/e2e/testnet" "github.com/celestiaorg/celestia-app/v3/test/util/testnode" + "github.com/celestiaorg/knuu/pkg/knuu" ) // This test runs a simple testnet with 4 validators. It submits both MsgPayForBlobs // and MsgSends over 30 seconds and then asserts that at least 10 transactions were // committed. func E2ESimple(logger *log.Logger) error { + const testName = "E2ESimple" + ctx, cancel := context.WithCancel(context.Background()) defer cancel() - testNet, err := testnet.New(ctx, "E2ESimple", seed, nil, "test") + identifier := fmt.Sprintf("%s_%s", testName, time.Now().Format(timeFormat)) + kn, err := knuu.New(ctx, knuu.Options{ + Scope: identifier, + ProxyEnabled: true, + }) + testnet.NoError("failed to initialize Knuu", err) + kn.HandleStopSignal(ctx) + logger.Printf("Knuu initialized with scope %s", kn.Scope) + + testNet, err := testnet.New(kn, testnet.Options{}) testnet.NoError("failed to create testnet", err) defer testNet.Cleanup(ctx) latestVersion, err := testnet.GetLatestVersion() testnet.NoError("failed to get latest version", err) - - logger.Println("Running E2ESimple test", "version", latestVersion) + logger.Printf("Running %s test with version %s", testName, latestVersion) logger.Println("Creating testnet validators") testnet.NoError("failed to create genesis nodes", diff --git a/test/e2e/testnet/testnet.go b/test/e2e/testnet/testnet.go index 159d59ab96..5b73daf596 100644 --- a/test/e2e/testnet/testnet.go +++ b/test/e2e/testnet/testnet.go @@ -20,6 +20,11 @@ import ( tmproto "github.com/tendermint/tendermint/proto/tendermint/types" ) +const ( + DefaultSeed int64 = 42 + DefaultChainID = "test-chain-id" +) + type Testnet struct { seed int64 nodes []*Node @@ -30,39 +35,25 @@ type Testnet struct { knuu *knuu.Knuu } -func New(ctx context.Context, name string, seed int64, grafana *GrafanaInfo, chainID string, genesisModifiers ...genesis.Modifier) (*Testnet, error) { - identifier := fmt.Sprintf("%s_%s", name, time.Now().Format("20060102_150405")) - kn, err := knuu.New(ctx, knuu.Options{ - Scope: identifier, - ProxyEnabled: true, - // if the tests timeout, pass the timeout option - // Timeout: 120 * time.Minute, - }) - if err != nil { - return nil, err - } - - log.Info(). - Str("scope", kn.Scope). - Str("TestName", name). - Msg("Knuu initialized") - - kn.HandleStopSignal(ctx) +type Options struct { + Seed int64 + Grafana *GrafanaInfo + ChainID string + GenesisModifiers []genesis.Modifier +} +func New(knuu *knuu.Knuu, opts Options) (*Testnet, error) { + opts.setDefaults() return &Testnet{ - seed: seed, + seed: opts.Seed, nodes: make([]*Node, 0), - genesis: genesis.NewDefaultGenesis().WithChainID(chainID).WithModifiers(genesisModifiers...), - keygen: newKeyGenerator(seed), - grafana: grafana, - knuu: kn, + genesis: genesis.NewDefaultGenesis().WithChainID(opts.ChainID).WithModifiers(opts.GenesisModifiers...), + keygen: newKeyGenerator(opts.Seed), + grafana: opts.Grafana, + knuu: knuu, }, nil } -func (t *Testnet) Knuu() *knuu.Knuu { - return t.knuu -} - func (t *Testnet) NewPreloader() (*preloader.Preloader, error) { if t.knuu == nil { return nil, errors.New("knuu is not initialized") @@ -479,3 +470,12 @@ func (t *Testnet) Nodes() []*Node { func (t *Testnet) Genesis() *genesis.Genesis { return t.genesis } + +func (o *Options) setDefaults() { + if o.ChainID == "" { + o.ChainID = DefaultChainID + } + if o.Seed == 0 { + o.Seed = DefaultSeed + } +}