mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-08 10:41:19 +00:00
5aac06f04e
* begin move * use same import path * imports * regen protos * regen * no rename * generate ssz * gaz * fmt * edit build file * imports * modify * remove generated files * remove protos * edit imports in prysm * beacon chain all builds * edit script * add generated pbs * add replace rules * license for ethereumapis protos * change visibility * fmt * update build files to gaz ignore * use proper form * edit imports * wrap block * revert scripts * revert go mod
64 lines
1.7 KiB
Go
64 lines
1.7 KiB
Go
package debugv1
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
types "github.com/prysmaticlabs/eth2-types"
|
|
blockchainmock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/rpc/testutil"
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1"
|
|
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
|
sharedtestutil "github.com/prysmaticlabs/prysm/shared/testutil"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
|
"google.golang.org/protobuf/types/known/emptypb"
|
|
)
|
|
|
|
func TestGetBeaconState(t *testing.T) {
|
|
fakeState, err := sharedtestutil.NewBeaconState()
|
|
require.NoError(t, err)
|
|
server := &Server{
|
|
StateFetcher: &testutil.MockFetcher{
|
|
BeaconState: fakeState,
|
|
},
|
|
}
|
|
resp, err := server.GetBeaconState(context.Background(), ðpb.StateRequest{
|
|
StateId: make([]byte, 0),
|
|
})
|
|
require.NoError(t, err)
|
|
assert.NotNil(t, resp)
|
|
}
|
|
|
|
func TestListForkChoiceHeads(t *testing.T) {
|
|
ctx := context.Background()
|
|
|
|
expectedSlotsAndRoots := []struct {
|
|
Slot types.Slot
|
|
Root [32]byte
|
|
}{{
|
|
Slot: 0,
|
|
Root: bytesutil.ToBytes32(bytesutil.PadTo([]byte("foo"), 32)),
|
|
}, {
|
|
Slot: 1,
|
|
Root: bytesutil.ToBytes32(bytesutil.PadTo([]byte("bar"), 32)),
|
|
}}
|
|
|
|
server := &Server{
|
|
HeadFetcher: &blockchainmock.ChainService{},
|
|
}
|
|
resp, err := server.ListForkChoiceHeads(ctx, &emptypb.Empty{})
|
|
require.NoError(t, err)
|
|
assert.Equal(t, 2, len(resp.Data))
|
|
for _, sr := range expectedSlotsAndRoots {
|
|
found := false
|
|
for _, h := range resp.Data {
|
|
if h.Slot == sr.Slot {
|
|
found = true
|
|
assert.DeepEqual(t, sr.Root[:], h.Root)
|
|
}
|
|
}
|
|
assert.Equal(t, true, found, "Expected head not found")
|
|
}
|
|
}
|