From 140db0d53894c67449b27a1641e7e900fbf16103 Mon Sep 17 00:00:00 2001 From: connorwstein Date: Mon, 25 Sep 2023 19:52:10 -0400 Subject: [PATCH] More tests --- .../plugins/ccip/commit_reporting_plugin.go | 23 +++--- .../ccip/commit_reporting_plugin_test.go | 41 +++++----- .../ccip/execution_reporting_plugin_test.go | 76 ++++++++----------- .../ccip/internal/ccipdata/onramp_v1_2_0.go | 6 +- 4 files changed, 65 insertions(+), 81 deletions(-) diff --git a/core/services/ocr2/plugins/ccip/commit_reporting_plugin.go b/core/services/ocr2/plugins/ccip/commit_reporting_plugin.go index 168aec08b1..3ecb4470dc 100644 --- a/core/services/ocr2/plugins/ccip/commit_reporting_plugin.go +++ b/core/services/ocr2/plugins/ccip/commit_reporting_plugin.go @@ -671,23 +671,22 @@ func (r *CommitReportingPlugin) buildReport(ctx context.Context, lggr logger.Log if err != nil { return commit_store.CommitStoreCommitReport{}, err } + if len(sendRequests) == 0 { + lggr.Warn("No messages found in interval", + "minSeqNr", interval.Min, + "maxSeqNr", interval.Max) + return commit_store.CommitStoreCommitReport{}, fmt.Errorf("tried building a tree without leaves") + } leaves := make([][32]byte, 0, len(sendRequests)) + var seqNrs []uint64 for _, req := range sendRequests { leaves = append(leaves, req.Data.Hash) + seqNrs = append(seqNrs, req.Data.SequenceNumber) + } + if !ccipcalc.ContiguousReqs(lggr, interval.Min, interval.Max, seqNrs) { + return commit_store.CommitStoreCommitReport{}, errors.Errorf("do not have full range [%v, %v] have %v", interval.Min, interval.Max, seqNrs) } - //leaves, err := hashlib.LeavesFromIntervals(lggr, interval, r.config.leafHasher, sendRequests) - //if err != nil { - // return commit_store.CommitStoreCommitReport{}, err - //} - // - //if len(leaves) == 0 { - // lggr.Warn("No leaves found in interval", - // "minSeqNr", interval.Min, - // "maxSeqNr", interval.Max) - // return commit_store.CommitStoreCommitReport{}, fmt.Errorf("tried building a tree without leaves") - //} - tree, err := merklemulti.NewTree(hashlib.NewKeccakCtx(), leaves) if err != nil { return commit_store.CommitStoreCommitReport{}, err 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 85fdb85114..9c13ffe98a 100644 --- a/core/services/ocr2/plugins/ccip/commit_reporting_plugin_test.go +++ b/core/services/ocr2/plugins/ccip/commit_reporting_plugin_test.go @@ -27,7 +27,6 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/chains/evm/gas" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/gas/mocks" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/commit_store" - "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/evm_2_evm_onramp" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/price_registry" "github.com/smartcontractkit/chainlink/v2/core/internal/testutils" "github.com/smartcontractkit/chainlink/v2/core/logger" @@ -54,7 +53,7 @@ func TestCommitReportingPlugin_Observation(t *testing.T) { commitStoreIsPaused bool commitStoreSeqNum uint64 tokenPrices map[common.Address]*big.Int - sendReqs []ccipdata.Event[evm_2_evm_onramp.EVM2EVMOnRampCCIPSendRequested] + sendReqs []ccipdata.Event[ccipdata.EVM2EVMMessage] tokenDecimals map[common.Address]uint8 fee *big.Int @@ -68,9 +67,9 @@ func TestCommitReportingPlugin_Observation(t *testing.T) { someTokenAddr: big.NewInt(2), sourceNativeTokenAddr: big.NewInt(2), }, - sendReqs: []ccipdata.Event[evm_2_evm_onramp.EVM2EVMOnRampCCIPSendRequested]{ - {Data: evm_2_evm_onramp.EVM2EVMOnRampCCIPSendRequested{Message: evm_2_evm_onramp.InternalEVM2EVMMessage{SequenceNumber: 54}}}, - {Data: evm_2_evm_onramp.EVM2EVMOnRampCCIPSendRequested{Message: evm_2_evm_onramp.InternalEVM2EVMMessage{SequenceNumber: 55}}}, + sendReqs: []ccipdata.Event[ccipdata.EVM2EVMMessage]{ + {Data: ccipdata.EVM2EVMMessage{SequenceNumber: 54}}, + {Data: ccipdata.EVM2EVMMessage{SequenceNumber: 55}}, }, fee: big.NewInt(100), tokenDecimals: map[common.Address]uint8{ @@ -97,7 +96,6 @@ func TestCommitReportingPlugin_Observation(t *testing.T) { ctx := testutils.Context(t) for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - onRampAddress := utils.RandomAddress() sourceFinalityDepth := 10 commitStore, _ := testhelpers.NewFakeCommitStore(t, tc.commitStoreSeqNum) @@ -105,7 +103,7 @@ func TestCommitReportingPlugin_Observation(t *testing.T) { sourceReader := ccipdata.NewMockOnRampReader(t) if len(tc.sendReqs) > 0 { - sourceReader.On("GetSendRequestsGteSeqNum", ctx, onRampAddress, tc.commitStoreSeqNum, false, sourceFinalityDepth). + sourceReader.On("GetSendRequestsGteSeqNum", ctx, tc.commitStoreSeqNum, sourceFinalityDepth). Return(tc.sendReqs, nil) } @@ -163,7 +161,7 @@ func TestCommitReportingPlugin_Report(t *testing.T) { f int gasPriceUpdates []ccipdata.Event[price_registry.PriceRegistryUsdPerUnitGasUpdated] tokenPriceUpdates []ccipdata.Event[price_registry.PriceRegistryUsdPerTokenUpdated] - sendRequests []ccipdata.Event[evm_2_evm_onramp.EVM2EVMOnRampCCIPSendRequested] + sendRequests []ccipdata.Event[ccipdata.EVM2EVMMessage] expCommitReport *commit_store.CommitStoreCommitReport expSeqNumRange commit_store.CommitStoreInterval @@ -176,18 +174,16 @@ func TestCommitReportingPlugin_Report(t *testing.T) { {Interval: commit_store.CommitStoreInterval{Min: 1, Max: 1}}, }, f: 1, - sendRequests: []ccipdata.Event[evm_2_evm_onramp.EVM2EVMOnRampCCIPSendRequested]{ + sendRequests: []ccipdata.Event[ccipdata.EVM2EVMMessage]{ { - Data: evm_2_evm_onramp.EVM2EVMOnRampCCIPSendRequested{ - Message: evm_2_evm_onramp.InternalEVM2EVMMessage{ - SequenceNumber: 1, - }, + Data: ccipdata.EVM2EVMMessage{ + SequenceNumber: 1, }, }, }, expSeqNumRange: commit_store.CommitStoreInterval{Min: 1, Max: 1}, expCommitReport: &commit_store.CommitStoreCommitReport{ - MerkleRoot: [32]byte{123}, + MerkleRoot: [32]byte{}, Interval: commit_store.CommitStoreInterval{Min: 1, Max: 1}, PriceUpdates: commit_store.InternalPriceUpdates{ TokenPriceUpdates: nil, @@ -203,7 +199,7 @@ func TestCommitReportingPlugin_Report(t *testing.T) { {Interval: commit_store.CommitStoreInterval{Min: 1, Max: 1}}, }, f: 1, - sendRequests: []ccipdata.Event[evm_2_evm_onramp.EVM2EVMOnRampCCIPSendRequested]{{}}, + sendRequests: []ccipdata.Event[ccipdata.EVM2EVMMessage]{{}}, expSeqNumRange: commit_store.CommitStoreInterval{Min: 1, Max: 1}, expErr: true, }, @@ -223,14 +219,13 @@ func TestCommitReportingPlugin_Report(t *testing.T) { {Interval: commit_store.CommitStoreInterval{Min: 2, Max: 2}}, }, f: 1, - sendRequests: []ccipdata.Event[evm_2_evm_onramp.EVM2EVMOnRampCCIPSendRequested]{{}}, + sendRequests: []ccipdata.Event[ccipdata.EVM2EVMMessage]{{}}, expSeqNumRange: commit_store.CommitStoreInterval{Min: 2, Max: 2}, expErr: true, }, } ctx := testutils.Context(t) - onRampAddress := utils.RandomAddress() sourceChainSelector := rand.Int() for _, tc := range testCases { @@ -243,7 +238,7 @@ func TestCommitReportingPlugin_Report(t *testing.T) { sourceReader := ccipdata.NewMockOnRampReader(t) if len(tc.sendRequests) > 0 { - sourceReader.On("GetSendRequestsBetweenSeqNums", ctx, onRampAddress, tc.expSeqNumRange.Min, tc.expSeqNumRange.Max, 0).Return(tc.sendRequests, nil) + sourceReader.On("GetSendRequestsBetweenSeqNums", ctx, tc.expSeqNumRange.Min, tc.expSeqNumRange.Max, 0).Return(tc.sendRequests, nil) } p := &CommitReportingPlugin{} @@ -1032,15 +1027,15 @@ func TestCommitReportingPlugin_calculateMinMaxSequenceNumbers(t *testing.T) { } sourceReader := ccipdata.NewMockOnRampReader(t) - var sendReqs []ccipdata.Event[evm_2_evm_onramp.EVM2EVMOnRampCCIPSendRequested] + var sendReqs []ccipdata.Event[ccipdata.EVM2EVMMessage] for _, seqNum := range tc.msgSeqNums { - sendReqs = append(sendReqs, ccipdata.Event[evm_2_evm_onramp.EVM2EVMOnRampCCIPSendRequested]{ - Data: evm_2_evm_onramp.EVM2EVMOnRampCCIPSendRequested{ - Message: evm_2_evm_onramp.InternalEVM2EVMMessage{SequenceNumber: seqNum}, + sendReqs = append(sendReqs, ccipdata.Event[ccipdata.EVM2EVMMessage]{ + Data: ccipdata.EVM2EVMMessage{ + SequenceNumber: seqNum, }, }) } - sourceReader.On("GetSendRequestsGteSeqNum", ctx, mock.Anything, tc.expQueryMin, false, 0).Return(sendReqs, nil) + sourceReader.On("GetSendRequestsGteSeqNum", ctx, tc.expQueryMin, 0).Return(sendReqs, nil) p.config.onRampReader = sourceReader minSeqNum, maxSeqNum, err := p.calculateMinMaxSequenceNumbers(ctx, lggr) diff --git a/core/services/ocr2/plugins/ccip/execution_reporting_plugin_test.go b/core/services/ocr2/plugins/ccip/execution_reporting_plugin_test.go index b5c32ef475..137d8a151b 100644 --- a/core/services/ocr2/plugins/ccip/execution_reporting_plugin_test.go +++ b/core/services/ocr2/plugins/ccip/execution_reporting_plugin_test.go @@ -55,7 +55,7 @@ func TestExecutionReportingPlugin_Observation(t *testing.T) { commitStorePaused bool inflightReports []InflightInternalExecutionReport unexpiredReports []ccipdata.Event[commit_store.CommitStoreReportAccepted] - sendRequests []ccipdata.Event[evm_2_evm_onramp.EVM2EVMOnRampCCIPSendRequested] + sendRequests []ccipdata.Event[ccipdata.EVM2EVMMessage] executedSeqNums []uint64 blessedRoots map[[32]byte]bool senderNonce uint64 @@ -89,21 +89,15 @@ func TestExecutionReportingPlugin_Observation(t *testing.T) { IsEnabled: false, }, senderNonce: 9, - sendRequests: []ccipdata.Event[evm_2_evm_onramp.EVM2EVMOnRampCCIPSendRequested]{ + sendRequests: []ccipdata.Event[ccipdata.EVM2EVMMessage]{ { - Data: evm_2_evm_onramp.EVM2EVMOnRampCCIPSendRequested{ - Message: evm_2_evm_onramp.InternalEVM2EVMMessage{SequenceNumber: 10}, - }, + Data: ccipdata.EVM2EVMMessage{SequenceNumber: 10}, }, { - Data: evm_2_evm_onramp.EVM2EVMOnRampCCIPSendRequested{ - Message: evm_2_evm_onramp.InternalEVM2EVMMessage{SequenceNumber: 11}, - }, + Data: ccipdata.EVM2EVMMessage{SequenceNumber: 11}, }, { - Data: evm_2_evm_onramp.EVM2EVMOnRampCCIPSendRequested{ - Message: evm_2_evm_onramp.InternalEVM2EVMMessage{SequenceNumber: 12}, - }, + Data: ccipdata.EVM2EVMMessage{SequenceNumber: 12}, }, }, }, @@ -140,11 +134,11 @@ func TestExecutionReportingPlugin_Observation(t *testing.T) { Return(executionEvents, nil).Maybe() p.config.destReader = destReader - onRamp, onRampAddr := testhelpers.NewFakeOnRamp(t) + onRamp, _ := testhelpers.NewFakeOnRamp(t) p.config.onRamp = onRamp sourceReader := ccipdata.NewMockOnRampReader(t) - sourceReader.On("GetSendRequestsBetweenSeqNums", ctx, onRampAddr, mock.Anything, mock.Anything, 0). + sourceReader.On("GetSendRequestsBetweenSeqNums", ctx, mock.Anything, mock.Anything, 0). Return(tc.sendRequests, nil).Maybe() p.config.onRampReader = sourceReader @@ -373,31 +367,31 @@ func TestExecutionReportingPlugin_buildReport(t *testing.T) { }, nil) p.config.destReader = destReader - onRamp, onRampAddr := testhelpers.NewFakeOnRamp(t) + onRamp, _ := testhelpers.NewFakeOnRamp(t) p.config.onRamp = onRamp - sendReqs := make([]ccipdata.Event[evm_2_evm_onramp.EVM2EVMOnRampCCIPSendRequested], len(observations)) + sendReqs := make([]ccipdata.Event[ccipdata.EVM2EVMMessage], len(observations)) for i := range observations { - sendReqs[i] = ccipdata.Event[evm_2_evm_onramp.EVM2EVMOnRampCCIPSendRequested]{ - Data: evm_2_evm_onramp.EVM2EVMOnRampCCIPSendRequested{Message: evm_2_evm_onramp.InternalEVM2EVMMessage{ - SourceChainSelector: math.MaxUint64, - SequenceNumber: uint64(i + 1), - FeeTokenAmount: big.NewInt(math.MaxInt64), - Sender: utils.RandomAddress(), - Nonce: math.MaxUint64, - GasLimit: big.NewInt(math.MaxInt64), - Strict: false, - Receiver: utils.RandomAddress(), - Data: bytes.Repeat([]byte{0}, bytesPerMessage), - TokenAmounts: nil, - FeeToken: utils.RandomAddress(), - MessageId: [32]byte{12}, - }}, + sendReqs[i] = ccipdata.Event[ccipdata.EVM2EVMMessage]{ + Data: ccipdata.EVM2EVMMessage{ + //SourceChainSelector: math.MaxUint64, + SequenceNumber: uint64(i + 1), + //FeeTokenAmount: big.NewInt(math.MaxInt64), + //Sender: utils.RandomAddress(), + Nonce: math.MaxUint64, + GasLimit: big.NewInt(math.MaxInt64), + //Strict: false, + //Receiver: utils.RandomAddress(), + //Data: bytes.Repeat([]byte{0}, bytesPerMessage), + //TokenAmounts: nil, + //FeeToken: utils.RandomAddress(), + MessageId: [32]byte{12}, + }, } } sourceReader := ccipdata.NewMockOnRampReader(t) sourceReader.On("GetSendRequestsBetweenSeqNums", - ctx, onRampAddr, observations[0].SeqNr, observations[len(observations)-1].SeqNr, 0).Return(sendReqs, nil) + ctx, observations[0].SeqNr, observations[len(observations)-1].SeqNr, 0).Return(sendReqs, nil) p.config.onRampReader = sourceReader execReport, err := p.buildReport(ctx, p.lggr, observations) @@ -930,7 +924,7 @@ func TestExecutionReportingPlugin_getReportsWithSendRequests(t *testing.T) { reports []commit_store.CommitStoreCommitReport expQueryMin uint64 // expected min/max used in the query to get ccipevents expQueryMax uint64 - onchainEvents []ccipdata.Event[evm_2_evm_onramp.EVM2EVMOnRampCCIPSendRequested] + onchainEvents []ccipdata.Event[ccipdata.EVM2EVMMessage] destLatestBlock int64 destExecutedSeqNums []uint64 @@ -957,16 +951,10 @@ func TestExecutionReportingPlugin_getReportsWithSendRequests(t *testing.T) { }, expQueryMin: 1, expQueryMax: 3, - onchainEvents: []ccipdata.Event[evm_2_evm_onramp.EVM2EVMOnRampCCIPSendRequested]{ - {Data: evm_2_evm_onramp.EVM2EVMOnRampCCIPSendRequested{ - Message: evm_2_evm_onramp.InternalEVM2EVMMessage{SequenceNumber: 1}, - }}, - {Data: evm_2_evm_onramp.EVM2EVMOnRampCCIPSendRequested{ - Message: evm_2_evm_onramp.InternalEVM2EVMMessage{SequenceNumber: 2}, - }}, - {Data: evm_2_evm_onramp.EVM2EVMOnRampCCIPSendRequested{ - Message: evm_2_evm_onramp.InternalEVM2EVMMessage{SequenceNumber: 3}, - }}, + onchainEvents: []ccipdata.Event[ccipdata.EVM2EVMMessage]{ + {Data: ccipdata.EVM2EVMMessage{SequenceNumber: 1}}, + {Data: ccipdata.EVM2EVMMessage{SequenceNumber: 2}}, + {Data: ccipdata.EVM2EVMMessage{SequenceNumber: 3}}, }, destLatestBlock: 10_000, destExecutedSeqNums: []uint64{1}, @@ -1014,14 +1002,14 @@ func TestExecutionReportingPlugin_getReportsWithSendRequests(t *testing.T) { p := &ExecutionReportingPlugin{} p.lggr = lggr - onRamp, onRampAddr := testhelpers.NewFakeOnRamp(t) + onRamp, _ := testhelpers.NewFakeOnRamp(t) p.config.onRamp = onRamp offRamp, offRampAddr := testhelpers.NewFakeOffRamp(t) p.config.offRamp = offRamp sourceReader := ccipdata.NewMockOnRampReader(t) - sourceReader.On("GetSendRequestsBetweenSeqNums", ctx, onRampAddr, tc.expQueryMin, tc.expQueryMax, 0). + sourceReader.On("GetSendRequestsBetweenSeqNums", ctx, tc.expQueryMin, tc.expQueryMax, 0). Return(tc.onchainEvents, nil).Maybe() p.config.onRampReader = sourceReader diff --git a/core/services/ocr2/plugins/ccip/internal/ccipdata/onramp_v1_2_0.go b/core/services/ocr2/plugins/ccip/internal/ccipdata/onramp_v1_2_0.go index e978a54caf..a84962dc4a 100644 --- a/core/services/ocr2/plugins/ccip/internal/ccipdata/onramp_v1_2_0.go +++ b/core/services/ocr2/plugins/ccip/internal/ccipdata/onramp_v1_2_0.go @@ -324,11 +324,13 @@ func NewOnRampV1_2_0( // Subscribe to the relevant logs // Note we can keep the same prefix across 1.0/1.1 and 1.2 because the onramp addresses will be different name := logpoller.FilterName(COMMIT_CCIP_SENDS, onRampAddress) - err = sourceLP.RegisterFilter(logpoller.Filter{ + if err = sourceLP.RegisterFilter(logpoller.Filter{ Name: name, EventSigs: []common.Hash{CCIPSendRequestEventSigV1_2_0}, Addresses: []common.Address{onRampAddress}, - }) + }); err != nil { + return nil, err + } return &OnRampV1_2_0{ finalityTags: finalityTags, lggr: lggr,