Skip to content

Commit

Permalink
test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
AnieeG committed Dec 20, 2024
1 parent a73c660 commit 6e6155c
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 107 deletions.
2 changes: 1 addition & 1 deletion deployment/ccip/changeset/cs_add_lane_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func TestAddLanesWithTestRouter(t *testing.T) {
chain2: true,
},
},
// off
// offramp update on dest chain
chain2: {
OffRampUpdates: map[uint64]bool{
chain1: true,
Expand Down
35 changes: 20 additions & 15 deletions deployment/ccip/changeset/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,8 @@ func MakeEVMExtraArgsV2(gasLimit uint64, allowOOO bool) []byte {
return extraArgs
}

func AddLaneWithDefaultPricesAndFeeQuoterConfig(t *testing.T, e *DeployedEnv, state CCIPOnChainState, from, to uint64, isTestRouter bool) {
func AddLane(t *testing.T, e *DeployedEnv, from, to uint64, isTestRouter bool, gasprice map[uint64]*big.Int, tokenPrices map[common.Address]*big.Int, fqCfg fee_quoter.FeeQuoterDestChainConfig) {
var err error
stateChain1 := state.Chains[from]
e.Env, err = commoncs.ApplyChangesets(t, e.Env, e.TimelockContracts(t), []commoncs.ChangesetApplication{
{
Changeset: commoncs.WrapChangeSet(UpdateOnRampsDests),
Expand All @@ -413,13 +412,8 @@ func AddLaneWithDefaultPricesAndFeeQuoterConfig(t *testing.T, e *DeployedEnv, st
Config: UpdateFeeQuoterPricesConfig{
InitialPrices: map[uint64]FeeQuoterPriceUpdatePerSource{
from: {
TokenPrices: map[common.Address]*big.Int{
stateChain1.LinkToken.Address(): DefaultLinkPrice,
stateChain1.Weth9.Address(): DefaultWethPrice,
},
GasPrices: map[uint64]*big.Int{
to: DefaultGasPrice,
},
TokenPrices: tokenPrices,
GasPrices: gasprice,
},
},
},
Expand All @@ -429,7 +423,7 @@ func AddLaneWithDefaultPricesAndFeeQuoterConfig(t *testing.T, e *DeployedEnv, st
Config: UpdateFeeQuoterDestsConfig{
UpdatesByChain: map[uint64]map[uint64]fee_quoter.FeeQuoterDestChainConfig{
from: {
to: DefaultFeeQuoterDestChainConfig(),
to: fqCfg,
},
},
},
Expand All @@ -441,7 +435,7 @@ func AddLaneWithDefaultPricesAndFeeQuoterConfig(t *testing.T, e *DeployedEnv, st
to: {
from: {
IsEnabled: true,
TestRouter: true,
TestRouter: isTestRouter,
},
},
},
Expand All @@ -450,18 +444,18 @@ func AddLaneWithDefaultPricesAndFeeQuoterConfig(t *testing.T, e *DeployedEnv, st
{
Changeset: commoncs.WrapChangeSet(UpdateRouterRamps),
Config: UpdateRouterRampsConfig{
TestRouter: true,
TestRouter: isTestRouter,
UpdatesByChain: map[uint64]RouterUpdates{
// onRamp update on source chain
from: {
OnRampUpdates: map[uint64]bool{
to: true,
},
},
// off
from: {
// offramp update on dest chain
to: {
OffRampUpdates: map[uint64]bool{
to: true,
from: true,
},
},
},
Expand All @@ -471,6 +465,17 @@ func AddLaneWithDefaultPricesAndFeeQuoterConfig(t *testing.T, e *DeployedEnv, st
require.NoError(t, err)
}

func AddLaneWithDefaultPricesAndFeeQuoterConfig(t *testing.T, e *DeployedEnv, state CCIPOnChainState, from, to uint64, isTestRouter bool) {
stateChainFrom := state.Chains[from]
AddLane(t, e, from, to, isTestRouter,
map[uint64]*big.Int{
to: DefaultGasPrice,
}, map[common.Address]*big.Int{
stateChainFrom.LinkToken.Address(): DefaultLinkPrice,
stateChainFrom.Weth9.Address(): DefaultWethPrice,
}, DefaultFeeQuoterDestChainConfig())
}

// AddLanesForAll adds densely connected lanes for all chains in the environment so that each chain
// is connected to every other chain except itself.
func AddLanesForAll(t *testing.T, e *DeployedEnv, state CCIPOnChainState) {
Expand Down
7 changes: 7 additions & 0 deletions deployment/multiclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/router"
"github.com/smartcontractkit/chainlink/v2/core/logger"
)

func TestRevert(t *testing.T) {
errreason, err := parseErrorFromABI("0xae236d9c0000000000000000000000000000000000000000000000004d0102030cb384f5", router.RouterABI)
require.NoError(t, err)
require.Contains(t, errreason, "error not found in ABI")
}

func TestMultiClient(t *testing.T) {
lggr := logger.TestLogger(t)
// Expect an error if no RPCs supplied.
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/contracts/ccipreader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ func Test_LinkPriceUSD(t *testing.T) {
linkPriceUSD, err := reader.LinkPriceUSD(ctx)
require.NoError(t, err)
require.NotNil(t, linkPriceUSD.Int)
require.Equal(t, changeset.DefaultInitialPrices.LinkPrice, linkPriceUSD.Int)
require.Equal(t, changeset.DefaultLinkPrice, linkPriceUSD.Int)
}

func Test_GetMedianDataAvailabilityGasConfig(t *testing.T) {
Expand Down Expand Up @@ -884,7 +884,7 @@ func Test_GetWrappedNativeTokenPriceUSD(t *testing.T) {

// Only chainD has reader contracts bound
require.Len(t, prices, 1)
require.Equal(t, changeset.DefaultInitialPrices.WethPrice, prices[cciptypes.ChainSelector(chain1)].Int)
require.Equal(t, changeset.DefaultWethPrice, prices[cciptypes.ChainSelector(chain1)].Int)
}

// Benchmark Results:
Expand Down
129 changes: 40 additions & 89 deletions integration-tests/smoke/ccip/ccip_fee_boosting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ package smoke

import (
"context"
"fmt"
"math/big"
"testing"
"time"

"github.com/pkg/errors"

"github.com/smartcontractkit/chainlink-common/pkg/config"
commonchangeset "github.com/smartcontractkit/chainlink/deployment/common/changeset"

commoncs "github.com/smartcontractkit/chainlink/deployment/common/changeset"
testsetups "github.com/smartcontractkit/chainlink/integration-tests/testsetups/ccip"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
Expand All @@ -20,11 +18,10 @@ import (

"github.com/smartcontractkit/chainlink-testing-framework/lib/utils/testcontext"

"github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/ccipevm"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/fee_quoter"

cciptypes "github.com/smartcontractkit/chainlink-ccip/pkg/types/ccipocr3"

"github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/ccipevm"

"github.com/smartcontractkit/chainlink/deployment"
"github.com/smartcontractkit/chainlink/deployment/ccip/changeset"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/onramp"
Expand Down Expand Up @@ -84,32 +81,31 @@ func Test_CCIPFeeBoosting(t *testing.T) {
)
t.Log("Adjusted gas price on dest chain:", adjustedGasPriceDest)

initialPrices := changeset.InitialPrices{
LinkPrice: linkPrice,
WethPrice: wethPrice,
GasPrice: changeset.ToPackedFee(adjustedGasPriceDest, big.NewInt(0)),
}

laneCfg := changeset.LaneConfig{
SourceSelector: sourceChain,
DestSelector: destChain,
InitialPricesBySource: initialPrices,
FeeQuoterDestChain: changeset.DefaultFeeQuoterDestChainConfig(),
TestRouter: false,
}

e.Env, err = commonchangeset.ApplyChangesets(t, e.Env, nil, []commonchangeset.ChangesetApplication{
{
Changeset: commonchangeset.WrapChangeSet(changeset.AddLanes),
Config: changeset.AddLanesConfig{LaneConfigs: []changeset.LaneConfig{laneCfg}},
changeset.AddLane(t, &e, sourceChain, destChain, false,
map[uint64]*big.Int{
destChain: changeset.ToPackedFee(adjustedGasPriceDest, big.NewInt(0)),
},
})
require.NoError(t, err)
map[common.Address]*big.Int{
state.Chains[sourceChain].LinkToken.Address(): linkPrice,
state.Chains[sourceChain].Weth9.Address(): wethPrice,
},
changeset.DefaultFeeQuoterDestChainConfig())

// Update token prices in destination chain FeeQuoter
err = updateTokensPrices(e, state, destChain, map[common.Address]*big.Int{
state.Chains[destChain].LinkToken.Address(): linkPrice,
state.Chains[destChain].Weth9.Address(): wethPrice,
e.Env, err = commoncs.ApplyChangesets(t, e.Env, e.TimelockContracts(t), []commoncs.ChangesetApplication{
{
Changeset: commoncs.WrapChangeSet(changeset.UpdateFeeQuoterPricesCS),
Config: changeset.UpdateFeeQuoterPricesConfig{
InitialPrices: map[uint64]changeset.FeeQuoterPriceUpdatePerSource{
destChain: {
TokenPrices: map[common.Address]*big.Int{
state.Chains[destChain].LinkToken.Address(): linkPrice,
state.Chains[destChain].Weth9.Address(): wethPrice,
},
},
},
},
},
})
require.NoError(t, err)

Expand Down Expand Up @@ -137,7 +133,20 @@ func Test_CCIPFeeBoosting(t *testing.T) {
DestChainSelector: destChain,
}] = []uint64{msgSentEvent.SequenceNumber}

err = updateGasPrice(e, state, sourceChain, destChain, originalGasPriceDestUSD)
e.Env, err = commoncs.ApplyChangesets(t, e.Env, e.TimelockContracts(t), []commoncs.ChangesetApplication{
{
Changeset: commoncs.WrapChangeSet(changeset.UpdateFeeQuoterPricesCS),
Config: changeset.UpdateFeeQuoterPricesConfig{
InitialPrices: map[uint64]changeset.FeeQuoterPriceUpdatePerSource{
sourceChain: {
GasPrices: map[uint64]*big.Int{
destChain: originalGasPriceDestUSD,
},
},
},
},
},
})
require.NoError(t, err)

// Confirm gas prices are updated
Expand Down Expand Up @@ -270,61 +279,3 @@ func convertToMessage(msg onramp.InternalEVM2AnyRampMessage) cciptypes.Message {
TokenAmounts: tokenAmounts,
}
}

func updateGasPrice(env changeset.DeployedEnv, state changeset.CCIPOnChainState, srcChain, destChain uint64, gasPrice *big.Int) error {
chainState, exists := state.Chains[srcChain]
if !exists {
return fmt.Errorf("chain state not found for selector: %d", srcChain)
}

feeQuoter := chainState.FeeQuoter
// Update gas price
auth := env.Env.Chains[srcChain].DeployerKey
tx, err := feeQuoter.UpdatePrices(auth, fee_quoter.InternalPriceUpdates{
TokenPriceUpdates: nil,
GasPriceUpdates: []fee_quoter.InternalGasPriceUpdate{
{
DestChainSelector: destChain,
UsdPerUnitGas: gasPrice,
},
},
})
if err != nil {
return errors.Wrapf(err, "updating gas price on chain %d", srcChain)
}
if _, err := deployment.ConfirmIfNoError(env.Env.Chains[srcChain], tx, err); err != nil {
return err
}

return nil
}

func updateTokensPrices(env changeset.DeployedEnv, state changeset.CCIPOnChainState, chain uint64, tokenPrices map[common.Address]*big.Int) error {
chainState, exists := state.Chains[chain]
if !exists {
return fmt.Errorf("chain state not found for selector: %d", chain)
}

feeQuoter := chainState.FeeQuoter
// Update token prices
auth := env.Env.Chains[chain].DeployerKey
tokenPricesUpdates := make([]fee_quoter.InternalTokenPriceUpdate, 0, len(tokenPrices))
for token, price := range tokenPrices {
tokenPricesUpdates = append(tokenPricesUpdates, fee_quoter.InternalTokenPriceUpdate{
SourceToken: token,
UsdPerToken: price,
})
}
tx, err := feeQuoter.UpdatePrices(auth, fee_quoter.InternalPriceUpdates{
TokenPriceUpdates: tokenPricesUpdates,
GasPriceUpdates: nil,
})
if err != nil {
return errors.Wrapf(err, "updating token prices on chain %d", chain)
}
if _, err := deployment.ConfirmIfNoError(env.Env.Chains[chain], tx, err); err != nil {
return err
}

return nil
}

0 comments on commit 6e6155c

Please sign in to comment.