mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-24 20:37:17 +00:00
Improve Validator Index RPC Error Handling (#11363)
* adding in nil check for head * adding changes based on feedback * Update beacon-chain/rpc/prysm/v1alpha1/validator/server_test.go Co-authored-by: Radosław Kapka <rkapka@wp.pl>
This commit is contained in:
parent
9729b2ec77
commit
52d48b328f
@ -123,6 +123,9 @@ func (vs *Server) ValidatorIndex(ctx context.Context, req *ethpb.ValidatorIndexR
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "Could not determine head state: %v", err)
|
||||
}
|
||||
if st == nil || st.IsNil() {
|
||||
return nil, status.Errorf(codes.Internal, "head state is empty")
|
||||
}
|
||||
index, ok := st.ValidatorIndexByPubkey(bytesutil.ToBytes48(req.PublicKey))
|
||||
if !ok {
|
||||
return nil, status.Errorf(codes.NotFound, "Could not find validator index for public key %#x", req.PublicKey)
|
||||
|
@ -48,6 +48,18 @@ func TestValidatorIndex_OK(t *testing.T) {
|
||||
assert.NoError(t, err, "Could not get validator index")
|
||||
}
|
||||
|
||||
func TestValidatorIndex_StateEmpty(t *testing.T) {
|
||||
Server := &Server{
|
||||
HeadFetcher: &mockChain.ChainService{},
|
||||
}
|
||||
pubKey := pubKey(1)
|
||||
req := ðpb.ValidatorIndexRequest{
|
||||
PublicKey: pubKey,
|
||||
}
|
||||
_, err := Server.ValidatorIndex(context.Background(), req)
|
||||
assert.ErrorContains(t, "head state is empty", err)
|
||||
}
|
||||
|
||||
func TestWaitForActivation_ContextClosed(t *testing.T) {
|
||||
beaconState, err := v1.InitializeFromProto(ðpb.BeaconState{
|
||||
Slot: 0,
|
||||
|
Loading…
Reference in New Issue
Block a user