From 98e2fba844f3b22368649ecf0795e59cc52e7d59 Mon Sep 17 00:00:00 2001 From: Jordan Krage Date: Tue, 6 Aug 2024 06:12:20 -0500 Subject: [PATCH] use gomods; add make generate; add CI check for tidiness+generation --- .github/workflows/relay.yml | 19 +++++++ Makefile | 22 ++++++-- pkg/cosmos/client/mocks/ReaderWriter.go | 68 +++++++++++++++++++++--- pkg/monitoring/fcdclient/mocks/Client.go | 33 ++++++++---- pkg/monitoring/mocks/ChainReader.go | 2 +- pkg/monitoring/mocks/Metrics.go | 2 +- 6 files changed, 124 insertions(+), 22 deletions(-) diff --git a/.github/workflows/relay.yml b/.github/workflows/relay.yml index 1d31a1428..362ac5f15 100644 --- a/.github/workflows/relay.yml +++ b/.github/workflows/relay.yml @@ -55,3 +55,22 @@ jobs: path: | ./unit_coverage.txt ./race_coverage.txt + + check-tidy: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 + - name: Set up Go + uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0 + with: + go-version-file: "relayer/go.mod" + - name: Ensure "make gomodtidy" has been run + run: | + make gomodtidy + git diff --exit-code + - name: Ensure "make generate" has been run + run: | + make rm-mocked + make generate + git diff --exit-code diff --git a/Makefile b/Makefile index a165e42aa..002fe5909 100644 --- a/Makefile +++ b/Makefile @@ -130,11 +130,25 @@ format-go-fmt: cd ./ops && go fmt ./... cd ./integration-tests && go fmt ./... +.PHONY: gomods +gomods: ## Install gomods + go install github.com/jmank88/gomods@v0.1.3 + .PHONY: gomodtidy -gomodtidy: - go mod tidy - cd ./ops && go mod tidy - cd ./integration-tests && go mod tidy +gomodtidy: gomods + gomods tidy + +.PHONY: mockery +mockery: $(mockery) ## Install mockery. + go install github.com/vektra/mockery/v2@v2.43.2 + +.PHONY: rm-mocked +rm-mocked: + grep -rl "^// Code generated by mockery" | grep .go$ | xargs -r rm + +.PHONY: generate +generate: mockery gomods + gomods -w go generate -x ./... .PHONY: lint-go lint-go: lint-go-ops lint-go-relayer lint-go-test diff --git a/pkg/cosmos/client/mocks/ReaderWriter.go b/pkg/cosmos/client/mocks/ReaderWriter.go index d6d57a0e2..3400ca964 100644 --- a/pkg/cosmos/client/mocks/ReaderWriter.go +++ b/pkg/cosmos/client/mocks/ReaderWriter.go @@ -1,10 +1,9 @@ -// Code generated by mockery v2.20.0. DO NOT EDIT. +// Code generated by mockery v2.43.2. DO NOT EDIT. package mocks import ( cosmos_sdkclient "github.com/cosmos/cosmos-sdk/client" - client "github.com/smartcontractkit/chainlink-cosmos/pkg/cosmos/client" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" @@ -29,6 +28,10 @@ type ReaderWriter struct { func (_m *ReaderWriter) Account(address types.AccAddress) (uint64, uint64, error) { ret := _m.Called(address) + if len(ret) == 0 { + panic("no return value specified for Account") + } + var r0 uint64 var r1 uint64 var r2 error @@ -60,6 +63,10 @@ func (_m *ReaderWriter) Account(address types.AccAddress) (uint64, uint64, error func (_m *ReaderWriter) Balance(addr types.AccAddress, denom string) (*types.Coin, error) { ret := _m.Called(addr, denom) + if len(ret) == 0 { + panic("no return value specified for Balance") + } + var r0 *types.Coin var r1 error if rf, ok := ret.Get(0).(func(types.AccAddress, string) (*types.Coin, error)); ok { @@ -86,6 +93,10 @@ func (_m *ReaderWriter) Balance(addr types.AccAddress, denom string) (*types.Coi func (_m *ReaderWriter) BatchSimulateUnsigned(msgs client.SimMsgs, sequence uint64) (*client.BatchSimResults, error) { ret := _m.Called(msgs, sequence) + if len(ret) == 0 { + panic("no return value specified for BatchSimulateUnsigned") + } + var r0 *client.BatchSimResults var r1 error if rf, ok := ret.Get(0).(func(client.SimMsgs, uint64) (*client.BatchSimResults, error)); ok { @@ -112,6 +123,10 @@ func (_m *ReaderWriter) BatchSimulateUnsigned(msgs client.SimMsgs, sequence uint func (_m *ReaderWriter) BlockByHeight(height int64) (*tmservice.GetBlockByHeightResponse, error) { ret := _m.Called(height) + if len(ret) == 0 { + panic("no return value specified for BlockByHeight") + } + var r0 *tmservice.GetBlockByHeightResponse var r1 error if rf, ok := ret.Get(0).(func(int64) (*tmservice.GetBlockByHeightResponse, error)); ok { @@ -138,6 +153,10 @@ func (_m *ReaderWriter) BlockByHeight(height int64) (*tmservice.GetBlockByHeight func (_m *ReaderWriter) Broadcast(txBytes []byte, mode tx.BroadcastMode) (*tx.BroadcastTxResponse, error) { ret := _m.Called(txBytes, mode) + if len(ret) == 0 { + panic("no return value specified for Broadcast") + } + var r0 *tx.BroadcastTxResponse var r1 error if rf, ok := ret.Get(0).(func([]byte, tx.BroadcastMode) (*tx.BroadcastTxResponse, error)); ok { @@ -164,6 +183,10 @@ func (_m *ReaderWriter) Broadcast(txBytes []byte, mode tx.BroadcastMode) (*tx.Br func (_m *ReaderWriter) Context() *cosmos_sdkclient.Context { ret := _m.Called() + if len(ret) == 0 { + panic("no return value specified for Context") + } + var r0 *cosmos_sdkclient.Context if rf, ok := ret.Get(0).(func() *cosmos_sdkclient.Context); ok { r0 = rf() @@ -180,6 +203,10 @@ func (_m *ReaderWriter) Context() *cosmos_sdkclient.Context { func (_m *ReaderWriter) ContractState(contractAddress types.AccAddress, queryMsg []byte) ([]byte, error) { ret := _m.Called(contractAddress, queryMsg) + if len(ret) == 0 { + panic("no return value specified for ContractState") + } + var r0 []byte var r1 error if rf, ok := ret.Get(0).(func(types.AccAddress, []byte) ([]byte, error)); ok { @@ -206,6 +233,10 @@ func (_m *ReaderWriter) ContractState(contractAddress types.AccAddress, queryMsg func (_m *ReaderWriter) CreateAndSign(msgs []types.Msg, account uint64, sequence uint64, gasLimit uint64, gasLimitMultiplier float64, gasPrice types.DecCoin, signer cryptotypes.PrivKey, timeoutHeight uint64) ([]byte, error) { ret := _m.Called(msgs, account, sequence, gasLimit, gasLimitMultiplier, gasPrice, signer, timeoutHeight) + if len(ret) == 0 { + panic("no return value specified for CreateAndSign") + } + var r0 []byte var r1 error if rf, ok := ret.Get(0).(func([]types.Msg, uint64, uint64, uint64, float64, types.DecCoin, cryptotypes.PrivKey, uint64) ([]byte, error)); ok { @@ -232,6 +263,10 @@ func (_m *ReaderWriter) CreateAndSign(msgs []types.Msg, account uint64, sequence func (_m *ReaderWriter) LatestBlock() (*tmservice.GetLatestBlockResponse, error) { ret := _m.Called() + if len(ret) == 0 { + panic("no return value specified for LatestBlock") + } + var r0 *tmservice.GetLatestBlockResponse var r1 error if rf, ok := ret.Get(0).(func() (*tmservice.GetLatestBlockResponse, error)); ok { @@ -258,6 +293,10 @@ func (_m *ReaderWriter) LatestBlock() (*tmservice.GetLatestBlockResponse, error) func (_m *ReaderWriter) SignAndBroadcast(msgs []types.Msg, accountNum uint64, sequence uint64, gasPrice types.DecCoin, signer cryptotypes.PrivKey, mode tx.BroadcastMode) (*tx.BroadcastTxResponse, error) { ret := _m.Called(msgs, accountNum, sequence, gasPrice, signer, mode) + if len(ret) == 0 { + panic("no return value specified for SignAndBroadcast") + } + var r0 *tx.BroadcastTxResponse var r1 error if rf, ok := ret.Get(0).(func([]types.Msg, uint64, uint64, types.DecCoin, cryptotypes.PrivKey, tx.BroadcastMode) (*tx.BroadcastTxResponse, error)); ok { @@ -284,6 +323,10 @@ func (_m *ReaderWriter) SignAndBroadcast(msgs []types.Msg, accountNum uint64, se func (_m *ReaderWriter) Simulate(txBytes []byte) (*tx.SimulateResponse, error) { ret := _m.Called(txBytes) + if len(ret) == 0 { + panic("no return value specified for Simulate") + } + var r0 *tx.SimulateResponse var r1 error if rf, ok := ret.Get(0).(func([]byte) (*tx.SimulateResponse, error)); ok { @@ -310,6 +353,10 @@ func (_m *ReaderWriter) Simulate(txBytes []byte) (*tx.SimulateResponse, error) { func (_m *ReaderWriter) SimulateUnsigned(msgs []types.Msg, sequence uint64) (*tx.SimulateResponse, error) { ret := _m.Called(msgs, sequence) + if len(ret) == 0 { + panic("no return value specified for SimulateUnsigned") + } + var r0 *tx.SimulateResponse var r1 error if rf, ok := ret.Get(0).(func([]types.Msg, uint64) (*tx.SimulateResponse, error)); ok { @@ -336,6 +383,10 @@ func (_m *ReaderWriter) SimulateUnsigned(msgs []types.Msg, sequence uint64) (*tx func (_m *ReaderWriter) Tx(hash string) (*tx.GetTxResponse, error) { ret := _m.Called(hash) + if len(ret) == 0 { + panic("no return value specified for Tx") + } + var r0 *tx.GetTxResponse var r1 error if rf, ok := ret.Get(0).(func(string) (*tx.GetTxResponse, error)); ok { @@ -362,6 +413,10 @@ func (_m *ReaderWriter) Tx(hash string) (*tx.GetTxResponse, error) { func (_m *ReaderWriter) TxsEvents(events []string, paginationParams *query.PageRequest) (*tx.GetTxsEventResponse, error) { ret := _m.Called(events, paginationParams) + if len(ret) == 0 { + panic("no return value specified for TxsEvents") + } + var r0 *tx.GetTxsEventResponse var r1 error if rf, ok := ret.Get(0).(func([]string, *query.PageRequest) (*tx.GetTxsEventResponse, error)); ok { @@ -384,13 +439,12 @@ func (_m *ReaderWriter) TxsEvents(events []string, paginationParams *query.PageR return r0, r1 } -type mockConstructorTestingTNewReaderWriter interface { +// NewReaderWriter creates a new instance of ReaderWriter. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewReaderWriter(t interface { mock.TestingT Cleanup(func()) -} - -// NewReaderWriter creates a new instance of ReaderWriter. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewReaderWriter(t mockConstructorTestingTNewReaderWriter) *ReaderWriter { +}) *ReaderWriter { mock := &ReaderWriter{} mock.Mock.Test(t) diff --git a/pkg/monitoring/fcdclient/mocks/Client.go b/pkg/monitoring/fcdclient/mocks/Client.go index 78dc28fbd..31b3c5a4f 100644 --- a/pkg/monitoring/fcdclient/mocks/Client.go +++ b/pkg/monitoring/fcdclient/mocks/Client.go @@ -1,15 +1,12 @@ -// Code generated by mockery v2.12.0. DO NOT EDIT. +// Code generated by mockery v2.43.2. DO NOT EDIT. package mocks import ( context "context" - mock "github.com/stretchr/testify/mock" - fcdclient "github.com/smartcontractkit/chainlink-cosmos/pkg/monitoring/fcdclient" - - testing "testing" + mock "github.com/stretchr/testify/mock" ) // Client is an autogenerated mock type for the Client type @@ -21,14 +18,21 @@ type Client struct { func (_m *Client) GetBlockAtHeight(_a0 context.Context, _a1 uint64) (fcdclient.Response, error) { ret := _m.Called(_a0, _a1) + if len(ret) == 0 { + panic("no return value specified for GetBlockAtHeight") + } + var r0 fcdclient.Response + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, uint64) (fcdclient.Response, error)); ok { + return rf(_a0, _a1) + } if rf, ok := ret.Get(0).(func(context.Context, uint64) fcdclient.Response); ok { r0 = rf(_a0, _a1) } else { r0 = ret.Get(0).(fcdclient.Response) } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, uint64) error); ok { r1 = rf(_a0, _a1) } else { @@ -42,14 +46,21 @@ func (_m *Client) GetBlockAtHeight(_a0 context.Context, _a1 uint64) (fcdclient.R func (_m *Client) GetTxList(_a0 context.Context, _a1 fcdclient.GetTxListParams) (fcdclient.Response, error) { ret := _m.Called(_a0, _a1) + if len(ret) == 0 { + panic("no return value specified for GetTxList") + } + var r0 fcdclient.Response + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, fcdclient.GetTxListParams) (fcdclient.Response, error)); ok { + return rf(_a0, _a1) + } if rf, ok := ret.Get(0).(func(context.Context, fcdclient.GetTxListParams) fcdclient.Response); ok { r0 = rf(_a0, _a1) } else { r0 = ret.Get(0).(fcdclient.Response) } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, fcdclient.GetTxListParams) error); ok { r1 = rf(_a0, _a1) } else { @@ -59,8 +70,12 @@ func (_m *Client) GetTxList(_a0 context.Context, _a1 fcdclient.GetTxListParams) return r0, r1 } -// NewClient creates a new instance of Client. It also registers the testing.TB interface on the mock and a cleanup function to assert the mocks expectations. -func NewClient(t testing.TB) *Client { +// NewClient creates a new instance of Client. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewClient(t interface { + mock.TestingT + Cleanup(func()) +}) *Client { mock := &Client{} mock.Mock.Test(t) diff --git a/pkg/monitoring/mocks/ChainReader.go b/pkg/monitoring/mocks/ChainReader.go index a2e0fd28f..0b1e84c6b 100644 --- a/pkg/monitoring/mocks/ChainReader.go +++ b/pkg/monitoring/mocks/ChainReader.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. +// Code generated by mockery v2.43.2. DO NOT EDIT. package mocks diff --git a/pkg/monitoring/mocks/Metrics.go b/pkg/monitoring/mocks/Metrics.go index 4b206efd1..6d52f5bb0 100644 --- a/pkg/monitoring/mocks/Metrics.go +++ b/pkg/monitoring/mocks/Metrics.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. +// Code generated by mockery v2.43.2. DO NOT EDIT. package mocks