Skip to content

Commit

Permalink
tests to increase the coverage (berachain#1445)
Browse files Browse the repository at this point in the history
Signed-off-by: nidhi-singh02 <[email protected]>
Co-authored-by: itsdevbear <[email protected]>
  • Loading branch information
nidhi-singh02 and itsdevbear authored Jun 12, 2024
1 parent b752e7e commit cf3dcd4
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
2 changes: 1 addition & 1 deletion contracts/lib/solady
30 changes: 30 additions & 0 deletions mod/consensus-types/pkg/types/body_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/berachain/beacon-kit/mod/primitives/pkg/common"
"github.com/berachain/beacon-kit/mod/primitives/pkg/crypto"
"github.com/berachain/beacon-kit/mod/primitives/pkg/eip4844"
"github.com/berachain/beacon-kit/mod/primitives/pkg/version"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -127,9 +128,38 @@ func TestBeaconBlockBodyDeneb_SetDeposits(t *testing.T) {
require.Equal(t, deposits, body.GetDeposits())
}

func TestBeaconBlockBodyDeneb_MarshalSSZ(t *testing.T) {
var byteArray [256]byte
byteSlice := byteArray[:]
body := types.BeaconBlockBodyDeneb{
BeaconBlockBodyBase: types.BeaconBlockBodyBase{
RandaoReveal: [96]byte{1, 2, 3},
Eth1Data: &types.Eth1Data{},
Graffiti: [32]byte{4, 5, 6},
Deposits: []*types.Deposit{},
},
ExecutionPayload: &types.ExecutableDataDeneb{
LogsBloom: byteSlice,
},
BlobKzgCommitments: []eip4844.KZGCommitment{},
}
data, err := body.MarshalSSZ()

require.NoError(t, err)
require.NotNil(t, data)
}
func TestBeaconBlockBodyDeneb_GetTopLevelRoots(t *testing.T) {
body := generateBeaconBlockBodyDeneb()
roots, err := body.GetTopLevelRoots()
require.NoError(t, err)
require.NotNil(t, roots)
}

func TestBeaconBlockBody_Empty(t *testing.T) {
blockBody := types.BeaconBlockBody{}
body := blockBody.Empty(version.Deneb)
require.NotNil(t, body)

_, ok := body.RawBeaconBlockBody.(*types.BeaconBlockBodyDeneb)
require.True(t, ok)
}
42 changes: 42 additions & 0 deletions mod/engine-primitives/pkg/engine-primitives/attributes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
engineprimitives "github.com/berachain/beacon-kit/mod/engine-primitives/pkg/engine-primitives"
"github.com/berachain/beacon-kit/mod/primitives"
"github.com/berachain/beacon-kit/mod/primitives/pkg/common"
"github.com/berachain/beacon-kit/mod/primitives/pkg/version"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -61,3 +62,44 @@ func TestPayloadAttributes(t *testing.T) {

require.NoError(t, payloadAttributes.Validate())
}

func TestNewPayloadAttributes_ErrorCases(t *testing.T) {
forkVersion := uint32(1)
prevRandao := primitives.Bytes32{1, 2, 3}
suggestedFeeRecipient := common.ExecutionAddress{}
withdrawals := []Withdrawal{}
parentBeaconBlockRoot := primitives.Root{}

// Test case where Timestamp is 0
_, err := engineprimitives.NewPayloadAttributes[Withdrawal](
forkVersion,
0,
prevRandao,
suggestedFeeRecipient,
withdrawals,
parentBeaconBlockRoot,
)
require.ErrorIs(t, err, engineprimitives.ErrInvalidTimestamp)

// Test case where PrevRandao is an empty array
_, err = engineprimitives.NewPayloadAttributes[Withdrawal](
forkVersion,
123456789,
primitives.Bytes32{},
suggestedFeeRecipient,
withdrawals,
parentBeaconBlockRoot,
)
require.ErrorIs(t, err, engineprimitives.ErrEmptyPrevRandao)

// Test case where Withdrawals is nil and version is equal to Capella
_, err = engineprimitives.NewPayloadAttributes[Withdrawal](
version.Capella,
123456789,
prevRandao,
suggestedFeeRecipient,
nil,
parentBeaconBlockRoot,
)
require.ErrorIs(t, err, engineprimitives.ErrNilWithdrawals)
}

0 comments on commit cf3dcd4

Please sign in to comment.