mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-07 22:54:17 -05:00
adding in error for generic check (#14801)
This commit is contained in:
3
changelog/james-prysm_handle-pbgeneric-error.md
Normal file
3
changelog/james-prysm_handle-pbgeneric-error.md
Normal file
@@ -0,0 +1,3 @@
|
||||
### Fixed
|
||||
|
||||
- fix panic with type cast on pbgenericblock()
|
||||
@@ -124,8 +124,12 @@ func (b *SignedBeaconBlock) PbGenericBlock() (*eth.GenericSignedBeaconBlock, err
|
||||
Block: ð.GenericSignedBeaconBlock_BlindedDeneb{BlindedDeneb: pb.(*eth.SignedBlindedBeaconBlockDeneb)},
|
||||
}, nil
|
||||
}
|
||||
bc, ok := pb.(*eth.SignedBeaconBlockContentsDeneb)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("PbGenericBlock() only supports block content type but got %T", pb)
|
||||
}
|
||||
return ð.GenericSignedBeaconBlock{
|
||||
Block: ð.GenericSignedBeaconBlock_Deneb{Deneb: pb.(*eth.SignedBeaconBlockContentsDeneb)},
|
||||
Block: ð.GenericSignedBeaconBlock_Deneb{Deneb: bc},
|
||||
}, nil
|
||||
case version.Electra:
|
||||
if b.IsBlinded() {
|
||||
@@ -133,8 +137,12 @@ func (b *SignedBeaconBlock) PbGenericBlock() (*eth.GenericSignedBeaconBlock, err
|
||||
Block: ð.GenericSignedBeaconBlock_BlindedElectra{BlindedElectra: pb.(*eth.SignedBlindedBeaconBlockElectra)},
|
||||
}, nil
|
||||
}
|
||||
bc, ok := pb.(*eth.SignedBeaconBlockContentsElectra)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("PbGenericBlock() only supports block content type but got %T", pb)
|
||||
}
|
||||
return ð.GenericSignedBeaconBlock{
|
||||
Block: ð.GenericSignedBeaconBlock_Electra{Electra: pb.(*eth.SignedBeaconBlockContentsElectra)},
|
||||
Block: ð.GenericSignedBeaconBlock_Electra{Electra: bc},
|
||||
}, nil
|
||||
case version.Fulu:
|
||||
if b.IsBlinded() {
|
||||
@@ -142,8 +150,12 @@ func (b *SignedBeaconBlock) PbGenericBlock() (*eth.GenericSignedBeaconBlock, err
|
||||
Block: ð.GenericSignedBeaconBlock_BlindedFulu{BlindedFulu: pb.(*eth.SignedBlindedBeaconBlockFulu)},
|
||||
}, nil
|
||||
}
|
||||
bc, ok := pb.(*eth.SignedBeaconBlockContentsFulu)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("PbGenericBlock() only supports block content type but got %T", pb)
|
||||
}
|
||||
return ð.GenericSignedBeaconBlock{
|
||||
Block: ð.GenericSignedBeaconBlock_Fulu{Fulu: pb.(*eth.SignedBeaconBlockContentsFulu)},
|
||||
Block: ð.GenericSignedBeaconBlock_Fulu{Fulu: bc},
|
||||
}, nil
|
||||
default:
|
||||
return nil, errIncorrectBlockVersion
|
||||
|
||||
@@ -322,3 +322,30 @@ func TestGenerateVoluntaryExits(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, coreBlock.VerifyExitAndSignature(val, beaconState, exit))
|
||||
}
|
||||
|
||||
func Test_PostDenebPbGenericBlock_ErrorsForPlainBlock(t *testing.T) {
|
||||
t.Run("Deneb block returns type error", func(t *testing.T) {
|
||||
eb := NewBeaconBlockDeneb()
|
||||
b, err := blocks.NewSignedBeaconBlock(eb)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = b.PbGenericBlock()
|
||||
require.ErrorContains(t, "PbGenericBlock() only supports block content type but got", err)
|
||||
})
|
||||
t.Run("Electra block returns type error", func(t *testing.T) {
|
||||
eb := NewBeaconBlockElectra()
|
||||
b, err := blocks.NewSignedBeaconBlock(eb)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = b.PbGenericBlock()
|
||||
require.ErrorContains(t, "PbGenericBlock() only supports block content type but got", err)
|
||||
})
|
||||
t.Run("Fulu block returns type error", func(t *testing.T) {
|
||||
eb := NewBeaconBlockFulu()
|
||||
b, err := blocks.NewSignedBeaconBlock(eb)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = b.PbGenericBlock()
|
||||
require.ErrorContains(t, "PbGenericBlock() only supports block content type but got", err)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user