diff --git a/Makefile b/Makefile index c55caf5a3cd..b5b581d1042 100644 --- a/Makefile +++ b/Makefile @@ -199,7 +199,7 @@ clean: ## devtools: installs dev tools (and checks for npm installation etc.) devtools: - # Notice! If you adding new binary - add it also to cmd/hack/binary-deps/main.go file + # Notice! If you adding new binary - add it also to tools.go file $(GOBUILD) -o $(GOBIN)/gencodec github.com/fjl/gencodec $(GOBUILD) -o $(GOBIN)/mockgen go.uber.org/mock/mockgen $(GOBUILD) -o $(GOBIN)/abigen ./cmd/abigen @@ -213,6 +213,16 @@ devtools: @type "solc" 2> /dev/null || echo 'Please install solc' @type "protoc" 2> /dev/null || echo 'Please install protoc' +## mocks: generate test mocks +mocks: mocks-clean + @cd erigon-lib && $(MAKE) mocks + $(GOBUILD) -o $(GOBIN)/mockgen go.uber.org/mock/mockgen + PATH="$(GOBIN):$(PATH)" go generate -run "mockgen" ./... + +## mocks-clean: cleans all generated test mocks +mocks-clean: + grep -r -l --exclude-dir=erigon-lib "^// Code generated by MockGen. DO NOT EDIT.$$" . | xargs rm -r + ## bindings: generate test contracts and core contracts bindings: PATH=$(GOBIN):$(PATH) go generate ./tests/contracts/ diff --git a/cl/beacon/handler/utils_test.go b/cl/beacon/handler/utils_test.go index 03ac9e58eb2..76e72eb2cdf 100644 --- a/cl/beacon/handler/utils_test.go +++ b/cl/beacon/handler/utils_test.go @@ -5,6 +5,11 @@ import ( "math" "testing" + "github.com/ledgerwatch/log/v3" + "github.com/spf13/afero" + "github.com/stretchr/testify/require" + "go.uber.org/mock/gomock" + "github.com/ledgerwatch/erigon-lib/common/datadir" "github.com/ledgerwatch/erigon-lib/kv" "github.com/ledgerwatch/erigon-lib/kv/memdb" @@ -20,18 +25,14 @@ import ( state_accessors "github.com/ledgerwatch/erigon/cl/persistence/state" "github.com/ledgerwatch/erigon/cl/persistence/state/historical_states_reader" "github.com/ledgerwatch/erigon/cl/phase1/core/state" - "github.com/ledgerwatch/erigon/cl/phase1/forkchoice" + mock_services2 "github.com/ledgerwatch/erigon/cl/phase1/forkchoice/mock_services" "github.com/ledgerwatch/erigon/cl/phase1/network/services/mock_services" "github.com/ledgerwatch/erigon/cl/pool" "github.com/ledgerwatch/erigon/cl/utils/eth_clock" "github.com/ledgerwatch/erigon/cl/validator/validator_params" - "github.com/ledgerwatch/log/v3" - "github.com/spf13/afero" - "github.com/stretchr/testify/require" - "go.uber.org/mock/gomock" ) -func setupTestingHandler(t *testing.T, v clparams.StateVersion, logger log.Logger) (db kv.RwDB, blocks []*cltypes.SignedBeaconBlock, f afero.Fs, preState, postState *state.CachingBeaconState, h *ApiHandler, opPool pool.OperationsPool, syncedData *synced_data.SyncedDataManager, fcu *forkchoice.ForkChoiceStorageMock, vp *validator_params.ValidatorParams) { +func setupTestingHandler(t *testing.T, v clparams.StateVersion, logger log.Logger) (db kv.RwDB, blocks []*cltypes.SignedBeaconBlock, f afero.Fs, preState, postState *state.CachingBeaconState, h *ApiHandler, opPool pool.OperationsPool, syncedData *synced_data.SyncedDataManager, fcu *mock_services2.ForkChoiceStorageMock, vp *validator_params.ValidatorParams) { bcfg := clparams.MainnetBeaconConfig if v == clparams.Phase0Version { blocks, preState, postState = tests.GetPhase0Random() @@ -45,7 +46,7 @@ func setupTestingHandler(t *testing.T, v clparams.StateVersion, logger log.Logge bcfg.CapellaForkEpoch = 1 blocks, preState, postState = tests.GetCapellaRandom() } - fcu = forkchoice.NewForkChoiceStorageMock(t) + fcu = mock_services2.NewForkChoiceStorageMock(t) db = memdb.NewTestDB(t) blobDb := memdb.NewTestDB(t) var reader *tests.MockBlockReader diff --git a/cl/phase1/forkchoice/forkchoice_mock.go b/cl/phase1/forkchoice/mock_services/forkchoice_mock.go similarity index 98% rename from cl/phase1/forkchoice/forkchoice_mock.go rename to cl/phase1/forkchoice/mock_services/forkchoice_mock.go index 5c8cb952e1a..1c117ca02ee 100644 --- a/cl/phase1/forkchoice/forkchoice_mock.go +++ b/cl/phase1/forkchoice/mock_services/forkchoice_mock.go @@ -1,20 +1,22 @@ -package forkchoice +package mock_services import ( "context" "testing" + "go.uber.org/mock/gomock" + "github.com/ledgerwatch/erigon-lib/common" libcommon "github.com/ledgerwatch/erigon-lib/common" "github.com/ledgerwatch/erigon/cl/cltypes" "github.com/ledgerwatch/erigon/cl/cltypes/solid" "github.com/ledgerwatch/erigon/cl/phase1/core/state" "github.com/ledgerwatch/erigon/cl/phase1/execution_client" + "github.com/ledgerwatch/erigon/cl/phase1/forkchoice" "github.com/ledgerwatch/erigon/cl/pool" "github.com/ledgerwatch/erigon/cl/transition/impl/eth2" "github.com/ledgerwatch/erigon/cl/validator/sync_contribution_pool" syncpoolmock "github.com/ledgerwatch/erigon/cl/validator/sync_contribution_pool/mock_services" - "go.uber.org/mock/gomock" ) // Make mocks with maps and simple setters and getters, panic on methods from ForkChoiceStorageWriter @@ -39,7 +41,7 @@ type ForkChoiceStorageMock struct { StateAtSlotVal map[uint64]*state.CachingBeaconState GetSyncCommitteesVal map[uint64][2]*solid.SyncCommittee GetFinalityCheckpointsVal map[common.Hash][3]solid.Checkpoint - WeightsMock []ForkNode + WeightsMock []forkchoice.ForkNode LightClientBootstraps map[common.Hash]*cltypes.LightClientBootstrap NewestLCUpdate *cltypes.LightClientUpdate LCUpdates map[uint64]*cltypes.LightClientUpdate @@ -229,7 +231,7 @@ func (f *ForkChoiceStorageMock) Partecipation(epoch uint64) (*solid.BitList, boo return f.ParticipationVal, f.ParticipationVal != nil } -func (f *ForkChoiceStorageMock) ForkNodes() []ForkNode { +func (f *ForkChoiceStorageMock) ForkNodes() []forkchoice.ForkNode { return f.WeightsMock } diff --git a/cl/phase1/network/services/aggregate_and_proof_service_test.go b/cl/phase1/network/services/aggregate_and_proof_service_test.go index e6ea4772ba1..2b1c02270f4 100644 --- a/cl/phase1/network/services/aggregate_and_proof_service_test.go +++ b/cl/phase1/network/services/aggregate_and_proof_service_test.go @@ -4,6 +4,9 @@ import ( "context" "testing" + "github.com/stretchr/testify/require" + "go.uber.org/mock/gomock" + "github.com/ledgerwatch/erigon-lib/common" libcommon "github.com/ledgerwatch/erigon-lib/common" "github.com/ledgerwatch/erigon/cl/antiquary/tests" @@ -12,10 +15,8 @@ import ( "github.com/ledgerwatch/erigon/cl/cltypes" "github.com/ledgerwatch/erigon/cl/cltypes/solid" "github.com/ledgerwatch/erigon/cl/phase1/core/state" - "github.com/ledgerwatch/erigon/cl/phase1/forkchoice" + "github.com/ledgerwatch/erigon/cl/phase1/forkchoice/mock_services" "github.com/ledgerwatch/erigon/cl/pool" - "github.com/stretchr/testify/require" - "go.uber.org/mock/gomock" ) func getAggregateAndProofAndState(t *testing.T) (*cltypes.SignedAggregateAndProof, *state.CachingBeaconState) { @@ -40,12 +41,12 @@ func getAggregateAndProofAndState(t *testing.T) (*cltypes.SignedAggregateAndProo } -func setupAggregateAndProofTest(t *testing.T) (AggregateAndProofService, *synced_data.SyncedDataManager, *forkchoice.ForkChoiceStorageMock) { +func setupAggregateAndProofTest(t *testing.T) (AggregateAndProofService, *synced_data.SyncedDataManager, *mock_services.ForkChoiceStorageMock) { ctx, cn := context.WithCancel(context.Background()) cn() cfg := &clparams.MainnetBeaconConfig syncedDataManager := synced_data.NewSyncedDataManager(true, cfg) - forkchoiceMock := forkchoice.NewForkChoiceStorageMock(t) + forkchoiceMock := mock_services.NewForkChoiceStorageMock(t) p := pool.OperationsPool{} p.AttestationsPool = pool.NewOperationPool[libcommon.Bytes96, *solid.Attestation](100, "test") blockService := NewAggregateAndProofService(ctx, syncedDataManager, forkchoiceMock, cfg, p, true) diff --git a/cl/phase1/network/services/attestation_service_test.go b/cl/phase1/network/services/attestation_service_test.go index ff15fd444b3..044dbe0eec7 100644 --- a/cl/phase1/network/services/attestation_service_test.go +++ b/cl/phase1/network/services/attestation_service_test.go @@ -5,6 +5,9 @@ import ( "log" "testing" + "github.com/stretchr/testify/suite" + "go.uber.org/mock/gomock" + "github.com/ledgerwatch/erigon-lib/common" "github.com/ledgerwatch/erigon-lib/types/ssz" mockSync "github.com/ledgerwatch/erigon/cl/beacon/synced_data/mock_services" @@ -13,11 +16,9 @@ import ( "github.com/ledgerwatch/erigon/cl/cltypes/solid" "github.com/ledgerwatch/erigon/cl/phase1/core/state" mockState "github.com/ledgerwatch/erigon/cl/phase1/core/state/mock_services" - "github.com/ledgerwatch/erigon/cl/phase1/forkchoice" + "github.com/ledgerwatch/erigon/cl/phase1/forkchoice/mock_services" "github.com/ledgerwatch/erigon/cl/utils/eth_clock" mockCommittee "github.com/ledgerwatch/erigon/cl/validator/committee_subscription/mock_services" - "github.com/stretchr/testify/suite" - "go.uber.org/mock/gomock" ) var ( @@ -38,7 +39,7 @@ var ( type attestationTestSuite struct { suite.Suite gomockCtrl *gomock.Controller - mockForkChoice *forkchoice.ForkChoiceStorageMock + mockForkChoice *mock_services.ForkChoiceStorageMock syncedData *mockSync.MockSyncedData beaconStateReader *mockState.MockBeaconStateReader committeeSubscibe *mockCommittee.MockCommitteeSubscribe @@ -49,7 +50,7 @@ type attestationTestSuite struct { func (t *attestationTestSuite) SetupTest() { t.gomockCtrl = gomock.NewController(t.T()) - t.mockForkChoice = &forkchoice.ForkChoiceStorageMock{} + t.mockForkChoice = &mock_services.ForkChoiceStorageMock{} t.syncedData = mockSync.NewMockSyncedData(t.gomockCtrl) t.beaconStateReader = mockState.NewMockBeaconStateReader(t.gomockCtrl) t.committeeSubscibe = mockCommittee.NewMockCommitteeSubscribe(t.gomockCtrl) diff --git a/cl/phase1/network/services/blob_sidecar_service_test.go b/cl/phase1/network/services/blob_sidecar_service_test.go index 0811ace2067..e2768e1ee96 100644 --- a/cl/phase1/network/services/blob_sidecar_service_test.go +++ b/cl/phase1/network/services/blob_sidecar_service_test.go @@ -5,17 +5,18 @@ import ( _ "embed" "testing" + "github.com/stretchr/testify/require" + "go.uber.org/mock/gomock" + "github.com/ledgerwatch/erigon-lib/common" libcommon "github.com/ledgerwatch/erigon-lib/common" "github.com/ledgerwatch/erigon/cl/beacon/synced_data" "github.com/ledgerwatch/erigon/cl/clparams" "github.com/ledgerwatch/erigon/cl/cltypes" "github.com/ledgerwatch/erigon/cl/phase1/core/state" - "github.com/ledgerwatch/erigon/cl/phase1/forkchoice" + "github.com/ledgerwatch/erigon/cl/phase1/forkchoice/mock_services" "github.com/ledgerwatch/erigon/cl/utils" "github.com/ledgerwatch/erigon/cl/utils/eth_clock" - "github.com/stretchr/testify/require" - "go.uber.org/mock/gomock" ) //go:embed test_data/blob_sidecar_service_blob.ssz_snappy @@ -48,14 +49,14 @@ func getObjectsForBlobSidecarServiceTests(t *testing.T) (*state.CachingBeaconSta return stateObj, block, sidecar } -func setupBlobSidecarService(t *testing.T, ctrl *gomock.Controller, test bool) (BlobSidecarsService, *synced_data.SyncedDataManager, *eth_clock.MockEthereumClock, *forkchoice.ForkChoiceStorageMock) { +func setupBlobSidecarService(t *testing.T, ctrl *gomock.Controller, test bool) (BlobSidecarsService, *synced_data.SyncedDataManager, *eth_clock.MockEthereumClock, *mock_services.ForkChoiceStorageMock) { ctx := context.Background() ctx2, cn := context.WithTimeout(ctx, 1) cn() cfg := &clparams.MainnetBeaconConfig syncedDataManager := synced_data.NewSyncedDataManager(true, cfg) ethClock := eth_clock.NewMockEthereumClock(ctrl) - forkchoiceMock := forkchoice.NewForkChoiceStorageMock(t) + forkchoiceMock := mock_services.NewForkChoiceStorageMock(t) blockService := NewBlobSidecarService(ctx2, cfg, forkchoiceMock, syncedDataManager, ethClock, test) return blockService, syncedDataManager, ethClock, forkchoiceMock } diff --git a/cl/phase1/network/services/block_service_test.go b/cl/phase1/network/services/block_service_test.go index f0eeb2ae39a..402912ecb05 100644 --- a/cl/phase1/network/services/block_service_test.go +++ b/cl/phase1/network/services/block_service_test.go @@ -4,24 +4,25 @@ import ( "context" "testing" + "github.com/stretchr/testify/require" + "go.uber.org/mock/gomock" + "github.com/ledgerwatch/erigon-lib/kv/memdb" "github.com/ledgerwatch/erigon/cl/antiquary/tests" "github.com/ledgerwatch/erigon/cl/beacon/synced_data" "github.com/ledgerwatch/erigon/cl/clparams" "github.com/ledgerwatch/erigon/cl/cltypes" "github.com/ledgerwatch/erigon/cl/cltypes/solid" - "github.com/ledgerwatch/erigon/cl/phase1/forkchoice" + "github.com/ledgerwatch/erigon/cl/phase1/forkchoice/mock_services" "github.com/ledgerwatch/erigon/cl/utils/eth_clock" - "github.com/stretchr/testify/require" - "go.uber.org/mock/gomock" ) -func setupBlockService(t *testing.T, ctrl *gomock.Controller) (BlockService, *synced_data.SyncedDataManager, *eth_clock.MockEthereumClock, *forkchoice.ForkChoiceStorageMock) { +func setupBlockService(t *testing.T, ctrl *gomock.Controller) (BlockService, *synced_data.SyncedDataManager, *eth_clock.MockEthereumClock, *mock_services.ForkChoiceStorageMock) { db := memdb.NewTestDB(t) cfg := &clparams.MainnetBeaconConfig syncedDataManager := synced_data.NewSyncedDataManager(true, cfg) ethClock := eth_clock.NewMockEthereumClock(ctrl) - forkchoiceMock := forkchoice.NewForkChoiceStorageMock(t) + forkchoiceMock := mock_services.NewForkChoiceStorageMock(t) blockService := NewBlockService(context.Background(), db, forkchoiceMock, syncedDataManager, ethClock, cfg, nil) return blockService, syncedDataManager, ethClock, forkchoiceMock } diff --git a/cl/sentinel/handlers/blobs_test.go b/cl/sentinel/handlers/blobs_test.go index 8aa459d4c03..d0feb663422 100644 --- a/cl/sentinel/handlers/blobs_test.go +++ b/cl/sentinel/handlers/blobs_test.go @@ -10,6 +10,12 @@ import ( "testing" "github.com/golang/snappy" + "github.com/libp2p/go-libp2p" + "github.com/libp2p/go-libp2p/core/peer" + "github.com/libp2p/go-libp2p/core/protocol" + "github.com/spf13/afero" + "github.com/stretchr/testify/require" + libcommon "github.com/ledgerwatch/erigon-lib/common" "github.com/ledgerwatch/erigon-lib/kv/memdb" "github.com/ledgerwatch/erigon/cl/antiquary/tests" @@ -18,17 +24,12 @@ import ( "github.com/ledgerwatch/erigon/cl/cltypes" "github.com/ledgerwatch/erigon/cl/cltypes/solid" "github.com/ledgerwatch/erigon/cl/persistence/blob_storage" - "github.com/ledgerwatch/erigon/cl/phase1/forkchoice" + "github.com/ledgerwatch/erigon/cl/phase1/forkchoice/mock_services" "github.com/ledgerwatch/erigon/cl/sentinel/communication" "github.com/ledgerwatch/erigon/cl/sentinel/communication/ssz_snappy" "github.com/ledgerwatch/erigon/cl/sentinel/peers" "github.com/ledgerwatch/erigon/cl/utils" "github.com/ledgerwatch/erigon/cl/utils/eth_clock" - "github.com/libp2p/go-libp2p" - "github.com/libp2p/go-libp2p/core/peer" - "github.com/libp2p/go-libp2p/core/protocol" - "github.com/spf13/afero" - "github.com/stretchr/testify/require" ) func getEthClock(t *testing.T) eth_clock.EthereumClock { @@ -101,7 +102,7 @@ func TestBlobsByRangeHandler(t *testing.T) { nil, beaconCfg, ethClock, - nil, &forkchoice.ForkChoiceStorageMock{}, blobStorage, true, + nil, &mock_services.ForkChoiceStorageMock{}, blobStorage, true, ) c.Start() req := &cltypes.BlobsByRangeRequest{ @@ -222,7 +223,7 @@ func TestBlobsByIdentifiersHandler(t *testing.T) { nil, beaconCfg, ethClock, - nil, &forkchoice.ForkChoiceStorageMock{}, blobStorage, true, + nil, &mock_services.ForkChoiceStorageMock{}, blobStorage, true, ) c.Start() req := solid.NewStaticListSSZ[*cltypes.BlobIdentifier](40269, 40) diff --git a/cl/sentinel/handlers/blocks_by_range_test.go b/cl/sentinel/handlers/blocks_by_range_test.go index d8d1f401463..6c53b598e07 100644 --- a/cl/sentinel/handlers/blocks_by_range_test.go +++ b/cl/sentinel/handlers/blocks_by_range_test.go @@ -9,19 +9,20 @@ import ( "testing" "github.com/golang/snappy" + "github.com/libp2p/go-libp2p" + "github.com/libp2p/go-libp2p/core/peer" + "github.com/libp2p/go-libp2p/core/protocol" + "github.com/stretchr/testify/require" + libcommon "github.com/ledgerwatch/erigon-lib/common" "github.com/ledgerwatch/erigon/cl/antiquary/tests" "github.com/ledgerwatch/erigon/cl/clparams" "github.com/ledgerwatch/erigon/cl/cltypes" - "github.com/ledgerwatch/erigon/cl/phase1/forkchoice" + "github.com/ledgerwatch/erigon/cl/phase1/forkchoice/mock_services" "github.com/ledgerwatch/erigon/cl/sentinel/communication" "github.com/ledgerwatch/erigon/cl/sentinel/communication/ssz_snappy" "github.com/ledgerwatch/erigon/cl/sentinel/peers" "github.com/ledgerwatch/erigon/cl/utils" - "github.com/libp2p/go-libp2p" - "github.com/libp2p/go-libp2p/core/peer" - "github.com/libp2p/go-libp2p/core/protocol" - "github.com/stretchr/testify/require" ) func TestBlocksByRootHandler(t *testing.T) { @@ -66,7 +67,7 @@ func TestBlocksByRootHandler(t *testing.T) { nil, beaconCfg, ethClock, - nil, &forkchoice.ForkChoiceStorageMock{}, nil, true, + nil, &mock_services.ForkChoiceStorageMock{}, nil, true, ) c.Start() req := &cltypes.BeaconBlocksByRangeRequest{ diff --git a/cl/sentinel/handlers/blocks_by_root_test.go b/cl/sentinel/handlers/blocks_by_root_test.go index 33e5ee8cef2..43c99e817c4 100644 --- a/cl/sentinel/handlers/blocks_by_root_test.go +++ b/cl/sentinel/handlers/blocks_by_root_test.go @@ -9,21 +9,22 @@ import ( "testing" "github.com/golang/snappy" + "github.com/libp2p/go-libp2p" + "github.com/libp2p/go-libp2p/core/peer" + "github.com/libp2p/go-libp2p/core/protocol" + "github.com/stretchr/testify/require" + libcommon "github.com/ledgerwatch/erigon-lib/common" "github.com/ledgerwatch/erigon/cl/antiquary/tests" "github.com/ledgerwatch/erigon/cl/clparams" "github.com/ledgerwatch/erigon/cl/cltypes" "github.com/ledgerwatch/erigon/cl/cltypes/solid" "github.com/ledgerwatch/erigon/cl/persistence/beacon_indicies" - "github.com/ledgerwatch/erigon/cl/phase1/forkchoice" + "github.com/ledgerwatch/erigon/cl/phase1/forkchoice/mock_services" "github.com/ledgerwatch/erigon/cl/sentinel/communication" "github.com/ledgerwatch/erigon/cl/sentinel/communication/ssz_snappy" "github.com/ledgerwatch/erigon/cl/sentinel/peers" "github.com/ledgerwatch/erigon/cl/utils" - "github.com/libp2p/go-libp2p" - "github.com/libp2p/go-libp2p/core/peer" - "github.com/libp2p/go-libp2p/core/protocol" - "github.com/stretchr/testify/require" ) func TestBlocksByRangeHandler(t *testing.T) { @@ -69,7 +70,7 @@ func TestBlocksByRangeHandler(t *testing.T) { nil, beaconCfg, ethClock, - nil, &forkchoice.ForkChoiceStorageMock{}, nil, true, + nil, &mock_services.ForkChoiceStorageMock{}, nil, true, ) c.Start() var req solid.HashListSSZ = solid.NewHashList(len(expBlocks)) diff --git a/cl/sentinel/handlers/heartbeats_test.go b/cl/sentinel/handlers/heartbeats_test.go index 17bc598dee1..4bfb28c8027 100644 --- a/cl/sentinel/handlers/heartbeats_test.go +++ b/cl/sentinel/handlers/heartbeats_test.go @@ -6,10 +6,16 @@ import ( "crypto/ecdsa" "testing" + "github.com/ledgerwatch/log/v3" + "github.com/libp2p/go-libp2p" + "github.com/libp2p/go-libp2p/core/peer" + "github.com/libp2p/go-libp2p/core/protocol" + "github.com/stretchr/testify/require" + libcommon "github.com/ledgerwatch/erigon-lib/common" "github.com/ledgerwatch/erigon/cl/clparams" "github.com/ledgerwatch/erigon/cl/cltypes" - "github.com/ledgerwatch/erigon/cl/phase1/forkchoice" + "github.com/ledgerwatch/erigon/cl/phase1/forkchoice/mock_services" "github.com/ledgerwatch/erigon/cl/sentinel/communication" "github.com/ledgerwatch/erigon/cl/sentinel/communication/ssz_snappy" "github.com/ledgerwatch/erigon/cl/sentinel/handshake" @@ -17,11 +23,6 @@ import ( "github.com/ledgerwatch/erigon/crypto" "github.com/ledgerwatch/erigon/p2p/enode" "github.com/ledgerwatch/erigon/p2p/enr" - "github.com/ledgerwatch/log/v3" - "github.com/libp2p/go-libp2p" - "github.com/libp2p/go-libp2p/core/peer" - "github.com/libp2p/go-libp2p/core/protocol" - "github.com/stretchr/testify/require" ) var ( @@ -68,7 +69,7 @@ func TestPing(t *testing.T) { peersPool := peers.NewPool() beaconDB, indiciesDB := setupStore(t) - f := forkchoice.NewForkChoiceStorageMock(t) + f := mock_services.NewForkChoiceStorageMock(t) ethClock := getEthClock(t) _, beaconCfg := clparams.GetConfigsByNetwork(1) @@ -123,7 +124,7 @@ func TestGoodbye(t *testing.T) { peersPool := peers.NewPool() beaconDB, indiciesDB := setupStore(t) - f := forkchoice.NewForkChoiceStorageMock(t) + f := mock_services.NewForkChoiceStorageMock(t) ethClock := getEthClock(t) _, beaconCfg := clparams.GetConfigsByNetwork(1) c := NewConsensusHandlers( @@ -183,7 +184,7 @@ func TestMetadataV2(t *testing.T) { peersPool := peers.NewPool() beaconDB, indiciesDB := setupStore(t) - f := forkchoice.NewForkChoiceStorageMock(t) + f := mock_services.NewForkChoiceStorageMock(t) ethClock := getEthClock(t) nc := clparams.NetworkConfigs[clparams.MainnetNetwork] _, beaconCfg := clparams.GetConfigsByNetwork(1) @@ -241,7 +242,7 @@ func TestMetadataV1(t *testing.T) { peersPool := peers.NewPool() beaconDB, indiciesDB := setupStore(t) - f := forkchoice.NewForkChoiceStorageMock(t) + f := mock_services.NewForkChoiceStorageMock(t) nc := clparams.NetworkConfigs[clparams.MainnetNetwork] ethClock := getEthClock(t) @@ -299,7 +300,7 @@ func TestStatus(t *testing.T) { peersPool := peers.NewPool() beaconDB, indiciesDB := setupStore(t) - f := forkchoice.NewForkChoiceStorageMock(t) + f := mock_services.NewForkChoiceStorageMock(t) hs := handshake.New(ctx, getEthClock(t), &clparams.MainnetBeaconConfig, nil) s := &cltypes.Status{ diff --git a/cl/sentinel/handlers/light_client_test.go b/cl/sentinel/handlers/light_client_test.go index 39a46209903..6ffcf412897 100644 --- a/cl/sentinel/handlers/light_client_test.go +++ b/cl/sentinel/handlers/light_client_test.go @@ -9,20 +9,21 @@ import ( "testing" "github.com/golang/snappy" + "github.com/libp2p/go-libp2p" + "github.com/libp2p/go-libp2p/core/peer" + "github.com/libp2p/go-libp2p/core/protocol" + "github.com/stretchr/testify/require" + "github.com/ledgerwatch/erigon-lib/common" libcommon "github.com/ledgerwatch/erigon-lib/common" "github.com/ledgerwatch/erigon/cl/clparams" "github.com/ledgerwatch/erigon/cl/cltypes" "github.com/ledgerwatch/erigon/cl/cltypes/solid" - "github.com/ledgerwatch/erigon/cl/phase1/forkchoice" + "github.com/ledgerwatch/erigon/cl/phase1/forkchoice/mock_services" "github.com/ledgerwatch/erigon/cl/sentinel/communication" "github.com/ledgerwatch/erigon/cl/sentinel/communication/ssz_snappy" "github.com/ledgerwatch/erigon/cl/sentinel/peers" "github.com/ledgerwatch/erigon/cl/utils" - "github.com/libp2p/go-libp2p" - "github.com/libp2p/go-libp2p/core/peer" - "github.com/libp2p/go-libp2p/core/protocol" - "github.com/stretchr/testify/require" ) func TestLightClientOptimistic(t *testing.T) { @@ -45,7 +46,7 @@ func TestLightClientOptimistic(t *testing.T) { peersPool := peers.NewPool() beaconDB, indiciesDB := setupStore(t) - f := forkchoice.NewForkChoiceStorageMock(t) + f := mock_services.NewForkChoiceStorageMock(t) f.NewestLCUpdate = &cltypes.LightClientUpdate{ AttestedHeader: cltypes.NewLightClientHeader(clparams.AltairVersion), @@ -115,7 +116,7 @@ func TestLightClientFinality(t *testing.T) { peersPool := peers.NewPool() beaconDB, indiciesDB := setupStore(t) - f := forkchoice.NewForkChoiceStorageMock(t) + f := mock_services.NewForkChoiceStorageMock(t) f.NewestLCUpdate = &cltypes.LightClientUpdate{ AttestedHeader: cltypes.NewLightClientHeader(clparams.AltairVersion), @@ -188,7 +189,7 @@ func TestLightClientBootstrap(t *testing.T) { peersPool := peers.NewPool() beaconDB, indiciesDB := setupStore(t) - f := forkchoice.NewForkChoiceStorageMock(t) + f := mock_services.NewForkChoiceStorageMock(t) f.NewestLCUpdate = &cltypes.LightClientUpdate{ AttestedHeader: cltypes.NewLightClientHeader(clparams.AltairVersion), @@ -270,7 +271,7 @@ func TestLightClientUpdates(t *testing.T) { peersPool := peers.NewPool() beaconDB, indiciesDB := setupStore(t) - f := forkchoice.NewForkChoiceStorageMock(t) + f := mock_services.NewForkChoiceStorageMock(t) ethClock := getEthClock(t) up := &cltypes.LightClientUpdate{ diff --git a/cl/sentinel/sentinel_gossip_test.go b/cl/sentinel/sentinel_gossip_test.go index 24dfaaa20da..7900885c8b1 100644 --- a/cl/sentinel/sentinel_gossip_test.go +++ b/cl/sentinel/sentinel_gossip_test.go @@ -6,13 +6,14 @@ import ( "testing" "time" - "github.com/ledgerwatch/erigon/cl/clparams" - "github.com/ledgerwatch/erigon/cl/clparams/initial_state" - "github.com/ledgerwatch/erigon/cl/phase1/forkchoice" - "github.com/ledgerwatch/erigon/cl/utils/eth_clock" "github.com/ledgerwatch/log/v3" "github.com/libp2p/go-libp2p/core/peer" "github.com/stretchr/testify/require" + + "github.com/ledgerwatch/erigon/cl/clparams" + "github.com/ledgerwatch/erigon/cl/clparams/initial_state" + "github.com/ledgerwatch/erigon/cl/phase1/forkchoice/mock_services" + "github.com/ledgerwatch/erigon/cl/utils/eth_clock" ) func getEthClock(t *testing.T) eth_clock.EthereumClock { @@ -45,7 +46,7 @@ func TestSentinelGossipOnHardFork(t *testing.T) { IpAddr: listenAddrHost, Port: 7070, EnableBlocks: true, - }, ethClock, reader, nil, db, log.New(), &forkchoice.ForkChoiceStorageMock{}) + }, ethClock, reader, nil, db, log.New(), &mock_services.ForkChoiceStorageMock{}) require.NoError(t, err) defer sentinel1.Stop() @@ -59,7 +60,7 @@ func TestSentinelGossipOnHardFork(t *testing.T) { Port: 7077, EnableBlocks: true, TCPPort: 9123, - }, ethClock, reader, nil, db, log.New(), &forkchoice.ForkChoiceStorageMock{}) + }, ethClock, reader, nil, db, log.New(), &mock_services.ForkChoiceStorageMock{}) require.NoError(t, err) defer sentinel2.Stop() diff --git a/cl/sentinel/sentinel_requests_test.go b/cl/sentinel/sentinel_requests_test.go index a346d2bd03e..4f821c53a1d 100644 --- a/cl/sentinel/sentinel_requests_test.go +++ b/cl/sentinel/sentinel_requests_test.go @@ -8,6 +8,13 @@ import ( "testing" "github.com/golang/snappy" + "github.com/ledgerwatch/log/v3" + "github.com/libp2p/go-libp2p" + "github.com/libp2p/go-libp2p/core/peer" + "github.com/libp2p/go-libp2p/core/protocol" + "github.com/spf13/afero" + "github.com/stretchr/testify/require" + "github.com/ledgerwatch/erigon-lib/common/datadir" "github.com/ledgerwatch/erigon-lib/kv" "github.com/ledgerwatch/erigon-lib/kv/memdb" @@ -18,16 +25,10 @@ import ( "github.com/ledgerwatch/erigon/cl/cltypes/solid" state_accessors "github.com/ledgerwatch/erigon/cl/persistence/state" "github.com/ledgerwatch/erigon/cl/phase1/core/state" - "github.com/ledgerwatch/erigon/cl/phase1/forkchoice" + "github.com/ledgerwatch/erigon/cl/phase1/forkchoice/mock_services" "github.com/ledgerwatch/erigon/cl/sentinel/communication" "github.com/ledgerwatch/erigon/cl/sentinel/communication/ssz_snappy" "github.com/ledgerwatch/erigon/cl/utils" - "github.com/ledgerwatch/log/v3" - "github.com/libp2p/go-libp2p" - "github.com/libp2p/go-libp2p/core/peer" - "github.com/libp2p/go-libp2p/core/protocol" - "github.com/spf13/afero" - "github.com/stretchr/testify/require" ) func loadChain(t *testing.T) (db kv.RwDB, blocks []*cltypes.SignedBeaconBlock, f afero.Fs, preState, postState *state.CachingBeaconState, reader *tests.MockBlockReader) { @@ -55,7 +56,7 @@ func TestSentinelBlocksByRange(t *testing.T) { IpAddr: listenAddrHost, Port: 7070, EnableBlocks: true, - }, ethClock, reader, nil, db, log.New(), &forkchoice.ForkChoiceStorageMock{}) + }, ethClock, reader, nil, db, log.New(), &mock_services.ForkChoiceStorageMock{}) require.NoError(t, err) defer sentinel.Stop() @@ -159,7 +160,7 @@ func TestSentinelBlocksByRoots(t *testing.T) { IpAddr: listenAddrHost, Port: 7070, EnableBlocks: true, - }, ethClock, reader, nil, db, log.New(), &forkchoice.ForkChoiceStorageMock{}) + }, ethClock, reader, nil, db, log.New(), &mock_services.ForkChoiceStorageMock{}) require.NoError(t, err) defer sentinel.Stop() @@ -268,7 +269,7 @@ func TestSentinelStatusRequest(t *testing.T) { IpAddr: listenAddrHost, Port: 7070, EnableBlocks: true, - }, ethClock, reader, nil, db, log.New(), &forkchoice.ForkChoiceStorageMock{}) + }, ethClock, reader, nil, db, log.New(), &mock_services.ForkChoiceStorageMock{}) require.NoError(t, err) defer sentinel.Stop() diff --git a/cl/validator/sync_contribution_pool/interface.go b/cl/validator/sync_contribution_pool/interface.go index 0f7b0693b52..13e10a41acc 100644 --- a/cl/validator/sync_contribution_pool/interface.go +++ b/cl/validator/sync_contribution_pool/interface.go @@ -9,7 +9,7 @@ import ( // SyncContributionPool is an interface for managing sync committee contributions and messages. // it keeps a store of sync committee contributions, if new messages are received they are aggregated with pre-existing contributions. -//go:generate mockgen -destination=mock_services/sync_contribution_pool_mock.go -package=sync_contribution_pool . SyncContributionPool +//go:generate mockgen -destination=mock_services/sync_contribution_pool_mock.go -package=mock_services . SyncContributionPool type SyncContributionPool interface { // AddSyncContribution adds a sync committee contribution to the pool. AddSyncContribution(headState *state.CachingBeaconState, contribution *cltypes.Contribution) error diff --git a/cl/validator/sync_contribution_pool/mock_services/sync_contribution_pool_mock.go b/cl/validator/sync_contribution_pool/mock_services/sync_contribution_pool_mock.go index 9e428bf97a0..28d195388d3 100644 --- a/cl/validator/sync_contribution_pool/mock_services/sync_contribution_pool_mock.go +++ b/cl/validator/sync_contribution_pool/mock_services/sync_contribution_pool_mock.go @@ -3,11 +3,11 @@ // // Generated by this command: // -// mockgen -destination=mock_services/sync_contribution_pool_mock.go -package=sync_contribution_pool . SyncContributionPool +// mockgen -destination=mock_services/sync_contribution_pool_mock.go -package=mock_services . SyncContributionPool // -// Package sync_contribution_pool is a generated GoMock package. -package sync_contribution_pool +// Package mock_services is a generated GoMock package. +package mock_services import ( reflect "reflect" diff --git a/erigon-lib/Makefile b/erigon-lib/Makefile index 54151bb86d2..6ba68de50f8 100644 --- a/erigon-lib/Makefile +++ b/erigon-lib/Makefile @@ -72,13 +72,14 @@ grpc: protoc-all txpool/txpool.proto txpool/mining.proto rm -rf vendor -$(GOBINREL)/moq: | $(GOBINREL) - $(GOBUILD) -o "$(GOBIN)/moq" github.com/matryer/moq +$(GOBINREL)/mockgen: | $(GOBINREL) + $(GOBUILD) -o "$(GOBIN)/mockgen" go.uber.org/mock/mockgen -mocks: $(GOBINREL)/moq - rm -f gointerfaces/remote/mocks.go - rm -f gointerfaces/sentry/mocks.go - PATH="$(GOBIN):$(PATH)" go generate ./... +mocks-clean: + grep -r -l "^// Code generated by MockGen. DO NOT EDIT.$$" . | xargs rm -r + +mocks: $(GOBINREL)/mockgen mocks-clean + PATH="$(GOBIN):$(PATH)" go generate -run "mockgen" ./... lintci-deps: @./tools/golangci_lint.sh --install-deps diff --git a/erigon-lib/go.mod b/erigon-lib/go.mod index 6d23b87681f..7c7a97c2850 100644 --- a/erigon-lib/go.mod +++ b/erigon-lib/go.mod @@ -27,7 +27,6 @@ require ( github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 github.com/hashicorp/golang-lru/v2 v2.0.6 github.com/holiman/uint256 v1.2.3 - github.com/matryer/moq v0.3.4 github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 github.com/pelletier/go-toml/v2 v2.1.0 github.com/prometheus/client_golang v1.18.0 @@ -48,7 +47,11 @@ require ( google.golang.org/protobuf v1.33.0 ) -require github.com/cespare/xxhash v1.1.0 // indirect +require ( + github.com/cespare/xxhash v1.1.0 // indirect + golang.org/x/mod v0.12.0 // indirect + golang.org/x/tools v0.13.0 // indirect +) require ( github.com/ajwerner/btree v0.0.0-20211221152037-f427b3e689c0 // indirect @@ -128,10 +131,8 @@ require ( go.etcd.io/bbolt v1.3.6 // indirect go.opentelemetry.io/otel v1.8.0 // indirect go.opentelemetry.io/otel/trace v1.8.0 // indirect - golang.org/x/mod v0.14.0 // indirect golang.org/x/net v0.21.0 // indirect golang.org/x/text v0.14.0 // indirect - golang.org/x/tools v0.17.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect gopkg.in/yaml.v3 v3.0.1 // indirect modernc.org/libc v1.24.1 // indirect diff --git a/erigon-lib/go.sum b/erigon-lib/go.sum index 8448cc70560..6fba8f15897 100644 --- a/erigon-lib/go.sum +++ b/erigon-lib/go.sum @@ -277,8 +277,6 @@ github.com/ledgerwatch/secp256k1 v1.0.0 h1:Usvz87YoTG0uePIV8woOof5cQnLXGYa162rFf github.com/ledgerwatch/secp256k1 v1.0.0/go.mod h1:SPmqJFciiF/Q0mPt2jVs2dTr/1TZBTIA+kPMmKgBAak= github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4= github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I= -github.com/matryer/moq v0.3.4 h1:czCFIos9rI2tyOehN9ktc/6bQ76N9J4xQ2n3dk063ac= -github.com/matryer/moq v0.3.4/go.mod h1:wqm9QObyoMuUtH81zFfs3EK6mXEcByy+TjvSROOXJ2U= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= @@ -501,8 +499,8 @@ golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHl golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0= -golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= +golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -616,8 +614,8 @@ golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roY golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/tools v0.17.0 h1:FvmRgNOcs3kOa+T20R1uhfP9F6HgG2mfxDv1vrx1Htc= -golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps= +golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ= +golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/erigon-lib/gointerfaces/remote/kv_client_mock.go b/erigon-lib/gointerfaces/remote/kv_client_mock.go new file mode 100644 index 00000000000..8d0b208e92f --- /dev/null +++ b/erigon-lib/gointerfaces/remote/kv_client_mock.go @@ -0,0 +1,483 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/ledgerwatch/erigon-lib/gointerfaces/remote (interfaces: KVClient) +// +// Generated by this command: +// +// mockgen -typed=true -destination=./kv_client_mock.go -package=remote . KVClient +// + +// Package remote is a generated GoMock package. +package remote + +import ( + context "context" + reflect "reflect" + + types "github.com/ledgerwatch/erigon-lib/gointerfaces/types" + gomock "go.uber.org/mock/gomock" + grpc "google.golang.org/grpc" + emptypb "google.golang.org/protobuf/types/known/emptypb" +) + +// MockKVClient is a mock of KVClient interface. +type MockKVClient struct { + ctrl *gomock.Controller + recorder *MockKVClientMockRecorder +} + +// MockKVClientMockRecorder is the mock recorder for MockKVClient. +type MockKVClientMockRecorder struct { + mock *MockKVClient +} + +// NewMockKVClient creates a new mock instance. +func NewMockKVClient(ctrl *gomock.Controller) *MockKVClient { + mock := &MockKVClient{ctrl: ctrl} + mock.recorder = &MockKVClientMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockKVClient) EXPECT() *MockKVClientMockRecorder { + return m.recorder +} + +// DomainGet mocks base method. +func (m *MockKVClient) DomainGet(arg0 context.Context, arg1 *DomainGetReq, arg2 ...grpc.CallOption) (*DomainGetReply, error) { + m.ctrl.T.Helper() + varargs := []any{arg0, arg1} + for _, a := range arg2 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "DomainGet", varargs...) + ret0, _ := ret[0].(*DomainGetReply) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// DomainGet indicates an expected call of DomainGet. +func (mr *MockKVClientMockRecorder) DomainGet(arg0, arg1 any, arg2 ...any) *MockKVClientDomainGetCall { + mr.mock.ctrl.T.Helper() + varargs := append([]any{arg0, arg1}, arg2...) + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DomainGet", reflect.TypeOf((*MockKVClient)(nil).DomainGet), varargs...) + return &MockKVClientDomainGetCall{Call: call} +} + +// MockKVClientDomainGetCall wrap *gomock.Call +type MockKVClientDomainGetCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockKVClientDomainGetCall) Return(arg0 *DomainGetReply, arg1 error) *MockKVClientDomainGetCall { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockKVClientDomainGetCall) Do(f func(context.Context, *DomainGetReq, ...grpc.CallOption) (*DomainGetReply, error)) *MockKVClientDomainGetCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockKVClientDomainGetCall) DoAndReturn(f func(context.Context, *DomainGetReq, ...grpc.CallOption) (*DomainGetReply, error)) *MockKVClientDomainGetCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// DomainRange mocks base method. +func (m *MockKVClient) DomainRange(arg0 context.Context, arg1 *DomainRangeReq, arg2 ...grpc.CallOption) (*Pairs, error) { + m.ctrl.T.Helper() + varargs := []any{arg0, arg1} + for _, a := range arg2 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "DomainRange", varargs...) + ret0, _ := ret[0].(*Pairs) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// DomainRange indicates an expected call of DomainRange. +func (mr *MockKVClientMockRecorder) DomainRange(arg0, arg1 any, arg2 ...any) *MockKVClientDomainRangeCall { + mr.mock.ctrl.T.Helper() + varargs := append([]any{arg0, arg1}, arg2...) + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DomainRange", reflect.TypeOf((*MockKVClient)(nil).DomainRange), varargs...) + return &MockKVClientDomainRangeCall{Call: call} +} + +// MockKVClientDomainRangeCall wrap *gomock.Call +type MockKVClientDomainRangeCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockKVClientDomainRangeCall) Return(arg0 *Pairs, arg1 error) *MockKVClientDomainRangeCall { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockKVClientDomainRangeCall) Do(f func(context.Context, *DomainRangeReq, ...grpc.CallOption) (*Pairs, error)) *MockKVClientDomainRangeCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockKVClientDomainRangeCall) DoAndReturn(f func(context.Context, *DomainRangeReq, ...grpc.CallOption) (*Pairs, error)) *MockKVClientDomainRangeCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// HistoryGet mocks base method. +func (m *MockKVClient) HistoryGet(arg0 context.Context, arg1 *HistoryGetReq, arg2 ...grpc.CallOption) (*HistoryGetReply, error) { + m.ctrl.T.Helper() + varargs := []any{arg0, arg1} + for _, a := range arg2 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "HistoryGet", varargs...) + ret0, _ := ret[0].(*HistoryGetReply) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// HistoryGet indicates an expected call of HistoryGet. +func (mr *MockKVClientMockRecorder) HistoryGet(arg0, arg1 any, arg2 ...any) *MockKVClientHistoryGetCall { + mr.mock.ctrl.T.Helper() + varargs := append([]any{arg0, arg1}, arg2...) + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HistoryGet", reflect.TypeOf((*MockKVClient)(nil).HistoryGet), varargs...) + return &MockKVClientHistoryGetCall{Call: call} +} + +// MockKVClientHistoryGetCall wrap *gomock.Call +type MockKVClientHistoryGetCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockKVClientHistoryGetCall) Return(arg0 *HistoryGetReply, arg1 error) *MockKVClientHistoryGetCall { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockKVClientHistoryGetCall) Do(f func(context.Context, *HistoryGetReq, ...grpc.CallOption) (*HistoryGetReply, error)) *MockKVClientHistoryGetCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockKVClientHistoryGetCall) DoAndReturn(f func(context.Context, *HistoryGetReq, ...grpc.CallOption) (*HistoryGetReply, error)) *MockKVClientHistoryGetCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// HistoryRange mocks base method. +func (m *MockKVClient) HistoryRange(arg0 context.Context, arg1 *HistoryRangeReq, arg2 ...grpc.CallOption) (*Pairs, error) { + m.ctrl.T.Helper() + varargs := []any{arg0, arg1} + for _, a := range arg2 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "HistoryRange", varargs...) + ret0, _ := ret[0].(*Pairs) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// HistoryRange indicates an expected call of HistoryRange. +func (mr *MockKVClientMockRecorder) HistoryRange(arg0, arg1 any, arg2 ...any) *MockKVClientHistoryRangeCall { + mr.mock.ctrl.T.Helper() + varargs := append([]any{arg0, arg1}, arg2...) + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HistoryRange", reflect.TypeOf((*MockKVClient)(nil).HistoryRange), varargs...) + return &MockKVClientHistoryRangeCall{Call: call} +} + +// MockKVClientHistoryRangeCall wrap *gomock.Call +type MockKVClientHistoryRangeCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockKVClientHistoryRangeCall) Return(arg0 *Pairs, arg1 error) *MockKVClientHistoryRangeCall { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockKVClientHistoryRangeCall) Do(f func(context.Context, *HistoryRangeReq, ...grpc.CallOption) (*Pairs, error)) *MockKVClientHistoryRangeCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockKVClientHistoryRangeCall) DoAndReturn(f func(context.Context, *HistoryRangeReq, ...grpc.CallOption) (*Pairs, error)) *MockKVClientHistoryRangeCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// IndexRange mocks base method. +func (m *MockKVClient) IndexRange(arg0 context.Context, arg1 *IndexRangeReq, arg2 ...grpc.CallOption) (*IndexRangeReply, error) { + m.ctrl.T.Helper() + varargs := []any{arg0, arg1} + for _, a := range arg2 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "IndexRange", varargs...) + ret0, _ := ret[0].(*IndexRangeReply) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// IndexRange indicates an expected call of IndexRange. +func (mr *MockKVClientMockRecorder) IndexRange(arg0, arg1 any, arg2 ...any) *MockKVClientIndexRangeCall { + mr.mock.ctrl.T.Helper() + varargs := append([]any{arg0, arg1}, arg2...) + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IndexRange", reflect.TypeOf((*MockKVClient)(nil).IndexRange), varargs...) + return &MockKVClientIndexRangeCall{Call: call} +} + +// MockKVClientIndexRangeCall wrap *gomock.Call +type MockKVClientIndexRangeCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockKVClientIndexRangeCall) Return(arg0 *IndexRangeReply, arg1 error) *MockKVClientIndexRangeCall { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockKVClientIndexRangeCall) Do(f func(context.Context, *IndexRangeReq, ...grpc.CallOption) (*IndexRangeReply, error)) *MockKVClientIndexRangeCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockKVClientIndexRangeCall) DoAndReturn(f func(context.Context, *IndexRangeReq, ...grpc.CallOption) (*IndexRangeReply, error)) *MockKVClientIndexRangeCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Range mocks base method. +func (m *MockKVClient) Range(arg0 context.Context, arg1 *RangeReq, arg2 ...grpc.CallOption) (*Pairs, error) { + m.ctrl.T.Helper() + varargs := []any{arg0, arg1} + for _, a := range arg2 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Range", varargs...) + ret0, _ := ret[0].(*Pairs) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Range indicates an expected call of Range. +func (mr *MockKVClientMockRecorder) Range(arg0, arg1 any, arg2 ...any) *MockKVClientRangeCall { + mr.mock.ctrl.T.Helper() + varargs := append([]any{arg0, arg1}, arg2...) + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Range", reflect.TypeOf((*MockKVClient)(nil).Range), varargs...) + return &MockKVClientRangeCall{Call: call} +} + +// MockKVClientRangeCall wrap *gomock.Call +type MockKVClientRangeCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockKVClientRangeCall) Return(arg0 *Pairs, arg1 error) *MockKVClientRangeCall { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockKVClientRangeCall) Do(f func(context.Context, *RangeReq, ...grpc.CallOption) (*Pairs, error)) *MockKVClientRangeCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockKVClientRangeCall) DoAndReturn(f func(context.Context, *RangeReq, ...grpc.CallOption) (*Pairs, error)) *MockKVClientRangeCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Snapshots mocks base method. +func (m *MockKVClient) Snapshots(arg0 context.Context, arg1 *SnapshotsRequest, arg2 ...grpc.CallOption) (*SnapshotsReply, error) { + m.ctrl.T.Helper() + varargs := []any{arg0, arg1} + for _, a := range arg2 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Snapshots", varargs...) + ret0, _ := ret[0].(*SnapshotsReply) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Snapshots indicates an expected call of Snapshots. +func (mr *MockKVClientMockRecorder) Snapshots(arg0, arg1 any, arg2 ...any) *MockKVClientSnapshotsCall { + mr.mock.ctrl.T.Helper() + varargs := append([]any{arg0, arg1}, arg2...) + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Snapshots", reflect.TypeOf((*MockKVClient)(nil).Snapshots), varargs...) + return &MockKVClientSnapshotsCall{Call: call} +} + +// MockKVClientSnapshotsCall wrap *gomock.Call +type MockKVClientSnapshotsCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockKVClientSnapshotsCall) Return(arg0 *SnapshotsReply, arg1 error) *MockKVClientSnapshotsCall { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockKVClientSnapshotsCall) Do(f func(context.Context, *SnapshotsRequest, ...grpc.CallOption) (*SnapshotsReply, error)) *MockKVClientSnapshotsCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockKVClientSnapshotsCall) DoAndReturn(f func(context.Context, *SnapshotsRequest, ...grpc.CallOption) (*SnapshotsReply, error)) *MockKVClientSnapshotsCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// StateChanges mocks base method. +func (m *MockKVClient) StateChanges(arg0 context.Context, arg1 *StateChangeRequest, arg2 ...grpc.CallOption) (KV_StateChangesClient, error) { + m.ctrl.T.Helper() + varargs := []any{arg0, arg1} + for _, a := range arg2 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "StateChanges", varargs...) + ret0, _ := ret[0].(KV_StateChangesClient) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// StateChanges indicates an expected call of StateChanges. +func (mr *MockKVClientMockRecorder) StateChanges(arg0, arg1 any, arg2 ...any) *MockKVClientStateChangesCall { + mr.mock.ctrl.T.Helper() + varargs := append([]any{arg0, arg1}, arg2...) + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateChanges", reflect.TypeOf((*MockKVClient)(nil).StateChanges), varargs...) + return &MockKVClientStateChangesCall{Call: call} +} + +// MockKVClientStateChangesCall wrap *gomock.Call +type MockKVClientStateChangesCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockKVClientStateChangesCall) Return(arg0 KV_StateChangesClient, arg1 error) *MockKVClientStateChangesCall { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockKVClientStateChangesCall) Do(f func(context.Context, *StateChangeRequest, ...grpc.CallOption) (KV_StateChangesClient, error)) *MockKVClientStateChangesCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockKVClientStateChangesCall) DoAndReturn(f func(context.Context, *StateChangeRequest, ...grpc.CallOption) (KV_StateChangesClient, error)) *MockKVClientStateChangesCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Tx mocks base method. +func (m *MockKVClient) Tx(arg0 context.Context, arg1 ...grpc.CallOption) (KV_TxClient, error) { + m.ctrl.T.Helper() + varargs := []any{arg0} + for _, a := range arg1 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Tx", varargs...) + ret0, _ := ret[0].(KV_TxClient) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Tx indicates an expected call of Tx. +func (mr *MockKVClientMockRecorder) Tx(arg0 any, arg1 ...any) *MockKVClientTxCall { + mr.mock.ctrl.T.Helper() + varargs := append([]any{arg0}, arg1...) + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Tx", reflect.TypeOf((*MockKVClient)(nil).Tx), varargs...) + return &MockKVClientTxCall{Call: call} +} + +// MockKVClientTxCall wrap *gomock.Call +type MockKVClientTxCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockKVClientTxCall) Return(arg0 KV_TxClient, arg1 error) *MockKVClientTxCall { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockKVClientTxCall) Do(f func(context.Context, ...grpc.CallOption) (KV_TxClient, error)) *MockKVClientTxCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockKVClientTxCall) DoAndReturn(f func(context.Context, ...grpc.CallOption) (KV_TxClient, error)) *MockKVClientTxCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Version mocks base method. +func (m *MockKVClient) Version(arg0 context.Context, arg1 *emptypb.Empty, arg2 ...grpc.CallOption) (*types.VersionReply, error) { + m.ctrl.T.Helper() + varargs := []any{arg0, arg1} + for _, a := range arg2 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Version", varargs...) + ret0, _ := ret[0].(*types.VersionReply) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Version indicates an expected call of Version. +func (mr *MockKVClientMockRecorder) Version(arg0, arg1 any, arg2 ...any) *MockKVClientVersionCall { + mr.mock.ctrl.T.Helper() + varargs := append([]any{arg0, arg1}, arg2...) + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Version", reflect.TypeOf((*MockKVClient)(nil).Version), varargs...) + return &MockKVClientVersionCall{Call: call} +} + +// MockKVClientVersionCall wrap *gomock.Call +type MockKVClientVersionCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockKVClientVersionCall) Return(arg0 *types.VersionReply, arg1 error) *MockKVClientVersionCall { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockKVClientVersionCall) Do(f func(context.Context, *emptypb.Empty, ...grpc.CallOption) (*types.VersionReply, error)) *MockKVClientVersionCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockKVClientVersionCall) DoAndReturn(f func(context.Context, *emptypb.Empty, ...grpc.CallOption) (*types.VersionReply, error)) *MockKVClientVersionCall { + c.Call = c.Call.DoAndReturn(f) + return c +} diff --git a/erigon-lib/gointerfaces/remote/kv_state_changes_client_mock.go b/erigon-lib/gointerfaces/remote/kv_state_changes_client_mock.go new file mode 100644 index 00000000000..02b061aab16 --- /dev/null +++ b/erigon-lib/gointerfaces/remote/kv_state_changes_client_mock.go @@ -0,0 +1,309 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/ledgerwatch/erigon-lib/gointerfaces/remote (interfaces: KV_StateChangesClient) +// +// Generated by this command: +// +// mockgen -typed=true -destination=./kv_state_changes_client_mock.go -package=remote . KV_StateChangesClient +// + +// Package remote is a generated GoMock package. +package remote + +import ( + context "context" + reflect "reflect" + + gomock "go.uber.org/mock/gomock" + metadata "google.golang.org/grpc/metadata" +) + +// MockKV_StateChangesClient is a mock of KV_StateChangesClient interface. +type MockKV_StateChangesClient struct { + ctrl *gomock.Controller + recorder *MockKV_StateChangesClientMockRecorder +} + +// MockKV_StateChangesClientMockRecorder is the mock recorder for MockKV_StateChangesClient. +type MockKV_StateChangesClientMockRecorder struct { + mock *MockKV_StateChangesClient +} + +// NewMockKV_StateChangesClient creates a new mock instance. +func NewMockKV_StateChangesClient(ctrl *gomock.Controller) *MockKV_StateChangesClient { + mock := &MockKV_StateChangesClient{ctrl: ctrl} + mock.recorder = &MockKV_StateChangesClientMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockKV_StateChangesClient) EXPECT() *MockKV_StateChangesClientMockRecorder { + return m.recorder +} + +// CloseSend mocks base method. +func (m *MockKV_StateChangesClient) CloseSend() error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "CloseSend") + ret0, _ := ret[0].(error) + return ret0 +} + +// CloseSend indicates an expected call of CloseSend. +func (mr *MockKV_StateChangesClientMockRecorder) CloseSend() *MockKV_StateChangesClientCloseSendCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CloseSend", reflect.TypeOf((*MockKV_StateChangesClient)(nil).CloseSend)) + return &MockKV_StateChangesClientCloseSendCall{Call: call} +} + +// MockKV_StateChangesClientCloseSendCall wrap *gomock.Call +type MockKV_StateChangesClientCloseSendCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockKV_StateChangesClientCloseSendCall) Return(arg0 error) *MockKV_StateChangesClientCloseSendCall { + c.Call = c.Call.Return(arg0) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockKV_StateChangesClientCloseSendCall) Do(f func() error) *MockKV_StateChangesClientCloseSendCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockKV_StateChangesClientCloseSendCall) DoAndReturn(f func() error) *MockKV_StateChangesClientCloseSendCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Context mocks base method. +func (m *MockKV_StateChangesClient) Context() context.Context { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Context") + ret0, _ := ret[0].(context.Context) + return ret0 +} + +// Context indicates an expected call of Context. +func (mr *MockKV_StateChangesClientMockRecorder) Context() *MockKV_StateChangesClientContextCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Context", reflect.TypeOf((*MockKV_StateChangesClient)(nil).Context)) + return &MockKV_StateChangesClientContextCall{Call: call} +} + +// MockKV_StateChangesClientContextCall wrap *gomock.Call +type MockKV_StateChangesClientContextCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockKV_StateChangesClientContextCall) Return(arg0 context.Context) *MockKV_StateChangesClientContextCall { + c.Call = c.Call.Return(arg0) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockKV_StateChangesClientContextCall) Do(f func() context.Context) *MockKV_StateChangesClientContextCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockKV_StateChangesClientContextCall) DoAndReturn(f func() context.Context) *MockKV_StateChangesClientContextCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Header mocks base method. +func (m *MockKV_StateChangesClient) Header() (metadata.MD, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Header") + ret0, _ := ret[0].(metadata.MD) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Header indicates an expected call of Header. +func (mr *MockKV_StateChangesClientMockRecorder) Header() *MockKV_StateChangesClientHeaderCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Header", reflect.TypeOf((*MockKV_StateChangesClient)(nil).Header)) + return &MockKV_StateChangesClientHeaderCall{Call: call} +} + +// MockKV_StateChangesClientHeaderCall wrap *gomock.Call +type MockKV_StateChangesClientHeaderCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockKV_StateChangesClientHeaderCall) Return(arg0 metadata.MD, arg1 error) *MockKV_StateChangesClientHeaderCall { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockKV_StateChangesClientHeaderCall) Do(f func() (metadata.MD, error)) *MockKV_StateChangesClientHeaderCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockKV_StateChangesClientHeaderCall) DoAndReturn(f func() (metadata.MD, error)) *MockKV_StateChangesClientHeaderCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Recv mocks base method. +func (m *MockKV_StateChangesClient) Recv() (*StateChangeBatch, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Recv") + ret0, _ := ret[0].(*StateChangeBatch) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Recv indicates an expected call of Recv. +func (mr *MockKV_StateChangesClientMockRecorder) Recv() *MockKV_StateChangesClientRecvCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Recv", reflect.TypeOf((*MockKV_StateChangesClient)(nil).Recv)) + return &MockKV_StateChangesClientRecvCall{Call: call} +} + +// MockKV_StateChangesClientRecvCall wrap *gomock.Call +type MockKV_StateChangesClientRecvCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockKV_StateChangesClientRecvCall) Return(arg0 *StateChangeBatch, arg1 error) *MockKV_StateChangesClientRecvCall { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockKV_StateChangesClientRecvCall) Do(f func() (*StateChangeBatch, error)) *MockKV_StateChangesClientRecvCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockKV_StateChangesClientRecvCall) DoAndReturn(f func() (*StateChangeBatch, error)) *MockKV_StateChangesClientRecvCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// RecvMsg mocks base method. +func (m *MockKV_StateChangesClient) RecvMsg(arg0 any) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "RecvMsg", arg0) + ret0, _ := ret[0].(error) + return ret0 +} + +// RecvMsg indicates an expected call of RecvMsg. +func (mr *MockKV_StateChangesClientMockRecorder) RecvMsg(arg0 any) *MockKV_StateChangesClientRecvMsgCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RecvMsg", reflect.TypeOf((*MockKV_StateChangesClient)(nil).RecvMsg), arg0) + return &MockKV_StateChangesClientRecvMsgCall{Call: call} +} + +// MockKV_StateChangesClientRecvMsgCall wrap *gomock.Call +type MockKV_StateChangesClientRecvMsgCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockKV_StateChangesClientRecvMsgCall) Return(arg0 error) *MockKV_StateChangesClientRecvMsgCall { + c.Call = c.Call.Return(arg0) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockKV_StateChangesClientRecvMsgCall) Do(f func(any) error) *MockKV_StateChangesClientRecvMsgCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockKV_StateChangesClientRecvMsgCall) DoAndReturn(f func(any) error) *MockKV_StateChangesClientRecvMsgCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// SendMsg mocks base method. +func (m *MockKV_StateChangesClient) SendMsg(arg0 any) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SendMsg", arg0) + ret0, _ := ret[0].(error) + return ret0 +} + +// SendMsg indicates an expected call of SendMsg. +func (mr *MockKV_StateChangesClientMockRecorder) SendMsg(arg0 any) *MockKV_StateChangesClientSendMsgCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendMsg", reflect.TypeOf((*MockKV_StateChangesClient)(nil).SendMsg), arg0) + return &MockKV_StateChangesClientSendMsgCall{Call: call} +} + +// MockKV_StateChangesClientSendMsgCall wrap *gomock.Call +type MockKV_StateChangesClientSendMsgCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockKV_StateChangesClientSendMsgCall) Return(arg0 error) *MockKV_StateChangesClientSendMsgCall { + c.Call = c.Call.Return(arg0) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockKV_StateChangesClientSendMsgCall) Do(f func(any) error) *MockKV_StateChangesClientSendMsgCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockKV_StateChangesClientSendMsgCall) DoAndReturn(f func(any) error) *MockKV_StateChangesClientSendMsgCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Trailer mocks base method. +func (m *MockKV_StateChangesClient) Trailer() metadata.MD { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Trailer") + ret0, _ := ret[0].(metadata.MD) + return ret0 +} + +// Trailer indicates an expected call of Trailer. +func (mr *MockKV_StateChangesClientMockRecorder) Trailer() *MockKV_StateChangesClientTrailerCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Trailer", reflect.TypeOf((*MockKV_StateChangesClient)(nil).Trailer)) + return &MockKV_StateChangesClientTrailerCall{Call: call} +} + +// MockKV_StateChangesClientTrailerCall wrap *gomock.Call +type MockKV_StateChangesClientTrailerCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockKV_StateChangesClientTrailerCall) Return(arg0 metadata.MD) *MockKV_StateChangesClientTrailerCall { + c.Call = c.Call.Return(arg0) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockKV_StateChangesClientTrailerCall) Do(f func() metadata.MD) *MockKV_StateChangesClientTrailerCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockKV_StateChangesClientTrailerCall) DoAndReturn(f func() metadata.MD) *MockKV_StateChangesClientTrailerCall { + c.Call = c.Call.DoAndReturn(f) + return c +} diff --git a/erigon-lib/gointerfaces/remote/mockgen.go b/erigon-lib/gointerfaces/remote/mockgen.go new file mode 100644 index 00000000000..b56c4e01b44 --- /dev/null +++ b/erigon-lib/gointerfaces/remote/mockgen.go @@ -0,0 +1,4 @@ +package remote + +//go:generate mockgen -typed=true -destination=./kv_client_mock.go -package=remote . KVClient +//go:generate mockgen -typed=true -destination=./kv_state_changes_client_mock.go -package=remote . KV_StateChangesClient diff --git a/erigon-lib/gointerfaces/remote/mocks.go b/erigon-lib/gointerfaces/remote/mocks.go deleted file mode 100644 index 8300eb434d2..00000000000 --- a/erigon-lib/gointerfaces/remote/mocks.go +++ /dev/null @@ -1,947 +0,0 @@ -// Code generated by moq; DO NOT EDIT. -// github.com/matryer/moq - -package remote - -import ( - context "context" - types "github.com/ledgerwatch/erigon-lib/gointerfaces/types" - grpc "google.golang.org/grpc" - "google.golang.org/grpc/metadata" - emptypb "google.golang.org/protobuf/types/known/emptypb" - sync "sync" -) - -// Ensure, that KVClientMock does implement KVClient. -// If this is not the case, regenerate this file with moq. -var _ KVClient = &KVClientMock{} - -// KVClientMock is a mock implementation of KVClient. -// -// func TestSomethingThatUsesKVClient(t *testing.T) { -// -// // make and configure a mocked KVClient -// mockedKVClient := &KVClientMock{ -// DomainGetFunc: func(ctx context.Context, in *DomainGetReq, opts ...grpc.CallOption) (*DomainGetReply, error) { -// panic("mock out the DomainGet method") -// }, -// DomainRangeFunc: func(ctx context.Context, in *DomainRangeReq, opts ...grpc.CallOption) (*Pairs, error) { -// panic("mock out the DomainRange method") -// }, -// HistoryGetFunc: func(ctx context.Context, in *HistoryGetReq, opts ...grpc.CallOption) (*HistoryGetReply, error) { -// panic("mock out the HistoryGet method") -// }, -// HistoryRangeFunc: func(ctx context.Context, in *HistoryRangeReq, opts ...grpc.CallOption) (*Pairs, error) { -// panic("mock out the HistoryRange method") -// }, -// IndexRangeFunc: func(ctx context.Context, in *IndexRangeReq, opts ...grpc.CallOption) (*IndexRangeReply, error) { -// panic("mock out the IndexRange method") -// }, -// RangeFunc: func(ctx context.Context, in *RangeReq, opts ...grpc.CallOption) (*Pairs, error) { -// panic("mock out the Range method") -// }, -// SnapshotsFunc: func(ctx context.Context, in *SnapshotsRequest, opts ...grpc.CallOption) (*SnapshotsReply, error) { -// panic("mock out the Snapshots method") -// }, -// StateChangesFunc: func(ctx context.Context, in *StateChangeRequest, opts ...grpc.CallOption) (KV_StateChangesClient, error) { -// panic("mock out the StateChanges method") -// }, -// TxFunc: func(ctx context.Context, opts ...grpc.CallOption) (KV_TxClient, error) { -// panic("mock out the Tx method") -// }, -// VersionFunc: func(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*types.VersionReply, error) { -// panic("mock out the Version method") -// }, -// } -// -// // use mockedKVClient in code that requires KVClient -// // and then make assertions. -// -// } -type KVClientMock struct { - // DomainGetFunc mocks the DomainGet method. - DomainGetFunc func(ctx context.Context, in *DomainGetReq, opts ...grpc.CallOption) (*DomainGetReply, error) - - // DomainRangeFunc mocks the DomainRange method. - DomainRangeFunc func(ctx context.Context, in *DomainRangeReq, opts ...grpc.CallOption) (*Pairs, error) - - // HistoryGetFunc mocks the HistoryGet method. - HistoryGetFunc func(ctx context.Context, in *HistoryGetReq, opts ...grpc.CallOption) (*HistoryGetReply, error) - - // HistoryRangeFunc mocks the HistoryRange method. - HistoryRangeFunc func(ctx context.Context, in *HistoryRangeReq, opts ...grpc.CallOption) (*Pairs, error) - - // IndexRangeFunc mocks the IndexRange method. - IndexRangeFunc func(ctx context.Context, in *IndexRangeReq, opts ...grpc.CallOption) (*IndexRangeReply, error) - - // RangeFunc mocks the Range method. - RangeFunc func(ctx context.Context, in *RangeReq, opts ...grpc.CallOption) (*Pairs, error) - - // SnapshotsFunc mocks the Snapshots method. - SnapshotsFunc func(ctx context.Context, in *SnapshotsRequest, opts ...grpc.CallOption) (*SnapshotsReply, error) - - // StateChangesFunc mocks the StateChanges method. - StateChangesFunc func(ctx context.Context, in *StateChangeRequest, opts ...grpc.CallOption) (KV_StateChangesClient, error) - - // TxFunc mocks the Tx method. - TxFunc func(ctx context.Context, opts ...grpc.CallOption) (KV_TxClient, error) - - // VersionFunc mocks the Version method. - VersionFunc func(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*types.VersionReply, error) - - // calls tracks calls to the methods. - calls struct { - // DomainGet holds details about calls to the DomainGet method. - DomainGet []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // In is the in argument value. - In *DomainGetReq - // Opts is the opts argument value. - Opts []grpc.CallOption - } - // DomainRange holds details about calls to the DomainRange method. - DomainRange []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // In is the in argument value. - In *DomainRangeReq - // Opts is the opts argument value. - Opts []grpc.CallOption - } - // HistoryGet holds details about calls to the HistoryGet method. - HistoryGet []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // In is the in argument value. - In *HistoryGetReq - // Opts is the opts argument value. - Opts []grpc.CallOption - } - // HistoryRange holds details about calls to the HistoryRange method. - HistoryRange []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // In is the in argument value. - In *HistoryRangeReq - // Opts is the opts argument value. - Opts []grpc.CallOption - } - // IndexRange holds details about calls to the IndexRange method. - IndexRange []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // In is the in argument value. - In *IndexRangeReq - // Opts is the opts argument value. - Opts []grpc.CallOption - } - // Range holds details about calls to the Range method. - Range []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // In is the in argument value. - In *RangeReq - // Opts is the opts argument value. - Opts []grpc.CallOption - } - // Snapshots holds details about calls to the Snapshots method. - Snapshots []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // In is the in argument value. - In *SnapshotsRequest - // Opts is the opts argument value. - Opts []grpc.CallOption - } - // StateChanges holds details about calls to the StateChanges method. - StateChanges []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // In is the in argument value. - In *StateChangeRequest - // Opts is the opts argument value. - Opts []grpc.CallOption - } - // Tx holds details about calls to the Tx method. - Tx []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // Opts is the opts argument value. - Opts []grpc.CallOption - } - // Version holds details about calls to the Version method. - Version []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // In is the in argument value. - In *emptypb.Empty - // Opts is the opts argument value. - Opts []grpc.CallOption - } - } - lockDomainGet sync.RWMutex - lockDomainRange sync.RWMutex - lockHistoryGet sync.RWMutex - lockHistoryRange sync.RWMutex - lockIndexRange sync.RWMutex - lockRange sync.RWMutex - lockSnapshots sync.RWMutex - lockStateChanges sync.RWMutex - lockTx sync.RWMutex - lockVersion sync.RWMutex -} - -// DomainGet calls DomainGetFunc. -func (mock *KVClientMock) DomainGet(ctx context.Context, in *DomainGetReq, opts ...grpc.CallOption) (*DomainGetReply, error) { - callInfo := struct { - Ctx context.Context - In *DomainGetReq - Opts []grpc.CallOption - }{ - Ctx: ctx, - In: in, - Opts: opts, - } - mock.lockDomainGet.Lock() - mock.calls.DomainGet = append(mock.calls.DomainGet, callInfo) - mock.lockDomainGet.Unlock() - if mock.DomainGetFunc == nil { - var ( - domainGetReplyOut *DomainGetReply - errOut error - ) - return domainGetReplyOut, errOut - } - return mock.DomainGetFunc(ctx, in, opts...) -} - -// DomainGetCalls gets all the calls that were made to DomainGet. -// Check the length with: -// -// len(mockedKVClient.DomainGetCalls()) -func (mock *KVClientMock) DomainGetCalls() []struct { - Ctx context.Context - In *DomainGetReq - Opts []grpc.CallOption -} { - var calls []struct { - Ctx context.Context - In *DomainGetReq - Opts []grpc.CallOption - } - mock.lockDomainGet.RLock() - calls = mock.calls.DomainGet - mock.lockDomainGet.RUnlock() - return calls -} - -// DomainRange calls DomainRangeFunc. -func (mock *KVClientMock) DomainRange(ctx context.Context, in *DomainRangeReq, opts ...grpc.CallOption) (*Pairs, error) { - callInfo := struct { - Ctx context.Context - In *DomainRangeReq - Opts []grpc.CallOption - }{ - Ctx: ctx, - In: in, - Opts: opts, - } - mock.lockDomainRange.Lock() - mock.calls.DomainRange = append(mock.calls.DomainRange, callInfo) - mock.lockDomainRange.Unlock() - if mock.DomainRangeFunc == nil { - var ( - pairsOut *Pairs - errOut error - ) - return pairsOut, errOut - } - return mock.DomainRangeFunc(ctx, in, opts...) -} - -// DomainRangeCalls gets all the calls that were made to DomainRange. -// Check the length with: -// -// len(mockedKVClient.DomainRangeCalls()) -func (mock *KVClientMock) DomainRangeCalls() []struct { - Ctx context.Context - In *DomainRangeReq - Opts []grpc.CallOption -} { - var calls []struct { - Ctx context.Context - In *DomainRangeReq - Opts []grpc.CallOption - } - mock.lockDomainRange.RLock() - calls = mock.calls.DomainRange - mock.lockDomainRange.RUnlock() - return calls -} - -// HistoryGet calls HistoryGetFunc. -func (mock *KVClientMock) HistoryGet(ctx context.Context, in *HistoryGetReq, opts ...grpc.CallOption) (*HistoryGetReply, error) { - callInfo := struct { - Ctx context.Context - In *HistoryGetReq - Opts []grpc.CallOption - }{ - Ctx: ctx, - In: in, - Opts: opts, - } - mock.lockHistoryGet.Lock() - mock.calls.HistoryGet = append(mock.calls.HistoryGet, callInfo) - mock.lockHistoryGet.Unlock() - if mock.HistoryGetFunc == nil { - var ( - historyGetReplyOut *HistoryGetReply - errOut error - ) - return historyGetReplyOut, errOut - } - return mock.HistoryGetFunc(ctx, in, opts...) -} - -// HistoryGetCalls gets all the calls that were made to HistoryGet. -// Check the length with: -// -// len(mockedKVClient.HistoryGetCalls()) -func (mock *KVClientMock) HistoryGetCalls() []struct { - Ctx context.Context - In *HistoryGetReq - Opts []grpc.CallOption -} { - var calls []struct { - Ctx context.Context - In *HistoryGetReq - Opts []grpc.CallOption - } - mock.lockHistoryGet.RLock() - calls = mock.calls.HistoryGet - mock.lockHistoryGet.RUnlock() - return calls -} - -// HistoryRange calls HistoryRangeFunc. -func (mock *KVClientMock) HistoryRange(ctx context.Context, in *HistoryRangeReq, opts ...grpc.CallOption) (*Pairs, error) { - callInfo := struct { - Ctx context.Context - In *HistoryRangeReq - Opts []grpc.CallOption - }{ - Ctx: ctx, - In: in, - Opts: opts, - } - mock.lockHistoryRange.Lock() - mock.calls.HistoryRange = append(mock.calls.HistoryRange, callInfo) - mock.lockHistoryRange.Unlock() - if mock.HistoryRangeFunc == nil { - var ( - pairsOut *Pairs - errOut error - ) - return pairsOut, errOut - } - return mock.HistoryRangeFunc(ctx, in, opts...) -} - -// HistoryRangeCalls gets all the calls that were made to HistoryRange. -// Check the length with: -// -// len(mockedKVClient.HistoryRangeCalls()) -func (mock *KVClientMock) HistoryRangeCalls() []struct { - Ctx context.Context - In *HistoryRangeReq - Opts []grpc.CallOption -} { - var calls []struct { - Ctx context.Context - In *HistoryRangeReq - Opts []grpc.CallOption - } - mock.lockHistoryRange.RLock() - calls = mock.calls.HistoryRange - mock.lockHistoryRange.RUnlock() - return calls -} - -// IndexRange calls IndexRangeFunc. -func (mock *KVClientMock) IndexRange(ctx context.Context, in *IndexRangeReq, opts ...grpc.CallOption) (*IndexRangeReply, error) { - callInfo := struct { - Ctx context.Context - In *IndexRangeReq - Opts []grpc.CallOption - }{ - Ctx: ctx, - In: in, - Opts: opts, - } - mock.lockIndexRange.Lock() - mock.calls.IndexRange = append(mock.calls.IndexRange, callInfo) - mock.lockIndexRange.Unlock() - if mock.IndexRangeFunc == nil { - var ( - indexRangeReplyOut *IndexRangeReply - errOut error - ) - return indexRangeReplyOut, errOut - } - return mock.IndexRangeFunc(ctx, in, opts...) -} - -// IndexRangeCalls gets all the calls that were made to IndexRange. -// Check the length with: -// -// len(mockedKVClient.IndexRangeCalls()) -func (mock *KVClientMock) IndexRangeCalls() []struct { - Ctx context.Context - In *IndexRangeReq - Opts []grpc.CallOption -} { - var calls []struct { - Ctx context.Context - In *IndexRangeReq - Opts []grpc.CallOption - } - mock.lockIndexRange.RLock() - calls = mock.calls.IndexRange - mock.lockIndexRange.RUnlock() - return calls -} - -// Range calls RangeFunc. -func (mock *KVClientMock) Range(ctx context.Context, in *RangeReq, opts ...grpc.CallOption) (*Pairs, error) { - callInfo := struct { - Ctx context.Context - In *RangeReq - Opts []grpc.CallOption - }{ - Ctx: ctx, - In: in, - Opts: opts, - } - mock.lockRange.Lock() - mock.calls.Range = append(mock.calls.Range, callInfo) - mock.lockRange.Unlock() - if mock.RangeFunc == nil { - var ( - pairsOut *Pairs - errOut error - ) - return pairsOut, errOut - } - return mock.RangeFunc(ctx, in, opts...) -} - -// RangeCalls gets all the calls that were made to Range. -// Check the length with: -// -// len(mockedKVClient.RangeCalls()) -func (mock *KVClientMock) RangeCalls() []struct { - Ctx context.Context - In *RangeReq - Opts []grpc.CallOption -} { - var calls []struct { - Ctx context.Context - In *RangeReq - Opts []grpc.CallOption - } - mock.lockRange.RLock() - calls = mock.calls.Range - mock.lockRange.RUnlock() - return calls -} - -// Snapshots calls SnapshotsFunc. -func (mock *KVClientMock) Snapshots(ctx context.Context, in *SnapshotsRequest, opts ...grpc.CallOption) (*SnapshotsReply, error) { - callInfo := struct { - Ctx context.Context - In *SnapshotsRequest - Opts []grpc.CallOption - }{ - Ctx: ctx, - In: in, - Opts: opts, - } - mock.lockSnapshots.Lock() - mock.calls.Snapshots = append(mock.calls.Snapshots, callInfo) - mock.lockSnapshots.Unlock() - if mock.SnapshotsFunc == nil { - var ( - snapshotsReplyOut *SnapshotsReply - errOut error - ) - return snapshotsReplyOut, errOut - } - return mock.SnapshotsFunc(ctx, in, opts...) -} - -// SnapshotsCalls gets all the calls that were made to Snapshots. -// Check the length with: -// -// len(mockedKVClient.SnapshotsCalls()) -func (mock *KVClientMock) SnapshotsCalls() []struct { - Ctx context.Context - In *SnapshotsRequest - Opts []grpc.CallOption -} { - var calls []struct { - Ctx context.Context - In *SnapshotsRequest - Opts []grpc.CallOption - } - mock.lockSnapshots.RLock() - calls = mock.calls.Snapshots - mock.lockSnapshots.RUnlock() - return calls -} - -// StateChanges calls StateChangesFunc. -func (mock *KVClientMock) StateChanges(ctx context.Context, in *StateChangeRequest, opts ...grpc.CallOption) (KV_StateChangesClient, error) { - callInfo := struct { - Ctx context.Context - In *StateChangeRequest - Opts []grpc.CallOption - }{ - Ctx: ctx, - In: in, - Opts: opts, - } - mock.lockStateChanges.Lock() - mock.calls.StateChanges = append(mock.calls.StateChanges, callInfo) - mock.lockStateChanges.Unlock() - if mock.StateChangesFunc == nil { - var ( - kV_StateChangesClientOut KV_StateChangesClient - errOut error - ) - return kV_StateChangesClientOut, errOut - } - return mock.StateChangesFunc(ctx, in, opts...) -} - -// StateChangesCalls gets all the calls that were made to StateChanges. -// Check the length with: -// -// len(mockedKVClient.StateChangesCalls()) -func (mock *KVClientMock) StateChangesCalls() []struct { - Ctx context.Context - In *StateChangeRequest - Opts []grpc.CallOption -} { - var calls []struct { - Ctx context.Context - In *StateChangeRequest - Opts []grpc.CallOption - } - mock.lockStateChanges.RLock() - calls = mock.calls.StateChanges - mock.lockStateChanges.RUnlock() - return calls -} - -// Tx calls TxFunc. -func (mock *KVClientMock) Tx(ctx context.Context, opts ...grpc.CallOption) (KV_TxClient, error) { - callInfo := struct { - Ctx context.Context - Opts []grpc.CallOption - }{ - Ctx: ctx, - Opts: opts, - } - mock.lockTx.Lock() - mock.calls.Tx = append(mock.calls.Tx, callInfo) - mock.lockTx.Unlock() - if mock.TxFunc == nil { - var ( - kV_TxClientOut KV_TxClient - errOut error - ) - return kV_TxClientOut, errOut - } - return mock.TxFunc(ctx, opts...) -} - -// TxCalls gets all the calls that were made to Tx. -// Check the length with: -// -// len(mockedKVClient.TxCalls()) -func (mock *KVClientMock) TxCalls() []struct { - Ctx context.Context - Opts []grpc.CallOption -} { - var calls []struct { - Ctx context.Context - Opts []grpc.CallOption - } - mock.lockTx.RLock() - calls = mock.calls.Tx - mock.lockTx.RUnlock() - return calls -} - -// Version calls VersionFunc. -func (mock *KVClientMock) Version(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*types.VersionReply, error) { - callInfo := struct { - Ctx context.Context - In *emptypb.Empty - Opts []grpc.CallOption - }{ - Ctx: ctx, - In: in, - Opts: opts, - } - mock.lockVersion.Lock() - mock.calls.Version = append(mock.calls.Version, callInfo) - mock.lockVersion.Unlock() - if mock.VersionFunc == nil { - var ( - versionReplyOut *types.VersionReply - errOut error - ) - return versionReplyOut, errOut - } - return mock.VersionFunc(ctx, in, opts...) -} - -// VersionCalls gets all the calls that were made to Version. -// Check the length with: -// -// len(mockedKVClient.VersionCalls()) -func (mock *KVClientMock) VersionCalls() []struct { - Ctx context.Context - In *emptypb.Empty - Opts []grpc.CallOption -} { - var calls []struct { - Ctx context.Context - In *emptypb.Empty - Opts []grpc.CallOption - } - mock.lockVersion.RLock() - calls = mock.calls.Version - mock.lockVersion.RUnlock() - return calls -} - -// Ensure, that KV_StateChangesClientMock does implement KV_StateChangesClient. -// If this is not the case, regenerate this file with moq. -var _ KV_StateChangesClient = &KV_StateChangesClientMock{} - -// KV_StateChangesClientMock is a mock implementation of KV_StateChangesClient. -// -// func TestSomethingThatUsesKV_StateChangesClient(t *testing.T) { -// -// // make and configure a mocked KV_StateChangesClient -// mockedKV_StateChangesClient := &KV_StateChangesClientMock{ -// CloseSendFunc: func() error { -// panic("mock out the CloseSend method") -// }, -// ContextFunc: func() context.Context { -// panic("mock out the Context method") -// }, -// HeaderFunc: func() (metadata.MD, error) { -// panic("mock out the Header method") -// }, -// RecvFunc: func() (*StateChangeBatch, error) { -// panic("mock out the Recv method") -// }, -// RecvMsgFunc: func(m any) error { -// panic("mock out the RecvMsg method") -// }, -// SendMsgFunc: func(m any) error { -// panic("mock out the SendMsg method") -// }, -// TrailerFunc: func() metadata.MD { -// panic("mock out the Trailer method") -// }, -// } -// -// // use mockedKV_StateChangesClient in code that requires KV_StateChangesClient -// // and then make assertions. -// -// } -type KV_StateChangesClientMock struct { - // CloseSendFunc mocks the CloseSend method. - CloseSendFunc func() error - - // ContextFunc mocks the Context method. - ContextFunc func() context.Context - - // HeaderFunc mocks the Header method. - HeaderFunc func() (metadata.MD, error) - - // RecvFunc mocks the Recv method. - RecvFunc func() (*StateChangeBatch, error) - - // RecvMsgFunc mocks the RecvMsg method. - RecvMsgFunc func(m any) error - - // SendMsgFunc mocks the SendMsg method. - SendMsgFunc func(m any) error - - // TrailerFunc mocks the Trailer method. - TrailerFunc func() metadata.MD - - // calls tracks calls to the methods. - calls struct { - // CloseSend holds details about calls to the CloseSend method. - CloseSend []struct { - } - // Context holds details about calls to the Context method. - Context []struct { - } - // Header holds details about calls to the Header method. - Header []struct { - } - // Recv holds details about calls to the Recv method. - Recv []struct { - } - // RecvMsg holds details about calls to the RecvMsg method. - RecvMsg []struct { - // M is the m argument value. - M any - } - // SendMsg holds details about calls to the SendMsg method. - SendMsg []struct { - // M is the m argument value. - M any - } - // Trailer holds details about calls to the Trailer method. - Trailer []struct { - } - } - lockCloseSend sync.RWMutex - lockContext sync.RWMutex - lockHeader sync.RWMutex - lockRecv sync.RWMutex - lockRecvMsg sync.RWMutex - lockSendMsg sync.RWMutex - lockTrailer sync.RWMutex -} - -// CloseSend calls CloseSendFunc. -func (mock *KV_StateChangesClientMock) CloseSend() error { - callInfo := struct { - }{} - mock.lockCloseSend.Lock() - mock.calls.CloseSend = append(mock.calls.CloseSend, callInfo) - mock.lockCloseSend.Unlock() - if mock.CloseSendFunc == nil { - var ( - errOut error - ) - return errOut - } - return mock.CloseSendFunc() -} - -// CloseSendCalls gets all the calls that were made to CloseSend. -// Check the length with: -// -// len(mockedKV_StateChangesClient.CloseSendCalls()) -func (mock *KV_StateChangesClientMock) CloseSendCalls() []struct { -} { - var calls []struct { - } - mock.lockCloseSend.RLock() - calls = mock.calls.CloseSend - mock.lockCloseSend.RUnlock() - return calls -} - -// Context calls ContextFunc. -func (mock *KV_StateChangesClientMock) Context() context.Context { - callInfo := struct { - }{} - mock.lockContext.Lock() - mock.calls.Context = append(mock.calls.Context, callInfo) - mock.lockContext.Unlock() - if mock.ContextFunc == nil { - var ( - contextOut context.Context - ) - return contextOut - } - return mock.ContextFunc() -} - -// ContextCalls gets all the calls that were made to Context. -// Check the length with: -// -// len(mockedKV_StateChangesClient.ContextCalls()) -func (mock *KV_StateChangesClientMock) ContextCalls() []struct { -} { - var calls []struct { - } - mock.lockContext.RLock() - calls = mock.calls.Context - mock.lockContext.RUnlock() - return calls -} - -// Header calls HeaderFunc. -func (mock *KV_StateChangesClientMock) Header() (metadata.MD, error) { - callInfo := struct { - }{} - mock.lockHeader.Lock() - mock.calls.Header = append(mock.calls.Header, callInfo) - mock.lockHeader.Unlock() - if mock.HeaderFunc == nil { - var ( - mDOut metadata.MD - errOut error - ) - return mDOut, errOut - } - return mock.HeaderFunc() -} - -// HeaderCalls gets all the calls that were made to Header. -// Check the length with: -// -// len(mockedKV_StateChangesClient.HeaderCalls()) -func (mock *KV_StateChangesClientMock) HeaderCalls() []struct { -} { - var calls []struct { - } - mock.lockHeader.RLock() - calls = mock.calls.Header - mock.lockHeader.RUnlock() - return calls -} - -// Recv calls RecvFunc. -func (mock *KV_StateChangesClientMock) Recv() (*StateChangeBatch, error) { - callInfo := struct { - }{} - mock.lockRecv.Lock() - mock.calls.Recv = append(mock.calls.Recv, callInfo) - mock.lockRecv.Unlock() - if mock.RecvFunc == nil { - var ( - stateChangeBatchOut *StateChangeBatch - errOut error - ) - return stateChangeBatchOut, errOut - } - return mock.RecvFunc() -} - -// RecvCalls gets all the calls that were made to Recv. -// Check the length with: -// -// len(mockedKV_StateChangesClient.RecvCalls()) -func (mock *KV_StateChangesClientMock) RecvCalls() []struct { -} { - var calls []struct { - } - mock.lockRecv.RLock() - calls = mock.calls.Recv - mock.lockRecv.RUnlock() - return calls -} - -// RecvMsg calls RecvMsgFunc. -func (mock *KV_StateChangesClientMock) RecvMsg(m any) error { - callInfo := struct { - M any - }{ - M: m, - } - mock.lockRecvMsg.Lock() - mock.calls.RecvMsg = append(mock.calls.RecvMsg, callInfo) - mock.lockRecvMsg.Unlock() - if mock.RecvMsgFunc == nil { - var ( - errOut error - ) - return errOut - } - return mock.RecvMsgFunc(m) -} - -// RecvMsgCalls gets all the calls that were made to RecvMsg. -// Check the length with: -// -// len(mockedKV_StateChangesClient.RecvMsgCalls()) -func (mock *KV_StateChangesClientMock) RecvMsgCalls() []struct { - M any -} { - var calls []struct { - M any - } - mock.lockRecvMsg.RLock() - calls = mock.calls.RecvMsg - mock.lockRecvMsg.RUnlock() - return calls -} - -// SendMsg calls SendMsgFunc. -func (mock *KV_StateChangesClientMock) SendMsg(m any) error { - callInfo := struct { - M any - }{ - M: m, - } - mock.lockSendMsg.Lock() - mock.calls.SendMsg = append(mock.calls.SendMsg, callInfo) - mock.lockSendMsg.Unlock() - if mock.SendMsgFunc == nil { - var ( - errOut error - ) - return errOut - } - return mock.SendMsgFunc(m) -} - -// SendMsgCalls gets all the calls that were made to SendMsg. -// Check the length with: -// -// len(mockedKV_StateChangesClient.SendMsgCalls()) -func (mock *KV_StateChangesClientMock) SendMsgCalls() []struct { - M any -} { - var calls []struct { - M any - } - mock.lockSendMsg.RLock() - calls = mock.calls.SendMsg - mock.lockSendMsg.RUnlock() - return calls -} - -// Trailer calls TrailerFunc. -func (mock *KV_StateChangesClientMock) Trailer() metadata.MD { - callInfo := struct { - }{} - mock.lockTrailer.Lock() - mock.calls.Trailer = append(mock.calls.Trailer, callInfo) - mock.lockTrailer.Unlock() - if mock.TrailerFunc == nil { - var ( - mDOut metadata.MD - ) - return mDOut - } - return mock.TrailerFunc() -} - -// TrailerCalls gets all the calls that were made to Trailer. -// Check the length with: -// -// len(mockedKV_StateChangesClient.TrailerCalls()) -func (mock *KV_StateChangesClientMock) TrailerCalls() []struct { -} { - var calls []struct { - } - mock.lockTrailer.RLock() - calls = mock.calls.Trailer - mock.lockTrailer.RUnlock() - return calls -} diff --git a/erigon-lib/gointerfaces/sentry/mockgen.go b/erigon-lib/gointerfaces/sentry/mockgen.go new file mode 100644 index 00000000000..cf7315d280e --- /dev/null +++ b/erigon-lib/gointerfaces/sentry/mockgen.go @@ -0,0 +1,4 @@ +package sentry + +//go:generate mockgen -typed=true -destination=./sentry_client_mock.go -package=sentry . SentryClient +//go:generate mockgen -typed=true -destination=./sentry_server_mock.go -package=sentry . SentryServer diff --git a/erigon-lib/gointerfaces/sentry/mocks.go b/erigon-lib/gointerfaces/sentry/mocks.go deleted file mode 100644 index 37a446b4470..00000000000 --- a/erigon-lib/gointerfaces/sentry/mocks.go +++ /dev/null @@ -1,1801 +0,0 @@ -// Code generated by moq; DO NOT EDIT. -// github.com/matryer/moq - -package sentry - -import ( - context "context" - types "github.com/ledgerwatch/erigon-lib/gointerfaces/types" - grpc "google.golang.org/grpc" - emptypb "google.golang.org/protobuf/types/known/emptypb" - sync "sync" -) - -// Ensure, that SentryServerMock does implement SentryServer. -// If this is not the case, regenerate this file with moq. -var _ SentryServer = &SentryServerMock{} - -// SentryServerMock is a mock implementation of SentryServer. -// -// func TestSomethingThatUsesSentryServer(t *testing.T) { -// -// // make and configure a mocked SentryServer -// mockedSentryServer := &SentryServerMock{ -// AddPeerFunc: func(contextMoqParam context.Context, addPeerRequest *AddPeerRequest) (*AddPeerReply, error) { -// panic("mock out the AddPeer method") -// }, -// HandShakeFunc: func(contextMoqParam context.Context, empty *emptypb.Empty) (*HandShakeReply, error) { -// panic("mock out the HandShake method") -// }, -// MessagesFunc: func(messagesRequest *MessagesRequest, sentry_MessagesServer Sentry_MessagesServer) error { -// panic("mock out the Messages method") -// }, -// NodeInfoFunc: func(contextMoqParam context.Context, empty *emptypb.Empty) (*types.NodeInfoReply, error) { -// panic("mock out the NodeInfo method") -// }, -// PeerByIdFunc: func(contextMoqParam context.Context, peerByIdRequest *PeerByIdRequest) (*PeerByIdReply, error) { -// panic("mock out the PeerById method") -// }, -// PeerCountFunc: func(contextMoqParam context.Context, peerCountRequest *PeerCountRequest) (*PeerCountReply, error) { -// panic("mock out the PeerCount method") -// }, -// PeerEventsFunc: func(peerEventsRequest *PeerEventsRequest, sentry_PeerEventsServer Sentry_PeerEventsServer) error { -// panic("mock out the PeerEvents method") -// }, -// PeerMinBlockFunc: func(contextMoqParam context.Context, peerMinBlockRequest *PeerMinBlockRequest) (*emptypb.Empty, error) { -// panic("mock out the PeerMinBlock method") -// }, -// PeersFunc: func(contextMoqParam context.Context, empty *emptypb.Empty) (*PeersReply, error) { -// panic("mock out the Peers method") -// }, -// PenalizePeerFunc: func(contextMoqParam context.Context, penalizePeerRequest *PenalizePeerRequest) (*emptypb.Empty, error) { -// panic("mock out the PenalizePeer method") -// }, -// SendMessageByIdFunc: func(contextMoqParam context.Context, sendMessageByIdRequest *SendMessageByIdRequest) (*SentPeers, error) { -// panic("mock out the SendMessageById method") -// }, -// SendMessageByMinBlockFunc: func(contextMoqParam context.Context, sendMessageByMinBlockRequest *SendMessageByMinBlockRequest) (*SentPeers, error) { -// panic("mock out the SendMessageByMinBlock method") -// }, -// SendMessageToAllFunc: func(contextMoqParam context.Context, outboundMessageData *OutboundMessageData) (*SentPeers, error) { -// panic("mock out the SendMessageToAll method") -// }, -// SendMessageToRandomPeersFunc: func(contextMoqParam context.Context, sendMessageToRandomPeersRequest *SendMessageToRandomPeersRequest) (*SentPeers, error) { -// panic("mock out the SendMessageToRandomPeers method") -// }, -// SetStatusFunc: func(contextMoqParam context.Context, statusData *StatusData) (*SetStatusReply, error) { -// panic("mock out the SetStatus method") -// }, -// mustEmbedUnimplementedSentryServerFunc: func() { -// panic("mock out the mustEmbedUnimplementedSentryServer method") -// }, -// } -// -// // use mockedSentryServer in code that requires SentryServer -// // and then make assertions. -// -// } -type SentryServerMock struct { - // AddPeerFunc mocks the AddPeer method. - AddPeerFunc func(contextMoqParam context.Context, addPeerRequest *AddPeerRequest) (*AddPeerReply, error) - - // HandShakeFunc mocks the HandShake method. - HandShakeFunc func(contextMoqParam context.Context, empty *emptypb.Empty) (*HandShakeReply, error) - - // MessagesFunc mocks the Messages method. - MessagesFunc func(messagesRequest *MessagesRequest, sentry_MessagesServer Sentry_MessagesServer) error - - // NodeInfoFunc mocks the NodeInfo method. - NodeInfoFunc func(contextMoqParam context.Context, empty *emptypb.Empty) (*types.NodeInfoReply, error) - - // PeerByIdFunc mocks the PeerById method. - PeerByIdFunc func(contextMoqParam context.Context, peerByIdRequest *PeerByIdRequest) (*PeerByIdReply, error) - - // PeerCountFunc mocks the PeerCount method. - PeerCountFunc func(contextMoqParam context.Context, peerCountRequest *PeerCountRequest) (*PeerCountReply, error) - - // PeerEventsFunc mocks the PeerEvents method. - PeerEventsFunc func(peerEventsRequest *PeerEventsRequest, sentry_PeerEventsServer Sentry_PeerEventsServer) error - - // PeerMinBlockFunc mocks the PeerMinBlock method. - PeerMinBlockFunc func(contextMoqParam context.Context, peerMinBlockRequest *PeerMinBlockRequest) (*emptypb.Empty, error) - - // PeersFunc mocks the Peers method. - PeersFunc func(contextMoqParam context.Context, empty *emptypb.Empty) (*PeersReply, error) - - // PenalizePeerFunc mocks the PenalizePeer method. - PenalizePeerFunc func(contextMoqParam context.Context, penalizePeerRequest *PenalizePeerRequest) (*emptypb.Empty, error) - - // SendMessageByIdFunc mocks the SendMessageById method. - SendMessageByIdFunc func(contextMoqParam context.Context, sendMessageByIdRequest *SendMessageByIdRequest) (*SentPeers, error) - - // SendMessageByMinBlockFunc mocks the SendMessageByMinBlock method. - SendMessageByMinBlockFunc func(contextMoqParam context.Context, sendMessageByMinBlockRequest *SendMessageByMinBlockRequest) (*SentPeers, error) - - // SendMessageToAllFunc mocks the SendMessageToAll method. - SendMessageToAllFunc func(contextMoqParam context.Context, outboundMessageData *OutboundMessageData) (*SentPeers, error) - - // SendMessageToRandomPeersFunc mocks the SendMessageToRandomPeers method. - SendMessageToRandomPeersFunc func(contextMoqParam context.Context, sendMessageToRandomPeersRequest *SendMessageToRandomPeersRequest) (*SentPeers, error) - - // SetStatusFunc mocks the SetStatus method. - SetStatusFunc func(contextMoqParam context.Context, statusData *StatusData) (*SetStatusReply, error) - - // mustEmbedUnimplementedSentryServerFunc mocks the mustEmbedUnimplementedSentryServer method. - mustEmbedUnimplementedSentryServerFunc func() - - // calls tracks calls to the methods. - calls struct { - // AddPeer holds details about calls to the AddPeer method. - AddPeer []struct { - // ContextMoqParam is the contextMoqParam argument value. - ContextMoqParam context.Context - // AddPeerRequest is the addPeerRequest argument value. - AddPeerRequest *AddPeerRequest - } - // HandShake holds details about calls to the HandShake method. - HandShake []struct { - // ContextMoqParam is the contextMoqParam argument value. - ContextMoqParam context.Context - // Empty is the empty argument value. - Empty *emptypb.Empty - } - // Messages holds details about calls to the Messages method. - Messages []struct { - // MessagesRequest is the messagesRequest argument value. - MessagesRequest *MessagesRequest - // Sentry_MessagesServer is the sentry_MessagesServer argument value. - Sentry_MessagesServer Sentry_MessagesServer - } - // NodeInfo holds details about calls to the NodeInfo method. - NodeInfo []struct { - // ContextMoqParam is the contextMoqParam argument value. - ContextMoqParam context.Context - // Empty is the empty argument value. - Empty *emptypb.Empty - } - // PeerById holds details about calls to the PeerById method. - PeerById []struct { - // ContextMoqParam is the contextMoqParam argument value. - ContextMoqParam context.Context - // PeerByIdRequest is the peerByIdRequest argument value. - PeerByIdRequest *PeerByIdRequest - } - // PeerCount holds details about calls to the PeerCount method. - PeerCount []struct { - // ContextMoqParam is the contextMoqParam argument value. - ContextMoqParam context.Context - // PeerCountRequest is the peerCountRequest argument value. - PeerCountRequest *PeerCountRequest - } - // PeerEvents holds details about calls to the PeerEvents method. - PeerEvents []struct { - // PeerEventsRequest is the peerEventsRequest argument value. - PeerEventsRequest *PeerEventsRequest - // Sentry_PeerEventsServer is the sentry_PeerEventsServer argument value. - Sentry_PeerEventsServer Sentry_PeerEventsServer - } - // PeerMinBlock holds details about calls to the PeerMinBlock method. - PeerMinBlock []struct { - // ContextMoqParam is the contextMoqParam argument value. - ContextMoqParam context.Context - // PeerMinBlockRequest is the peerMinBlockRequest argument value. - PeerMinBlockRequest *PeerMinBlockRequest - } - // Peers holds details about calls to the Peers method. - Peers []struct { - // ContextMoqParam is the contextMoqParam argument value. - ContextMoqParam context.Context - // Empty is the empty argument value. - Empty *emptypb.Empty - } - // PenalizePeer holds details about calls to the PenalizePeer method. - PenalizePeer []struct { - // ContextMoqParam is the contextMoqParam argument value. - ContextMoqParam context.Context - // PenalizePeerRequest is the penalizePeerRequest argument value. - PenalizePeerRequest *PenalizePeerRequest - } - // SendMessageById holds details about calls to the SendMessageById method. - SendMessageById []struct { - // ContextMoqParam is the contextMoqParam argument value. - ContextMoqParam context.Context - // SendMessageByIdRequest is the sendMessageByIdRequest argument value. - SendMessageByIdRequest *SendMessageByIdRequest - } - // SendMessageByMinBlock holds details about calls to the SendMessageByMinBlock method. - SendMessageByMinBlock []struct { - // ContextMoqParam is the contextMoqParam argument value. - ContextMoqParam context.Context - // SendMessageByMinBlockRequest is the sendMessageByMinBlockRequest argument value. - SendMessageByMinBlockRequest *SendMessageByMinBlockRequest - } - // SendMessageToAll holds details about calls to the SendMessageToAll method. - SendMessageToAll []struct { - // ContextMoqParam is the contextMoqParam argument value. - ContextMoqParam context.Context - // OutboundMessageData is the outboundMessageData argument value. - OutboundMessageData *OutboundMessageData - } - // SendMessageToRandomPeers holds details about calls to the SendMessageToRandomPeers method. - SendMessageToRandomPeers []struct { - // ContextMoqParam is the contextMoqParam argument value. - ContextMoqParam context.Context - // SendMessageToRandomPeersRequest is the sendMessageToRandomPeersRequest argument value. - SendMessageToRandomPeersRequest *SendMessageToRandomPeersRequest - } - // SetStatus holds details about calls to the SetStatus method. - SetStatus []struct { - // ContextMoqParam is the contextMoqParam argument value. - ContextMoqParam context.Context - // StatusData is the statusData argument value. - StatusData *StatusData - } - // mustEmbedUnimplementedSentryServer holds details about calls to the mustEmbedUnimplementedSentryServer method. - mustEmbedUnimplementedSentryServer []struct { - } - } - lockAddPeer sync.RWMutex - lockHandShake sync.RWMutex - lockMessages sync.RWMutex - lockNodeInfo sync.RWMutex - lockPeerById sync.RWMutex - lockPeerCount sync.RWMutex - lockPeerEvents sync.RWMutex - lockPeerMinBlock sync.RWMutex - lockPeers sync.RWMutex - lockPenalizePeer sync.RWMutex - lockSendMessageById sync.RWMutex - lockSendMessageByMinBlock sync.RWMutex - lockSendMessageToAll sync.RWMutex - lockSendMessageToRandomPeers sync.RWMutex - lockSetStatus sync.RWMutex - lockmustEmbedUnimplementedSentryServer sync.RWMutex -} - -// AddPeer calls AddPeerFunc. -func (mock *SentryServerMock) AddPeer(contextMoqParam context.Context, addPeerRequest *AddPeerRequest) (*AddPeerReply, error) { - callInfo := struct { - ContextMoqParam context.Context - AddPeerRequest *AddPeerRequest - }{ - ContextMoqParam: contextMoqParam, - AddPeerRequest: addPeerRequest, - } - mock.lockAddPeer.Lock() - mock.calls.AddPeer = append(mock.calls.AddPeer, callInfo) - mock.lockAddPeer.Unlock() - if mock.AddPeerFunc == nil { - var ( - addPeerReplyOut *AddPeerReply - errOut error - ) - return addPeerReplyOut, errOut - } - return mock.AddPeerFunc(contextMoqParam, addPeerRequest) -} - -// AddPeerCalls gets all the calls that were made to AddPeer. -// Check the length with: -// -// len(mockedSentryServer.AddPeerCalls()) -func (mock *SentryServerMock) AddPeerCalls() []struct { - ContextMoqParam context.Context - AddPeerRequest *AddPeerRequest -} { - var calls []struct { - ContextMoqParam context.Context - AddPeerRequest *AddPeerRequest - } - mock.lockAddPeer.RLock() - calls = mock.calls.AddPeer - mock.lockAddPeer.RUnlock() - return calls -} - -// HandShake calls HandShakeFunc. -func (mock *SentryServerMock) HandShake(contextMoqParam context.Context, empty *emptypb.Empty) (*HandShakeReply, error) { - callInfo := struct { - ContextMoqParam context.Context - Empty *emptypb.Empty - }{ - ContextMoqParam: contextMoqParam, - Empty: empty, - } - mock.lockHandShake.Lock() - mock.calls.HandShake = append(mock.calls.HandShake, callInfo) - mock.lockHandShake.Unlock() - if mock.HandShakeFunc == nil { - var ( - handShakeReplyOut *HandShakeReply - errOut error - ) - return handShakeReplyOut, errOut - } - return mock.HandShakeFunc(contextMoqParam, empty) -} - -// HandShakeCalls gets all the calls that were made to HandShake. -// Check the length with: -// -// len(mockedSentryServer.HandShakeCalls()) -func (mock *SentryServerMock) HandShakeCalls() []struct { - ContextMoqParam context.Context - Empty *emptypb.Empty -} { - var calls []struct { - ContextMoqParam context.Context - Empty *emptypb.Empty - } - mock.lockHandShake.RLock() - calls = mock.calls.HandShake - mock.lockHandShake.RUnlock() - return calls -} - -// Messages calls MessagesFunc. -func (mock *SentryServerMock) Messages(messagesRequest *MessagesRequest, sentry_MessagesServer Sentry_MessagesServer) error { - callInfo := struct { - MessagesRequest *MessagesRequest - Sentry_MessagesServer Sentry_MessagesServer - }{ - MessagesRequest: messagesRequest, - Sentry_MessagesServer: sentry_MessagesServer, - } - mock.lockMessages.Lock() - mock.calls.Messages = append(mock.calls.Messages, callInfo) - mock.lockMessages.Unlock() - if mock.MessagesFunc == nil { - var ( - errOut error - ) - return errOut - } - return mock.MessagesFunc(messagesRequest, sentry_MessagesServer) -} - -// MessagesCalls gets all the calls that were made to Messages. -// Check the length with: -// -// len(mockedSentryServer.MessagesCalls()) -func (mock *SentryServerMock) MessagesCalls() []struct { - MessagesRequest *MessagesRequest - Sentry_MessagesServer Sentry_MessagesServer -} { - var calls []struct { - MessagesRequest *MessagesRequest - Sentry_MessagesServer Sentry_MessagesServer - } - mock.lockMessages.RLock() - calls = mock.calls.Messages - mock.lockMessages.RUnlock() - return calls -} - -// NodeInfo calls NodeInfoFunc. -func (mock *SentryServerMock) NodeInfo(contextMoqParam context.Context, empty *emptypb.Empty) (*types.NodeInfoReply, error) { - callInfo := struct { - ContextMoqParam context.Context - Empty *emptypb.Empty - }{ - ContextMoqParam: contextMoqParam, - Empty: empty, - } - mock.lockNodeInfo.Lock() - mock.calls.NodeInfo = append(mock.calls.NodeInfo, callInfo) - mock.lockNodeInfo.Unlock() - if mock.NodeInfoFunc == nil { - var ( - nodeInfoReplyOut *types.NodeInfoReply - errOut error - ) - return nodeInfoReplyOut, errOut - } - return mock.NodeInfoFunc(contextMoqParam, empty) -} - -// NodeInfoCalls gets all the calls that were made to NodeInfo. -// Check the length with: -// -// len(mockedSentryServer.NodeInfoCalls()) -func (mock *SentryServerMock) NodeInfoCalls() []struct { - ContextMoqParam context.Context - Empty *emptypb.Empty -} { - var calls []struct { - ContextMoqParam context.Context - Empty *emptypb.Empty - } - mock.lockNodeInfo.RLock() - calls = mock.calls.NodeInfo - mock.lockNodeInfo.RUnlock() - return calls -} - -// PeerById calls PeerByIdFunc. -func (mock *SentryServerMock) PeerById(contextMoqParam context.Context, peerByIdRequest *PeerByIdRequest) (*PeerByIdReply, error) { - callInfo := struct { - ContextMoqParam context.Context - PeerByIdRequest *PeerByIdRequest - }{ - ContextMoqParam: contextMoqParam, - PeerByIdRequest: peerByIdRequest, - } - mock.lockPeerById.Lock() - mock.calls.PeerById = append(mock.calls.PeerById, callInfo) - mock.lockPeerById.Unlock() - if mock.PeerByIdFunc == nil { - var ( - peerByIdReplyOut *PeerByIdReply - errOut error - ) - return peerByIdReplyOut, errOut - } - return mock.PeerByIdFunc(contextMoqParam, peerByIdRequest) -} - -// PeerByIdCalls gets all the calls that were made to PeerById. -// Check the length with: -// -// len(mockedSentryServer.PeerByIdCalls()) -func (mock *SentryServerMock) PeerByIdCalls() []struct { - ContextMoqParam context.Context - PeerByIdRequest *PeerByIdRequest -} { - var calls []struct { - ContextMoqParam context.Context - PeerByIdRequest *PeerByIdRequest - } - mock.lockPeerById.RLock() - calls = mock.calls.PeerById - mock.lockPeerById.RUnlock() - return calls -} - -// PeerCount calls PeerCountFunc. -func (mock *SentryServerMock) PeerCount(contextMoqParam context.Context, peerCountRequest *PeerCountRequest) (*PeerCountReply, error) { - callInfo := struct { - ContextMoqParam context.Context - PeerCountRequest *PeerCountRequest - }{ - ContextMoqParam: contextMoqParam, - PeerCountRequest: peerCountRequest, - } - mock.lockPeerCount.Lock() - mock.calls.PeerCount = append(mock.calls.PeerCount, callInfo) - mock.lockPeerCount.Unlock() - if mock.PeerCountFunc == nil { - var ( - peerCountReplyOut *PeerCountReply - errOut error - ) - return peerCountReplyOut, errOut - } - return mock.PeerCountFunc(contextMoqParam, peerCountRequest) -} - -// PeerCountCalls gets all the calls that were made to PeerCount. -// Check the length with: -// -// len(mockedSentryServer.PeerCountCalls()) -func (mock *SentryServerMock) PeerCountCalls() []struct { - ContextMoqParam context.Context - PeerCountRequest *PeerCountRequest -} { - var calls []struct { - ContextMoqParam context.Context - PeerCountRequest *PeerCountRequest - } - mock.lockPeerCount.RLock() - calls = mock.calls.PeerCount - mock.lockPeerCount.RUnlock() - return calls -} - -// PeerEvents calls PeerEventsFunc. -func (mock *SentryServerMock) PeerEvents(peerEventsRequest *PeerEventsRequest, sentry_PeerEventsServer Sentry_PeerEventsServer) error { - callInfo := struct { - PeerEventsRequest *PeerEventsRequest - Sentry_PeerEventsServer Sentry_PeerEventsServer - }{ - PeerEventsRequest: peerEventsRequest, - Sentry_PeerEventsServer: sentry_PeerEventsServer, - } - mock.lockPeerEvents.Lock() - mock.calls.PeerEvents = append(mock.calls.PeerEvents, callInfo) - mock.lockPeerEvents.Unlock() - if mock.PeerEventsFunc == nil { - var ( - errOut error - ) - return errOut - } - return mock.PeerEventsFunc(peerEventsRequest, sentry_PeerEventsServer) -} - -// PeerEventsCalls gets all the calls that were made to PeerEvents. -// Check the length with: -// -// len(mockedSentryServer.PeerEventsCalls()) -func (mock *SentryServerMock) PeerEventsCalls() []struct { - PeerEventsRequest *PeerEventsRequest - Sentry_PeerEventsServer Sentry_PeerEventsServer -} { - var calls []struct { - PeerEventsRequest *PeerEventsRequest - Sentry_PeerEventsServer Sentry_PeerEventsServer - } - mock.lockPeerEvents.RLock() - calls = mock.calls.PeerEvents - mock.lockPeerEvents.RUnlock() - return calls -} - -// PeerMinBlock calls PeerMinBlockFunc. -func (mock *SentryServerMock) PeerMinBlock(contextMoqParam context.Context, peerMinBlockRequest *PeerMinBlockRequest) (*emptypb.Empty, error) { - callInfo := struct { - ContextMoqParam context.Context - PeerMinBlockRequest *PeerMinBlockRequest - }{ - ContextMoqParam: contextMoqParam, - PeerMinBlockRequest: peerMinBlockRequest, - } - mock.lockPeerMinBlock.Lock() - mock.calls.PeerMinBlock = append(mock.calls.PeerMinBlock, callInfo) - mock.lockPeerMinBlock.Unlock() - if mock.PeerMinBlockFunc == nil { - var ( - emptyOut *emptypb.Empty - errOut error - ) - return emptyOut, errOut - } - return mock.PeerMinBlockFunc(contextMoqParam, peerMinBlockRequest) -} - -// PeerMinBlockCalls gets all the calls that were made to PeerMinBlock. -// Check the length with: -// -// len(mockedSentryServer.PeerMinBlockCalls()) -func (mock *SentryServerMock) PeerMinBlockCalls() []struct { - ContextMoqParam context.Context - PeerMinBlockRequest *PeerMinBlockRequest -} { - var calls []struct { - ContextMoqParam context.Context - PeerMinBlockRequest *PeerMinBlockRequest - } - mock.lockPeerMinBlock.RLock() - calls = mock.calls.PeerMinBlock - mock.lockPeerMinBlock.RUnlock() - return calls -} - -// Peers calls PeersFunc. -func (mock *SentryServerMock) Peers(contextMoqParam context.Context, empty *emptypb.Empty) (*PeersReply, error) { - callInfo := struct { - ContextMoqParam context.Context - Empty *emptypb.Empty - }{ - ContextMoqParam: contextMoqParam, - Empty: empty, - } - mock.lockPeers.Lock() - mock.calls.Peers = append(mock.calls.Peers, callInfo) - mock.lockPeers.Unlock() - if mock.PeersFunc == nil { - var ( - peersReplyOut *PeersReply - errOut error - ) - return peersReplyOut, errOut - } - return mock.PeersFunc(contextMoqParam, empty) -} - -// PeersCalls gets all the calls that were made to Peers. -// Check the length with: -// -// len(mockedSentryServer.PeersCalls()) -func (mock *SentryServerMock) PeersCalls() []struct { - ContextMoqParam context.Context - Empty *emptypb.Empty -} { - var calls []struct { - ContextMoqParam context.Context - Empty *emptypb.Empty - } - mock.lockPeers.RLock() - calls = mock.calls.Peers - mock.lockPeers.RUnlock() - return calls -} - -// PenalizePeer calls PenalizePeerFunc. -func (mock *SentryServerMock) PenalizePeer(contextMoqParam context.Context, penalizePeerRequest *PenalizePeerRequest) (*emptypb.Empty, error) { - callInfo := struct { - ContextMoqParam context.Context - PenalizePeerRequest *PenalizePeerRequest - }{ - ContextMoqParam: contextMoqParam, - PenalizePeerRequest: penalizePeerRequest, - } - mock.lockPenalizePeer.Lock() - mock.calls.PenalizePeer = append(mock.calls.PenalizePeer, callInfo) - mock.lockPenalizePeer.Unlock() - if mock.PenalizePeerFunc == nil { - var ( - emptyOut *emptypb.Empty - errOut error - ) - return emptyOut, errOut - } - return mock.PenalizePeerFunc(contextMoqParam, penalizePeerRequest) -} - -// PenalizePeerCalls gets all the calls that were made to PenalizePeer. -// Check the length with: -// -// len(mockedSentryServer.PenalizePeerCalls()) -func (mock *SentryServerMock) PenalizePeerCalls() []struct { - ContextMoqParam context.Context - PenalizePeerRequest *PenalizePeerRequest -} { - var calls []struct { - ContextMoqParam context.Context - PenalizePeerRequest *PenalizePeerRequest - } - mock.lockPenalizePeer.RLock() - calls = mock.calls.PenalizePeer - mock.lockPenalizePeer.RUnlock() - return calls -} - -// SendMessageById calls SendMessageByIdFunc. -func (mock *SentryServerMock) SendMessageById(contextMoqParam context.Context, sendMessageByIdRequest *SendMessageByIdRequest) (*SentPeers, error) { - callInfo := struct { - ContextMoqParam context.Context - SendMessageByIdRequest *SendMessageByIdRequest - }{ - ContextMoqParam: contextMoqParam, - SendMessageByIdRequest: sendMessageByIdRequest, - } - mock.lockSendMessageById.Lock() - mock.calls.SendMessageById = append(mock.calls.SendMessageById, callInfo) - mock.lockSendMessageById.Unlock() - if mock.SendMessageByIdFunc == nil { - var ( - sentPeersOut *SentPeers - errOut error - ) - return sentPeersOut, errOut - } - return mock.SendMessageByIdFunc(contextMoqParam, sendMessageByIdRequest) -} - -// SendMessageByIdCalls gets all the calls that were made to SendMessageById. -// Check the length with: -// -// len(mockedSentryServer.SendMessageByIdCalls()) -func (mock *SentryServerMock) SendMessageByIdCalls() []struct { - ContextMoqParam context.Context - SendMessageByIdRequest *SendMessageByIdRequest -} { - var calls []struct { - ContextMoqParam context.Context - SendMessageByIdRequest *SendMessageByIdRequest - } - mock.lockSendMessageById.RLock() - calls = mock.calls.SendMessageById - mock.lockSendMessageById.RUnlock() - return calls -} - -// SendMessageByMinBlock calls SendMessageByMinBlockFunc. -func (mock *SentryServerMock) SendMessageByMinBlock(contextMoqParam context.Context, sendMessageByMinBlockRequest *SendMessageByMinBlockRequest) (*SentPeers, error) { - callInfo := struct { - ContextMoqParam context.Context - SendMessageByMinBlockRequest *SendMessageByMinBlockRequest - }{ - ContextMoqParam: contextMoqParam, - SendMessageByMinBlockRequest: sendMessageByMinBlockRequest, - } - mock.lockSendMessageByMinBlock.Lock() - mock.calls.SendMessageByMinBlock = append(mock.calls.SendMessageByMinBlock, callInfo) - mock.lockSendMessageByMinBlock.Unlock() - if mock.SendMessageByMinBlockFunc == nil { - var ( - sentPeersOut *SentPeers - errOut error - ) - return sentPeersOut, errOut - } - return mock.SendMessageByMinBlockFunc(contextMoqParam, sendMessageByMinBlockRequest) -} - -// SendMessageByMinBlockCalls gets all the calls that were made to SendMessageByMinBlock. -// Check the length with: -// -// len(mockedSentryServer.SendMessageByMinBlockCalls()) -func (mock *SentryServerMock) SendMessageByMinBlockCalls() []struct { - ContextMoqParam context.Context - SendMessageByMinBlockRequest *SendMessageByMinBlockRequest -} { - var calls []struct { - ContextMoqParam context.Context - SendMessageByMinBlockRequest *SendMessageByMinBlockRequest - } - mock.lockSendMessageByMinBlock.RLock() - calls = mock.calls.SendMessageByMinBlock - mock.lockSendMessageByMinBlock.RUnlock() - return calls -} - -// SendMessageToAll calls SendMessageToAllFunc. -func (mock *SentryServerMock) SendMessageToAll(contextMoqParam context.Context, outboundMessageData *OutboundMessageData) (*SentPeers, error) { - callInfo := struct { - ContextMoqParam context.Context - OutboundMessageData *OutboundMessageData - }{ - ContextMoqParam: contextMoqParam, - OutboundMessageData: outboundMessageData, - } - mock.lockSendMessageToAll.Lock() - mock.calls.SendMessageToAll = append(mock.calls.SendMessageToAll, callInfo) - mock.lockSendMessageToAll.Unlock() - if mock.SendMessageToAllFunc == nil { - var ( - sentPeersOut *SentPeers - errOut error - ) - return sentPeersOut, errOut - } - return mock.SendMessageToAllFunc(contextMoqParam, outboundMessageData) -} - -// SendMessageToAllCalls gets all the calls that were made to SendMessageToAll. -// Check the length with: -// -// len(mockedSentryServer.SendMessageToAllCalls()) -func (mock *SentryServerMock) SendMessageToAllCalls() []struct { - ContextMoqParam context.Context - OutboundMessageData *OutboundMessageData -} { - var calls []struct { - ContextMoqParam context.Context - OutboundMessageData *OutboundMessageData - } - mock.lockSendMessageToAll.RLock() - calls = mock.calls.SendMessageToAll - mock.lockSendMessageToAll.RUnlock() - return calls -} - -// SendMessageToRandomPeers calls SendMessageToRandomPeersFunc. -func (mock *SentryServerMock) SendMessageToRandomPeers(contextMoqParam context.Context, sendMessageToRandomPeersRequest *SendMessageToRandomPeersRequest) (*SentPeers, error) { - callInfo := struct { - ContextMoqParam context.Context - SendMessageToRandomPeersRequest *SendMessageToRandomPeersRequest - }{ - ContextMoqParam: contextMoqParam, - SendMessageToRandomPeersRequest: sendMessageToRandomPeersRequest, - } - mock.lockSendMessageToRandomPeers.Lock() - mock.calls.SendMessageToRandomPeers = append(mock.calls.SendMessageToRandomPeers, callInfo) - mock.lockSendMessageToRandomPeers.Unlock() - if mock.SendMessageToRandomPeersFunc == nil { - var ( - sentPeersOut *SentPeers - errOut error - ) - return sentPeersOut, errOut - } - return mock.SendMessageToRandomPeersFunc(contextMoqParam, sendMessageToRandomPeersRequest) -} - -// SendMessageToRandomPeersCalls gets all the calls that were made to SendMessageToRandomPeers. -// Check the length with: -// -// len(mockedSentryServer.SendMessageToRandomPeersCalls()) -func (mock *SentryServerMock) SendMessageToRandomPeersCalls() []struct { - ContextMoqParam context.Context - SendMessageToRandomPeersRequest *SendMessageToRandomPeersRequest -} { - var calls []struct { - ContextMoqParam context.Context - SendMessageToRandomPeersRequest *SendMessageToRandomPeersRequest - } - mock.lockSendMessageToRandomPeers.RLock() - calls = mock.calls.SendMessageToRandomPeers - mock.lockSendMessageToRandomPeers.RUnlock() - return calls -} - -// SetStatus calls SetStatusFunc. -func (mock *SentryServerMock) SetStatus(contextMoqParam context.Context, statusData *StatusData) (*SetStatusReply, error) { - callInfo := struct { - ContextMoqParam context.Context - StatusData *StatusData - }{ - ContextMoqParam: contextMoqParam, - StatusData: statusData, - } - mock.lockSetStatus.Lock() - mock.calls.SetStatus = append(mock.calls.SetStatus, callInfo) - mock.lockSetStatus.Unlock() - if mock.SetStatusFunc == nil { - var ( - setStatusReplyOut *SetStatusReply - errOut error - ) - return setStatusReplyOut, errOut - } - return mock.SetStatusFunc(contextMoqParam, statusData) -} - -// SetStatusCalls gets all the calls that were made to SetStatus. -// Check the length with: -// -// len(mockedSentryServer.SetStatusCalls()) -func (mock *SentryServerMock) SetStatusCalls() []struct { - ContextMoqParam context.Context - StatusData *StatusData -} { - var calls []struct { - ContextMoqParam context.Context - StatusData *StatusData - } - mock.lockSetStatus.RLock() - calls = mock.calls.SetStatus - mock.lockSetStatus.RUnlock() - return calls -} - -// mustEmbedUnimplementedSentryServer calls mustEmbedUnimplementedSentryServerFunc. -func (mock *SentryServerMock) mustEmbedUnimplementedSentryServer() { - callInfo := struct { - }{} - mock.lockmustEmbedUnimplementedSentryServer.Lock() - mock.calls.mustEmbedUnimplementedSentryServer = append(mock.calls.mustEmbedUnimplementedSentryServer, callInfo) - mock.lockmustEmbedUnimplementedSentryServer.Unlock() - if mock.mustEmbedUnimplementedSentryServerFunc == nil { - return - } - mock.mustEmbedUnimplementedSentryServerFunc() -} - -// mustEmbedUnimplementedSentryServerCalls gets all the calls that were made to mustEmbedUnimplementedSentryServer. -// Check the length with: -// -// len(mockedSentryServer.mustEmbedUnimplementedSentryServerCalls()) -func (mock *SentryServerMock) mustEmbedUnimplementedSentryServerCalls() []struct { -} { - var calls []struct { - } - mock.lockmustEmbedUnimplementedSentryServer.RLock() - calls = mock.calls.mustEmbedUnimplementedSentryServer - mock.lockmustEmbedUnimplementedSentryServer.RUnlock() - return calls -} - -// Ensure, that SentryClientMock does implement SentryClient. -// If this is not the case, regenerate this file with moq. -var _ SentryClient = &SentryClientMock{} - -// SentryClientMock is a mock implementation of SentryClient. -// -// func TestSomethingThatUsesSentryClient(t *testing.T) { -// -// // make and configure a mocked SentryClient -// mockedSentryClient := &SentryClientMock{ -// AddPeerFunc: func(ctx context.Context, in *AddPeerRequest, opts ...grpc.CallOption) (*AddPeerReply, error) { -// panic("mock out the AddPeer method") -// }, -// HandShakeFunc: func(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*HandShakeReply, error) { -// panic("mock out the HandShake method") -// }, -// MessagesFunc: func(ctx context.Context, in *MessagesRequest, opts ...grpc.CallOption) (Sentry_MessagesClient, error) { -// panic("mock out the Messages method") -// }, -// NodeInfoFunc: func(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*types.NodeInfoReply, error) { -// panic("mock out the NodeInfo method") -// }, -// PeerByIdFunc: func(ctx context.Context, in *PeerByIdRequest, opts ...grpc.CallOption) (*PeerByIdReply, error) { -// panic("mock out the PeerById method") -// }, -// PeerCountFunc: func(ctx context.Context, in *PeerCountRequest, opts ...grpc.CallOption) (*PeerCountReply, error) { -// panic("mock out the PeerCount method") -// }, -// PeerEventsFunc: func(ctx context.Context, in *PeerEventsRequest, opts ...grpc.CallOption) (Sentry_PeerEventsClient, error) { -// panic("mock out the PeerEvents method") -// }, -// PeerMinBlockFunc: func(ctx context.Context, in *PeerMinBlockRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) { -// panic("mock out the PeerMinBlock method") -// }, -// PeersFunc: func(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*PeersReply, error) { -// panic("mock out the Peers method") -// }, -// PenalizePeerFunc: func(ctx context.Context, in *PenalizePeerRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) { -// panic("mock out the PenalizePeer method") -// }, -// SendMessageByIdFunc: func(ctx context.Context, in *SendMessageByIdRequest, opts ...grpc.CallOption) (*SentPeers, error) { -// panic("mock out the SendMessageById method") -// }, -// SendMessageByMinBlockFunc: func(ctx context.Context, in *SendMessageByMinBlockRequest, opts ...grpc.CallOption) (*SentPeers, error) { -// panic("mock out the SendMessageByMinBlock method") -// }, -// SendMessageToAllFunc: func(ctx context.Context, in *OutboundMessageData, opts ...grpc.CallOption) (*SentPeers, error) { -// panic("mock out the SendMessageToAll method") -// }, -// SendMessageToRandomPeersFunc: func(ctx context.Context, in *SendMessageToRandomPeersRequest, opts ...grpc.CallOption) (*SentPeers, error) { -// panic("mock out the SendMessageToRandomPeers method") -// }, -// SetStatusFunc: func(ctx context.Context, in *StatusData, opts ...grpc.CallOption) (*SetStatusReply, error) { -// panic("mock out the SetStatus method") -// }, -// } -// -// // use mockedSentryClient in code that requires SentryClient -// // and then make assertions. -// -// } -type SentryClientMock struct { - // AddPeerFunc mocks the AddPeer method. - AddPeerFunc func(ctx context.Context, in *AddPeerRequest, opts ...grpc.CallOption) (*AddPeerReply, error) - - // HandShakeFunc mocks the HandShake method. - HandShakeFunc func(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*HandShakeReply, error) - - // MessagesFunc mocks the Messages method. - MessagesFunc func(ctx context.Context, in *MessagesRequest, opts ...grpc.CallOption) (Sentry_MessagesClient, error) - - // NodeInfoFunc mocks the NodeInfo method. - NodeInfoFunc func(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*types.NodeInfoReply, error) - - // PeerByIdFunc mocks the PeerById method. - PeerByIdFunc func(ctx context.Context, in *PeerByIdRequest, opts ...grpc.CallOption) (*PeerByIdReply, error) - - // PeerCountFunc mocks the PeerCount method. - PeerCountFunc func(ctx context.Context, in *PeerCountRequest, opts ...grpc.CallOption) (*PeerCountReply, error) - - // PeerEventsFunc mocks the PeerEvents method. - PeerEventsFunc func(ctx context.Context, in *PeerEventsRequest, opts ...grpc.CallOption) (Sentry_PeerEventsClient, error) - - // PeerMinBlockFunc mocks the PeerMinBlock method. - PeerMinBlockFunc func(ctx context.Context, in *PeerMinBlockRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) - - // PeersFunc mocks the Peers method. - PeersFunc func(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*PeersReply, error) - - // PenalizePeerFunc mocks the PenalizePeer method. - PenalizePeerFunc func(ctx context.Context, in *PenalizePeerRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) - - // SendMessageByIdFunc mocks the SendMessageById method. - SendMessageByIdFunc func(ctx context.Context, in *SendMessageByIdRequest, opts ...grpc.CallOption) (*SentPeers, error) - - // SendMessageByMinBlockFunc mocks the SendMessageByMinBlock method. - SendMessageByMinBlockFunc func(ctx context.Context, in *SendMessageByMinBlockRequest, opts ...grpc.CallOption) (*SentPeers, error) - - // SendMessageToAllFunc mocks the SendMessageToAll method. - SendMessageToAllFunc func(ctx context.Context, in *OutboundMessageData, opts ...grpc.CallOption) (*SentPeers, error) - - // SendMessageToRandomPeersFunc mocks the SendMessageToRandomPeers method. - SendMessageToRandomPeersFunc func(ctx context.Context, in *SendMessageToRandomPeersRequest, opts ...grpc.CallOption) (*SentPeers, error) - - // SetStatusFunc mocks the SetStatus method. - SetStatusFunc func(ctx context.Context, in *StatusData, opts ...grpc.CallOption) (*SetStatusReply, error) - - // calls tracks calls to the methods. - calls struct { - // AddPeer holds details about calls to the AddPeer method. - AddPeer []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // In is the in argument value. - In *AddPeerRequest - // Opts is the opts argument value. - Opts []grpc.CallOption - } - // HandShake holds details about calls to the HandShake method. - HandShake []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // In is the in argument value. - In *emptypb.Empty - // Opts is the opts argument value. - Opts []grpc.CallOption - } - // Messages holds details about calls to the Messages method. - Messages []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // In is the in argument value. - In *MessagesRequest - // Opts is the opts argument value. - Opts []grpc.CallOption - } - // NodeInfo holds details about calls to the NodeInfo method. - NodeInfo []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // In is the in argument value. - In *emptypb.Empty - // Opts is the opts argument value. - Opts []grpc.CallOption - } - // PeerById holds details about calls to the PeerById method. - PeerById []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // In is the in argument value. - In *PeerByIdRequest - // Opts is the opts argument value. - Opts []grpc.CallOption - } - // PeerCount holds details about calls to the PeerCount method. - PeerCount []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // In is the in argument value. - In *PeerCountRequest - // Opts is the opts argument value. - Opts []grpc.CallOption - } - // PeerEvents holds details about calls to the PeerEvents method. - PeerEvents []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // In is the in argument value. - In *PeerEventsRequest - // Opts is the opts argument value. - Opts []grpc.CallOption - } - // PeerMinBlock holds details about calls to the PeerMinBlock method. - PeerMinBlock []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // In is the in argument value. - In *PeerMinBlockRequest - // Opts is the opts argument value. - Opts []grpc.CallOption - } - // Peers holds details about calls to the Peers method. - Peers []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // In is the in argument value. - In *emptypb.Empty - // Opts is the opts argument value. - Opts []grpc.CallOption - } - // PenalizePeer holds details about calls to the PenalizePeer method. - PenalizePeer []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // In is the in argument value. - In *PenalizePeerRequest - // Opts is the opts argument value. - Opts []grpc.CallOption - } - // SendMessageById holds details about calls to the SendMessageById method. - SendMessageById []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // In is the in argument value. - In *SendMessageByIdRequest - // Opts is the opts argument value. - Opts []grpc.CallOption - } - // SendMessageByMinBlock holds details about calls to the SendMessageByMinBlock method. - SendMessageByMinBlock []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // In is the in argument value. - In *SendMessageByMinBlockRequest - // Opts is the opts argument value. - Opts []grpc.CallOption - } - // SendMessageToAll holds details about calls to the SendMessageToAll method. - SendMessageToAll []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // In is the in argument value. - In *OutboundMessageData - // Opts is the opts argument value. - Opts []grpc.CallOption - } - // SendMessageToRandomPeers holds details about calls to the SendMessageToRandomPeers method. - SendMessageToRandomPeers []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // In is the in argument value. - In *SendMessageToRandomPeersRequest - // Opts is the opts argument value. - Opts []grpc.CallOption - } - // SetStatus holds details about calls to the SetStatus method. - SetStatus []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // In is the in argument value. - In *StatusData - // Opts is the opts argument value. - Opts []grpc.CallOption - } - } - lockAddPeer sync.RWMutex - lockHandShake sync.RWMutex - lockMessages sync.RWMutex - lockNodeInfo sync.RWMutex - lockPeerById sync.RWMutex - lockPeerCount sync.RWMutex - lockPeerEvents sync.RWMutex - lockPeerMinBlock sync.RWMutex - lockPeers sync.RWMutex - lockPenalizePeer sync.RWMutex - lockSendMessageById sync.RWMutex - lockSendMessageByMinBlock sync.RWMutex - lockSendMessageToAll sync.RWMutex - lockSendMessageToRandomPeers sync.RWMutex - lockSetStatus sync.RWMutex -} - -// AddPeer calls AddPeerFunc. -func (mock *SentryClientMock) AddPeer(ctx context.Context, in *AddPeerRequest, opts ...grpc.CallOption) (*AddPeerReply, error) { - callInfo := struct { - Ctx context.Context - In *AddPeerRequest - Opts []grpc.CallOption - }{ - Ctx: ctx, - In: in, - Opts: opts, - } - mock.lockAddPeer.Lock() - mock.calls.AddPeer = append(mock.calls.AddPeer, callInfo) - mock.lockAddPeer.Unlock() - if mock.AddPeerFunc == nil { - var ( - addPeerReplyOut *AddPeerReply - errOut error - ) - return addPeerReplyOut, errOut - } - return mock.AddPeerFunc(ctx, in, opts...) -} - -// AddPeerCalls gets all the calls that were made to AddPeer. -// Check the length with: -// -// len(mockedSentryClient.AddPeerCalls()) -func (mock *SentryClientMock) AddPeerCalls() []struct { - Ctx context.Context - In *AddPeerRequest - Opts []grpc.CallOption -} { - var calls []struct { - Ctx context.Context - In *AddPeerRequest - Opts []grpc.CallOption - } - mock.lockAddPeer.RLock() - calls = mock.calls.AddPeer - mock.lockAddPeer.RUnlock() - return calls -} - -// HandShake calls HandShakeFunc. -func (mock *SentryClientMock) HandShake(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*HandShakeReply, error) { - callInfo := struct { - Ctx context.Context - In *emptypb.Empty - Opts []grpc.CallOption - }{ - Ctx: ctx, - In: in, - Opts: opts, - } - mock.lockHandShake.Lock() - mock.calls.HandShake = append(mock.calls.HandShake, callInfo) - mock.lockHandShake.Unlock() - if mock.HandShakeFunc == nil { - var ( - handShakeReplyOut *HandShakeReply - errOut error - ) - return handShakeReplyOut, errOut - } - return mock.HandShakeFunc(ctx, in, opts...) -} - -// HandShakeCalls gets all the calls that were made to HandShake. -// Check the length with: -// -// len(mockedSentryClient.HandShakeCalls()) -func (mock *SentryClientMock) HandShakeCalls() []struct { - Ctx context.Context - In *emptypb.Empty - Opts []grpc.CallOption -} { - var calls []struct { - Ctx context.Context - In *emptypb.Empty - Opts []grpc.CallOption - } - mock.lockHandShake.RLock() - calls = mock.calls.HandShake - mock.lockHandShake.RUnlock() - return calls -} - -// Messages calls MessagesFunc. -func (mock *SentryClientMock) Messages(ctx context.Context, in *MessagesRequest, opts ...grpc.CallOption) (Sentry_MessagesClient, error) { - callInfo := struct { - Ctx context.Context - In *MessagesRequest - Opts []grpc.CallOption - }{ - Ctx: ctx, - In: in, - Opts: opts, - } - mock.lockMessages.Lock() - mock.calls.Messages = append(mock.calls.Messages, callInfo) - mock.lockMessages.Unlock() - if mock.MessagesFunc == nil { - var ( - sentry_MessagesClientOut Sentry_MessagesClient - errOut error - ) - return sentry_MessagesClientOut, errOut - } - return mock.MessagesFunc(ctx, in, opts...) -} - -// MessagesCalls gets all the calls that were made to Messages. -// Check the length with: -// -// len(mockedSentryClient.MessagesCalls()) -func (mock *SentryClientMock) MessagesCalls() []struct { - Ctx context.Context - In *MessagesRequest - Opts []grpc.CallOption -} { - var calls []struct { - Ctx context.Context - In *MessagesRequest - Opts []grpc.CallOption - } - mock.lockMessages.RLock() - calls = mock.calls.Messages - mock.lockMessages.RUnlock() - return calls -} - -// NodeInfo calls NodeInfoFunc. -func (mock *SentryClientMock) NodeInfo(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*types.NodeInfoReply, error) { - callInfo := struct { - Ctx context.Context - In *emptypb.Empty - Opts []grpc.CallOption - }{ - Ctx: ctx, - In: in, - Opts: opts, - } - mock.lockNodeInfo.Lock() - mock.calls.NodeInfo = append(mock.calls.NodeInfo, callInfo) - mock.lockNodeInfo.Unlock() - if mock.NodeInfoFunc == nil { - var ( - nodeInfoReplyOut *types.NodeInfoReply - errOut error - ) - return nodeInfoReplyOut, errOut - } - return mock.NodeInfoFunc(ctx, in, opts...) -} - -// NodeInfoCalls gets all the calls that were made to NodeInfo. -// Check the length with: -// -// len(mockedSentryClient.NodeInfoCalls()) -func (mock *SentryClientMock) NodeInfoCalls() []struct { - Ctx context.Context - In *emptypb.Empty - Opts []grpc.CallOption -} { - var calls []struct { - Ctx context.Context - In *emptypb.Empty - Opts []grpc.CallOption - } - mock.lockNodeInfo.RLock() - calls = mock.calls.NodeInfo - mock.lockNodeInfo.RUnlock() - return calls -} - -// PeerById calls PeerByIdFunc. -func (mock *SentryClientMock) PeerById(ctx context.Context, in *PeerByIdRequest, opts ...grpc.CallOption) (*PeerByIdReply, error) { - callInfo := struct { - Ctx context.Context - In *PeerByIdRequest - Opts []grpc.CallOption - }{ - Ctx: ctx, - In: in, - Opts: opts, - } - mock.lockPeerById.Lock() - mock.calls.PeerById = append(mock.calls.PeerById, callInfo) - mock.lockPeerById.Unlock() - if mock.PeerByIdFunc == nil { - var ( - peerByIdReplyOut *PeerByIdReply - errOut error - ) - return peerByIdReplyOut, errOut - } - return mock.PeerByIdFunc(ctx, in, opts...) -} - -// PeerByIdCalls gets all the calls that were made to PeerById. -// Check the length with: -// -// len(mockedSentryClient.PeerByIdCalls()) -func (mock *SentryClientMock) PeerByIdCalls() []struct { - Ctx context.Context - In *PeerByIdRequest - Opts []grpc.CallOption -} { - var calls []struct { - Ctx context.Context - In *PeerByIdRequest - Opts []grpc.CallOption - } - mock.lockPeerById.RLock() - calls = mock.calls.PeerById - mock.lockPeerById.RUnlock() - return calls -} - -// PeerCount calls PeerCountFunc. -func (mock *SentryClientMock) PeerCount(ctx context.Context, in *PeerCountRequest, opts ...grpc.CallOption) (*PeerCountReply, error) { - callInfo := struct { - Ctx context.Context - In *PeerCountRequest - Opts []grpc.CallOption - }{ - Ctx: ctx, - In: in, - Opts: opts, - } - mock.lockPeerCount.Lock() - mock.calls.PeerCount = append(mock.calls.PeerCount, callInfo) - mock.lockPeerCount.Unlock() - if mock.PeerCountFunc == nil { - var ( - peerCountReplyOut *PeerCountReply - errOut error - ) - return peerCountReplyOut, errOut - } - return mock.PeerCountFunc(ctx, in, opts...) -} - -// PeerCountCalls gets all the calls that were made to PeerCount. -// Check the length with: -// -// len(mockedSentryClient.PeerCountCalls()) -func (mock *SentryClientMock) PeerCountCalls() []struct { - Ctx context.Context - In *PeerCountRequest - Opts []grpc.CallOption -} { - var calls []struct { - Ctx context.Context - In *PeerCountRequest - Opts []grpc.CallOption - } - mock.lockPeerCount.RLock() - calls = mock.calls.PeerCount - mock.lockPeerCount.RUnlock() - return calls -} - -// PeerEvents calls PeerEventsFunc. -func (mock *SentryClientMock) PeerEvents(ctx context.Context, in *PeerEventsRequest, opts ...grpc.CallOption) (Sentry_PeerEventsClient, error) { - callInfo := struct { - Ctx context.Context - In *PeerEventsRequest - Opts []grpc.CallOption - }{ - Ctx: ctx, - In: in, - Opts: opts, - } - mock.lockPeerEvents.Lock() - mock.calls.PeerEvents = append(mock.calls.PeerEvents, callInfo) - mock.lockPeerEvents.Unlock() - if mock.PeerEventsFunc == nil { - var ( - sentry_PeerEventsClientOut Sentry_PeerEventsClient - errOut error - ) - return sentry_PeerEventsClientOut, errOut - } - return mock.PeerEventsFunc(ctx, in, opts...) -} - -// PeerEventsCalls gets all the calls that were made to PeerEvents. -// Check the length with: -// -// len(mockedSentryClient.PeerEventsCalls()) -func (mock *SentryClientMock) PeerEventsCalls() []struct { - Ctx context.Context - In *PeerEventsRequest - Opts []grpc.CallOption -} { - var calls []struct { - Ctx context.Context - In *PeerEventsRequest - Opts []grpc.CallOption - } - mock.lockPeerEvents.RLock() - calls = mock.calls.PeerEvents - mock.lockPeerEvents.RUnlock() - return calls -} - -// PeerMinBlock calls PeerMinBlockFunc. -func (mock *SentryClientMock) PeerMinBlock(ctx context.Context, in *PeerMinBlockRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) { - callInfo := struct { - Ctx context.Context - In *PeerMinBlockRequest - Opts []grpc.CallOption - }{ - Ctx: ctx, - In: in, - Opts: opts, - } - mock.lockPeerMinBlock.Lock() - mock.calls.PeerMinBlock = append(mock.calls.PeerMinBlock, callInfo) - mock.lockPeerMinBlock.Unlock() - if mock.PeerMinBlockFunc == nil { - var ( - emptyOut *emptypb.Empty - errOut error - ) - return emptyOut, errOut - } - return mock.PeerMinBlockFunc(ctx, in, opts...) -} - -// PeerMinBlockCalls gets all the calls that were made to PeerMinBlock. -// Check the length with: -// -// len(mockedSentryClient.PeerMinBlockCalls()) -func (mock *SentryClientMock) PeerMinBlockCalls() []struct { - Ctx context.Context - In *PeerMinBlockRequest - Opts []grpc.CallOption -} { - var calls []struct { - Ctx context.Context - In *PeerMinBlockRequest - Opts []grpc.CallOption - } - mock.lockPeerMinBlock.RLock() - calls = mock.calls.PeerMinBlock - mock.lockPeerMinBlock.RUnlock() - return calls -} - -// Peers calls PeersFunc. -func (mock *SentryClientMock) Peers(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*PeersReply, error) { - callInfo := struct { - Ctx context.Context - In *emptypb.Empty - Opts []grpc.CallOption - }{ - Ctx: ctx, - In: in, - Opts: opts, - } - mock.lockPeers.Lock() - mock.calls.Peers = append(mock.calls.Peers, callInfo) - mock.lockPeers.Unlock() - if mock.PeersFunc == nil { - var ( - peersReplyOut *PeersReply - errOut error - ) - return peersReplyOut, errOut - } - return mock.PeersFunc(ctx, in, opts...) -} - -// PeersCalls gets all the calls that were made to Peers. -// Check the length with: -// -// len(mockedSentryClient.PeersCalls()) -func (mock *SentryClientMock) PeersCalls() []struct { - Ctx context.Context - In *emptypb.Empty - Opts []grpc.CallOption -} { - var calls []struct { - Ctx context.Context - In *emptypb.Empty - Opts []grpc.CallOption - } - mock.lockPeers.RLock() - calls = mock.calls.Peers - mock.lockPeers.RUnlock() - return calls -} - -// PenalizePeer calls PenalizePeerFunc. -func (mock *SentryClientMock) PenalizePeer(ctx context.Context, in *PenalizePeerRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) { - callInfo := struct { - Ctx context.Context - In *PenalizePeerRequest - Opts []grpc.CallOption - }{ - Ctx: ctx, - In: in, - Opts: opts, - } - mock.lockPenalizePeer.Lock() - mock.calls.PenalizePeer = append(mock.calls.PenalizePeer, callInfo) - mock.lockPenalizePeer.Unlock() - if mock.PenalizePeerFunc == nil { - var ( - emptyOut *emptypb.Empty - errOut error - ) - return emptyOut, errOut - } - return mock.PenalizePeerFunc(ctx, in, opts...) -} - -// PenalizePeerCalls gets all the calls that were made to PenalizePeer. -// Check the length with: -// -// len(mockedSentryClient.PenalizePeerCalls()) -func (mock *SentryClientMock) PenalizePeerCalls() []struct { - Ctx context.Context - In *PenalizePeerRequest - Opts []grpc.CallOption -} { - var calls []struct { - Ctx context.Context - In *PenalizePeerRequest - Opts []grpc.CallOption - } - mock.lockPenalizePeer.RLock() - calls = mock.calls.PenalizePeer - mock.lockPenalizePeer.RUnlock() - return calls -} - -// SendMessageById calls SendMessageByIdFunc. -func (mock *SentryClientMock) SendMessageById(ctx context.Context, in *SendMessageByIdRequest, opts ...grpc.CallOption) (*SentPeers, error) { - callInfo := struct { - Ctx context.Context - In *SendMessageByIdRequest - Opts []grpc.CallOption - }{ - Ctx: ctx, - In: in, - Opts: opts, - } - mock.lockSendMessageById.Lock() - mock.calls.SendMessageById = append(mock.calls.SendMessageById, callInfo) - mock.lockSendMessageById.Unlock() - if mock.SendMessageByIdFunc == nil { - var ( - sentPeersOut *SentPeers - errOut error - ) - return sentPeersOut, errOut - } - return mock.SendMessageByIdFunc(ctx, in, opts...) -} - -// SendMessageByIdCalls gets all the calls that were made to SendMessageById. -// Check the length with: -// -// len(mockedSentryClient.SendMessageByIdCalls()) -func (mock *SentryClientMock) SendMessageByIdCalls() []struct { - Ctx context.Context - In *SendMessageByIdRequest - Opts []grpc.CallOption -} { - var calls []struct { - Ctx context.Context - In *SendMessageByIdRequest - Opts []grpc.CallOption - } - mock.lockSendMessageById.RLock() - calls = mock.calls.SendMessageById - mock.lockSendMessageById.RUnlock() - return calls -} - -// SendMessageByMinBlock calls SendMessageByMinBlockFunc. -func (mock *SentryClientMock) SendMessageByMinBlock(ctx context.Context, in *SendMessageByMinBlockRequest, opts ...grpc.CallOption) (*SentPeers, error) { - callInfo := struct { - Ctx context.Context - In *SendMessageByMinBlockRequest - Opts []grpc.CallOption - }{ - Ctx: ctx, - In: in, - Opts: opts, - } - mock.lockSendMessageByMinBlock.Lock() - mock.calls.SendMessageByMinBlock = append(mock.calls.SendMessageByMinBlock, callInfo) - mock.lockSendMessageByMinBlock.Unlock() - if mock.SendMessageByMinBlockFunc == nil { - var ( - sentPeersOut *SentPeers - errOut error - ) - return sentPeersOut, errOut - } - return mock.SendMessageByMinBlockFunc(ctx, in, opts...) -} - -// SendMessageByMinBlockCalls gets all the calls that were made to SendMessageByMinBlock. -// Check the length with: -// -// len(mockedSentryClient.SendMessageByMinBlockCalls()) -func (mock *SentryClientMock) SendMessageByMinBlockCalls() []struct { - Ctx context.Context - In *SendMessageByMinBlockRequest - Opts []grpc.CallOption -} { - var calls []struct { - Ctx context.Context - In *SendMessageByMinBlockRequest - Opts []grpc.CallOption - } - mock.lockSendMessageByMinBlock.RLock() - calls = mock.calls.SendMessageByMinBlock - mock.lockSendMessageByMinBlock.RUnlock() - return calls -} - -// SendMessageToAll calls SendMessageToAllFunc. -func (mock *SentryClientMock) SendMessageToAll(ctx context.Context, in *OutboundMessageData, opts ...grpc.CallOption) (*SentPeers, error) { - callInfo := struct { - Ctx context.Context - In *OutboundMessageData - Opts []grpc.CallOption - }{ - Ctx: ctx, - In: in, - Opts: opts, - } - mock.lockSendMessageToAll.Lock() - mock.calls.SendMessageToAll = append(mock.calls.SendMessageToAll, callInfo) - mock.lockSendMessageToAll.Unlock() - if mock.SendMessageToAllFunc == nil { - var ( - sentPeersOut *SentPeers - errOut error - ) - return sentPeersOut, errOut - } - return mock.SendMessageToAllFunc(ctx, in, opts...) -} - -// SendMessageToAllCalls gets all the calls that were made to SendMessageToAll. -// Check the length with: -// -// len(mockedSentryClient.SendMessageToAllCalls()) -func (mock *SentryClientMock) SendMessageToAllCalls() []struct { - Ctx context.Context - In *OutboundMessageData - Opts []grpc.CallOption -} { - var calls []struct { - Ctx context.Context - In *OutboundMessageData - Opts []grpc.CallOption - } - mock.lockSendMessageToAll.RLock() - calls = mock.calls.SendMessageToAll - mock.lockSendMessageToAll.RUnlock() - return calls -} - -// SendMessageToRandomPeers calls SendMessageToRandomPeersFunc. -func (mock *SentryClientMock) SendMessageToRandomPeers(ctx context.Context, in *SendMessageToRandomPeersRequest, opts ...grpc.CallOption) (*SentPeers, error) { - callInfo := struct { - Ctx context.Context - In *SendMessageToRandomPeersRequest - Opts []grpc.CallOption - }{ - Ctx: ctx, - In: in, - Opts: opts, - } - mock.lockSendMessageToRandomPeers.Lock() - mock.calls.SendMessageToRandomPeers = append(mock.calls.SendMessageToRandomPeers, callInfo) - mock.lockSendMessageToRandomPeers.Unlock() - if mock.SendMessageToRandomPeersFunc == nil { - var ( - sentPeersOut *SentPeers - errOut error - ) - return sentPeersOut, errOut - } - return mock.SendMessageToRandomPeersFunc(ctx, in, opts...) -} - -// SendMessageToRandomPeersCalls gets all the calls that were made to SendMessageToRandomPeers. -// Check the length with: -// -// len(mockedSentryClient.SendMessageToRandomPeersCalls()) -func (mock *SentryClientMock) SendMessageToRandomPeersCalls() []struct { - Ctx context.Context - In *SendMessageToRandomPeersRequest - Opts []grpc.CallOption -} { - var calls []struct { - Ctx context.Context - In *SendMessageToRandomPeersRequest - Opts []grpc.CallOption - } - mock.lockSendMessageToRandomPeers.RLock() - calls = mock.calls.SendMessageToRandomPeers - mock.lockSendMessageToRandomPeers.RUnlock() - return calls -} - -// SetStatus calls SetStatusFunc. -func (mock *SentryClientMock) SetStatus(ctx context.Context, in *StatusData, opts ...grpc.CallOption) (*SetStatusReply, error) { - callInfo := struct { - Ctx context.Context - In *StatusData - Opts []grpc.CallOption - }{ - Ctx: ctx, - In: in, - Opts: opts, - } - mock.lockSetStatus.Lock() - mock.calls.SetStatus = append(mock.calls.SetStatus, callInfo) - mock.lockSetStatus.Unlock() - if mock.SetStatusFunc == nil { - var ( - setStatusReplyOut *SetStatusReply - errOut error - ) - return setStatusReplyOut, errOut - } - return mock.SetStatusFunc(ctx, in, opts...) -} - -// SetStatusCalls gets all the calls that were made to SetStatus. -// Check the length with: -// -// len(mockedSentryClient.SetStatusCalls()) -func (mock *SentryClientMock) SetStatusCalls() []struct { - Ctx context.Context - In *StatusData - Opts []grpc.CallOption -} { - var calls []struct { - Ctx context.Context - In *StatusData - Opts []grpc.CallOption - } - mock.lockSetStatus.RLock() - calls = mock.calls.SetStatus - mock.lockSetStatus.RUnlock() - return calls -} diff --git a/erigon-lib/gointerfaces/sentry/sentry_client_mock.go b/erigon-lib/gointerfaces/sentry/sentry_client_mock.go new file mode 100644 index 00000000000..f17b8731e8a --- /dev/null +++ b/erigon-lib/gointerfaces/sentry/sentry_client_mock.go @@ -0,0 +1,703 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/ledgerwatch/erigon-lib/gointerfaces/sentry (interfaces: SentryClient) +// +// Generated by this command: +// +// mockgen -typed=true -destination=./sentry_client_mock.go -package=sentry . SentryClient +// + +// Package sentry is a generated GoMock package. +package sentry + +import ( + context "context" + reflect "reflect" + + types "github.com/ledgerwatch/erigon-lib/gointerfaces/types" + gomock "go.uber.org/mock/gomock" + grpc "google.golang.org/grpc" + emptypb "google.golang.org/protobuf/types/known/emptypb" +) + +// MockSentryClient is a mock of SentryClient interface. +type MockSentryClient struct { + ctrl *gomock.Controller + recorder *MockSentryClientMockRecorder +} + +// MockSentryClientMockRecorder is the mock recorder for MockSentryClient. +type MockSentryClientMockRecorder struct { + mock *MockSentryClient +} + +// NewMockSentryClient creates a new mock instance. +func NewMockSentryClient(ctrl *gomock.Controller) *MockSentryClient { + mock := &MockSentryClient{ctrl: ctrl} + mock.recorder = &MockSentryClientMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockSentryClient) EXPECT() *MockSentryClientMockRecorder { + return m.recorder +} + +// AddPeer mocks base method. +func (m *MockSentryClient) AddPeer(arg0 context.Context, arg1 *AddPeerRequest, arg2 ...grpc.CallOption) (*AddPeerReply, error) { + m.ctrl.T.Helper() + varargs := []any{arg0, arg1} + for _, a := range arg2 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "AddPeer", varargs...) + ret0, _ := ret[0].(*AddPeerReply) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// AddPeer indicates an expected call of AddPeer. +func (mr *MockSentryClientMockRecorder) AddPeer(arg0, arg1 any, arg2 ...any) *MockSentryClientAddPeerCall { + mr.mock.ctrl.T.Helper() + varargs := append([]any{arg0, arg1}, arg2...) + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddPeer", reflect.TypeOf((*MockSentryClient)(nil).AddPeer), varargs...) + return &MockSentryClientAddPeerCall{Call: call} +} + +// MockSentryClientAddPeerCall wrap *gomock.Call +type MockSentryClientAddPeerCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockSentryClientAddPeerCall) Return(arg0 *AddPeerReply, arg1 error) *MockSentryClientAddPeerCall { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockSentryClientAddPeerCall) Do(f func(context.Context, *AddPeerRequest, ...grpc.CallOption) (*AddPeerReply, error)) *MockSentryClientAddPeerCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockSentryClientAddPeerCall) DoAndReturn(f func(context.Context, *AddPeerRequest, ...grpc.CallOption) (*AddPeerReply, error)) *MockSentryClientAddPeerCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// HandShake mocks base method. +func (m *MockSentryClient) HandShake(arg0 context.Context, arg1 *emptypb.Empty, arg2 ...grpc.CallOption) (*HandShakeReply, error) { + m.ctrl.T.Helper() + varargs := []any{arg0, arg1} + for _, a := range arg2 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "HandShake", varargs...) + ret0, _ := ret[0].(*HandShakeReply) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// HandShake indicates an expected call of HandShake. +func (mr *MockSentryClientMockRecorder) HandShake(arg0, arg1 any, arg2 ...any) *MockSentryClientHandShakeCall { + mr.mock.ctrl.T.Helper() + varargs := append([]any{arg0, arg1}, arg2...) + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HandShake", reflect.TypeOf((*MockSentryClient)(nil).HandShake), varargs...) + return &MockSentryClientHandShakeCall{Call: call} +} + +// MockSentryClientHandShakeCall wrap *gomock.Call +type MockSentryClientHandShakeCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockSentryClientHandShakeCall) Return(arg0 *HandShakeReply, arg1 error) *MockSentryClientHandShakeCall { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockSentryClientHandShakeCall) Do(f func(context.Context, *emptypb.Empty, ...grpc.CallOption) (*HandShakeReply, error)) *MockSentryClientHandShakeCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockSentryClientHandShakeCall) DoAndReturn(f func(context.Context, *emptypb.Empty, ...grpc.CallOption) (*HandShakeReply, error)) *MockSentryClientHandShakeCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Messages mocks base method. +func (m *MockSentryClient) Messages(arg0 context.Context, arg1 *MessagesRequest, arg2 ...grpc.CallOption) (Sentry_MessagesClient, error) { + m.ctrl.T.Helper() + varargs := []any{arg0, arg1} + for _, a := range arg2 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Messages", varargs...) + ret0, _ := ret[0].(Sentry_MessagesClient) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Messages indicates an expected call of Messages. +func (mr *MockSentryClientMockRecorder) Messages(arg0, arg1 any, arg2 ...any) *MockSentryClientMessagesCall { + mr.mock.ctrl.T.Helper() + varargs := append([]any{arg0, arg1}, arg2...) + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Messages", reflect.TypeOf((*MockSentryClient)(nil).Messages), varargs...) + return &MockSentryClientMessagesCall{Call: call} +} + +// MockSentryClientMessagesCall wrap *gomock.Call +type MockSentryClientMessagesCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockSentryClientMessagesCall) Return(arg0 Sentry_MessagesClient, arg1 error) *MockSentryClientMessagesCall { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockSentryClientMessagesCall) Do(f func(context.Context, *MessagesRequest, ...grpc.CallOption) (Sentry_MessagesClient, error)) *MockSentryClientMessagesCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockSentryClientMessagesCall) DoAndReturn(f func(context.Context, *MessagesRequest, ...grpc.CallOption) (Sentry_MessagesClient, error)) *MockSentryClientMessagesCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// NodeInfo mocks base method. +func (m *MockSentryClient) NodeInfo(arg0 context.Context, arg1 *emptypb.Empty, arg2 ...grpc.CallOption) (*types.NodeInfoReply, error) { + m.ctrl.T.Helper() + varargs := []any{arg0, arg1} + for _, a := range arg2 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "NodeInfo", varargs...) + ret0, _ := ret[0].(*types.NodeInfoReply) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// NodeInfo indicates an expected call of NodeInfo. +func (mr *MockSentryClientMockRecorder) NodeInfo(arg0, arg1 any, arg2 ...any) *MockSentryClientNodeInfoCall { + mr.mock.ctrl.T.Helper() + varargs := append([]any{arg0, arg1}, arg2...) + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NodeInfo", reflect.TypeOf((*MockSentryClient)(nil).NodeInfo), varargs...) + return &MockSentryClientNodeInfoCall{Call: call} +} + +// MockSentryClientNodeInfoCall wrap *gomock.Call +type MockSentryClientNodeInfoCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockSentryClientNodeInfoCall) Return(arg0 *types.NodeInfoReply, arg1 error) *MockSentryClientNodeInfoCall { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockSentryClientNodeInfoCall) Do(f func(context.Context, *emptypb.Empty, ...grpc.CallOption) (*types.NodeInfoReply, error)) *MockSentryClientNodeInfoCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockSentryClientNodeInfoCall) DoAndReturn(f func(context.Context, *emptypb.Empty, ...grpc.CallOption) (*types.NodeInfoReply, error)) *MockSentryClientNodeInfoCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// PeerById mocks base method. +func (m *MockSentryClient) PeerById(arg0 context.Context, arg1 *PeerByIdRequest, arg2 ...grpc.CallOption) (*PeerByIdReply, error) { + m.ctrl.T.Helper() + varargs := []any{arg0, arg1} + for _, a := range arg2 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "PeerById", varargs...) + ret0, _ := ret[0].(*PeerByIdReply) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// PeerById indicates an expected call of PeerById. +func (mr *MockSentryClientMockRecorder) PeerById(arg0, arg1 any, arg2 ...any) *MockSentryClientPeerByIdCall { + mr.mock.ctrl.T.Helper() + varargs := append([]any{arg0, arg1}, arg2...) + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PeerById", reflect.TypeOf((*MockSentryClient)(nil).PeerById), varargs...) + return &MockSentryClientPeerByIdCall{Call: call} +} + +// MockSentryClientPeerByIdCall wrap *gomock.Call +type MockSentryClientPeerByIdCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockSentryClientPeerByIdCall) Return(arg0 *PeerByIdReply, arg1 error) *MockSentryClientPeerByIdCall { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockSentryClientPeerByIdCall) Do(f func(context.Context, *PeerByIdRequest, ...grpc.CallOption) (*PeerByIdReply, error)) *MockSentryClientPeerByIdCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockSentryClientPeerByIdCall) DoAndReturn(f func(context.Context, *PeerByIdRequest, ...grpc.CallOption) (*PeerByIdReply, error)) *MockSentryClientPeerByIdCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// PeerCount mocks base method. +func (m *MockSentryClient) PeerCount(arg0 context.Context, arg1 *PeerCountRequest, arg2 ...grpc.CallOption) (*PeerCountReply, error) { + m.ctrl.T.Helper() + varargs := []any{arg0, arg1} + for _, a := range arg2 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "PeerCount", varargs...) + ret0, _ := ret[0].(*PeerCountReply) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// PeerCount indicates an expected call of PeerCount. +func (mr *MockSentryClientMockRecorder) PeerCount(arg0, arg1 any, arg2 ...any) *MockSentryClientPeerCountCall { + mr.mock.ctrl.T.Helper() + varargs := append([]any{arg0, arg1}, arg2...) + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PeerCount", reflect.TypeOf((*MockSentryClient)(nil).PeerCount), varargs...) + return &MockSentryClientPeerCountCall{Call: call} +} + +// MockSentryClientPeerCountCall wrap *gomock.Call +type MockSentryClientPeerCountCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockSentryClientPeerCountCall) Return(arg0 *PeerCountReply, arg1 error) *MockSentryClientPeerCountCall { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockSentryClientPeerCountCall) Do(f func(context.Context, *PeerCountRequest, ...grpc.CallOption) (*PeerCountReply, error)) *MockSentryClientPeerCountCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockSentryClientPeerCountCall) DoAndReturn(f func(context.Context, *PeerCountRequest, ...grpc.CallOption) (*PeerCountReply, error)) *MockSentryClientPeerCountCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// PeerEvents mocks base method. +func (m *MockSentryClient) PeerEvents(arg0 context.Context, arg1 *PeerEventsRequest, arg2 ...grpc.CallOption) (Sentry_PeerEventsClient, error) { + m.ctrl.T.Helper() + varargs := []any{arg0, arg1} + for _, a := range arg2 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "PeerEvents", varargs...) + ret0, _ := ret[0].(Sentry_PeerEventsClient) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// PeerEvents indicates an expected call of PeerEvents. +func (mr *MockSentryClientMockRecorder) PeerEvents(arg0, arg1 any, arg2 ...any) *MockSentryClientPeerEventsCall { + mr.mock.ctrl.T.Helper() + varargs := append([]any{arg0, arg1}, arg2...) + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PeerEvents", reflect.TypeOf((*MockSentryClient)(nil).PeerEvents), varargs...) + return &MockSentryClientPeerEventsCall{Call: call} +} + +// MockSentryClientPeerEventsCall wrap *gomock.Call +type MockSentryClientPeerEventsCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockSentryClientPeerEventsCall) Return(arg0 Sentry_PeerEventsClient, arg1 error) *MockSentryClientPeerEventsCall { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockSentryClientPeerEventsCall) Do(f func(context.Context, *PeerEventsRequest, ...grpc.CallOption) (Sentry_PeerEventsClient, error)) *MockSentryClientPeerEventsCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockSentryClientPeerEventsCall) DoAndReturn(f func(context.Context, *PeerEventsRequest, ...grpc.CallOption) (Sentry_PeerEventsClient, error)) *MockSentryClientPeerEventsCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// PeerMinBlock mocks base method. +func (m *MockSentryClient) PeerMinBlock(arg0 context.Context, arg1 *PeerMinBlockRequest, arg2 ...grpc.CallOption) (*emptypb.Empty, error) { + m.ctrl.T.Helper() + varargs := []any{arg0, arg1} + for _, a := range arg2 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "PeerMinBlock", varargs...) + ret0, _ := ret[0].(*emptypb.Empty) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// PeerMinBlock indicates an expected call of PeerMinBlock. +func (mr *MockSentryClientMockRecorder) PeerMinBlock(arg0, arg1 any, arg2 ...any) *MockSentryClientPeerMinBlockCall { + mr.mock.ctrl.T.Helper() + varargs := append([]any{arg0, arg1}, arg2...) + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PeerMinBlock", reflect.TypeOf((*MockSentryClient)(nil).PeerMinBlock), varargs...) + return &MockSentryClientPeerMinBlockCall{Call: call} +} + +// MockSentryClientPeerMinBlockCall wrap *gomock.Call +type MockSentryClientPeerMinBlockCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockSentryClientPeerMinBlockCall) Return(arg0 *emptypb.Empty, arg1 error) *MockSentryClientPeerMinBlockCall { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockSentryClientPeerMinBlockCall) Do(f func(context.Context, *PeerMinBlockRequest, ...grpc.CallOption) (*emptypb.Empty, error)) *MockSentryClientPeerMinBlockCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockSentryClientPeerMinBlockCall) DoAndReturn(f func(context.Context, *PeerMinBlockRequest, ...grpc.CallOption) (*emptypb.Empty, error)) *MockSentryClientPeerMinBlockCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Peers mocks base method. +func (m *MockSentryClient) Peers(arg0 context.Context, arg1 *emptypb.Empty, arg2 ...grpc.CallOption) (*PeersReply, error) { + m.ctrl.T.Helper() + varargs := []any{arg0, arg1} + for _, a := range arg2 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Peers", varargs...) + ret0, _ := ret[0].(*PeersReply) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Peers indicates an expected call of Peers. +func (mr *MockSentryClientMockRecorder) Peers(arg0, arg1 any, arg2 ...any) *MockSentryClientPeersCall { + mr.mock.ctrl.T.Helper() + varargs := append([]any{arg0, arg1}, arg2...) + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Peers", reflect.TypeOf((*MockSentryClient)(nil).Peers), varargs...) + return &MockSentryClientPeersCall{Call: call} +} + +// MockSentryClientPeersCall wrap *gomock.Call +type MockSentryClientPeersCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockSentryClientPeersCall) Return(arg0 *PeersReply, arg1 error) *MockSentryClientPeersCall { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockSentryClientPeersCall) Do(f func(context.Context, *emptypb.Empty, ...grpc.CallOption) (*PeersReply, error)) *MockSentryClientPeersCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockSentryClientPeersCall) DoAndReturn(f func(context.Context, *emptypb.Empty, ...grpc.CallOption) (*PeersReply, error)) *MockSentryClientPeersCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// PenalizePeer mocks base method. +func (m *MockSentryClient) PenalizePeer(arg0 context.Context, arg1 *PenalizePeerRequest, arg2 ...grpc.CallOption) (*emptypb.Empty, error) { + m.ctrl.T.Helper() + varargs := []any{arg0, arg1} + for _, a := range arg2 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "PenalizePeer", varargs...) + ret0, _ := ret[0].(*emptypb.Empty) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// PenalizePeer indicates an expected call of PenalizePeer. +func (mr *MockSentryClientMockRecorder) PenalizePeer(arg0, arg1 any, arg2 ...any) *MockSentryClientPenalizePeerCall { + mr.mock.ctrl.T.Helper() + varargs := append([]any{arg0, arg1}, arg2...) + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PenalizePeer", reflect.TypeOf((*MockSentryClient)(nil).PenalizePeer), varargs...) + return &MockSentryClientPenalizePeerCall{Call: call} +} + +// MockSentryClientPenalizePeerCall wrap *gomock.Call +type MockSentryClientPenalizePeerCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockSentryClientPenalizePeerCall) Return(arg0 *emptypb.Empty, arg1 error) *MockSentryClientPenalizePeerCall { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockSentryClientPenalizePeerCall) Do(f func(context.Context, *PenalizePeerRequest, ...grpc.CallOption) (*emptypb.Empty, error)) *MockSentryClientPenalizePeerCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockSentryClientPenalizePeerCall) DoAndReturn(f func(context.Context, *PenalizePeerRequest, ...grpc.CallOption) (*emptypb.Empty, error)) *MockSentryClientPenalizePeerCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// SendMessageById mocks base method. +func (m *MockSentryClient) SendMessageById(arg0 context.Context, arg1 *SendMessageByIdRequest, arg2 ...grpc.CallOption) (*SentPeers, error) { + m.ctrl.T.Helper() + varargs := []any{arg0, arg1} + for _, a := range arg2 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "SendMessageById", varargs...) + ret0, _ := ret[0].(*SentPeers) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// SendMessageById indicates an expected call of SendMessageById. +func (mr *MockSentryClientMockRecorder) SendMessageById(arg0, arg1 any, arg2 ...any) *MockSentryClientSendMessageByIdCall { + mr.mock.ctrl.T.Helper() + varargs := append([]any{arg0, arg1}, arg2...) + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendMessageById", reflect.TypeOf((*MockSentryClient)(nil).SendMessageById), varargs...) + return &MockSentryClientSendMessageByIdCall{Call: call} +} + +// MockSentryClientSendMessageByIdCall wrap *gomock.Call +type MockSentryClientSendMessageByIdCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockSentryClientSendMessageByIdCall) Return(arg0 *SentPeers, arg1 error) *MockSentryClientSendMessageByIdCall { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockSentryClientSendMessageByIdCall) Do(f func(context.Context, *SendMessageByIdRequest, ...grpc.CallOption) (*SentPeers, error)) *MockSentryClientSendMessageByIdCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockSentryClientSendMessageByIdCall) DoAndReturn(f func(context.Context, *SendMessageByIdRequest, ...grpc.CallOption) (*SentPeers, error)) *MockSentryClientSendMessageByIdCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// SendMessageByMinBlock mocks base method. +func (m *MockSentryClient) SendMessageByMinBlock(arg0 context.Context, arg1 *SendMessageByMinBlockRequest, arg2 ...grpc.CallOption) (*SentPeers, error) { + m.ctrl.T.Helper() + varargs := []any{arg0, arg1} + for _, a := range arg2 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "SendMessageByMinBlock", varargs...) + ret0, _ := ret[0].(*SentPeers) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// SendMessageByMinBlock indicates an expected call of SendMessageByMinBlock. +func (mr *MockSentryClientMockRecorder) SendMessageByMinBlock(arg0, arg1 any, arg2 ...any) *MockSentryClientSendMessageByMinBlockCall { + mr.mock.ctrl.T.Helper() + varargs := append([]any{arg0, arg1}, arg2...) + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendMessageByMinBlock", reflect.TypeOf((*MockSentryClient)(nil).SendMessageByMinBlock), varargs...) + return &MockSentryClientSendMessageByMinBlockCall{Call: call} +} + +// MockSentryClientSendMessageByMinBlockCall wrap *gomock.Call +type MockSentryClientSendMessageByMinBlockCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockSentryClientSendMessageByMinBlockCall) Return(arg0 *SentPeers, arg1 error) *MockSentryClientSendMessageByMinBlockCall { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockSentryClientSendMessageByMinBlockCall) Do(f func(context.Context, *SendMessageByMinBlockRequest, ...grpc.CallOption) (*SentPeers, error)) *MockSentryClientSendMessageByMinBlockCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockSentryClientSendMessageByMinBlockCall) DoAndReturn(f func(context.Context, *SendMessageByMinBlockRequest, ...grpc.CallOption) (*SentPeers, error)) *MockSentryClientSendMessageByMinBlockCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// SendMessageToAll mocks base method. +func (m *MockSentryClient) SendMessageToAll(arg0 context.Context, arg1 *OutboundMessageData, arg2 ...grpc.CallOption) (*SentPeers, error) { + m.ctrl.T.Helper() + varargs := []any{arg0, arg1} + for _, a := range arg2 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "SendMessageToAll", varargs...) + ret0, _ := ret[0].(*SentPeers) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// SendMessageToAll indicates an expected call of SendMessageToAll. +func (mr *MockSentryClientMockRecorder) SendMessageToAll(arg0, arg1 any, arg2 ...any) *MockSentryClientSendMessageToAllCall { + mr.mock.ctrl.T.Helper() + varargs := append([]any{arg0, arg1}, arg2...) + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendMessageToAll", reflect.TypeOf((*MockSentryClient)(nil).SendMessageToAll), varargs...) + return &MockSentryClientSendMessageToAllCall{Call: call} +} + +// MockSentryClientSendMessageToAllCall wrap *gomock.Call +type MockSentryClientSendMessageToAllCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockSentryClientSendMessageToAllCall) Return(arg0 *SentPeers, arg1 error) *MockSentryClientSendMessageToAllCall { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockSentryClientSendMessageToAllCall) Do(f func(context.Context, *OutboundMessageData, ...grpc.CallOption) (*SentPeers, error)) *MockSentryClientSendMessageToAllCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockSentryClientSendMessageToAllCall) DoAndReturn(f func(context.Context, *OutboundMessageData, ...grpc.CallOption) (*SentPeers, error)) *MockSentryClientSendMessageToAllCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// SendMessageToRandomPeers mocks base method. +func (m *MockSentryClient) SendMessageToRandomPeers(arg0 context.Context, arg1 *SendMessageToRandomPeersRequest, arg2 ...grpc.CallOption) (*SentPeers, error) { + m.ctrl.T.Helper() + varargs := []any{arg0, arg1} + for _, a := range arg2 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "SendMessageToRandomPeers", varargs...) + ret0, _ := ret[0].(*SentPeers) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// SendMessageToRandomPeers indicates an expected call of SendMessageToRandomPeers. +func (mr *MockSentryClientMockRecorder) SendMessageToRandomPeers(arg0, arg1 any, arg2 ...any) *MockSentryClientSendMessageToRandomPeersCall { + mr.mock.ctrl.T.Helper() + varargs := append([]any{arg0, arg1}, arg2...) + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendMessageToRandomPeers", reflect.TypeOf((*MockSentryClient)(nil).SendMessageToRandomPeers), varargs...) + return &MockSentryClientSendMessageToRandomPeersCall{Call: call} +} + +// MockSentryClientSendMessageToRandomPeersCall wrap *gomock.Call +type MockSentryClientSendMessageToRandomPeersCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockSentryClientSendMessageToRandomPeersCall) Return(arg0 *SentPeers, arg1 error) *MockSentryClientSendMessageToRandomPeersCall { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockSentryClientSendMessageToRandomPeersCall) Do(f func(context.Context, *SendMessageToRandomPeersRequest, ...grpc.CallOption) (*SentPeers, error)) *MockSentryClientSendMessageToRandomPeersCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockSentryClientSendMessageToRandomPeersCall) DoAndReturn(f func(context.Context, *SendMessageToRandomPeersRequest, ...grpc.CallOption) (*SentPeers, error)) *MockSentryClientSendMessageToRandomPeersCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// SetStatus mocks base method. +func (m *MockSentryClient) SetStatus(arg0 context.Context, arg1 *StatusData, arg2 ...grpc.CallOption) (*SetStatusReply, error) { + m.ctrl.T.Helper() + varargs := []any{arg0, arg1} + for _, a := range arg2 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "SetStatus", varargs...) + ret0, _ := ret[0].(*SetStatusReply) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// SetStatus indicates an expected call of SetStatus. +func (mr *MockSentryClientMockRecorder) SetStatus(arg0, arg1 any, arg2 ...any) *MockSentryClientSetStatusCall { + mr.mock.ctrl.T.Helper() + varargs := append([]any{arg0, arg1}, arg2...) + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetStatus", reflect.TypeOf((*MockSentryClient)(nil).SetStatus), varargs...) + return &MockSentryClientSetStatusCall{Call: call} +} + +// MockSentryClientSetStatusCall wrap *gomock.Call +type MockSentryClientSetStatusCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockSentryClientSetStatusCall) Return(arg0 *SetStatusReply, arg1 error) *MockSentryClientSetStatusCall { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockSentryClientSetStatusCall) Do(f func(context.Context, *StatusData, ...grpc.CallOption) (*SetStatusReply, error)) *MockSentryClientSetStatusCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockSentryClientSetStatusCall) DoAndReturn(f func(context.Context, *StatusData, ...grpc.CallOption) (*SetStatusReply, error)) *MockSentryClientSetStatusCall { + c.Call = c.Call.DoAndReturn(f) + return c +} diff --git a/erigon-lib/gointerfaces/sentry/sentry_server_mock.go b/erigon-lib/gointerfaces/sentry/sentry_server_mock.go new file mode 100644 index 00000000000..b8b7c87039c --- /dev/null +++ b/erigon-lib/gointerfaces/sentry/sentry_server_mock.go @@ -0,0 +1,661 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/ledgerwatch/erigon-lib/gointerfaces/sentry (interfaces: SentryServer) +// +// Generated by this command: +// +// mockgen -typed=true -destination=./sentry_server_mock.go -package=sentry . SentryServer +// + +// Package sentry is a generated GoMock package. +package sentry + +import ( + context "context" + reflect "reflect" + + types "github.com/ledgerwatch/erigon-lib/gointerfaces/types" + gomock "go.uber.org/mock/gomock" + emptypb "google.golang.org/protobuf/types/known/emptypb" +) + +// MockSentryServer is a mock of SentryServer interface. +type MockSentryServer struct { + ctrl *gomock.Controller + recorder *MockSentryServerMockRecorder +} + +// MockSentryServerMockRecorder is the mock recorder for MockSentryServer. +type MockSentryServerMockRecorder struct { + mock *MockSentryServer +} + +// NewMockSentryServer creates a new mock instance. +func NewMockSentryServer(ctrl *gomock.Controller) *MockSentryServer { + mock := &MockSentryServer{ctrl: ctrl} + mock.recorder = &MockSentryServerMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockSentryServer) EXPECT() *MockSentryServerMockRecorder { + return m.recorder +} + +// AddPeer mocks base method. +func (m *MockSentryServer) AddPeer(arg0 context.Context, arg1 *AddPeerRequest) (*AddPeerReply, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddPeer", arg0, arg1) + ret0, _ := ret[0].(*AddPeerReply) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// AddPeer indicates an expected call of AddPeer. +func (mr *MockSentryServerMockRecorder) AddPeer(arg0, arg1 any) *MockSentryServerAddPeerCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddPeer", reflect.TypeOf((*MockSentryServer)(nil).AddPeer), arg0, arg1) + return &MockSentryServerAddPeerCall{Call: call} +} + +// MockSentryServerAddPeerCall wrap *gomock.Call +type MockSentryServerAddPeerCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockSentryServerAddPeerCall) Return(arg0 *AddPeerReply, arg1 error) *MockSentryServerAddPeerCall { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockSentryServerAddPeerCall) Do(f func(context.Context, *AddPeerRequest) (*AddPeerReply, error)) *MockSentryServerAddPeerCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockSentryServerAddPeerCall) DoAndReturn(f func(context.Context, *AddPeerRequest) (*AddPeerReply, error)) *MockSentryServerAddPeerCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// HandShake mocks base method. +func (m *MockSentryServer) HandShake(arg0 context.Context, arg1 *emptypb.Empty) (*HandShakeReply, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "HandShake", arg0, arg1) + ret0, _ := ret[0].(*HandShakeReply) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// HandShake indicates an expected call of HandShake. +func (mr *MockSentryServerMockRecorder) HandShake(arg0, arg1 any) *MockSentryServerHandShakeCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HandShake", reflect.TypeOf((*MockSentryServer)(nil).HandShake), arg0, arg1) + return &MockSentryServerHandShakeCall{Call: call} +} + +// MockSentryServerHandShakeCall wrap *gomock.Call +type MockSentryServerHandShakeCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockSentryServerHandShakeCall) Return(arg0 *HandShakeReply, arg1 error) *MockSentryServerHandShakeCall { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockSentryServerHandShakeCall) Do(f func(context.Context, *emptypb.Empty) (*HandShakeReply, error)) *MockSentryServerHandShakeCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockSentryServerHandShakeCall) DoAndReturn(f func(context.Context, *emptypb.Empty) (*HandShakeReply, error)) *MockSentryServerHandShakeCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Messages mocks base method. +func (m *MockSentryServer) Messages(arg0 *MessagesRequest, arg1 Sentry_MessagesServer) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Messages", arg0, arg1) + ret0, _ := ret[0].(error) + return ret0 +} + +// Messages indicates an expected call of Messages. +func (mr *MockSentryServerMockRecorder) Messages(arg0, arg1 any) *MockSentryServerMessagesCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Messages", reflect.TypeOf((*MockSentryServer)(nil).Messages), arg0, arg1) + return &MockSentryServerMessagesCall{Call: call} +} + +// MockSentryServerMessagesCall wrap *gomock.Call +type MockSentryServerMessagesCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockSentryServerMessagesCall) Return(arg0 error) *MockSentryServerMessagesCall { + c.Call = c.Call.Return(arg0) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockSentryServerMessagesCall) Do(f func(*MessagesRequest, Sentry_MessagesServer) error) *MockSentryServerMessagesCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockSentryServerMessagesCall) DoAndReturn(f func(*MessagesRequest, Sentry_MessagesServer) error) *MockSentryServerMessagesCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// NodeInfo mocks base method. +func (m *MockSentryServer) NodeInfo(arg0 context.Context, arg1 *emptypb.Empty) (*types.NodeInfoReply, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NodeInfo", arg0, arg1) + ret0, _ := ret[0].(*types.NodeInfoReply) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// NodeInfo indicates an expected call of NodeInfo. +func (mr *MockSentryServerMockRecorder) NodeInfo(arg0, arg1 any) *MockSentryServerNodeInfoCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NodeInfo", reflect.TypeOf((*MockSentryServer)(nil).NodeInfo), arg0, arg1) + return &MockSentryServerNodeInfoCall{Call: call} +} + +// MockSentryServerNodeInfoCall wrap *gomock.Call +type MockSentryServerNodeInfoCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockSentryServerNodeInfoCall) Return(arg0 *types.NodeInfoReply, arg1 error) *MockSentryServerNodeInfoCall { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockSentryServerNodeInfoCall) Do(f func(context.Context, *emptypb.Empty) (*types.NodeInfoReply, error)) *MockSentryServerNodeInfoCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockSentryServerNodeInfoCall) DoAndReturn(f func(context.Context, *emptypb.Empty) (*types.NodeInfoReply, error)) *MockSentryServerNodeInfoCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// PeerById mocks base method. +func (m *MockSentryServer) PeerById(arg0 context.Context, arg1 *PeerByIdRequest) (*PeerByIdReply, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "PeerById", arg0, arg1) + ret0, _ := ret[0].(*PeerByIdReply) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// PeerById indicates an expected call of PeerById. +func (mr *MockSentryServerMockRecorder) PeerById(arg0, arg1 any) *MockSentryServerPeerByIdCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PeerById", reflect.TypeOf((*MockSentryServer)(nil).PeerById), arg0, arg1) + return &MockSentryServerPeerByIdCall{Call: call} +} + +// MockSentryServerPeerByIdCall wrap *gomock.Call +type MockSentryServerPeerByIdCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockSentryServerPeerByIdCall) Return(arg0 *PeerByIdReply, arg1 error) *MockSentryServerPeerByIdCall { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockSentryServerPeerByIdCall) Do(f func(context.Context, *PeerByIdRequest) (*PeerByIdReply, error)) *MockSentryServerPeerByIdCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockSentryServerPeerByIdCall) DoAndReturn(f func(context.Context, *PeerByIdRequest) (*PeerByIdReply, error)) *MockSentryServerPeerByIdCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// PeerCount mocks base method. +func (m *MockSentryServer) PeerCount(arg0 context.Context, arg1 *PeerCountRequest) (*PeerCountReply, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "PeerCount", arg0, arg1) + ret0, _ := ret[0].(*PeerCountReply) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// PeerCount indicates an expected call of PeerCount. +func (mr *MockSentryServerMockRecorder) PeerCount(arg0, arg1 any) *MockSentryServerPeerCountCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PeerCount", reflect.TypeOf((*MockSentryServer)(nil).PeerCount), arg0, arg1) + return &MockSentryServerPeerCountCall{Call: call} +} + +// MockSentryServerPeerCountCall wrap *gomock.Call +type MockSentryServerPeerCountCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockSentryServerPeerCountCall) Return(arg0 *PeerCountReply, arg1 error) *MockSentryServerPeerCountCall { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockSentryServerPeerCountCall) Do(f func(context.Context, *PeerCountRequest) (*PeerCountReply, error)) *MockSentryServerPeerCountCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockSentryServerPeerCountCall) DoAndReturn(f func(context.Context, *PeerCountRequest) (*PeerCountReply, error)) *MockSentryServerPeerCountCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// PeerEvents mocks base method. +func (m *MockSentryServer) PeerEvents(arg0 *PeerEventsRequest, arg1 Sentry_PeerEventsServer) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "PeerEvents", arg0, arg1) + ret0, _ := ret[0].(error) + return ret0 +} + +// PeerEvents indicates an expected call of PeerEvents. +func (mr *MockSentryServerMockRecorder) PeerEvents(arg0, arg1 any) *MockSentryServerPeerEventsCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PeerEvents", reflect.TypeOf((*MockSentryServer)(nil).PeerEvents), arg0, arg1) + return &MockSentryServerPeerEventsCall{Call: call} +} + +// MockSentryServerPeerEventsCall wrap *gomock.Call +type MockSentryServerPeerEventsCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockSentryServerPeerEventsCall) Return(arg0 error) *MockSentryServerPeerEventsCall { + c.Call = c.Call.Return(arg0) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockSentryServerPeerEventsCall) Do(f func(*PeerEventsRequest, Sentry_PeerEventsServer) error) *MockSentryServerPeerEventsCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockSentryServerPeerEventsCall) DoAndReturn(f func(*PeerEventsRequest, Sentry_PeerEventsServer) error) *MockSentryServerPeerEventsCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// PeerMinBlock mocks base method. +func (m *MockSentryServer) PeerMinBlock(arg0 context.Context, arg1 *PeerMinBlockRequest) (*emptypb.Empty, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "PeerMinBlock", arg0, arg1) + ret0, _ := ret[0].(*emptypb.Empty) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// PeerMinBlock indicates an expected call of PeerMinBlock. +func (mr *MockSentryServerMockRecorder) PeerMinBlock(arg0, arg1 any) *MockSentryServerPeerMinBlockCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PeerMinBlock", reflect.TypeOf((*MockSentryServer)(nil).PeerMinBlock), arg0, arg1) + return &MockSentryServerPeerMinBlockCall{Call: call} +} + +// MockSentryServerPeerMinBlockCall wrap *gomock.Call +type MockSentryServerPeerMinBlockCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockSentryServerPeerMinBlockCall) Return(arg0 *emptypb.Empty, arg1 error) *MockSentryServerPeerMinBlockCall { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockSentryServerPeerMinBlockCall) Do(f func(context.Context, *PeerMinBlockRequest) (*emptypb.Empty, error)) *MockSentryServerPeerMinBlockCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockSentryServerPeerMinBlockCall) DoAndReturn(f func(context.Context, *PeerMinBlockRequest) (*emptypb.Empty, error)) *MockSentryServerPeerMinBlockCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Peers mocks base method. +func (m *MockSentryServer) Peers(arg0 context.Context, arg1 *emptypb.Empty) (*PeersReply, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Peers", arg0, arg1) + ret0, _ := ret[0].(*PeersReply) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Peers indicates an expected call of Peers. +func (mr *MockSentryServerMockRecorder) Peers(arg0, arg1 any) *MockSentryServerPeersCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Peers", reflect.TypeOf((*MockSentryServer)(nil).Peers), arg0, arg1) + return &MockSentryServerPeersCall{Call: call} +} + +// MockSentryServerPeersCall wrap *gomock.Call +type MockSentryServerPeersCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockSentryServerPeersCall) Return(arg0 *PeersReply, arg1 error) *MockSentryServerPeersCall { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockSentryServerPeersCall) Do(f func(context.Context, *emptypb.Empty) (*PeersReply, error)) *MockSentryServerPeersCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockSentryServerPeersCall) DoAndReturn(f func(context.Context, *emptypb.Empty) (*PeersReply, error)) *MockSentryServerPeersCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// PenalizePeer mocks base method. +func (m *MockSentryServer) PenalizePeer(arg0 context.Context, arg1 *PenalizePeerRequest) (*emptypb.Empty, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "PenalizePeer", arg0, arg1) + ret0, _ := ret[0].(*emptypb.Empty) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// PenalizePeer indicates an expected call of PenalizePeer. +func (mr *MockSentryServerMockRecorder) PenalizePeer(arg0, arg1 any) *MockSentryServerPenalizePeerCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PenalizePeer", reflect.TypeOf((*MockSentryServer)(nil).PenalizePeer), arg0, arg1) + return &MockSentryServerPenalizePeerCall{Call: call} +} + +// MockSentryServerPenalizePeerCall wrap *gomock.Call +type MockSentryServerPenalizePeerCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockSentryServerPenalizePeerCall) Return(arg0 *emptypb.Empty, arg1 error) *MockSentryServerPenalizePeerCall { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockSentryServerPenalizePeerCall) Do(f func(context.Context, *PenalizePeerRequest) (*emptypb.Empty, error)) *MockSentryServerPenalizePeerCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockSentryServerPenalizePeerCall) DoAndReturn(f func(context.Context, *PenalizePeerRequest) (*emptypb.Empty, error)) *MockSentryServerPenalizePeerCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// SendMessageById mocks base method. +func (m *MockSentryServer) SendMessageById(arg0 context.Context, arg1 *SendMessageByIdRequest) (*SentPeers, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SendMessageById", arg0, arg1) + ret0, _ := ret[0].(*SentPeers) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// SendMessageById indicates an expected call of SendMessageById. +func (mr *MockSentryServerMockRecorder) SendMessageById(arg0, arg1 any) *MockSentryServerSendMessageByIdCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendMessageById", reflect.TypeOf((*MockSentryServer)(nil).SendMessageById), arg0, arg1) + return &MockSentryServerSendMessageByIdCall{Call: call} +} + +// MockSentryServerSendMessageByIdCall wrap *gomock.Call +type MockSentryServerSendMessageByIdCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockSentryServerSendMessageByIdCall) Return(arg0 *SentPeers, arg1 error) *MockSentryServerSendMessageByIdCall { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockSentryServerSendMessageByIdCall) Do(f func(context.Context, *SendMessageByIdRequest) (*SentPeers, error)) *MockSentryServerSendMessageByIdCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockSentryServerSendMessageByIdCall) DoAndReturn(f func(context.Context, *SendMessageByIdRequest) (*SentPeers, error)) *MockSentryServerSendMessageByIdCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// SendMessageByMinBlock mocks base method. +func (m *MockSentryServer) SendMessageByMinBlock(arg0 context.Context, arg1 *SendMessageByMinBlockRequest) (*SentPeers, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SendMessageByMinBlock", arg0, arg1) + ret0, _ := ret[0].(*SentPeers) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// SendMessageByMinBlock indicates an expected call of SendMessageByMinBlock. +func (mr *MockSentryServerMockRecorder) SendMessageByMinBlock(arg0, arg1 any) *MockSentryServerSendMessageByMinBlockCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendMessageByMinBlock", reflect.TypeOf((*MockSentryServer)(nil).SendMessageByMinBlock), arg0, arg1) + return &MockSentryServerSendMessageByMinBlockCall{Call: call} +} + +// MockSentryServerSendMessageByMinBlockCall wrap *gomock.Call +type MockSentryServerSendMessageByMinBlockCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockSentryServerSendMessageByMinBlockCall) Return(arg0 *SentPeers, arg1 error) *MockSentryServerSendMessageByMinBlockCall { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockSentryServerSendMessageByMinBlockCall) Do(f func(context.Context, *SendMessageByMinBlockRequest) (*SentPeers, error)) *MockSentryServerSendMessageByMinBlockCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockSentryServerSendMessageByMinBlockCall) DoAndReturn(f func(context.Context, *SendMessageByMinBlockRequest) (*SentPeers, error)) *MockSentryServerSendMessageByMinBlockCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// SendMessageToAll mocks base method. +func (m *MockSentryServer) SendMessageToAll(arg0 context.Context, arg1 *OutboundMessageData) (*SentPeers, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SendMessageToAll", arg0, arg1) + ret0, _ := ret[0].(*SentPeers) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// SendMessageToAll indicates an expected call of SendMessageToAll. +func (mr *MockSentryServerMockRecorder) SendMessageToAll(arg0, arg1 any) *MockSentryServerSendMessageToAllCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendMessageToAll", reflect.TypeOf((*MockSentryServer)(nil).SendMessageToAll), arg0, arg1) + return &MockSentryServerSendMessageToAllCall{Call: call} +} + +// MockSentryServerSendMessageToAllCall wrap *gomock.Call +type MockSentryServerSendMessageToAllCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockSentryServerSendMessageToAllCall) Return(arg0 *SentPeers, arg1 error) *MockSentryServerSendMessageToAllCall { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockSentryServerSendMessageToAllCall) Do(f func(context.Context, *OutboundMessageData) (*SentPeers, error)) *MockSentryServerSendMessageToAllCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockSentryServerSendMessageToAllCall) DoAndReturn(f func(context.Context, *OutboundMessageData) (*SentPeers, error)) *MockSentryServerSendMessageToAllCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// SendMessageToRandomPeers mocks base method. +func (m *MockSentryServer) SendMessageToRandomPeers(arg0 context.Context, arg1 *SendMessageToRandomPeersRequest) (*SentPeers, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SendMessageToRandomPeers", arg0, arg1) + ret0, _ := ret[0].(*SentPeers) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// SendMessageToRandomPeers indicates an expected call of SendMessageToRandomPeers. +func (mr *MockSentryServerMockRecorder) SendMessageToRandomPeers(arg0, arg1 any) *MockSentryServerSendMessageToRandomPeersCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendMessageToRandomPeers", reflect.TypeOf((*MockSentryServer)(nil).SendMessageToRandomPeers), arg0, arg1) + return &MockSentryServerSendMessageToRandomPeersCall{Call: call} +} + +// MockSentryServerSendMessageToRandomPeersCall wrap *gomock.Call +type MockSentryServerSendMessageToRandomPeersCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockSentryServerSendMessageToRandomPeersCall) Return(arg0 *SentPeers, arg1 error) *MockSentryServerSendMessageToRandomPeersCall { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockSentryServerSendMessageToRandomPeersCall) Do(f func(context.Context, *SendMessageToRandomPeersRequest) (*SentPeers, error)) *MockSentryServerSendMessageToRandomPeersCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockSentryServerSendMessageToRandomPeersCall) DoAndReturn(f func(context.Context, *SendMessageToRandomPeersRequest) (*SentPeers, error)) *MockSentryServerSendMessageToRandomPeersCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// SetStatus mocks base method. +func (m *MockSentryServer) SetStatus(arg0 context.Context, arg1 *StatusData) (*SetStatusReply, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SetStatus", arg0, arg1) + ret0, _ := ret[0].(*SetStatusReply) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// SetStatus indicates an expected call of SetStatus. +func (mr *MockSentryServerMockRecorder) SetStatus(arg0, arg1 any) *MockSentryServerSetStatusCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetStatus", reflect.TypeOf((*MockSentryServer)(nil).SetStatus), arg0, arg1) + return &MockSentryServerSetStatusCall{Call: call} +} + +// MockSentryServerSetStatusCall wrap *gomock.Call +type MockSentryServerSetStatusCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockSentryServerSetStatusCall) Return(arg0 *SetStatusReply, arg1 error) *MockSentryServerSetStatusCall { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockSentryServerSetStatusCall) Do(f func(context.Context, *StatusData) (*SetStatusReply, error)) *MockSentryServerSetStatusCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockSentryServerSetStatusCall) DoAndReturn(f func(context.Context, *StatusData) (*SetStatusReply, error)) *MockSentryServerSetStatusCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// mustEmbedUnimplementedSentryServer mocks base method. +func (m *MockSentryServer) mustEmbedUnimplementedSentryServer() { + m.ctrl.T.Helper() + m.ctrl.Call(m, "mustEmbedUnimplementedSentryServer") +} + +// mustEmbedUnimplementedSentryServer indicates an expected call of mustEmbedUnimplementedSentryServer. +func (mr *MockSentryServerMockRecorder) mustEmbedUnimplementedSentryServer() *MockSentryServermustEmbedUnimplementedSentryServerCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "mustEmbedUnimplementedSentryServer", reflect.TypeOf((*MockSentryServer)(nil).mustEmbedUnimplementedSentryServer)) + return &MockSentryServermustEmbedUnimplementedSentryServerCall{Call: call} +} + +// MockSentryServermustEmbedUnimplementedSentryServerCall wrap *gomock.Call +type MockSentryServermustEmbedUnimplementedSentryServerCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockSentryServermustEmbedUnimplementedSentryServerCall) Return() *MockSentryServermustEmbedUnimplementedSentryServerCall { + c.Call = c.Call.Return() + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockSentryServermustEmbedUnimplementedSentryServerCall) Do(f func()) *MockSentryServermustEmbedUnimplementedSentryServerCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockSentryServermustEmbedUnimplementedSentryServerCall) DoAndReturn(f func()) *MockSentryServermustEmbedUnimplementedSentryServerCall { + c.Call = c.Call.DoAndReturn(f) + return c +} diff --git a/erigon-lib/gointerfaces/test_util.go b/erigon-lib/gointerfaces/test_util.go deleted file mode 100644 index 25e9b45751d..00000000000 --- a/erigon-lib/gointerfaces/test_util.go +++ /dev/null @@ -1,4 +0,0 @@ -package gointerfaces - -//go:generate moq -stub -out ./sentry/mocks.go ./sentry SentryServer SentryClient -//go:generate moq -stub -out ./remote/mocks.go ./remote KVClient KV_StateChangesClient diff --git a/erigon-lib/tools.go b/erigon-lib/tools.go index 11fd6f3620b..cc5eef6637f 100644 --- a/erigon-lib/tools.go +++ b/erigon-lib/tools.go @@ -26,7 +26,7 @@ import ( _ "github.com/ledgerwatch/interfaces/txpool" _ "github.com/ledgerwatch/interfaces/types" _ "github.com/ledgerwatch/interfaces/web3" - _ "github.com/matryer/moq" + _ "go.uber.org/mock/mockgen" _ "go.uber.org/mock/mockgen/model" _ "google.golang.org/grpc/cmd/protoc-gen-go-grpc" ) diff --git a/erigon-lib/txpool/fetch_test.go b/erigon-lib/txpool/fetch_test.go index b000f7d38e9..b03f474fc30 100644 --- a/erigon-lib/txpool/fetch_test.go +++ b/erigon-lib/txpool/fetch_test.go @@ -24,29 +24,35 @@ import ( "sync" "testing" + "github.com/ledgerwatch/log/v3" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "go.uber.org/mock/gomock" + "google.golang.org/grpc" + "github.com/ledgerwatch/erigon-lib/common/u256" "github.com/ledgerwatch/erigon-lib/direct" "github.com/ledgerwatch/erigon-lib/gointerfaces" "github.com/ledgerwatch/erigon-lib/gointerfaces/remote" "github.com/ledgerwatch/erigon-lib/gointerfaces/sentry" - "github.com/ledgerwatch/erigon-lib/gointerfaces/types" + "github.com/ledgerwatch/erigon-lib/kv" "github.com/ledgerwatch/erigon-lib/kv/memdb" - types3 "github.com/ledgerwatch/erigon-lib/types" - "github.com/ledgerwatch/log/v3" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "google.golang.org/grpc" + erigonlibtypes "github.com/ledgerwatch/erigon-lib/types" ) func TestFetch(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - m := NewMockSentry(ctx) - sentryClient := direct.NewSentryClientDirect(direct.ETH66, m) - pool := &PoolMock{} + ctrl := gomock.NewController(t) + remoteKvClient := remote.NewMockKVClient(ctrl) + sentryServer := sentry.NewMockSentryServer(ctrl) + pool := NewMockPool(ctrl) + pool.EXPECT().Started().Return(true) - fetch := NewFetch(ctx, []direct.SentryClient{sentryClient}, pool, &remote.KVClientMock{}, nil, nil, *u256.N1, log.New()) + m := NewMockSentry(ctx, sentryServer) + sentryClient := direct.NewSentryClientDirect(direct.ETH66, m) + fetch := NewFetch(ctx, []direct.SentryClient{sentryClient}, pool, remoteKvClient, nil, nil, *u256.N1, log.New()) var wg sync.WaitGroup fetch.SetWaitGroup(&wg) m.StreamWg.Add(2) @@ -65,33 +71,58 @@ func TestFetch(t *testing.T) { } } wg.Wait() - } func TestSendTxPropagate(t *testing.T) { ctx, cancelFn := context.WithCancel(context.Background()) defer cancelFn() t.Run("few remote byHash", func(t *testing.T) { - m := NewMockSentry(ctx) + ctrl := gomock.NewController(t) + sentryServer := sentry.NewMockSentryServer(ctrl) + + times := 2 + requests := make([]*sentry.SendMessageToRandomPeersRequest, 0, times) + sentryServer.EXPECT(). + SendMessageToRandomPeers(gomock.Any(), gomock.Any()). + DoAndReturn(func(_ context.Context, r *sentry.SendMessageToRandomPeersRequest) (*sentry.SentPeers, error) { + requests = append(requests, r) + return nil, nil + }). + Times(times) + + m := NewMockSentry(ctx, sentryServer) send := NewSend(ctx, []direct.SentryClient{direct.NewSentryClientDirect(direct.ETH68, m)}, nil, log.New()) send.BroadcastPooledTxs(testRlps(2), 100) send.AnnouncePooledTxs([]byte{0, 1}, []uint32{10, 15}, toHashes(1, 42), 100) - calls := m.SendMessageToRandomPeersCalls() - require.Equal(t, 2, len(calls)) + require.Equal(t, 2, len(requests)) - txsMessage := calls[0].SendMessageToRandomPeersRequest.Data + txsMessage := requests[0].Data assert.Equal(t, sentry.MessageId_TRANSACTIONS_66, txsMessage.Id) assert.Equal(t, 3, len(txsMessage.Data)) - txnHashesMessage := calls[1].SendMessageToRandomPeersRequest.Data + txnHashesMessage := requests[1].Data assert.Equal(t, sentry.MessageId_NEW_POOLED_TRANSACTION_HASHES_68, txnHashesMessage.Id) assert.Equal(t, 76, len(txnHashesMessage.Data)) }) + t.Run("much remote byHash", func(t *testing.T) { - m := NewMockSentry(ctx) + ctrl := gomock.NewController(t) + sentryServer := sentry.NewMockSentryServer(ctrl) + + times := 2 + requests := make([]*sentry.SendMessageToRandomPeersRequest, 0, times) + sentryServer.EXPECT(). + SendMessageToRandomPeers(gomock.Any(), gomock.Any()). + DoAndReturn(func(_ context.Context, r *sentry.SendMessageToRandomPeersRequest) (*sentry.SentPeers, error) { + requests = append(requests, r) + return nil, nil + }). + Times(times) + + m := NewMockSentry(ctx, sentryServer) send := NewSend(ctx, []direct.SentryClient{direct.NewSentryClientDirect(direct.ETH68, m)}, nil, log.New()) - list := make(types3.Hashes, p2pTxPacketLimit*3) + list := make(erigonlibtypes.Hashes, p2pTxPacketLimit*3) for i := 0; i < len(list); i += 32 { b := []byte(fmt.Sprintf("%x", i)) copy(list[i:i+32], b) @@ -99,52 +130,69 @@ func TestSendTxPropagate(t *testing.T) { send.BroadcastPooledTxs(testRlps(len(list)/32), 100) send.AnnouncePooledTxs([]byte{0, 1, 2}, []uint32{10, 12, 14}, list, 100) - calls := m.SendMessageToRandomPeersCalls() - require.Equal(t, 2, len(calls)) + require.Equal(t, 2, len(requests)) - txsMessage := calls[0].SendMessageToRandomPeersRequest.Data + txsMessage := requests[0].Data require.Equal(t, sentry.MessageId_TRANSACTIONS_66, txsMessage.Id) require.True(t, len(txsMessage.Data) > 0) - txnHashesMessage := calls[1].SendMessageToRandomPeersRequest.Data + txnHashesMessage := requests[1].Data require.Equal(t, sentry.MessageId_NEW_POOLED_TRANSACTION_HASHES_68, txnHashesMessage.Id) require.True(t, len(txnHashesMessage.Data) > 0) }) + t.Run("few local byHash", func(t *testing.T) { - m := NewMockSentry(ctx) - m.SendMessageToAllFunc = func(contextMoqParam context.Context, outboundMessageData *sentry.OutboundMessageData) (*sentry.SentPeers, error) { - return &sentry.SentPeers{Peers: make([]*types.H512, 5)}, nil - } + ctrl := gomock.NewController(t) + sentryServer := sentry.NewMockSentryServer(ctrl) + + times := 2 + requests := make([]*sentry.SendMessageToRandomPeersRequest, 0, times) + sentryServer.EXPECT(). + SendMessageToRandomPeers(gomock.Any(), gomock.Any()). + DoAndReturn(func(_ context.Context, r *sentry.SendMessageToRandomPeersRequest) (*sentry.SentPeers, error) { + requests = append(requests, r) + return nil, nil + }). + Times(times) + + m := NewMockSentry(ctx, sentryServer) send := NewSend(ctx, []direct.SentryClient{direct.NewSentryClientDirect(direct.ETH68, m)}, nil, log.New()) send.BroadcastPooledTxs(testRlps(2), 100) send.AnnouncePooledTxs([]byte{0, 1}, []uint32{10, 15}, toHashes(1, 42), 100) - calls := m.SendMessageToRandomPeersCalls() - require.Equal(t, 2, len(calls)) + require.Equal(t, 2, len(requests)) - txsMessage := calls[0].SendMessageToRandomPeersRequest.Data + txsMessage := requests[0].Data assert.Equal(t, sentry.MessageId_TRANSACTIONS_66, txsMessage.Id) assert.True(t, len(txsMessage.Data) > 0) - txnHashesMessage := calls[1].SendMessageToRandomPeersRequest.Data + txnHashesMessage := requests[1].Data assert.Equal(t, sentry.MessageId_NEW_POOLED_TRANSACTION_HASHES_68, txnHashesMessage.Id) assert.Equal(t, 76, len(txnHashesMessage.Data)) }) + t.Run("sync with new peer", func(t *testing.T) { - m := NewMockSentry(ctx) + ctrl := gomock.NewController(t) + sentryServer := sentry.NewMockSentryServer(ctrl) - m.SendMessageToAllFunc = func(contextMoqParam context.Context, outboundMessageData *sentry.OutboundMessageData) (*sentry.SentPeers, error) { - return &sentry.SentPeers{Peers: make([]*types.H512, 5)}, nil - } + times := 3 + requests := make([]*sentry.SendMessageByIdRequest, 0, times) + sentryServer.EXPECT(). + SendMessageById(gomock.Any(), gomock.Any()). + DoAndReturn(func(_ context.Context, r *sentry.SendMessageByIdRequest) (*sentry.SentPeers, error) { + requests = append(requests, r) + return nil, nil + }). + Times(times) + + m := NewMockSentry(ctx, sentryServer) send := NewSend(ctx, []direct.SentryClient{direct.NewSentryClientDirect(direct.ETH68, m)}, nil, log.New()) expectPeers := toPeerIDs(1, 2, 42) send.PropagatePooledTxsToPeersList(expectPeers, []byte{0, 1}, []uint32{10, 15}, toHashes(1, 42)) - calls := m.SendMessageByIdCalls() - require.Equal(t, 3, len(calls)) - for i, call := range calls { - req := call.SendMessageByIdRequest - assert.Equal(t, expectPeers[i], types3.PeerID(req.PeerId)) + require.Equal(t, 3, len(requests)) + for i, req := range requests { + assert.Equal(t, expectPeers[i], erigonlibtypes.PeerID(req.PeerId)) assert.Equal(t, sentry.MessageId_NEW_POOLED_TRANSACTION_HASHES_68, req.Data.Id) assert.True(t, len(req.Data.Data) > 0) } @@ -162,10 +210,13 @@ func TestOnNewBlock(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() coreDB, db := memdb.NewTestDB(t), memdb.NewTestDB(t) + ctrl := gomock.NewController(t) + stream := remote.NewMockKV_StateChangesClient(ctrl) i := 0 - stream := &remote.KV_StateChangesClientMock{ - RecvFunc: func() (*remote.StateChangeBatch, error) { + stream.EXPECT(). + Recv(). + DoAndReturn(func() (*remote.StateChangeBatch, error) { if i > 0 { return nil, io.EOF } @@ -173,20 +224,57 @@ func TestOnNewBlock(t *testing.T) { return &remote.StateChangeBatch{ StateVersionId: 1, ChangeBatch: []*remote.StateChange{ - {Txs: [][]byte{decodeHex(types3.TxParseMainnetTests[0].PayloadStr), decodeHex(types3.TxParseMainnetTests[1].PayloadStr), decodeHex(types3.TxParseMainnetTests[2].PayloadStr)}, BlockHeight: 1, BlockHash: gointerfaces.ConvertHashToH256([32]byte{})}, + { + Txs: [][]byte{ + decodeHex(erigonlibtypes.TxParseMainnetTests[0].PayloadStr), + decodeHex(erigonlibtypes.TxParseMainnetTests[1].PayloadStr), + decodeHex(erigonlibtypes.TxParseMainnetTests[2].PayloadStr), + }, + BlockHeight: 1, + BlockHash: gointerfaces.ConvertHashToH256([32]byte{}), + }, }, }, nil - }, - } - stateChanges := &remote.KVClientMock{ - StateChangesFunc: func(ctx context.Context, in *remote.StateChangeRequest, opts ...grpc.CallOption) (remote.KV_StateChangesClient, error) { + }). + AnyTimes() + + stateChanges := remote.NewMockKVClient(ctrl) + stateChanges. + EXPECT(). + StateChanges(gomock.Any(), gomock.Any(), gomock.Any()). + DoAndReturn(func(_ context.Context, _ *remote.StateChangeRequest, _ ...grpc.CallOption) (remote.KV_StateChangesClient, error) { return stream, nil - }, - } - pool := &PoolMock{} + }) + + pool := NewMockPool(ctrl) + + pool.EXPECT(). + ValidateSerializedTxn(gomock.Any()). + DoAndReturn(func(_ []byte) error { + return nil + }). + Times(3) + + var minedTxs erigonlibtypes.TxSlots + pool.EXPECT(). + OnNewBlock(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()). + DoAndReturn( + func( + _ context.Context, + _ *remote.StateChangeBatch, + _ erigonlibtypes.TxSlots, + _ erigonlibtypes.TxSlots, + minedTxsArg erigonlibtypes.TxSlots, + _ kv.Tx, + ) error { + minedTxs = minedTxsArg + return nil + }, + ). + Times(1) + fetch := NewFetch(ctx, nil, pool, stateChanges, coreDB, db, *u256.N1, log.New()) err := fetch.handleStateChanges(ctx, stateChanges) assert.ErrorIs(t, io.EOF, err) - assert.Equal(t, 1, len(pool.OnNewBlockCalls())) - assert.Equal(t, 3, len(pool.OnNewBlockCalls()[0].MinedTxs.Txs)) + assert.Equal(t, 3, len(minedTxs.Txs)) } diff --git a/erigon-lib/txpool/mocks_test.go b/erigon-lib/txpool/mocks_test.go deleted file mode 100644 index 502b4a69002..00000000000 --- a/erigon-lib/txpool/mocks_test.go +++ /dev/null @@ -1,515 +0,0 @@ -// Code generated by moq; DO NOT EDIT. -// github.com/matryer/moq - -package txpool - -import ( - "context" - "github.com/ledgerwatch/erigon-lib/gointerfaces/remote" - "github.com/ledgerwatch/erigon-lib/kv" - "github.com/ledgerwatch/erigon-lib/txpool/txpoolcfg" - types2 "github.com/ledgerwatch/erigon-lib/types" - "sync" -) - -// Ensure, that PoolMock does implement Pool. -// If this is not the case, regenerate this file with moq. -var _ Pool = &PoolMock{} - -// PoolMock is a mock implementation of Pool. -// -// func TestSomethingThatUsesPool(t *testing.T) { -// -// // make and configure a mocked Pool -// mockedPool := &PoolMock{ -// AddLocalTxsFunc: func(ctx context.Context, newTxs types2.TxSlots, tx kv.Tx) ([]txpoolcfg.DiscardReason, error) { -// panic("mock out the AddLocalTxs method") -// }, -// AddNewGoodPeerFunc: func(peerID types2.PeerID) { -// panic("mock out the AddNewGoodPeer method") -// }, -// AddRemoteTxsFunc: func(ctx context.Context, newTxs types2.TxSlots) { -// panic("mock out the AddRemoteTxs method") -// }, -// FilterKnownIdHashesFunc: func(tx kv.Tx, hashes types2.Hashes) (types2.Hashes, error) { -// panic("mock out the FilterKnownIdHashes method") -// }, -// GetRlpFunc: func(tx kv.Tx, hash []byte) ([]byte, error) { -// panic("mock out the GetRlp method") -// }, -// IdHashKnownFunc: func(tx kv.Tx, hash []byte) (bool, error) { -// panic("mock out the IdHashKnown method") -// }, -// OnNewBlockFunc: func(ctx context.Context, stateChanges *remote.StateChangeBatch, unwindTxs types2.TxSlots, unwindBlobTxs types2.TxSlots, minedTxs types2.TxSlots, tx kv.Tx) error { -// panic("mock out the OnNewBlock method") -// }, -// StartedFunc: func() bool { -// panic("mock out the Started method") -// }, -// ValidateSerializedTxnFunc: func(serializedTxn []byte) error { -// panic("mock out the ValidateSerializedTxn method") -// }, -// } -// -// // use mockedPool in code that requires Pool -// // and then make assertions. -// -// } -type PoolMock struct { - // AddLocalTxsFunc mocks the AddLocalTxs method. - AddLocalTxsFunc func(ctx context.Context, newTxs types2.TxSlots, tx kv.Tx) ([]txpoolcfg.DiscardReason, error) - - // AddNewGoodPeerFunc mocks the AddNewGoodPeer method. - AddNewGoodPeerFunc func(peerID types2.PeerID) - - // AddRemoteTxsFunc mocks the AddRemoteTxs method. - AddRemoteTxsFunc func(ctx context.Context, newTxs types2.TxSlots) - - // FilterKnownIdHashesFunc mocks the FilterKnownIdHashes method. - FilterKnownIdHashesFunc func(tx kv.Tx, hashes types2.Hashes) (types2.Hashes, error) - - // GetRlpFunc mocks the GetRlp method. - GetRlpFunc func(tx kv.Tx, hash []byte) ([]byte, error) - - // IdHashKnownFunc mocks the IdHashKnown method. - IdHashKnownFunc func(tx kv.Tx, hash []byte) (bool, error) - - // OnNewBlockFunc mocks the OnNewBlock method. - OnNewBlockFunc func(ctx context.Context, stateChanges *remote.StateChangeBatch, unwindTxs types2.TxSlots, unwindBlobTxs types2.TxSlots, minedTxs types2.TxSlots, tx kv.Tx) error - - // StartedFunc mocks the Started method. - StartedFunc func() bool - - // ValidateSerializedTxnFunc mocks the ValidateSerializedTxn method. - ValidateSerializedTxnFunc func(serializedTxn []byte) error - - // calls tracks calls to the methods. - calls struct { - // AddLocalTxs holds details about calls to the AddLocalTxs method. - AddLocalTxs []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // NewTxs is the newTxs argument value. - NewTxs types2.TxSlots - // Tx is the tx argument value. - Tx kv.Tx - } - // AddNewGoodPeer holds details about calls to the AddNewGoodPeer method. - AddNewGoodPeer []struct { - // PeerID is the peerID argument value. - PeerID types2.PeerID - } - // AddRemoteTxs holds details about calls to the AddRemoteTxs method. - AddRemoteTxs []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // NewTxs is the newTxs argument value. - NewTxs types2.TxSlots - } - // FilterKnownIdHashes holds details about calls to the FilterKnownIdHashes method. - FilterKnownIdHashes []struct { - // Tx is the tx argument value. - Tx kv.Tx - // Hashes is the hashes argument value. - Hashes types2.Hashes - } - // GetRlp holds details about calls to the GetRlp method. - GetRlp []struct { - // Tx is the tx argument value. - Tx kv.Tx - // Hash is the hash argument value. - Hash []byte - } - // IdHashKnown holds details about calls to the IdHashKnown method. - IdHashKnown []struct { - // Tx is the tx argument value. - Tx kv.Tx - // Hash is the hash argument value. - Hash []byte - } - // OnNewBlock holds details about calls to the OnNewBlock method. - OnNewBlock []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // StateChanges is the stateChanges argument value. - StateChanges *remote.StateChangeBatch - // UnwindTxs is the unwindTxs argument value. - UnwindTxs types2.TxSlots - // UnwindBlobTxs is the unwindBlobTxs argument value. - UnwindBlobTxs types2.TxSlots - // MinedTxs is the minedTxs argument value. - MinedTxs types2.TxSlots - // Tx is the tx argument value. - Tx kv.Tx - } - // Started holds details about calls to the Started method. - Started []struct { - } - // ValidateSerializedTxn holds details about calls to the ValidateSerializedTxn method. - ValidateSerializedTxn []struct { - // SerializedTxn is the serializedTxn argument value. - SerializedTxn []byte - } - } - lockAddLocalTxs sync.RWMutex - lockAddNewGoodPeer sync.RWMutex - lockAddRemoteTxs sync.RWMutex - lockFilterKnownIdHashes sync.RWMutex - lockGetRlp sync.RWMutex - lockIdHashKnown sync.RWMutex - lockOnNewBlock sync.RWMutex - lockStarted sync.RWMutex - lockValidateSerializedTxn sync.RWMutex -} - -// AddLocalTxs calls AddLocalTxsFunc. -func (mock *PoolMock) AddLocalTxs(ctx context.Context, newTxs types2.TxSlots, tx kv.Tx) ([]txpoolcfg.DiscardReason, error) { - callInfo := struct { - Ctx context.Context - NewTxs types2.TxSlots - Tx kv.Tx - }{ - Ctx: ctx, - NewTxs: newTxs, - Tx: tx, - } - mock.lockAddLocalTxs.Lock() - mock.calls.AddLocalTxs = append(mock.calls.AddLocalTxs, callInfo) - mock.lockAddLocalTxs.Unlock() - if mock.AddLocalTxsFunc == nil { - var ( - discardReasonsOut []txpoolcfg.DiscardReason - errOut error - ) - return discardReasonsOut, errOut - } - return mock.AddLocalTxsFunc(ctx, newTxs, tx) -} - -// AddLocalTxsCalls gets all the calls that were made to AddLocalTxs. -// Check the length with: -// -// len(mockedPool.AddLocalTxsCalls()) -func (mock *PoolMock) AddLocalTxsCalls() []struct { - Ctx context.Context - NewTxs types2.TxSlots - Tx kv.Tx -} { - var calls []struct { - Ctx context.Context - NewTxs types2.TxSlots - Tx kv.Tx - } - mock.lockAddLocalTxs.RLock() - calls = mock.calls.AddLocalTxs - mock.lockAddLocalTxs.RUnlock() - return calls -} - -// AddNewGoodPeer calls AddNewGoodPeerFunc. -func (mock *PoolMock) AddNewGoodPeer(peerID types2.PeerID) { - callInfo := struct { - PeerID types2.PeerID - }{ - PeerID: peerID, - } - mock.lockAddNewGoodPeer.Lock() - mock.calls.AddNewGoodPeer = append(mock.calls.AddNewGoodPeer, callInfo) - mock.lockAddNewGoodPeer.Unlock() - if mock.AddNewGoodPeerFunc == nil { - return - } - mock.AddNewGoodPeerFunc(peerID) -} - -// AddNewGoodPeerCalls gets all the calls that were made to AddNewGoodPeer. -// Check the length with: -// -// len(mockedPool.AddNewGoodPeerCalls()) -func (mock *PoolMock) AddNewGoodPeerCalls() []struct { - PeerID types2.PeerID -} { - var calls []struct { - PeerID types2.PeerID - } - mock.lockAddNewGoodPeer.RLock() - calls = mock.calls.AddNewGoodPeer - mock.lockAddNewGoodPeer.RUnlock() - return calls -} - -// AddRemoteTxs calls AddRemoteTxsFunc. -func (mock *PoolMock) AddRemoteTxs(ctx context.Context, newTxs types2.TxSlots) { - callInfo := struct { - Ctx context.Context - NewTxs types2.TxSlots - }{ - Ctx: ctx, - NewTxs: newTxs, - } - mock.lockAddRemoteTxs.Lock() - mock.calls.AddRemoteTxs = append(mock.calls.AddRemoteTxs, callInfo) - mock.lockAddRemoteTxs.Unlock() - if mock.AddRemoteTxsFunc == nil { - return - } - mock.AddRemoteTxsFunc(ctx, newTxs) -} - -// AddRemoteTxsCalls gets all the calls that were made to AddRemoteTxs. -// Check the length with: -// -// len(mockedPool.AddRemoteTxsCalls()) -func (mock *PoolMock) AddRemoteTxsCalls() []struct { - Ctx context.Context - NewTxs types2.TxSlots -} { - var calls []struct { - Ctx context.Context - NewTxs types2.TxSlots - } - mock.lockAddRemoteTxs.RLock() - calls = mock.calls.AddRemoteTxs - mock.lockAddRemoteTxs.RUnlock() - return calls -} - -// FilterKnownIdHashes calls FilterKnownIdHashesFunc. -func (mock *PoolMock) FilterKnownIdHashes(tx kv.Tx, hashes types2.Hashes) (types2.Hashes, error) { - callInfo := struct { - Tx kv.Tx - Hashes types2.Hashes - }{ - Tx: tx, - Hashes: hashes, - } - mock.lockFilterKnownIdHashes.Lock() - mock.calls.FilterKnownIdHashes = append(mock.calls.FilterKnownIdHashes, callInfo) - mock.lockFilterKnownIdHashes.Unlock() - if mock.FilterKnownIdHashesFunc == nil { - var ( - unknownHashesOut types2.Hashes - errOut error - ) - return unknownHashesOut, errOut - } - return mock.FilterKnownIdHashesFunc(tx, hashes) -} - -// FilterKnownIdHashesCalls gets all the calls that were made to FilterKnownIdHashes. -// Check the length with: -// -// len(mockedPool.FilterKnownIdHashesCalls()) -func (mock *PoolMock) FilterKnownIdHashesCalls() []struct { - Tx kv.Tx - Hashes types2.Hashes -} { - var calls []struct { - Tx kv.Tx - Hashes types2.Hashes - } - mock.lockFilterKnownIdHashes.RLock() - calls = mock.calls.FilterKnownIdHashes - mock.lockFilterKnownIdHashes.RUnlock() - return calls -} - -// GetRlp calls GetRlpFunc. -func (mock *PoolMock) GetRlp(tx kv.Tx, hash []byte) ([]byte, error) { - callInfo := struct { - Tx kv.Tx - Hash []byte - }{ - Tx: tx, - Hash: hash, - } - mock.lockGetRlp.Lock() - mock.calls.GetRlp = append(mock.calls.GetRlp, callInfo) - mock.lockGetRlp.Unlock() - if mock.GetRlpFunc == nil { - var ( - bytesOut []byte - errOut error - ) - return bytesOut, errOut - } - return mock.GetRlpFunc(tx, hash) -} - -// GetRlpCalls gets all the calls that were made to GetRlp. -// Check the length with: -// -// len(mockedPool.GetRlpCalls()) -func (mock *PoolMock) GetRlpCalls() []struct { - Tx kv.Tx - Hash []byte -} { - var calls []struct { - Tx kv.Tx - Hash []byte - } - mock.lockGetRlp.RLock() - calls = mock.calls.GetRlp - mock.lockGetRlp.RUnlock() - return calls -} - -// IdHashKnown calls IdHashKnownFunc. -func (mock *PoolMock) IdHashKnown(tx kv.Tx, hash []byte) (bool, error) { - callInfo := struct { - Tx kv.Tx - Hash []byte - }{ - Tx: tx, - Hash: hash, - } - mock.lockIdHashKnown.Lock() - mock.calls.IdHashKnown = append(mock.calls.IdHashKnown, callInfo) - mock.lockIdHashKnown.Unlock() - if mock.IdHashKnownFunc == nil { - var ( - bOut bool - errOut error - ) - return bOut, errOut - } - return mock.IdHashKnownFunc(tx, hash) -} - -// IdHashKnownCalls gets all the calls that were made to IdHashKnown. -// Check the length with: -// -// len(mockedPool.IdHashKnownCalls()) -func (mock *PoolMock) IdHashKnownCalls() []struct { - Tx kv.Tx - Hash []byte -} { - var calls []struct { - Tx kv.Tx - Hash []byte - } - mock.lockIdHashKnown.RLock() - calls = mock.calls.IdHashKnown - mock.lockIdHashKnown.RUnlock() - return calls -} - -// OnNewBlock calls OnNewBlockFunc. -func (mock *PoolMock) OnNewBlock(ctx context.Context, stateChanges *remote.StateChangeBatch, unwindTxs types2.TxSlots, unwindBlobTxs types2.TxSlots, minedTxs types2.TxSlots, tx kv.Tx) error { - callInfo := struct { - Ctx context.Context - StateChanges *remote.StateChangeBatch - UnwindTxs types2.TxSlots - UnwindBlobTxs types2.TxSlots - MinedTxs types2.TxSlots - Tx kv.Tx - }{ - Ctx: ctx, - StateChanges: stateChanges, - UnwindTxs: unwindTxs, - UnwindBlobTxs: unwindBlobTxs, - MinedTxs: minedTxs, - Tx: tx, - } - mock.lockOnNewBlock.Lock() - mock.calls.OnNewBlock = append(mock.calls.OnNewBlock, callInfo) - mock.lockOnNewBlock.Unlock() - if mock.OnNewBlockFunc == nil { - var ( - errOut error - ) - return errOut - } - return mock.OnNewBlockFunc(ctx, stateChanges, unwindTxs, unwindBlobTxs, minedTxs, tx) -} - -// OnNewBlockCalls gets all the calls that were made to OnNewBlock. -// Check the length with: -// -// len(mockedPool.OnNewBlockCalls()) -func (mock *PoolMock) OnNewBlockCalls() []struct { - Ctx context.Context - StateChanges *remote.StateChangeBatch - UnwindTxs types2.TxSlots - UnwindBlobTxs types2.TxSlots - MinedTxs types2.TxSlots - Tx kv.Tx -} { - var calls []struct { - Ctx context.Context - StateChanges *remote.StateChangeBatch - UnwindTxs types2.TxSlots - UnwindBlobTxs types2.TxSlots - MinedTxs types2.TxSlots - Tx kv.Tx - } - mock.lockOnNewBlock.RLock() - calls = mock.calls.OnNewBlock - mock.lockOnNewBlock.RUnlock() - return calls -} - -// Started calls StartedFunc. -func (mock *PoolMock) Started() bool { - callInfo := struct { - }{} - mock.lockStarted.Lock() - mock.calls.Started = append(mock.calls.Started, callInfo) - mock.lockStarted.Unlock() - if mock.StartedFunc == nil { - var ( - bOut bool - ) - return bOut - } - return mock.StartedFunc() -} - -// StartedCalls gets all the calls that were made to Started. -// Check the length with: -// -// len(mockedPool.StartedCalls()) -func (mock *PoolMock) StartedCalls() []struct { -} { - var calls []struct { - } - mock.lockStarted.RLock() - calls = mock.calls.Started - mock.lockStarted.RUnlock() - return calls -} - -// ValidateSerializedTxn calls ValidateSerializedTxnFunc. -func (mock *PoolMock) ValidateSerializedTxn(serializedTxn []byte) error { - callInfo := struct { - SerializedTxn []byte - }{ - SerializedTxn: serializedTxn, - } - mock.lockValidateSerializedTxn.Lock() - mock.calls.ValidateSerializedTxn = append(mock.calls.ValidateSerializedTxn, callInfo) - mock.lockValidateSerializedTxn.Unlock() - if mock.ValidateSerializedTxnFunc == nil { - var ( - errOut error - ) - return errOut - } - return mock.ValidateSerializedTxnFunc(serializedTxn) -} - -// ValidateSerializedTxnCalls gets all the calls that were made to ValidateSerializedTxn. -// Check the length with: -// -// len(mockedPool.ValidateSerializedTxnCalls()) -func (mock *PoolMock) ValidateSerializedTxnCalls() []struct { - SerializedTxn []byte -} { - var calls []struct { - SerializedTxn []byte - } - mock.lockValidateSerializedTxn.RLock() - calls = mock.calls.ValidateSerializedTxn - mock.lockValidateSerializedTxn.RUnlock() - return calls -} diff --git a/erigon-lib/txpool/pool.go b/erigon-lib/txpool/pool.go index 09fa1477457..846a6b3e6be 100644 --- a/erigon-lib/txpool/pool.go +++ b/erigon-lib/txpool/pool.go @@ -52,7 +52,7 @@ import ( "github.com/ledgerwatch/erigon-lib/gointerfaces" "github.com/ledgerwatch/erigon-lib/gointerfaces/grpcutil" "github.com/ledgerwatch/erigon-lib/gointerfaces/remote" - proto_txpool "github.com/ledgerwatch/erigon-lib/gointerfaces/txpool" + txpoolproto "github.com/ledgerwatch/erigon-lib/gointerfaces/txpool" "github.com/ledgerwatch/erigon-lib/kv" "github.com/ledgerwatch/erigon-lib/kv/kvcache" "github.com/ledgerwatch/erigon-lib/kv/mdbx" @@ -82,6 +82,8 @@ var TraceAll = false // Pool is interface for the transaction pool // This interface exists for the convenience of testing, and not yet because // there are multiple implementations +// +//go:generate mockgen -typed=true -destination=./pool_mock.go -package=txpool . Pool type Pool interface { ValidateSerializedTxn(serializedTxn []byte) error @@ -1897,7 +1899,7 @@ func MainLoop(ctx context.Context, db kv.RwDB, p *TxPool, newTxs chan types.Anno return } if newSlotsStreams != nil { - newSlotsStreams.Broadcast(&proto_txpool.OnAddReply{RplTxs: slotsRlp}, p.logger) + newSlotsStreams.Broadcast(&txpoolproto.OnAddReply{RplTxs: slotsRlp}, p.logger) } // broadcast local transactions diff --git a/erigon-lib/txpool/pool_mock.go b/erigon-lib/txpool/pool_mock.go new file mode 100644 index 00000000000..8d34190039e --- /dev/null +++ b/erigon-lib/txpool/pool_mock.go @@ -0,0 +1,386 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/ledgerwatch/erigon-lib/txpool (interfaces: Pool) +// +// Generated by this command: +// +// mockgen -typed=true -destination=./pool_mock.go -package=txpool . Pool +// + +// Package txpool is a generated GoMock package. +package txpool + +import ( + context "context" + reflect "reflect" + + remote "github.com/ledgerwatch/erigon-lib/gointerfaces/remote" + kv "github.com/ledgerwatch/erigon-lib/kv" + txpoolcfg "github.com/ledgerwatch/erigon-lib/txpool/txpoolcfg" + types "github.com/ledgerwatch/erigon-lib/types" + gomock "go.uber.org/mock/gomock" +) + +// MockPool is a mock of Pool interface. +type MockPool struct { + ctrl *gomock.Controller + recorder *MockPoolMockRecorder +} + +// MockPoolMockRecorder is the mock recorder for MockPool. +type MockPoolMockRecorder struct { + mock *MockPool +} + +// NewMockPool creates a new mock instance. +func NewMockPool(ctrl *gomock.Controller) *MockPool { + mock := &MockPool{ctrl: ctrl} + mock.recorder = &MockPoolMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockPool) EXPECT() *MockPoolMockRecorder { + return m.recorder +} + +// AddLocalTxs mocks base method. +func (m *MockPool) AddLocalTxs(arg0 context.Context, arg1 types.TxSlots, arg2 kv.Tx) ([]txpoolcfg.DiscardReason, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddLocalTxs", arg0, arg1, arg2) + ret0, _ := ret[0].([]txpoolcfg.DiscardReason) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// AddLocalTxs indicates an expected call of AddLocalTxs. +func (mr *MockPoolMockRecorder) AddLocalTxs(arg0, arg1, arg2 any) *MockPoolAddLocalTxsCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddLocalTxs", reflect.TypeOf((*MockPool)(nil).AddLocalTxs), arg0, arg1, arg2) + return &MockPoolAddLocalTxsCall{Call: call} +} + +// MockPoolAddLocalTxsCall wrap *gomock.Call +type MockPoolAddLocalTxsCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockPoolAddLocalTxsCall) Return(arg0 []txpoolcfg.DiscardReason, arg1 error) *MockPoolAddLocalTxsCall { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockPoolAddLocalTxsCall) Do(f func(context.Context, types.TxSlots, kv.Tx) ([]txpoolcfg.DiscardReason, error)) *MockPoolAddLocalTxsCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockPoolAddLocalTxsCall) DoAndReturn(f func(context.Context, types.TxSlots, kv.Tx) ([]txpoolcfg.DiscardReason, error)) *MockPoolAddLocalTxsCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// AddNewGoodPeer mocks base method. +func (m *MockPool) AddNewGoodPeer(arg0 types.PeerID) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "AddNewGoodPeer", arg0) +} + +// AddNewGoodPeer indicates an expected call of AddNewGoodPeer. +func (mr *MockPoolMockRecorder) AddNewGoodPeer(arg0 any) *MockPoolAddNewGoodPeerCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddNewGoodPeer", reflect.TypeOf((*MockPool)(nil).AddNewGoodPeer), arg0) + return &MockPoolAddNewGoodPeerCall{Call: call} +} + +// MockPoolAddNewGoodPeerCall wrap *gomock.Call +type MockPoolAddNewGoodPeerCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockPoolAddNewGoodPeerCall) Return() *MockPoolAddNewGoodPeerCall { + c.Call = c.Call.Return() + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockPoolAddNewGoodPeerCall) Do(f func(types.PeerID)) *MockPoolAddNewGoodPeerCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockPoolAddNewGoodPeerCall) DoAndReturn(f func(types.PeerID)) *MockPoolAddNewGoodPeerCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// AddRemoteTxs mocks base method. +func (m *MockPool) AddRemoteTxs(arg0 context.Context, arg1 types.TxSlots) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "AddRemoteTxs", arg0, arg1) +} + +// AddRemoteTxs indicates an expected call of AddRemoteTxs. +func (mr *MockPoolMockRecorder) AddRemoteTxs(arg0, arg1 any) *MockPoolAddRemoteTxsCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddRemoteTxs", reflect.TypeOf((*MockPool)(nil).AddRemoteTxs), arg0, arg1) + return &MockPoolAddRemoteTxsCall{Call: call} +} + +// MockPoolAddRemoteTxsCall wrap *gomock.Call +type MockPoolAddRemoteTxsCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockPoolAddRemoteTxsCall) Return() *MockPoolAddRemoteTxsCall { + c.Call = c.Call.Return() + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockPoolAddRemoteTxsCall) Do(f func(context.Context, types.TxSlots)) *MockPoolAddRemoteTxsCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockPoolAddRemoteTxsCall) DoAndReturn(f func(context.Context, types.TxSlots)) *MockPoolAddRemoteTxsCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// FilterKnownIdHashes mocks base method. +func (m *MockPool) FilterKnownIdHashes(arg0 kv.Tx, arg1 types.Hashes) (types.Hashes, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "FilterKnownIdHashes", arg0, arg1) + ret0, _ := ret[0].(types.Hashes) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// FilterKnownIdHashes indicates an expected call of FilterKnownIdHashes. +func (mr *MockPoolMockRecorder) FilterKnownIdHashes(arg0, arg1 any) *MockPoolFilterKnownIdHashesCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FilterKnownIdHashes", reflect.TypeOf((*MockPool)(nil).FilterKnownIdHashes), arg0, arg1) + return &MockPoolFilterKnownIdHashesCall{Call: call} +} + +// MockPoolFilterKnownIdHashesCall wrap *gomock.Call +type MockPoolFilterKnownIdHashesCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockPoolFilterKnownIdHashesCall) Return(arg0 types.Hashes, arg1 error) *MockPoolFilterKnownIdHashesCall { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockPoolFilterKnownIdHashesCall) Do(f func(kv.Tx, types.Hashes) (types.Hashes, error)) *MockPoolFilterKnownIdHashesCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockPoolFilterKnownIdHashesCall) DoAndReturn(f func(kv.Tx, types.Hashes) (types.Hashes, error)) *MockPoolFilterKnownIdHashesCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// GetRlp mocks base method. +func (m *MockPool) GetRlp(arg0 kv.Tx, arg1 []byte) ([]byte, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetRlp", arg0, arg1) + ret0, _ := ret[0].([]byte) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetRlp indicates an expected call of GetRlp. +func (mr *MockPoolMockRecorder) GetRlp(arg0, arg1 any) *MockPoolGetRlpCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetRlp", reflect.TypeOf((*MockPool)(nil).GetRlp), arg0, arg1) + return &MockPoolGetRlpCall{Call: call} +} + +// MockPoolGetRlpCall wrap *gomock.Call +type MockPoolGetRlpCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockPoolGetRlpCall) Return(arg0 []byte, arg1 error) *MockPoolGetRlpCall { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockPoolGetRlpCall) Do(f func(kv.Tx, []byte) ([]byte, error)) *MockPoolGetRlpCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockPoolGetRlpCall) DoAndReturn(f func(kv.Tx, []byte) ([]byte, error)) *MockPoolGetRlpCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// IdHashKnown mocks base method. +func (m *MockPool) IdHashKnown(arg0 kv.Tx, arg1 []byte) (bool, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "IdHashKnown", arg0, arg1) + ret0, _ := ret[0].(bool) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// IdHashKnown indicates an expected call of IdHashKnown. +func (mr *MockPoolMockRecorder) IdHashKnown(arg0, arg1 any) *MockPoolIdHashKnownCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IdHashKnown", reflect.TypeOf((*MockPool)(nil).IdHashKnown), arg0, arg1) + return &MockPoolIdHashKnownCall{Call: call} +} + +// MockPoolIdHashKnownCall wrap *gomock.Call +type MockPoolIdHashKnownCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockPoolIdHashKnownCall) Return(arg0 bool, arg1 error) *MockPoolIdHashKnownCall { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockPoolIdHashKnownCall) Do(f func(kv.Tx, []byte) (bool, error)) *MockPoolIdHashKnownCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockPoolIdHashKnownCall) DoAndReturn(f func(kv.Tx, []byte) (bool, error)) *MockPoolIdHashKnownCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// OnNewBlock mocks base method. +func (m *MockPool) OnNewBlock(arg0 context.Context, arg1 *remote.StateChangeBatch, arg2, arg3, arg4 types.TxSlots, arg5 kv.Tx) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "OnNewBlock", arg0, arg1, arg2, arg3, arg4, arg5) + ret0, _ := ret[0].(error) + return ret0 +} + +// OnNewBlock indicates an expected call of OnNewBlock. +func (mr *MockPoolMockRecorder) OnNewBlock(arg0, arg1, arg2, arg3, arg4, arg5 any) *MockPoolOnNewBlockCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "OnNewBlock", reflect.TypeOf((*MockPool)(nil).OnNewBlock), arg0, arg1, arg2, arg3, arg4, arg5) + return &MockPoolOnNewBlockCall{Call: call} +} + +// MockPoolOnNewBlockCall wrap *gomock.Call +type MockPoolOnNewBlockCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockPoolOnNewBlockCall) Return(arg0 error) *MockPoolOnNewBlockCall { + c.Call = c.Call.Return(arg0) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockPoolOnNewBlockCall) Do(f func(context.Context, *remote.StateChangeBatch, types.TxSlots, types.TxSlots, types.TxSlots, kv.Tx) error) *MockPoolOnNewBlockCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockPoolOnNewBlockCall) DoAndReturn(f func(context.Context, *remote.StateChangeBatch, types.TxSlots, types.TxSlots, types.TxSlots, kv.Tx) error) *MockPoolOnNewBlockCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Started mocks base method. +func (m *MockPool) Started() bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Started") + ret0, _ := ret[0].(bool) + return ret0 +} + +// Started indicates an expected call of Started. +func (mr *MockPoolMockRecorder) Started() *MockPoolStartedCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Started", reflect.TypeOf((*MockPool)(nil).Started)) + return &MockPoolStartedCall{Call: call} +} + +// MockPoolStartedCall wrap *gomock.Call +type MockPoolStartedCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockPoolStartedCall) Return(arg0 bool) *MockPoolStartedCall { + c.Call = c.Call.Return(arg0) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockPoolStartedCall) Do(f func() bool) *MockPoolStartedCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockPoolStartedCall) DoAndReturn(f func() bool) *MockPoolStartedCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// ValidateSerializedTxn mocks base method. +func (m *MockPool) ValidateSerializedTxn(arg0 []byte) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ValidateSerializedTxn", arg0) + ret0, _ := ret[0].(error) + return ret0 +} + +// ValidateSerializedTxn indicates an expected call of ValidateSerializedTxn. +func (mr *MockPoolMockRecorder) ValidateSerializedTxn(arg0 any) *MockPoolValidateSerializedTxnCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateSerializedTxn", reflect.TypeOf((*MockPool)(nil).ValidateSerializedTxn), arg0) + return &MockPoolValidateSerializedTxnCall{Call: call} +} + +// MockPoolValidateSerializedTxnCall wrap *gomock.Call +type MockPoolValidateSerializedTxnCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockPoolValidateSerializedTxnCall) Return(arg0 error) *MockPoolValidateSerializedTxnCall { + c.Call = c.Call.Return(arg0) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockPoolValidateSerializedTxnCall) Do(f func([]byte) error) *MockPoolValidateSerializedTxnCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockPoolValidateSerializedTxnCall) DoAndReturn(f func([]byte) error) *MockPoolValidateSerializedTxnCall { + c.Call = c.Call.DoAndReturn(f) + return c +} diff --git a/erigon-lib/txpool/test_util.go b/erigon-lib/txpool/test_util.go index 93c52f810a9..695c23a4a86 100644 --- a/erigon-lib/txpool/test_util.go +++ b/erigon-lib/txpool/test_util.go @@ -20,25 +20,27 @@ import ( "context" "sync" + "google.golang.org/protobuf/types/known/emptypb" + "github.com/ledgerwatch/erigon-lib/gointerfaces" "github.com/ledgerwatch/erigon-lib/gointerfaces/sentry" "github.com/ledgerwatch/erigon-lib/types" - "google.golang.org/protobuf/types/known/emptypb" ) -//go:generate moq -stub -out mocks_test.go . Pool - type MockSentry struct { ctx context.Context - *sentry.SentryServerMock + *sentry.MockSentryServer streams map[sentry.MessageId][]sentry.Sentry_MessagesServer peersStreams []sentry.Sentry_PeerEventsServer StreamWg sync.WaitGroup lock sync.RWMutex } -func NewMockSentry(ctx context.Context) *MockSentry { - return &MockSentry{ctx: ctx, SentryServerMock: &sentry.SentryServerMock{}} +func NewMockSentry(ctx context.Context, sentryServer *sentry.MockSentryServer) *MockSentry { + return &MockSentry{ + ctx: ctx, + MockSentryServer: sentryServer, + } } var peerID types.PeerID = gointerfaces.ConvertHashToH512([64]byte{0x12, 0x34, 0x50}) // "12345" diff --git a/sonar-project.properties b/sonar-project.properties index c135363a895..8daa603d847 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -6,7 +6,9 @@ sonar.sources=. sonar.exclusions=\ **/*.pb.go,\ **/gen_*.go,\ + **/*_gen.go,\ **/*_mock.go,\ + **/mock_*.go,\ **/graphql/graph/generated.go,\ **/*.sol,\ common/compiler/*.v.py,\ diff --git a/tools.go b/tools.go index 7a30b753e67..5458665badd 100644 --- a/tools.go +++ b/tools.go @@ -21,6 +21,7 @@ import ( _ "github.com/erigontech/mdbx-go/mdbxdist" _ "github.com/fjl/gencodec" _ "github.com/ugorji/go/codec/codecgen" + _ "go.uber.org/mock/mockgen" _ "go.uber.org/mock/mockgen/model" _ "google.golang.org/grpc/cmd/protoc-gen-go-grpc" )