Skip to content

Commit

Permalink
Add TestProcessOperationsWithNilRequests
Browse files Browse the repository at this point in the history
  • Loading branch information
terencechain committed Jan 31, 2025
1 parent eb8b62e commit c86f8fa
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
61 changes: 61 additions & 0 deletions beacon-chain/core/electra/transition_no_verify_sig_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package electra_test

import (
"context"
"testing"

"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/electra"
"github.com/prysmaticlabs/prysm/v5/consensus-types/blocks"
enginev1 "github.com/prysmaticlabs/prysm/v5/proto/engine/v1"
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v5/testing/require"
"github.com/prysmaticlabs/prysm/v5/testing/util"
)

func TestProcessOperationsWithNilRequests(t *testing.T) {
tests := []struct {
name string
modifyBlk func(blockElectra *ethpb.SignedBeaconBlockElectra)
errMsg string
}{
{
name: "Nil deposit request",
modifyBlk: func(blk *ethpb.SignedBeaconBlockElectra) {
blk.Block.Body.ExecutionRequests.Deposits = []*enginev1.DepositRequest{nil}
},
errMsg: "nil deposit request",
},
{
name: "Nil withdrawal request",
modifyBlk: func(blk *ethpb.SignedBeaconBlockElectra) {
blk.Block.Body.ExecutionRequests.Withdrawals = []*enginev1.WithdrawalRequest{nil}
},
errMsg: "nil withdrawal request",
},
{
name: "Nil consolidation request",
modifyBlk: func(blk *ethpb.SignedBeaconBlockElectra) {
blk.Block.Body.ExecutionRequests.Consolidations = []*enginev1.ConsolidationRequest{nil}
},
errMsg: "nil consolidation request",
},
}

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
st, ks := util.DeterministicGenesisStateElectra(t, 128)
blk, err := util.GenerateFullBlockElectra(st, ks, util.DefaultBlockGenConfig(), 1)
require.NoError(t, err)

tc.modifyBlk(blk)

b, err := blocks.NewSignedBeaconBlock(blk)
require.NoError(t, err)

require.NoError(t, st.SetSlot(1))

_, err = electra.ProcessOperations(context.Background(), st, b.Block())
require.ErrorContains(t, tc.errMsg, err)
})
}
}
3 changes: 3 additions & 0 deletions beacon-chain/core/electra/withdrawals.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ func ProcessWithdrawalRequests(ctx context.Context, st state.BeaconState, wrs []
defer span.End()
currentEpoch := slots.ToEpoch(st.Slot())
for _, wr := range wrs {
if wr == nil {
return nil, errors.New("nil execution layer withdrawal request")
}
amount := wr.Amount
isFullExitRequest := amount == params.BeaconConfig().FullExitRequestAmount
// If partial withdrawal queue is full, only full exits are processed
Expand Down

0 comments on commit c86f8fa

Please sign in to comment.