Skip to content

Commit

Permalink
Use commonconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanTinianov committed Jan 4, 2024
1 parent f6b7170 commit 365c127
Show file tree
Hide file tree
Showing 33 changed files with 164 additions and 165 deletions.
7 changes: 3 additions & 4 deletions core/chains/evm/headtracker/head_tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import (

"github.com/jmoiron/sqlx"

commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config"
"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink-common/pkg/services"
"github.com/smartcontractkit/chainlink-common/pkg/sqlutil"
"github.com/smartcontractkit/chainlink-common/pkg/utils/mailbox"
"github.com/smartcontractkit/chainlink-common/pkg/utils/mailbox/mailboxtest"

Expand All @@ -39,7 +39,6 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/evmtest"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/pgtest"
"github.com/smartcontractkit/chainlink/v2/core/services/chainlink"
"github.com/smartcontractkit/chainlink/v2/core/utils"
)

func firstHead(t *testing.T, db *sqlx.DB) (h evmtypes.Head) {
Expand Down Expand Up @@ -427,7 +426,7 @@ func TestHeadTracker_SwitchesToLongestChainWithHeadSamplingEnabled(t *testing.T)
c.EVM[0].FinalityDepth = ptr[uint32](50)
// Need to set the buffer to something large since we inject a lot of heads at once and otherwise they will be dropped
c.EVM[0].HeadTracker.MaxBufferSize = ptr[uint32](100)
c.EVM[0].HeadTracker.SamplingInterval = sqlutil.MustNewDuration(2500 * time.Millisecond)
c.EVM[0].HeadTracker.SamplingInterval = commonconfig.MustNewDuration(2500 * time.Millisecond)
})

ethClient := evmtest.NewEthClientMockWithDefaultChain(t)
Expand Down Expand Up @@ -555,7 +554,7 @@ func TestHeadTracker_SwitchesToLongestChainWithHeadSamplingDisabled(t *testing.T
c.EVM[0].FinalityDepth = ptr[uint32](50)
// Need to set the buffer to something large since we inject a lot of heads at once and otherwise they will be dropped
c.EVM[0].HeadTracker.MaxBufferSize = ptr[uint32](100)
c.EVM[0].HeadTracker.SamplingInterval = sqlutil.MustNewDuration(0)
c.EVM[0].HeadTracker.SamplingInterval = commonconfig.MustNewDuration(0)
})

