Skip to content

Commit

Permalink
Adding more checks
Browse files Browse the repository at this point in the history
  • Loading branch information
b-gopalswami committed Jul 5, 2024
1 parent d6ced58 commit 40002ad
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 2 deletions.
22 changes: 20 additions & 2 deletions integration-tests/ccip-tests/actions/ccip_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,15 @@ type CCIPCommon struct {
tokenPriceUpdateWatcher map[common.Address]*big.Int // key - token; value - timestamp of update
gasUpdateWatcherMu *sync.Mutex
gasUpdateWatcher map[uint64]*big.Int // key - destchain id; value - timestamp of update
GasUpdater []gasUpdateInfo
}

type gasUpdateInfo struct {
Sender string
Tx string
Value *big.Int
DestChain uint64
ChainSelector uint64
}

// FreeUpUnusedSpace sets nil to various elements of ccipModule which are only used
Expand Down Expand Up @@ -555,13 +564,21 @@ func (ccipModule *CCIPCommon) WatchForPriceUpdates(ctx context.Context, lggr *ze
if tokenUpdateSub == nil {
return fmt.Errorf("no event subscription found")
}
processEvent := func(timestamp *big.Int, destChainSelector uint64) error {
processEvent := func(value, timestamp *big.Int, destChainSelector uint64, raw types.Log) error {
destChain, err := chainselectors.ChainIdFromSelector(destChainSelector)
if err != nil {
return err
}
ccipModule.gasUpdateWatcherMu.Lock()
ccipModule.gasUpdateWatcher[destChain] = timestamp

ccipModule.GasUpdater = append(ccipModule.GasUpdater, gasUpdateInfo{
Sender: raw.Address.Hex(),
Tx: raw.TxHash.Hex(),
Value: value,
DestChain: destChain,
ChainSelector: destChainSelector,
})
ccipModule.gasUpdateWatcherMu.Unlock()
lggr.Info().
Uint64("chainSelector", destChainSelector).
Expand All @@ -578,13 +595,14 @@ func (ccipModule *CCIPCommon) WatchForPriceUpdates(ctx context.Context, lggr *ze
tokenUpdateSub.Unsubscribe()
ccipModule.gasUpdateWatcher = nil
ccipModule.gasUpdateWatcherMu = nil
ccipModule.GasUpdater = nil
ccipModule.tokenPriceUpdateWatcher = nil
ccipModule.tokenPriceUpdateWatcherMu = nil
}()
for {
select {
case e := <-gasUpdateEventLatest:
err := processEvent(e.Timestamp, e.DestChain)
err := processEvent(e.Value, e.Timestamp, e.DestChain, e.Raw)
if err != nil {
continue
}
Expand Down
69 changes: 69 additions & 0 deletions integration-tests/ccip-tests/testsetups/ccip.go
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,72 @@ func (o *CCIPTestSetUpOutputs) WaitForPriceUpdates() {
require.NoError(t, priceUpdateGrp.Wait())
}

func (o *CCIPTestSetUpOutputs) CheckGasUpdateTransaction() error {
txCount := make(map[string]map[uint64]string)
for _, lanes := range o.ReadLanes() {
lanes := lanes
for _, g := range lanes.ForwardLane.Source.Common.GasUpdater {
if g.Value == nil {
return fmt.Errorf("gas update value should not be nil for chain selected %s in tx %s", g.ChainSelector, g.Tx)
}
if v, ok := txCount[g.Tx]; ok {
v[g.ChainSelector] = g.Value.String()
txCount[g.Tx] = v
} else {
txCount[g.Tx] = map[uint64]string{
g.ChainSelector: g.Value.String(),
}
}

lanes.ForwardLane.Logger.Debug().
Str("Sender", g.Sender).
Str("Tx Hash", g.Tx).
Uint64("Dest", g.DestChain).
Bool("PR disabled", lanes.ForwardLane.PriceReportingDisabled).
Uint64("ChainSelector", g.ChainSelector).
Str("Value", g.Value.String()).
Msg("Gas price Updater details")
}
if lanes.ReverseLane != nil {
for _, g := range lanes.ReverseLane.Source.Common.GasUpdater {
if g.Value == nil {
return fmt.Errorf("gas update value should not be nil for chain selected %s in tx %s", g.ChainSelector, g.Tx)
}
if v, ok := txCount[g.Tx]; ok {
v[g.ChainSelector] = g.Value.String()
txCount[g.Tx] = v
} else {
txCount[g.Tx] = map[uint64]string{
g.ChainSelector: g.Value.String(),
}
}
lanes.ReverseLane.Logger.Debug().
Str("Sender", g.Sender).
Str("Tx Hash", g.Tx).
Uint64("Dest", g.DestChain).
Bool("PR disabled", lanes.ReverseLane.PriceReportingDisabled).
Uint64("ChainSelector", g.ChainSelector).
Str("Value", g.Value.String()).
Msg("Gas price Updater details")
}
}
}
// when leader lane setup is enabled, number of transaction should match the number of network and each transaction
// should have number of network - 1 chain selectors and corresponding gas values
if len(txCount) != len(o.Cfg.AllNetworks) {
return fmt.Errorf("transaction count %d shouldn't be more than the number of networks %d when "+
"leader lane feature is on", len(txCount), len(o.Cfg.AllNetworks))
}
for _, v := range txCount {
if len(v) != len(o.Cfg.AllNetworks)-1 {
return fmt.Errorf("number of chain selector count %d shouldn't be more than the number of "+
"all networks minus one %d", len(v), len(o.Cfg.AllNetworks)-1)
}
}
log.Info().Interface("Token list", txCount).Msg("List of transaction hash:")
return nil
}

// CCIPDefaultTestSetUp sets up the environment for CCIP tests
// if configureCLNode is set as false, it assumes:
// 1. contracts are already deployed on live networks
Expand Down Expand Up @@ -1070,6 +1136,9 @@ func CCIPDefaultTestSetUp(
require.NoError(t, setUpArgs.JobAddGrp.Wait(), "Creating jobs shouldn't fail")
// wait for price updates to be available
setUpArgs.WaitForPriceUpdates()
if setUpArgs.Cfg.EnvInput.Lane.LeaderLaneEnabled {
require.NoError(t, setUpArgs.CheckGasUpdateTransaction(), "gas update transaction check shouldn't fail")
}
// if dynamic price update is required
if setUpArgs.Cfg.TestGroupInput.TokenConfig.IsDynamicPriceUpdate() {
require.NoError(t, setUpArgs.SetupDynamicTokenPriceUpdates(), "setting up dynamic price update should not fail")
Expand Down

0 comments on commit 40002ad

Please sign in to comment.