-
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 - new integration tests #15473
Merged
Merged
ccip - new integration tests #15473
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b0fdf3b
token price / chain fee price updates e2e tests
dimkouv 636e79c
test ccip msg limitations
dimkouv 7ff44e2
enable the tests in ci
dimkouv b569433
individual test cases
dimkouv 52d41b2
fix ci
dimkouv 258f53e
fix flakyiness of Test_CCIPTokenPriceUpdates
dimkouv 6f29f3a
fix gas price updates test
dimkouv 7eccb6d
mateusz code review
dimkouv 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
126 changes: 126 additions & 0 deletions
126
integration-tests/smoke/ccip/ccip_gas_price_updates_test.go
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,126 @@ | ||
package smoke | ||
|
||
import ( | ||
"math/big" | ||
"testing" | ||
"time" | ||
|
||
"github.com/ethereum/go-ethereum/accounts/abi/bind" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"golang.org/x/exp/maps" | ||
|
||
"github.com/smartcontractkit/chainlink-common/pkg/config" | ||
"github.com/smartcontractkit/chainlink-common/pkg/utils/tests" | ||
"github.com/smartcontractkit/chainlink/deployment" | ||
"github.com/smartcontractkit/chainlink/deployment/ccip/changeset" | ||
testsetups "github.com/smartcontractkit/chainlink/integration-tests/testsetups/ccip" | ||
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/fee_quoter" | ||
"github.com/smartcontractkit/chainlink/v2/core/logger" | ||
) | ||
|
||
// Test_CCIPGasPriceUpdates tests that chain fee price updates are propagated correctly when | ||
// price reaches some deviation threshold or when the price has expired. | ||
func Test_CCIPGasPriceUpdates(t *testing.T) { | ||
lggr := logger.TestLogger(t) | ||
ctx := changeset.Context(t) | ||
callOpts := &bind.CallOpts{Context: ctx} | ||
|
||
var gasPriceExpiry = 5 * time.Second | ||
e, _, _ := testsetups.NewLocalDevEnvironmentWithDefaultPrice(t, lggr, &changeset.TestConfigs{ | ||
OCRConfigOverride: func(params changeset.CCIPOCRParams) changeset.CCIPOCRParams { | ||
params.CommitOffChainConfig.RemoteGasPriceBatchWriteFrequency = *config.MustNewDuration(gasPriceExpiry) | ||
return params | ||
}, | ||
}) | ||
state, err := changeset.LoadOnchainState(e.Env) | ||
require.NoError(t, err) | ||
require.NoError(t, changeset.AddLanesForAll(e.Env, state)) | ||
|
||
allChainSelectors := maps.Keys(e.Env.Chains) | ||
assert.GreaterOrEqual(t, len(allChainSelectors), 2, "test requires at least 2 chains") | ||
|
||
sourceChain1 := allChainSelectors[0] | ||
sourceChain2 := allChainSelectors[1] | ||
|
||
feeQuoter1 := state.Chains[sourceChain1].FeeQuoter | ||
feeQuoter2 := state.Chains[sourceChain2].FeeQuoter | ||
|
||
// get initial chain fees | ||
initialChain2Fee, err := feeQuoter1.GetDestinationChainGasPrice(callOpts, sourceChain2) | ||
require.NoError(t, err) | ||
initialChain1Fee, err := feeQuoter2.GetDestinationChainGasPrice(callOpts, sourceChain1) | ||
require.NoError(t, err) | ||
t.Logf("initial chain1 fee (stored in chain2): %v", initialChain1Fee) | ||
t.Logf("initial chain2 fee (stored in chain1): %v", initialChain2Fee) | ||
|
||
// get latest price updates sequence number from the offRamps | ||
offRampChain1 := state.Chains[sourceChain1].OffRamp | ||
offRampChain2 := state.Chains[sourceChain2].OffRamp | ||
priceUpdatesSeqNumChain1, err := offRampChain1.GetLatestPriceSequenceNumber(callOpts) | ||
require.NoError(t, err) | ||
priceUpdatesSeqNumChain2, err := offRampChain2.GetLatestPriceSequenceNumber(callOpts) | ||
require.NoError(t, err) | ||
t.Logf("priceUpdatesSeqNumChain1: %v", priceUpdatesSeqNumChain1) | ||
t.Logf("priceUpdatesSeqNumChain2: %v", priceUpdatesSeqNumChain2) | ||
|
||
// update the price of chain2 | ||
tx, err := feeQuoter1.UpdatePrices(e.Env.Chains[sourceChain1].DeployerKey, fee_quoter.InternalPriceUpdates{ | ||
TokenPriceUpdates: nil, | ||
GasPriceUpdates: []fee_quoter.InternalGasPriceUpdate{ | ||
{DestChainSelector: sourceChain2, UsdPerUnitGas: big.NewInt(5123)}, | ||
}, | ||
}) | ||
require.NoError(t, err) | ||
_, err = deployment.ConfirmIfNoError(e.Env.Chains[sourceChain1], tx, err) | ||
require.NoError(t, err) | ||
|
||
// assert that the chain fees are updated by the commit plugin reports | ||
priceDeviationChecked := false // flag to check if price deviation condition was met | ||
assert.Eventually(t, func() bool { | ||
// offRamps should have updated the sequence number | ||
priceUpdatesSeqNumChain1Now, err := offRampChain1.GetLatestPriceSequenceNumber(callOpts) | ||
require.NoError(t, err) | ||
priceUpdatesSeqNumChain2Now, err := offRampChain2.GetLatestPriceSequenceNumber(callOpts) | ||
require.NoError(t, err) | ||
t.Logf("priceUpdatesSeqNumChain1: %v", priceUpdatesSeqNumChain1Now) | ||
t.Logf("priceUpdatesSeqNumChain2: %v", priceUpdatesSeqNumChain2Now) | ||
if priceUpdatesSeqNumChain1Now <= priceUpdatesSeqNumChain1 { | ||
return false | ||
} | ||
if priceUpdatesSeqNumChain2Now <= priceUpdatesSeqNumChain2 { | ||
return false | ||
} | ||
|
||
chain2FeeNow, err := feeQuoter1.GetDestinationChainGasPrice(callOpts, sourceChain2) | ||
require.NoError(t, err) | ||
chain1FeeNow, err := feeQuoter2.GetDestinationChainGasPrice(callOpts, sourceChain1) | ||
require.NoError(t, err) | ||
t.Logf("chainFee1 (stored in chain2): %v", chain1FeeNow) | ||
t.Logf("chainFee2 (stored in chain1): %v", chain2FeeNow) | ||
|
||
if !priceDeviationChecked { | ||
// make sure there was a price update for chain2 when price deviation was reached | ||
if chain2FeeNow.Value.Cmp(initialChain2Fee.Value) == 0 { | ||
t.Logf("chainFee2 not updated: %v original=%v", chain2FeeNow, initialChain2Fee.Value) | ||
return false | ||
} | ||
require.NotEqual(t, chain2FeeNow.Timestamp, initialChain2Fee.Timestamp) | ||
priceDeviationChecked = true | ||
} | ||
|
||
// make sure there was a price update for chain1 but with the same price - when expiration is reached | ||
if chain1FeeNow.Timestamp == initialChain1Fee.Timestamp { | ||
t.Logf("chainFee1 timestamp not updated: %v original=%v", chain1FeeNow, initialChain1Fee.Timestamp) | ||
initialChain1Fee = chain1FeeNow | ||
return false | ||
} | ||
if chain1FeeNow.Value.Cmp(initialChain1Fee.Value) != 0 { | ||
t.Logf("chainFee1 changed: %v prev:%v", chain1FeeNow, initialChain1Fee.Value) | ||
initialChain1Fee = chain1FeeNow | ||
return false | ||
} | ||
|
||
return priceDeviationChecked | ||
}, tests.WaitTimeout(t), 500*time.Millisecond) | ||
} |
Oops, something went wrong.
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.
No need to define 3 chains if you need only 2 of them. Let's keep only as many chains as we need for tests, that will make them faster
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 guess same applied to other tests