Skip to content

Commit

Permalink
Dry run
Browse files Browse the repository at this point in the history
  • Loading branch information
b-gopalswami committed Sep 24, 2024
1 parent 30c8d5b commit 57544d9
Show file tree
Hide file tree
Showing 3 changed files with 208 additions and 197 deletions.
32 changes: 18 additions & 14 deletions .github/workflows/ccip-live-network-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -256,59 +256,59 @@ jobs:
lanes:
- name: 'ARBITRUM_MAINNET'
pairs: 'ARBITRUM_MAINNET,BSC_MAINNET;ARBITRUM_MAINNET,OPTIMISM_MAINNET'
enabled: false
enabled: true
phaseTimeout: 20m
- name: 'AVALANCHE_MAINNET'
pairs: 'AVALANCHE_MAINNET,ARBITRUM_MAINNET;AVALANCHE_MAINNET,BASE_MAINNET;AVALANCHE_MAINNET,BSC_MAINNET;AVALANCHE_MAINNET,OPTIMISM_MAINNET;AVALANCHE_MAINNET,POLYGON_MAINNET;AVALANCHE_MAINNET,WEMIX_MAINNET'
enabled: false
enabled: true
phaseTimeout: 20m
- name: 'BASE_MAINNET'
pairs: 'BASE_MAINNET,ARBITRUM_MAINNET;BASE_MAINNET,BSC_MAINNET;BASE_MAINNET,OPTIMISM_MAINNET;BASE_MAINNET,POLYGON_MAINNET'
enabled: false
enabled: true
phaseTimeout: 20m
- name: 'BLAST_MAINNET'
pairs: 'BLAST_MAINNET,ARBITRUM_MAINNET;BLAST_MAINNET,BASE_MAINNET;BLAST_MAINNET,BSC_MAINNET'
enabled: false
enabled: true
phaseTimeout: 20m
- name: 'BSC_MAINNET'
pairs: 'BSC_MAINNET,OPTIMISM_MAINNET;BSC_MAINNET,POLYGON_MAINNET;BSC_MAINNET,WEMIX_MAINNET'
enabled: false
enabled: true
phaseTimeout: 20m
- name: 'ETHEREUM_MAINNET 1'
pairs: 'ETHEREUM_MAINNET,ARBITRUM_MAINNET;ETHEREUM_MAINNET,AVALANCHE_MAINNET;ETHEREUM_MAINNET,BASE_MAINNET;ETHEREUM_MAINNET,BLAST_MAINNET;ETHEREUM_MAINNET,BSC_MAINNET;ETHEREUM_MAINNET,CELO_MAINNET;ETHEREUM_MAINNET,GNOSIS_MAINNET;ETHEREUM_MAINNET,OPTIMISM_MAINNET;ETHEREUM_MAINNET,POLYGON_MAINNET;ETHEREUM_MAINNET,WEMIX_MAINNET'
enabled: false
enabled: true
phaseTimeout: 40m
- name: 'ETHEREUM_MAINNET 2'
pairs: 'ETHEREUM_MAINNET,METIS_ANDROMEDA;ETHEREUM_MAINNET,ZKSYNC_MAINNET'
enabled: false
enabled: true
phaseTimeout: 90m
- name: 'GNOSIS_MAINNET'
pairs: 'GNOSIS_MAINNET,ARBITRUM_MAINNET;GNOSIS_MAINNET,AVALANCHE_MAINNET;GNOSIS_MAINNET,BASE_MAINNET;GNOSIS_MAINNET,BSC_MAINNET;GNOSIS_MAINNET,OPTIMISM_MAINNET;GNOSIS_MAINNET,POLYGON_MAINNET'
enabled: false
enabled: true
phaseTimeout: 20m
- name: 'METIS_ANDROMEDA'
pairs: 'METIS_ANDROMEDA,ARBITRUM_MAINNET'
enabled: false
enabled: true
phaseTimeout: 60m
- name: 'MODE_MAINNET'
pairs: 'MODE_MAINNET,OPTIMISM_MAINNET;MODE_MAINNET,ARBITRUM_MAINNET;MODE_MAINNET,BASE_MAINNET;MODE_MAINNET,BSC_MAINNET'
enabled: false
enabled: true
phaseTimeout: 20m
- name: 'OPTIMISM_MAINNET'
pairs: 'OPTIMISM_MAINNET,POLYGON_MAINNET;OPTIMISM_MAINNET,WEMIX_MAINNET'
enabled: false
enabled: true
phaseTimeout: 20m
- name: 'POLYGON_MAINNET'
pairs: 'POLYGON_MAINNET,ARBITRUM_MAINNET;POLYGON_MAINNET,WEMIX_MAINNET'
enabled: false
enabled: true
phaseTimeout: 20m
- name: 'WEMIX_MAINNET'
pairs: 'WEMIX_MAINNET,ARBITRUM_MAINNET;WEMIX_MAINNET,KROMA_MAINNET'
enabled: true
phaseTimeout: 20m
- name: 'ZKSYNC_MAINNET'
pairs: 'ZKSYNC_MAINNET,ARBITRUM_MAINNET'
enabled: false
enabled: true
phaseTimeout: 90m
steps:
- name: Collect Metrics
Expand Down Expand Up @@ -336,7 +336,11 @@ jobs:
echo ::add-mask::$SLACK_USER
echo "SLACK_USER=$SLACK_USER" >> "$GITHUB_ENV"
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
BASE64_CCIP_CONFIG_OVERRIDE=$(base64 -w 0 -i ./integration-tests/ccip-tests/testconfig/override/mainnet.toml)
if [[ -z "${{ input.base64_test_input }}" ]]; then
BASE64_CCIP_CONFIG_OVERRIDE=$(jq -r '.inputs.base64_test_input' $GITHUB_EVENT_PATH)
else
BASE64_CCIP_CONFIG_OVERRIDE=$(base64 -w 0 -i ./integration-tests/ccip-tests/testconfig/override/mainnet.toml)
fi
echo ::add-mask::$BASE64_CCIP_CONFIG_OVERRIDE
echo "base_64_override=$BASE64_CCIP_CONFIG_OVERRIDE" >> $GITHUB_OUTPUT
fi
Expand Down
233 changes: 120 additions & 113 deletions integration-tests/ccip-tests/smoke/ccip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ package smoke