ethClient := evmtest.NewEthClientMockWithDefaultChain(t)
Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/txmgr/evm_tx_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1380,7 +1380,7 @@ func TestORM_UpdateTxUnstartedToInProgress(t *testing.T) {
etx := mustInsertInProgressEthTxWithAttempt(t, txStore, nonce, fromAddress)
require.Len(t, etx.TxAttempts, 1)

zero := sqlutil.MustNewDuration(time.Duration(0))
zero := commonconfig.MustNewDuration(time.Duration(0))
evmCfg := configtest.NewGeneralConfig(t, func(c *chainlink.Config, s *chainlink.Secrets) {
c.EVM[0].Chain.Transactions.ReaperInterval = zero
c.EVM[0].Chain.Transactions.ReaperThreshold = zero
Expand Down
6 changes: 3 additions & 3 deletions core/chains/evm/txmgr/resender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"github.com/stretchr/testify/require"
"go.uber.org/zap/zapcore"

commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config"
"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink-common/pkg/sqlutil"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/toml"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/txmgr"
ubig "github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils/big"
Expand Down Expand Up @@ -106,7 +106,7 @@ func Test_EthResender_alertUnconfirmed(t *testing.T) {
ethKeyStore := cltest.NewKeyStore(t, db, logCfg).Eth()
ethClient := evmtest.NewEthClientMockWithDefaultChain(t)
// Set this to the smallest non-zero value possible for the attempt to be eligible for resend
delay := sqlutil.MustNewDuration(1 * time.Nanosecond)
delay := commonconfig.MustNewDuration(1 * time.Nanosecond)
cfg := configtest.NewGeneralConfig(t, func(c *chainlink.Config, s *chainlink.Secrets) {
c.EVM[0] = &toml.EVMConfig{
Chain: toml.Defaults(ubig.New(big.NewInt(0)), &toml.Chain{
Expand Down Expand Up @@ -144,7 +144,7 @@ func Test_EthResender_Start(t *testing.T) {
db := pgtest.NewSqlxDB(t)
cfg := configtest.NewGeneralConfig(t, func(c *chainlink.Config, s *chainlink.Secrets) {
// This can be anything as long as it isn't zero
c.EVM[0].Transactions.ResendAfterThreshold = sqlutil.MustNewDuration(42 * time.Hour)
c.EVM[0].Transactions.ResendAfterThreshold = commonconfig.MustNewDuration(42 * time.Hour)
// Set batch size low to test batching
c.EVM[0].RPCDefaultBatchSize = ptr[uint32](1)
})
Expand Down
6 changes: 3 additions & 3 deletions core/cmd/evm_transaction_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/urfave/cli"

"github.com/smartcontractkit/chainlink-common/pkg/sqlutil"
commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/txmgr"
evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
Expand Down Expand Up @@ -151,7 +151,7 @@ func TestShell_SendEther_From_Txm(t *testing.T) {

// NOTE: FallbackPollInterval is used in this test to quickly create TxAttempts
// Testing triggers requires committing transactions and does not work with transactional tests
c.Database.Listener.FallbackPollInterval = sqlutil.MustNewDuration(time.Second)
c.Database.Listener.FallbackPollInterval = commonconfig.MustNewDuration(time.Second)
},
withKey(),
withMocks(ethMock, key),
Expand Down Expand Up @@ -217,7 +217,7 @@ func TestShell_SendEther_From_Txm_WEI(t *testing.T) {

// NOTE: FallbackPollInterval is used in this test to quickly create TxAttempts
// Testing triggers requires committing transactions and does not work with transactional tests
c.Database.Listener.FallbackPollInterval = sqlutil.MustNewDuration(time.Second)
c.Database.Listener.FallbackPollInterval = commonconfig.MustNewDuration(time.Second)
},
withKey(),
withMocks(ethMock, key),
Expand Down
6 changes: 3 additions & 3 deletions core/cmd/jobs_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/urfave/cli"

"github.com/smartcontractkit/chainlink-common/pkg/sqlutil"
commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config"
"github.com/smartcontractkit/chainlink/v2/core/cmd"
"github.com/smartcontractkit/chainlink/v2/core/internal/cltest"
"github.com/smartcontractkit/chainlink/v2/core/services/chainlink"
Expand Down Expand Up @@ -368,7 +368,7 @@ func TestShell_CreateJobV2(t *testing.T) {
t.Parallel()

app := startNewApplicationV2(t, func(c *chainlink.Config, s *chainlink.Secrets) {
c.Database.Listener.FallbackPollInterval = sqlutil.MustNewDuration(100 * time.Millisecond)
c.Database.Listener.FallbackPollInterval = commonconfig.MustNewDuration(100 * time.Millisecond)
c.OCR.Enabled = ptr(true)
c.P2P.V2.Enabled = ptr(true)
c.P2P.V2.ListenAddresses = &[]string{fmt.Sprintf("127.0.0.1:%d", freeport.GetOne(t))}
Expand Down Expand Up @@ -406,7 +406,7 @@ func TestShell_DeleteJob(t *testing.T) {
t.Parallel()

app := startNewApplicationV2(t, func(c *chainlink.Config, s *chainlink.Secrets) {
c.Database.Listener.FallbackPollInterval = sqlutil.MustNewDuration(100 * time.Millisecond)
c.Database.Listener.FallbackPollInterval = commonconfig.MustNewDuration(100 * time.Millisecond)
c.EVM[0].Enabled = ptr(true)
c.EVM[0].NonceAutoSync = ptr(false)
c.EVM[0].BalanceMonitor.Enabled = ptr(false)
Expand Down
4 changes: 2 additions & 2 deletions core/cmd/shell_remote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/urfave/cli"

"github.com/smartcontractkit/chainlink-common/pkg/sqlutil"
commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config"
"github.com/smartcontractkit/chainlink/v2/core/auth"
"github.com/smartcontractkit/chainlink/v2/core/bridges"
evmclimocks "github.com/smartcontractkit/chainlink/v2/core/chains/evm/client/mocks"
Expand Down Expand Up @@ -60,7 +60,7 @@ func startNewApplicationV2(t *testing.T, overrideFn func(c *chainlink.Config, s
}

config := configtest.NewGeneralConfig(t, func(c *chainlink.Config, s *chainlink.Secrets) {
c.JobPipeline.HTTPRequest.DefaultTimeout = sqlutil.MustNewDuration(30 * time.Millisecond)
c.JobPipeline.HTTPRequest.DefaultTimeout = commonconfig.MustNewDuration(30 * time.Millisecond)
f := false
c.EVM[0].Enabled = &f
c.P2P.V2.Enabled = &f
Expand Down
14 changes: 7 additions & 7 deletions core/internal/features/features_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
"go.uber.org/zap/zaptest/observer"
"gopkg.in/guregu/null.v4"

"github.com/smartcontractkit/chainlink-common/pkg/sqlutil"
commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config"
ocrcommontypes "github.com/smartcontractkit/libocr/commontypes"
"github.com/smartcontractkit/libocr/gethwrappers/offchainaggregator"
"github.com/smartcontractkit/libocr/gethwrappers/testoffchainaggregator"
Expand Down Expand Up @@ -86,7 +86,7 @@ func TestIntegration_ExternalInitiatorV2(t *testing.T) {

cfg := configtest.NewGeneralConfig(t, func(c *chainlink.Config, s *chainlink.Secrets) {
c.JobPipeline.ExternalInitiatorsEnabled = ptr(true)
c.Database.Listener.FallbackPollInterval = sqlutil.MustNewDuration(10 * time.Millisecond)
c.Database.Listener.FallbackPollInterval = commonconfig.MustNewDuration(10 * time.Millisecond)
})

app := cltest.NewApplicationWithConfig(t, cfg, ethClient, cltest.UseRealExternalInitiatorManager)
Expand Down Expand Up @@ -363,7 +363,7 @@ func TestIntegration_DirectRequest(t *testing.T) {
// Simulate a consumer contract calling to obtain ETH quotes in 3 different currencies
// in a single callback.
config := configtest.NewGeneralConfigSimulated(t, func(c *chainlink.Config, s *chainlink.Secrets) {
c.Database.Listener.FallbackPollInterval = sqlutil.MustNewDuration(100 * time.Millisecond)
c.Database.Listener.FallbackPollInterval = commonconfig.MustNewDuration(100 * time.Millisecond)
c.EVM[0].GasEstimator.EIP1559DynamicFees = ptr(true)
})
operatorContracts := setupOperatorContracts(t)
Expand Down Expand Up @@ -468,7 +468,7 @@ func setupAppForEthTx(t *testing.T, operatorContracts OperatorContracts) (app *c
lggr, o := logger.TestLoggerObserved(t, zapcore.DebugLevel)

cfg := configtest.NewGeneralConfigSimulated(t, func(c *chainlink.Config, s *chainlink.Secrets) {
c.Database.Listener.FallbackPollInterval = sqlutil.MustNewDuration(100 * time.Millisecond)
c.Database.Listener.FallbackPollInterval = commonconfig.MustNewDuration(100 * time.Millisecond)
})
app = cltest.NewApplicationWithConfigV2AndKeyOnSimulatedBlockchain(t, cfg, b, lggr)
b.Commit()
Expand Down Expand Up @@ -690,10 +690,10 @@ func setupNode(t *testing.T, owner *bind.TransactOpts, portV2 int,

c.P2P.V2.Enabled = ptr(true)
c.P2P.V2.ListenAddresses = &[]string{fmt.Sprintf("127.0.0.1:%d", portV2)}
c.P2P.V2.DeltaReconcile = sqlutil.MustNewDuration(5 * time.Second)
c.P2P.V2.DeltaReconcile = commonconfig.MustNewDuration(5 * time.Second)

// GracePeriod < ObservationTimeout
c.EVM[0].OCR.ObservationGracePeriod = sqlutil.MustNewDuration(100 * time.Millisecond)
c.EVM[0].OCR.ObservationGracePeriod = commonconfig.MustNewDuration(100 * time.Millisecond)

if overrides != nil {
overrides(c, s)
Expand Down Expand Up @@ -733,7 +733,7 @@ func setupForwarderEnabledNode(t *testing.T, owner *bind.TransactOpts, portV2 in
c.P2P.PeerID = ptr(p2pKey.PeerID())
c.P2P.V2.Enabled = ptr(true)
c.P2P.V2.ListenAddresses = &[]string{fmt.Sprintf("127.0.0.1:%d", portV2)}
c.P2P.V2.DeltaReconcile = sqlutil.MustNewDuration(5 * time.Second)
c.P2P.V2.DeltaReconcile = commonconfig.MustNewDuration(5 * time.Second)

c.EVM[0].Transactions.ForwardersEnabled = ptr(true)

Expand Down
8 changes: 4 additions & 4 deletions core/internal/features/ocr2/features_ocr2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/smartcontractkit/chainlink-common/pkg/sqlutil"
"io"
"maps"
"math/big"
Expand Down Expand Up @@ -35,6 +34,7 @@ import (
confighelper2 "github.com/smartcontractkit/libocr/offchainreporting2plus/confighelper"
ocrtypes2 "github.com/smartcontractkit/libocr/offchainreporting2plus/types"

commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config"
"github.com/smartcontractkit/chainlink/v2/core/bridges"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/forwarders"
Expand Down Expand Up @@ -121,14 +121,14 @@ func setupNodeOCR2(

c.P2P.PeerID = ptr(p2pKey.PeerID())
c.P2P.V2.Enabled = ptr(true)
c.P2P.V2.DeltaDial = sqlutil.MustNewDuration(500 * time.Millisecond)
c.P2P.V2.DeltaReconcile = sqlutil.MustNewDuration(5 * time.Second)
c.P2P.V2.DeltaDial = commonconfig.MustNewDuration(500 * time.Millisecond)
c.P2P.V2.DeltaReconcile = commonconfig.MustNewDuration(5 * time.Second)
c.P2P.V2.ListenAddresses = &[]string{fmt.Sprintf("127.0.0.1:%d", port)}
if len(p2pV2Bootstrappers) > 0 {
c.P2P.V2.DefaultBootstrappers = &p2pV2Bootstrappers
}

c.EVM[0].LogPollInterval = sqlutil.MustNewDuration(5 * time.Second)
c.EVM[0].LogPollInterval = commonconfig.MustNewDuration(5 * time.Second)
c.EVM[0].Transactions.ForwardersEnabled = &useForwarder
})

Expand Down
10 changes: 5 additions & 5 deletions core/internal/testutils/configtest/general_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink-common/pkg/sqlutil"
commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/client"
evmclient "github.com/smartcontractkit/chainlink/v2/core/chains/evm/client"
evmcfg "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/toml"
Expand Down Expand Up @@ -46,20 +46,20 @@ func overrides(c *chainlink.Config, s *chainlink.Secrets) {

c.Insecure.OCRDevelopmentMode = ptr(true)
c.InsecureFastScrypt = ptr(true)
c.ShutdownGracePeriod = sqlutil.MustNewDuration(testutils.DefaultWaitTimeout)
c.ShutdownGracePeriod = commonconfig.MustNewDuration(testutils.DefaultWaitTimeout)

c.Database.Dialect = dialects.TransactionWrappedPostgres
c.Database.Lock.Enabled = ptr(false)
c.Database.MaxIdleConns = ptr[int64](20)
c.Database.MaxOpenConns = ptr[int64](20)
c.Database.MigrateOnStartup = ptr(false)
c.Database.DefaultLockTimeout = sqlutil.MustNewDuration(1 * time.Minute)
c.Database.DefaultLockTimeout = commonconfig.MustNewDuration(1 * time.Minute)

c.JobPipeline.ReaperInterval = sqlutil.MustNewDuration(0)
c.JobPipeline.ReaperInterval = commonconfig.MustNewDuration(0)

c.P2P.V2.Enabled = ptr(false)

c.WebServer.SessionTimeout = sqlutil.MustNewDuration(2 * time.Minute)
c.WebServer.SessionTimeout = commonconfig.MustNewDuration(2 * time.Minute)
c.WebServer.BridgeResponseURL = models.MustParseURL("http://localhost:6688")
testIP := net.ParseIP("127.0.0.1")
c.WebServer.ListenIP = &testIP
Expand Down
Loading

0 comments on commit 365c127

Please sign in to comment.