Skip to content

Commit

Permalink
Merge branch 'ccip-develop' into dk/commit-e2e-test
Browse files Browse the repository at this point in the history
  • Loading branch information
dimkouv authored Aug 28, 2024
2 parents f9b94b1 + 19e757f commit c3877d1
Show file tree
Hide file tree
Showing 14 changed files with 746 additions and 189 deletions.
5 changes: 5 additions & 0 deletions .mockery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ packages:
HomeChain:
CCIP:
TokenPrices:
github.com/smartcontractkit/chainlink-common/pkg/types:
interfaces:
ChainReader:
config:
dir: mocks/cl-common/chainreader
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ generate: ensure_go_version
mockery

test: ensure_go_version
go test -race -fullpath -shuffle on -count $(TEST_COUNT) -coverprofile=$(COVERAGE_FILE) ./...
go test -race -fullpath -shuffle on -count $(TEST_COUNT) -coverprofile=$(COVERAGE_FILE) `go list ./... | grep -Ev 'chainlink-ccip/internal/mocks|chainlink-ccip/mocks'`

lint: ensure_go_version
golangci-lint run -c .golangci.yml
Expand Down
10 changes: 7 additions & 3 deletions execute/plugin_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/smartcontractkit/chainlink-ccip/internal/mocks"
"github.com/smartcontractkit/chainlink-ccip/internal/mocks/inmem"
"github.com/smartcontractkit/chainlink-ccip/internal/reader"
chainreadermocks "github.com/smartcontractkit/chainlink-ccip/mocks/cl-common/chainreader"
mock_types "github.com/smartcontractkit/chainlink-ccip/mocks/execute/exectypes"
"github.com/smartcontractkit/chainlink-ccip/pkg/consts"
"github.com/smartcontractkit/chainlink-ccip/pluginconfig"
Expand Down Expand Up @@ -90,8 +91,11 @@ type nodeSetup struct {
TokenDataReader *mock_types.MockTokenDataReader
}

