Skip to content

Commit

Permalink
change context expectation in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rkapka committed Jun 20, 2024
1 parent c0411b6 commit f8afde5
Show file tree
Hide file tree
Showing 38 changed files with 178 additions and 182 deletions.
8 changes: 4 additions & 4 deletions validator/client/beacon-api/activation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func TestActivation_Nominal(t *testing.T) {

// Get does not return any result for non existing key
jsonRestHandler.EXPECT().Post(
ctx,
gomock.Any(),
"/eth/v1/beacon/states/head/validators",
nil,
bytes.NewBuffer(reqBytes),
Expand Down Expand Up @@ -240,7 +240,7 @@ func TestActivation_InvalidData(t *testing.T) {

jsonRestHandler := mock.NewMockJsonRestHandler(ctrl)
jsonRestHandler.EXPECT().Post(
ctx,
gomock.Any(),
gomock.Any(),
gomock.Any(),
gomock.Any(),
Expand Down Expand Up @@ -281,7 +281,7 @@ func TestActivation_JsonResponseError(t *testing.T) {

jsonRestHandler := mock.NewMockJsonRestHandler(ctrl)
jsonRestHandler.EXPECT().Post(
ctx,
gomock.Any(),
gomock.Any(),
gomock.Any(),
gomock.Any(),
Expand All @@ -291,7 +291,7 @@ func TestActivation_JsonResponseError(t *testing.T) {
).Times(1)

jsonRestHandler.EXPECT().Get(
ctx,
gomock.Any(),
gomock.Any(),
gomock.Any(),
).Return(
Expand Down
6 changes: 3 additions & 3 deletions validator/client/beacon-api/attestation_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestGetAttestationData_ValidAttestation(t *testing.T) {
produceAttestationDataResponseJson := structs.GetAttestationDataResponse{}

jsonRestHandler.EXPECT().Get(
ctx,
gomock.Any(),
fmt.Sprintf("/eth/v1/validator/attestation_data?committee_index=%d&slot=%d", expectedCommitteeIndex, expectedSlot),
&produceAttestationDataResponseJson,
).Return(
Expand Down Expand Up @@ -183,7 +183,7 @@ func TestGetAttestationData_InvalidData(t *testing.T) {
produceAttestationDataResponseJson := structs.GetAttestationDataResponse{}
jsonRestHandler := mock.NewMockJsonRestHandler(ctrl)
jsonRestHandler.EXPECT().Get(
ctx,
gomock.Any(),
"/eth/v1/validator/attestation_data?committee_index=2&slot=1",
&produceAttestationDataResponseJson,
).Return(
Expand Down Expand Up @@ -212,7 +212,7 @@ func TestGetAttestationData_JsonResponseError(t *testing.T) {
jsonRestHandler := mock.NewMockJsonRestHandler(ctrl)
produceAttestationDataResponseJson := structs.GetAttestationDataResponse{}
jsonRestHandler.EXPECT().Get(
ctx,
gomock.Any(),
fmt.Sprintf("/eth/v1/validator/attestation_data?committee_index=%d&slot=%d", committeeIndex, slot),
&produceAttestationDataResponseJson,
).Return(
Expand Down
30 changes: 15 additions & 15 deletions validator/client/beacon-api/beacon_api_beacon_chain_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestListValidators(t *testing.T) {
ctx := context.Background()

stateValidatorsProvider := mock.NewMockStateValidatorsProvider(ctrl)
stateValidatorsProvider.EXPECT().StateValidatorsForSlot(ctx, gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(
stateValidatorsProvider.EXPECT().StateValidatorsForSlot(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(
nil,
errors.New("foo error"),
)
Expand All @@ -78,7 +78,7 @@ func TestListValidators(t *testing.T) {
ctx := context.Background()

stateValidatorsProvider := mock.NewMockStateValidatorsProvider(ctrl)
stateValidatorsProvider.EXPECT().StateValidatorsForSlot(ctx, gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(
stateValidatorsProvider.EXPECT().StateValidatorsForSlot(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(
nil,
errors.New("bar error"),
)
Expand All @@ -96,7 +96,7 @@ func TestListValidators(t *testing.T) {
ctx := context.Background()

stateValidatorsProvider := mock.NewMockStateValidatorsProvider(ctrl)
stateValidatorsProvider.EXPECT().StateValidatorsForHead(ctx, gomock.Any(), gomock.Any(), gomock.Any()).Return(
stateValidatorsProvider.EXPECT().StateValidatorsForHead(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(
nil,
errors.New("foo error"),
)
Expand All @@ -114,13 +114,13 @@ func TestListValidators(t *testing.T) {
ctx := context.Background()

stateValidatorsProvider := mock.NewMockStateValidatorsProvider(ctrl)
stateValidatorsProvider.EXPECT().StateValidatorsForHead(ctx, gomock.Any(), gomock.Any(), gomock.Any()).Return(
stateValidatorsProvider.EXPECT().StateValidatorsForHead(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(
nil,
nil,
)

jsonRestHandler := mock.NewMockJsonRestHandler(ctrl)
jsonRestHandler.EXPECT().Get(ctx, blockHeaderEndpoint, gomock.Any()).Return(errors.New("bar error"))
jsonRestHandler.EXPECT().Get(gomock.Any(), blockHeaderEndpoint, gomock.Any()).Return(errors.New("bar error"))

beaconChainClient := beaconApiChainClient{
stateValidatorsProvider: stateValidatorsProvider,
Expand Down Expand Up @@ -187,13 +187,13 @@ func TestListValidators(t *testing.T) {
ctx := context.Background()

stateValidatorsProvider := mock.NewMockStateValidatorsProvider(ctrl)
stateValidatorsProvider.EXPECT().StateValidatorsForHead(ctx, gomock.Any(), gomock.Any(), gomock.Any()).Return(
stateValidatorsProvider.EXPECT().StateValidatorsForHead(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(
nil,
nil,
)

jsonRestHandler := mock.NewMockJsonRestHandler(ctrl)
jsonRestHandler.EXPECT().Get(ctx, blockHeaderEndpoint, gomock.Any()).Return(
jsonRestHandler.EXPECT().Get(gomock.Any(), blockHeaderEndpoint, gomock.Any()).Return(
nil,
).SetArg(
2,
Expand Down Expand Up @@ -328,7 +328,7 @@ func TestListValidators(t *testing.T) {
ctx := context.Background()

stateValidatorsProvider := mock.NewMockStateValidatorsProvider(ctrl)
stateValidatorsProvider.EXPECT().StateValidatorsForSlot(ctx, gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(
stateValidatorsProvider.EXPECT().StateValidatorsForSlot(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(
testCase.generateStateValidatorsResponse(),
nil,
)
Expand Down Expand Up @@ -556,7 +556,7 @@ func TestListValidators(t *testing.T) {
ctx := context.Background()

stateValidatorsProvider := mock.NewMockStateValidatorsProvider(ctrl)
stateValidatorsProvider.EXPECT().StateValidatorsForSlot(ctx, primitives.Slot(0), make([]string, 0), []primitives.ValidatorIndex{}, nil).Return(
stateValidatorsProvider.EXPECT().StateValidatorsForSlot(gomock.Any(), primitives.Slot(0), make([]string, 0), []primitives.ValidatorIndex{}, nil).Return(
testCase.generateJsonStateValidatorsResponse(),
nil,
)
Expand Down Expand Up @@ -745,7 +745,7 @@ func TestGetChainHead(t *testing.T) {

finalityCheckpointsResponse := structs.GetFinalityCheckpointsResponse{}
jsonRestHandler := mock.NewMockJsonRestHandler(ctrl)
jsonRestHandler.EXPECT().Get(ctx, finalityCheckpointsEndpoint, &finalityCheckpointsResponse).Return(
jsonRestHandler.EXPECT().Get(gomock.Any(), finalityCheckpointsEndpoint, &finalityCheckpointsResponse).Return(
testCase.finalityCheckpointsError,
).SetArg(
2,
Expand Down Expand Up @@ -844,15 +844,15 @@ func TestGetChainHead(t *testing.T) {
jsonRestHandler := mock.NewMockJsonRestHandler(ctrl)

finalityCheckpointsResponse := structs.GetFinalityCheckpointsResponse{}
jsonRestHandler.EXPECT().Get(ctx, finalityCheckpointsEndpoint, &finalityCheckpointsResponse).Return(
jsonRestHandler.EXPECT().Get(gomock.Any(), finalityCheckpointsEndpoint, &finalityCheckpointsResponse).Return(
nil,
).SetArg(
2,
generateValidFinalityCheckpointsResponse(),
)

headBlockHeadersResponse := structs.GetBlockHeaderResponse{}
jsonRestHandler.EXPECT().Get(ctx, headBlockHeadersEndpoint, &headBlockHeadersResponse).Return(
jsonRestHandler.EXPECT().Get(gomock.Any(), headBlockHeadersEndpoint, &headBlockHeadersResponse).Return(
testCase.headBlockHeadersError,
).SetArg(
2,
Expand All @@ -874,15 +874,15 @@ func TestGetChainHead(t *testing.T) {
jsonRestHandler := mock.NewMockJsonRestHandler(ctrl)

finalityCheckpointsResponse := structs.GetFinalityCheckpointsResponse{}
jsonRestHandler.EXPECT().Get(ctx, finalityCheckpointsEndpoint, &finalityCheckpointsResponse).Return(
jsonRestHandler.EXPECT().Get(gomock.Any(), finalityCheckpointsEndpoint, &finalityCheckpointsResponse).Return(
nil,
).SetArg(
2,
generateValidFinalityCheckpointsResponse(),
)

headBlockHeadersResponse := structs.GetBlockHeaderResponse{}
jsonRestHandler.EXPECT().Get(ctx, headBlockHeadersEndpoint, &headBlockHeadersResponse).Return(
jsonRestHandler.EXPECT().Get(gomock.Any(), headBlockHeadersEndpoint, &headBlockHeadersResponse).Return(
nil,
).SetArg(
2,
Expand Down Expand Up @@ -940,7 +940,7 @@ func Test_beaconApiBeaconChainClient_GetValidatorPerformance(t *testing.T) {
want := &ethpb.ValidatorPerformanceResponse{}
jsonRestHandler := mock.NewMockJsonRestHandler(ctrl)
jsonRestHandler.EXPECT().Post(
ctx,
gomock.Any(),
getValidatorPerformanceEndpoint,
nil,
bytes.NewBuffer(request),
Expand Down
16 changes: 8 additions & 8 deletions validator/client/beacon-api/beacon_api_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func TestGetFork_Nominal(t *testing.T) {
ctx := context.Background()

jsonRestHandler.EXPECT().Get(
ctx,
gomock.Any(),
forkEndpoint,
&stateForkResponseJson,
).Return(
Expand Down Expand Up @@ -137,7 +137,7 @@ func TestGetFork_Invalid(t *testing.T) {
ctx := context.Background()

jsonRestHandler.EXPECT().Get(
ctx,
gomock.Any(),
forkEndpoint,
gomock.Any(),
).Return(
Expand Down Expand Up @@ -176,7 +176,7 @@ func TestGetHeaders_Nominal(t *testing.T) {
ctx := context.Background()

jsonRestHandler.EXPECT().Get(
ctx,
gomock.Any(),
headersEndpoint,
&blockHeadersResponseJson,
).Return(
Expand Down Expand Up @@ -204,7 +204,7 @@ func TestGetHeaders_Invalid(t *testing.T) {
ctx := context.Background()

jsonRestHandler.EXPECT().Get(
ctx,
gomock.Any(),
headersEndpoint,
gomock.Any(),
).Return(
Expand Down Expand Up @@ -248,7 +248,7 @@ func TestGetLiveness_Nominal(t *testing.T) {

jsonRestHandler := mock.NewMockJsonRestHandler(ctrl)
jsonRestHandler.EXPECT().Post(
ctx,
gomock.Any(),
livenessEndpoint,
nil,
bytes.NewBuffer(marshalledIndexes),
Expand All @@ -275,7 +275,7 @@ func TestGetLiveness_Invalid(t *testing.T) {

jsonRestHandler := mock.NewMockJsonRestHandler(ctrl)
jsonRestHandler.EXPECT().Post(
ctx,
gomock.Any(),
livenessEndpoint,
nil,
gomock.Any(),
Expand Down Expand Up @@ -324,7 +324,7 @@ func TestGetIsSyncing_Nominal(t *testing.T) {
ctx := context.Background()

jsonRestHandler.EXPECT().Get(
ctx,
gomock.Any(),
syncingEndpoint,
&syncingResponseJson,
).Return(
Expand Down Expand Up @@ -355,7 +355,7 @@ func TestGetIsSyncing_Invalid(t *testing.T) {
ctx := context.Background()

jsonRestHandler.EXPECT().Get(
ctx,
gomock.Any(),
syncingEndpoint,
&syncingResponseJson,
).Return(
Expand Down
8 changes: 4 additions & 4 deletions validator/client/beacon-api/beacon_api_node_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func TestGetGenesis(t *testing.T) {

genesisProvider := mock.NewMockGenesisProvider(ctrl)
genesisProvider.EXPECT().Genesis(
ctx,
gomock.Any(),
).Return(
testCase.genesisResponse,
testCase.genesisError,
Expand All @@ -124,7 +124,7 @@ func TestGetGenesis(t *testing.T) {

if testCase.queriesDepositContract {
jsonRestHandler.EXPECT().Get(
ctx,
gomock.Any(),
"/eth/v1/config/deposit_contract",
&depositContractJson,
).Return(
Expand Down Expand Up @@ -203,7 +203,7 @@ func TestGetSyncStatus(t *testing.T) {
syncingResponse := structs.SyncStatusResponse{}
jsonRestHandler := mock.NewMockJsonRestHandler(ctrl)
jsonRestHandler.EXPECT().Get(
ctx,
gomock.Any(),
syncingEndpoint,
&syncingResponse,
).Return(
Expand Down Expand Up @@ -267,7 +267,7 @@ func TestGetVersion(t *testing.T) {
var versionResponse structs.GetVersionResponse
jsonRestHandler := mock.NewMockJsonRestHandler(ctrl)
jsonRestHandler.EXPECT().Get(
ctx,
gomock.Any(),
versionEndpoint,
&versionResponse,
).Return(
Expand Down
10 changes: 5 additions & 5 deletions validator/client/beacon-api/beacon_api_validator_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestBeaconApiValidatorClient_GetAttestationDataValid(t *testing.T) {
jsonRestHandler := mock.NewMockJsonRestHandler(ctrl)
produceAttestationDataResponseJson := structs.GetAttestationDataResponse{}
jsonRestHandler.EXPECT().Get(
ctx,
gomock.Any(),
fmt.Sprintf("/eth/v1/validator/attestation_data?committee_index=%d&slot=%d", committeeIndex, slot),
&produceAttestationDataResponseJson,
).Return(
Expand Down Expand Up @@ -66,7 +66,7 @@ func TestBeaconApiValidatorClient_GetAttestationDataError(t *testing.T) {
jsonRestHandler := mock.NewMockJsonRestHandler(ctrl)
produceAttestationDataResponseJson := structs.GetAttestationDataResponse{}
jsonRestHandler.EXPECT().Get(
ctx,
gomock.Any(),
fmt.Sprintf("/eth/v1/validator/attestation_data?committee_index=%d&slot=%d", committeeIndex, slot),
&produceAttestationDataResponseJson,
).Return(
Expand Down Expand Up @@ -109,7 +109,7 @@ func TestBeaconApiValidatorClient_DomainDataValid(t *testing.T) {
ctx := context.Background()

genesisProvider := mock.NewMockGenesisProvider(ctrl)
genesisProvider.EXPECT().Genesis(ctx).Return(
genesisProvider.EXPECT().Genesis(gomock.Any()).Return(
&structs.Genesis{GenesisValidatorsRoot: genesisValidatorRoot},
nil,
).Times(2)
Expand Down Expand Up @@ -139,7 +139,7 @@ func TestBeaconApiValidatorClient_ProposeBeaconBlockValid(t *testing.T) {

jsonRestHandler := mock.NewMockJsonRestHandler(ctrl)
jsonRestHandler.EXPECT().Post(
ctx,
gomock.Any(),
"/eth/v1/beacon/blocks",
map[string]string{"Eth-Consensus-Version": "phase0"},
gomock.Any(),
Expand Down Expand Up @@ -175,7 +175,7 @@ func TestBeaconApiValidatorClient_ProposeBeaconBlockError(t *testing.T) {

jsonRestHandler := mock.NewMockJsonRestHandler(ctrl)
jsonRestHandler.EXPECT().Post(
ctx,
gomock.Any(),
"/eth/v1/beacon/blocks",
map[string]string{"Eth-Consensus-Version": "phase0"},
gomock.Any(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func TestGetAggregatedSelections(t *testing.T) {

ctx := context.Background()
jsonRestHandler.EXPECT().Post(
ctx,
gomock.Any(),
"/eth/v1/validator/beacon_committee_selections",
nil,
bytes.NewBuffer(reqBody),
Expand Down
6 changes: 3 additions & 3 deletions validator/client/beacon-api/domain_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestGetDomainData_ValidDomainData(t *testing.T) {

// Make sure that Genesis() is called exactly once
genesisProvider := mock.NewMockGenesisProvider(ctrl)
genesisProvider.EXPECT().Genesis(ctx).Return(
genesisProvider.EXPECT().Genesis(gomock.Any()).Return(
&structs.Genesis{GenesisValidatorsRoot: genesisValidatorRoot},
nil,
).Times(1)
Expand Down Expand Up @@ -66,7 +66,7 @@ func TestGetDomainData_GenesisError(t *testing.T) {

// Make sure that Genesis() is called exactly once
genesisProvider := mock.NewMockGenesisProvider(ctrl)
genesisProvider.EXPECT().Genesis(ctx).Return(nil, errors.New("foo error")).Times(1)
genesisProvider.EXPECT().Genesis(gomock.Any()).Return(nil, errors.New("foo error")).Times(1)

validatorClient := &beaconApiValidatorClient{genesisProvider: genesisProvider}
_, err := validatorClient.domainData(ctx, epoch, domainType)
Expand All @@ -85,7 +85,7 @@ func TestGetDomainData_InvalidGenesisRoot(t *testing.T) {

// Make sure that Genesis() is called exactly once
genesisProvider := mock.NewMockGenesisProvider(ctrl)
genesisProvider.EXPECT().Genesis(ctx).Return(
genesisProvider.EXPECT().Genesis(gomock.Any()).Return(
&structs.Genesis{GenesisValidatorsRoot: "foo"},
nil,
).Times(1)
Expand Down
Loading

0 comments on commit f8afde5

Please sign in to comment.