diff --git a/e2etest/container/config.go b/e2etest/container/config.go index 2ca2a09..f71c384 100644 --- a/e2etest/container/config.go +++ b/e2etest/container/config.go @@ -1,5 +1,11 @@ package container +import ( + "github.com/babylonlabs-io/vigilante/testutil" + "github.com/stretchr/testify/require" + "testing" +) + // ImageConfig contains all images and their respective tags // needed for running e2e tests. type ImageConfig struct { @@ -14,15 +20,17 @@ const ( dockerBitcoindRepository = "lncm/bitcoind" dockerBitcoindVersionTag = "v27.0" dockerBabylondRepository = "babylonlabs/babylond" - dockerBabylondVersionTag = "v0.10.0" ) // NewImageConfig returns ImageConfig needed for running e2e test. -func NewImageConfig() ImageConfig { +func NewImageConfig(t *testing.T) ImageConfig { + babylondVersion, err := testutil.GetBabylonVersion() + require.NoError(t, err) + return ImageConfig{ BitcoindRepository: dockerBitcoindRepository, BitcoindVersion: dockerBitcoindVersionTag, BabylonRepository: dockerBabylondRepository, - BabylonVersion: dockerBabylondVersionTag, + BabylonVersion: babylondVersion, } } diff --git a/e2etest/container/container.go b/e2etest/container/container.go index 179e7aa..c2274ff 100644 --- a/e2etest/container/container.go +++ b/e2etest/container/container.go @@ -40,9 +40,9 @@ type Manager struct { // NewManager creates a new Manager instance and initializes // all Docker specific utilities. Returns an error if initialization fails. -func NewManager() (docker *Manager, err error) { +func NewManager(t *testing.T) (docker *Manager, err error) { docker = &Manager{ - cfg: NewImageConfig(), + cfg: NewImageConfig(t), resources: make(map[string]*dockertest.Resource), } docker.pool, err = dockertest.NewPool("") diff --git a/e2etest/test_manager.go b/e2etest/test_manager.go index 17a82bb..16df8a2 100644 --- a/e2etest/test_manager.go +++ b/e2etest/test_manager.go @@ -84,7 +84,7 @@ func initBTCClientWithSubscriber(t *testing.T, cfg *config.Config) *btcclient.Cl // StartManager creates a test manager // NOTE: uses btc client with zmq func StartManager(t *testing.T, numMatureOutputsInWallet uint32, epochInterval uint) *TestManager { - manager, err := container.NewManager() + manager, err := container.NewManager(t) require.NoError(t, err) btcHandler := NewBitcoindHandler(t, manager) diff --git a/testutil/version.go b/testutil/version.go new file mode 100644 index 0000000..5a2dfaf --- /dev/null +++ b/testutil/version.go @@ -0,0 +1,32 @@ +package testutil + +import ( + "fmt" + "golang.org/x/mod/modfile" + "os" + "path/filepath" +) + +// GetBabylonVersion returns babylond version from go.mod +func GetBabylonVersion() (string, error) { + goModPath := filepath.Join("..", "go.mod") + data, err := os.ReadFile(goModPath) + if err != nil { + return "", err + } + + // Parse the go.mod file + modFile, err := modfile.Parse("go.mod", data, nil) + if err != nil { + return "", err + } + + const modName = "github.com/babylonlabs-io/babylon" + for _, require := range modFile.Require { + if require.Mod.Path == modName { + return require.Mod.Version, nil + } + } + + return "", fmt.Errorf("module %s not found", modName) +}