Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core/services/keystore: switch to sqlutil.DataStore #12810

Merged
merged 1 commit into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/lucky-ghosts-give.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": patch
---

core/services/keystore: switch to sqlutil.DataStore #internal
2 changes: 1 addition & 1 deletion core/chains/evm/log/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func newBroadcasterHelperWithEthClient(t *testing.T, ethClient evmclient.Client,
db := pgtest.NewSqlxDB(t)
orm := log.NewORM(db, cltest.FixtureChainID)
lb := log.NewTestBroadcaster(orm, ethClient, config.EVM(), lggr, highestSeenHead, mailMon)
kst := cltest.NewKeyStore(t, db, globalConfig.Database())
kst := cltest.NewKeyStore(t, db)

cc := evmtest.NewChainRelayExtenders(t, evmtest.TestChainOpts{
Client: ethClient,
Expand Down
7 changes: 2 additions & 5 deletions core/chains/evm/log/orm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/log"
"github.com/smartcontractkit/chainlink/v2/core/internal/cltest"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/configtest"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/pgtest"
)

func TestORM_broadcasts(t *testing.T) {
db := pgtest.NewSqlxDB(t)
cfg := configtest.NewGeneralConfig(t, nil)
ethKeyStore := cltest.NewKeyStore(t, db, cfg.Database()).Eth()
ethKeyStore := cltest.NewKeyStore(t, db).Eth()

orm := log.NewORM(db, cltest.FixtureChainID)

Expand Down Expand Up @@ -108,8 +106,7 @@ func TestORM_pending(t *testing.T) {
func TestORM_MarkUnconsumed(t *testing.T) {
ctx := testutils.Context(t)
db := pgtest.NewSqlxDB(t)
cfg := configtest.NewGeneralConfig(t, nil)
ethKeyStore := cltest.NewKeyStore(t, db, cfg.Database()).Eth()
ethKeyStore := cltest.NewKeyStore(t, db).Eth()

orm := log.NewORM(db, cltest.FixtureChainID)

Expand Down
18 changes: 6 additions & 12 deletions core/chains/evm/monitor/balance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/monitor"
"github.com/smartcontractkit/chainlink/v2/core/internal/cltest"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/configtest"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/pgtest"
)

Expand All @@ -35,11 +34,9 @@ func newEthClientMock(t *testing.T) *evmclimocks.Client {
func TestBalanceMonitor_Start(t *testing.T) {
t.Parallel()

cfg := configtest.NewGeneralConfig(t, nil)

t.Run("updates balance from nil for multiple keys", func(t *testing.T) {
db := pgtest.NewSqlxDB(t)
ethKeyStore := cltest.NewKeyStore(t, db, cfg.Database()).Eth()
ethKeyStore := cltest.NewKeyStore(t, db).Eth()
ethClient := newEthClientMock(t)
_, k1Addr := cltest.MustInsertRandomKey(t, ethKeyStore)
_, k0Addr := cltest.MustInsertRandomKey(t, ethKeyStore)
Expand All @@ -66,7 +63,7 @@ func TestBalanceMonitor_Start(t *testing.T) {

t.Run("handles nil head", func(t *testing.T) {
db := pgtest.NewSqlxDB(t)
ethKeyStore := cltest.NewKeyStore(t, db, cfg.Database()).Eth()
ethKeyStore := cltest.NewKeyStore(t, db).Eth()
ethClient := newEthClientMock(t)

_, k0Addr := cltest.MustInsertRandomKey(t, ethKeyStore)
Expand All @@ -85,7 +82,7 @@ func TestBalanceMonitor_Start(t *testing.T) {

t.Run("cancelled context", func(t *testing.T) {
db := pgtest.NewSqlxDB(t)
ethKeyStore := cltest.NewKeyStore(t, db, cfg.Database()).Eth()
ethKeyStore := cltest.NewKeyStore(t, db).Eth()
ethClient := newEthClientMock(t)

_, k0Addr := cltest.MustInsertRandomKey(t, ethKeyStore)
Expand Down Expand Up @@ -114,7 +111,7 @@ func TestBalanceMonitor_Start(t *testing.T) {

t.Run("recovers on error", func(t *testing.T) {
db := pgtest.NewSqlxDB(t)
ethKeyStore := cltest.NewKeyStore(t, db, cfg.Database()).Eth()
ethKeyStore := cltest.NewKeyStore(t, db).Eth()
ethClient := newEthClientMock(t)

_, k0Addr := cltest.MustInsertRandomKey(t, ethKeyStore)
Expand All @@ -136,11 +133,9 @@ func TestBalanceMonitor_Start(t *testing.T) {
func TestBalanceMonitor_OnNewLongestChain_UpdatesBalance(t *testing.T) {
t.Parallel()

cfg := configtest.NewGeneralConfig(t, nil)

t.Run("updates balance for multiple keys", func(t *testing.T) {
db := pgtest.NewSqlxDB(t)
ethKeyStore := cltest.NewKeyStore(t, db, cfg.Database()).Eth()
ethKeyStore := cltest.NewKeyStore(t, db).Eth()
ethClient := newEthClientMock(t)

_, k0Addr := cltest.MustInsertRandomKey(t, ethKeyStore)
Expand Down Expand Up @@ -190,8 +185,7 @@ func TestBalanceMonitor_FewerRPCCallsWhenBehind(t *testing.T) {
t.Parallel()

db := pgtest.NewSqlxDB(t)
cfg := configtest.NewGeneralConfig(t, nil)
ethKeyStore := cltest.NewKeyStore(t, db, cfg.Database()).Eth()
ethKeyStore := cltest.NewKeyStore(t, db).Eth()

cltest.MustInsertRandomKey(t, ethKeyStore)

Expand Down
36 changes: 18 additions & 18 deletions core/chains/evm/txmgr/broadcaster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func TestEthBroadcaster_Lifecycle(t *testing.T) {
txStore := cltest.NewTestTxStore(t, db)
evmcfg := evmtest.NewChainScopedConfig(t, cfg)
ethClient := evmtest.NewEthClientMockWithDefaultChain(t)
ethKeyStore := cltest.NewKeyStore(t, db, cfg.Database()).Eth()
ethKeyStore := cltest.NewKeyStore(t, db).Eth()
cltest.MustInsertRandomKeyReturningState(t, ethKeyStore)
estimator := gasmocks.NewEvmFeeEstimator(t)
txBuilder := txmgr.NewEvmTxAttemptBuilder(*ethClient.ConfiguredChainID(), evmcfg.EVM().GasEstimator(), ethKeyStore, estimator)
Expand Down Expand Up @@ -139,7 +139,7 @@ func TestEthBroadcaster_LoadNextSequenceMapFailure_StartupSuccess(t *testing.T)
txStore := cltest.NewTestTxStore(t, db)
evmcfg := evmtest.NewChainScopedConfig(t, cfg)
ethClient := evmtest.NewEthClientMockWithDefaultChain(t)
ethKeyStore := cltest.NewKeyStore(t, db, cfg.Database()).Eth()
ethKeyStore := cltest.NewKeyStore(t, db).Eth()
cltest.MustInsertRandomKeyReturningState(t, ethKeyStore)
estimator := gasmocks.NewEvmFeeEstimator(t)
txBuilder := txmgr.NewEvmTxAttemptBuilder(*ethClient.ConfiguredChainID(), evmcfg.EVM().GasEstimator(), ethKeyStore, estimator)
Expand Down Expand Up @@ -170,7 +170,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Success(t *testing.T) {
cfg := configtest.NewTestGeneralConfig(t)
ctx := testutils.Context(t)
txStore := cltest.NewTestTxStore(t, db)
ethKeyStore := cltest.NewKeyStore(t, db, cfg.Database()).Eth()
ethKeyStore := cltest.NewKeyStore(t, db).Eth()
_, fromAddress := cltest.MustInsertRandomKey(t, ethKeyStore)
_, otherAddress := cltest.MustInsertRandomKey(t, ethKeyStore)

Expand Down Expand Up @@ -525,7 +525,7 @@ func TestEthBroadcaster_TransmitChecking(t *testing.T) {
cfg := configtest.NewTestGeneralConfig(t)
ctx := testutils.Context(t)
txStore := cltest.NewTestTxStore(t, db)
ethKeyStore := cltest.NewKeyStore(t, db, cfg.Database()).Eth()
ethKeyStore := cltest.NewKeyStore(t, db).Eth()
_, fromAddress := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore)

ethClient := evmtest.NewEthClientMockWithDefaultChain(t)
Expand Down Expand Up @@ -611,7 +611,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_OptimisticLockingOnEthTx(t *testi
ccfg := evmtest.NewChainScopedConfig(t, cfg)
evmcfg := txmgr.NewEvmTxmConfig(ccfg.EVM())
ethClient := evmtest.NewEthClientMockWithDefaultChain(t)
ethKeyStore := cltest.NewKeyStore(t, db, cfg.Database()).Eth()
ethKeyStore := cltest.NewKeyStore(t, db).Eth()
_, fromAddress := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore)
estimator := gasmocks.NewEvmFeeEstimator(t)
txBuilder := txmgr.NewEvmTxAttemptBuilder(*ethClient.ConfiguredChainID(), ccfg.EVM().GasEstimator(), ethKeyStore, estimator)
Expand Down Expand Up @@ -674,7 +674,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Success_WithMultiplier(t *testing
})
txStore := cltest.NewTestTxStore(t, db)

ethKeyStore := cltest.NewKeyStore(t, db, cfg.Database()).Eth()
ethKeyStore := cltest.NewKeyStore(t, db).Eth()
_, fromAddress := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore)

evmcfg := evmtest.NewChainScopedConfig(t, cfg)
Expand Down Expand Up @@ -723,7 +723,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_ResumingFromCrash(t *testing.T) {
db := pgtest.NewSqlxDB(t)
txStore := cltest.NewTestTxStore(t, db)

ethKeyStore := cltest.NewKeyStore(t, db, cfg.Database()).Eth()
ethKeyStore := cltest.NewKeyStore(t, db).Eth()
_, fromAddress := cltest.RandomKey{Nonce: nextNonce.Int64()}.MustInsertWithState(t, ethKeyStore)

firstInProgress := txmgr.Tx{
Expand Down Expand Up @@ -758,7 +758,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_ResumingFromCrash(t *testing.T) {
db := pgtest.NewSqlxDB(t)
txStore := cltest.NewTestTxStore(t, db)

ethKeyStore := cltest.NewKeyStore(t, db, cfg.Database()).Eth()
ethKeyStore := cltest.NewKeyStore(t, db).Eth()
_, fromAddress := cltest.RandomKey{Nonce: nextNonce.Int64()}.MustInsertWithState(t, ethKeyStore)

ethClient := evmtest.NewEthClientMockWithDefaultChain(t)
Expand Down Expand Up @@ -797,7 +797,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_ResumingFromCrash(t *testing.T) {
db := pgtest.NewSqlxDB(t)
txStore := cltest.NewTestTxStore(t, db)

ethKeyStore := cltest.NewKeyStore(t, db, cfg.Database()).Eth()
ethKeyStore := cltest.NewKeyStore(t, db).Eth()
_, fromAddress := cltest.RandomKey{Nonce: nextNonce.Int64()}.MustInsertWithState(t, ethKeyStore)

ethClient := evmtest.NewEthClientMockWithDefaultChain(t)
Expand Down Expand Up @@ -834,7 +834,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_ResumingFromCrash(t *testing.T) {
db := pgtest.NewSqlxDB(t)
txStore := cltest.NewTestTxStore(t, db)

ethKeyStore := cltest.NewKeyStore(t, db, cfg.Database()).Eth()
ethKeyStore := cltest.NewKeyStore(t, db).Eth()
_, fromAddress := cltest.RandomKey{Nonce: nextNonce.Int64()}.MustInsertWithState(t, ethKeyStore)

ethClient := evmtest.NewEthClientMockWithDefaultChain(t)
Expand Down Expand Up @@ -870,7 +870,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_ResumingFromCrash(t *testing.T) {
db := pgtest.NewSqlxDB(t)
txStore := cltest.NewTestTxStore(t, db)

ethKeyStore := cltest.NewKeyStore(t, db, cfg.Database()).Eth()
ethKeyStore := cltest.NewKeyStore(t, db).Eth()
_, fromAddress := cltest.RandomKey{Nonce: nextNonce.Int64()}.MustInsertWithState(t, ethKeyStore)

ethClient := evmtest.NewEthClientMockWithDefaultChain(t)
Expand Down Expand Up @@ -908,7 +908,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_ResumingFromCrash(t *testing.T) {
db := pgtest.NewSqlxDB(t)
txStore := cltest.NewTestTxStore(t, db)

ethKeyStore := cltest.NewKeyStore(t, db, cfg.Database()).Eth()
ethKeyStore := cltest.NewKeyStore(t, db).Eth()
_, fromAddress := cltest.RandomKey{Nonce: nextNonce.Int64()}.MustInsertWithState(t, ethKeyStore)

ethClient := evmtest.NewEthClientMockWithDefaultChain(t)
Expand Down Expand Up @@ -944,7 +944,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_ResumingFromCrash(t *testing.T) {
db := pgtest.NewSqlxDB(t)
txStore := cltest.NewTestTxStore(t, db)

ethKeyStore := cltest.NewKeyStore(t, db, cfg.Database()).Eth()
ethKeyStore := cltest.NewKeyStore(t, db).Eth()
_, fromAddress := cltest.RandomKey{Nonce: nextNonce.Int64()}.MustInsertWithState(t, ethKeyStore)

cfg := configtest.NewGeneralConfig(t, func(c *chainlink.Config, s *chainlink.Secrets) {
Expand Down Expand Up @@ -1013,7 +1013,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Errors(t *testing.T) {
cfg := configtest.NewTestGeneralConfig(t)
txStore := cltest.NewTestTxStore(t, db)

ethKeyStore := cltest.NewKeyStore(t, db, cfg.Database()).Eth()
ethKeyStore := cltest.NewKeyStore(t, db).Eth()
_, fromAddress := cltest.MustInsertRandomKey(t, ethKeyStore)

evmcfg := evmtest.NewChainScopedConfig(t, cfg)
Expand Down Expand Up @@ -1655,7 +1655,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_KeystoreErrors(t *testing.T) {
cfg := configtest.NewGeneralConfig(t, nil)
txStore := cltest.NewTestTxStore(t, db)

realKeystore := cltest.NewKeyStore(t, db, cfg.Database())
realKeystore := cltest.NewKeyStore(t, db)
_, fromAddress := cltest.MustInsertRandomKeyReturningState(t, realKeystore.Eth())

evmcfg := evmtest.NewChainScopedConfig(t, cfg)
Expand Down Expand Up @@ -1712,7 +1712,7 @@ func TestEthBroadcaster_Trigger(t *testing.T) {
cfg := configtest.NewGeneralConfig(t, nil)
txStore := cltest.NewTestTxStore(t, db)
evmcfg := evmtest.NewChainScopedConfig(t, cfg)
ethKeyStore := cltest.NewKeyStore(t, db, cfg.Database()).Eth()
ethKeyStore := cltest.NewKeyStore(t, db).Eth()
ethClient := evmtest.NewEthClientMockWithDefaultChain(t)
lggr := logger.Test(t)
nonceTracker := txmgr.NewNonceTracker(lggr, txStore, txmgr.NewEvmTxmClient(ethClient))
Expand All @@ -1735,7 +1735,7 @@ func TestEthBroadcaster_SyncNonce(t *testing.T) {
evmTxmCfg := txmgr.NewEvmTxmConfig(evmcfg.EVM())
txStore := cltest.NewTestTxStore(t, db)

kst := cltest.NewKeyStore(t, db, cfg.Database()).Eth()
kst := cltest.NewKeyStore(t, db).Eth()
_, fromAddress := cltest.RandomKey{Disabled: false}.MustInsertWithState(t, kst)

estimator := gas.NewEvmFeeEstimator(lggr, func(lggr logger.Logger) gas.EvmEstimator {
Expand Down Expand Up @@ -1770,7 +1770,7 @@ func TestEthBroadcaster_NonceTracker_InProgressTx(t *testing.T) {
db := pgtest.NewSqlxDB(t)
cfg := configtest.NewTestGeneralConfig(t)
txStore := cltest.NewTestTxStore(t, db)
ethKeyStore := cltest.NewKeyStore(t, db, cfg.Database()).Eth()
ethKeyStore := cltest.NewKeyStore(t, db).Eth()
_, fromAddress := cltest.MustInsertRandomKey(t, ethKeyStore)

ethClient := evmtest.NewEthClientMockWithDefaultChain(t)
Expand Down
Loading
Loading