diff --git a/internal/config/config.go b/internal/config/config.go index a251c949..586a7df9 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -97,6 +97,7 @@ func StringWithDefault(value, defaultValue string) string { } var ( + Debug = "debug" DatabaseHost = "database.host" DatabasePort = "database.port" DatabaseUser = "database.user" diff --git a/pkg/contractCaller/sequentialContractCaller/contractCaller_test.go b/pkg/contractCaller/sequentialContractCaller/contractCaller_test.go index 61056c7a..7ab30b06 100644 --- a/pkg/contractCaller/sequentialContractCaller/contractCaller_test.go +++ b/pkg/contractCaller/sequentialContractCaller/contractCaller_test.go @@ -10,6 +10,7 @@ import ( "github.com/Layr-Labs/sidecar/pkg/utils" "github.com/stretchr/testify/assert" "go.uber.org/zap" + "os" "testing" ) @@ -21,10 +22,10 @@ func setup() ( cfg := config.NewConfig() cfg.Chain = config.Chain_Mainnet cfg.EthereumRpcConfig.BaseUrl = "https://tame-fabled-liquid.quiknode.pro/f27d4be93b4d7de3679f5c5ae881233f857407a0" - cfg.Debug = true + cfg.Debug = os.Getenv(config.Debug) == "true" cfg.DatabaseConfig = *tests.GetDbConfigFromEnv() - l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: true}) + l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: cfg.Debug}) return l, cfg, nil } diff --git a/pkg/contractStore/postgresContractStore/postgresContractStore.go b/pkg/contractStore/postgresContractStore/postgresContractStore.go index 7a62b918..09c22918 100644 --- a/pkg/contractStore/postgresContractStore/postgresContractStore.go +++ b/pkg/contractStore/postgresContractStore/postgresContractStore.go @@ -238,7 +238,7 @@ func (s *PostgresContractStore) InitializeCoreContracts() error { return fmt.Errorf("Failed to create core contract: %w", err) } if found { - s.Logger.Sugar().Infow("Contract already exists", zap.String("contractAddress", contract.ContractAddress)) + s.Logger.Sugar().Debugw("Contract already exists", zap.String("contractAddress", contract.ContractAddress)) continue } @@ -246,7 +246,7 @@ func (s *PostgresContractStore) InitializeCoreContracts() error { if err != nil { return fmt.Errorf("Failed to create core contract: %w", err) } - s.Logger.Sugar().Infow("Created core contract", zap.String("contractAddress", contract.ContractAddress)) + s.Logger.Sugar().Debugw("Created core contract", zap.String("contractAddress", contract.ContractAddress)) } for _, proxy := range coreContracts.ProxyContracts { _, found, err := s.FindOrCreateProxyContract( @@ -258,13 +258,13 @@ func (s *PostgresContractStore) InitializeCoreContracts() error { return fmt.Errorf("Failed to create core proxy contract: %w", err) } if found { - s.Logger.Sugar().Infow("Proxy contract already exists", + s.Logger.Sugar().Debugw("Proxy contract already exists", zap.String("contractAddress", proxy.ContractAddress), zap.String("proxyContractAddress", proxy.ContractAddress), ) continue } - s.Logger.Sugar().Infow("Created proxy contract", + s.Logger.Sugar().Debugw("Created proxy contract", zap.String("contractAddress", proxy.ContractAddress), zap.String("proxyContractAddress", proxy.ContractAddress), ) diff --git a/pkg/contractStore/postgresContractStore/postgresContractStore_test.go b/pkg/contractStore/postgresContractStore/postgresContractStore_test.go index 5e5e35b2..b016636b 100644 --- a/pkg/contractStore/postgresContractStore/postgresContractStore_test.go +++ b/pkg/contractStore/postgresContractStore/postgresContractStore_test.go @@ -9,6 +9,7 @@ import ( "github.com/stretchr/testify/assert" "go.uber.org/zap" "gorm.io/gorm" + "os" "testing" ) @@ -20,9 +21,10 @@ func setup() ( error, ) { cfg := config.NewConfig() + cfg.Debug = os.Getenv(config.Debug) == "true" cfg.DatabaseConfig = *tests.GetDbConfigFromEnv() - l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: true}) + l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: cfg.Debug}) dbname, _, grm, err := postgres.GetTestPostgresDatabase(cfg.DatabaseConfig, cfg, l) if err != nil { diff --git a/pkg/eigenState/avsOperators/avsOperators_test.go b/pkg/eigenState/avsOperators/avsOperators_test.go index 25acc620..8048b73a 100644 --- a/pkg/eigenState/avsOperators/avsOperators_test.go +++ b/pkg/eigenState/avsOperators/avsOperators_test.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/Layr-Labs/sidecar/pkg/postgres" "github.com/Layr-Labs/sidecar/pkg/storage" + "os" "testing" "time" @@ -26,10 +27,10 @@ func setup() ( ) { cfg := config.NewConfig() cfg.Chain = config.Chain_Mainnet - cfg.Debug = false + cfg.Debug = os.Getenv(config.Debug) == "true" cfg.DatabaseConfig = *tests.GetDbConfigFromEnv() - l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: true}) + l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: cfg.Debug}) dbname, _, grm, err := postgres.GetTestPostgresDatabase(cfg.DatabaseConfig, cfg, l) if err != nil { diff --git a/pkg/eigenState/disabledDistributionRoots/disabledDistributionRoots_test.go b/pkg/eigenState/disabledDistributionRoots/disabledDistributionRoots_test.go index feba36b1..e2096d58 100644 --- a/pkg/eigenState/disabledDistributionRoots/disabledDistributionRoots_test.go +++ b/pkg/eigenState/disabledDistributionRoots/disabledDistributionRoots_test.go @@ -5,6 +5,7 @@ import ( "github.com/Layr-Labs/sidecar/pkg/postgres" "github.com/Layr-Labs/sidecar/pkg/storage" "math/big" + "os" "testing" "time" @@ -25,9 +26,10 @@ func setup() ( error, ) { cfg := config.NewConfig() + cfg.Debug = os.Getenv(config.Debug) == "true" cfg.DatabaseConfig = *tests.GetDbConfigFromEnv() - l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: true}) + l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: cfg.Debug}) dbname, _, grm, err := postgres.GetTestPostgresDatabase(cfg.DatabaseConfig, cfg, l) if err != nil { diff --git a/pkg/eigenState/eigenstate_test.go b/pkg/eigenState/eigenstate_test.go index 1ea293c6..4c79ba58 100644 --- a/pkg/eigenState/eigenstate_test.go +++ b/pkg/eigenState/eigenstate_test.go @@ -2,6 +2,7 @@ package eigenState import ( "github.com/Layr-Labs/sidecar/pkg/postgres" + "os" "testing" "github.com/Layr-Labs/sidecar/internal/config" @@ -23,9 +24,10 @@ func setup() ( error, ) { cfg := config.NewConfig() + cfg.Debug = os.Getenv(config.Debug) == "true" cfg.DatabaseConfig = *tests.GetDbConfigFromEnv() - l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: true}) + l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: cfg.Debug}) dbname, _, grm, err := postgres.GetTestPostgresDatabase(cfg.DatabaseConfig, cfg, l) if err != nil { diff --git a/pkg/eigenState/rewardSubmissions/rewardSubmissions_test.go b/pkg/eigenState/rewardSubmissions/rewardSubmissions_test.go index 48c38744..0ca23776 100644 --- a/pkg/eigenState/rewardSubmissions/rewardSubmissions_test.go +++ b/pkg/eigenState/rewardSubmissions/rewardSubmissions_test.go @@ -5,6 +5,7 @@ import ( "github.com/Layr-Labs/sidecar/pkg/postgres" "github.com/Layr-Labs/sidecar/pkg/storage" "math/big" + "os" "strings" "testing" "time" @@ -27,8 +28,9 @@ func setup() ( ) { cfg := config.NewConfig() cfg.DatabaseConfig = *tests.GetDbConfigFromEnv() + cfg.Debug = os.Getenv(config.Debug) == "true" - l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: true}) + l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: cfg.Debug}) dbname, _, grm, err := postgres.GetTestPostgresDatabase(cfg.DatabaseConfig, cfg, l) if err != nil { diff --git a/pkg/eigenState/stakerShares/stakerShares_test.go b/pkg/eigenState/stakerShares/stakerShares_test.go index 642e6922..148a6085 100644 --- a/pkg/eigenState/stakerShares/stakerShares_test.go +++ b/pkg/eigenState/stakerShares/stakerShares_test.go @@ -39,12 +39,6 @@ func setup() ( return dbname, grm, l, cfg, nil } -func logChanges(changes *AccumulatedStateChanges) { - // for _, change := range changes.Changes { - // // fmt.Printf("Change: %+v\n", change) - // } -} - func Test_StakerSharesState(t *testing.T) { dbName, grm, l, cfg, err := setup() @@ -112,7 +106,6 @@ func Test_StakerSharesState(t *testing.T) { assert.NotNil(t, change) typedChange := change.(*AccumulatedStateChanges) - logChanges(typedChange) assert.Equal(t, 1, len(typedChange.Changes)) assert.Equal(t, "0x00105f70bf0a2dec987dbfc87a869c3090abf6a0", typedChange.Changes[0].Staker) @@ -192,14 +185,9 @@ func Test_StakerSharesState(t *testing.T) { assert.Nil(t, err) assert.NotNil(t, change) - typedChange = change.(*AccumulatedStateChanges) - logChanges(typedChange) - change, err = model.HandleStateChange(withdrawalQueuedTx) assert.Nil(t, err) assert.NotNil(t, change) - typedChange = change.(*AccumulatedStateChanges) - logChanges(typedChange) err = model.CommitFinalState(transaction.BlockNumber) assert.Nil(t, err) @@ -267,14 +255,10 @@ func Test_StakerSharesState(t *testing.T) { change, err = model.HandleStateChange(withdrawalQueued) assert.Nil(t, err) assert.NotNil(t, change) - typedChange = change.(*AccumulatedStateChanges) - logChanges(typedChange) change, err = model.HandleStateChange(withdrawalMigrated) assert.Nil(t, err) assert.NotNil(t, change) - typedChange = change.(*AccumulatedStateChanges) - logChanges(typedChange) err = model.CommitFinalState(transaction.BlockNumber) assert.Nil(t, err) @@ -324,8 +308,6 @@ func Test_StakerSharesState(t *testing.T) { change, err = model.HandleStateChange(deposit2) assert.Nil(t, err) assert.NotNil(t, change) - typedChange = change.(*AccumulatedStateChanges) - logChanges(typedChange) err = model.CommitFinalState(transaction.BlockNumber) assert.Nil(t, err) diff --git a/pkg/eigenState/stateManager/stateManager_test.go b/pkg/eigenState/stateManager/stateManager_test.go index 6d9732d3..fff2c08f 100644 --- a/pkg/eigenState/stateManager/stateManager_test.go +++ b/pkg/eigenState/stateManager/stateManager_test.go @@ -3,6 +3,7 @@ package stateManager import ( "github.com/Layr-Labs/sidecar/pkg/postgres" "github.com/Layr-Labs/sidecar/pkg/storage" + "os" "testing" "time" @@ -23,9 +24,10 @@ func setup() ( error, ) { cfg := config.NewConfig() + cfg.Debug = os.Getenv(config.Debug) == "true" cfg.DatabaseConfig = *tests.GetDbConfigFromEnv() - l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: true}) + l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: cfg.Debug}) dbname, _, grm, err := postgres.GetTestPostgresDatabase(cfg.DatabaseConfig, cfg, l) if err != nil { diff --git a/pkg/eigenState/submittedDistributionRoots/submittedDistributionRoots_test.go b/pkg/eigenState/submittedDistributionRoots/submittedDistributionRoots_test.go index 7bf20753..40ad41c4 100644 --- a/pkg/eigenState/submittedDistributionRoots/submittedDistributionRoots_test.go +++ b/pkg/eigenState/submittedDistributionRoots/submittedDistributionRoots_test.go @@ -5,6 +5,7 @@ import ( "github.com/Layr-Labs/sidecar/pkg/postgres" "github.com/Layr-Labs/sidecar/pkg/storage" "math/big" + "os" "testing" "time" @@ -25,9 +26,10 @@ func setup() ( error, ) { cfg := config.NewConfig() + cfg.Debug = os.Getenv(config.Debug) == "true" cfg.DatabaseConfig = *tests.GetDbConfigFromEnv() - l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: true}) + l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: cfg.Debug}) dbname, _, grm, err := postgres.GetTestPostgresDatabase(cfg.DatabaseConfig, cfg, l) if err != nil { diff --git a/pkg/eventBus/eventBus_test.go b/pkg/eventBus/eventBus_test.go index bac32ed8..ef583fd0 100644 --- a/pkg/eventBus/eventBus_test.go +++ b/pkg/eventBus/eventBus_test.go @@ -2,16 +2,19 @@ package eventBus import ( "context" + "github.com/Layr-Labs/sidecar/internal/config" "github.com/Layr-Labs/sidecar/internal/logger" "github.com/Layr-Labs/sidecar/pkg/eventBus/eventBusTypes" "github.com/stretchr/testify/assert" + "os" "sync" "sync/atomic" "testing" ) func Test_EventBus(t *testing.T) { - l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: true}) + debug := os.Getenv(config.Debug) == "true" + l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: debug}) eb := NewEventBus(l) diff --git a/pkg/indexer/restakedStrategies_test.go b/pkg/indexer/restakedStrategies_test.go index 5b888e6a..869bc5b7 100644 --- a/pkg/indexer/restakedStrategies_test.go +++ b/pkg/indexer/restakedStrategies_test.go @@ -20,6 +20,7 @@ import ( "go.uber.org/zap" "gorm.io/gorm" "log" + "os" "testing" "time" ) @@ -33,10 +34,10 @@ func setup() ( ) { cfg := config.NewConfig() cfg.Chain = config.Chain_Holesky - cfg.Debug = false + cfg.Debug = os.Getenv(config.Debug) == "true" cfg.DatabaseConfig = *tests.GetDbConfigFromEnv() - l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: true}) + l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: cfg.Debug}) dbname, _, grm, err := postgres.GetTestPostgresDatabase(cfg.DatabaseConfig, cfg, l) if err != nil { @@ -162,8 +163,6 @@ func Test_IndexerRestakedStrategies(t *testing.T) { query := `select * from operator_restaked_strategies` result := grm.Raw(query).Scan(&results) - fmt.Printf("Results: %+v\n", results) - assert.Nil(t, result.Error) assert.True(t, len(results) > 0) diff --git a/pkg/pipeline/pipelineIntegration_test.go b/pkg/pipeline/pipelineIntegration_test.go index 2768d075..0c7c9c5b 100644 --- a/pkg/pipeline/pipelineIntegration_test.go +++ b/pkg/pipeline/pipelineIntegration_test.go @@ -19,6 +19,7 @@ import ( "github.com/Layr-Labs/sidecar/pkg/storage" pgStorage "github.com/Layr-Labs/sidecar/pkg/storage/postgres" "log" + "os" "testing" "github.com/Layr-Labs/sidecar/internal/config" @@ -51,11 +52,12 @@ func setup(ethConfig *ethereum.EthereumClientConfig) ( ) cfg := config.NewConfig() + cfg.Debug = os.Getenv(config.Debug) == "true" cfg.Chain = config.Chain_Mainnet cfg.EthereumRpcConfig.BaseUrl = rpcUrl cfg.DatabaseConfig = *tests.GetDbConfigFromEnv() - l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: true}) + l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: cfg.Debug}) metricsClients, err := metrics.InitMetricsSinksFromConfig(cfg, l) if err != nil { diff --git a/pkg/postgres/migrations/migrator.go b/pkg/postgres/migrations/migrator.go index 1bc7cca3..7ef3cbf8 100644 --- a/pkg/postgres/migrations/migrator.go +++ b/pkg/postgres/migrations/migrator.go @@ -132,7 +132,7 @@ func (m *Migrator) Migrate(migration Migration) error { result := m.GDb.Find(&migrationRecord, "name = ?", name).Limit(1) if result.Error == nil && result.RowsAffected == 0 { - m.Logger.Sugar().Infof("Running migration '%s'", name) + m.Logger.Sugar().Debugf("Running migration '%s'", name) // run migration err := migration.Up(m.Db, m.GDb, m.globalConfig) if err != nil { @@ -153,7 +153,7 @@ func (m *Migrator) Migrate(migration Migration) error { m.Logger.Sugar().Errorw(fmt.Sprintf("Failed to find migration '%s'", name), zap.Error(result.Error)) return result.Error } else if result.RowsAffected > 0 { - m.Logger.Sugar().Infof("Migration %s already run", name) + m.Logger.Sugar().Debugf("Migration %s already run", name) return nil } return nil diff --git a/pkg/postgres/postgres_test.go b/pkg/postgres/postgres_test.go index 7a811ae6..bf030993 100644 --- a/pkg/postgres/postgres_test.go +++ b/pkg/postgres/postgres_test.go @@ -5,11 +5,13 @@ import ( "github.com/Layr-Labs/sidecar/internal/logger" "github.com/Layr-Labs/sidecar/internal/tests" "github.com/Layr-Labs/sidecar/pkg/postgres/migrations" + "os" "testing" ) func Test_Postgres(t *testing.T) { cfg := config.NewConfig() + cfg.Debug = os.Getenv(config.Debug) == "true" cfg.DatabaseConfig = *tests.GetDbConfigFromEnv() testDbName, err := tests.GenerateTestDbName() @@ -18,7 +20,7 @@ func Test_Postgres(t *testing.T) { } cfg.DatabaseConfig.DbName = testDbName - l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: true}) + l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: cfg.Debug}) pgConfig := PostgresConfigFromDbConfig(&cfg.DatabaseConfig) pgConfig.CreateDbIfNotExists = true diff --git a/pkg/storage/postgres/storage_test.go b/pkg/storage/postgres/storage_test.go index c91f7c19..a49febb0 100644 --- a/pkg/storage/postgres/storage_test.go +++ b/pkg/storage/postgres/storage_test.go @@ -5,6 +5,7 @@ import ( "github.com/Layr-Labs/sidecar/pkg/parser" "github.com/Layr-Labs/sidecar/pkg/postgres" "github.com/Layr-Labs/sidecar/pkg/storage" + "os" "strings" "testing" "time" @@ -24,9 +25,10 @@ func setup() ( error, ) { cfg := config.NewConfig() + cfg.Debug = os.Getenv(config.Debug) == "true" cfg.DatabaseConfig = *tests.GetDbConfigFromEnv() - l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: true}) + l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: cfg.Debug}) dbname, _, grm, err := postgres.GetTestPostgresDatabase(cfg.DatabaseConfig, cfg, l) if err != nil { diff --git a/scripts/goTest.sh b/scripts/goTest.sh index ece0bcf7..3f976021 100755 --- a/scripts/goTest.sh +++ b/scripts/goTest.sh @@ -6,7 +6,7 @@ export SIDECAR_DATABASE_HOST=${SIDECAR_DATABASE_HOST:-"localhost"} export SIDECAR_DATABASE_PORT=${SIDECAR_DATABASE_PORT:-5432} export SIDECAR_DATABASE_USER=${SIDECAR_DATABASE_USER:-""} export SIDECAR_DATABASE_PASSWORD=${SIDECAR_DATABASE_PASSWORD:-""} -export SIDECAR_DEBUG=${SIDECAR_DEBUG:-"true"} +export SIDECAR_DEBUG=${SIDECAR_DEBUG:-"false"} go test $@