diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index db0a241..3a287a4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,7 @@ jobs: go-version: '1.23' go-lint-version: 'v1.60.2' run-unit-tests: false - run-integration-tests: false + run-integration-tests: true run-lint: true install-dependencies-command: | sudo apt-get update diff --git a/Makefile b/Makefile index 86dc7a8..03f3856 100644 --- a/Makefile +++ b/Makefile @@ -34,6 +34,8 @@ ldflags := $(LDFLAGS) -X github.com/babylonlabs-io/babylon-benchmark/lib/version BUILD_TARGETS := build install BUILD_FLAGS := --tags "$(build_tags)" --ldflags '$(ldflags)' +PACKAGES_E2E=$(shell go list ./... | grep '/e2e') + build-babylond: $(MAKE) -C $(GIT_TOPLEVEL)/submodules/babylon/contrib/images babylond @@ -60,4 +62,7 @@ $(BUILDDIR)/: run-dgd: build @./build/dgd generate --total-fps 5 --total-stakers 150 +test-e2e: + go test -mod=readonly -failfast -timeout=15m -v $(PACKAGES_E2E) -count=1 + .PHONY: build help diff --git a/e2e/e2e_test.go b/e2e/e2e_test.go new file mode 100644 index 0000000..02c0690 --- /dev/null +++ b/e2e/e2e_test.go @@ -0,0 +1,36 @@ +package e2e + +import ( + "context" + "github.com/babylonlabs-io/babylon-benchmark/config" + "github.com/babylonlabs-io/babylon-benchmark/harness" + "github.com/stretchr/testify/require" + "testing" + "time" +) + +func TestCreatesDelegations(t *testing.T) { + ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute) + defer cancel() + + cfg := config.Config{ + NumPubRand: 1000, + TotalStakers: 20, + TotalFinalityProviders: 3, + TotalDelegations: 50, + BabylonPath: "", + } + + done := make(chan error, 1) + go func() { + err := harness.Run(ctx, cfg) + done <- err + }() + + select { + case <-ctx.Done(): + t.Fatalf("Test failed due to timeout: %v", ctx.Err()) + case err := <-done: + require.NoError(t, err) + } +} diff --git a/harness/app.go b/harness/app.go index a69e893..866e493 100644 --- a/harness/app.go +++ b/harness/app.go @@ -18,7 +18,10 @@ func Run(ctx context.Context, cfg config.Config) error { return startHarness(ctx, cfg) } -func startHarness(ctx context.Context, cfg config.Config) error { +func startHarness(cmdCtx context.Context, cfg config.Config) error { + ctx, cancel := context.WithCancel(cmdCtx) + defer cancel() + numStakers := cfg.TotalStakers numFinalityProviders := cfg.TotalFinalityProviders const numMatureOutputs = uint32(500) @@ -122,6 +125,7 @@ func startHarness(ctx context.Context, cfg config.Config) error { select { case <-ctx.Done(): case <-stopChan: + cancel() return nil } diff --git a/lib/version.go b/lib/version.go index 8eacace..ddd1a7e 100644 --- a/lib/version.go +++ b/lib/version.go @@ -16,7 +16,7 @@ func GetBabylonVersion() (string, error) { } fmt.Println("Current working directory:", dir) - goModPath := filepath.Join("go.mod") + goModPath := filepath.Join("..", "go.mod") data, err := os.ReadFile(goModPath) if err != nil { return "", err