Skip to content

Commit

Permalink
Extract core/store/models (#11626)
Browse files Browse the repository at this point in the history
* Extract URL

* tidy

* Extract duration tests

* Generate

* update imports

* Extract duration to common

* tidy

* fix imports

* tidy

* remove unused import

* Remove unused mock file

* fix imports

* Use commonconfig Duration

* Use commonconfig

* Use commonconfig

* Use MustNewDuration

* use commonconfig

* fix imports

* fix imports

* fmt

* Use common url

* fix imports
  • Loading branch information
DylanTinianov authored Jan 10, 2024
1 parent 6594979 commit ba841a5
Show file tree
Hide file tree
Showing 91 changed files with 564 additions and 1,071 deletions.
6 changes: 3 additions & 3 deletions core/chains/evm/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

configurl "github.com/smartcontractkit/chainlink-common/pkg/config"
commonconfig "github.com/smartcontractkit/chainlink/v2/common/config"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/toml"
Expand All @@ -21,7 +22,6 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/evmtest"
"github.com/smartcontractkit/chainlink/v2/core/services/chainlink"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/ethkey"
"github.com/smartcontractkit/chainlink/v2/core/store/models"
)

func TestChainScopedConfig(t *testing.T) {
Expand Down Expand Up @@ -383,8 +383,8 @@ func Test_chainScopedConfig_Validate(t *testing.T) {
c.EVM[0] = &toml.EVMConfig{ChainID: chainID, Enabled: ptr(true), Chain: toml.Defaults(chainID, chains...),
Nodes: toml.EVMNodes{{
Name: ptr("fake"),
WSURL: models.MustParseURL("wss://foo.test/ws"),
HTTPURL: models.MustParseURL("http://foo.test"),
WSURL: configurl.MustParseURL("wss://foo.test/ws"),
HTTPURL: configurl.MustParseURL("http://foo.test"),
}}}
})
}
Expand Down
31 changes: 15 additions & 16 deletions core/chains/evm/config/toml/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils/big"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/ethkey"
"github.com/smartcontractkit/chainlink/v2/core/store/models"
)

