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

CCIP-4948: Adding new test for disable and enable lane #16038

Merged
merged 12 commits into from
Jan 28, 2025
10 changes: 4 additions & 6 deletions deployment/ccip/changeset/cs_chain_contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -706,12 +706,10 @@ func UpdateOffRampSourcesChangeset(e deployment.Environment, cfg UpdateOffRampSo
var args []offramp.OffRampSourceChainConfigArgs
for source, update := range updates {
router := common.HexToAddress("0x0")
if update.IsEnabled {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

router can't be 0x0 address as Offramp expects valid router address ow it will throw ZeroAddressNotAllowed error message.

revert ZeroAddressNotAllowed();

Copy link
Contributor

Choose a reason for hiding this comment

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

If it's not possible to disable a router in offRamp, the parameter IsEnabled should be removed

Copy link
Contributor Author

@b-gopalswami b-gopalswami Jan 27, 2025

Choose a reason for hiding this comment

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

I think it is still needed to make here

IsEnabled: update.IsEnabled,

if update.TestRouter {
router = s.Chains[chainSel].TestRouter.Address()
} else {
router = s.Chains[chainSel].Router.Address()
}
if update.TestRouter {
router = s.Chains[chainSel].TestRouter.Address()
} else {
router = s.Chains[chainSel].Router.Address()
}
onRamp := s.Chains[source].OnRamp
args = append(args, offramp.OffRampSourceChainConfigArgs{
Expand Down
39 changes: 39 additions & 0 deletions deployment/ccip/changeset/testhelpers/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,45 @@ func AddLane(
require.NoError(t, err)
}

func UpdateLane(
b-gopalswami marked this conversation as resolved.
Show resolved Hide resolved
t *testing.T,
e *DeployedEnv,
from, to uint64,
isTestRouter, isEnabled bool,
) {
var err error
var apps []commoncs.ChangesetApplication
apps = append(apps, commoncs.ChangesetApplication{
b-gopalswami marked this conversation as resolved.
Show resolved Hide resolved
Changeset: commoncs.WrapChangeSet(changeset.UpdateOnRampsDestsChangeset),
Config: changeset.UpdateOnRampDestsConfig{
UpdatesByChain: map[uint64]map[uint64]changeset.OnRampDestinationUpdate{
from: {
to: {
IsEnabled: isEnabled,
TestRouter: isTestRouter,
AllowListEnabled: false,
},
},
},
},
})
apps = append(apps, commoncs.ChangesetApplication{
Changeset: commoncs.WrapChangeSet(changeset.UpdateOffRampSourcesChangeset),
Config: changeset.UpdateOffRampSourcesConfig{
UpdatesByChain: map[uint64]map[uint64]changeset.OffRampSourceUpdate{
to: {
from: {
IsEnabled: isEnabled,
TestRouter: isTestRouter,
},
},
},
},
})
e.Env, err = commoncs.ApplyChangesets(t, e.Env, e.TimelockContracts(t), apps)
require.NoError(t, err)
}

func AddLaneWithDefaultPricesAndFeeQuoterConfig(t *testing.T, e *DeployedEnv, state changeset.CCIPOnChainState, from, to uint64, isTestRouter bool) {
stateChainFrom := state.Chains[from]
AddLane(
Expand Down
114 changes: 114 additions & 0 deletions integration-tests/smoke/ccip/ccip_update_lane_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package ccip

import (
"testing"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"

"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink-testing-framework/lib/utils/testcontext"
"github.com/smartcontractkit/chainlink/deployment/ccip/changeset"
"github.com/smartcontractkit/chainlink/deployment/ccip/changeset/testhelpers"
testsetups "github.com/smartcontractkit/chainlink/integration-tests/testsetups/ccip"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/onramp"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/router"
)

// Intention of this test is to ensure that the lane can be disabled and enabled correctly without disrupting the other lanes.
func TestDisableLane(t *testing.T) {
tenv, _, _ := testsetups.NewIntegrationEnvironment(t,
testhelpers.WithNumOfChains(3),
testhelpers.WithNumOfUsersPerChain(2),
)

e := tenv.Env
state, err := changeset.LoadOnchainState(e)
require.NoError(t, err)

// add all lanes
testhelpers.AddLanesForAll(t, &tenv, state)

var (
chains = e.AllChainSelectors()
chainA, chainB, chainC = chains[0], chains[1], chains[2]
expectedSeqNumExec = make(map[testhelpers.SourceDestPair][]uint64)
startBlocks = make(map[uint64]*uint64)
pairs = testsetups.GetSourceDestPairs([]uint64{chainA, chainB, chainC})

sendmessage = func(src, dest uint64, deployer *bind.TransactOpts) (*onramp.OnRampCCIPMessageSent, error) {
return testhelpers.DoSendRequest(
t,
e,
state,
testhelpers.WithSender(deployer),
testhelpers.WithSourceChain(src),
testhelpers.WithDestChain(dest),
testhelpers.WithTestRouter(false),
testhelpers.WithEvm2AnyMessage(router.ClientEVM2AnyMessage{
Receiver: common.LeftPadBytes(state.Chains[chainB].Receiver.Address().Bytes(), 32),
Data: []byte("hello"),
TokenAmounts: nil,
FeeToken: common.HexToAddress("0x0"),
ExtraArgs: nil,
}))
}

assertSendRequestReverted = func(src, dest uint64, deployer *bind.TransactOpts) {
_, err = sendmessage(src, dest, deployer)
require.Error(t, err)
require.Contains(t, err.Error(), "execution reverted")
}

assertRequestSent = func(src, dest uint64, deployer *bind.TransactOpts) {
latestHeader, err := e.Chains[dest].Client.HeaderByNumber(testcontext.Get(t), nil)
require.NoError(t, err)
block := latestHeader.Number.Uint64()
messageSentEvent, err := sendmessage(src, dest, e.Chains[src].DeployerKey)
require.NoError(t, err)
expectedSeqNumExec[testhelpers.SourceDestPair{
SourceChainSelector: src,
DestChainSelector: dest,
}] = []uint64{messageSentEvent.SequenceNumber}
startBlocks[dest] = &block
}
)

// disable lane A -> B
testhelpers.UpdateLane(t, &tenv, chainA, chainB, false, false)
// send a message to confirm it is reverted between chainA and chainB
assertSendRequestReverted(chainA, chainB, e.Chains[chainA].Users[0])
// send a message between chainB and chainA to confirm it is not reverted
assertRequestSent(chainB, chainA, e.Chains[chainB].Users[0])
// disable lane B -> A
testhelpers.UpdateLane(t, &tenv, chainB, chainA, false, false)
assertSendRequestReverted(chainB, chainA, e.Chains[chainB].Users[0])

// send message in other lanes and ensure they are delivered
go func() {
assertRequestSent(chainA, chainC, e.Chains[chainA].Users[1])
assertRequestSent(chainC, chainA, e.Chains[chainC].Users[1])
assertRequestSent(chainB, chainC, e.Chains[chainB].Users[1])
assertRequestSent(chainC, chainB, e.Chains[chainC].Users[1])
}()
// disable lanes between A & C and C & B while requests are getting sent
testhelpers.UpdateLane(t, &tenv, chainA, chainC, false, false)
testhelpers.UpdateLane(t, &tenv, chainC, chainA, false, false)
testhelpers.UpdateLane(t, &tenv, chainB, chainC, false, false)
testhelpers.UpdateLane(t, &tenv, chainC, chainB, false, false)
// confirm that message sent in all lanes are reverted after disabling the lanes
for _, pair := range pairs {
assertSendRequestReverted(pair.SourceChainSelector, pair.DestChainSelector, e.Chains[pair.SourceChainSelector].Users[0])
}
// re-enable all the lanes
for _, pair := range pairs {
testhelpers.UpdateLane(t, &tenv, pair.SourceChainSelector, pair.DestChainSelector, false, true)
}
// send a message in all the lane including re-enabled lanes
for _, pair := range pairs {
assertRequestSent(pair.SourceChainSelector, pair.DestChainSelector, e.Chains[pair.SourceChainSelector].Users[0])
}
// confirm all messages are delivered
testhelpers.ConfirmExecWithSeqNrsForAll(t, e, state, expectedSeqNumExec, startBlocks)
}
15 changes: 15 additions & 0 deletions integration-tests/testsetups/ccip/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -721,3 +721,18 @@ func SetNodeConfig(nets []blockchain.EVMNetwork, nodeConfig, commonChain string,
tomlStr, err := tomlCfg.TOMLString()
return tomlCfg, tomlStr, err
}

func GetSourceDestPairs(chains []uint64) []testhelpers.SourceDestPair {
var pairs []testhelpers.SourceDestPair
for i, src := range chains {
for j, dest := range chains {
if i != j {
pairs = append(pairs, testhelpers.SourceDestPair{
SourceChainSelector: src,
DestChainSelector: dest,
})
}
}
}
return pairs
}
Loading