From a8e0398a05a11bef93578f226b494b2cd9c4b7dd Mon Sep 17 00:00:00 2001 From: Lazar <12626340+Lazar955@users.noreply.github.com> Date: Wed, 25 Sep 2024 11:38:27 +0200 Subject: [PATCH 1/2] chore(e2e): parse go mod file (#64) Parse go mod file in order to get docker image version in e2e tests --- e2etest/container/config.go | 14 +++++++++++--- e2etest/container/container.go | 4 ++-- e2etest/test_manager.go | 2 +- testutil/version.go | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 testutil/version.go diff --git a/e2etest/container/config.go b/e2etest/container/config.go index 2ca2a09e..f71c3840 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 179e7aa9..c2274fff 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 17a82bbf..16df8a28 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 00000000..5a2dfafa --- /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) +} From bafeadc03974abdac8ae6907b9a809ff8d124778 Mon Sep 17 00:00:00 2001 From: Lazar <12626340+Lazar955@users.noreply.github.com> Date: Thu, 26 Sep 2024 09:18:37 +0200 Subject: [PATCH 2/2] fix(config): fix db config meta fields (#65) Fixes db config meta fields to conform viper --- config/dbconfig.go | 12 ++++++------ config/monitor.go | 4 ++-- config/submitter.go | 5 +++-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/config/dbconfig.go b/config/dbconfig.go index fc6dc54d..ec98aec4 100644 --- a/config/dbconfig.go +++ b/config/dbconfig.go @@ -13,31 +13,31 @@ const ( type DBConfig struct { // DBPath is the directory path in which the database file should be // stored. - DBPath string `long:"dbpath" description:"The directory path in which the database file should be stored."` + DBPath string `mapstructure:"dbpath"` // DBFileName is the name of the database file. - DBFileName string `long:"dbfilename" description:"The name of the database file."` + DBFileName string `mapstructure:"dbfilename"` // NoFreelistSync, if true, prevents the database from syncing its // freelist to disk, resulting in improved performance at the expense of // increased startup time. - NoFreelistSync bool `long:"nofreelistsync" description:"Prevents the database from syncing its freelist to disk, resulting in improved performance at the expense of increased startup time."` + NoFreelistSync bool `mapstructure:"nofreelistsync"` // AutoCompact specifies if a Bolt based database backend should be // automatically compacted on startup (if the minimum age of the // database file is reached). This will require additional disk space // for the compacted copy of the database but will result in an overall // lower database size after the compaction. - AutoCompact bool `long:"autocompact" description:"Specifies if a Bolt based database backend should be automatically compacted on startup (if the minimum age of the database file is reached). This will require additional disk space for the compacted copy of the database but will result in an overall lower database size after the compaction."` + AutoCompact bool `mapstructure:"autocompact"` // AutoCompactMinAge specifies the minimum time that must have passed // since a bolt database file was last compacted for the compaction to // be considered again. - AutoCompactMinAge time.Duration `long:"autocompactminage" description:"Specifies the minimum time that must have passed since a bolt database file was last compacted for the compaction to be considered again."` + AutoCompactMinAge time.Duration `mapstructure:"autocompact"` // DBTimeout specifies the timeout value to use when opening the wallet // database. - DBTimeout time.Duration `long:"dbtimeout" description:"Specifies the timeout value to use when opening the wallet database."` + DBTimeout time.Duration `mapstructure:"autocompact"` } func DefaultDBConfig() *DBConfig { diff --git a/config/monitor.go b/config/monitor.go index 9653141f..aace1b77 100644 --- a/config/monitor.go +++ b/config/monitor.go @@ -29,8 +29,8 @@ type MonitorConfig struct { BtcConfirmationDepth uint64 `mapstructure:"btc-confirmation-depth"` // whether to enable liveness checker EnableLivenessChecker bool `mapstructure:"enable-liveness-checker"` - - DatabaseConfig *DBConfig `mapstructure:"database-config"` + // DatabaseConfig stores lates epoch and height used for faster bootstrap + DatabaseConfig *DBConfig `mapstructure:"dbconfig"` } func (cfg *MonitorConfig) Validate() error { diff --git a/config/submitter.go b/config/submitter.go index 511deee3..6a7b6d83 100644 --- a/config/submitter.go +++ b/config/submitter.go @@ -25,8 +25,9 @@ type SubmitterConfig struct { PollingIntervalSeconds uint `mapstructure:"polling-interval-seconds"` // ResendIntervalSeconds defines the time (in seconds) which the submitter awaits // before resubmitting checkpoints to BTC - ResendIntervalSeconds uint `mapstructure:"resend-interval-seconds"` - DatabaseConfig *DBConfig `mapstructure:"database-config"` + ResendIntervalSeconds uint `mapstructure:"resend-interval-seconds"` + // DatabaseConfig stores last submitted txn + DatabaseConfig *DBConfig `mapstructure:"dbconfig"` } func (cfg *SubmitterConfig) Validate() error {