Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
connorwstein committed Sep 25, 2023
1 parent 53bd56b commit 140db0d
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 81 deletions.
23 changes: 11 additions & 12 deletions core/services/ocr2/plugins/ccip/commit_reporting_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 18 additions & 23 deletions core/services/ocr2/plugins/ccip/commit_reporting_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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

Expand All @@ -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{
Expand All @@ -97,15 +96,14 @@ 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)
commitStore.SetPaused(tc.commitStoreIsPaused)

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)
}

Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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,
},
Expand All @@ -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 {
Expand All @@ -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{}
Expand Down Expand Up @@ -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)
Expand Down
76 changes: 32 additions & 44 deletions core/services/ocr2/plugins/ccip/execution_reporting_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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},
},
},
},
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand All @@ -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},
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 140db0d

Please sign in to comment.