Skip to content

Commit

Permalink
Minor refactoring in tests and linter fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusz-sekara committed Jul 5, 2024
1 parent ef927a6 commit f3d98eb
Show file tree
Hide file tree
Showing 23 changed files with 569 additions and 396 deletions.
2 changes: 1 addition & 1 deletion core/scripts/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ require (
github.com/shopspring/decimal v1.3.1
github.com/smartcontractkit/chain-selectors v1.0.17
github.com/smartcontractkit/chainlink-automation v1.0.4
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240625144005-556a7ba7b11c
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240703135949-d9562d7964d5
github.com/smartcontractkit/chainlink-vrf v0.0.0-20240222010609-cd67d123c772
github.com/smartcontractkit/chainlink/v2 v2.0.0-00010101000000-000000000000
github.com/smartcontractkit/libocr v0.0.0-20240419185742-fd3cab206b2c
Expand Down
4 changes: 2 additions & 2 deletions core/scripts/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1121,8 +1121,8 @@ github.com/smartcontractkit/chain-selectors v1.0.17 h1:otOlYUnutS8oQBEAi9RLQICqZ
github.com/smartcontractkit/chain-selectors v1.0.17/go.mod h1:d4Hi+E1zqjy9HqMkjBE5q1vcG9VGgxf5VxiRHfzi2kE=
github.com/smartcontractkit/chainlink-automation v1.0.4 h1:iyW181JjKHLNMnDleI8umfIfVVlwC7+n5izbLSFgjw8=
github.com/smartcontractkit/chainlink-automation v1.0.4/go.mod h1:u4NbPZKJ5XiayfKHD/v3z3iflQWqvtdhj13jVZXj/cM=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240625144005-556a7ba7b11c h1:dR2y3uzuZ8cJOaMSij8LQIdySuImwxkiZFjZ62ML5S0=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240625144005-556a7ba7b11c/go.mod h1:L32xvCpk84Nglit64OhySPMP1tM3TTBK7Tw0qZl7Sd4=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240703135949-d9562d7964d5 h1:uPU5HyhYF03wHuQPC7K1wQDzy35UE0uYuo5GG2WIR8w=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240703135949-d9562d7964d5/go.mod h1:L32xvCpk84Nglit64OhySPMP1tM3TTBK7Tw0qZl7Sd4=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240621143432-85370a54b141 h1:TMOoYaeSDkkI3jkCH7lKHOZaLkeDuxFTNC+XblD6M0M=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240621143432-85370a54b141/go.mod h1:0UNuO3nDt9MFsZPaHJBEUolxVkN0iC69j1ccDp95e8k=
github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240220203239-09be0ea34540 h1:xFSv8561jsLtF6gYZr/zW2z5qUUAkcFkApin2mnbYTo=
Expand Down
6 changes: 3 additions & 3 deletions core/services/ocr2/plugins/ccip/ccipcommit/ocr2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func TestCommitReportingPlugin_Observation(t *testing.T) {
onRampReader.On("IsSourceChainHealthy", ctx).Return(true, nil)
onRampReader.On("IsSourceCursed", ctx).Return(tc.sourceChainCursed, nil)
if len(tc.sendReqs) > 0 {
onRampReader.On("GetSendRequestsBetweenSeqNums", ctx, tc.commitStoreSeqNum, tc.commitStoreSeqNum+OnRampMessagesScanLimit, true).
onRampReader.On("GetSendRequestsForSeqNums", ctx, []cciptypes.SequenceNumberRange{{Min: tc.commitStoreSeqNum, Max: tc.commitStoreSeqNum + OnRampMessagesScanLimit}}, true).
Return(tc.sendReqs, nil)
}

Expand Down Expand Up @@ -405,7 +405,7 @@ func TestCommitReportingPlugin_Report(t *testing.T) {

onRampReader := ccipdatamocks.NewOnRampReader(t)
if len(tc.sendRequests) > 0 {
onRampReader.On("GetSendRequestsBetweenSeqNums", ctx, tc.expSeqNumRange.Min, tc.expSeqNumRange.Max, true).Return(tc.sendRequests, nil)
onRampReader.On("GetSendRequestsForSeqNums", ctx, []cciptypes.SequenceNumberRange{{Min: tc.expSeqNumRange.Min, Max: tc.expSeqNumRange.Max}}, true).Return(tc.sendRequests, nil)
}

evmEstimator := mocks.NewEvmFeeEstimator(t)
Expand Down Expand Up @@ -1569,7 +1569,7 @@ func TestCommitReportingPlugin_calculateMinMaxSequenceNumbers(t *testing.T) {
},
})
}
onRampReader.On("GetSendRequestsBetweenSeqNums", ctx, tc.expQueryMin, tc.expQueryMin+OnRampMessagesScanLimit, true).Return(sendReqs, nil)
onRampReader.On("GetSendRequestsForSeqNums", ctx, []cciptypes.SequenceNumberRange{{Min: tc.expQueryMin, Max: tc.expQueryMin + OnRampMessagesScanLimit}}, true).Return(sendReqs, nil)
p.onRampReader = onRampReader

