From 7c3a6882a438d2cdcd880b15b8a39329bb27ae17 Mon Sep 17 00:00:00 2001 From: Gurjot Date: Mon, 16 Dec 2024 14:16:20 +0530 Subject: [PATCH] fix cfg --- e2etest/test_manager.go | 52 ++++++++++++++++++++++++++++++++++----- internal/config/config.go | 47 ----------------------------------- 2 files changed, 46 insertions(+), 53 deletions(-) diff --git a/e2etest/test_manager.go b/e2etest/test_manager.go index c204ba2..80e2c7b 100644 --- a/e2etest/test_manager.go +++ b/e2etest/test_manager.go @@ -27,6 +27,7 @@ import ( bbn "github.com/babylonlabs-io/babylon/types" btclctypes "github.com/babylonlabs-io/babylon/x/btclightclient/types" queuecli "github.com/babylonlabs-io/staking-queue-client/client" + queuecfg "github.com/babylonlabs-io/staking-queue-client/config" "github.com/babylonlabs-io/staking-queue-client/queuemngr" "github.com/btcsuite/btcd/btcec/v2" "github.com/btcsuite/btcd/btcutil" @@ -36,6 +37,7 @@ import ( "github.com/btcsuite/btcd/txscript" "github.com/btcsuite/btcd/wire" pv "github.com/cosmos/relayer/v2/relayer/provider" + "github.com/stretchr/testify/require" "go.uber.org/zap" ) @@ -70,7 +72,7 @@ func StartManager(t *testing.T, numMatureOutputsInWallet uint32, epochInterval u passphrase := "pass" _ = btcHandler.CreateWallet("default", passphrase) - cfg := DefaultStakingIndexerConfig() + cfg := TestConfig(t) cfg.BTC.RPCHost = fmt.Sprintf("127.0.0.1:%s", bitcoind.GetPort("18443/tcp")) @@ -227,12 +229,50 @@ func tempDir(t *testing.T) (string, error) { return tempPath, err } -func DefaultStakingIndexerConfig() *config.Config { - defaultConfig := config.DefaultConfig() - defaultConfig.Queue.QueueProcessingTimeout = time.Duration(500) * time.Second - defaultConfig.Queue.ReQueueDelayTime = time.Duration(300) * time.Second +func TestConfig(t *testing.T) *config.Config { + // TODO: ideally this should be setup through config-test.yaml + cfg := &config.Config{ + BTC: config.BTCConfig{ + RPCHost: "127.0.0.1:18443", + RPCUser: "user", + RPCPass: "pass", + BlockPollingInterval: 30 * time.Second, + TxPollingInterval: 30 * time.Second, + BlockCacheSize: 20 * 1024 * 1024, // 20 MB + MaxRetryTimes: 5, + RetryInterval: 500 * time.Millisecond, + NetParams: "regtest", + }, + Db: config.DbConfig{ + Address: "mongodb://localhost:27019/?replicaSet=RS&directConnection=true", + Username: "root", + Password: "example", + DbName: "babylon-staking-indexer", + }, + BBN: config.BBNConfig{ + RPCAddr: "http://localhost:26657", + Timeout: 20 * time.Second, + MaxRetryTimes: 3, + RetryInterval: 1 * time.Second, + }, + Poller: config.PollerConfig{ + ParamPollingInterval: 1 * time.Second, + ExpiryCheckerPollingInterval: 1 * time.Second, + ExpiredDelegationsLimit: 1000, + }, + Queue: *queuecfg.DefaultQueueConfig(), + Metrics: config.MetricsConfig{ + Host: "0.0.0.0", + Port: 2112, + }, + } + cfg.Queue.QueueProcessingTimeout = time.Duration(50) * time.Second + cfg.Queue.ReQueueDelayTime = time.Duration(100) * time.Second + + err := cfg.Validate() + require.NoError(t, err) - return defaultConfig + return cfg } // RetrieveTransactionFromMempool fetches transactions from the mempool for the given hashes diff --git a/internal/config/config.go b/internal/config/config.go index 7c31ceb..399746e 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -4,9 +4,7 @@ import ( "fmt" "os" "strings" - "time" - bbncfg "github.com/babylonlabs-io/babylon/client/config" queue "github.com/babylonlabs-io/staking-queue-client/config" "github.com/spf13/viper" ) @@ -83,48 +81,3 @@ func New(cfgFile string) (*Config, error) { return &cfg, nil } - -func DefaultConfig() *Config { - bbnCfg := bbncfg.DefaultBabylonConfig() - cfg := &Config{ - BTC: BTCConfig{ - RPCHost: "127.0.0.1:18443", - RPCUser: "user", - RPCPass: "pass", - BlockPollingInterval: 30 * time.Second, - TxPollingInterval: 30 * time.Second, - BlockCacheSize: 20 * 1024 * 1024, // 20 MB - MaxRetryTimes: 5, - RetryInterval: 500 * time.Millisecond, - NetParams: "regtest", - }, - Db: DbConfig{ - Address: "mongodb://localhost:27019/?replicaSet=RS&directConnection=true", - Username: "root", - Password: "example", - DbName: "babylon-staking-indexer", - }, - BBN: BBNConfig{ - RPCAddr: bbnCfg.RPCAddr, - Timeout: bbnCfg.Timeout, - MaxRetryTimes: 3, - RetryInterval: 1 * time.Second, - }, - Poller: PollerConfig{ - ParamPollingInterval: 1 * time.Second, - ExpiryCheckerPollingInterval: 1 * time.Second, - ExpiredDelegationsLimit: 1000, - }, - Queue: *queue.DefaultQueueConfig(), - Metrics: MetricsConfig{ - Host: "0.0.0.0", - Port: 2112, - }, - } - - if err := cfg.Validate(); err != nil { - panic(err) - } - - return cfg -}