mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-07 02:02:18 +00:00
4ff91bebf8
* Update gomock * Update mockgen * Gaz * Go mod * Cleanup * Regenerate gomock * Manually fix import
69 lines
1.8 KiB
Go
69 lines
1.8 KiB
Go
package beacon_api
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/api/server/structs"
|
|
"github.com/prysmaticlabs/prysm/v5/testing/assert"
|
|
"github.com/prysmaticlabs/prysm/v5/testing/require"
|
|
"github.com/prysmaticlabs/prysm/v5/validator/client/beacon-api/mock"
|
|
"go.uber.org/mock/gomock"
|
|
)
|
|
|
|
func TestGetGenesis_ValidGenesis(t *testing.T) {
|
|
ctrl := gomock.NewController(t)
|
|
defer ctrl.Finish()
|
|
|
|
ctx := context.Background()
|
|
|
|
genesisResponseJson := structs.GetGenesisResponse{}
|
|
jsonRestHandler := mock.NewMockJsonRestHandler(ctrl)
|
|
jsonRestHandler.EXPECT().Get(
|
|
ctx,
|
|
"/eth/v1/beacon/genesis",
|
|
&genesisResponseJson,
|
|
).Return(
|
|
nil,
|
|
).SetArg(
|
|
2,
|
|
structs.GetGenesisResponse{
|
|
Data: &structs.Genesis{
|
|
GenesisTime: "1234",
|
|
GenesisValidatorsRoot: "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2",
|
|
},
|
|
},
|
|
).Times(1)
|
|
|
|
genesisProvider := &beaconApiGenesisProvider{jsonRestHandler: jsonRestHandler}
|
|
resp, err := genesisProvider.GetGenesis(ctx)
|
|
assert.NoError(t, err)
|
|
require.NotNil(t, resp)
|
|
assert.Equal(t, "1234", resp.GenesisTime)
|
|
assert.Equal(t, "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2", resp.GenesisValidatorsRoot)
|
|
}
|
|
|
|
func TestGetGenesis_NilData(t *testing.T) {
|
|
ctrl := gomock.NewController(t)
|
|
defer ctrl.Finish()
|
|
|
|
ctx := context.Background()
|
|
|
|
genesisResponseJson := structs.GetGenesisResponse{}
|
|
jsonRestHandler := mock.NewMockJsonRestHandler(ctrl)
|
|
jsonRestHandler.EXPECT().Get(
|
|
ctx,
|
|
"/eth/v1/beacon/genesis",
|
|
&genesisResponseJson,
|
|
).Return(
|
|
nil,
|
|
).SetArg(
|
|
2,
|
|
structs.GetGenesisResponse{Data: nil},
|
|
).Times(1)
|
|
|
|
genesisProvider := &beaconApiGenesisProvider{jsonRestHandler: jsonRestHandler}
|
|
_, err := genesisProvider.GetGenesis(ctx)
|
|
assert.ErrorContains(t, "genesis data is nil", err)
|
|
}
|