Skip to content

Commit

Permalink
Fully functional HTTP
Browse files Browse the repository at this point in the history
  • Loading branch information
davidcauchi committed Jan 30, 2025
1 parent c9671d8 commit 680151e
Show file tree
Hide file tree
Showing 4 changed files with 402 additions and 1 deletion.
238 changes: 238 additions & 0 deletions integration-tests/ccip-tests/actions/ccip_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ import (
"golang.org/x/exp/rand"
"golang.org/x/sync/errgroup"

"github.com/smartcontractkit/chainlink-testing-framework/lib/utils/ptr"
"github.com/smartcontractkit/chainlink-testing-framework/sentinel"

chainselectors "github.com/smartcontractkit/chain-selectors"

commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config"
Expand Down Expand Up @@ -3618,6 +3621,241 @@ func (lane *CCIPLane) StartEventWatchers() error {
return nil
}

func (lane *CCIPLane) StartEventWatchersPolling(sc *sentinel.SentinelCoordinator) error {
lane.Logger.Info().Msg("Starting event watchers, Polling")
if lane.Source.Common.ChainClient.GetNetworkConfig().FinalityDepth == 0 {
err := lane.Source.Common.ChainClient.PollFinality()
if err != nil {
return err
}
}

sendReqEventSub, err := sc.Sentinel.Subscribe(
lane.SourceChain.GetChainID().Int64(),
lane.Source.OnRamp.EthAddress,
evm_2_evm_onramp.EVM2EVMOnRampCCIPSendRequested{}.Topic(),
)
if err != nil {
log.Error().Err(err).Msg("error in setting up polling to CCIPSendRequested event")
return err
}
go func() {
defer sc.Sentinel.Unsubscribe(lane.SourceChain.GetChainID().Int64(), lane.Source.OnRamp.EthAddress, evm_2_evm_onramp.EVM2EVMOnRampCCIPSendRequested{}.Topic(), sendReqEventSub)
for {
select {
case <-sc.Ctx.Done():
return
case event, ok := <-sendReqEventSub:
if !ok {
lane.Logger.Info().Msg("Sentinel log channel closed. Exiting goroutine.")
return
}
typesLog, _ := sentinel.ConvertAPILogToTypesLog(event)
e, _ := lane.Source.OnRamp.Instance.Latest.EVM2EVMOnRampFilterer.ParseCCIPSendRequested(*typesLog)
lane.Logger.Info().Msgf("CCIPSendRequested event received for seq number %d", e.Message.SequenceNumber)
eventsForTx, ok := lane.Source.CCIPSendRequestedWatcher.Load(e.Raw.TxHash.Hex())
if ok {
lane.Source.CCIPSendRequestedWatcher.Store(e.Raw.TxHash.Hex(), append(eventsForTx.([]*contracts.SendReqEventData),
&contracts.SendReqEventData{
MessageId: e.Message.MessageId,
SequenceNumber: e.Message.SequenceNumber,
DataLength: len(e.Message.Data),
NoOfTokens: len(e.Message.TokenAmounts),
LogInfo: contracts.LogInfo{
BlockNumber: e.Raw.BlockNumber,
TxHash: e.Raw.TxHash,
},
Fee: e.Message.FeeTokenAmount,
}))
} else {
lane.Source.CCIPSendRequestedWatcher.Store(e.Raw.TxHash.Hex(), []*contracts.SendReqEventData{
{
MessageId: e.Message.MessageId,
SequenceNumber: e.Message.SequenceNumber,
DataLength: len(e.Message.Data),
NoOfTokens: len(e.Message.TokenAmounts),
LogInfo: contracts.LogInfo{
BlockNumber: e.Raw.BlockNumber,
TxHash: e.Raw.TxHash,
},
Fee: e.Message.FeeTokenAmount,
},
})
}

lane.Source.CCIPSendRequestedWatcher = testutils.DeleteNilEntriesFromMap(lane.Source.CCIPSendRequestedWatcher)
case <-lane.Context.Done():
return
}
}
}()

reportAcceptedSub, err := sc.Sentinel.Subscribe(
lane.DestChain.GetChainID().Int64(),
lane.Dest.CommitStore.EthAddress,
commit_store.CommitStoreReportAccepted{}.Topic(),
)
if err != nil {
log.Error().Err(err).Msg("error in setting up polling to ReportAccepted event")
return fmt.Errorf("failed to subscribe to ReportAccepted event")
}
go func() {
defer sc.Sentinel.Unsubscribe(lane.DestChain.GetChainID().Int64(), lane.Dest.CommitStore.EthAddress, commit_store.CommitStoreReportAccepted{}.Topic(), reportAcceptedSub)
for {
select {
case <-sc.Ctx.Done():
return
case event, ok := <-reportAcceptedSub:
if !ok {
lane.Logger.Info().Msg("Sentinel log channel closed. Exiting goroutine.")
return
}

// Convert the log and parse the ReportAccepted event
typesLog, err := sentinel.ConvertAPILogToTypesLog(event)
if err != nil {
lane.Logger.Error().Err(err).Msg("error converting Sentinel log to types.Log")
continue
}
e, err := lane.Dest.CommitStore.Instance.Latest.CommitStoreFilterer.ParseReportAccepted(*typesLog)
if err != nil {
lane.Logger.Error().Err(err).Msg("error parsing ReportAccepted event")
continue
}

// Log and store the event
lane.Logger.Info().Interface("Interval", e.Report.Interval).Msgf("ReportAccepted event received")
for i := e.Report.Interval.Min; i <= e.Report.Interval.Max; i++ {
lane.Dest.ReportAcceptedWatcher.Store(i, &contracts.CommitStoreReportAccepted{
Min: e.Report.Interval.Min,
Max: e.Report.Interval.Max,
MerkleRoot: e.Report.MerkleRoot,
LogInfo: contracts.LogInfo{
BlockNumber: e.Raw.BlockNumber,
TxHash: e.Raw.TxHash,
},
})
}

// Clean up nil entries
lane.Dest.ReportAcceptedWatcher = testutils.DeleteNilEntriesFromMap(lane.Dest.ReportAcceptedWatcher)
case <-lane.Context.Done():
return
}
}
}()

if lane.Dest.Common.ARM != nil {

reportBlessedEventSub, err := sc.Sentinel.Subscribe(
lane.DestChain.GetChainID().Int64(),
lane.Dest.Common.ARM.EthAddress,
rmn_contract.RMNContractTaggedRootBlessed{}.Topic(),
)
if err != nil {
log.Error().Err(err).Msg("error in setting up polling to TaggedRootBlessed event")
return fmt.Errorf("failed to subscribe to TaggedRootBlessed event")
}

go func() {
defer sc.Sentinel.Unsubscribe(lane.DestChain.GetChainID().Int64(), lane.Dest.Common.ARM.EthAddress, rmn_contract.RMNContractTaggedRootBlessed{}.Topic(), reportBlessedEventSub)
for {
select {
case <-sc.Ctx.Done():
return
case event, ok := <-reportBlessedEventSub:
if !ok {
lane.Logger.Info().Msg("Sentinel log channel closed. Exiting goroutine.")
return
}

// Convert the log and parse the TaggedRootBlessed event
typesLog, err := sentinel.ConvertAPILogToTypesLog(event)
if err != nil {
lane.Logger.Error().Err(err).Msg("error converting Sentinel log to types.Log")
continue
}
e, err := lane.Dest.Common.ARM.Instance.RMNContractFilterer.ParseTaggedRootBlessed(*typesLog)
if err != nil {
lane.Logger.Error().Err(err).Msg("error parsing TaggedRootBlessed event")
continue
}

// Process the event
lane.Logger.Info().Msgf("TaggedRootBlessed event received for root %x", e.TaggedRoot.Root)
if e.TaggedRoot.CommitStore == lane.Dest.CommitStore.EthAddress {
lane.Dest.ReportBlessedWatcher.Store(e.TaggedRoot.Root, &contracts.LogInfo{
BlockNumber: e.Raw.BlockNumber,
TxHash: e.Raw.TxHash,
})
}

// Clean up nil entries
lane.Dest.ReportBlessedWatcher = testutils.DeleteNilEntriesFromMap(lane.Dest.ReportBlessedWatcher)
case <-lane.Context.Done():
return
}
}
}()
}

execStateChangedEventSub, err := sc.Sentinel.Subscribe(
lane.DestChain.GetChainID().Int64(),
lane.Dest.OffRamp.EthAddress,
evm_2_evm_offramp.EVM2EVMOffRampExecutionStateChanged{}.Topic(),
)
if err != nil {
log.Error().Err(err).Msg("error in setting up polling to ExecutionStateChanged event")
return fmt.Errorf("failed to subscribe to ExecutionStateChanged event")
}

go func() {
defer sc.Sentinel.Unsubscribe(lane.DestChain.GetChainID().Int64(), lane.Dest.OffRamp.EthAddress, evm_2_evm_offramp.EVM2EVMOffRampExecutionStateChanged{}.Topic(), execStateChangedEventSub)
for {
select {
case <-sc.Ctx.Done():
return
case event, ok := <-execStateChangedEventSub:
if !ok {
lane.Logger.Info().Msg("Sentinel log channel closed. Exiting goroutine.")
return
}

// Convert the log and parse the ExecutionStateChanged event
typesLog, err := sentinel.ConvertAPILogToTypesLog(event)
if err != nil {
lane.Logger.Error().Err(err).Msg("error converting Sentinel log to types.Log")
continue
}
e, err := lane.Dest.OffRamp.Instance.Latest.EVM2EVMOffRampFilterer.ParseExecutionStateChanged(*typesLog)
if err != nil {
lane.Logger.Error().Err(err).Msg("error parsing ExecutionStateChanged event")
continue
}

// Process the event
lane.Logger.Info().Msgf("Execution state changed event received for seq number %d", e.SequenceNumber)
lane.Dest.ExecStateChangedWatcher.Store(e.SequenceNumber, &contracts.EVM2EVMOffRampExecutionStateChanged{
SequenceNumber: e.SequenceNumber,
MessageId: e.MessageId,
State: e.State,
ReturnData: e.ReturnData,
LogInfo: contracts.LogInfo{
BlockNumber: e.Raw.BlockNumber,
TxHash: e.Raw.TxHash,
},
})

// Clean up nil entries
lane.Dest.ExecStateChangedWatcher = testutils.DeleteNilEntriesFromMap(lane.Dest.ExecStateChangedWatcher)
case <-lane.Context.Done():
return
}
}
}()
return nil
}

func (lane *CCIPLane) CleanUp(clearFees bool) error {
lane.Logger.Info().Msg("Cleaning up lane")
if lane.Source.Common.ChainClient.GetNetworkConfig().FinalityDepth == 0 {
Expand Down
17 changes: 17 additions & 0 deletions integration-tests/ccip-tests/testconfig/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,23 @@ Example usage:
TTL = "11h"
```

### CCIP.Env.Logging

Specifies the logging configuration for the test. Imported from [LoggingConfig](https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/config/logging.go#L11) in chainlink-testing-framework.
Example usage:

```toml
[CCIP.Env.Logging]

[CCIP.Env.Logging.Loki]
tenant_id = "..."
endpoint = "https://loki...."

[CCIP.Env.Logging.Grafana]
base_url = "https://grafana..../"
dashboard_url = "/d/6vjVx-1V8/ccip-long-running-tests"
```

### CCIP.Env.Lane.LeaderLaneEnabled

Specifies whether to enable the leader lane feature. This setting is only applicable for new deployments.
Expand Down
84 changes: 84 additions & 0 deletions integration-tests/ccip-tests/testconfig/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,90 @@ type Common struct {
func (p *Common) ReadFromEnvVar() error {
logger := logging.GetTestLogger(nil)

lokiTenantID := ctfconfig.MustReadEnvVar_String(ctfconfig.E2E_TEST_LOKI_TENANT_ID_ENV)
if lokiTenantID != "" {
if p.Logging == nil {
p.Logging = &ctfconfig.LoggingConfig{}
}
if p.Logging.Loki == nil {
p.Logging.Loki = &ctfconfig.LokiConfig{}
}
logger.Debug().Msgf("Using %s env var to override Logging.Loki.TenantId", ctfconfig.E2E_TEST_LOKI_TENANT_ID_ENV)
p.Logging.Loki.TenantId = &lokiTenantID
}

lokiEndpoint := ctfconfig.MustReadEnvVar_String(ctfconfig.E2E_TEST_LOKI_ENDPOINT_ENV)
if lokiEndpoint != "" {
if p.Logging == nil {
p.Logging = &ctfconfig.LoggingConfig{}
}
if p.Logging.Loki == nil {
p.Logging.Loki = &ctfconfig.LokiConfig{}
}
logger.Debug().Msgf("Using %s env var to override Logging.Loki.Endpoint", ctfconfig.E2E_TEST_LOKI_ENDPOINT_ENV)
p.Logging.Loki.Endpoint = &lokiEndpoint
}

lokiBasicAuth := ctfconfig.MustReadEnvVar_String(ctfconfig.E2E_TEST_LOKI_BASIC_AUTH_ENV)
if lokiBasicAuth != "" {
if p.Logging == nil {
p.Logging = &ctfconfig.LoggingConfig{}
}
if p.Logging.Loki == nil {
p.Logging.Loki = &ctfconfig.LokiConfig{}
}
logger.Debug().Msgf("Using %s env var to override Logging.Loki.BasicAuth", ctfconfig.E2E_TEST_LOKI_BASIC_AUTH_ENV)
p.Logging.Loki.BasicAuth = &lokiBasicAuth
}

lokiBearerToken := ctfconfig.MustReadEnvVar_String(ctfconfig.E2E_TEST_LOKI_BEARER_TOKEN_ENV)
if lokiBearerToken != "" {
if p.Logging == nil {
p.Logging = &ctfconfig.LoggingConfig{}
}
if p.Logging.Loki == nil {
p.Logging.Loki = &ctfconfig.LokiConfig{}
}
logger.Debug().Msgf("Using %s env var to override Logging.Loki.BearerToken", ctfconfig.E2E_TEST_LOKI_BEARER_TOKEN_ENV)
p.Logging.Loki.BearerToken = &lokiBearerToken
}

grafanaBaseUrl := ctfconfig.MustReadEnvVar_String(ctfconfig.E2E_TEST_GRAFANA_BASE_URL_ENV)
if grafanaBaseUrl != "" {
if p.Logging == nil {
p.Logging = &ctfconfig.LoggingConfig{}
}
if p.Logging.Grafana == nil {
p.Logging.Grafana = &ctfconfig.GrafanaConfig{}
}
logger.Debug().Msgf("Using %s env var to override Logging.Grafana.BaseUrl", ctfconfig.E2E_TEST_GRAFANA_BASE_URL_ENV)
p.Logging.Grafana.BaseUrl = &grafanaBaseUrl
}

grafanaDashboardUrl := ctfconfig.MustReadEnvVar_String(ctfconfig.E2E_TEST_GRAFANA_DASHBOARD_URL_ENV)
if grafanaDashboardUrl != "" {
if p.Logging == nil {
p.Logging = &ctfconfig.LoggingConfig{}
}
if p.Logging.Grafana == nil {
p.Logging.Grafana = &ctfconfig.GrafanaConfig{}
}
logger.Debug().Msgf("Using %s env var to override Logging.Grafana.DashboardUrl", ctfconfig.E2E_TEST_GRAFANA_DASHBOARD_URL_ENV)
p.Logging.Grafana.DashboardUrl = &grafanaDashboardUrl
}

grafanaBearerToken := ctfconfig.MustReadEnvVar_String(ctfconfig.E2E_TEST_GRAFANA_BEARER_TOKEN_ENV)
if grafanaBearerToken != "" {
if p.Logging == nil {
p.Logging = &ctfconfig.LoggingConfig{}
}
if p.Logging.Grafana == nil {
p.Logging.Grafana = &ctfconfig.GrafanaConfig{}
}
logger.Debug().Msgf("Using %s env var to override Logging.Grafana.BearerToken", ctfconfig.E2E_TEST_GRAFANA_BEARER_TOKEN_ENV)
p.Logging.Grafana.BearerToken = &grafanaBearerToken
}

selectedNetworks := ctfconfig.MustReadEnvVar_Strings(ctfconfig.E2E_TEST_SELECTED_NETWORK_ENV, ",")
if len(selectedNetworks) > 0 {
if p.Network == nil {
Expand Down
Loading

0 comments on commit 680151e

Please sign in to comment.