Skip to content

Commit

Permalink
fix linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jmank88 committed Nov 18, 2024
1 parent b545e08 commit 7c5ef33
Show file tree
Hide file tree
Showing 31 changed files with 256 additions and 147 deletions.
2 changes: 0 additions & 2 deletions deployment/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ module github.com/smartcontractkit/chainlink/deployment

go 1.23

toolchain go1.23.0

// Make sure we're working with the latest chainlink libs
replace github.com/smartcontractkit/chainlink/v2 => ../

Expand Down
31 changes: 19 additions & 12 deletions integration-tests/actions/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,27 +350,34 @@ func SendFunds(logger zerolog.Logger, client *seth.Client, payload FundsToSendPa
return nil, err
}

var gasLimit int64
var gasLimit uint64
gasLimitRaw, err := client.EstimateGasLimitForFundTransfer(fromAddress, payload.ToAddress, payload.Amount)
if err != nil {
gasLimit = client.Cfg.Network.TransferGasFee
transferGasFee := client.Cfg.Network.TransferGasFee
if transferGasFee < 0 {
return nil, fmt.Errorf("negative transfer gas fee: %d", transferGasFee)
}
gasLimit = uint64(transferGasFee)
} else {
gasLimit = int64(gasLimitRaw)
gasLimit = gasLimitRaw
}

gasPrice := big.NewInt(0)
gasFeeCap := big.NewInt(0)
gasTipCap := big.NewInt(0)

if payload.GasLimit != nil {
gasLimit = *payload.GasLimit
if *payload.GasLimit < 0 {
return nil, fmt.Errorf("negative gas limit: %d", *payload.GasLimit)
}
gasLimit = uint64(*payload.GasLimit)
}