import (
"fmt"
"github.com/ethereum/go-ethereum/core/types"
"github.com/smartcontractkit/chainlink-common/pkg/config"
"github.com/smartcontractkit/chainlink-testing-framework/lib/utils/osutil"
"math/big"
"strings"
"testing"
"time"

"github.com/smartcontractkit/chainlink-common/pkg/config"
"github.com/smartcontractkit/chainlink-testing-framework/lib/utils/osutil"

"github.com/ethereum/go-ethereum/core/types"

"github.com/AlekSi/pointer"
"github.com/rs/zerolog"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -97,114 +95,6 @@ func TestSmokeCCIPForBidirectionalLane(t *testing.T) {
}
}

func TestSmokeCCIPForGivenNetworkPairs(t *testing.T) {
t.Parallel()
log := logging.GetTestLogger(t)
TestCfg := testsetups.NewCCIPTestConfig(t, log, testconfig.Smoke)
// override network pairs and phase timeout
var temp []testsetups.NetworkPair
overrideNetworkPairs, err := osutil.GetEnv("OVERRIDE_NETWORK_PAIRS")
require.NoError(t, err, "Error getting OVERRIDE_NETWORK_PAIRS environment variable")
networkPairs := strings.Split(overrideNetworkPairs, ";")
for _, networkPair := range networkPairs {
// check for any malformed inputs
if !strings.Contains(networkPair, ",") || len(strings.Split(networkPair, ",")) != 2 {
log.Error().Msgf("malformed OVERRIDE_NETWORK_PAIRS environment variable for network pair: %s ", networkPair)
return
}
networkPair = strings.ToUpper(strings.ReplaceAll(networkPair, "_", " "))
for _, network := range TestCfg.NetworkPairs {
if strings.Contains(networkPair, strings.ToUpper(network.NetworkA.Name)) && strings.Contains(networkPair, strings.ToUpper(network.NetworkB.Name)) {
temp = append(temp, network)
break
}
}
}
log.Info().Int("Pairs", len(temp)).Msg("**** Number of lanes overridden in the test. ****")
log.Info().Interface("Lanes", networkPairs).Msg("Lanes under test")
TestCfg.NetworkPairs = temp
phaseTimeout, err := osutil.GetEnv("OVERRIDE_PHASE_TIMEOUT")
require.NoError(t, err, "Error getting OVERRIDE_PHASE_TIMEOUT environment variable")
configDuration, err := config.ParseDuration(phaseTimeout)
require.NoError(t, err, "Error parsing phase timeout value")
TestCfg.TestGroupInput.PhaseTimeout = &configDuration

gasLimit := big.NewInt(*TestCfg.TestGroupInput.MsgDetails.DestGasLimit)
setUpOutput := testsetups.CCIPDefaultTestSetUp(t, &log, "smoke-ccip", nil, TestCfg)
if len(setUpOutput.Lanes) == 0 {
log.Error().Msg("No lanes found")
return
}

t.Cleanup(func() {
// If we are running a test that is a token transfer, we need to verify the balance.
// skip the balance check for existing deployment, there can be multiple external requests in progress for existing deployments
// other than token transfer initiated by the test, which can affect the balance check
// therefore we check the balance only for the ccip environment created by the test
if TestCfg.TestGroupInput.MsgDetails.IsTokenTransfer() &&
!pointer.GetBool(TestCfg.TestGroupInput.USDCMockDeployment) &&
!pointer.GetBool(TestCfg.TestGroupInput.ExistingDeployment) {
setUpOutput.Balance.Verify(t)
}
require.NoError(t, setUpOutput.TearDown(), "error in tear down step")
})

var tests []testDefinition
lookBackDuration := TestCfg.TestGroupInput.SkipRequestIfAnotherRequestTriggeredWithin
var recentTxFound *types.Log

addLanesToTest := func(lane *actions.CCIPLane) {
// Create test definitions for given lane if no previous request has been triggered within the specified timeframe.
// By default, the timeframe is set to nil. To define a timeframe, assign a duration to the variable
// SkipRequestIfAnotherRequestTriggeredWithin.
if lookBackDuration != nil {
recentTxFound, err = lane.Source.IsPastRequestTriggeredWithinTimeframe(lane.Context, lookBackDuration)
require.NoError(t, err, "error while finding recent request for lane network %s to network %s",
lane.SourceNetworkName, lane.DestNetworkName)
}
if recentTxFound == nil {
tests = append(tests, testDefinition{
testName: fmt.Sprintf("CCIP message transfer from network %s to network %s",
lane.SourceNetworkName, lane.DestNetworkName),
lane: lane,
})
} else {
log.Info().
Str("TX", recentTxFound.TxHash.Hex()).
Uint64("Block Number", recentTxFound.BlockNumber).
Str("Source", lane.SourceNetworkName).
Str("Dest", lane.DestNetworkName).
Msgf("Lane Skipped. Recent request found within %v minutes.", lookBackDuration.Duration().Minutes())
}
}
for _, lane := range setUpOutput.Lanes {
addLanesToTest(lane.ForwardLane)
if lane.ReverseLane != nil {
recentTxFound = nil
addLanesToTest(lane.ReverseLane)
}
}

// Execute tests.
log.Info().Int("Total Lanes", len(tests)).Msg("Starting CCIP test")
for _, test := range tests {
tc := test
t.Run(tc.testName, func(t *testing.T) {
t.Parallel()
tc.lane.Test = t
log.Info().
Str("Source", tc.lane.SourceNetworkName).
Str("Destination", tc.lane.DestNetworkName).
Msgf("Starting lane %s -> %s", tc.lane.SourceNetworkName, tc.lane.DestNetworkName)

tc.lane.RecordStateBeforeTransfer()
err = tc.lane.SendRequests(1, gasLimit)
require.NoError(t, err, "error sending requests")
tc.lane.ValidateRequests()
})
}
}

