Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AnieeG committed Dec 20, 2024
1 parent 0e7593d commit 4afbdb5
Show file tree
Hide file tree
Showing 14 changed files with 203 additions and 52 deletions.
13 changes: 3 additions & 10 deletions deployment/ccip/changeset/cs_add_lane_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,11 @@ import (

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

"github.com/smartcontractkit/chainlink/deployment"
commoncs "github.com/smartcontractkit/chainlink/deployment/common/changeset"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/fee_quoter"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/router"
)

var (
LINKPrice = deployment.E18Mult(20)
WETHPrice = deployment.E18Mult(4000)
GasPrice = ToPackedFee(big.NewInt(8e14), big.NewInt(0))
)

func TestAddLanesWithTestRouter(t *testing.T) {
t.Parallel()
e := NewMemoryEnvironment(t)
Expand Down Expand Up @@ -53,11 +46,11 @@ func TestAddLanesWithTestRouter(t *testing.T) {
InitialPrices: map[uint64]FeeQuoterPriceUpdatePerSource{
chain1: {
TokenPrices: map[common.Address]*big.Int{
stateChain1.LinkToken.Address(): LINKPrice,
stateChain1.Weth9.Address(): WETHPrice,
stateChain1.LinkToken.Address(): DefaultLinkPrice,
stateChain1.Weth9.Address(): DefaultWethPrice,
},
GasPrices: map[uint64]*big.Int{
chain2: GasPrice,
chain2: DefaultGasPrice,
},
},
},
Expand Down
105 changes: 89 additions & 16 deletions deployment/ccip/changeset/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/pkg/errors"

commoncs "github.com/smartcontractkit/chainlink/deployment/common/changeset"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/fee_quoter"
"github.com/smartcontractkit/chainlink/v2/core/services/relay"

"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -60,6 +62,10 @@ var (
evmExtraArgsV2Tag = hexutil.MustDecode("0x181dcf10")

routerABI = abihelpers.MustParseABI(router.RouterABI)

DefaultLinkPrice = deployment.E18Mult(20)
DefaultWethPrice = deployment.E18Mult(4000)
DefaultGasPrice = ToPackedFee(big.NewInt(8e14), big.NewInt(0))
)

// Context returns a context with the test's deadline, if available.
Expand Down Expand Up @@ -384,30 +390,97 @@ func MakeEVMExtraArgsV2(gasLimit uint64, allowOOO bool) []byte {
return extraArgs
}

func AddLaneWithDefaultPricesAndFeeQuoterConfig(e deployment.Environment, state CCIPOnChainState, from, to uint64, isTestRouter bool) error {
cfg := LaneConfig{
SourceSelector: from,
DestSelector: to,
InitialPricesBySource: DefaultInitialPrices,
FeeQuoterDestChain: DefaultFeeQuoterDestChainConfig(),
}
return addLane(e, state, cfg, isTestRouter)
func AddLaneWithDefaultPricesAndFeeQuoterConfig(t *testing.T, e *DeployedEnv, state CCIPOnChainState, from, to uint64, isTestRouter bool) {
var err error
stateChain1 := state.Chains[from]
e.Env, err = commoncs.ApplyChangesets(t, e.Env, e.TimelockContracts(t), []commoncs.ChangesetApplication{
{
Changeset: commoncs.WrapChangeSet(UpdateOnRampsDests),
Config: UpdateOnRampDestsConfig{
UpdatesByChain: map[uint64]map[uint64]OnRampDestinationUpdate{
from: {
to: {
IsEnabled: true,
TestRouter: isTestRouter,
AllowListEnabled: false,
},
},
},
},
},
{
Changeset: commoncs.WrapChangeSet(UpdateFeeQuoterPricesCS),
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,
},
},
},
},
},
{
Changeset: commoncs.WrapChangeSet(UpdateFeeQuoterDests),
Config: UpdateFeeQuoterDestsConfig{
UpdatesByChain: map[uint64]map[uint64]fee_quoter.FeeQuoterDestChainConfig{
from: {
to: DefaultFeeQuoterDestChainConfig(),
},
},
},
},
{
Changeset: commoncs.WrapChangeSet(UpdateOffRampSources),
Config: UpdateOffRampSourcesConfig{
UpdatesByChain: map[uint64]map[uint64]OffRampSourceUpdate{
to: {
from: {
IsEnabled: true,
TestRouter: true,
},
},
},
},
},
{
Changeset: commoncs.WrapChangeSet(UpdateRouterRamps),
Config: UpdateRouterRampsConfig{
TestRouter: true,
UpdatesByChain: map[uint64]RouterUpdates{
// onRamp update on source chain
from: {
OnRampUpdates: map[uint64]bool{
to: true,
},
},
// off
from: {
OffRampUpdates: map[uint64]bool{
to: true,
},
},
},
},
},
})
require.NoError(t, err)
}

