mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-08 21:08:10 -05:00
64 lines
1.9 KiB
Go
64 lines
1.9 KiB
Go
package beacon_api
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"github.com/OffchainLabs/prysm/v6/api/server/structs"
|
|
ethpb "github.com/OffchainLabs/prysm/v6/proto/prysm/v1alpha1"
|
|
"github.com/OffchainLabs/prysm/v6/testing/assert"
|
|
"github.com/OffchainLabs/prysm/v6/testing/require"
|
|
"github.com/OffchainLabs/prysm/v6/validator/client/beacon-api/mock"
|
|
testhelpers "github.com/OffchainLabs/prysm/v6/validator/client/beacon-api/test-helpers"
|
|
"go.uber.org/mock/gomock"
|
|
)
|
|
|
|
func TestProposeBeaconBlock_Altair(t *testing.T) {
|
|
ctrl := gomock.NewController(t)
|
|
defer ctrl.Finish()
|
|
jsonRestHandler := mock.NewMockJsonRestHandler(ctrl)
|
|
|
|
altairBlock := generateSignedAltairBlock()
|
|
|
|
genericSignedBlock := ðpb.GenericSignedBeaconBlock{}
|
|
genericSignedBlock.Block = altairBlock
|
|
|
|
jsonAltairBlock := structs.SignedBeaconBlockAltairFromConsensus(altairBlock.Altair)
|
|
|
|
marshalledBlock, err := json.Marshal(jsonAltairBlock)
|
|
require.NoError(t, err)
|
|
|
|
ctx := t.Context()
|
|
|
|
// Make sure that what we send in the POST body is the marshalled version of the protobuf block
|
|
headers := map[string]string{"Eth-Consensus-Version": "altair"}
|
|
jsonRestHandler.EXPECT().Post(
|
|
gomock.Any(),
|
|
"/eth/v2/beacon/blocks",
|
|
headers,
|
|
bytes.NewBuffer(marshalledBlock),
|
|
nil,
|
|
)
|
|
|
|
validatorClient := &beaconApiValidatorClient{jsonRestHandler: jsonRestHandler}
|
|
proposeResponse, err := validatorClient.proposeBeaconBlock(ctx, genericSignedBlock)
|
|
assert.NoError(t, err)
|
|
require.NotNil(t, proposeResponse)
|
|
|
|
expectedBlockRoot, err := altairBlock.Altair.Block.HashTreeRoot()
|
|
require.NoError(t, err)
|
|
|
|
// Make sure that the block root is set
|
|
assert.DeepEqual(t, expectedBlockRoot[:], proposeResponse.BlockRoot)
|
|
}
|
|
|
|
func generateSignedAltairBlock() *ethpb.GenericSignedBeaconBlock_Altair {
|
|
return ðpb.GenericSignedBeaconBlock_Altair{
|
|
Altair: ðpb.SignedBeaconBlockAltair{
|
|
Block: testhelpers.GenerateProtoAltairBeaconBlock(),
|
|
Signature: testhelpers.FillByteSlice(96, 112),
|
|
},
|
|
}
|
|
}
|