Skip to content

Commit

Permalink
Compiling
Browse files Browse the repository at this point in the history
  • Loading branch information
connorwstein committed Sep 25, 2023
1 parent 1e9beaa commit bf720db
Show file tree
Hide file tree
Showing 22 changed files with 481 additions and 380 deletions.
7 changes: 1 addition & 6 deletions core/services/ocr2/plugins/ccip/abihelpers/abi_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ const (
ExecutionStateFailure
)

// TODO: Deprecate in favour of version specific types
var EventSignatures struct {
// OnRamp
//SendRequested common.Hash
// CommitStore
ReportAccepted common.Hash
// OffRamp
Expand All @@ -45,10 +44,6 @@ var EventSignatures struct {
FeeTokenAdded common.Hash
FeeTokenRemoved common.Hash

USDCMessageSent common.Hash

// offset || sourceChainID || seqNum || ...
SendRequestedSequenceNumberWord int
// offset || priceUpdatesOffset || minSeqNum || maxSeqNum || merkleRoot
ReportAcceptedMaxSequenceNumberWord int
// sig || seqNum || messageId || ...
Expand Down
13 changes: 8 additions & 5 deletions core/services/ocr2/plugins/ccip/commit_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@ 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"
)

func TestGetCommitPluginFilterNamesFromSpec(t *testing.T) {
lggr := logger.TestLogger(t)
testCases := []struct {
description string
spec *job.OCR2OracleSpec
Expand Down Expand Up @@ -63,6 +63,7 @@ func TestGetCommitPluginFilterNamesFromSpec(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.description, func(t *testing.T) {
chainSet := &evmmocks.LegacyChainContainer{}
prMock := &pipelinemocks.Runner{}

if tc.spec != nil {
if chainID, ok := tc.spec.RelayConfig["chainID"]; ok {
Expand All @@ -72,7 +73,7 @@ func TestGetCommitPluginFilterNamesFromSpec(t *testing.T) {
}
}

err := UnregisterCommitPluginLpFilters(context.Background(), tc.spec, chainSet)
err := UnregisterCommitPluginLpFilters(context.Background(), lggr, job.Job{OCR2OracleSpec: tc.spec}, prMock, chainSet)
if tc.expectingErr {
assert.Error(t, err)
} else {
Expand Down Expand Up @@ -104,13 +105,14 @@ func TestGetCommitPluginFilterNames(t *testing.T) {
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(), srcLP, dstLP, mockCommitStore, offRampAddr)
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{}
Expand Down Expand Up @@ -165,3 +167,4 @@ func Test_updateCommitPluginLogPollerFilters(t *testing.T) {
srcLP.AssertExpectations(t)
dstLP.AssertExpectations(t)
}
*/
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func TestCommitReportingPlugin_Observation(t *testing.T) {
commitStore, _ := testhelpers.NewFakeCommitStore(t, tc.commitStoreSeqNum)
commitStore.SetPaused(tc.commitStoreIsPaused)

sourceReader := ccipdata.NewMockReader(t)
sourceReader := ccipdata.NewMockOnRampReader(t)
if len(tc.sendReqs) > 0 {
sourceReader.On("GetSendRequestsGteSeqNum", ctx, onRampAddress, tc.commitStoreSeqNum, false, sourceFinalityDepth).
Return(tc.sendReqs, nil)
Expand Down Expand Up @@ -133,7 +133,6 @@ func TestCommitReportingPlugin_Observation(t *testing.T) {
p.lggr = logger.TestLogger(t)
p.inflightReports = newInflightCommitReportsContainer(time.Hour)
p.config.commitStore = commitStore
p.config.onRampAddress = onRampAddress
p.offchainConfig.SourceFinalityDepth = uint32(sourceFinalityDepth)
p.config.onRampReader = sourceReader
p.tokenDecimalsCache = tokenDecimalsCache
Expand Down Expand Up @@ -242,7 +241,7 @@ func TestCommitReportingPlugin_Report(t *testing.T) {
destReader.On("GetGasPriceUpdatesCreatedAfter", ctx, destPriceRegistryAddress, uint64(sourceChainSelector), mock.Anything, 0).Return(tc.gasPriceUpdates, nil)
destReader.On("GetTokenPriceUpdatesCreatedAfter", ctx, destPriceRegistryAddress, mock.Anything, 0).Return(tc.tokenPriceUpdates, nil)

sourceReader := ccipdata.NewMockReader(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)
}
Expand All @@ -253,9 +252,7 @@ func TestCommitReportingPlugin_Report(t *testing.T) {
p.destPriceRegistry = destPriceRegistry
p.config.destReader = destReader
p.config.onRampReader = sourceReader
p.config.onRampAddress = onRampAddress
p.config.sourceChainSelector = uint64(sourceChainSelector)
p.config.leafHasher = &leafHasher123{}

aos := make([]types.AttributedObservation, 0, len(tc.observations))
for _, o := range tc.observations {
Expand Down Expand Up @@ -1034,7 +1031,7 @@ func TestCommitReportingPlugin_calculateMinMaxSequenceNumbers(t *testing.T) {
}
}

sourceReader := ccipdata.NewMockReader(t)
sourceReader := ccipdata.NewMockOnRampReader(t)
var sendReqs []ccipdata.Event[evm_2_evm_onramp.EVM2EVMOnRampCCIPSendRequested]
for _, seqNum := range tc.msgSeqNums {
sendReqs = append(sendReqs, ccipdata.Event[evm_2_evm_onramp.EVM2EVMOnRampCCIPSendRequested]{
Expand Down
29 changes: 10 additions & 19 deletions core/services/ocr2/plugins/ccip/execution_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ import (
"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/config"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/testhelpers"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/tokendata/usdc"
"github.com/smartcontractkit/chainlink/v2/core/utils"
)

func TestGetExecutionPluginFilterNamesFromSpec(t *testing.T) {
Expand Down Expand Up @@ -57,7 +54,7 @@ func TestGetExecutionPluginFilterNamesFromSpec(t *testing.T) {
for _, tc := range testCases {
chainSet := &mocks.LegacyChainContainer{}
t.Run(tc.description, func(t *testing.T) {
err := UnregisterExecPluginLpFilters(context.Background(), logger.TestLogger(t), tc.spec, chainSet)
err := UnregisterExecPluginLpFilters(context.Background(), logger.TestLogger(t), job.Job{OCR2OracleSpec: tc.spec}, chainSet)
if tc.expectingErr {
assert.Error(t, err)
} else {
Expand All @@ -78,20 +75,20 @@ func TestGetExecutionPluginFilterNames(t *testing.T) {
mockOnRamp, onRampAddr := testhelpers.NewFakeOnRamp(t)
mockOnRamp.SetDynamicCfg(evm_2_evm_onramp.EVM2EVMOnRampDynamicConfig{PriceRegistry: srcPriceRegAddr})

pluginConfig := config.ExecutionPluginJobSpecConfig{
USDCConfig: config.USDCConfig{
SourceTokenAddress: utils.RandomAddress(),
SourceMessageTransmitterAddress: utils.RandomAddress(),
AttestationAPI: "http://localhost:8080",
},
}
//pluginConfig := config.ExecutionPluginJobSpecConfig{
// USDCConfig: config.USDCConfig{
// SourceTokenAddress: utils.RandomAddress(),
// SourceMessageTransmitterAddress: utils.RandomAddress(),
// AttestationAPI: "http://localhost:8080",
// },
//}

srcLP := mocklp.NewLogPoller(t)
srcFilters := []string{
"Exec ccip sends - " + onRampAddr.String(),
"Fee token added - 0xdAFea492D9c6733aE3d56B7ed1ADb60692c98bC9",
"Fee token removed - 0xdAFea492D9c6733aE3d56B7ed1ADb60692c98bC9",
usdc.MESSAGE_SENT_FILTER_NAME + " - " + pluginConfig.USDCConfig.SourceMessageTransmitterAddress.Hex(),
//usdc.MESSAGE_SENT_FILTER_NAME + " - " + pluginConfig.USDCConfig.SourceMessageTransmitterAddress.Hex(),
}
for _, f := range srcFilters {
srcLP.On("UnregisterFilter", f, mock.Anything).Return(nil)
Expand All @@ -112,18 +109,12 @@ func TestGetExecutionPluginFilterNames(t *testing.T) {

err := unregisterExecutionPluginLpFilters(
context.Background(),
logger.TestLogger(t),
srcLP,
dstLP,
mockOffRamp,
evm_2_evm_offramp.EVM2EVMOffRampStaticConfig{
CommitStore: commitStoreAddr,
OnRamp: onRampAddr,
SourceChainSelector: 5009297550715157269,
},
commitStoreAddr,
mockOnRamp,
nil,
pluginConfig,
)
assert.NoError(t, err)

Expand Down
20 changes: 9 additions & 11 deletions core/services/ocr2/plugins/ccip/execution_reporting_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ func TestExecutionReportingPlugin_Observation(t *testing.T) {
onRamp, onRampAddr := testhelpers.NewFakeOnRamp(t)
p.config.onRamp = onRamp

sourceReader := ccipdata.NewMockReader(t)
sourceReader := ccipdata.NewMockOnRampReader(t)
sourceReader.On("GetSendRequestsBetweenSeqNums", ctx, onRampAddr, mock.Anything, mock.Anything, 0).
Return(tc.sendRequests, nil).Maybe()
p.config.sourceReader = sourceReader
p.config.onRampReader = sourceReader

cachedDestTokens := cache.NewMockAutoSync[cache.CachedTokens](t)
cachedDestTokens.On("Get", ctx).Return(cache.CachedTokens{
Expand Down Expand Up @@ -373,8 +373,6 @@ func TestExecutionReportingPlugin_buildReport(t *testing.T) {
}, nil)
p.config.destReader = destReader

p.config.leafHasher = leafHasher123{}

onRamp, onRampAddr := testhelpers.NewFakeOnRamp(t)
p.config.onRamp = onRamp

Expand All @@ -397,10 +395,10 @@ func TestExecutionReportingPlugin_buildReport(t *testing.T) {
}},
}
}
sourceReader := ccipdata.NewMockReader(t)
sourceReader := ccipdata.NewMockOnRampReader(t)
sourceReader.On("GetSendRequestsBetweenSeqNums",
ctx, onRampAddr, observations[0].SeqNr, observations[len(observations)-1].SeqNr, 0).Return(sendReqs, nil)
p.config.sourceReader = sourceReader
p.config.onRampReader = sourceReader

execReport, err := p.buildReport(ctx, p.lggr, observations)
assert.NoError(t, err)
Expand Down Expand Up @@ -1022,18 +1020,18 @@ func TestExecutionReportingPlugin_getReportsWithSendRequests(t *testing.T) {
offRamp, offRampAddr := testhelpers.NewFakeOffRamp(t)
p.config.offRamp = offRamp

sourceReader := ccipdata.NewMockReader(t)
sourceReader := ccipdata.NewMockOnRampReader(t)
sourceReader.On("GetSendRequestsBetweenSeqNums", ctx, onRampAddr, tc.expQueryMin, tc.expQueryMax, 0).
Return(tc.onchainEvents, nil).Maybe()
p.config.sourceReader = sourceReader
p.config.onRampReader = sourceReader

destReader := ccipdata.NewMockReader(t)
destReader.On("LatestBlock", ctx).Return(tc.destLatestBlock, nil).Maybe()
var executedEvents []ccipdata.Event[evm_2_evm_offramp.EVM2EVMOffRampExecutionStateChanged]
for _, executedSeqNum := range tc.destExecutedSeqNums {
executedEvents = append(executedEvents, ccipdata.Event[evm_2_evm_offramp.EVM2EVMOffRampExecutionStateChanged]{
Data: evm_2_evm_offramp.EVM2EVMOffRampExecutionStateChanged{SequenceNumber: executedSeqNum},
BlockMeta: ccipdata.BlockMeta{BlockNumber: tc.destLatestBlock - 10},
Data: evm_2_evm_offramp.EVM2EVMOffRampExecutionStateChanged{SequenceNumber: executedSeqNum},
Meta: ccipdata.Meta{BlockNumber: tc.destLatestBlock - 10},
})
}
destReader.On("GetExecutionStateChangesBetweenSeqNums", ctx, offRampAddr, tc.expQueryMin, tc.expQueryMax, 0).Return(executedEvents, nil).Maybe()
Expand Down Expand Up @@ -1097,7 +1095,7 @@ func TestExecutionReportingPluginFactory_UpdateLogPollerFilters(t *testing.T) {
},
}

for _, f := range getExecutionPluginSourceLpChainFilters(onRamp.Address(), sourcePriceRegistry.Address(), tokenDataProviders) {
for _, f := range getExecutionPluginSourceLpChainFilters(sourcePriceRegistry.Address()) {
sourceLP.On("RegisterFilter", f).Return(nil)
}
for _, f := range getExecutionPluginDestLpChainFilters(commitStore.Address(), offRamp.Address(), destPriceRegistryAddr) {
Expand Down
20 changes: 0 additions & 20 deletions core/services/ocr2/plugins/ccip/internal/ccipdata/logpoller.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/pkg/errors"

evmclient "github.com/smartcontractkit/chainlink/v2/core/chains/evm/client"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller"
Expand Down Expand Up @@ -121,25 +120,6 @@ func (c *LogPollerReader) GetExecutionStateChangesBetweenSeqNums(ctx context.Con
)
}

func (c *LogPollerReader) GetLastUSDCMessagePriorToLogIndexInTx(ctx context.Context, logIndex int64, txHash common.Hash) ([]byte, error) {
logs, err := c.lp.IndexedLogsByTxHash(
abihelpers.EventSignatures.USDCMessageSent,
txHash,
pg.WithParentCtx(ctx),
)
if err != nil {
return nil, err
}

for i := range logs {
current := logs[len(logs)-i-1]
if current.LogIndex < logIndex {
return current.Data, nil
}
}
return nil, errors.Errorf("no USDC message found prior to log index %d in tx %s", logIndex, txHash.Hex())
}

func (c *LogPollerReader) LatestBlock(ctx context.Context) (int64, error) {
return c.lp.LatestBlock(pg.WithParentCtx(ctx))
}
Expand Down
Loading

0 comments on commit bf720db

Please sign in to comment.