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

golangci-lint: fix some issues #14322

Merged
merged 1 commit into from
Sep 4, 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
1 change: 1 addition & 0 deletions core/capabilities/targets/write_target_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion core/chains/evm/client/rpc_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/gas/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ type MockGasEstimatorConfig struct {
FeeCapDefaultF *assets.Wei
LimitMaxF uint64
ModeF string
EstimateLimitF bool
EstimateLimitF bool
}

func NewMockGasConfig() *MockGasEstimatorConfig {
Expand Down
7 changes: 6 additions & 1 deletion core/internal/cltest/cltest.go
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been initializing a relayer for chain ID zero. Now it disables again.

Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
3 changes: 2 additions & 1 deletion core/services/feeds/orm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions core/services/feeds/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion core/services/llo/data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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] })
Expand Down
5 changes: 1 addition & 4 deletions core/services/llo/evm/report_codec_premium_legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions core/services/llo/onchain_channel_definition_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"maps"
"math/big"
"net/http"
Expand Down Expand Up @@ -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)
}
Expand Down
15 changes: 12 additions & 3 deletions core/services/llo/onchain_channel_definition_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")

Expand All @@ -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}))}

Expand All @@ -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))}

Expand All @@ -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))}

Expand All @@ -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}))}

Expand All @@ -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"}`)))}

Expand All @@ -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
Expand All @@ -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)
})
})

Expand All @@ -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

Expand All @@ -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")
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion core/services/ocr2/plugins/ccip/exportinternal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 1 addition & 2 deletions core/services/ocr2/plugins/llo/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
Expand Down
23 changes: 15 additions & 8 deletions core/services/relay/evm/evm.go
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the only real bug.

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"math/big"
"net/http"
"strings"
"sync"

"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -185,19 +185,22 @@ 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,
lggr: sugared,
ks: opts.CSAETHKeystore,
mercuryPool: opts.MercuryPool,
cdcFactory: cdcFactory,
lloORM: lloORM,
mercuryORM: mercuryORM,
transmitterCfg: opts.TransmitterConfig,
capabilitiesRegistry: opts.CapabilitiesRegistry,
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions core/services/relay/evm/mercury/verifier/verifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
1 change: 0 additions & 1 deletion core/services/versioning/orm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ func TestORM_CheckVersion_CCIP(t *testing.T) {
require.NoError(t, err)
}
})

}
}

Expand Down
Loading