func setupHomeChainPoller(lggr logger.Logger, chainConfigInfos []reader.ChainConfigInfo) reader.HomeChain {
homeChainReader := mocks.NewContractReaderMock()
func setupHomeChainPoller(
t *testing.T,
lggr logger.Logger,
chainConfigInfos []reader.ChainConfigInfo) reader.HomeChain {
homeChainReader := chainreadermocks.NewMockChainReader(t)
var firstCall = true
homeChainReader.On(
"GetLatestValue",
Expand Down Expand Up @@ -231,7 +235,7 @@ func setupSimpleTest(
},
}

homeChain := setupHomeChainPoller(lggr, chainConfigInfos)
homeChain := setupHomeChainPoller(t, lggr, chainConfigInfos)
err = homeChain.Start(ctx)
require.NoError(t, err, "failed to start home chain poller")

Expand Down
40 changes: 24 additions & 16 deletions execute/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/smartcontractkit/chainlink-ccip/execute/exectypes"
"github.com/smartcontractkit/chainlink-ccip/internal/libs/slicelib"
"github.com/smartcontractkit/chainlink-ccip/internal/plugincommon"
"github.com/smartcontractkit/chainlink-ccip/internal/reader"
codec_mocks "github.com/smartcontractkit/chainlink-ccip/mocks/execute/internal_/gen"
reader_mock "github.com/smartcontractkit/chainlink-ccip/mocks/internal_/reader"
"github.com/smartcontractkit/chainlink-ccip/pluginconfig"
Expand Down Expand Up @@ -209,16 +208,16 @@ func TestPlugin_ValidateObservation_SupportedChainsError(t *testing.T) {
func TestPlugin_ValidateObservation_IneligibleObserver(t *testing.T) {
lggr := logger.Test(t)

mockHomeChain := reader_mock.NewMockHomeChain(t)
mockHomeChain.EXPECT().GetSupportedChainsForPeer(mock.Anything).Return(mapset.NewSet[cciptypes.ChainSelector](), nil)
defer mockHomeChain.AssertExpectations(t)

p := &Plugin{
homeChain: setupHomeChainPoller(lggr, []reader.ChainConfigInfo{
{
ChainSelector: 0,
ChainConfig: reader.HomeChainConfigMapper{},
},
}),
homeChain: mockHomeChain,
oracleIDToP2pID: map[commontypes.OracleID]libocrtypes.PeerID{
0: {},
},
lggr: lggr,
}

observation := exectypes.NewObservation(nil, exectypes.MessageObservations{
Expand All @@ -242,13 +241,12 @@ func TestPlugin_ValidateObservation_IneligibleObserver(t *testing.T) {
func TestPlugin_ValidateObservation_ValidateObservedSeqNum_Error(t *testing.T) {
lggr := logger.Test(t)

mockHomeChain := reader_mock.NewMockHomeChain(t)
mockHomeChain.EXPECT().GetSupportedChainsForPeer(mock.Anything).Return(mapset.NewSet(cciptypes.ChainSelector(0)), nil)

p := &Plugin{
homeChain: setupHomeChainPoller(lggr, []reader.ChainConfigInfo{
{
ChainSelector: 1,
ChainConfig: reader.HomeChainConfigMapper{},
},
}),
lggr: lggr,
homeChain: mockHomeChain,
oracleIDToP2pID: map[commontypes.OracleID]libocrtypes.PeerID{
0: {},
},
Expand Down Expand Up @@ -283,8 +281,11 @@ func TestPlugin_Observation_BadPreviousOutcome(t *testing.T) {

func TestPlugin_Observation_EligibilityCheckFailure(t *testing.T) {
lggr := logger.Test(t)

mockHomeChain := reader_mock.NewMockHomeChain(t)

p := &Plugin{
homeChain: setupHomeChainPoller(lggr, []reader.ChainConfigInfo{}),
homeChain: mockHomeChain,
oracleIDToP2pID: map[commontypes.OracleID]libocrtypes.PeerID{},
lggr: lggr,
}
Expand Down Expand Up @@ -464,8 +465,10 @@ func TestPlugin_ShouldAcceptAttestedReport_ShouldAccept(t *testing.T) {

func TestPlugin_ShouldTransmitAcceptReport_ElegibilityCheckFailure(t *testing.T) {
lggr := logger.Test(t)

p := &Plugin{
homeChain: setupHomeChainPoller(lggr, []reader.ChainConfigInfo{}),
lggr: lggr,
homeChain: reader_mock.NewMockHomeChain(t),
oracleIDToP2pID: map[commontypes.OracleID]libocrtypes.PeerID{},
}

Expand All @@ -477,11 +480,16 @@ func TestPlugin_ShouldTransmitAcceptReport_ElegibilityCheckFailure(t *testing.T)

func TestPlugin_ShouldTransmitAcceptReport_Ineligible(t *testing.T) {
lggr, logs := logger.TestObserved(t, zapcore.DebugLevel)

mockHomeChain := reader_mock.NewMockHomeChain(t)
mockHomeChain.EXPECT().GetSupportedChainsForPeer(mock.Anything).Return(mapset.NewSet[cciptypes.ChainSelector](), nil)
defer mockHomeChain.AssertExpectations(t)

p := &Plugin{
lggr: lggr,
cfg: pluginconfig.ExecutePluginConfig{DestChain: 1},
reportingCfg: ocr3types.ReportingPluginConfig{OracleID: 2},
homeChain: setupHomeChainPoller(lggr, []reader.ChainConfigInfo{}),
homeChain: mockHomeChain,
oracleIDToP2pID: map[commontypes.OracleID]libocrtypes.PeerID{
2: {},
},
Expand Down
73 changes: 0 additions & 73 deletions internal/mocks/contract_reader.go

This file was deleted.

7 changes: 7 additions & 0 deletions internal/mocks/inmem/ccipreader_inmem.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ type InMemoryCCIPReader struct {
Dest cciptypes.ChainSelector
}

// GetExpectedNextSequenceNumber implements reader.CCIP.
func (r InMemoryCCIPReader) GetExpectedNextSequenceNumber(
ctx context.Context,
sourceChainSelector, destChainSelector cciptypes.ChainSelector) (cciptypes.SeqNum, error) {
panic("unimplemented")
}

func (r InMemoryCCIPReader) CommitReportsGTETimestamp(
_ context.Context, _ cciptypes.ChainSelector, ts time.Time, limit int,
) ([]plugintypes.CommitPluginReportWithMeta, error) {
Expand Down
42 changes: 42 additions & 0 deletions internal/reader/ccip.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ type CCIP interface {
seqNumRange cciptypes.SeqNumRange,
) ([]cciptypes.Message, error)

// GetExpectedNextSequenceNumber returns the next sequence number to be used
// in the onramp.
GetExpectedNextSequenceNumber(
ctx context.Context,
sourceChainSelector, destChainSelector cciptypes.ChainSelector,
) (cciptypes.SeqNum, error)

// NextSeqNum reads the destination chain.
// Returns the next expected sequence number for each one of the provided chains.
// TODO: if destination was a parameter, this could be a capability reused across plugin instances.
Expand Down Expand Up @@ -387,6 +394,41 @@ func (r *CCIPChainReader) MsgsBetweenSeqNums(
return msgs, nil
}

// GetExpectedNextSequenceNumber implements CCIP.
func (r *CCIPChainReader) GetExpectedNextSequenceNumber(
ctx context.Context,
sourceChainSelector, destChainSelector cciptypes.ChainSelector) (cciptypes.SeqNum, error) {
if destChainSelector != r.destChain {
return 0, fmt.Errorf("expected destination chain %d, got %d", r.destChain, destChainSelector)
}

if err := r.validateReaderExistence(sourceChainSelector); err != nil {
return 0, err
}

bindings := r.contractReaders[sourceChainSelector].GetBindings(consts.ContractNameOnRamp)
if len(bindings) != 1 {
return 0, fmt.Errorf("expected one binding for onRamp contract, got %d", len(bindings))
}

var expectedNextSequenceNumber uint64
err := r.contractReaders[sourceChainSelector].GetLatestValue(
ctx,
consts.ContractNameOnRamp,
consts.MethodNameGetExpectedNextSequenceNumber,
primitives.Unconfirmed,
map[string]any{
"destChainSelector": destChainSelector,
},
&expectedNextSequenceNumber,
)
if err != nil {
return 0, fmt.Errorf("failed to get expected next sequence number from onramp: %w", err)
}

return cciptypes.SeqNum(expectedNextSequenceNumber), nil
}

func (r *CCIPChainReader) NextSeqNum(
ctx context.Context, chains []cciptypes.ChainSelector,
) ([]cciptypes.SeqNum, error) {
Expand Down
8 changes: 4 additions & 4 deletions internal/reader/ccip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ import (
"github.com/smartcontractkit/chainlink-common/pkg/types"
cciptypes "github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3"

"github.com/smartcontractkit/chainlink-ccip/internal/mocks"
chainreadermocks "github.com/smartcontractkit/chainlink-ccip/mocks/cl-common/chainreader"
"github.com/smartcontractkit/chainlink-ccip/pkg/consts"
)

func TestCCIPChainReader_getSourceChainsConfig(t *testing.T) {
sourceCRs := make(map[cciptypes.ChainSelector]*mocks.ContractReaderMock)
sourceCRs := make(map[cciptypes.ChainSelector]*chainreadermocks.MockChainReader)
for _, chain := range []cciptypes.ChainSelector{chainA, chainB} {
sourceCRs[chain] = mocks.NewContractReaderMock()
sourceCRs[chain] = chainreadermocks.NewMockChainReader(t)
}

destCR := mocks.NewContractReaderMock()
destCR := chainreadermocks.NewMockChainReader(t)

destCR.On(
"GetLatestValue",
Expand Down
11 changes: 6 additions & 5 deletions internal/reader/home_chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
libocrtypes "github.com/smartcontractkit/libocr/ragep2p/types"

"github.com/smartcontractkit/chainlink-ccip/chainconfig"
"github.com/smartcontractkit/chainlink-ccip/internal/mocks"
"github.com/smartcontractkit/chainlink-ccip/pkg/consts"

"github.com/smartcontractkit/libocr/commontypes"
Expand All @@ -21,6 +20,8 @@ import (

"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"

chainreadermocks "github.com/smartcontractkit/chainlink-ccip/mocks/cl-common/chainreader"
)

var (
Expand All @@ -36,7 +37,7 @@ var (
)

func TestHomeChainConfigPoller_HealthReport(t *testing.T) {
homeChainReader := mocks.NewContractReaderMock()
homeChainReader := chainreadermocks.NewMockChainReader(t)
homeChainReader.On(
"GetLatestValue",
mock.Anything,
Expand Down Expand Up @@ -130,7 +131,7 @@ func Test_PollingWorking(t *testing.T) {
},
}

homeChainReader := mocks.NewContractReaderMock()
homeChainReader := chainreadermocks.NewMockChainReader(t)
homeChainReader.On(
"GetLatestValue",
mock.Anything,
Expand All @@ -149,7 +150,7 @@ func Test_PollingWorking(t *testing.T) {

var (
tickTime = 2 * time.Millisecond
totalSleepTime = tickTime * 4
totalSleepTime = tickTime * 20
)

configPoller := NewHomeChainConfigPoller(
Expand Down Expand Up @@ -185,7 +186,7 @@ func Test_PollingWorking(t *testing.T) {
func Test_HomeChainPoller_GetOCRConfig(t *testing.T) {
donID := uint32(1)
pluginType := uint8(1) // execution
homeChainReader := mocks.NewContractReaderMock()
homeChainReader := chainreadermocks.NewMockChainReader(t)
homeChainReader.On(
"GetLatestValue",
mock.Anything,
Expand Down
Loading

0 comments on commit c3877d1

Please sign in to comment.