Builder API: Fix max field check on toProto function (#13334)

* fixing field param used in ToProto function

* fxing test to pass

* making blobs empty in test
This commit is contained in:
james-prysm 2023-12-13 21:03:00 -06:00 committed by GitHub
parent 09f3df309d
commit 45a2746d0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 20 deletions

View File

@ -1021,8 +1021,8 @@ type BlobsBundle struct {
// ToProto returns a BlobsBundle Proto.
func (b BlobsBundle) ToProto() (*v1.BlobsBundle, error) {
if len(b.Blobs) > fieldparams.MaxBlobsPerBlock {
return nil, fmt.Errorf("blobs length %d is more than max %d", len(b.Blobs), fieldparams.MaxBlobsPerBlock)
if len(b.Blobs) > fieldparams.MaxBlobCommitmentsPerBlock {
return nil, fmt.Errorf("blobs length %d is more than max %d", len(b.Blobs), fieldparams.MaxBlobCommitmentsPerBlock)
}
if len(b.Commitments) != len(b.Blobs) {
return nil, fmt.Errorf("commitments length %d does not equal blobs length %d", len(b.Commitments), len(b.Blobs))

View File

@ -666,25 +666,20 @@ var testExampleExecutionPayloadDenebTooManyBlobs = fmt.Sprintf(`{
"proofs": [
"0xb4021b0de10f743893d4f71e1bf830c019e832958efd6795baf2f83b8699a9eccc5dc99015d8d4d8ec370d0cc333c06a"
],
"blobs": [
"%s",
"%s",
"%s",
"%s",
"%s",
"%s",
"%s"
]
"blobs": %s
}
}
}`, hexutil.Encode(make([]byte, fieldparams.BlobLength)), // 1
hexutil.Encode(make([]byte, fieldparams.BlobLength)), // 2
hexutil.Encode(make([]byte, fieldparams.BlobLength)), // 3
hexutil.Encode(make([]byte, fieldparams.BlobLength)), // 4
hexutil.Encode(make([]byte, fieldparams.BlobLength)), // 5
hexutil.Encode(make([]byte, fieldparams.BlobLength)), // 6
hexutil.Encode(make([]byte, fieldparams.BlobLength)), // 7
)
}`, beyondMaxEmptyBlobs())
func beyondMaxEmptyBlobs() string {
moreThanMax := fieldparams.MaxBlobCommitmentsPerBlock + 2
blobs := make([]string, moreThanMax)
b, err := json.Marshal(blobs)
if err != nil {
panic(err)
}
return string(b)
}
var testExampleExecutionPayloadDenebDifferentCommitmentCount = fmt.Sprintf(`{
"version": "deneb",
@ -1238,7 +1233,7 @@ func TestExecutionPayloadResponseDenebToProtoInvalidBlobCount(t *testing.T) {
hr := &ExecPayloadResponseDeneb{}
require.NoError(t, json.Unmarshal([]byte(testExampleExecutionPayloadDenebTooManyBlobs), hr))
_, _, err := hr.ToProto()
require.ErrorContains(t, "blobs length 7 is more than max 6", err)
require.ErrorContains(t, fmt.Sprintf("blobs length %d is more than max %d", fieldparams.MaxBlobCommitmentsPerBlock+2, fieldparams.MaxBlobCommitmentsPerBlock), err)
}
func TestExecutionPayloadResponseDenebToProtoDifferentCommitmentCount(t *testing.T) {