diff --git a/core/services/ocr2/plugins/ccip/commit_inflight_test.go b/core/services/ocr2/plugins/ccip/commit_inflight_test.go index 39d6a1ea7a..c766c2ae4f 100644 --- a/core/services/ocr2/plugins/ccip/commit_inflight_test.go +++ b/core/services/ocr2/plugins/ccip/commit_inflight_test.go @@ -10,9 +10,9 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/commit_store" "github.com/smartcontractkit/chainlink/v2/core/logger" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipcalc" + "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipdata" "github.com/smartcontractkit/chainlink/v2/core/utils" ) @@ -21,7 +21,7 @@ func TestCommitInflight(t *testing.T) { c := newInflightCommitReportsContainer(time.Hour) c.inFlightPriceUpdates = append(c.inFlightPriceUpdates, InflightPriceUpdate{ - priceUpdates: commit_store.InternalPriceUpdates{DestChainSelector: 0}, // skipped when destChainSelector is 0 + gasPrices: []ccipdata.GasPrice{{DestChainSelector: 0, Value: big.NewInt(0)}}, createdAt: time.Now(), epochAndRound: ccipcalc.MergeEpochAndRound(2, 4), }) @@ -36,7 +36,7 @@ func TestCommitInflight(t *testing.T) { // Add a single report inflight root1 := utils.Keccak256Fixed(hexutil.MustDecode("0xaa")) - require.NoError(t, c.add(lggr, commit_store.CommitStoreCommitReport{Interval: commit_store.CommitStoreInterval{Min: 1, Max: 2}, MerkleRoot: root1}, epochAndRound)) + require.NoError(t, c.add(lggr, ccipdata.CommitStoreReport{Interval: ccipdata.CommitStoreInterval{Min: 1, Max: 2}, MerkleRoot: root1}, epochAndRound)) inflightUpdate, hasUpdate = c.getLatestInflightGasPriceUpdate() assert.Equal(t, inflightUpdate, update{}) assert.False(t, hasUpdate) @@ -45,7 +45,7 @@ func TestCommitInflight(t *testing.T) { // Add another price report root2 := utils.Keccak256Fixed(hexutil.MustDecode("0xab")) - require.NoError(t, c.add(lggr, commit_store.CommitStoreCommitReport{Interval: commit_store.CommitStoreInterval{Min: 3, Max: 4}, MerkleRoot: root2}, epochAndRound)) + require.NoError(t, c.add(lggr, ccipdata.CommitStoreReport{Interval: ccipdata.CommitStoreInterval{Min: 3, Max: 4}, MerkleRoot: root2}, epochAndRound)) inflightUpdate, hasUpdate = c.getLatestInflightGasPriceUpdate() assert.Equal(t, inflightUpdate, update{}) assert.False(t, hasUpdate) @@ -53,10 +53,13 @@ func TestCommitInflight(t *testing.T) { epochAndRound++ // Add gas price updates - require.NoError(t, c.add(lggr, commit_store.CommitStoreCommitReport{PriceUpdates: commit_store.InternalPriceUpdates{ - DestChainSelector: uint64(1), - UsdPerUnitGas: big.NewInt(1), - }}, epochAndRound)) + require.NoError(t, c.add(lggr, ccipdata.CommitStoreReport{ + GasPrices: []ccipdata.GasPrice{ + { + DestChainSelector: uint64(1), + Value: big.NewInt(1), + }, + }}, epochAndRound)) inflightUpdate, hasUpdate = c.getLatestInflightGasPriceUpdate() assert.Equal(t, big.NewInt(1), inflightUpdate.value) @@ -66,14 +69,14 @@ func TestCommitInflight(t *testing.T) { // Add a token price update token := common.HexToAddress("0xa") - require.NoError(t, c.add(lggr, commit_store.CommitStoreCommitReport{PriceUpdates: commit_store.InternalPriceUpdates{ - TokenPriceUpdates: []commit_store.InternalTokenPriceUpdate{ + require.NoError(t, c.add(lggr, ccipdata.CommitStoreReport{ + TokenPrices: []ccipdata.TokenPrice{ { - SourceToken: token, - UsdPerToken: big.NewInt(10), + Token: token, + Value: big.NewInt(10), }, }, - }}, epochAndRound)) + }, epochAndRound)) // Apply cache price to existing latestInflightTokenPriceUpdates := c.latestInflightTokenPriceUpdates() require.Equal(t, len(latestInflightTokenPriceUpdates), 1) @@ -81,12 +84,14 @@ func TestCommitInflight(t *testing.T) { // larger epoch and round overrides existing price update c.inFlightPriceUpdates = append(c.inFlightPriceUpdates, InflightPriceUpdate{ - priceUpdates: commit_store.InternalPriceUpdates{ - TokenPriceUpdates: []commit_store.InternalTokenPriceUpdate{ - {SourceToken: token, UsdPerToken: big.NewInt(9999)}, + tokenPrices: []ccipdata.TokenPrice{ + {Token: token, Value: big.NewInt(9999)}, + }, + gasPrices: []ccipdata.GasPrice{ + { + DestChainSelector: uint64(1), + Value: big.NewInt(999), }, - DestChainSelector: uint64(1), - UsdPerUnitGas: big.NewInt(999), }, createdAt: time.Now(), epochAndRound: ccipcalc.MergeEpochAndRound(999, 99), @@ -101,22 +106,22 @@ func Test_inflightCommitReportsContainer_expire(t *testing.T) { cacheExpiry: time.Minute, inFlight: map[[32]byte]InflightCommitReport{ common.HexToHash("1"): { - report: commit_store.CommitStoreCommitReport{}, + report: ccipdata.CommitStoreReport{}, createdAt: time.Now().Add(-5 * time.Minute), }, common.HexToHash("2"): { - report: commit_store.CommitStoreCommitReport{}, + report: ccipdata.CommitStoreReport{}, createdAt: time.Now().Add(-10 * time.Second), }, }, inFlightPriceUpdates: []InflightPriceUpdate{ { - priceUpdates: commit_store.InternalPriceUpdates{DestChainSelector: 100}, + gasPrices: []ccipdata.GasPrice{{DestChainSelector: 100, Value: big.NewInt(0)}}, createdAt: time.Now().Add(-PRICE_EXPIRY_MULTIPLIER * time.Minute), epochAndRound: ccipcalc.MergeEpochAndRound(10, 5), }, { - priceUpdates: commit_store.InternalPriceUpdates{DestChainSelector: 200}, + gasPrices: []ccipdata.GasPrice{{DestChainSelector: 200, Value: big.NewInt(0)}}, createdAt: time.Now().Add(-PRICE_EXPIRY_MULTIPLIER * time.Second), epochAndRound: ccipcalc.MergeEpochAndRound(20, 5), }, diff --git a/core/services/ocr2/plugins/ccip/commit_plugin_test.go b/core/services/ocr2/plugins/ccip/commit_plugin_test.go index 7bc06fe515..d1c6aa5b94 100644 --- a/core/services/ocr2/plugins/ccip/commit_plugin_test.go +++ b/core/services/ocr2/plugins/ccip/commit_plugin_test.go @@ -4,21 +4,13 @@ import ( "context" "fmt" "strconv" - "sync" "testing" - "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/mock" - "github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller" - mocklp "github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller/mocks" evmmocks "github.com/smartcontractkit/chainlink/v2/core/chains/evm/mocks" - "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/commit_store" - mock_contracts "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/mocks" "github.com/smartcontractkit/chainlink/v2/core/logger" "github.com/smartcontractkit/chainlink/v2/core/services/job" - "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/testhelpers" pipelinemocks "github.com/smartcontractkit/chainlink/v2/core/services/pipeline/mocks" "github.com/smartcontractkit/chainlink/v2/core/utils" ) @@ -88,66 +80,3 @@ func TestGetCommitPluginFilterNamesFromSpec(t *testing.T) { } } - -func TestGetCommitPluginFilterNames(t *testing.T) { - onRampAddr := common.HexToAddress("0xdafea492d9c6733ae3d56b7ed1adb60692c98bc2") - priceRegAddr := common.HexToAddress("0xdafea492d9c6733ae3d56b7ed1adb60692c98bc3") - offRampAddr := common.HexToAddress("0xDAFeA492D9c6733Ae3D56b7eD1AdB60692C98BC4") - - mockCommitStore, _ := testhelpers.NewFakeCommitStore(t, 1) - mockCommitStore.SetStaticConfig(commit_store.CommitStoreStaticConfig{OnRamp: onRampAddr}) - mockCommitStore.SetDynamicConfig(commit_store.CommitStoreDynamicConfig{PriceRegistry: priceRegAddr}) - - srcLP := mocklp.NewLogPoller(t) - dstLP := mocklp.NewLogPoller(t) - - dstLP.On("UnregisterFilter", "Commit price updates - 0xdafEa492d9C6733aE3D56b7eD1aDb60692c98bc3", mock.Anything).Return(nil) - dstLP.On("UnregisterFilter", "Fee token added - 0xdafEa492d9C6733aE3D56b7eD1aDb60692c98bc3", mock.Anything).Return(nil) - dstLP.On("UnregisterFilter", "Fee token removed - 0xdafEa492d9C6733aE3D56b7eD1aDb60692c98bc3", mock.Anything).Return(nil) - dstLP.On("UnregisterFilter", "Token pool added - 0xDAFeA492D9c6733Ae3D56b7eD1AdB60692C98BC4", mock.Anything).Return(nil) - dstLP.On("UnregisterFilter", "Token pool removed - 0xDAFeA492D9c6733Ae3D56b7eD1AdB60692C98BC4", mock.Anything).Return(nil) - - err := unregisterCommitPluginFilters(context.Background(), dstLP, mockCommitStore, offRampAddr) - assert.NoError(t, err) - - srcLP.AssertExpectations(t) - dstLP.AssertExpectations(t) -} - -func Test_updateCommitPluginLogPollerFilters(t *testing.T) { - srcLP := &mocklp.LogPoller{} - dstLP := &mocklp.LogPoller{} - - priceRegAddr := common.HexToAddress("0xdafea492d9c6733ae3d56b7ed1adb60692c98bc3") - offRampAddr := common.HexToAddress("0xDAFeA492D9c6733Ae3D56b7eD1AdB60692C98BC4") - offRamp := &mock_contracts.EVM2EVMOffRampInterface{} - offRamp.On("Address").Return(offRampAddr) - - newDestFilters := getCommitPluginDestLpFilters(priceRegAddr, offRampAddr) - - rf := &CommitReportingPluginFactory{ - config: CommitPluginStaticConfig{ - destLP: dstLP, - offRamp: offRamp, - }, - destChainFilters: []logpoller.Filter{ - {Name: "a"}, - {Name: "b"}, - }, - filtersMu: &sync.Mutex{}, - } - - // make sure existing filters get unregistered - for _, f := range rf.destChainFilters { - dstLP.On("UnregisterFilter", f.Name, mock.Anything).Return(nil) - } - // make sure new filters are registered - for _, f := range newDestFilters { - dstLP.On("RegisterFilter", f).Return(nil) - } - err := rf.UpdateLogPollerFilters(priceRegAddr) - assert.NoError(t, err) - - srcLP.AssertExpectations(t) - dstLP.AssertExpectations(t) -} diff --git a/core/services/ocr2/plugins/ccip/commit_reporting_plugin.go b/core/services/ocr2/plugins/ccip/commit_reporting_plugin.go index 67242cb92e..f8cdb5810c 100644 --- a/core/services/ocr2/plugins/ccip/commit_reporting_plugin.go +++ b/core/services/ocr2/plugins/ccip/commit_reporting_plugin.go @@ -78,7 +78,7 @@ type CommitReportingPlugin struct { // Dest commitStoreReader ccipdata.CommitStoreReader destPriceRegistryReader ccipdata.PriceRegistryReader - offchainConfig ccipdata.OffchainConfig + offchainConfig ccipdata.CommitOffchainConfig tokenDecimalsCache cache.AutoSync[map[common.Address]uint8] F int // Offchain diff --git a/core/services/ocr2/plugins/ccip/commit_reporting_plugin_test.go b/core/services/ocr2/plugins/ccip/commit_reporting_plugin_test.go index e8e1b605ac..3e92fb40c3 100644 --- a/core/services/ocr2/plugins/ccip/commit_reporting_plugin_test.go +++ b/core/services/ocr2/plugins/ccip/commit_reporting_plugin_test.go @@ -81,7 +81,7 @@ func TestCommitReportingPlugin_Observation(t *testing.T) { someTokenAddr: big.NewInt(20000000000), }, SourceGasPriceUSD: big.NewInt(0), - Interval: commit_store.CommitStoreInterval{ + Interval: ccipdata.CommitStoreInterval{ Min: 54, Max: 55, }, @@ -171,7 +171,7 @@ func TestCommitReportingPlugin_Report(t *testing.T) { p.tokenDecimalsCache = tokenDecimalsCache p.F = 1 - o := CommitObservation{Interval: commit_store.CommitStoreInterval{Min: 1, Max: 1}, SourceGasPriceUSD: big.NewInt(0)} + o := CommitObservation{Interval: ccipdata.CommitStoreInterval{Min: 1, Max: 1}, SourceGasPriceUSD: big.NewInt(0)} obs, err := o.Marshal() assert.NoError(t, err) @@ -192,15 +192,15 @@ func TestCommitReportingPlugin_Report(t *testing.T) { tokenPriceUpdates []ccipdata.Event[price_registry.PriceRegistryUsdPerTokenUpdated] sendRequests []ccipdata.Event[internal.EVM2EVMMessage] - expCommitReport *commit_store.CommitStoreCommitReport - expSeqNumRange commit_store.CommitStoreInterval + expCommitReport *ccipdata.CommitStoreReport + expSeqNumRange ccipdata.CommitStoreInterval expErr bool }{ { name: "base", observations: []CommitObservation{ - {Interval: commit_store.CommitStoreInterval{Min: 1, Max: 1}, SourceGasPriceUSD: gasPrice}, - {Interval: commit_store.CommitStoreInterval{Min: 1, Max: 1}, SourceGasPriceUSD: gasPrice}, + {Interval: ccipdata.CommitStoreInterval{Min: 1, Max: 1}, SourceGasPriceUSD: gasPrice}, + {Interval: ccipdata.CommitStoreInterval{Min: 1, Max: 1}, SourceGasPriceUSD: gasPrice}, }, f: 1, sendRequests: []ccipdata.Event[internal.EVM2EVMMessage]{ @@ -218,23 +218,20 @@ func TestCommitReportingPlugin_Report(t *testing.T) { }, }, }, - expSeqNumRange: commit_store.CommitStoreInterval{Min: 1, Max: 1}, - expCommitReport: &commit_store.CommitStoreCommitReport{ + expSeqNumRange: ccipdata.CommitStoreInterval{Min: 1, Max: 1}, + expCommitReport: &ccipdata.CommitStoreReport{ MerkleRoot: [32]byte{}, - Interval: commit_store.CommitStoreInterval{Min: 1, Max: 1}, - PriceUpdates: commit_store.InternalPriceUpdates{ - TokenPriceUpdates: nil, - DestChainSelector: uint64(sourceChainSelector), - UsdPerUnitGas: gasPrice, - }, + Interval: ccipdata.CommitStoreInterval{Min: 1, Max: 1}, + TokenPrices: nil, + GasPrices: []ccipdata.GasPrice{{DestChainSelector: uint64(sourceChainSelector), Value: gasPrice}}, }, expErr: false, }, { name: "empty", observations: []CommitObservation{ - {Interval: commit_store.CommitStoreInterval{Min: 0, Max: 0}, SourceGasPriceUSD: big.NewInt(0)}, - {Interval: commit_store.CommitStoreInterval{Min: 0, Max: 0}, SourceGasPriceUSD: big.NewInt(0)}, + {Interval: ccipdata.CommitStoreInterval{Min: 0, Max: 0}, SourceGasPriceUSD: big.NewInt(0)}, + {Interval: ccipdata.CommitStoreInterval{Min: 0, Max: 0}, SourceGasPriceUSD: big.NewInt(0)}, }, gasPriceUpdates: []ccipdata.Event[price_registry.PriceRegistryUsdPerUnitGasUpdated]{ { @@ -250,12 +247,12 @@ func TestCommitReportingPlugin_Report(t *testing.T) { { name: "no leaves", observations: []CommitObservation{ - {Interval: commit_store.CommitStoreInterval{Min: 2, Max: 2}, SourceGasPriceUSD: big.NewInt(0)}, - {Interval: commit_store.CommitStoreInterval{Min: 2, Max: 2}, SourceGasPriceUSD: big.NewInt(0)}, + {Interval: ccipdata.CommitStoreInterval{Min: 2, Max: 2}, SourceGasPriceUSD: big.NewInt(0)}, + {Interval: ccipdata.CommitStoreInterval{Min: 2, Max: 2}, SourceGasPriceUSD: big.NewInt(0)}, }, f: 1, sendRequests: []ccipdata.Event[internal.EVM2EVMMessage]{{}}, - expSeqNumRange: commit_store.CommitStoreInterval{Min: 2, Max: 2}, + expSeqNumRange: ccipdata.CommitStoreInterval{Min: 2, Max: 2}, expErr: true, }, } @@ -286,12 +283,12 @@ func TestCommitReportingPlugin_Report(t *testing.T) { p.lggr = logger.TestLogger(t) p.inflightReports = newInflightCommitReportsContainer(time.Minute) p.destPriceRegistry = destPriceRegistry - p.config.destReader = destReader + p.= destReader p.config.onRampReader = onRampReader p.config.sourceChainSelector = uint64(sourceChainSelector) p.tokenDecimalsCache = tokenDecimalsCache p.gasPriceEstimator = gasPriceEstimator - p.offchainConfig.GasPriceHeartBeat = gasPriceHeartBeat + p.offchainConfig.GasPriceHeartBeat = gasPriceHeartBeat.Duration() p.F = tc.f aos := make([]types.AttributedObservation, 0, len(tc.observations)) @@ -338,7 +335,7 @@ func TestCommitReportingPlugin_ShouldAcceptFinalizedReport(t *testing.T) { t.Run("empty report should not be accepted", func(t *testing.T) { p := newPlugin() - report := commit_store.CommitStoreCommitReport{ + report := ccipdata.CommitStoreReport{ // UsdPerUnitGas is mandatory otherwise report cannot be encoded/decoded PriceUpdates: commit_store.InternalPriceUpdates{UsdPerUnitGas: big.NewInt(int64(rand.Int()))}, } @@ -357,13 +354,13 @@ func TestCommitReportingPlugin_ShouldAcceptFinalizedReport(t *testing.T) { p := newPlugin() p.config.commitStore = commitStore - report := commit_store.CommitStoreCommitReport{ + report := ccipdata.CommitStoreReport{ PriceUpdates: commit_store.InternalPriceUpdates{UsdPerUnitGas: big.NewInt(int64(rand.Int()))}, MerkleRoot: [32]byte{123}, // this report is considered non-empty since it has a merkle root } // stale since report interval is behind on chain seq num - report.Interval = commit_store.CommitStoreInterval{Min: onChainSeqNum - 2, Max: onChainSeqNum + 10} + report.Interval = ccipdata.CommitStoreInterval{Min: onChainSeqNum - 2, Max: onChainSeqNum + 10} encodedReport, err := abihelpers.EncodeCommitReport(report) assert.NoError(t, err) @@ -380,7 +377,7 @@ func TestCommitReportingPlugin_ShouldAcceptFinalizedReport(t *testing.T) { p := newPlugin() p.config.commitStore = commitStore - report := commit_store.CommitStoreCommitReport{ + report := ccipdata.CommitStoreReport{ PriceUpdates: commit_store.InternalPriceUpdates{ TokenPriceUpdates: []commit_store.InternalTokenPriceUpdate{ { @@ -395,7 +392,7 @@ func TestCommitReportingPlugin_ShouldAcceptFinalizedReport(t *testing.T) { } // non-stale since report interval is not behind on-chain seq num - report.Interval = commit_store.CommitStoreInterval{Min: onChainSeqNum, Max: onChainSeqNum + 10} + report.Interval = ccipdata.CommitStoreInterval{Min: onChainSeqNum, Max: onChainSeqNum + 10} encodedReport, err := abihelpers.EncodeCommitReport(report) assert.NoError(t, err) @@ -411,7 +408,7 @@ func TestCommitReportingPlugin_ShouldAcceptFinalizedReport(t *testing.T) { } func TestCommitReportingPlugin_ShouldTransmitAcceptedReport(t *testing.T) { - report := commit_store.CommitStoreCommitReport{ + report := ccipdata.CommitStoreReport{ PriceUpdates: commit_store.InternalPriceUpdates{ TokenPriceUpdates: []commit_store.InternalTokenPriceUpdate{ {SourceToken: utils.RandomAddress(), UsdPerToken: big.NewInt(9e18)}, @@ -433,7 +430,7 @@ func TestCommitReportingPlugin_ShouldTransmitAcceptedReport(t *testing.T) { onChainSeqNum := uint64(100) commitStore.SetNextSequenceNumber(onChainSeqNum) // not-stale since report interval is not behind on chain seq num - report.Interval = commit_store.CommitStoreInterval{Min: onChainSeqNum, Max: onChainSeqNum + 10} + report.Interval = ccipdata.CommitStoreInterval{Min: onChainSeqNum, Max: onChainSeqNum + 10} encodedReport, err := abihelpers.EncodeCommitReport(report) assert.NoError(t, err) shouldTransmit, err := p.ShouldTransmitAcceptedReport(ctx, types.ReportTimestamp{}, encodedReport) @@ -445,7 +442,7 @@ func TestCommitReportingPlugin_ShouldTransmitAcceptedReport(t *testing.T) { onChainSeqNum := uint64(100) commitStore.SetNextSequenceNumber(onChainSeqNum) // stale since report interval is behind on chain seq num - report.Interval = commit_store.CommitStoreInterval{Min: onChainSeqNum - 2, Max: onChainSeqNum + 10} + report.Interval = ccipdata.CommitStoreInterval{Min: onChainSeqNum - 2, Max: onChainSeqNum + 10} encodedReport, err := abihelpers.EncodeCommitReport(report) assert.NoError(t, err) shouldTransmit, err := p.ShouldTransmitAcceptedReport(ctx, types.ReportTimestamp{}, encodedReport) @@ -474,7 +471,7 @@ func TestCommitReportingPlugin_validateObservations(t *testing.T) { tokenDecimals[token2] = 18 ob1 := CommitObservation{ - Interval: commit_store.CommitStoreInterval{Min: 0, Max: 0}, + Interval: ccipdata.CommitStoreInterval{Min: 0, Max: 0}, TokenPricesUSD: map[common.Address]*big.Int{ token1: token1Price, token2: token2Price, @@ -488,7 +485,7 @@ func TestCommitReportingPlugin_validateObservations(t *testing.T) { _ = json.Unmarshal(ob1Bytes, &ob3) obWithNilGasPrice := CommitObservation{ - Interval: commit_store.CommitStoreInterval{Min: 0, Max: 0}, + Interval: ccipdata.CommitStoreInterval{Min: 0, Max: 0}, TokenPricesUSD: map[common.Address]*big.Int{ token1: token1Price, token2: token2Price, @@ -496,7 +493,7 @@ func TestCommitReportingPlugin_validateObservations(t *testing.T) { SourceGasPriceUSD: nil, } obWithNilTokenPrice := CommitObservation{ - Interval: commit_store.CommitStoreInterval{Min: 0, Max: 0}, + Interval: ccipdata.CommitStoreInterval{Min: 0, Max: 0}, TokenPricesUSD: map[common.Address]*big.Int{ token1: token1Price, token2: nil, @@ -504,12 +501,12 @@ func TestCommitReportingPlugin_validateObservations(t *testing.T) { SourceGasPriceUSD: gasPrice, } obMissingTokenPrices := CommitObservation{ - Interval: commit_store.CommitStoreInterval{Min: 0, Max: 0}, + Interval: ccipdata.CommitStoreInterval{Min: 0, Max: 0}, TokenPricesUSD: map[common.Address]*big.Int{}, SourceGasPriceUSD: gasPrice, } obWithUnsupportedToken := CommitObservation{ - Interval: commit_store.CommitStoreInterval{Min: 0, Max: 0}, + Interval: ccipdata.CommitStoreInterval{Min: 0, Max: 0}, TokenPricesUSD: map[common.Address]*big.Int{ token1: token1Price, token2: token2Price, @@ -518,7 +515,7 @@ func TestCommitReportingPlugin_validateObservations(t *testing.T) { SourceGasPriceUSD: gasPrice, } obEmpty := CommitObservation{ - Interval: commit_store.CommitStoreInterval{Min: 0, Max: 0}, + Interval: ccipdata.CommitStoreInterval{Min: 0, Max: 0}, TokenPricesUSD: nil, SourceGasPriceUSD: nil, } @@ -1103,7 +1100,7 @@ func TestCommitReportingPlugin_nextMinSeqNum(t *testing.T) { var tt = []struct { onChainMin uint64 - inflight []commit_store.CommitStoreCommitReport + inflight []ccipdata.CommitStoreReport expectedOnChainMin uint64 expectedInflightMin uint64 }{ @@ -1115,22 +1112,22 @@ func TestCommitReportingPlugin_nextMinSeqNum(t *testing.T) { }, { onChainMin: uint64(1), - inflight: []commit_store.CommitStoreCommitReport{ - {Interval: commit_store.CommitStoreInterval{Min: uint64(1), Max: uint64(2)}, MerkleRoot: root1}}, + inflight: []ccipdata.CommitStoreReport{ + {Interval: ccipdata.CommitStoreInterval{Min: uint64(1), Max: uint64(2)}, MerkleRoot: root1}}, expectedInflightMin: uint64(3), expectedOnChainMin: uint64(1), }, { onChainMin: uint64(1), - inflight: []commit_store.CommitStoreCommitReport{ - {Interval: commit_store.CommitStoreInterval{Min: uint64(3), Max: uint64(4)}, MerkleRoot: root1}}, + inflight: []ccipdata.CommitStoreReport{ + {Interval: ccipdata.CommitStoreInterval{Min: uint64(3), Max: uint64(4)}, MerkleRoot: root1}}, expectedInflightMin: uint64(5), expectedOnChainMin: uint64(1), }, { onChainMin: uint64(1), - inflight: []commit_store.CommitStoreCommitReport{ - {Interval: commit_store.CommitStoreInterval{Min: uint64(1), Max: uint64(MaxInflightSeqNumGap + 2)}, MerkleRoot: root1}}, + inflight: []ccipdata.CommitStoreReport{ + {Interval: ccipdata.CommitStoreInterval{Min: uint64(1), Max: uint64(MaxInflightSeqNumGap + 2)}, MerkleRoot: root1}}, expectedInflightMin: uint64(1), expectedOnChainMin: uint64(1), }, @@ -1162,7 +1159,7 @@ func TestCommitReportingPlugin_isStaleReport(t *testing.T) { t.Run("empty report", func(t *testing.T) { commitStore, _ := testhelpers.NewFakeCommitStore(t, 1) r := &CommitReportingPlugin{config: CommitPluginStaticConfig{commitStore: commitStore}} - isStale := r.isStaleReport(ctx, lggr, commit_store.CommitStoreCommitReport{}, false, types.ReportTimestamp{}) + isStale := r.isStaleReport(ctx, lggr, ccipdata.CommitStoreReport{}, false, types.ReportTimestamp{}) assert.True(t, isStale) }) @@ -1175,25 +1172,25 @@ func TestCommitReportingPlugin_isStaleReport(t *testing.T) { inflightReports: &inflightCommitReportsContainer{ inFlight: map[[32]byte]InflightCommitReport{ merkleRoot2: { - report: commit_store.CommitStoreCommitReport{ - Interval: commit_store.CommitStoreInterval{Min: expNextSeqNum + 1, Max: expNextSeqNum + 10}, + report: ccipdata.CommitStoreReport{ + Interval: ccipdata.CommitStoreInterval{Min: expNextSeqNum + 1, Max: expNextSeqNum + 10}, }, }, }, }, } - assert.False(t, r.isStaleReport(ctx, lggr, commit_store.CommitStoreCommitReport{ + assert.False(t, r.isStaleReport(ctx, lggr, ccipdata.CommitStoreReport{ MerkleRoot: merkleRoot1, - Interval: commit_store.CommitStoreInterval{Min: expNextSeqNum + 1, Max: expNextSeqNum + 10}, + Interval: ccipdata.CommitStoreInterval{Min: expNextSeqNum + 1, Max: expNextSeqNum + 10}, }, false, types.ReportTimestamp{})) - assert.True(t, r.isStaleReport(ctx, lggr, commit_store.CommitStoreCommitReport{ + assert.True(t, r.isStaleReport(ctx, lggr, ccipdata.CommitStoreReport{ MerkleRoot: merkleRoot1, - Interval: commit_store.CommitStoreInterval{Min: expNextSeqNum + 1, Max: expNextSeqNum + 10}, + Interval: ccipdata.CommitStoreInterval{Min: expNextSeqNum + 1, Max: expNextSeqNum + 10}, }, true, types.ReportTimestamp{})) - assert.True(t, r.isStaleReport(ctx, lggr, commit_store.CommitStoreCommitReport{ + assert.True(t, r.isStaleReport(ctx, lggr, ccipdata.CommitStoreReport{ MerkleRoot: merkleRoot1}, false, types.ReportTimestamp{})) }) } @@ -1267,8 +1264,8 @@ func TestCommitReportingPlugin_calculateMinMaxSequenceNumbers(t *testing.T) { p.inflightReports = newInflightCommitReportsContainer(time.Minute) if tc.inflightSeqNum > 0 { p.inflightReports.inFlight[[32]byte{}] = InflightCommitReport{ - report: commit_store.CommitStoreCommitReport{ - Interval: commit_store.CommitStoreInterval{ + report: ccipdata.CommitStoreReport{ + Interval: ccipdata.CommitStoreInterval{ Min: tc.inflightSeqNum, Max: tc.inflightSeqNum, }, @@ -1513,9 +1510,9 @@ func Test_commitReportSize(t *testing.T) { p.Property("bounded commit report size", prop.ForAll(func(root []byte, min, max uint64) bool { var root32 [32]byte copy(root32[:], root) - rep, err := abihelpers.EncodeCommitReport(commit_store.CommitStoreCommitReport{ + rep, err := abihelpers.EncodeCommitReport(ccipdata.CommitStoreReport{ MerkleRoot: root32, - Interval: commit_store.CommitStoreInterval{Min: min, Max: max}, + Interval: ccipdata.CommitStoreInterval{Min: min, Max: max}, PriceUpdates: commit_store.InternalPriceUpdates{ TokenPriceUpdates: []commit_store.InternalTokenPriceUpdate{}, DestChainSelector: 1337, @@ -1531,26 +1528,26 @@ func Test_commitReportSize(t *testing.T) { func Test_calculateIntervalConsensus(t *testing.T) { tests := []struct { name string - intervals []commit_store.CommitStoreInterval + intervals []ccipdata.CommitStoreInterval rangeLimit uint64 f int wantMin uint64 wantMax uint64 wantErr bool }{ - {"no obs", []commit_store.CommitStoreInterval{{Min: 0, Max: 0}}, 0, 0, 0, 0, false}, - {"basic", []commit_store.CommitStoreInterval{ + {"no obs", []ccipdata.CommitStoreInterval{{Min: 0, Max: 0}}, 0, 0, 0, 0, false}, + {"basic", []ccipdata.CommitStoreInterval{ {Min: 9, Max: 14}, {Min: 10, Max: 12}, {Min: 10, Max: 14}, }, 0, 1, 10, 14, false}, - {"min > max", []commit_store.CommitStoreInterval{ + {"min > max", []ccipdata.CommitStoreInterval{ {Min: 9, Max: 4}, {Min: 10, Max: 4}, {Min: 10, Max: 6}, }, 0, 1, 0, 0, true}, { - "range limit", []commit_store.CommitStoreInterval{ + "range limit", []ccipdata.CommitStoreInterval{ {Min: 10, Max: 100}, {Min: 1, Max: 1000}, }, 256, 1, 10, 265, false, @@ -1634,14 +1631,14 @@ func TestCommitReportToEthTxMeta(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { - report := commit_store.CommitStoreCommitReport{ + report := ccipdata.CommitStoreReport{ PriceUpdates: commit_store.InternalPriceUpdates{ TokenPriceUpdates: []commit_store.InternalTokenPriceUpdate{}, DestChainSelector: uint64(1337), UsdPerUnitGas: big.NewInt(2000e9), // $2000 per eth * 1gwei = 2000e9 }, MerkleRoot: tree.Root(), - Interval: commit_store.CommitStoreInterval{Min: tc.min, Max: tc.max}, + Interval: ccipdata.CommitStoreInterval{Min: tc.min, Max: tc.max}, } out, err := abihelpers.EncodeCommitReport(report) require.NoError(t, err) diff --git a/core/services/ocr2/plugins/ccip/execution_plugin.go b/core/services/ocr2/plugins/ccip/execution_plugin.go index adf1191dda..a12e9b3aca 100644 --- a/core/services/ocr2/plugins/ccip/execution_plugin.go +++ b/core/services/ocr2/plugins/ccip/execution_plugin.go @@ -122,7 +122,6 @@ func jobSpecToExecPluginConfig(lggr logger.Logger, jb job.Job, chainSet evm.Lega destLP: destChain.LogPoller(), onRampReader: onRampReader, destReader: ccipdata.NewLogPollerReader(destChain.LogPoller(), execLggr, destChain.Client()), - onRamp: onRamp, offRamp: offRamp, commitStoreReader: commitStoreReader, offRampReader: offRampReader, diff --git a/core/services/ocr2/plugins/ccip/execution_plugin_test.go b/core/services/ocr2/plugins/ccip/execution_plugin_test.go index ab1b27331b..e870814c9d 100644 --- a/core/services/ocr2/plugins/ccip/execution_plugin_test.go +++ b/core/services/ocr2/plugins/ccip/execution_plugin_test.go @@ -4,17 +4,11 @@ import ( "context" "testing" - "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/mock" - mocklp "github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller/mocks" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/mocks" - "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/evm_2_evm_offramp" - "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/evm_2_evm_onramp" "github.com/smartcontractkit/chainlink/v2/core/logger" "github.com/smartcontractkit/chainlink/v2/core/services/job" - "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/testhelpers" ) func TestGetExecutionPluginFilterNamesFromSpec(t *testing.T) { @@ -63,51 +57,3 @@ func TestGetExecutionPluginFilterNamesFromSpec(t *testing.T) { }) } } - -func TestGetExecutionPluginFilterNames(t *testing.T) { - commitStoreAddr := common.HexToAddress("0xdafea492d9c6733ae3d56b7ed1adb60692c98bc3") - srcPriceRegAddr := common.HexToAddress("0xdafea492d9c6733ae3d56b7ed1adb60692c98bc9") - dstPriceRegAddr := common.HexToAddress("0xdafea492d9c6733ae3d56b7ed1adb60692c98b19") - - mockOffRamp, offRampAddr := testhelpers.NewFakeOffRamp(t) - mockOffRamp.SetDynamicConfig(evm_2_evm_offramp.EVM2EVMOffRampDynamicConfig{PriceRegistry: dstPriceRegAddr}) - - mockOnRamp, _ := testhelpers.NewFakeOnRamp(t) - mockOnRamp.SetDynamicCfg(evm_2_evm_onramp.EVM2EVMOnRampDynamicConfig{PriceRegistry: srcPriceRegAddr}) - - srcLP := mocklp.NewLogPoller(t) - srcFilters := []string{ - "Fee token added - 0xdAFea492D9c6733aE3d56B7ed1ADb60692c98bC9", - "Fee token removed - 0xdAFea492D9c6733aE3d56B7ed1ADb60692c98bC9", - } - for _, f := range srcFilters { - srcLP.On("UnregisterFilter", f, mock.Anything).Return(nil) - } - - dstLP := mocklp.NewLogPoller(t) - dstFilters := []string{ - "Exec report accepts - 0xdafEa492d9C6733aE3D56b7eD1aDb60692c98bc3", - "Exec execution state changes - " + offRampAddr.String(), - "Token pool added - " + offRampAddr.String(), - "Token pool removed - " + offRampAddr.String(), - "Fee token added - 0xdaFEa492D9C6733Ae3D56b7ed1adB60692C98b19", - "Fee token removed - 0xdaFEa492D9C6733Ae3D56b7ed1adB60692C98b19", - } - for _, f := range dstFilters { - dstLP.On("UnregisterFilter", f, mock.Anything).Return(nil) - } - - err := unregisterExecutionPluginLpFilters( - context.Background(), - srcLP, - dstLP, - mockOffRamp, - commitStoreAddr, - mockOnRamp, - nil, - ) - assert.NoError(t, err) - - srcLP.AssertExpectations(t) - dstLP.AssertExpectations(t) -} diff --git a/core/services/ocr2/plugins/ccip/internal/ccipdata/commit_store_reader.go b/core/services/ocr2/plugins/ccip/internal/ccipdata/commit_store_reader.go index 0a3c6da897..b1a9db30ca 100644 --- a/core/services/ocr2/plugins/ccip/internal/ccipdata/commit_store_reader.go +++ b/core/services/ocr2/plugins/ccip/internal/ccipdata/commit_store_reader.go @@ -52,7 +52,7 @@ func (d CommitOnchainConfig) Validate() error { return nil } -type OffchainConfig struct { +type CommitOffchainConfig struct { SourceFinalityDepth uint32 GasPriceDeviationPPB uint32 GasPriceHeartBeat time.Duration @@ -62,6 +62,7 @@ type OffchainConfig struct { DestFinalityDepth uint32 } +//go:generate mockery --quiet --name CommitStoreReader --output . --filename commit_store_reader_mock.go --inpackage --case=underscore type CommitStoreReader interface { Closer GetExpectedNextSequenceNumber(context context.Context) (uint64, error) @@ -74,7 +75,7 @@ type CommitStoreReader interface { IsBlessed(ctx context.Context, root [32]byte) (bool, error) // Notifies the reader that the config has changed onchain ConfigChanged(onchainConfig []byte, offchainConfig []byte) (common.Address, error) - OffchainConfig() OffchainConfig + OffchainConfig() CommitOffchainConfig GasPriceEstimator() prices.GasPriceEstimatorCommit EncodeCommitReport(report CommitStoreReport) ([]byte, error) DecodeCommitReport(report []byte) (CommitStoreReport, error) diff --git a/core/services/ocr2/plugins/ccip/internal/ccipdata/commit_store_reader_mock.go b/core/services/ocr2/plugins/ccip/internal/ccipdata/commit_store_reader_mock.go new file mode 100644 index 0000000000..659c1b585c --- /dev/null +++ b/core/services/ocr2/plugins/ccip/internal/ccipdata/commit_store_reader_mock.go @@ -0,0 +1,315 @@ +// Code generated by mockery v2.28.1. DO NOT EDIT. + +package ccipdata + +import ( + context "context" + + common "github.com/ethereum/go-ethereum/common" + + mock "github.com/stretchr/testify/mock" + + pg "github.com/smartcontractkit/chainlink/v2/core/services/pg" + + prices "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/prices" + + time "time" +) + +// MockCommitStoreReader is an autogenerated mock type for the CommitStoreReader type +type MockCommitStoreReader struct { + mock.Mock +} + +// Close provides a mock function with given fields: qopts +func (_m *MockCommitStoreReader) Close(qopts ...pg.QOpt) error { + _va := make([]interface{}, len(qopts)) + for _i := range qopts { + _va[_i] = qopts[_i] + } + var _ca []interface{} + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + var r0 error + if rf, ok := ret.Get(0).(func(...pg.QOpt) error); ok { + r0 = rf(qopts...) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// ConfigChanged provides a mock function with given fields: onchainConfig, offchainConfig +func (_m *MockCommitStoreReader) ConfigChanged(onchainConfig []byte, offchainConfig []byte) (common.Address, error) { + ret := _m.Called(onchainConfig, offchainConfig) + + var r0 common.Address + var r1 error + if rf, ok := ret.Get(0).(func([]byte, []byte) (common.Address, error)); ok { + return rf(onchainConfig, offchainConfig) + } + if rf, ok := ret.Get(0).(func([]byte, []byte) common.Address); ok { + r0 = rf(onchainConfig, offchainConfig) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(common.Address) + } + } + + if rf, ok := ret.Get(1).(func([]byte, []byte) error); ok { + r1 = rf(onchainConfig, offchainConfig) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// DecodeCommitReport provides a mock function with given fields: report +func (_m *MockCommitStoreReader) DecodeCommitReport(report []byte) (CommitStoreReport, error) { + ret := _m.Called(report) + + var r0 CommitStoreReport + var r1 error + if rf, ok := ret.Get(0).(func([]byte) (CommitStoreReport, error)); ok { + return rf(report) + } + if rf, ok := ret.Get(0).(func([]byte) CommitStoreReport); ok { + r0 = rf(report) + } else { + r0 = ret.Get(0).(CommitStoreReport) + } + + if rf, ok := ret.Get(1).(func([]byte) error); ok { + r1 = rf(report) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// EncodeCommitReport provides a mock function with given fields: report +func (_m *MockCommitStoreReader) EncodeCommitReport(report CommitStoreReport) ([]byte, error) { + ret := _m.Called(report) + + var r0 []byte + var r1 error + if rf, ok := ret.Get(0).(func(CommitStoreReport) ([]byte, error)); ok { + return rf(report) + } + if rf, ok := ret.Get(0).(func(CommitStoreReport) []byte); ok { + r0 = rf(report) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]byte) + } + } + + if rf, ok := ret.Get(1).(func(CommitStoreReport) error); ok { + r1 = rf(report) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GasPriceEstimator provides a mock function with given fields: +func (_m *MockCommitStoreReader) GasPriceEstimator() prices.GasPriceEstimatorCommit { + ret := _m.Called() + + var r0 prices.GasPriceEstimatorCommit + if rf, ok := ret.Get(0).(func() prices.GasPriceEstimatorCommit); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(prices.GasPriceEstimatorCommit) + } + } + + return r0 +} + +// GetAcceptedCommitReportsGteSeqNum provides a mock function with given fields: ctx, seqNum, confs +func (_m *MockCommitStoreReader) GetAcceptedCommitReportsGteSeqNum(ctx context.Context, seqNum uint64, confs int) ([]Event[CommitStoreReport], error) { + ret := _m.Called(ctx, seqNum, confs) + + var r0 []Event[CommitStoreReport] + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, uint64, int) ([]Event[CommitStoreReport], error)); ok { + return rf(ctx, seqNum, confs) + } + if rf, ok := ret.Get(0).(func(context.Context, uint64, int) []Event[CommitStoreReport]); ok { + r0 = rf(ctx, seqNum, confs) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]Event[CommitStoreReport]) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, uint64, int) error); ok { + r1 = rf(ctx, seqNum, confs) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetAcceptedCommitReportsGteTimestamp provides a mock function with given fields: ctx, ts, confs +func (_m *MockCommitStoreReader) GetAcceptedCommitReportsGteTimestamp(ctx context.Context, ts time.Time, confs int) ([]Event[CommitStoreReport], error) { + ret := _m.Called(ctx, ts, confs) + + var r0 []Event[CommitStoreReport] + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, time.Time, int) ([]Event[CommitStoreReport], error)); ok { + return rf(ctx, ts, confs) + } + if rf, ok := ret.Get(0).(func(context.Context, time.Time, int) []Event[CommitStoreReport]); ok { + r0 = rf(ctx, ts, confs) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]Event[CommitStoreReport]) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, time.Time, int) error); ok { + r1 = rf(ctx, ts, confs) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetExpectedNextSequenceNumber provides a mock function with given fields: _a0 +func (_m *MockCommitStoreReader) GetExpectedNextSequenceNumber(_a0 context.Context) (uint64, error) { + ret := _m.Called(_a0) + + var r0 uint64 + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) (uint64, error)); ok { + return rf(_a0) + } + if rf, ok := ret.Get(0).(func(context.Context) uint64); ok { + r0 = rf(_a0) + } else { + r0 = ret.Get(0).(uint64) + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(_a0) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetLatestPriceEpochAndRound provides a mock function with given fields: _a0 +func (_m *MockCommitStoreReader) GetLatestPriceEpochAndRound(_a0 context.Context) (uint64, error) { + ret := _m.Called(_a0) + + var r0 uint64 + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) (uint64, error)); ok { + return rf(_a0) + } + if rf, ok := ret.Get(0).(func(context.Context) uint64); ok { + r0 = rf(_a0) + } else { + r0 = ret.Get(0).(uint64) + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(_a0) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// IsBlessed provides a mock function with given fields: ctx, root +func (_m *MockCommitStoreReader) IsBlessed(ctx context.Context, root [32]byte) (bool, error) { + ret := _m.Called(ctx, root) + + var r0 bool + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, [32]byte) (bool, error)); ok { + return rf(ctx, root) + } + if rf, ok := ret.Get(0).(func(context.Context, [32]byte) bool); ok { + r0 = rf(ctx, root) + } else { + r0 = ret.Get(0).(bool) + } + + if rf, ok := ret.Get(1).(func(context.Context, [32]byte) error); ok { + r1 = rf(ctx, root) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// IsDown provides a mock function with given fields: ctx +func (_m *MockCommitStoreReader) IsDown(ctx context.Context) bool { + ret := _m.Called(ctx) + + var r0 bool + if rf, ok := ret.Get(0).(func(context.Context) bool); ok { + r0 = rf(ctx) + } else { + r0 = ret.Get(0).(bool) + } + + return r0 +} + +// OffchainConfig provides a mock function with given fields: +func (_m *MockCommitStoreReader) OffchainConfig() CommitOffchainConfig { + ret := _m.Called() + + var r0 CommitOffchainConfig + if rf, ok := ret.Get(0).(func() CommitOffchainConfig); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(CommitOffchainConfig) + } + + return r0 +} + +// Verify provides a mock function with given fields: ctx, report +func (_m *MockCommitStoreReader) Verify(ctx context.Context, report ExecReport) bool { + ret := _m.Called(ctx, report) + + var r0 bool + if rf, ok := ret.Get(0).(func(context.Context, ExecReport) bool); ok { + r0 = rf(ctx, report) + } else { + r0 = ret.Get(0).(bool) + } + + return r0 +} + +type mockConstructorTestingTNewMockCommitStoreReader interface { + mock.TestingT + Cleanup(func()) +} + +// NewMockCommitStoreReader creates a new instance of MockCommitStoreReader. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewMockCommitStoreReader(t mockConstructorTestingTNewMockCommitStoreReader) *MockCommitStoreReader { + mock := &MockCommitStoreReader{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/core/services/ocr2/plugins/ccip/internal/ccipdata/commit_store_v1_0_0.go b/core/services/ocr2/plugins/ccip/internal/ccipdata/commit_store_v1_0_0.go index d38ebd26d7..8b1c5a3c67 100644 --- a/core/services/ocr2/plugins/ccip/internal/ccipdata/commit_store_v1_0_0.go +++ b/core/services/ocr2/plugins/ccip/internal/ccipdata/commit_store_v1_0_0.go @@ -38,7 +38,7 @@ type CommitStoreV1_0_0 struct { address common.Address estimator gas.EvmFeeEstimator gasPriceEstimator prices.ExecGasPriceEstimator - offchainConfig OffchainConfig + offchainConfig CommitOffchainConfig filters []logpoller.Filter reportAcceptedSig common.Hash reportAcceptedMaxSeqIndex int @@ -123,7 +123,7 @@ func (c *CommitStoreV1_0_0) IsBlessed(ctx context.Context, root [32]byte) (bool, return c.commitStore.IsBlessed(&bind.CallOpts{Context: ctx}, root) } -func (c *CommitStoreV1_0_0) OffchainConfig() OffchainConfig { +func (c *CommitStoreV1_0_0) OffchainConfig() CommitOffchainConfig { return c.offchainConfig } @@ -178,7 +178,7 @@ func (c *CommitStoreV1_0_0) ConfigChanged(onchainConfig []byte, offchainConfig [ c.estimator, big.NewInt(int64(offchainConfigV1.MaxGasPrice)), int64(offchainConfigV1.FeeUpdateDeviationPPB)) - c.offchainConfig = OffchainConfig{ + c.offchainConfig = CommitOffchainConfig{ SourceFinalityDepth: offchainConfigV1.SourceFinalityDepth, GasPriceDeviationPPB: offchainConfigV1.FeeUpdateDeviationPPB, TokenPriceDeviationPPB: offchainConfigV1.FeeUpdateDeviationPPB, diff --git a/core/services/ocr2/plugins/ccip/internal/ccipdata/commit_store_v1_2_0.go b/core/services/ocr2/plugins/ccip/internal/ccipdata/commit_store_v1_2_0.go index 00d05ba6d7..65c9b58137 100644 --- a/core/services/ocr2/plugins/ccip/internal/ccipdata/commit_store_v1_2_0.go +++ b/core/services/ocr2/plugins/ccip/internal/ccipdata/commit_store_v1_2_0.go @@ -65,7 +65,7 @@ func (c CommitOffchainConfigV1_2_0) Validate() error { type CommitStoreV1_2_0 struct { *CommitStoreV1_0_0 gasPriceEstimator prices.DAGasPriceEstimator - offchainConfig OffchainConfig + offchainConfig CommitOffchainConfig } func (c *CommitStoreV1_2_0) ConfigChanged(onchainConfig []byte, offchainConfig []byte) (common.Address, error) { @@ -84,7 +84,7 @@ func (c *CommitStoreV1_2_0) ConfigChanged(onchainConfig []byte, offchainConfig [ int64(offchainConfigParsed.ExecGasPriceDeviationPPB), int64(offchainConfigParsed.DAGasPriceDeviationPPB), ) - c.offchainConfig = OffchainConfig{ + c.offchainConfig = CommitOffchainConfig{ SourceFinalityDepth: offchainConfigParsed.SourceFinalityDepth, GasPriceDeviationPPB: offchainConfigParsed.ExecGasPriceDeviationPPB, TokenPriceDeviationPPB: offchainConfigParsed.TokenPriceDeviationPPB, @@ -98,7 +98,7 @@ func (c *CommitStoreV1_2_0) ConfigChanged(onchainConfig []byte, offchainConfig [ return onchainConfigParsed.PriceRegistry, nil } -func (c *CommitStoreV1_2_0) OffchainConfig() OffchainConfig { +func (c *CommitStoreV1_2_0) OffchainConfig() CommitOffchainConfig { return c.offchainConfig } diff --git a/core/services/ocr2/plugins/ccip/internal/ccipdata/offramp_reader.go b/core/services/ocr2/plugins/ccip/internal/ccipdata/offramp_reader.go index a23cb75edd..37b29df96b 100644 --- a/core/services/ocr2/plugins/ccip/internal/ccipdata/offramp_reader.go +++ b/core/services/ocr2/plugins/ccip/internal/ccipdata/offramp_reader.go @@ -121,6 +121,7 @@ type ExecReport struct { ProofFlagBits *big.Int } +//go:generate mockery --quiet --name OffRampReader --output . --filename offramp_reader_mock.go --inpackage --case=underscore type OffRampReader interface { Closer // Will error if messages are not a compatible verion diff --git a/core/services/ocr2/plugins/ccip/internal/ccipdata/offramp_reader_mock.go b/core/services/ocr2/plugins/ccip/internal/ccipdata/offramp_reader_mock.go new file mode 100644 index 0000000000..660dece30f --- /dev/null +++ b/core/services/ocr2/plugins/ccip/internal/ccipdata/offramp_reader_mock.go @@ -0,0 +1,346 @@ +// Code generated by mockery v2.28.1. DO NOT EDIT. + +package ccipdata + +import ( + context "context" + + common "github.com/ethereum/go-ethereum/common" + + mock "github.com/stretchr/testify/mock" + + pg "github.com/smartcontractkit/chainlink/v2/core/services/pg" + + prices "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/prices" +) + +// MockOffRampReader is an autogenerated mock type for the OffRampReader type +type MockOffRampReader struct { + mock.Mock +} + +// Address provides a mock function with given fields: +func (_m *MockOffRampReader) Address() common.Address { + ret := _m.Called() + + var r0 common.Address + if rf, ok := ret.Get(0).(func() common.Address); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(common.Address) + } + } + + return r0 +} + +// Close provides a mock function with given fields: qopts +func (_m *MockOffRampReader) Close(qopts ...pg.QOpt) error { + _va := make([]interface{}, len(qopts)) + for _i := range qopts { + _va[_i] = qopts[_i] + } + var _ca []interface{} + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + var r0 error + if rf, ok := ret.Get(0).(func(...pg.QOpt) error); ok { + r0 = rf(qopts...) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// ConfigChanged provides a mock function with given fields: onchainConfig, offchainConfig +func (_m *MockOffRampReader) ConfigChanged(onchainConfig []byte, offchainConfig []byte) (common.Address, common.Address, error) { + ret := _m.Called(onchainConfig, offchainConfig) + + var r0 common.Address + var r1 common.Address + var r2 error + if rf, ok := ret.Get(0).(func([]byte, []byte) (common.Address, common.Address, error)); ok { + return rf(onchainConfig, offchainConfig) + } + if rf, ok := ret.Get(0).(func([]byte, []byte) common.Address); ok { + r0 = rf(onchainConfig, offchainConfig) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(common.Address) + } + } + + if rf, ok := ret.Get(1).(func([]byte, []byte) common.Address); ok { + r1 = rf(onchainConfig, offchainConfig) + } else { + if ret.Get(1) != nil { + r1 = ret.Get(1).(common.Address) + } + } + + if rf, ok := ret.Get(2).(func([]byte, []byte) error); ok { + r2 = rf(onchainConfig, offchainConfig) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// DecodeExecutionReport provides a mock function with given fields: report +func (_m *MockOffRampReader) DecodeExecutionReport(report []byte) (ExecReport, error) { + ret := _m.Called(report) + + var r0 ExecReport + var r1 error + if rf, ok := ret.Get(0).(func([]byte) (ExecReport, error)); ok { + return rf(report) + } + if rf, ok := ret.Get(0).(func([]byte) ExecReport); ok { + r0 = rf(report) + } else { + r0 = ret.Get(0).(ExecReport) + } + + if rf, ok := ret.Get(1).(func([]byte) error); ok { + r1 = rf(report) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// EncodeExecutionReport provides a mock function with given fields: report +func (_m *MockOffRampReader) EncodeExecutionReport(report ExecReport) ([]byte, error) { + ret := _m.Called(report) + + var r0 []byte + var r1 error + if rf, ok := ret.Get(0).(func(ExecReport) ([]byte, error)); ok { + return rf(report) + } + if rf, ok := ret.Get(0).(func(ExecReport) []byte); ok { + r0 = rf(report) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]byte) + } + } + + if rf, ok := ret.Get(1).(func(ExecReport) error); ok { + r1 = rf(report) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GasPriceEstimator provides a mock function with given fields: +func (_m *MockOffRampReader) GasPriceEstimator() prices.GasPriceEstimatorExec { + ret := _m.Called() + + var r0 prices.GasPriceEstimatorExec + if rf, ok := ret.Get(0).(func() prices.GasPriceEstimatorExec); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(prices.GasPriceEstimatorExec) + } + } + + return r0 +} + +// GetDestinationToken provides a mock function with given fields: ctx, address +func (_m *MockOffRampReader) GetDestinationToken(ctx context.Context, address common.Address) (common.Address, error) { + ret := _m.Called(ctx, address) + + var r0 common.Address + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, common.Address) (common.Address, error)); ok { + return rf(ctx, address) + } + if rf, ok := ret.Get(0).(func(context.Context, common.Address) common.Address); ok { + r0 = rf(ctx, address) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(common.Address) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, common.Address) error); ok { + r1 = rf(ctx, address) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetDestinationTokens provides a mock function with given fields: ctx +func (_m *MockOffRampReader) GetDestinationTokens(ctx context.Context) ([]common.Address, error) { + ret := _m.Called(ctx) + + var r0 []common.Address + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) ([]common.Address, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) []common.Address); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]common.Address) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetExecutionStateChangesBetweenSeqNums provides a mock function with given fields: ctx, seqNumMin, seqNumMax, confs +func (_m *MockOffRampReader) GetExecutionStateChangesBetweenSeqNums(ctx context.Context, seqNumMin uint64, seqNumMax uint64, confs int) ([]Event[ExecutionStateChanged], error) { + ret := _m.Called(ctx, seqNumMin, seqNumMax, confs) + + var r0 []Event[ExecutionStateChanged] + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, uint64, uint64, int) ([]Event[ExecutionStateChanged], error)); ok { + return rf(ctx, seqNumMin, seqNumMax, confs) + } + if rf, ok := ret.Get(0).(func(context.Context, uint64, uint64, int) []Event[ExecutionStateChanged]); ok { + r0 = rf(ctx, seqNumMin, seqNumMax, confs) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]Event[ExecutionStateChanged]) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, uint64, uint64, int) error); ok { + r1 = rf(ctx, seqNumMin, seqNumMax, confs) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetPoolByDestToken provides a mock function with given fields: ctx, address +func (_m *MockOffRampReader) GetPoolByDestToken(ctx context.Context, address common.Address) (common.Address, error) { + ret := _m.Called(ctx, address) + + var r0 common.Address + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, common.Address) (common.Address, error)); ok { + return rf(ctx, address) + } + if rf, ok := ret.Get(0).(func(context.Context, common.Address) common.Address); ok { + r0 = rf(ctx, address) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(common.Address) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, common.Address) error); ok { + r1 = rf(ctx, address) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetSupportedTokens provides a mock function with given fields: ctx +func (_m *MockOffRampReader) GetSupportedTokens(ctx context.Context) ([]common.Address, error) { + ret := _m.Called(ctx) + + var r0 []common.Address + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) ([]common.Address, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) []common.Address); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]common.Address) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// OffchainConfig provides a mock function with given fields: +func (_m *MockOffRampReader) OffchainConfig() ExecOffchainConfig { + ret := _m.Called() + + var r0 ExecOffchainConfig + if rf, ok := ret.Get(0).(func() ExecOffchainConfig); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(ExecOffchainConfig) + } + + return r0 +} + +// OnchainConfig provides a mock function with given fields: +func (_m *MockOffRampReader) OnchainConfig() ExecOnchainConfig { + ret := _m.Called() + + var r0 ExecOnchainConfig + if rf, ok := ret.Get(0).(func() ExecOnchainConfig); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(ExecOnchainConfig) + } + + return r0 +} + +// TokenEvents provides a mock function with given fields: +func (_m *MockOffRampReader) TokenEvents() []common.Hash { + ret := _m.Called() + + var r0 []common.Hash + if rf, ok := ret.Get(0).(func() []common.Hash); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]common.Hash) + } + } + + return r0 +} + +type mockConstructorTestingTNewMockOffRampReader interface { + mock.TestingT + Cleanup(func()) +} + +// NewMockOffRampReader creates a new instance of MockOffRampReader. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewMockOffRampReader(t mockConstructorTestingTNewMockOffRampReader) *MockOffRampReader { + mock := &MockOffRampReader{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/core/services/ocr2/plugins/ccip/internal/ccipdata/onramp_reader_mock.go b/core/services/ocr2/plugins/ccip/internal/ccipdata/onramp_reader_mock.go index 2ddbd979da..c4ccd04dbc 100644 --- a/core/services/ocr2/plugins/ccip/internal/ccipdata/onramp_reader_mock.go +++ b/core/services/ocr2/plugins/ccip/internal/ccipdata/onramp_reader_mock.go @@ -18,11 +18,11 @@ type MockOnRampReader struct { mock.Mock } -// Close provides a mock function with given fields: opt -func (_m *MockOnRampReader) Close(opt ...pg.QOpt) error { - _va := make([]interface{}, len(opt)) - for _i := range opt { - _va[_i] = opt[_i] +// Close provides a mock function with given fields: qopts +func (_m *MockOnRampReader) Close(qopts ...pg.QOpt) error { + _va := make([]interface{}, len(qopts)) + for _i := range qopts { + _va[_i] = qopts[_i] } var _ca []interface{} _ca = append(_ca, _va...) @@ -30,7 +30,7 @@ func (_m *MockOnRampReader) Close(opt ...pg.QOpt) error { var r0 error if rf, ok := ret.Get(0).(func(...pg.QOpt) error); ok { - r0 = rf(opt...) + r0 = rf(qopts...) } else { r0 = ret.Error(0) } diff --git a/core/services/ocr2/plugins/ccip/internal/ccipdata/price_registry_reader.go b/core/services/ocr2/plugins/ccip/internal/ccipdata/price_registry_reader.go index 944d88ac15..bbf99bb836 100644 --- a/core/services/ocr2/plugins/ccip/internal/ccipdata/price_registry_reader.go +++ b/core/services/ocr2/plugins/ccip/internal/ccipdata/price_registry_reader.go @@ -41,6 +41,7 @@ type GasPriceUpdate struct { Timestamp *big.Int } +//go:generate mockery --quiet --name PriceRegistryReader --output . --filename price_registry_reader_mock.go --inpackage --case=underscore type PriceRegistryReader interface { Close(qopts ...pg.QOpt) error // GetTokenPriceUpdatesCreatedAfter returns all the token price updates that happened after the provided timestamp. diff --git a/core/services/ocr2/plugins/ccip/internal/ccipdata/price_registry_reader_mock.go b/core/services/ocr2/plugins/ccip/internal/ccipdata/price_registry_reader_mock.go new file mode 100644 index 0000000000..2ebf23e211 --- /dev/null +++ b/core/services/ocr2/plugins/ccip/internal/ccipdata/price_registry_reader_mock.go @@ -0,0 +1,191 @@ +// Code generated by mockery v2.28.1. DO NOT EDIT. + +package ccipdata + +import ( + context "context" + + common "github.com/ethereum/go-ethereum/common" + + mock "github.com/stretchr/testify/mock" + + pg "github.com/smartcontractkit/chainlink/v2/core/services/pg" + + time "time" +) + +// MockPriceRegistryReader is an autogenerated mock type for the PriceRegistryReader type +type MockPriceRegistryReader struct { + mock.Mock +} + +// Address provides a mock function with given fields: +func (_m *MockPriceRegistryReader) Address() common.Address { + ret := _m.Called() + + var r0 common.Address + if rf, ok := ret.Get(0).(func() common.Address); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(common.Address) + } + } + + return r0 +} + +// Close provides a mock function with given fields: qopts +func (_m *MockPriceRegistryReader) Close(qopts ...pg.QOpt) error { + _va := make([]interface{}, len(qopts)) + for _i := range qopts { + _va[_i] = qopts[_i] + } + var _ca []interface{} + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + var r0 error + if rf, ok := ret.Get(0).(func(...pg.QOpt) error); ok { + r0 = rf(qopts...) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// FeeTokenEvents provides a mock function with given fields: +func (_m *MockPriceRegistryReader) FeeTokenEvents() []common.Hash { + ret := _m.Called() + + var r0 []common.Hash + if rf, ok := ret.Get(0).(func() []common.Hash); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]common.Hash) + } + } + + return r0 +} + +// GetFeeTokens provides a mock function with given fields: ctx +func (_m *MockPriceRegistryReader) GetFeeTokens(ctx context.Context) ([]common.Address, error) { + ret := _m.Called(ctx) + + var r0 []common.Address + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) ([]common.Address, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) []common.Address); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]common.Address) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetGasPriceUpdatesCreatedAfter provides a mock function with given fields: ctx, chainSelector, ts, confs +func (_m *MockPriceRegistryReader) GetGasPriceUpdatesCreatedAfter(ctx context.Context, chainSelector uint64, ts time.Time, confs int) ([]Event[GasPriceUpdate], error) { + ret := _m.Called(ctx, chainSelector, ts, confs) + + var r0 []Event[GasPriceUpdate] + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, uint64, time.Time, int) ([]Event[GasPriceUpdate], error)); ok { + return rf(ctx, chainSelector, ts, confs) + } + if rf, ok := ret.Get(0).(func(context.Context, uint64, time.Time, int) []Event[GasPriceUpdate]); ok { + r0 = rf(ctx, chainSelector, ts, confs) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]Event[GasPriceUpdate]) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, uint64, time.Time, int) error); ok { + r1 = rf(ctx, chainSelector, ts, confs) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetTokenPriceUpdatesCreatedAfter provides a mock function with given fields: ctx, ts, confs +func (_m *MockPriceRegistryReader) GetTokenPriceUpdatesCreatedAfter(ctx context.Context, ts time.Time, confs int) ([]Event[TokenPriceUpdate], error) { + ret := _m.Called(ctx, ts, confs) + + var r0 []Event[TokenPriceUpdate] + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, time.Time, int) ([]Event[TokenPriceUpdate], error)); ok { + return rf(ctx, ts, confs) + } + if rf, ok := ret.Get(0).(func(context.Context, time.Time, int) []Event[TokenPriceUpdate]); ok { + r0 = rf(ctx, ts, confs) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]Event[TokenPriceUpdate]) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, time.Time, int) error); ok { + r1 = rf(ctx, ts, confs) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetTokenPrices provides a mock function with given fields: ctx, wantedTokens +func (_m *MockPriceRegistryReader) GetTokenPrices(ctx context.Context, wantedTokens []common.Address) ([]TokenPriceUpdate, error) { + ret := _m.Called(ctx, wantedTokens) + + var r0 []TokenPriceUpdate + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, []common.Address) ([]TokenPriceUpdate, error)); ok { + return rf(ctx, wantedTokens) + } + if rf, ok := ret.Get(0).(func(context.Context, []common.Address) []TokenPriceUpdate); ok { + r0 = rf(ctx, wantedTokens) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]TokenPriceUpdate) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, []common.Address) error); ok { + r1 = rf(ctx, wantedTokens) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +type mockConstructorTestingTNewMockPriceRegistryReader interface { + mock.TestingT + Cleanup(func()) +} + +// NewMockPriceRegistryReader creates a new instance of MockPriceRegistryReader. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewMockPriceRegistryReader(t mockConstructorTestingTNewMockPriceRegistryReader) *MockPriceRegistryReader { + mock := &MockPriceRegistryReader{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/core/services/ocr2/plugins/ccip/internal/contractutil/shortcuts.go b/core/services/ocr2/plugins/ccip/internal/contractutil/shortcuts.go index 2209f8b09e..a6175d5561 100644 --- a/core/services/ocr2/plugins/ccip/internal/contractutil/shortcuts.go +++ b/core/services/ocr2/plugins/ccip/internal/contractutil/shortcuts.go @@ -1,26 +1,11 @@ package contractutil import ( - "context" "encoding/hex" - "github.com/ethereum/go-ethereum/accounts/abi/bind" - - "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/commit_store" - "github.com/smartcontractkit/chainlink/v2/core/logger" + "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal" ) -// IsCommitStoreDownNow Checks whether the commit store is down by doing an onchain check for Paused and ARM status -func IsCommitStoreDownNow(ctx context.Context, lggr logger.Logger, commitStore commit_store.CommitStoreInterface) bool { - unPausedAndHealthy, err := commitStore.IsUnpausedAndARMHealthy(&bind.CallOpts{Context: ctx}) - if err != nil { - // If we cannot read the state, assume the worst - lggr.Errorw("Unable to read CommitStore IsUnpausedAndARMHealthy", "err", err) - return true - } - return !unPausedAndHealthy -} - func GetMessageIDsAsHexString(messages []internal.EVM2EVMMessage) []string { messageIDs := make([]string, 0, len(messages)) for _, m := range messages { diff --git a/core/services/ocr2/plugins/ccip/testhelpers/ccip_contracts.go b/core/services/ocr2/plugins/ccip/testhelpers/ccip_contracts.go index aee8f196c6..25b2ee4363 100644 --- a/core/services/ocr2/plugins/ccip/testhelpers/ccip_contracts.go +++ b/core/services/ocr2/plugins/ccip/testhelpers/ccip_contracts.go @@ -1169,7 +1169,7 @@ func (c *CCIPContracts) SendRequest(t *testing.T, msg router.ClientEVM2AnyMessag return tx } -func (c *CCIPContracts) AssertExecState(t *testing.T, log logpoller.Log, state abihelpers.MessageExecutionState, offRampOpts ...common.Address) { +func (c *CCIPContracts) AssertExecState(t *testing.T, log logpoller.Log, state ccipdata.MessageExecutionState, offRampOpts ...common.Address) { var offRamp *evm_2_evm_offramp.EVM2EVMOffRamp var err error if len(offRampOpts) > 0 { @@ -1181,7 +1181,7 @@ func (c *CCIPContracts) AssertExecState(t *testing.T, log logpoller.Log, state a } executionStateChanged, err := offRamp.ParseExecutionStateChanged(log.ToGethLog()) require.NoError(t, err) - if abihelpers.MessageExecutionState(executionStateChanged.State) != state { + if ccipdata.MessageExecutionState(executionStateChanged.State) != state { t.Log("Execution failed") t.Fail() } diff --git a/core/services/ocr2/plugins/ccip/testhelpers/config.go b/core/services/ocr2/plugins/ccip/testhelpers/config.go index 8e10d17bad..baa4d8e5aa 100644 --- a/core/services/ocr2/plugins/ccip/testhelpers/config.go +++ b/core/services/ocr2/plugins/ccip/testhelpers/config.go @@ -10,13 +10,14 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/abihelpers" ccipconfig "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/config" + "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipdata" "github.com/smartcontractkit/chainlink/v2/core/store/models" ) var PermissionLessExecutionThresholdSeconds = uint32(FirstBlockAge.Seconds()) func (c *CCIPContracts) CreateDefaultCommitOnchainConfig(t *testing.T) []byte { - config, err := abihelpers.EncodeAbiStruct(ccipconfig.CommitOnchainConfig{ + config, err := abihelpers.EncodeAbiStruct(ccipdata.CommitOnchainConfig{ PriceRegistry: c.Dest.PriceRegistry.Address(), }) require.NoError(t, err) @@ -28,7 +29,7 @@ func (c *CCIPContracts) CreateDefaultCommitOffchainConfig(t *testing.T) []byte { } func (c *CCIPContracts) createCommitOffchainConfig(t *testing.T, feeUpdateHearBeat time.Duration, inflightCacheExpiry time.Duration) []byte { - config, err := ccipconfig.EncodeOffchainConfig(ccipconfig.CommitOffchainConfig{ + config, err := ccipconfig.EncodeOffchainConfig(ccipdata.CommitOffchainConfigV1_2_0{ SourceFinalityDepth: 1, DestFinalityDepth: 1, GasPriceHeartBeat: models.MustMakeDuration(feeUpdateHearBeat), @@ -44,7 +45,7 @@ func (c *CCIPContracts) createCommitOffchainConfig(t *testing.T, feeUpdateHearBe } func (c *CCIPContracts) CreateDefaultExecOnchainConfig(t *testing.T) []byte { - config, err := abihelpers.EncodeAbiStruct(ccipconfig.ExecOnchainConfig{ + config, err := abihelpers.EncodeAbiStruct(ccipdata.ExecOnchainConfigV1_0_0{ PermissionLessExecutionThresholdSeconds: PermissionLessExecutionThresholdSeconds, Router: c.Dest.Router.Address(), PriceRegistry: c.Dest.PriceRegistry.Address(), @@ -60,7 +61,7 @@ func (c *CCIPContracts) CreateDefaultExecOffchainConfig(t *testing.T) []byte { } func (c *CCIPContracts) createExecOffchainConfig(t *testing.T, inflightCacheExpiry time.Duration, rootSnoozeTime time.Duration) []byte { - config, err := ccipconfig.EncodeOffchainConfig(ccipconfig.ExecOffchainConfig{ + config, err := ccipconfig.EncodeOffchainConfig(ccipdata.ExecOffchainConfig{ SourceFinalityDepth: 1, DestOptimisticConfirmations: 1, DestFinalityDepth: 1,