-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
83533b9
CCIP-4948: Adding new test for disable and enable lane
b-gopalswami 48c7cb7
Merge branch 'develop' of github.com:smartcontractkit/chainlink into …
b-gopalswami bbc49ec
Merge branch 'develop' of github.com:smartcontractkit/chainlink into …
b-gopalswami 0824a15
Send request before disabling the lane
b-gopalswami 093222d
lint fix
b-gopalswami ed042b6
Merge branch 'develop' of github.com:smartcontractkit/chainlink into …
b-gopalswami 2a3a956
revert gethwrappers change
b-gopalswami 0ad73f4
review comments
b-gopalswami 2dbae80
Disabling fee quoter as well
b-gopalswami d957762
fix test
b-gopalswami 769e9b2
fix lint
b-gopalswami 193de02
review comments
b-gopalswami File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
package ccip | ||
|
||
import ( | ||
"math/big" | ||
"testing" | ||
|
||
"github.com/ethereum/go-ethereum/accounts/abi/bind" | ||
"github.com/ethereum/go-ethereum/common" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/smartcontractkit/chainlink-common/pkg/utils/tests" | ||
"github.com/smartcontractkit/chainlink-testing-framework/lib/utils/testcontext" | ||
"github.com/smartcontractkit/chainlink/deployment" | ||
"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 and in-flight requests are delivered. | ||
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 []testhelpers.SourceDestPair | ||
linkPrice = deployment.E18Mult(100) | ||
wethPrice = deployment.E18Mult(4000) | ||
noOfRequests = 3 | ||
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 | ||
pairs = append(pairs, testhelpers.SourceDestPair{ | ||
SourceChainSelector: chainA, | ||
DestChainSelector: chainB, | ||
}) | ||
testhelpers.RemoveLane(t, &tenv, chainA, chainB, false) | ||
// send a message to confirm it is reverted between A -> B | ||
assertSendRequestReverted(chainA, chainB, e.Chains[chainA].Users[0]) | ||
|
||
// send a message in other direction B -> A to confirm it is delivered | ||
assertRequestSent(chainB, chainA, e.Chains[chainB].Users[0]) | ||
testhelpers.ConfirmExecWithSeqNrsForAll(t, e, state, expectedSeqNumExec, startBlocks) | ||
|
||
// send a multiple message between A -> C and disable the lane while the requests are in-flight | ||
expectedSeqNumExec = make(map[testhelpers.SourceDestPair][]uint64) | ||
for range noOfRequests { | ||
assertRequestSent(chainA, chainC, e.Chains[chainA].Users[1]) | ||
} | ||
// disable lane A -> C while requests are getting sent in that lane | ||
pairs = append(pairs, testhelpers.SourceDestPair{ | ||
SourceChainSelector: chainA, | ||
DestChainSelector: chainC, | ||
}) | ||
testhelpers.RemoveLane(t, &tenv, chainA, chainC, false) | ||
b-gopalswami marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// confirm all in-flight messages are delivered in A -> C lane | ||
testhelpers.ConfirmExecWithSeqNrsForAll(t, e, state, expectedSeqNumExec, startBlocks) | ||
|
||
// now, as the lane is disabled, confirm that message sent in A -> C is reverted | ||
assertSendRequestReverted(chainA, chainC, e.Chains[chainA].Users[0]) | ||
|
||
// check getting token and gas price form fee quoter returns error when A -> C lane is disabled | ||
gp, err := state.Chains[chainA].FeeQuoter.GetTokenAndGasPrices(&bind.CallOpts{ | ||
Context: tests.Context(t), | ||
}, state.Chains[chainC].Weth9.Address(), chainC) | ||
require.Error(t, err) | ||
require.Contains(t, err.Error(), "execution reverted") | ||
require.Nil(t, gp.GasPriceValue) | ||
require.Nil(t, gp.TokenPrice) | ||
|
||
// re-enable all the disabled lanes | ||
for _, pair := range pairs { | ||
testhelpers.AddLane(t, &tenv, pair.SourceChainSelector, pair.DestChainSelector, false, | ||
map[uint64]*big.Int{ | ||
pair.DestChainSelector: testhelpers.DefaultGasPrice, | ||
}, | ||
map[common.Address]*big.Int{ | ||
state.Chains[pair.SourceChainSelector].LinkToken.Address(): linkPrice, | ||
state.Chains[pair.SourceChainSelector].Weth9.Address(): wethPrice, | ||
}, | ||
changeset.DefaultFeeQuoterDestChainConfig(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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
chainlink/contracts/src/v0.8/ccip/offRamp/OffRamp.sol
Line 994 in ba148ac
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
chainlink/deployment/ccip/changeset/cs_chain_contracts.go
Line 718 in 48c7cb7