Skip to content

Commit

Permalink
Add DataSource to ChainOpts and pass to newChain
Browse files Browse the repository at this point in the history
  • Loading branch information
reductionista committed Nov 8, 2024
1 parent 970b557 commit 9be5b57
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
10 changes: 7 additions & 3 deletions pkg/solana/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (

"github.com/smartcontractkit/chainlink-common/pkg/chains"
"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink-common/pkg/loop"
"github.com/smartcontractkit/chainlink-common/pkg/services"
"github.com/smartcontractkit/chainlink-common/pkg/sqlutil"
"github.com/smartcontractkit/chainlink-common/pkg/types"
"github.com/smartcontractkit/chainlink-common/pkg/types/core"
"github.com/smartcontractkit/chainlink-common/pkg/utils"
Expand Down Expand Up @@ -49,6 +49,7 @@ const DefaultRequestTimeout = 30 * time.Second
type ChainOpts struct {
Logger logger.Logger
KeyStore core.Keystore
DS sqlutil.DataSource
}

func (o *ChainOpts) Validate() (err error) {
Expand All @@ -61,6 +62,9 @@ func (o *ChainOpts) Validate() (err error) {
if o.KeyStore == nil {
err = errors.Join(err, required("KeyStore"))
}
if o.DS == nil {
err = errors.Join(err, required("DataSource"))
}
return
}

Expand All @@ -72,7 +76,7 @@ func NewChain(cfg *config.TOMLConfig, opts ChainOpts) (Chain, error) {
if !cfg.IsEnabled() {
return nil, fmt.Errorf("cannot create new chain with ID %s: chain is disabled", *cfg.ChainID)
}
c, err := newChain(*cfg.ChainID, cfg, opts.KeyStore, opts.Logger)
c, err := newChain(*cfg.ChainID, cfg, opts.KeyStore, opts.Logger, opts.DS)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -222,7 +226,7 @@ func (v *verifiedCachedClient) GetAccountInfoWithOpts(ctx context.Context, addr
return v.ReaderWriter.GetAccountInfoWithOpts(ctx, addr, opts)
}

func newChain(id string, cfg *config.TOMLConfig, ks loop.Keystore, lggr logger.Logger) (*chain, error) {
func newChain(id string, cfg *config.TOMLConfig, ks core.Keystore, lggr logger.Logger, ds sqlutil.DataSource) (*chain, error) {
lggr = logger.With(lggr, "chainID", id, "chain", "solana")
var ch = chain{
id: id,
Expand Down
16 changes: 9 additions & 7 deletions pkg/solana/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ import (
"github.com/gagliardetto/solana-go/programs/system"
"github.com/gagliardetto/solana-go/rpc"
"github.com/google/uuid"
"github.com/smartcontractkit/chainlink-common/pkg/config"
"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zapcore"

"github.com/smartcontractkit/chainlink-common/pkg/config"
"github.com/smartcontractkit/chainlink-common/pkg/logger"
sqlutilmocks "github.com/smartcontractkit/chainlink-common/pkg/sqlutil/mocks"
"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"

"github.com/smartcontractkit/chainlink-solana/pkg/solana/client"
mn "github.com/smartcontractkit/chainlink-solana/pkg/solana/client/multinode"
solcfg "github.com/smartcontractkit/chainlink-solana/pkg/solana/config"
Expand Down Expand Up @@ -282,7 +284,7 @@ func TestChain_Transact(t *testing.T) {
return sig[:]
}, nil)

c, err := newChain("localnet", cfg, mkey, lgr)
c, err := newChain("localnet", cfg, mkey, lgr, sqlutilmocks.NewDataSource(t))
require.NoError(t, err)
require.NoError(t, c.txm.Start(ctx))

Expand Down Expand Up @@ -356,7 +358,7 @@ func TestSolanaChain_MultiNode_GetClient(t *testing.T) {
},
}

testChain, err := newChain("devnet", cfg, nil, logger.Test(t))
testChain, err := newChain("devnet", cfg, nil, logger.Test(t), sqlutilmocks.NewDataSource(t))
require.NoError(t, err)

err = testChain.Start(tests.Context(t))
Expand Down Expand Up @@ -398,7 +400,7 @@ func TestChain_MultiNode_TransactionSender(t *testing.T) {

// mocked keystore
mkey := mocks.NewSimpleKeystore(t)
c, err := newChain("localnet", cfg, mkey, lgr)
c, err := newChain("localnet", cfg, mkey, lgr, sqlutilmocks.NewDataSource(t))
require.NoError(t, err)
require.NoError(t, c.Start(ctx))
defer func() {
Expand Down Expand Up @@ -516,7 +518,7 @@ func TestSolanaChain_MultiNode_Txm(t *testing.T) {
}, nil)
mkey.On("Sign", mock.Anything, pubKeyReceiver.String(), mock.Anything).Return([]byte{}, config.KeyNotFoundError{ID: pubKeyReceiver.String(), KeyType: "Solana"})

testChain, err := newChain("localnet", cfg, mkey, logger.Test(t))
testChain, err := newChain("localnet", cfg, mkey, logger.Test(t), sqlutilmocks.NewDataSource(t))
require.NoError(t, err)

err = testChain.Start(tests.Context(t))
Expand Down

0 comments on commit 9be5b57

Please sign in to comment.