Skip to content

Commit

Permalink
Migrate to mockery packagess feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
winder committed Jul 30, 2024
1 parent bc3fc8a commit f2fa806
Show file tree
Hide file tree
Showing 8 changed files with 487 additions and 49 deletions.
16 changes: 16 additions & 0 deletions .mockery.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
with-expecter: true
filename: "{{.InterfaceName | snakecase}}.go"
dir: "internal/mocks"
outpkg: "mocks"
packages:
github.com/smartcontractkit/chainlink-ccip/execute/types:
interfaces:
TokenDataReader:
github.com/smartcontractkit/chainlink-ccip/execute/internal/gen:
interfaces:
ExecutePluginCodec:
github.com/smartcontractkit/chainlink-ccip/internal/reader:
interfaces:
HomeChain:
config:
dir: "internal/reader/mocks"
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build: ensure_go_version
go build -v ./...

generate: ensure_go_version
go generate ./...
mockery

test: ensure_go_version
go test -race -fullpath -shuffle on -count $(TEST_COUNT) -coverprofile=$(COVERAGE_FILE) ./...
Expand Down
7 changes: 7 additions & 0 deletions execute/internal/gen/codec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package gen

import cciptypes "github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3"

type ExecutePluginCodec interface {
cciptypes.ExecutePluginCodec
}
4 changes: 2 additions & 2 deletions execute/plugin_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ type nodeSetup struct {
node *Plugin
reportCodec *mocks.ExecutePluginJSONReportCodec
msgHasher cciptypes.MessageHasher
TokenDataReader *mocks.TokenDataReader
TokenDataReader *mocks.MockTokenDataReader
}

func setupHomeChainPoller(lggr logger.Logger, chainConfigInfos []reader.ChainConfigInfo) reader.HomeChain {
Expand Down Expand Up @@ -200,7 +200,7 @@ func setupSimpleTest(
err = homeChain.Start(ctx)
require.NoError(t, err, "failed to start home chain poller")

tokenDataReader := mocks.NewTokenDataReader(t)
tokenDataReader := mocks.NewMockTokenDataReader(t)
tokenDataReader.On("ReadTokenData", mock.Anything, mock.Anything, mock.Anything).Return([][]byte{}, nil)

oracleIDToP2pID := GetP2pIDs(1, 2, 3)
Expand Down
22 changes: 11 additions & 11 deletions execute/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ func TestPlugin_Outcome_BelowF(t *testing.T) {
}

func TestPlugin_Outcome_HomeChainError(t *testing.T) {
homeChain := reader_mock.NewHomeChain(t)
homeChain := reader_mock.NewMockHomeChain(t)
homeChain.On("GetFChain", mock.Anything).Return(nil, fmt.Errorf("test error"))

p := &Plugin{
Expand All @@ -332,7 +332,7 @@ func TestPlugin_Outcome_HomeChainError(t *testing.T) {
}

func TestPlugin_Outcome_CommitReportsMergeError(t *testing.T) {
homeChain := reader_mock.NewHomeChain(t)
homeChain := reader_mock.NewMockHomeChain(t)
fChainMap := map[cciptypes.ChainSelector]int{
10: 20,
}
Expand All @@ -358,7 +358,7 @@ func TestPlugin_Outcome_CommitReportsMergeError(t *testing.T) {
}

func TestPlugin_Outcome_MessagesMergeError(t *testing.T) {
homeChain := reader_mock.NewHomeChain(t)
homeChain := reader_mock.NewMockHomeChain(t)
fChainMap := map[cciptypes.ChainSelector]int{
10: 20,
}
Expand Down Expand Up @@ -397,7 +397,7 @@ func TestPlugin_Reports_UnableToParse(t *testing.T) {
}

func TestPlugin_Reports_UnableToEncode(t *testing.T) {
codec := mocks.NewExecutePluginCodec(t)
codec := mocks.NewMockExecutePluginCodec(t)
codec.On("Encode", mock.Anything, mock.Anything).
Return(nil, fmt.Errorf("test error"))
p := &Plugin{reportCodec: codec}
Expand All @@ -410,7 +410,7 @@ func TestPlugin_Reports_UnableToEncode(t *testing.T) {
}

func TestPlugin_ShouldAcceptAttestedReport_DoesNotDecode(t *testing.T) {
codec := mocks.NewExecutePluginCodec(t)
codec := mocks.NewMockExecutePluginCodec(t)
codec.On("Decode", mock.Anything, mock.Anything).
Return(cciptypes.ExecutePluginReport{}, fmt.Errorf("test error"))
p := &Plugin{
Expand All @@ -422,7 +422,7 @@ func TestPlugin_ShouldAcceptAttestedReport_DoesNotDecode(t *testing.T) {
}

func TestPlugin_ShouldAcceptAttestedReport_NoReports(t *testing.T) {
codec := mocks.NewExecutePluginCodec(t)
codec := mocks.NewMockExecutePluginCodec(t)
codec.On("Decode", mock.Anything, mock.Anything).
Return(cciptypes.ExecutePluginReport{}, nil)
p := &Plugin{
Expand All @@ -435,7 +435,7 @@ func TestPlugin_ShouldAcceptAttestedReport_NoReports(t *testing.T) {
}

func TestPlugin_ShouldAcceptAttestedReport_ShouldAccept(t *testing.T) {
codec := mocks.NewExecutePluginCodec(t)
codec := mocks.NewMockExecutePluginCodec(t)
codec.On("Decode", mock.Anything, mock.Anything).
Return(cciptypes.ExecutePluginReport{
ChainReports: []cciptypes.ExecutePluginReportSingleChain{
Expand Down Expand Up @@ -487,9 +487,9 @@ func TestPlugin_ShouldTransmitAcceptReport_Ineligible(t *testing.T) {
}

func TestPlugin_ShouldTransmitAcceptReport_DecodeFailure(t *testing.T) {
homeChain := reader_mock.NewHomeChain(t)
homeChain := reader_mock.NewMockHomeChain(t)
homeChain.On("GetSupportedChainsForPeer", mock.Anything).Return(mapset.NewSet(cciptypes.ChainSelector(1)), nil)
codec := mocks.NewExecutePluginCodec(t)
codec := mocks.NewMockExecutePluginCodec(t)
codec.On("Decode", mock.Anything, mock.Anything).
Return(cciptypes.ExecutePluginReport{}, fmt.Errorf("test error"))

Expand All @@ -511,9 +511,9 @@ func TestPlugin_ShouldTransmitAcceptReport_DecodeFailure(t *testing.T) {

func TestPlugin_ShouldTransmitAcceptReport_Success(t *testing.T) {
lggr, logs := logger.TestObserved(t, zapcore.DebugLevel)
homeChain := reader_mock.NewHomeChain(t)
homeChain := reader_mock.NewMockHomeChain(t)
homeChain.On("GetSupportedChainsForPeer", mock.Anything).Return(mapset.NewSet(cciptypes.ChainSelector(1)), nil)
codec := mocks.NewExecutePluginCodec(t)
codec := mocks.NewMockExecutePluginCodec(t)
codec.On("Decode", mock.Anything, mock.Anything).
Return(cciptypes.ExecutePluginReport{}, nil)

Expand Down
88 changes: 77 additions & 11 deletions internal/mocks/execute_plugin_codec.go

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

52 changes: 45 additions & 7 deletions internal/mocks/token_data_reader.go

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

Loading

0 comments on commit f2fa806

Please sign in to comment.