Skip to content

Commit

Permalink
adds simple e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
Lazar955 committed Nov 5, 2024
1 parent 756a000 commit 3d7c547
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
36 changes: 36 additions & 0 deletions e2e/e2e_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
6 changes: 5 additions & 1 deletion harness/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -122,6 +125,7 @@ func startHarness(ctx context.Context, cfg config.Config) error {
select {
case <-ctx.Done():
case <-stopChan:
cancel()
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion lib/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3d7c547

Please sign in to comment.