// 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(e deployment.Environment, state CCIPOnChainState) error {
for source := range e.Chains {
for dest := range e.Chains {
func AddLanesForAll(t *testing.T, e *DeployedEnv, state CCIPOnChainState) {
for source := range e.Env.Chains {
for dest := range e.Env.Chains {
if source != dest {
err := AddLaneWithDefaultPricesAndFeeQuoterConfig(e, state, source, dest, false)
if err != nil {
return err
}
AddLaneWithDefaultPricesAndFeeQuoterConfig(t, e, state, source, dest, false)
}
}
}
return nil
}

func ToPackedFee(execFee, daFee *big.Int) *big.Int {
Expand Down
93 changes: 89 additions & 4 deletions deployment/environment/crib/ccip_deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import (
"context"
"errors"
"fmt"
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/smartcontractkit/ccip-owner-contracts/pkg/config"

commonchangeset "github.com/smartcontractkit/chainlink/deployment/common/changeset"
commontypes "github.com/smartcontractkit/chainlink/deployment/common/types"
"github.com/smartcontractkit/chainlink/deployment/environment/devenv"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/fee_quoter"
"github.com/smartcontractkit/chainlink/v2/core/services/relay"
"math/big"

"github.com/smartcontractkit/chainlink/deployment"
"github.com/smartcontractkit/chainlink/deployment/ccip/changeset"
Expand Down Expand Up @@ -120,9 +123,91 @@ func DeployCCIPAndAddLanes(ctx context.Context, lggr logger.Logger, envConfig de
return DeployCCIPOutput{}, fmt.Errorf("failed to load onchain state: %w", err)
}
// Add all lanes
err = changeset.AddLanesForAll(*e, state)
if err != nil {
return DeployCCIPOutput{}, fmt.Errorf("failed to add lanes: %w", err)
for from := range e.Chains {
for to := range e.Chains {
if from != to {
stateChain1 := state.Chains[from]
newEnv, err := commonchangeset.ApplyChangesets(nil, *e, nil, []commonchangeset.ChangesetApplication{
{
Changeset: commonchangeset.WrapChangeSet(changeset.UpdateOnRampsDests),
Config: changeset.UpdateOnRampDestsConfig{
UpdatesByChain: map[uint64]map[uint64]changeset.OnRampDestinationUpdate{
from: {
to: {
IsEnabled: true,
TestRouter: false,
AllowListEnabled: false,
},
},
},
},
},
{
Changeset: commonchangeset.WrapChangeSet(changeset.UpdateFeeQuoterPricesCS),
Config: changeset.UpdateFeeQuoterPricesConfig{
InitialPrices: map[uint64]changeset.FeeQuoterPriceUpdatePerSource{
from: {
TokenPrices: map[common.Address]*big.Int{
stateChain1.LinkToken.Address(): changeset.DefaultLinkPrice,
stateChain1.Weth9.Address(): changeset.DefaultWethPrice,
},
GasPrices: map[uint64]*big.Int{
to: changeset.DefaultGasPrice,
},
},
},
},
},
{
Changeset: commonchangeset.WrapChangeSet(changeset.UpdateFeeQuoterDests),
Config: changeset.UpdateFeeQuoterDestsConfig{
UpdatesByChain: map[uint64]map[uint64]fee_quoter.FeeQuoterDestChainConfig{
from: {
to: changeset.DefaultFeeQuoterDestChainConfig(),
},
},
},
},
{
Changeset: commonchangeset.WrapChangeSet(changeset.UpdateOffRampSources),
Config: changeset.UpdateOffRampSourcesConfig{
UpdatesByChain: map[uint64]map[uint64]changeset.OffRampSourceUpdate{
to: {
from: {
IsEnabled: true,
TestRouter: true,
},
},
},
},
},
{
Changeset: commonchangeset.WrapChangeSet(changeset.UpdateRouterRamps),
Config: changeset.UpdateRouterRampsConfig{
TestRouter: true,
UpdatesByChain: map[uint64]changeset.RouterUpdates{
// onRamp update on source chain
from: {
OnRampUpdates: map[uint64]bool{
to: true,
},
},
// off
from: {
OffRampUpdates: map[uint64]bool{
to: true,
},
},
},
},
},
})
if err != nil {
return DeployCCIPOutput{}, fmt.Errorf("failed to apply changesets: %w", err)
}
e = &newEnv
}
}
}

addresses, err := e.ExistingAddresses.Addresses()
Expand Down
22 changes: 11 additions & 11 deletions integration-tests/contracts/ccipreader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,8 +597,8 @@ func TestCCIPReader_GetExpectedNextSequenceNumber(t *testing.T) {
selectors := env.Env.AllChainSelectors()
destChain, srcChain := selectors[0], selectors[1]

require.NoError(t, changeset.AddLaneWithDefaultPricesAndFeeQuoterConfig(env.Env, state, destChain, srcChain, false))
require.NoError(t, changeset.AddLaneWithDefaultPricesAndFeeQuoterConfig(env.Env, state, srcChain, destChain, false))
changeset.AddLaneWithDefaultPricesAndFeeQuoterConfig(t, &env, state, destChain, srcChain, false)
changeset.AddLaneWithDefaultPricesAndFeeQuoterConfig(t, &env, state, srcChain, destChain, false)

reader := testSetupRealContracts(
ctx,
Expand Down Expand Up @@ -707,8 +707,8 @@ func Test_GetChainFeePriceUpdates(t *testing.T) {
selectors := env.Env.AllChainSelectors()
chain1, chain2 := selectors[0], selectors[1]

require.NoError(t, changeset.AddLaneWithDefaultPricesAndFeeQuoterConfig(env.Env, state, chain1, chain2, false))
require.NoError(t, changeset.AddLaneWithDefaultPricesAndFeeQuoterConfig(env.Env, state, chain2, chain1, false))
changeset.AddLaneWithDefaultPricesAndFeeQuoterConfig(t, &env, state, chain1, chain2, false)
changeset.AddLaneWithDefaultPricesAndFeeQuoterConfig(t, &env, state, chain2, chain1, false)

// Change the gas price for chain2
feeQuoter := state.Chains[chain1].FeeQuoter
Expand Down Expand Up @@ -763,8 +763,8 @@ func Test_LinkPriceUSD(t *testing.T) {
selectors := env.Env.AllChainSelectors()
chain1, chain2 := selectors[0], selectors[1]

require.NoError(t, changeset.AddLaneWithDefaultPricesAndFeeQuoterConfig(env.Env, state, chain1, chain2, false))
require.NoError(t, changeset.AddLaneWithDefaultPricesAndFeeQuoterConfig(env.Env, state, chain2, chain1, false))
changeset.AddLaneWithDefaultPricesAndFeeQuoterConfig(t, &env, state, chain1, chain2, false)
changeset.AddLaneWithDefaultPricesAndFeeQuoterConfig(t, &env, state, chain2, chain1, false)

reader := testSetupRealContracts(
ctx,
Expand Down Expand Up @@ -798,9 +798,9 @@ func Test_GetMedianDataAvailabilityGasConfig(t *testing.T) {
selectors := env.Env.AllChainSelectors()
destChain, chain1, chain2, chain3 := selectors[0], selectors[1], selectors[2], selectors[3]

require.NoError(t, changeset.AddLaneWithDefaultPricesAndFeeQuoterConfig(env.Env, state, chain1, destChain, false))
require.NoError(t, changeset.AddLaneWithDefaultPricesAndFeeQuoterConfig(env.Env, state, chain2, destChain, false))
require.NoError(t, changeset.AddLaneWithDefaultPricesAndFeeQuoterConfig(env.Env, state, chain3, destChain, false))
changeset.AddLaneWithDefaultPricesAndFeeQuoterConfig(t, &env, state, chain1, destChain, false)
changeset.AddLaneWithDefaultPricesAndFeeQuoterConfig(t, &env, state, chain2, destChain, false)
changeset.AddLaneWithDefaultPricesAndFeeQuoterConfig(t, &env, state, chain3, destChain, false)

boundContracts := map[cciptypes.ChainSelector][]types.BoundContract{}
for i, selector := range env.Env.AllChainSelectorsExcluding([]uint64{destChain}) {
Expand Down Expand Up @@ -857,8 +857,8 @@ func Test_GetWrappedNativeTokenPriceUSD(t *testing.T) {
selectors := env.Env.AllChainSelectors()
chain1, chain2 := selectors[0], selectors[1]

require.NoError(t, changeset.AddLaneWithDefaultPricesAndFeeQuoterConfig(env.Env, state, chain1, chain2, false))
require.NoError(t, changeset.AddLaneWithDefaultPricesAndFeeQuoterConfig(env.Env, state, chain2, chain1, false))
changeset.AddLaneWithDefaultPricesAndFeeQuoterConfig(t, &env, state, chain1, chain2, false)
changeset.AddLaneWithDefaultPricesAndFeeQuoterConfig(t, &env, state, chain2, chain1, false)

reader := testSetupRealContracts(
ctx,
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/smoke/ccip/ccip_batching_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ func newBatchTestSetup(t *testing.T) batchTestSetup {
)

// connect sourceChain1 and sourceChain2 to destChain
require.NoError(t, changeset.AddLaneWithDefaultPricesAndFeeQuoterConfig(e.Env, state, sourceChain1, destChain, false))
require.NoError(t, changeset.AddLaneWithDefaultPricesAndFeeQuoterConfig(e.Env, state, sourceChain2, destChain, false))
changeset.AddLaneWithDefaultPricesAndFeeQuoterConfig(t, &e, state, sourceChain1, destChain, false)
changeset.AddLaneWithDefaultPricesAndFeeQuoterConfig(t, &e, state, sourceChain2, destChain, false)

return batchTestSetup{e, state, sourceChain1, sourceChain2, destChain}
}
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/smoke/ccip/ccip_fees_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func Test_CCIPFees(t *testing.T) {
changeset.ReplayLogs(t, e.Offchain, tenv.ReplayBlocks)

// Add all lanes
require.NoError(t, changeset.AddLanesForAll(e, state))
changeset.AddLanesForAll(t, &tenv, state)

t.Run("Send programmable token transfer pay with Link token", func(t *testing.T) {
runFeeTokenTestCase(feeTokenTestCase{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func Test_CCIPGasPriceUpdates(t *testing.T) {
)
state, err := changeset.LoadOnchainState(e.Env)
require.NoError(t, err)
require.NoError(t, changeset.AddLanesForAll(e.Env, state))
changeset.AddLanesForAll(t, &e, state)

allChainSelectors := maps.Keys(e.Env.Chains)
assert.GreaterOrEqual(t, len(allChainSelectors), 2, "test requires at least 2 chains")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func Test_CCIPMessageLimitations(t *testing.T) {
onChainState, err := changeset.LoadOnchainState(testEnv.Env)
require.NoError(t, err)

require.NoError(t, changeset.AddLanesForAll(testEnv.Env, onChainState))
changeset.AddLanesForAll(t, &testEnv, onChainState)

srcToken, _ := setupTokens(
t,
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/smoke/ccip/ccip_messaging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func Test_CCIPMessaging(t *testing.T) {
", dest chain selector:", destChain,
)
// connect a single lane, source to dest
require.NoError(t, changeset.AddLaneWithDefaultPricesAndFeeQuoterConfig(e.Env, state, sourceChain, destChain, false))
changeset.AddLaneWithDefaultPricesAndFeeQuoterConfig(t, &e, state, sourceChain, destChain, false)

var (
replayed bool
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/smoke/ccip/ccip_ooo_execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func Test_OutOfOrderExecution(t *testing.T) {
},
},
)
require.NoError(t, changeset.AddLanesForAll(e, state))
changeset.AddLanesForAll(t, &tenv, state)

tokenTransfer := []router.ClientEVMTokenAmount{
{
Expand Down
Loading

0 comments on commit 4afbdb5

Please sign in to comment.