diff --git a/core/capabilities/targets/write_target_test.go b/core/capabilities/targets/write_target_test.go index 9f7b6a2de2f..7f589e335d9 100644 --- a/core/capabilities/targets/write_target_test.go +++ b/core/capabilities/targets/write_target_test.go @@ -154,6 +154,7 @@ func TestWriteTarget(t *testing.T) { configGasLimit, err = values.NewMap(map[string]any{ "Address": forwarderAddr, }) + require.NoError(t, err) req = capabilities.CapabilityRequest{ Metadata: validMetadata, Config: configGasLimit, diff --git a/core/chains/evm/client/rpc_client_test.go b/core/chains/evm/client/rpc_client_test.go index eafbea5cd5f..07e097727a3 100644 --- a/core/chains/evm/client/rpc_client_test.go +++ b/core/chains/evm/client/rpc_client_test.go @@ -156,7 +156,6 @@ func TestRPCClient_SubscribeNewHead(t *testing.T) { }() wg.Wait() } - }) t.Run("Block's chain ID matched configured", func(t *testing.T) { server := testutils.NewWSServer(t, chainId, serverCallBack) diff --git a/core/chains/evm/gas/helpers_test.go b/core/chains/evm/gas/helpers_test.go index ae93d9e8c78..0c9a74a18dc 100644 --- a/core/chains/evm/gas/helpers_test.go +++ b/core/chains/evm/gas/helpers_test.go @@ -157,7 +157,7 @@ type MockGasEstimatorConfig struct { FeeCapDefaultF *assets.Wei LimitMaxF uint64 ModeF string - EstimateLimitF bool + EstimateLimitF bool } func NewMockGasConfig() *MockGasEstimatorConfig { diff --git a/core/internal/cltest/cltest.go b/core/internal/cltest/cltest.go index 371cada3307..23469cbb80c 100644 --- a/core/internal/cltest/cltest.go +++ b/core/internal/cltest/cltest.go @@ -212,7 +212,12 @@ type TestApplication struct { func NewApplicationEVMDisabled(t *testing.T) *TestApplication { t.Helper() - c := configtest.NewGeneralConfig(t, nil) + c := configtest.NewGeneralConfig(t, func(config *chainlink.Config, secrets *chainlink.Secrets) { + f := false + for _, c := range config.EVM { + c.Enabled = &f + } + }) return NewApplicationWithConfig(t, c) } diff --git a/core/services/feeds/orm.go b/core/services/feeds/orm.go index a49882ccf5f..82d1114a23d 100644 --- a/core/services/feeds/orm.go +++ b/core/services/feeds/orm.go @@ -9,9 +9,10 @@ import ( "github.com/google/uuid" "github.com/lib/pq" "github.com/pkg/errors" - "github.com/smartcontractkit/chainlink/v2/core/utils/crypto" "github.com/smartcontractkit/chainlink-common/pkg/sqlutil" + + "github.com/smartcontractkit/chainlink/v2/core/utils/crypto" ) type ORM interface { diff --git a/core/services/feeds/service_test.go b/core/services/feeds/service_test.go index 1dc9904fd51..9098d439eb2 100644 --- a/core/services/feeds/service_test.go +++ b/core/services/feeds/service_test.go @@ -374,6 +374,7 @@ func Test_Service_RegisterManager_DuplicateFeedsManager(t *testing.T) { var pubKeyHex = "0f17c3bf72de8beef6e2d17a14c0a972f5d7e0e66e70722373f12b88382d40f9" var pubKey crypto.PublicKey _, err := hex.Decode([]byte(pubKeyHex), pubKey) + require.NoError(t, err) var ( mgr = feeds.FeedsManager{ diff --git a/core/services/llo/data_source.go b/core/services/llo/data_source.go index 4f6e91675c5..3d265de2618 100644 --- a/core/services/llo/data_source.go +++ b/core/services/llo/data_source.go @@ -149,7 +149,7 @@ func (d *dataSource) Observe(ctx context.Context, streamValues llo.StreamValues, if opts.VerboseLogging() { successes := make([]streams.StreamID, 0, len(streamValues)) - for strmID, _ := range streamValues { + for strmID := range streamValues { successes = append(successes, strmID) } sort.Slice(successes, func(i, j int) bool { return successes[i] < successes[j] }) diff --git a/core/services/llo/evm/report_codec_premium_legacy.go b/core/services/llo/evm/report_codec_premium_legacy.go index a062f77b65f..da14aceab69 100644 --- a/core/services/llo/evm/report_codec_premium_legacy.go +++ b/core/services/llo/evm/report_codec_premium_legacy.go @@ -51,10 +51,7 @@ func (r *ReportFormatEVMPremiumLegacyOpts) Decode(opts []byte) error { // special case if opts are unspecified, just use the zero options rather than erroring return nil } - if err := json.Unmarshal(opts, r); err != nil { - return err - } - return nil + return json.Unmarshal(opts, r) } func (r ReportCodecPremiumLegacy) Encode(report llo.Report, cd llotypes.ChannelDefinition) ([]byte, error) { diff --git a/core/services/llo/onchain_channel_definition_cache.go b/core/services/llo/onchain_channel_definition_cache.go index 51cfae964d6..752dc3196e9 100644 --- a/core/services/llo/onchain_channel_definition_cache.go +++ b/core/services/llo/onchain_channel_definition_cache.go @@ -8,7 +8,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "maps" "math/big" "net/http" @@ -385,7 +384,7 @@ func (c *channelDefinitionCache) fetchChannelDefinitions(ctx context.Context, ur // logs with potentially huge messages body := http.MaxBytesReader(nil, reader, 1024) defer body.Close() - bodyBytes, err := ioutil.ReadAll(body) + bodyBytes, err := io.ReadAll(body) if err != nil { return nil, fmt.Errorf("got error from %s: (status code: %d, error reading response body: %w, response body: %s)", url, statusCode, err, bodyBytes) } diff --git a/core/services/llo/onchain_channel_definition_cache_test.go b/core/services/llo/onchain_channel_definition_cache_test.go index 5bd7eedbb1a..d2b976dddef 100644 --- a/core/services/llo/onchain_channel_definition_cache_test.go +++ b/core/services/llo/onchain_channel_definition_cache_test.go @@ -96,7 +96,6 @@ func makeDonIDTopic(donID uint32) []byte { func Test_ChannelDefinitionCache(t *testing.T) { donID := rand.Uint32() - ctx := tests.Context(t) t.Run("Definitions", func(t *testing.T) { // NOTE: this is covered more thoroughly in the integration tests @@ -277,11 +276,12 @@ func Test_ChannelDefinitionCache(t *testing.T) { } t.Run("nil ctx returns error", func(t *testing.T) { - _, err := cdc.fetchChannelDefinitions(nil, "notvalid://foos", [32]byte{}) + _, err := cdc.fetchChannelDefinitions(nil, "notvalid://foos", [32]byte{}) //nolint assert.EqualError(t, err, "failed to create http.Request; net/http: nil Context") }) t.Run("networking error while making request returns error", func(t *testing.T) { + ctx := tests.Context(t) c.resp = nil c.err = errors.New("http request failed") @@ -290,6 +290,7 @@ func Test_ChannelDefinitionCache(t *testing.T) { }) t.Run("server returns 500 returns error", func(t *testing.T) { + ctx := tests.Context(t) c.err = nil c.resp = &http.Response{StatusCode: 500, Body: io.NopCloser(bytes.NewReader([]byte{1, 2, 3}))} @@ -303,6 +304,7 @@ func Test_ChannelDefinitionCache(t *testing.T) { } t.Run("server returns 404 returns error (and does not log entirety of huge response body)", func(t *testing.T) { + ctx := tests.Context(t) c.err = nil c.resp = &http.Response{StatusCode: 404, Body: io.NopCloser(bytes.NewReader(largeBody))} @@ -314,6 +316,7 @@ func Test_ChannelDefinitionCache(t *testing.T) { c.resp.Body = io.NopCloser(bytes.NewReader(hugeBody)) t.Run("server returns body that is too large", func(t *testing.T) { + ctx := tests.Context(t) c.err = nil c.resp = &http.Response{StatusCode: 200, Body: io.NopCloser(bytes.NewReader(hugeBody))} @@ -322,6 +325,7 @@ func Test_ChannelDefinitionCache(t *testing.T) { }) t.Run("server returns invalid JSON returns error", func(t *testing.T) { + ctx := tests.Context(t) c.err = nil c.resp = &http.Response{StatusCode: 200, Body: io.NopCloser(bytes.NewReader([]byte{1, 2, 3}))} @@ -330,6 +334,7 @@ func Test_ChannelDefinitionCache(t *testing.T) { }) t.Run("SHA mismatch returns error", func(t *testing.T) { + ctx := tests.Context(t) c.err = nil c.resp = &http.Response{StatusCode: 200, Body: io.NopCloser(bytes.NewReader([]byte(`{"foo":"bar"}`)))} @@ -338,6 +343,7 @@ func Test_ChannelDefinitionCache(t *testing.T) { }) t.Run("valid JSON matching SHA returns channel definitions", func(t *testing.T) { + ctx := tests.Context(t) chainSelector := 4949039107694359620 // arbitrum mainnet feedID := [32]byte{00, 03, 107, 74, 167, 229, 124, 167, 182, 138, 225, 191, 69, 101, 63, 86, 182, 86, 253, 58, 163, 53, 239, 127, 174, 105, 107, 102, 63, 27, 132, 114} expirationWindow := 3600 @@ -363,7 +369,7 @@ func Test_ChannelDefinitionCache(t *testing.T) { cd, err := cdc.fetchChannelDefinitions(ctx, "http://example.com/definitions.json", common.HexToHash("0x367bbc75f7b6c9fc66a98ea99f837ea7ac4a3c2d6a9ee284de018bd02c41b52d")) assert.NoError(t, err) - assert.Equal(t, llotypes.ChannelDefinitions(llotypes.ChannelDefinitions{0x2a: llotypes.ChannelDefinition{ReportFormat: 0x1, Streams: []llotypes.Stream{llotypes.Stream{StreamID: 0x34, Aggregator: 0x1}, llotypes.Stream{StreamID: 0x35, Aggregator: 0x1}, llotypes.Stream{StreamID: 0x37, Aggregator: 0x3}}, Opts: llotypes.ChannelOpts{0x7b, 0x22, 0x62, 0x61, 0x73, 0x65, 0x55, 0x53, 0x44, 0x46, 0x65, 0x65, 0x22, 0x3a, 0x22, 0x31, 0x30, 0x22, 0x2c, 0x22, 0x65, 0x78, 0x70, 0x69, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x57, 0x69, 0x6e, 0x64, 0x6f, 0x77, 0x22, 0x3a, 0x33, 0x36, 0x30, 0x30, 0x2c, 0x22, 0x66, 0x65, 0x65, 0x64, 0x49, 0x64, 0x22, 0x3a, 0x22, 0x30, 0x78, 0x30, 0x30, 0x30, 0x33, 0x36, 0x62, 0x34, 0x61, 0x61, 0x37, 0x65, 0x35, 0x37, 0x63, 0x61, 0x37, 0x62, 0x36, 0x38, 0x61, 0x65, 0x31, 0x62, 0x66, 0x34, 0x35, 0x36, 0x35, 0x33, 0x66, 0x35, 0x36, 0x62, 0x36, 0x35, 0x36, 0x66, 0x64, 0x33, 0x61, 0x61, 0x33, 0x33, 0x35, 0x65, 0x66, 0x37, 0x66, 0x61, 0x65, 0x36, 0x39, 0x36, 0x62, 0x36, 0x36, 0x33, 0x66, 0x31, 0x62, 0x38, 0x34, 0x37, 0x32, 0x22, 0x2c, 0x22, 0x6d, 0x75, 0x6c, 0x74, 0x69, 0x70, 0x6c, 0x69, 0x65, 0x72, 0x22, 0x3a, 0x22, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x22, 0x7d}}}), cd) + assert.Equal(t, llotypes.ChannelDefinitions{0x2a: llotypes.ChannelDefinition{ReportFormat: 0x1, Streams: []llotypes.Stream{llotypes.Stream{StreamID: 0x34, Aggregator: 0x1}, llotypes.Stream{StreamID: 0x35, Aggregator: 0x1}, llotypes.Stream{StreamID: 0x37, Aggregator: 0x3}}, Opts: llotypes.ChannelOpts{0x7b, 0x22, 0x62, 0x61, 0x73, 0x65, 0x55, 0x53, 0x44, 0x46, 0x65, 0x65, 0x22, 0x3a, 0x22, 0x31, 0x30, 0x22, 0x2c, 0x22, 0x65, 0x78, 0x70, 0x69, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x57, 0x69, 0x6e, 0x64, 0x6f, 0x77, 0x22, 0x3a, 0x33, 0x36, 0x30, 0x30, 0x2c, 0x22, 0x66, 0x65, 0x65, 0x64, 0x49, 0x64, 0x22, 0x3a, 0x22, 0x30, 0x78, 0x30, 0x30, 0x30, 0x33, 0x36, 0x62, 0x34, 0x61, 0x61, 0x37, 0x65, 0x35, 0x37, 0x63, 0x61, 0x37, 0x62, 0x36, 0x38, 0x61, 0x65, 0x31, 0x62, 0x66, 0x34, 0x35, 0x36, 0x35, 0x33, 0x66, 0x35, 0x36, 0x62, 0x36, 0x35, 0x36, 0x66, 0x64, 0x33, 0x61, 0x61, 0x33, 0x33, 0x35, 0x65, 0x66, 0x37, 0x66, 0x61, 0x65, 0x36, 0x39, 0x36, 0x62, 0x36, 0x36, 0x33, 0x66, 0x31, 0x62, 0x38, 0x34, 0x37, 0x32, 0x22, 0x2c, 0x22, 0x6d, 0x75, 0x6c, 0x74, 0x69, 0x70, 0x6c, 0x69, 0x65, 0x72, 0x22, 0x3a, 0x22, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x22, 0x7d}}}, cd) }) }) @@ -384,6 +390,7 @@ func Test_ChannelDefinitionCache(t *testing.T) { } t.Run("does nothing if persisted version is up-to-date", func(t *testing.T) { + ctx := tests.Context(t) cdc.definitionsVersion = 42 cdc.persistedVersion = 42 @@ -398,6 +405,7 @@ func Test_ChannelDefinitionCache(t *testing.T) { cdc.orm = orm t.Run("returns error on db failure and does not update persisted version", func(t *testing.T) { + ctx := tests.Context(t) cdc.persistedVersion = 42 cdc.definitionsVersion = 43 orm.err = errors.New("test error") @@ -410,6 +418,7 @@ func Test_ChannelDefinitionCache(t *testing.T) { }) t.Run("updates persisted version on success", func(t *testing.T) { + ctx := tests.Context(t) cdc.definitionsVersion = 43 orm.err = nil diff --git a/core/services/ocr2/plugins/ccip/exportinternal.go b/core/services/ocr2/plugins/ccip/exportinternal.go index e6c41a28b20..aecf1a0b163 100644 --- a/core/services/ocr2/plugins/ccip/exportinternal.go +++ b/core/services/ocr2/plugins/ccip/exportinternal.go @@ -6,8 +6,8 @@ import ( "time" "github.com/ethereum/go-ethereum/common" - "github.com/smartcontractkit/chainlink-common/pkg/logger" + "github.com/smartcontractkit/chainlink-common/pkg/logger" "github.com/smartcontractkit/chainlink-common/pkg/types/ccip" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/client" diff --git a/core/services/ocr2/plugins/llo/integration_test.go b/core/services/ocr2/plugins/llo/integration_test.go index 4cebe3bf22c..f5c2869442a 100644 --- a/core/services/ocr2/plugins/llo/integration_test.go +++ b/core/services/ocr2/plugins/llo/integration_test.go @@ -43,7 +43,7 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/csakey" lloevm "github.com/smartcontractkit/chainlink/v2/core/services/llo/evm" "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm" - mercury "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/mercury" + "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/mercury" reportcodecv3 "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/mercury/v3/reportcodec" mercuryverifier "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/mercury/verifier" ) @@ -428,7 +428,6 @@ channelDefinitionsContractFromBlock = %d`, serverURL, donID, serverPubKey, confi t.Run(fmt.Sprintf("test on-chain verification - node %x", req.pk), func(t *testing.T) { _, err = verifierProxy.Verify(steve, req.req.Payload, []byte{}) require.NoError(t, err) - }) t.Logf("oracle %x reported for 0x%x", req.pk, feedID) diff --git a/core/services/relay/evm/evm.go b/core/services/relay/evm/evm.go index 5156f98185d..f2b4cbc7a9b 100644 --- a/core/services/relay/evm/evm.go +++ b/core/services/relay/evm/evm.go @@ -10,6 +10,7 @@ import ( "math/big" "net/http" "strings" + "sync" "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" @@ -144,8 +145,7 @@ type Relayer struct { triggerCapability *triggers.MercuryTriggerService // LLO/data streams - cdcFactory llo.ChannelDefinitionCacheFactory - lloORM llo.ORM + cdcFactory func() (llo.ChannelDefinitionCacheFactory, error) } type CSAETHKeystore interface { @@ -185,11 +185,15 @@ func NewRelayer(lggr logger.Logger, chain legacyevm.Chain, opts RelayerOpts) (*R return nil, fmt.Errorf("cannot create evm relayer: %w", err) } sugared := logger.Sugared(lggr).Named("Relayer") - mercuryORM := mercury.NewORM(opts.DS) - chainSelector, err := chainselectors.SelectorFromChainId(chain.ID().Uint64()) - lloORM := llo.NewORM(opts.DS, chainSelector) - cdcFactory := llo.NewChannelDefinitionCacheFactory(sugared, lloORM, chain.LogPoller(), opts.HTTPClient) + cdcFactory := sync.OnceValues(func() (llo.ChannelDefinitionCacheFactory, error) { + chainSelector, err := chainselectors.SelectorFromChainId(chain.ID().Uint64()) + if err != nil { + return nil, fmt.Errorf("failed to get chain selector for chain id %s: %w", chain.ID(), err) + } + lloORM := llo.NewORM(opts.DS, chainSelector) + return llo.NewChannelDefinitionCacheFactory(sugared, lloORM, chain.LogPoller(), opts.HTTPClient), nil + }) relayer := &Relayer{ ds: opts.DS, chain: chain, @@ -197,7 +201,6 @@ func NewRelayer(lggr logger.Logger, chain legacyevm.Chain, opts RelayerOpts) (*R ks: opts.CSAETHKeystore, mercuryPool: opts.MercuryPool, cdcFactory: cdcFactory, - lloORM: lloORM, mercuryORM: mercuryORM, transmitterCfg: opts.TransmitterConfig, capabilitiesRegistry: opts.CapabilitiesRegistry, @@ -446,7 +449,11 @@ func (r *Relayer) NewLLOProvider(rargs commontypes.RelayArgs, pargs commontypes. transmitter = llo.NewTransmitter(r.lggr, client, privKey.PublicKey) } - cdc, err := r.cdcFactory.NewCache(lloCfg) + cdcFactory, err := r.cdcFactory() + if err != nil { + return nil, err + } + cdc, err := cdcFactory.NewCache(lloCfg) if err != nil { return nil, err } diff --git a/core/services/relay/evm/mercury/verifier/verifier_test.go b/core/services/relay/evm/mercury/verifier/verifier_test.go index 4cc9dcc9bf2..abe891b583e 100644 --- a/core/services/relay/evm/mercury/verifier/verifier_test.go +++ b/core/services/relay/evm/mercury/verifier/verifier_test.go @@ -5,8 +5,8 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" - "github.com/test-go/testify/assert" - "github.com/test-go/testify/require" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/mercury" ) diff --git a/core/services/versioning/orm_test.go b/core/services/versioning/orm_test.go index e2f05e3903d..44c63f60d04 100644 --- a/core/services/versioning/orm_test.go +++ b/core/services/versioning/orm_test.go @@ -174,7 +174,6 @@ func TestORM_CheckVersion_CCIP(t *testing.T) { require.NoError(t, err) } }) - } }