minSeqNum, maxSeqNum, _, err := p.calculateMinMaxSequenceNumbers(ctx, lggr)
Expand Down
22 changes: 12 additions & 10 deletions core/services/ocr2/plugins/ccip/ccipexec/ocr2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func TestExecutionReportingPlugin_Observation(t *testing.T) {
p.tokenPoolBatchedReader = tokenPoolBatchedReader

mockOffRampReader := ccipdatamocks.NewOffRampReader(t)
mockOffRampReader.On("GetExecutionStateChangesBetweenSeqNums", ctx, mock.Anything, mock.Anything, 0).
mockOffRampReader.On("GetExecutionStateChangesForSeqNums", ctx, mock.Anything, 0).
Return(executionEvents, nil).Maybe()
mockOffRampReader.On("CurrentRateLimiterState", mock.Anything).Return(tc.rateLimiterState, nil).Maybe()
mockOffRampReader.On("Address", ctx).Return(cciptypes.Address(offRamp.Address().String()), nil).Maybe()
Expand All @@ -189,7 +189,7 @@ func TestExecutionReportingPlugin_Observation(t *testing.T) {
mockOnRampReader := ccipdatamocks.NewOnRampReader(t)
mockOnRampReader.On("IsSourceCursed", ctx).Return(tc.sourceChainCursed, nil).Maybe()
mockOnRampReader.On("IsSourceChainHealthy", ctx).Return(tc.sourceChainHealthy, nil).Maybe()
mockOnRampReader.On("GetSendRequestsBetweenSeqNums", ctx, mock.Anything, mock.Anything, false).
mockOnRampReader.On("GetSendRequestsForSeqNums", ctx, mock.Anything, false).
Return(tc.sendRequests, nil).Maybe()
sourcePriceRegistryAddress := cciptypes.Address(utils.RandomAddress().String())
mockOnRampReader.On("SourcePriceRegistryAddress", ctx).Return(sourcePriceRegistryAddress, nil).Maybe()
Expand Down Expand Up @@ -449,8 +449,12 @@ func TestExecutionReportingPlugin_buildReport(t *testing.T) {
}
sendReqs[i] = cciptypes.EVM2EVMMessageWithTxMeta{EVM2EVMMessage: msg}
}
sourceReader.On("GetSendRequestsBetweenSeqNums",
ctx, observations[0].SeqNr, observations[len(observations)-1].SeqNr, false).Return(sendReqs, nil)
sourceReader.On(
"GetSendRequestsForSeqNums",
ctx,
[]cciptypes.SequenceNumberRange{{Min: observations[0].SeqNr, Max: observations[len(observations)-1].SeqNr}},
false,
).Return(sendReqs, nil)
p.onRampReader = sourceReader

execReport, err := p.buildReport(ctx, p.lggr, observations)
Expand Down Expand Up @@ -857,8 +861,7 @@ func TestExecutionReportingPlugin_getReportsWithSendRequests(t *testing.T) {
testCases := []struct {
name string
reports []cciptypes.CommitStoreReport
expQueryMin uint64 // expected min/max used in the query to get ccipevents
expQueryMax uint64
expSeqNumbers []cciptypes.SequenceNumberRange
onchainEvents []cciptypes.EVM2EVMMessageWithTxMeta
destExecutedSeqNums []uint64

Expand All @@ -883,8 +886,7 @@ func TestExecutionReportingPlugin_getReportsWithSendRequests(t *testing.T) {
MerkleRoot: [32]byte{200},
},
},
expQueryMin: 1,
expQueryMax: 3,
expSeqNumbers: []cciptypes.SequenceNumberRange{{Min: 1, Max: 2}, {Min: 3, Max: 3}},
onchainEvents: []cciptypes.EVM2EVMMessageWithTxMeta{
{EVM2EVMMessage: cciptypes.EVM2EVMMessage{SequenceNumber: 1}},
{EVM2EVMMessage: cciptypes.EVM2EVMMessage{SequenceNumber: 2}},
Expand Down Expand Up @@ -939,7 +941,7 @@ func TestExecutionReportingPlugin_getReportsWithSendRequests(t *testing.T) {
p.offRampReader = offRampReader

sourceReader := ccipdatamocks.NewOnRampReader(t)
sourceReader.On("GetSendRequestsBetweenSeqNums", ctx, tc.expQueryMin, tc.expQueryMax, false).
sourceReader.On("GetSendRequestsForSeqNums", ctx, tc.expSeqNumbers, false).
Return(tc.onchainEvents, nil).Maybe()
p.onRampReader = sourceReader

Expand All @@ -959,7 +961,7 @@ func TestExecutionReportingPlugin_getReportsWithSendRequests(t *testing.T) {
},
})
}
offRampReader.On("GetExecutionStateChangesBetweenSeqNums", ctx, tc.expQueryMin, tc.expQueryMax, 0).Return(executedEvents, nil).Maybe()
offRampReader.On("GetExecutionStateChangesForSeqNums", ctx, tc.expSeqNumbers, 0).Return(executedEvents, nil).Maybe()

populatedReports, err := p.getReportsWithSendRequests(ctx, tc.reports)
if tc.expErr {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ func testOnRampReader(t *testing.T, th onRampReaderTH, expectedRouterAddress com
require.NoError(t, err)
require.Equal(t, ccipcalc.EvmAddrToGeneric(expectedRouterAddress), res)

msg, err := th.reader.GetSendRequestsBetweenSeqNums(ctx, 0, 10, true)
msg, err := th.reader.GetSendRequestsForSeqNums(ctx, []cciptypes.SequenceNumberRange{{Min: 0, Max: 10}}, true)
require.NoError(t, err)
require.NotNil(t, msg)
require.Equal(t, []cciptypes.EVM2EVMMessageWithTxMeta{}, msg)
Expand Down
3 changes: 1 addition & 2 deletions core/services/ocr2/plugins/ccip/internal/ccipdata/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"time"

"github.com/ethereum/go-ethereum/core/types"
"github.com/smartcontractkit/chainlink-common/pkg/types/query/primitives"

cciptypes "github.com/smartcontractkit/chainlink-common/pkg/types/ccip"
"github.com/smartcontractkit/chainlink-common/pkg/types/query/primitives"

"github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller"
evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
Expand Down Expand Up @@ -51,7 +51,6 @@ func LogsConfidence(finalized bool) primitives.ConfidenceLevel {
return primitives.Finalized
}
return primitives.Unconfirmed

}

func LogsConfirmations(finalized bool) evmtypes.Confirmations {
Expand Down
Loading

0 comments on commit f3d98eb

Please sign in to comment.