Skip to content

Commit

Permalink
chore(e2e): run babylond in docker (#52)
Browse files Browse the repository at this point in the history
Instead of managing babylond as a process, we run it in a Docker
container.
This will make e2e tests more consistent as bitcoind is also running in
Docker and will enable us to run tests in parallel with `t.Parallel`
(next PR).

[References
issue](#25)
  • Loading branch information
Lazar955 authored Sep 18, 2024
1 parent 49e8cb8 commit 8a4bdf5
Show file tree
Hide file tree
Showing 10 changed files with 195 additions and 2,273 deletions.
22 changes: 11 additions & 11 deletions .github/workflows/publish.yml → .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@ name: docker_publish
on:
push:
branches:
- 'main'
- 'main'
tags:
- '*'
- '*'

jobs:
lint_test:
uses: babylonlabs-io/.github/.github/workflows/[email protected]
with:
go-version: '1.23'
go-lint-version: 'v1.60.2'
run-unit-tests: true
run-integration-tests: true
run-lint: true
install-dependencies-command: |
sudo apt-get update
sudo apt-get install -y libzmq3-dev
go-version: '1.23'
go-lint-version: 'v1.60.2'
run-unit-tests: true
run-integration-tests: true
run-lint: true
install-dependencies-command: |
sudo apt-get update
sudo apt-get install -y libzmq3-dev
docker_pipeline:
needs: ["lint_test"]
uses: babylonlabs-io/.github/.github/workflows/[email protected]
secrets: inherit
with:
publish: true
publish: true
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ MOCKGEN_REPO=github.com/golang/mock/mockgen
MOCKGEN_VERSION=v1.6.0
MOCKGEN_CMD=go run ${MOCKGEN_REPO}@${MOCKGEN_VERSION}
BUILDDIR ?= $(CURDIR)/build
TOOLS_DIR := tools

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

Expand Down Expand Up @@ -49,8 +48,7 @@ test:
go test -race ./...

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

build-docker:
$(DOCKER) build --tag babylonlabs-io/vigilante -f Dockerfile \
Expand Down
214 changes: 0 additions & 214 deletions e2etest/babylon_node_handler.go

This file was deleted.

16 changes: 10 additions & 6 deletions e2etest/bitcoind_node_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"github.com/babylonlabs-io/vigilante/e2etest/container"
"github.com/ory/dockertest/v3"
"github.com/stretchr/testify/require"
"os"
"strconv"
Expand Down Expand Up @@ -33,25 +34,22 @@ type BitcoindTestHandler struct {
m *container.Manager
}

func NewBitcoindHandler(t *testing.T) *BitcoindTestHandler {
manager, err := container.NewManager()
require.NoError(t, err)

func NewBitcoindHandler(t *testing.T, manager *container.Manager) *BitcoindTestHandler {
return &BitcoindTestHandler{
t: t,
m: manager,
}
}

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

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

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

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

return bitcoinResource
}

// GetBlockCount retrieves the current number of blocks in the blockchain from the Bitcoind.
Expand Down Expand Up @@ -115,3 +115,7 @@ func (h *BitcoindTestHandler) ImportDescriptors(descriptor string) {
_, _, err := h.m.ExecBitcoindCliCmd(h.t, []string{"importdescriptors", descriptor})
require.NoError(h.t, err)
}

func (h *BitcoindTestHandler) Stop() {
_ = h.m.ClearResources()
}
9 changes: 7 additions & 2 deletions e2etest/container/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,24 @@ package container
type ImageConfig struct {
BitcoindRepository string
BitcoindVersion string
BabylonRepository string
BabylonVersion string
}

//nolint:deadcode
const (
dockerBitcoindRepository = "lncm/bitcoind"
dockerBitcoindVersionTag = "v27.0"
dockerBabylondRepository = "babylonlabs/babylond"
dockerBabylondVersionTag = "8e0222804ed19b18d74d599b80baa18f05e87d8a" // this is built from commit b1e255a
)

// NewImageConfig returns ImageConfig needed for running e2e test.
func NewImageConfig() ImageConfig {
config := ImageConfig{
return ImageConfig{
BitcoindRepository: dockerBitcoindRepository,
BitcoindVersion: dockerBitcoindVersionTag,
BabylonRepository: dockerBabylondRepository,
BabylonVersion: dockerBabylondVersionTag,
}
return config
}
Loading

0 comments on commit 8a4bdf5

Please sign in to comment.