-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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-5118] Refactor Test_CCIPMessageLimitations logic into helper pkg #16680
Open
NourElRashidy
wants to merge
9
commits into
develop
Choose a base branch
from
CCIP-5118-cont
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+213
−76
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
244870d
Refactor test logic into helper pkg
NourElRashidy 77fcacb
go mod tidy
NourElRashidy 85ceff8
fix bug
NourElRashidy ba4db98
Fix import path
NourElRashidy 859a963
go mod tidy
NourElRashidy 562e33f
Refactor Test_CCIPMessageLimitations to use test helpers
NourElRashidy 53640bc
fix imports order
NourElRashidy 69f9a24
WIP fix test
NourElRashidy 1dc8a91
Fix tests
NourElRashidy 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
127 changes: 127 additions & 0 deletions
127
deployment/ccip/changeset/testhelpers/messagelimitationstest/helpers.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,127 @@ | ||
package messagelimitationstest | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/smartcontractkit/chainlink/deployment" | ||
"github.com/smartcontractkit/chainlink/deployment/ccip/changeset" | ||
"github.com/smartcontractkit/chainlink/deployment/ccip/changeset/testhelpers" | ||
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/v1_2_0/router" | ||
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/v1_6_0/fee_quoter" | ||
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/v1_6_0/onramp" | ||
) | ||
|
||
// Use this when testhelpers.DeployedEnv is available (usually in ephemeral test environments). | ||
func NewTestSetupWithDeployedEnv( | ||
t *testing.T, | ||
depEnv testhelpers.DeployedEnv, | ||
onchainState changeset.CCIPOnChainState, | ||
sourceChain, | ||
destChain uint64, | ||
srctoken common.Address, | ||
srcFeeQuoterDestChainConfig fee_quoter.FeeQuoterDestChainConfig, | ||
testRouter, | ||
validateResp bool, | ||
) TestSetup { | ||
return TestSetup{ | ||
T: t, | ||
Env: depEnv.Env, | ||
DeployedEnv: &depEnv, | ||
OnchainState: onchainState, | ||
SrcChain: sourceChain, | ||
DestChain: destChain, | ||
SrcToken: srctoken, | ||
SrcFeeQuoterDestChainConfig: srcFeeQuoterDestChainConfig, | ||
TestRouter: testRouter, | ||
ValidateResp: validateResp, | ||
} | ||
} | ||
|
||
// Use this when testhelpers.DeployedEnv is not available (usually in long-running test environments like staging). | ||
func NewTestSetup( | ||
t *testing.T, | ||
env deployment.Environment, | ||
onchainState changeset.CCIPOnChainState, | ||
sourceChain, | ||
destChain uint64, | ||
srctoken common.Address, | ||
srcFeeQuoterDestChainConfig fee_quoter.FeeQuoterDestChainConfig, | ||
testRouter, | ||
validateResp bool, | ||
) TestSetup { | ||
return TestSetup{ | ||
T: t, | ||
Env: env, | ||
// no DeployedEnv | ||
OnchainState: onchainState, | ||
SrcChain: sourceChain, | ||
DestChain: destChain, | ||
SrcToken: srctoken, | ||
SrcFeeQuoterDestChainConfig: srcFeeQuoterDestChainConfig, | ||
TestRouter: testRouter, | ||
ValidateResp: validateResp, | ||
} | ||
} | ||
|
||
type TestSetup struct { | ||
T *testing.T | ||
Env deployment.Environment | ||
DeployedEnv *testhelpers.DeployedEnv | ||
OnchainState changeset.CCIPOnChainState | ||
SrcChain uint64 | ||
DestChain uint64 | ||
SrcToken common.Address | ||
SrcFeeQuoterDestChainConfig fee_quoter.FeeQuoterDestChainConfig | ||
TestRouter bool | ||
ValidateResp bool | ||
} | ||
|
||
type TestCase struct { | ||
TestSetup | ||
Name string | ||
Msg router.ClientEVM2AnyMessage | ||
ExpRevert bool | ||
} | ||
|
||
type TestCaseOutput struct { | ||
MsgSentEvent *onramp.OnRampCCIPMessageSent | ||
} | ||
|
||
func Run(tc TestCase) TestCaseOutput { | ||
Comment on lines
+89
to
+93
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LGTM, can we use this helper struct + method in the current message limitations test as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this is the one item I have left in the TODOs. |
||
tc.T.Logf("Sending msg: %s", tc.Name) | ||
require.NotEqual(tc.T, tc.SrcChain, tc.DestChain, "fromChain and toChain cannot be the same") | ||
|
||
// Approve router to send token only on long-running environments | ||
if tc.DeployedEnv == nil && tc.SrcToken != (common.Address{}) { | ||
routerAddress := tc.OnchainState.Chains[tc.SrcChain].Router.Address() | ||
if tc.TestRouter { | ||
routerAddress = tc.OnchainState.Chains[tc.SrcChain].TestRouter.Address() | ||
} | ||
err := testhelpers.ApproveToken(tc.Env, tc.SrcChain, tc.SrcToken, routerAddress, testhelpers.OneCoin) | ||
require.NoError(tc.T, err) | ||
} | ||
|
||
msgSentEvent, err := testhelpers.DoSendRequest( | ||
tc.T, tc.Env, tc.OnchainState, | ||
testhelpers.WithSourceChain(tc.SrcChain), | ||
testhelpers.WithDestChain(tc.DestChain), | ||
testhelpers.WithTestRouter(tc.TestRouter), | ||
testhelpers.WithEvm2AnyMessage(tc.Msg)) | ||
|
||
if tc.ExpRevert { | ||
tc.T.Logf("Message reverted as expected") | ||
require.Error(tc.T, err) | ||
require.Contains(tc.T, err.Error(), "execution reverted") | ||
return TestCaseOutput{} | ||
} | ||
require.NoError(tc.T, err) | ||
|
||
tc.T.Logf("Message not reverted as expected") | ||
|
||
return TestCaseOutput{ | ||
MsgSentEvent: msgSentEvent, | ||
} | ||
} |
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.
nit: how about using functional opts here?