func TestSmokeCCIPRateLimit(t *testing.T) {
t.Parallel()
log := logging.GetTestLogger(t)
Expand Down Expand Up @@ -1020,6 +910,123 @@ func TestSmokeCCIPReorgAboveFinalityAtSource(t *testing.T) {
})
}

// TestSmokeCCIPForGivenNetworkPairs is designed specifically for scheduled mainnet testing. This test checks for recent
// transaction and skip the lanes accordingly. This test also has capability to take override input on network pairs and phase timeout.
func TestSmokeCCIPForGivenNetworkPairs(t *testing.T) {
t.Parallel()
log := logging.GetTestLogger(t)
TestCfg := testsetups.NewCCIPTestConfig(t, log, testconfig.Smoke)
// override network pairs
var temp []testsetups.NetworkPair
overrideNetworkPairs, err := osutil.GetEnv("OVERRIDE_NETWORK_PAIRS")
require.NoError(t, err, "Error getting OVERRIDE_NETWORK_PAIRS environment variable")
if overrideNetworkPairs != "" {
networkPairs := strings.Split(overrideNetworkPairs, ";")
for _, networkPair := range networkPairs {
// check for any malformed inputs
if !strings.Contains(networkPair, ",") || len(strings.Split(networkPair, ",")) != 2 {
log.Error().Msgf("malformed OVERRIDE_NETWORK_PAIRS environment variable for network pair: %s ", networkPair)
return
}
networkPair = strings.ToUpper(strings.ReplaceAll(networkPair, "_", " "))
for _, network := range TestCfg.NetworkPairs {
if strings.Contains(networkPair, strings.ToUpper(network.NetworkA.Name)) && strings.Contains(networkPair, strings.ToUpper(network.NetworkB.Name)) {
temp = append(temp, network)
break
}
}
}
log.Info().Int("Pairs", len(temp)).Msg("**** Number of lanes overridden in the test. ****")
log.Info().Interface("Lanes", networkPairs).Msg("Lanes under test")
TestCfg.NetworkPairs = temp
}

// phase timeout override
phaseTimeout, err := osutil.GetEnv("OVERRIDE_PHASE_TIMEOUT")
require.NoError(t, err, "Error getting OVERRIDE_PHASE_TIMEOUT environment variable")
if phaseTimeout != "" {
configDuration, err := config.ParseDuration(phaseTimeout)
require.NoError(t, err, "Error parsing phase timeout value")
TestCfg.TestGroupInput.PhaseTimeout = &configDuration
log.Info().Float64("Timeout in minutes", configDuration.Duration().Minutes()).Msg("Phase timeout is overridden")
}

gasLimit := big.NewInt(*TestCfg.TestGroupInput.MsgDetails.DestGasLimit)
setUpOutput := testsetups.CCIPDefaultTestSetUp(t, &log, "smoke-ccip", nil, TestCfg)
if len(setUpOutput.Lanes) == 0 {
log.Error().Msg("No lanes found")
return
}

t.Cleanup(func() {
// If we are running a test that is a token transfer, we need to verify the balance.
// skip the balance check for existing deployment, there can be multiple external requests in progress for existing deployments
// other than token transfer initiated by the test, which can affect the balance check
// therefore we check the balance only for the ccip environment created by the test
if TestCfg.TestGroupInput.MsgDetails.IsTokenTransfer() &&
!pointer.GetBool(TestCfg.TestGroupInput.USDCMockDeployment) &&
!pointer.GetBool(TestCfg.TestGroupInput.ExistingDeployment) {
setUpOutput.Balance.Verify(t)
}
require.NoError(t, setUpOutput.TearDown(), "error in tear down step")
})

var tests []testDefinition
lookBackDuration := TestCfg.TestGroupInput.SkipRequestIfAnotherRequestTriggeredWithin
var recentTxFound *types.Log

addLanesToTest := func(lane *actions.CCIPLane) {
// Create test definitions for given lane if no previous request has been triggered within the specified timeframe.
// By default, the timeframe is set to nil. To define a timeframe, assign a duration to the variable
// SkipRequestIfAnotherRequestTriggeredWithin.
if lookBackDuration != nil {
recentTxFound, err = lane.Source.IsPastRequestTriggeredWithinTimeframe(lane.Context, lookBackDuration)
require.NoError(t, err, "error while finding recent request for lane network %s to network %s",
lane.SourceNetworkName, lane.DestNetworkName)
}
if recentTxFound == nil {
tests = append(tests, testDefinition{
testName: fmt.Sprintf("CCIP message transfer from network %s to network %s",
lane.SourceNetworkName, lane.DestNetworkName),
lane: lane,
})
} else {
log.Info().
Str("TX", recentTxFound.TxHash.Hex()).
Uint64("Block Number", recentTxFound.BlockNumber).
Str("Source", lane.SourceNetworkName).
Str("Dest", lane.DestNetworkName).
Msgf("***Lane Skipped.*** Recent request found within %v minutes.", lookBackDuration.Duration().Minutes())
}
}
for _, lane := range setUpOutput.Lanes {
addLanesToTest(lane.ForwardLane)
if lane.ReverseLane != nil {
recentTxFound = nil
addLanesToTest(lane.ReverseLane)
}
}

// Execute tests.
log.Info().Int("Total Lanes", len(tests)).Msg("Starting CCIP test")
for _, test := range tests {
tc := test
t.Run(tc.testName, func(t *testing.T) {
t.Parallel()
tc.lane.Test = t
log.Info().
Str("Source", tc.lane.SourceNetworkName).
Str("Destination", tc.lane.DestNetworkName).
Msgf("Starting lane %s -> %s", tc.lane.SourceNetworkName, tc.lane.DestNetworkName)

tc.lane.RecordStateBeforeTransfer()
err = tc.lane.SendRequests(1, gasLimit)
require.NoError(t, err, "error sending requests")
tc.lane.ValidateRequests()
})
}
}

// performAboveFinalityReorgAndValidate is to perform the above finality reorg test
func performAboveFinalityReorgAndValidate(t *testing.T, network string) {
t.Helper()
Expand Down
Loading

0 comments on commit 57544d9

Please sign in to comment.