diff --git a/integration-tests/ccip-tests/actions/ccip_helpers.go b/integration-tests/ccip-tests/actions/ccip_helpers.go index 153f5e7ea9..5a5fb74017 100644 --- a/integration-tests/ccip-tests/actions/ccip_helpers.go +++ b/integration-tests/ccip-tests/actions/ccip_helpers.go @@ -583,6 +583,26 @@ type SourceCCIPModule struct { NewFinalizedBlockTimestamp atomic.Time } +func (sourceCCIP *SourceCCIPModule) PayCCIPFeeToOwnerAddress() error { + isNativeFee := sourceCCIP.Common.FeeToken.EthAddress == common.HexToAddress("0x0") + if isNativeFee { + err := sourceCCIP.OnRamp.WithdrawNonLinkFees(sourceCCIP.Common.WrappedNative) + if err != nil { + return err + } + } else { + err := sourceCCIP.OnRamp.SetNops() + if err != nil { + return err + } + err = sourceCCIP.OnRamp.PayNops() + if err != nil { + return err + } + } + return nil +} + func (sourceCCIP *SourceCCIPModule) LoadContracts(conf *laneconfig.LaneConfig) { if conf != nil { cfg, ok := conf.SrcContracts[sourceCCIP.DestNetworkName] @@ -609,6 +629,7 @@ func (sourceCCIP *SourceCCIPModule) DeployContracts(lane *laneconfig.LaneConfig) if err != nil { return err } + sourceCCIP.LoadContracts(lane) // update transfer amount array length to be equal to the number of tokens // each index in TransferAmount array corresponds to the amount to be transferred for the token at the same index in BridgeTokens array @@ -1711,7 +1732,7 @@ func (lane *CCIPLane) StartEventWatchers() error { return nil } -func (lane *CCIPLane) CleanUp() { +func (lane *CCIPLane) CleanUp(clearFees bool) error { lane.Logger.Info().Msg("Cleaning up lane") if !lane.Source.Common.ChainClient.NetworkSimulated() && lane.Source.Common.ChainClient.GetNetworkConfig().FinalityDepth == 0 { @@ -1720,8 +1741,18 @@ func (lane *CCIPLane) CleanUp() { for _, sub := range lane.Subscriptions { sub.Unsubscribe() } - require.NoError(lane.Test, lane.DestChain.Close()) - require.NoError(lane.Test, lane.SourceChain.Close()) + // recover fees from onRamp contract + if clearFees && !lane.Source.Common.ChainClient.NetworkSimulated() { + err := lane.Source.PayCCIPFeeToOwnerAddress() + if err != nil { + return err + } + } + err := lane.Dest.Common.ChainClient.Close() + if err != nil { + return err + } + return lane.Source.Common.ChainClient.Close() } // DeployNewCCIPLane sets up a lane and initiates lane.Source and lane.Destination diff --git a/integration-tests/ccip-tests/chaos/ccip_test.go b/integration-tests/ccip-tests/chaos/ccip_test.go index fb4c644402..515e022bf0 100644 --- a/integration-tests/ccip-tests/chaos/ccip_test.go +++ b/integration-tests/ccip-tests/chaos/ccip_test.go @@ -135,9 +135,9 @@ func TestChaosCCIP(t *testing.T) { require.NoError(t, err) t.Cleanup(func() { if chaosId != "" { - testEnvironment.Chaos.Stop(chaosId) + require.NoError(t, testEnvironment.Chaos.Stop(chaosId)) } - tearDown() + require.NoError(t, tearDown()) }) lane.RecordStateBeforeTransfer() // Now send the ccip-request while the chaos is at play @@ -145,7 +145,7 @@ func TestChaosCCIP(t *testing.T) { require.NoError(t, err) if in.waitForChaosRecovery { // wait for chaos to be recovered before further validation - testEnvironment.Chaos.WaitForAllRecovered(chaosId, 1*time.Minute) + require.NoError(t, testEnvironment.Chaos.WaitForAllRecovered(chaosId, 1*time.Minute)) } else { l.Info().Msg("proceeding without waiting for chaos recovery") } diff --git a/integration-tests/ccip-tests/contracts/contract_models.go b/integration-tests/ccip-tests/contracts/contract_models.go index 02f22c54ab..ca26b2f3e3 100644 --- a/integration-tests/ccip-tests/contracts/contract_models.go +++ b/integration-tests/ccip-tests/contracts/contract_models.go @@ -580,6 +580,48 @@ func (onRamp *OnRamp) Address() string { return onRamp.EthAddress.Hex() } +func (onRamp *OnRamp) SetNops() error { + opts, err := onRamp.client.TransactionOpts(onRamp.client.GetDefaultWallet()) + if err != nil { + return err + } + owner := common.HexToAddress(onRamp.client.GetDefaultWallet().Address()) + // set the payee to the default wallet + tx, err := onRamp.Instance.SetNops(opts, []evm_2_evm_onramp.EVM2EVMOnRampNopAndWeight{{ + Nop: owner, + Weight: 1, + }}) + if err != nil { + return err + } + return onRamp.client.ProcessTransaction(tx) +} + +func (onRamp *OnRamp) PayNops() error { + opts, err := onRamp.client.TransactionOpts(onRamp.client.GetDefaultWallet()) + if err != nil { + return err + } + tx, err := onRamp.Instance.PayNops(opts) + if err != nil { + return err + } + return onRamp.client.ProcessTransaction(tx) +} + +func (onRamp *OnRamp) WithdrawNonLinkFees(wrappedNative common.Address) error { + opts, err := onRamp.client.TransactionOpts(onRamp.client.GetDefaultWallet()) + if err != nil { + return err + } + owner := common.HexToAddress(onRamp.client.GetDefaultWallet().Address()) + tx, err := onRamp.Instance.WithdrawNonLinkFees(opts, wrappedNative, owner) + if err != nil { + return err + } + return onRamp.client.ProcessTransaction(tx) +} + func (onRamp *OnRamp) SetRateLimit(rlConfig evm_2_evm_onramp.RateLimiterConfig) error { opts, err := onRamp.client.TransactionOpts(onRamp.client.GetDefaultWallet()) if err != nil { diff --git a/integration-tests/ccip-tests/contracts/laneconfig/contracts.json b/integration-tests/ccip-tests/contracts/laneconfig/contracts.json index 2de02c302a..1962cbc704 100644 --- a/integration-tests/ccip-tests/contracts/laneconfig/contracts.json +++ b/integration-tests/ccip-tests/contracts/laneconfig/contracts.json @@ -1064,6 +1064,7 @@ "Base Goerli-1": { "is_mock_arm": true, "fee_token": "0xD886E2286Fd1073df82462ea1822119600Af80b6", + "is_native_fee_token" : true, "bridge_tokens": null, "bridge_tokens_pools": null, "arm": "0x1E5b6ce8EB1071B2B1686ddd241fE6a3c07560DE", @@ -1123,6 +1124,7 @@ "Base Goerli-2": { "is_mock_arm": true, "fee_token": "0xD886E2286Fd1073df82462ea1822119600Af80b6", + "is_native_fee_token" : true, "bridge_tokens": null, "bridge_tokens_pools": null, "arm": "0xE42597d226Eab595893f1ad1B0d7F58d7F1Cc375", @@ -1182,6 +1184,7 @@ "Base Goerli-3": { "is_mock_arm": true, "fee_token": "0xD886E2286Fd1073df82462ea1822119600Af80b6", + "is_native_fee_token" : true, "bridge_tokens": null, "bridge_tokens_pools": null, "arm": "0xE42597d226Eab595893f1ad1B0d7F58d7F1Cc375", @@ -1241,6 +1244,7 @@ "Base Goerli-4": { "is_mock_arm": true, "fee_token": "0xD886E2286Fd1073df82462ea1822119600Af80b6", + "is_native_fee_token" : true, "bridge_tokens": null, "bridge_tokens_pools": null, "arm": "0xE42597d226Eab595893f1ad1B0d7F58d7F1Cc375", diff --git a/integration-tests/ccip-tests/contracts/laneconfig/parse_contracts.go b/integration-tests/ccip-tests/contracts/laneconfig/parse_contracts.go index b8ab13c627..9063d1462d 100644 --- a/integration-tests/ccip-tests/contracts/laneconfig/parse_contracts.go +++ b/integration-tests/ccip-tests/contracts/laneconfig/parse_contracts.go @@ -134,8 +134,9 @@ func (l *Lanes) CopyCommonContracts(fromNetwork, toNetwork string, reuse, isToke DestContractsMu: &sync.Mutex{}, DestContracts: make(map[string]DestContracts), CommonContracts: CommonContracts{ - FeeToken: existing.FeeToken, - WrappedNative: existing.WrappedNative, + FeeToken: existing.FeeToken, + WrappedNative: existing.WrappedNative, + IsNativeFeeToken: existing.IsNativeFeeToken, }, } // if reuse is set to true, it copies all the common contracts except the router diff --git a/integration-tests/ccip-tests/load/ccip_test.go b/integration-tests/ccip-tests/load/ccip_test.go index de1b526c6d..40dfa9d18e 100644 --- a/integration-tests/ccip-tests/load/ccip_test.go +++ b/integration-tests/ccip-tests/load/ccip_test.go @@ -9,6 +9,7 @@ import ( "github.com/smartcontractkit/chainlink-env/chaos" a "github.com/smartcontractkit/chainlink-env/pkg/alias" "github.com/smartcontractkit/chainlink-testing-framework/logging" + "github.com/stretchr/testify/require" "github.com/smartcontractkit/chainlink/integration-tests/ccip-tests/actions" ) @@ -24,7 +25,7 @@ func TestLoadCCIPStableRPS(t *testing.T) { } t.Cleanup(func() { log.Info().Msg("Tearing down the environment") - testArgs.TestSetupArgs.TearDown() + require.NoError(t, testArgs.TestSetupArgs.TearDown()) }) testArgs.TriggerLoad() testArgs.Wait() @@ -46,7 +47,7 @@ func TestLoadCCIPSequentialLaneAdd(t *testing.T) { } t.Cleanup(func() { log.Info().Msg("Tearing down the environment") - testArgs.TestSetupArgs.TearDown() + require.NoError(t, testArgs.TestSetupArgs.TearDown()) }) testArgs.TriggerLoad() testArgs.AddMoreLanesToRun() @@ -108,7 +109,7 @@ func TestLoadCCIPStableRequestTriggeringWithPodChaos(t *testing.T) { } t.Cleanup(func() { log.Info().Msg("Tearing down the environment") - testArgs.TestSetupArgs.TearDown() + require.NoError(t, testArgs.TestSetupArgs.TearDown()) }) testArgs.SanityCheck() testArgs.TriggerLoad() diff --git a/integration-tests/ccip-tests/load/helper.go b/integration-tests/ccip-tests/load/helper.go index b2196d3643..52e848e2d9 100644 --- a/integration-tests/ccip-tests/load/helper.go +++ b/integration-tests/ccip-tests/load/helper.go @@ -272,7 +272,7 @@ func (l *loadArgs) TearDown() { for i := range l.ccipLoad { l.ccipLoad[i].ReportAcceptedLog() } - l.TestSetupArgs.TearDown() + require.NoError(l.t, l.TestSetupArgs.TearDown()) } } diff --git a/integration-tests/ccip-tests/smoke/ccip_test.go b/integration-tests/ccip-tests/smoke/ccip_test.go index a2e434fe64..509460c63d 100644 --- a/integration-tests/ccip-tests/smoke/ccip_test.go +++ b/integration-tests/ccip-tests/smoke/ccip_test.go @@ -35,6 +35,7 @@ func TestSmokeCCIPForBidirectionalLane(t *testing.T) { if TestCfg.MsgType == actions.TokenTransfer { setUpOutput.Balance.Verify(t) } + require.NoError(t, setUpOutput.TearDown()) }) for i := range setUpOutput.Lanes { tcs = append(tcs, subtestInput{ @@ -50,7 +51,7 @@ func TestSmokeCCIPForBidirectionalLane(t *testing.T) { }) } } - + l.Info().Int("Total Lanes", len(tcs)).Msg("Starting CCIP test") for _, testcase := range tcs { tc := testcase t.Run(tc.testName, func(t *testing.T) { @@ -88,7 +89,7 @@ func TestSmokeCCIPRateLimit(t *testing.T) { } t.Cleanup(func() { - setUpOutput.TearDown() + require.NoError(t, setUpOutput.TearDown()) }) for i := range setUpOutput.Lanes { diff --git a/integration-tests/ccip-tests/testsetups/ccip.go b/integration-tests/ccip-tests/testsetups/ccip.go index 9389b62690..5ffc1933d7 100644 --- a/integration-tests/ccip-tests/testsetups/ccip.go +++ b/integration-tests/ccip-tests/testsetups/ccip.go @@ -518,7 +518,7 @@ type CCIPTestSetUpOutputs struct { Reporter *testreporters.CCIPTestReporter LaneConfigFile string LaneConfig *laneconfig.Lanes - TearDown func() + TearDown func() error Env *actions.CCIPTestEnv Balance *actions.BalanceSheet BootstrapAdded *atomic.Bool @@ -1081,13 +1081,23 @@ func CCIPDefaultTestSetUp( // start event watchers for all lanes setUpArgs.StartEventWatchers() - setUpArgs.TearDown = func() { + setUpArgs.TearDown = func() error { + var errs error for _, lanes := range setUpArgs.Lanes { - lanes.ForwardLane.CleanUp() + // if existing deployment is true, don't attempt to pay ccip fees + err := lanes.ForwardLane.CleanUp(!setUpArgs.Cfg.ExistingDeployment) + if err != nil { + errs = multierr.Append(errs, err) + } if lanes.ReverseLane != nil { - lanes.ReverseLane.CleanUp() + // if existing deployment is true, don't attempt to pay ccip fees + err := lanes.ReverseLane.CleanUp(!setUpArgs.Cfg.ExistingDeployment) + if err != nil { + errs = multierr.Append(errs, err) + } } } + return errs } lggr.Info().Msg("Test setup completed") return setUpArgs