mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-10 16:08:26 -05:00
* remove api/gateway/apimiddleware * fix errors in api/gateway * remove beacon-chain/rpc/apimiddleware * fix errors in api/client/beacon * fix errors in validator/client/beacon-api * fix errors in beacon-chain/node * fix errors in validator/node * fix errors in cmd/prysmctl/validator * fix errors in testing/endtoend * fix all other code * remove comment * fix tests --------- Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
106 lines
3.4 KiB
Go
106 lines
3.4 KiB
Go
package beacon_api
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"github.com/golang/mock/gomock"
|
|
"github.com/pkg/errors"
|
|
"github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/shared"
|
|
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/v4/testing/assert"
|
|
"github.com/prysmaticlabs/prysm/v4/testing/require"
|
|
"github.com/prysmaticlabs/prysm/v4/validator/client/beacon-api/mock"
|
|
test_helpers "github.com/prysmaticlabs/prysm/v4/validator/client/beacon-api/test-helpers"
|
|
)
|
|
|
|
func TestSubmitSignedAggregateSelectionProof_Valid(t *testing.T) {
|
|
ctrl := gomock.NewController(t)
|
|
defer ctrl.Finish()
|
|
|
|
signedAggregateAndProof := generateSignedAggregateAndProofJson()
|
|
marshalledSignedAggregateSignedAndProof, err := json.Marshal([]*shared.SignedAggregateAttestationAndProof{jsonifySignedAggregateAndProof(signedAggregateAndProof)})
|
|
require.NoError(t, err)
|
|
|
|
ctx := context.Background()
|
|
|
|
jsonRestHandler := mock.NewMockJsonRestHandler(ctrl)
|
|
jsonRestHandler.EXPECT().Post(
|
|
ctx,
|
|
"/eth/v1/validator/aggregate_and_proofs",
|
|
nil,
|
|
bytes.NewBuffer(marshalledSignedAggregateSignedAndProof),
|
|
nil,
|
|
).Return(
|
|
nil,
|
|
nil,
|
|
).Times(1)
|
|
|
|
attestationDataRoot, err := signedAggregateAndProof.Message.Aggregate.Data.HashTreeRoot()
|
|
require.NoError(t, err)
|
|
|
|
validatorClient := &beaconApiValidatorClient{jsonRestHandler: jsonRestHandler}
|
|
resp, err := validatorClient.submitSignedAggregateSelectionProof(ctx, ðpb.SignedAggregateSubmitRequest{
|
|
SignedAggregateAndProof: signedAggregateAndProof,
|
|
})
|
|
require.NoError(t, err)
|
|
assert.DeepEqual(t, attestationDataRoot[:], resp.AttestationDataRoot)
|
|
}
|
|
|
|
func TestSubmitSignedAggregateSelectionProof_BadRequest(t *testing.T) {
|
|
ctrl := gomock.NewController(t)
|
|
defer ctrl.Finish()
|
|
|
|
signedAggregateAndProof := generateSignedAggregateAndProofJson()
|
|
marshalledSignedAggregateSignedAndProof, err := json.Marshal([]*shared.SignedAggregateAttestationAndProof{jsonifySignedAggregateAndProof(signedAggregateAndProof)})
|
|
require.NoError(t, err)
|
|
|
|
ctx := context.Background()
|
|
jsonRestHandler := mock.NewMockJsonRestHandler(ctrl)
|
|
jsonRestHandler.EXPECT().Post(
|
|
ctx,
|
|
"/eth/v1/validator/aggregate_and_proofs",
|
|
nil,
|
|
bytes.NewBuffer(marshalledSignedAggregateSignedAndProof),
|
|
nil,
|
|
).Return(
|
|
nil,
|
|
errors.New("bad request"),
|
|
).Times(1)
|
|
|
|
validatorClient := &beaconApiValidatorClient{jsonRestHandler: jsonRestHandler}
|
|
_, err = validatorClient.submitSignedAggregateSelectionProof(ctx, ðpb.SignedAggregateSubmitRequest{
|
|
SignedAggregateAndProof: signedAggregateAndProof,
|
|
})
|
|
assert.ErrorContains(t, "bad request", err)
|
|
}
|
|
|
|
func generateSignedAggregateAndProofJson() *ethpb.SignedAggregateAttestationAndProof {
|
|
return ðpb.SignedAggregateAttestationAndProof{
|
|
Message: ðpb.AggregateAttestationAndProof{
|
|
AggregatorIndex: 72,
|
|
Aggregate: ðpb.Attestation{
|
|
AggregationBits: test_helpers.FillByteSlice(4, 74),
|
|
Data: ðpb.AttestationData{
|
|
Slot: 75,
|
|
CommitteeIndex: 76,
|
|
BeaconBlockRoot: test_helpers.FillByteSlice(32, 38),
|
|
Source: ðpb.Checkpoint{
|
|
Epoch: 78,
|
|
Root: test_helpers.FillByteSlice(32, 79),
|
|
},
|
|
Target: ðpb.Checkpoint{
|
|
Epoch: 80,
|
|
Root: test_helpers.FillByteSlice(32, 81),
|
|
},
|
|
},
|
|
Signature: test_helpers.FillByteSlice(96, 82),
|
|
},
|
|
SelectionProof: test_helpers.FillByteSlice(96, 82),
|
|
},
|
|
Signature: test_helpers.FillByteSlice(96, 82),
|
|
}
|
|
}
|