if client.Cfg.Network.EIP1559DynamicFees {
// if any of the dynamic fees are not set, we need to either estimate them or read them from config
if payload.GasFeeCap == nil || payload.GasTipCap == nil {
// estimation or config reading happens here
txOptions := client.NewTXOpts(seth.WithGasLimit(uint64(gasLimit)))
txOptions := client.NewTXOpts(seth.WithGasLimit(gasLimit))
gasFeeCap = txOptions.GasFeeCap
gasTipCap = txOptions.GasTipCap
}
Expand All @@ -385,7 +392,7 @@ func SendFunds(logger zerolog.Logger, client *seth.Client, payload FundsToSendPa
}
} else {
if payload.GasPrice == nil {
txOptions := client.NewTXOpts(seth.WithGasLimit(uint64(gasLimit)))
txOptions := client.NewTXOpts(seth.WithGasLimit(gasLimit))
gasPrice = txOptions.GasPrice
} else {
gasPrice = payload.GasPrice
Expand All @@ -399,7 +406,7 @@ func SendFunds(logger zerolog.Logger, client *seth.Client, payload FundsToSendPa
Nonce: nonce,
To: &payload.ToAddress,
Value: payload.Amount,
Gas: uint64(gasLimit),
Gas: gasLimit,
GasFeeCap: gasFeeCap,
GasTipCap: gasTipCap,
}
Expand All @@ -408,7 +415,7 @@ func SendFunds(logger zerolog.Logger, client *seth.Client, payload FundsToSendPa
Nonce: nonce,
To: &payload.ToAddress,
Value: payload.Amount,
Gas: uint64(gasLimit),
Gas: gasLimit,
GasPrice: gasPrice,
}
}
Expand All @@ -429,7 +436,7 @@ func SendFunds(logger zerolog.Logger, client *seth.Client, payload FundsToSendPa
Str("To", payload.ToAddress.Hex()).
Str("Amount (wei/ether)", fmt.Sprintf("%s/%s", payload.Amount, conversions.WeiToEther(payload.Amount).Text('f', -1))).
Uint64("Nonce", nonce).
Int64("Gas Limit", gasLimit).
Uint64("Gas Limit", gasLimit).
Str("Gas Price", gasPrice.String()).
Str("Gas Fee Cap", gasFeeCap.String()).
Str("Gas Tip Cap", gasTipCap.String()).
Expand All @@ -449,7 +456,7 @@ func SendFunds(logger zerolog.Logger, client *seth.Client, payload FundsToSendPa
Str("TxHash", signedTx.Hash().String()).
Str("Amount (wei/ether)", fmt.Sprintf("%s/%s", payload.Amount, conversions.WeiToEther(payload.Amount).Text('f', -1))).
Uint64("Nonce", nonce).
Int64("Gas Limit", gasLimit).
Uint64("Gas Limit", gasLimit).
Str("Gas Price", gasPrice.String()).
Str("Gas Fee Cap", gasFeeCap.String()).
Str("Gas Tip Cap", gasTipCap.String()).
Expand Down Expand Up @@ -1038,7 +1045,7 @@ func GetLatestFinalizedBlockHeader(ctx context.Context, client *seth.Client, net
}
latestBlockNumber := header.Number.Uint64()
finalizedBlockNumber := latestBlockNumber - network.FinalityDepth
return client.Client.HeaderByNumber(ctx, big.NewInt(int64(finalizedBlockNumber)))
return client.Client.HeaderByNumber(ctx, new(big.Int).SetUint64(finalizedBlockNumber))
}

// SendLinkFundsToDeploymentAddresses sends LINK token to all addresses, but the root one, from the root address. It uses
Expand Down Expand Up @@ -1241,7 +1248,7 @@ func GetStalenessReportCleanupFn(t *testing.T, logger zerolog.Logger, chainClien
endBlock, err := chainClient.Client.BlockNumber(context.Background())
require.NoError(t, err, "Failed to get end block")

total, ok, reverted, stale, err := GenerateUpkeepReport(t, chainClient, big.NewInt(int64(startBlock)), big.NewInt(int64(endBlock)), registry, registryVersion)
total, ok, reverted, stale, err := GenerateUpkeepReport(t, chainClient, new(big.Int).SetUint64(startBlock), new(big.Int).SetUint64(endBlock), registry, registryVersion)
require.NoError(t, err, "Failed to get staleness data")
if stale > 0 || reverted > 0 {
logger.Warn().Int("Total upkeeps", total).Int("Successful upkeeps", ok).Int("Reverted Upkeeps", reverted).Int("Stale Upkeeps", stale).Msg("Staleness data")
Expand Down
8 changes: 7 additions & 1 deletion integration-tests/actions/automationv2/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"encoding/json"
"errors"
"fmt"
"math"
"math/big"
"strings"
"testing"
Expand Down Expand Up @@ -642,10 +643,15 @@ func calculateOCR2ConfigArgs(a *AutomationTest, S []int, oracleIdentities []conf
MaxUpkeepBatchSize: a.PluginConfig.MaxUpkeepBatchSize,
})

rMax := a.PublicConfig.RMax
if rMax > math.MaxUint8 {
panic(fmt.Errorf("rmax overflows uint8: %d", rMax))
}

return ocr2.ContractSetConfigArgsForTests(
a.PublicConfig.DeltaProgress, a.PublicConfig.DeltaResend,
a.PublicConfig.DeltaRound, a.PublicConfig.DeltaGrace,
a.PublicConfig.DeltaStage, uint8(a.PublicConfig.RMax),
a.PublicConfig.DeltaStage, uint8(rMax),
S, oracleIdentities, offC,
nil,
a.PublicConfig.MaxDurationQuery, a.PublicConfig.MaxDurationObservation,
Expand Down
15 changes: 7 additions & 8 deletions integration-tests/actions/keeper_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -670,15 +670,14 @@ Distribute your funds across multiple private keys and update your configuration
func GetAndAssertCorrectConcurrency(client *seth.Client, minConcurrency int) (int, error) {
concurrency := client.Cfg.GetMaxConcurrency()

var msg string
if client.Cfg.IsSimulatedNetwork() {
msg = fmt.Sprintf(INSUFFICIENT_EPHEMERAL_KEYS, concurrency)
} else {
msg = fmt.Sprintf(INSUFFICIENT_STATIC_KEYS, concurrency)
}

if concurrency < minConcurrency {
return 0, fmt.Errorf(msg)
var err error
if client.Cfg.IsSimulatedNetwork() {
err = fmt.Errorf(INSUFFICIENT_EPHEMERAL_KEYS, concurrency)
} else {
err = fmt.Errorf(INSUFFICIENT_STATIC_KEYS, concurrency)
}
return 0, err
}

return concurrency, nil
Expand Down
4 changes: 4 additions & 0 deletions integration-tests/actions/refund.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/ecdsa"
"encoding/json"
"fmt"
"math"
"math/big"
"regexp"
"strconv"
Expand Down Expand Up @@ -343,6 +344,9 @@ func returnAllFundsIfPossible(log zerolog.Logger, sethClient *seth.Client, fromP
if err != nil {
gasLimit = sethClient.Cfg.Network.TransferGasFee
} else {
if gasLimitRaw > math.MaxInt64 {
return fmt.Errorf("gas limit overflows int64: %d", gasLimitRaw)
}
gasLimit = int64(gasLimitRaw)
}

Expand Down
2 changes: 1 addition & 1 deletion integration-tests/actions/vrf/vrfv2plus/setup_steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func SetupVRFV2_5Environment(
return nil, nil, nil, err
}
l.Info().Str("Coordinator", vrfContracts.CoordinatorV2Plus.Address()).Msg("Registering Proving Key")
provingKey, err := VRFV2_5RegisterProvingKey(vrfKey, vrfContracts.CoordinatorV2Plus, uint64(assets.GWei(*configGeneral.CLNodeMaxGasPriceGWei).Int64()))
provingKey, err := VRFV2_5RegisterProvingKey(vrfKey, vrfContracts.CoordinatorV2Plus, assets.GWei(*configGeneral.CLNodeMaxGasPriceGWei).ToInt().Uint64())
if err != nil {
return nil, nil, nil, fmt.Errorf(vrfcommon.ErrGenericFormat, vrfcommon.ErrRegisteringProvingKey, err)
}
Expand Down
16 changes: 12 additions & 4 deletions integration-tests/ccip-tests/actions/ccip_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,11 @@ func (ccipModule *CCIPCommon) UpdateTokenPricesAtRegularInterval(ctx context.Con
aggregators = append(aggregators, contract)
}
go func(aggregators []*contracts.MockAggregator) {
rand.NewSource(uint64(time.Now().UnixNano()))
now := time.Now().UnixNano()
if now < 0 {
panic(fmt.Errorf("negative timestamp: %d", now))
}
rand.NewSource(uint64(now))
ticker := time.NewTicker(interval)
for {
select {
Expand Down Expand Up @@ -1661,7 +1665,11 @@ func (sourceCCIP *SourceCCIPModule) IsPastRequestTriggeredWithinTimeframe(ctx co
if err != nil {
return nil, fmt.Errorf("error while getting average source block time. Error: %w", err)
}
filterFromBlock := latestBlock - uint64(timeframe.Duration()/avgBlockTime)
blocks := timeframe.Duration() / avgBlockTime
if blocks < 0 {
return nil, fmt.Errorf("negative blocks: %d", blocks)
}
filterFromBlock := latestBlock - uint64(blocks)

onRampContract, err := evm_2_evm_onramp.NewEVM2EVMOnRamp(common.HexToAddress(sourceCCIP.OnRamp.EthAddress.Hex()),
sourceCCIP.Common.ChainClient.Backend())
Expand All @@ -1678,7 +1686,7 @@ func (sourceCCIP *SourceCCIPModule) IsPastRequestTriggeredWithinTimeframe(ctx co
_ = iterator.Close()
}()
if iterator.Next() {
hdr, err := sourceCCIP.Common.ChainClient.HeaderByNumber(context.Background(), big.NewInt(int64(iterator.Event.Raw.BlockNumber)))
hdr, err := sourceCCIP.Common.ChainClient.HeaderByNumber(context.Background(), new(big.Int).SetUint64(iterator.Event.Raw.BlockNumber))
if err != nil {
return nil, fmt.Errorf("error getting header for block: %d, Error: %w", iterator.Event.Raw.BlockNumber, err)
}
Expand Down Expand Up @@ -4157,7 +4165,7 @@ func (c *CCIPTestEnv) SetUpNodeKeysAndFund(
nodeFund *big.Float,
chains []blockchain.EVMClient,
) error {
if c.CLNodes == nil || len(c.CLNodes) == 0 {
if len(c.CLNodes) == 0 {
return fmt.Errorf("no chainlink nodes to setup")
}
var chainlinkNodes []*nodeclient.ChainlinkClient
Expand Down
6 changes: 3 additions & 3 deletions integration-tests/ccip-tests/actions/reorg_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ type ReorgConfig struct {
// DstGethHTTPURL dest chain Geth HTTP URL
DstGethHTTPURL string
// SrcFinalityDepth source chain finality depth
SrcFinalityDepth uint64
SrcFinalityDepth int
// DstGethHTTPURL dest chain finality depth
DstFinalityDepth uint64
DstFinalityDepth int
// FinalityDelta blocks to rewind below or above finality
FinalityDelta int
}

// Validate validates ReorgConfig params
func (rc *ReorgConfig) Validate() error {
if rc.FinalityDelta >= int(rc.SrcFinalityDepth) || rc.FinalityDelta >= int(rc.DstFinalityDepth) {
if rc.FinalityDelta >= rc.SrcFinalityDepth || rc.FinalityDelta >= rc.DstFinalityDepth {
return fmt.Errorf(
"finality delta can't be higher than source or dest chain finality, delta: %d, src: %d, dst: %d",
rc.FinalityDelta, rc.SrcFinalityDepth, rc.DstFinalityDepth,
Expand Down
6 changes: 5 additions & 1 deletion integration-tests/ccip-tests/contracts/contract_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -2241,7 +2241,11 @@ func (a *MockAggregator) UpdateRoundData(answer *big.Int, minP, maxP *int) error

// if answer is nil, we calculate the answer with random percentage (within the provided range) of latest answer
if answer == nil {
rand.Seed(uint64(time.Now().UnixNano()))
now := time.Now().UnixNano()
if now < 0 {
return fmt.Errorf("negative timestamp: %d", now)
}
rand.Seed(uint64(now))
randomNumber := rand.Intn(pointer.GetInt(maxP)-pointer.GetInt(minP)+1) + pointer.GetInt(minP)
// answer = previous round answer + (previous round answer * random percentage)
answer = new(big.Int).Add(a.Answer, new(big.Int).Div(new(big.Int).Mul(a.Answer, big.NewInt(int64(randomNumber))), big.NewInt(100)))
Expand Down
25 changes: 17 additions & 8 deletions integration-tests/ccip-tests/smoke/ccip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package smoke

import (
"fmt"
"math"
"math/big"
"testing"
"time"
Expand Down Expand Up @@ -874,8 +875,8 @@ func TestSmokeCCIPReorgBelowFinality(t *testing.T) {
require.NoError(t, err, "Send requests failed")
rs := SetupReorgSuite(t, &log, setUpOutput)
// run below finality reorg in both source and destination chain
blocksBackSrc := int(rs.Cfg.SrcFinalityDepth) - rs.Cfg.FinalityDelta
blocksBackDst := int(rs.Cfg.DstFinalityDepth) - rs.Cfg.FinalityDelta
blocksBackSrc := rs.Cfg.SrcFinalityDepth - rs.Cfg.FinalityDelta
blocksBackDst := rs.Cfg.DstFinalityDepth - rs.Cfg.FinalityDelta
rs.RunReorg(rs.DstClient, blocksBackSrc, "Source", 2*time.Second)
rs.RunReorg(rs.DstClient, blocksBackDst, "Destination", 2*time.Second)
time.Sleep(1 * time.Minute)
Expand Down Expand Up @@ -930,10 +931,10 @@ func performAboveFinalityReorgAndValidate(t *testing.T, network string) {
logPollerName := ""
if network == "Destination" {
logPollerName = fmt.Sprintf("EVM.%d.LogPoller", lane.DestChain.GetChainID())
rs.RunReorg(rs.DstClient, int(rs.Cfg.DstFinalityDepth)+rs.Cfg.FinalityDelta, network, 2*time.Second)
rs.RunReorg(rs.DstClient, rs.Cfg.DstFinalityDepth+rs.Cfg.FinalityDelta, network, 2*time.Second)
} else {
logPollerName = fmt.Sprintf("EVM.%d.LogPoller", lane.SourceChain.GetChainID())
rs.RunReorg(rs.SrcClient, int(rs.Cfg.SrcFinalityDepth)+rs.Cfg.FinalityDelta, network, 2*time.Second)
rs.RunReorg(rs.SrcClient, rs.Cfg.SrcFinalityDepth+rs.Cfg.FinalityDelta, network, 2*time.Second)
}
clNodes := setUpOutput.Env.CLNodes
// assert every node is detecting the reorg (LogPollInterval is set as 1s for faster detection)
Expand Down Expand Up @@ -1123,17 +1124,25 @@ func testOffRampRateLimits(t *testing.T, rateLimiterConfig contracts.RateLimiter

// SetupReorgSuite defines the setup required to perform re-org step
func SetupReorgSuite(t *testing.T, lggr *zerolog.Logger, setupOutput *testsetups.CCIPTestSetUpOutputs) *actions.ReorgSuite {
var finalitySrc uint64
var finalityDst uint64
var finalitySrc int
var finalityDst int
if setupOutput.Cfg.SelectedNetworks[0].FinalityTag {
finalitySrc = 10
} else {
finalitySrc = setupOutput.Cfg.SelectedNetworks[0].FinalityDepth
finalityDepth := setupOutput.Cfg.SelectedNetworks[0].FinalityDepth
if finalityDepth > math.MaxInt {
t.Fatalf("source finality depth overflows int: %d", finalityDepth)
}
finalitySrc = int(finalityDepth)
}
if setupOutput.Cfg.SelectedNetworks[1].FinalityTag {
finalityDst = 10
} else {
finalityDst = setupOutput.Cfg.SelectedNetworks[1].FinalityDepth
finalityDepth := setupOutput.Cfg.SelectedNetworks[1].FinalityDepth
if finalityDepth > math.MaxInt {
t.Fatalf("destination finality depth overflows int: %d", finalityDepth)
}
finalityDst = int(finalityDepth)
}
var srcGethHTTPURL, dstGethHTTPURL string
if setupOutput.Env.LocalCluster != nil {
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/ccip-tests/testconfig/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ func (c *ChainlinkDeployment) Validate() error {
if c.NoOfNodes == nil {
return errors.New("chainlink config is invalid, NoOfNodes should be specified")
}
if c.Nodes != nil && len(c.Nodes) > 0 {
if len(c.Nodes) > 0 {
noOfNodes := pointer.GetInt(c.NoOfNodes)
if noOfNodes != len(c.Nodes) {
return errors.New("chainlink config is invalid, NoOfNodes and Nodes length mismatch")
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/ccip-tests/testsetups/ccip.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ func (c *CCIPTestConfig) SetNetworkPairs(lggr zerolog.Logger) error {
var newNetworkPairs []NetworkPair
denselyConnectedNetworks := make(map[string]struct{})
// if densely connected networks are provided, choose all the network pairs containing the networks mentioned in the list for DenselyConnectedNetworkChainIds
if c.TestGroupInput.DenselyConnectedNetworkChainIds != nil && len(c.TestGroupInput.DenselyConnectedNetworkChainIds) > 0 {
if len(c.TestGroupInput.DenselyConnectedNetworkChainIds) > 0 {
for _, n := range c.TestGroupInput.DenselyConnectedNetworkChainIds {
denselyConnectedNetworks[n] = struct{}{}
}
Expand Down
3 changes: 3 additions & 0 deletions integration-tests/ccip-tests/testsetups/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,9 @@ func CreateChainConfigFromNetworks(
require.NoError(t, err)
deployer, err := bind.NewKeyedTransactorWithChainID(pvtKey, big.NewInt(int64(chainId)))
require.NoError(t, err)
if chainId < 0 {
t.Fatalf("negative chain ID: %d", chainId)
}
chains = append(chains, devenv.ChainConfig{
ChainID: uint64(chainId),
ChainName: chainName,
Expand Down
4 changes: 4 additions & 0 deletions integration-tests/ccip-tests/types/config/node/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package node
import (
"bytes"
"fmt"
"math"
"math/big"

"github.com/smartcontractkit/chainlink-testing-framework/lib/blockchain"
Expand Down Expand Up @@ -54,6 +55,9 @@ func WithPrivateEVMs(networks []blockchain.EVMNetwork, commonChainConfig *evmcfg
}
}
if evmConfig.Chain.FinalityDepth == nil && network.FinalityDepth > 0 {
if network.FinalityDepth > math.MaxUint32 {
panic(fmt.Errorf("finality depth overflows uint32: %d", network.FinalityDepth))
}
evmConfig.Chain.FinalityDepth = ptr.Ptr(uint32(network.FinalityDepth))
}
if evmConfig.Chain.FinalityTagEnabled == nil && network.FinalityTag {
Expand Down
Loading

0 comments on commit 7c5ef33

Please sign in to comment.