type HasEVMConfigs interface {
Expand Down Expand Up @@ -351,12 +350,12 @@ type Chain struct {
FlagsContractAddress *ethkey.EIP55Address
LinkContractAddress *ethkey.EIP55Address
LogBackfillBatchSize *uint32
LogPollInterval *models.Duration
LogPollInterval *commonconfig.Duration
LogKeepBlocksDepth *uint32
MinIncomingConfirmations *uint32
MinContractPayment *commonassets.Link
NonceAutoSync *bool
NoNewHeadsThreshold *models.Duration
NoNewHeadsThreshold *commonconfig.Duration
OperatorFactoryAddress *ethkey.EIP55Address
RPCDefaultBatchSize *uint32
RPCBlockQueryDelay *uint16
Expand Down Expand Up @@ -404,9 +403,9 @@ type Transactions struct {
ForwardersEnabled *bool
MaxInFlight *uint32
MaxQueued *uint32
ReaperInterval *models.Duration
ReaperThreshold *models.Duration
ResendAfterThreshold *models.Duration
ReaperInterval *commonconfig.Duration
ReaperThreshold *commonconfig.Duration
ResendAfterThreshold *commonconfig.Duration
}

func (t *Transactions) setFrom(f *Transactions) {
Expand Down Expand Up @@ -669,7 +668,7 @@ func (e *KeySpecificGasEstimator) setFrom(f *KeySpecificGasEstimator) {
type HeadTracker struct {
HistoryDepth *uint32
MaxBufferSize *uint32
SamplingInterval *models.Duration
SamplingInterval *commonconfig.Duration
}

func (t *HeadTracker) setFrom(f *HeadTracker) {
Expand All @@ -686,10 +685,10 @@ func (t *HeadTracker) setFrom(f *HeadTracker) {

type NodePool struct {
PollFailureThreshold *uint32
PollInterval *models.Duration
PollInterval *commonconfig.Duration
SelectionMode *string
SyncThreshold *uint32
LeaseDuration *models.Duration
LeaseDuration *commonconfig.Duration
}

func (p *NodePool) setFrom(f *NodePool) {
Expand All @@ -712,11 +711,11 @@ func (p *NodePool) setFrom(f *NodePool) {

type OCR struct {
ContractConfirmations *uint16
ContractTransmitterTransmitTimeout *models.Duration
DatabaseTimeout *models.Duration
DeltaCOverride *models.Duration
DeltaCJitterOverride *models.Duration
ObservationGracePeriod *models.Duration
ContractTransmitterTransmitTimeout *commonconfig.Duration
DatabaseTimeout *commonconfig.Duration
DeltaCOverride *commonconfig.Duration
DeltaCJitterOverride *commonconfig.Duration
ObservationGracePeriod *commonconfig.Duration
}

func (o *OCR) setFrom(f *OCR) {
Expand All @@ -742,8 +741,8 @@ func (o *OCR) setFrom(f *OCR) {

type Node struct {
Name *string
WSURL *models.URL
HTTPURL *models.URL
WSURL *commonconfig.URL
HTTPURL *commonconfig.URL
SendOnly *bool
Order *int32
}
Expand Down
4 changes: 2 additions & 2 deletions core/chains/evm/headtracker/head_broadcaster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"

commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config"
"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink-common/pkg/services/servicetest"
"github.com/smartcontractkit/chainlink-common/pkg/utils/mailbox/mailboxtest"
Expand All @@ -26,7 +27,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/store/models"
)

func waitHeadBroadcasterToStart(t *testing.T, hb types.HeadBroadcaster) {
Expand All @@ -46,7 +46,7 @@ func TestHeadBroadcaster_Subscribe(t *testing.T) {
g := gomega.NewWithT(t)

cfg := configtest.NewGeneralConfig(t, func(c *chainlink.Config, s *chainlink.Secrets) {
c.EVM[0].HeadTracker.SamplingInterval = &models.Duration{}
c.EVM[0].HeadTracker.SamplingInterval = &commonconfig.Duration{}
})
evmCfg := evmtest.NewChainScopedConfig(t, cfg)
db := pgtest.NewSqlxDB(t)
Expand Down
6 changes: 3 additions & 3 deletions core/chains/evm/headtracker/head_listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"

commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config"
"github.com/smartcontractkit/chainlink-common/pkg/logger"
commonmocks "github.com/smartcontractkit/chainlink/v2/common/types/mocks"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/headtracker"
Expand All @@ -21,7 +22,6 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/configtest"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/evmtest"
"github.com/smartcontractkit/chainlink/v2/core/services/chainlink"
"github.com/smartcontractkit/chainlink/v2/core/store/models"
)

func Test_HeadListener_HappyPath(t *testing.T) {
Expand All @@ -39,7 +39,7 @@ func Test_HeadListener_HappyPath(t *testing.T) {
ethClient := evmtest.NewEthClientMockWithDefaultChain(t)
cfg := configtest.NewGeneralConfig(t, func(c *chainlink.Config, s *chainlink.Secrets) {
// no need to test head timeouts here
c.EVM[0].NoNewHeadsThreshold = &models.Duration{}
c.EVM[0].NoNewHeadsThreshold = &commonconfig.Duration{}
})
evmcfg := evmtest.NewChainScopedConfig(t, cfg)
chStop := make(chan struct{})
Expand Down Expand Up @@ -100,7 +100,7 @@ func Test_HeadListener_NotReceivingHeads(t *testing.T) {
ethClient := evmtest.NewEthClientMockWithDefaultChain(t)

cfg := configtest.NewGeneralConfig(t, func(c *chainlink.Config, s *chainlink.Secrets) {
c.EVM[0].NoNewHeadsThreshold = models.MustNewDuration(time.Second)
c.EVM[0].NoNewHeadsThreshold = commonconfig.MustNewDuration(time.Second)
})
evmcfg := evmtest.NewChainScopedConfig(t, cfg)
chStop := make(chan struct{})
Expand Down
6 changes: 3 additions & 3 deletions core/chains/evm/headtracker/head_tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ 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/utils/mailbox"
Expand All @@ -38,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/store/models"
)

func firstHead(t *testing.T, db *sqlx.DB) (h evmtypes.Head) {
Expand Down Expand Up @@ -426,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 = models.MustNewDuration(2500 * time.Millisecond)
c.EVM[0].HeadTracker.SamplingInterval = commonconfig.MustNewDuration(2500 * time.Millisecond)
})

ethClient := evmtest.NewEthClientMockWithDefaultChain(t)
Expand Down Expand Up @@ -554,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 = models.MustNewDuration(0)
c.EVM[0].HeadTracker.SamplingInterval = commonconfig.MustNewDuration(0)
})

ethClient := evmtest.NewEthClientMockWithDefaultChain(t)
Expand Down
4 changes: 2 additions & 2 deletions core/chains/evm/txmgr/evm_tx_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"testing"
"time"

commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config"
"github.com/smartcontractkit/chainlink-common/pkg/logger"
txmgrcommon "github.com/smartcontractkit/chainlink/v2/common/txmgr"
txmgrtypes "github.com/smartcontractkit/chainlink/v2/common/txmgr/types"
Expand All @@ -23,7 +24,6 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/services/chainlink"
"github.com/smartcontractkit/chainlink/v2/core/services/pg"
"github.com/smartcontractkit/chainlink/v2/core/services/pipeline"
"github.com/smartcontractkit/chainlink/v2/core/store/models"

"github.com/google/uuid"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -1379,7 +1379,7 @@ func TestORM_UpdateTxUnstartedToInProgress(t *testing.T) {
etx := mustInsertInProgressEthTxWithAttempt(t, txStore, nonce, fromAddress)
require.Len(t, etx.TxAttempts, 1)

zero := models.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,6 +13,7 @@ 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/v2/core/chains/evm/config/toml"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/txmgr"
Expand All @@ -23,7 +24,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/store/models"
)

func Test_EthResender_resendUnconfirmed(t *testing.T) {
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 := models.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 = models.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
10 changes: 5 additions & 5 deletions core/cmd/evm_node_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config"
evmcfg "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/toml"
"github.com/smartcontractkit/chainlink/v2/core/cmd"
"github.com/smartcontractkit/chainlink/v2/core/internal/cltest"
"github.com/smartcontractkit/chainlink/v2/core/services/chainlink"
"github.com/smartcontractkit/chainlink/v2/core/store/models"
)

func assertTableRenders(t *testing.T, r *cltest.RendererMock) {
Expand All @@ -31,15 +31,15 @@ func TestShell_IndexEVMNodes(t *testing.T) {
chainID := newRandChainID()
node1 := evmcfg.Node{
Name: ptr("Test node 1"),
WSURL: models.MustParseURL("ws://localhost:8546"),
HTTPURL: models.MustParseURL("http://localhost:8546"),
WSURL: commonconfig.MustParseURL("ws://localhost:8546"),
HTTPURL: commonconfig.MustParseURL("http://localhost:8546"),
SendOnly: ptr(false),
Order: ptr(int32(15)),
}
node2 := evmcfg.Node{
Name: ptr("Test node 2"),
WSURL: models.MustParseURL("ws://localhost:8547"),
HTTPURL: models.MustParseURL("http://localhost:8547"),
WSURL: commonconfig.MustParseURL("ws://localhost:8547"),
HTTPURL: commonconfig.MustParseURL("http://localhost:8547"),
SendOnly: ptr(false),
Order: ptr(int32(36)),
}
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,6 +12,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/urfave/cli"

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 All @@ -22,7 +23,6 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/pgtest"
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/services/chainlink"
"github.com/smartcontractkit/chainlink/v2/core/store/models"
)

func TestShell_IndexTransactions(t *testing.T) {
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 = models.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 = models.MustNewDuration(time.Second)
c.Database.Listener.FallbackPollInterval = commonconfig.MustNewDuration(time.Second)
},
withKey(),
withMocks(ethMock, key),
Expand Down
5 changes: 3 additions & 2 deletions core/cmd/jobs_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/urfave/cli"

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 @@ -367,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 = models.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 @@ -405,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 = models.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
9 changes: 5 additions & 4 deletions core/cmd/shell_local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"testing"
"time"

commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config"
"github.com/smartcontractkit/chainlink-common/pkg/utils/mailbox"

"github.com/smartcontractkit/chainlink/v2/common/client"
Expand Down Expand Up @@ -73,8 +74,8 @@ func TestShell_RunNodeWithPasswords(t *testing.T) {
cfg := configtest.NewGeneralConfig(t, func(c *chainlink.Config, s *chainlink.Secrets) {
s.Password.Keystore = models.NewSecret("dummy")
c.EVM[0].Nodes[0].Name = ptr("fake")
c.EVM[0].Nodes[0].HTTPURL = models.MustParseURL("http://fake.com")
c.EVM[0].Nodes[0].WSURL = models.MustParseURL("WSS://fake.com/ws")
c.EVM[0].Nodes[0].HTTPURL = commonconfig.MustParseURL("http://fake.com")
c.EVM[0].Nodes[0].WSURL = commonconfig.MustParseURL("WSS://fake.com/ws")
// seems to be needed for config validate
c.Insecure.OCRDevelopmentMode = nil
})
Expand Down Expand Up @@ -166,8 +167,8 @@ func TestShell_RunNodeWithAPICredentialsFile(t *testing.T) {
cfg := configtest.NewGeneralConfig(t, func(c *chainlink.Config, s *chainlink.Secrets) {
s.Password.Keystore = models.NewSecret("16charlengthp4SsW0rD1!@#_")
c.EVM[0].Nodes[0].Name = ptr("fake")
c.EVM[0].Nodes[0].WSURL = models.MustParseURL("WSS://fake.com/ws")
c.EVM[0].Nodes[0].HTTPURL = models.MustParseURL("http://fake.com")
c.EVM[0].Nodes[0].WSURL = commonconfig.MustParseURL("WSS://fake.com/ws")
c.EVM[0].Nodes[0].HTTPURL = commonconfig.MustParseURL("http://fake.com")
// seems to be needed for config validate
c.Insecure.OCRDevelopmentMode = nil
})
Expand Down
Loading

0 comments on commit ba841a5

Please sign in to comment.