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

Add support for custom bridge tokens in bidirectional CCIP test setup #50

Merged
merged 3 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions integration-tests/actions/ccip_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,9 @@ func (ccipModule *CCIPCommon) CleanUp() error {

// DeployContracts deploys the contracts which are necessary in both source and dest chain
// This reuses common contracts for bidirectional lanes
func (ccipModule *CCIPCommon) DeployContracts(noOfTokens int, conf *laneconfig.LaneConfig) error {
func (ccipModule *CCIPCommon) DeployContracts(noOfTokens int,
tokenDeployerFns []blockchain.ContractDeployer,
conf *laneconfig.LaneConfig) error {
var err error
cd := ccipModule.Deployer

Expand Down Expand Up @@ -360,7 +362,13 @@ func (ccipModule *CCIPCommon) DeployContracts(noOfTokens int, conf *laneconfig.L
if len(ccipModule.BridgeTokens) == 0 {
// deploy bridge token.
for i := len(ccipModule.BridgeTokens); i < noOfTokens; i++ {
token, err := cd.DeployLinkTokenContract()
var token *ccip.LinkToken
var err error
if len(tokenDeployerFns) != noOfTokens {
token, err = cd.DeployLinkTokenContract()
} else {
token, err = cd.DeployERC20TokenContract(tokenDeployerFns[i])
}
if err != nil {
return fmt.Errorf("deploying bridge token contract shouldn't fail %+v", err)
}
Expand Down Expand Up @@ -1764,6 +1772,7 @@ func (lane *CCIPLane) DeployNewCCIPLane(
sourceCommon *CCIPCommon,
destCommon *CCIPCommon,
transferAmounts []*big.Int,
tokenDeployerFns []blockchain.ContractDeployer,
newBootstrap bool,
configureCLNodes bool,
existingDeployment bool,
Expand Down Expand Up @@ -1796,11 +1805,11 @@ func (lane *CCIPLane) DeployNewCCIPLane(

// deploy all common contracts in parallel
lane.Source.Common.deploy.Go(func() error {
return lane.Source.Common.DeployContracts(len(lane.Source.TransferAmount), srcConf)
return lane.Source.Common.DeployContracts(len(lane.Source.TransferAmount), tokenDeployerFns, srcConf)
})

lane.Dest.Common.deploy.Go(func() error {
return lane.Dest.Common.DeployContracts(len(lane.Source.TransferAmount), destConf)
return lane.Dest.Common.DeployContracts(len(lane.Source.TransferAmount), tokenDeployerFns, destConf)
})

// deploy all source contracts
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/chaos/ccip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func TestChaosCCIP(t *testing.T) {

setUpArgs := testsetups.CCIPDefaultTestSetUp(
t, l, "chaos-ccip", 12, []*big.Int{big.NewInt(1e8)},
numOfCommitNodes, false, false, testCfg)
nil, numOfCommitNodes, false, false, testCfg)

if len(setUpArgs.Lanes) == 0 {
return
Expand Down
13 changes: 13 additions & 0 deletions integration-tests/contracts/ccip/contract_deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@ func (e *CCIPContractsDeployer) DeployLinkTokenContract() (*LinkToken, error) {
}, err
}

func (e *CCIPContractsDeployer) DeployERC20TokenContract(deployerFn blockchain.ContractDeployer) (*LinkToken, error) {
address, _, instance, err := e.evmClient.DeployContract("ERC20 Token", deployerFn)
if err != nil {
return nil, err
}

return &LinkToken{
client: e.evmClient,
instance: instance.(*link_token_interface.LinkToken),
EthAddress: *address,
}, err
}

func (e *CCIPContractsDeployer) NewLinkTokenContract(addr common.Address) (*LinkToken, error) {
token, err := link_token_interface.NewLinkToken(addr, e.evmClient.Backend())

Expand Down
4 changes: 2 additions & 2 deletions integration-tests/load/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (l *loadArgs) Setup(sameCommitAndExec bool) {
replicas = 12
}
setUpArgs = testsetups.CCIPDefaultTestSetUp(l.TestCfg.Test, lggr, "load-ccip",
replicas, transferAmounts, 5, sameCommitAndExec, true, l.TestCfg)
replicas, transferAmounts, nil, 5, sameCommitAndExec, true, l.TestCfg)
} else {
setUpArgs = testsetups.CCIPExistingDeploymentTestSetUp(l.TestCfg.Test, lggr, transferAmounts, true, l.TestCfg)
}
Expand Down Expand Up @@ -141,7 +141,7 @@ func (l *loadArgs) AddMoreLanesToRun() {
err := l.TestSetupArgs.AddLanesForNetworkPair(
l.lggr, n.NetworkA, n.NetworkB,
n.ChainClientA, n.ChainClientB,
transferAmounts, 5, true,
transferAmounts, nil, 5, true,
true, false)
assert.NoError(l.t, err)
l.LaneLoadCfg <- laneLoadCfg{
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/smoke/ccip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestSmokeCCIPForBidirectionalLane(t *testing.T) {
l := utils.GetTestLogger(t)
TestCfg := testsetups.NewCCIPTestConfig(t, l, testsetups.Smoke)
transferAmounts := []*big.Int{big.NewInt(1e14), big.NewInt(1e14)}
setUpOutput := testsetups.CCIPDefaultTestSetUp(t, l, "smoke-ccip", 6, transferAmounts, 5, true, true, TestCfg)
setUpOutput := testsetups.CCIPDefaultTestSetUp(t, l, "smoke-ccip", 6, transferAmounts, nil, 5, true, true, TestCfg)
var tcs []subtestInput
if len(setUpOutput.Lanes) == 0 {
return
Expand Down Expand Up @@ -77,7 +77,7 @@ func TestSmokeCCIPRateLimit(t *testing.T) {
require.Equal(t, actions.TokenTransfer, TestCfg.MsgType, "Test config should have token transfer message type")
transferAmounts := []*big.Int{big.NewInt(1e14)}
setUpOutput := testsetups.CCIPDefaultTestSetUp(
t, l, "smoke-ccip", 6, transferAmounts,
t, l, "smoke-ccip", 6, transferAmounts, nil,
5, true, false, TestCfg)
var tcs []subtestInput
if len(setUpOutput.Lanes) == 0 {
Expand Down
10 changes: 6 additions & 4 deletions integration-tests/testsetups/ccip.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ func (o *CCIPTestSetUpOutputs) AddLanesForNetworkPair(
networkA, networkB blockchain.EVMNetwork,
chainClientA, chainClientB blockchain.EVMClient,
transferAmounts []*big.Int,
tokenDeployerFns []blockchain.ContractDeployer,
numOfCommitNodes int,
commitAndExecOnSameDON, bidirectional bool,
newBootstrap bool,
Expand Down Expand Up @@ -528,7 +529,7 @@ func (o *CCIPTestSetUpOutputs) AddLanesForNetworkPair(
setUpFuncs.Go(func() error {
lggr.Info().Msgf("Setting up lane %s to %s", networkA.Name, networkB.Name)
err := ccipLaneA2B.DeployNewCCIPLane(numOfCommitNodes, commitAndExecOnSameDON, nil, nil,
transferAmounts, newBootstrap, configureCLNode, o.Cfg.ExistingDeployment)
transferAmounts, tokenDeployerFns, newBootstrap, configureCLNode, o.Cfg.ExistingDeployment)
if err != nil {
allErrors = multierr.Append(allErrors, fmt.Errorf("deploying lane %s to %s; err - %+v", networkA.Name, networkB.Name, err))
}
Expand All @@ -546,7 +547,7 @@ func (o *CCIPTestSetUpOutputs) AddLanesForNetworkPair(
destCommon := ccipLaneA2B.Source.Common.CopyAddresses(ccipLaneB2A.Context, ccipLaneB2A.DestChain, o.Cfg.ExistingDeployment)
lggr.Info().Msgf("Setting up lane %s to %s", networkB.Name, networkA.Name)
err := ccipLaneB2A.DeployNewCCIPLane(numOfCommitNodes, commitAndExecOnSameDON, srcCommon, destCommon,
transferAmounts, false, configureCLNode, o.Cfg.ExistingDeployment)
transferAmounts, tokenDeployerFns, false, configureCLNode, o.Cfg.ExistingDeployment)
if err != nil {
allErrors = multierr.Append(allErrors, fmt.Errorf("deploying lane %s to %s; err - %+v", networkB.Name, networkA.Name, err))
}
Expand Down Expand Up @@ -594,6 +595,7 @@ func CCIPDefaultTestSetUp(
envName string,
numOfCLNodes int64,
transferAmounts []*big.Int,
tokenDeployerFns []blockchain.ContractDeployer,
numOfCommitNodes int, commitAndExecOnSameDON, bidirectional bool,
inputs *CCIPTestConfig,
) *CCIPTestSetUpOutputs {
Expand Down Expand Up @@ -750,7 +752,7 @@ func CCIPDefaultTestSetUp(
err = setUpArgs.AddLanesForNetworkPair(
lggr, n.NetworkA, n.NetworkB,
chainByChainID[n.NetworkA.ChainID], chainByChainID[n.NetworkB.ChainID],
transferAmounts, numOfCommitNodes, commitAndExecOnSameDON,
transferAmounts, tokenDeployerFns, numOfCommitNodes, commitAndExecOnSameDON,
bidirectional, newBootstrap)
require.NoError(t, err)
err = laneconfig.WriteLanesToJSON(setUpArgs.LaneConfigFile, setUpArgs.LaneConfig)
Expand Down Expand Up @@ -785,7 +787,7 @@ func CCIPExistingDeploymentTestSetUp(
input *CCIPTestConfig,
) *CCIPTestSetUpOutputs {
return CCIPDefaultTestSetUp(t, lggr, "ccip-runner", 0, transferAmounts,
0, false, bidirectional, input)
nil, 0, false, bidirectional, input)
}

func DeployLocalCluster(
Expand Down