Skip to content

Commit

Permalink
chore(itest): run babylond in e2e (#36)
Browse files Browse the repository at this point in the history
* adds babylond docker

* rm unused code

* lint

* cleanup

* chore(e2e): parallel e2e (#37)

* parallel go brrr

* cleanup

* pr comments
  • Loading branch information
Lazar955 authored Sep 27, 2024
1 parent cef0e86 commit a0a2db4
Show file tree
Hide file tree
Showing 14 changed files with 409 additions and 2,415 deletions.
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
DOCKER = $(shell which docker)
BUILDDIR ?= $(CURDIR)/build
TOOLS_DIR := tools

BABYLON_PKG := github.com/babylonlabs-io/babylon/cmd/babylond

Expand Down Expand Up @@ -51,8 +50,7 @@ test:
go test ./...

test-e2e:
cd $(TOOLS_DIR); go install -trimpath $(BABYLON_PKG);
go test -mod=readonly -timeout=25m -v $(PACKAGES_E2E) -count=1 --tags=e2e
go test -mod=readonly -timeout=25m -failfast -v $(PACKAGES_E2E) -count=1 --tags=e2e

proto-gen:
@$(call print, "Compiling protos.")
Expand Down
15 changes: 6 additions & 9 deletions cmd/stakerd/main.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
package main

import (
"context"
"fmt"
"net/http"
"os"
"os/signal"
"runtime/pprof"
"syscall"

"github.com/babylonlabs-io/btc-staker/metrics"
staker "github.com/babylonlabs-io/btc-staker/staker"
scfg "github.com/babylonlabs-io/btc-staker/stakercfg"
service "github.com/babylonlabs-io/btc-staker/stakerservice"

"github.com/jessevdk/go-flags"
"github.com/lightningnetwork/lnd/signal"
)

func main() {
// Hook interceptor for os signals.
shutdownInterceptor, err := signal.Intercept()
if err != nil {
_, _ = fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer cancel()

cfg, cfgLogger, zapLogger, err := scfg.LoadConfig()

Expand Down Expand Up @@ -89,15 +88,13 @@ func main() {
cfg,
staker,
cfgLogger,
shutdownInterceptor,
dbBackend,
)

addr := fmt.Sprintf("%s:%d", cfg.MetricsConfig.Host, cfg.MetricsConfig.ServerPort)
metrics.Start(cfgLogger, addr, stakerMetrics.Registry)

err = service.RunUntilShutdown()
if err != nil {
if err = service.RunUntilShutdown(ctx); err != nil {
_, _ = fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
Expand Down
276 changes: 0 additions & 276 deletions itest/babylon_node_handler.go

This file was deleted.

10 changes: 5 additions & 5 deletions itest/bitcoind_node_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package e2etest
import (
"encoding/json"
"fmt"
"github.com/ory/dockertest/v3"
"os"
"strconv"
"strings"
Expand Down Expand Up @@ -34,24 +35,22 @@ type BitcoindTestHandler struct {
m *containers.Manager
}

func NewBitcoindHandler(t *testing.T) *BitcoindTestHandler {
m, err := containers.NewManager()
require.NoError(t, err)
func NewBitcoindHandler(t *testing.T, m *containers.Manager) *BitcoindTestHandler {
return &BitcoindTestHandler{
t: t,
m: m,
}
}

func (h *BitcoindTestHandler) Start() {
func (h *BitcoindTestHandler) Start() *dockertest.Resource {
tempPath, err := os.MkdirTemp("", "bitcoind-staker-test-*")
require.NoError(h.t, err)

h.t.Cleanup(func() {
_ = os.RemoveAll(tempPath)
})

_, err = h.m.RunBitcoindResource(tempPath)
bitcoinResource, err := h.m.RunBitcoindResource(h.t, tempPath)
require.NoError(h.t, err)

h.t.Cleanup(func() {
Expand All @@ -64,6 +63,7 @@ func (h *BitcoindTestHandler) Start() {
return err == nil
}, startTimeout, 500*time.Millisecond, "bitcoind did not start")

return bitcoinResource
}

func (h *BitcoindTestHandler) GetBlockCount() (int, error) {
Expand Down
Loading

0 comments on commit a0a2db4

Please sign in to comment.