fix: use hexutil bytes for blobs bundle (#12623)

This commit is contained in:
terencechain
2023-07-17 12:54:18 +02:00
committed by Preston Van Loon
parent a40640c9b9
commit b8fb602fc4
6 changed files with 37 additions and 12 deletions

View File

@@ -16,6 +16,7 @@ go_library(
deps = [
"//config/fieldparams:go_default_library",
"//consensus-types/primitives:go_default_library",
"@com_github_ethereum_go_ethereum//common/hexutil:go_default_library",
"@com_github_pkg_errors//:go_default_library",
],
)
@@ -35,5 +36,6 @@ go_test(
"//config/fieldparams:go_default_library",
"//testing/assert:go_default_library",
"//testing/require:go_default_library",
"@com_github_ethereum_go_ethereum//common/hexutil:go_default_library",
],
)

View File

@@ -3,6 +3,8 @@ package bytesutil
import (
"fmt"
"github.com/ethereum/go-ethereum/common/hexutil"
)
// ToBytes48Array is a convenience method for converting an array of
@@ -104,6 +106,18 @@ func SafeCopy2d32Bytes(ary [][32]byte) [][32]byte {
return nil
}
// SafeCopy2dHexUtilBytes will copy and return a non-nil 2d hex util byte slice, otherwise it returns nil.
func SafeCopy2dHexUtilBytes(ary []hexutil.Bytes) [][]byte {
if ary != nil {
copied := make([][]byte, len(ary))
for i, a := range ary {
copied[i] = SafeCopyBytes(a)
}
return copied
}
return nil
}
// ReverseBytes32Slice will reverse the provided slice's order.
func ReverseBytes32Slice(arr [][32]byte) [][32]byte {
for i, j := 0, len(arr)-1; i < j; i, j = i+1, j-1 {

View File

@@ -6,6 +6,7 @@ import (
"reflect"
"testing"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/prysmaticlabs/prysm/v4/encoding/bytesutil"
"github.com/prysmaticlabs/prysm/v4/testing/assert"
)
@@ -162,6 +163,14 @@ func TestSafeCopy2d32Bytes(t *testing.T) {
assert.DeepEqual(t, input, output)
}
func TestSafeCopy2dHexUtilBytes(t *testing.T) {
input := make([]hexutil.Bytes, 2)
input[0] = hexutil.Bytes{'a'}
input[1] = hexutil.Bytes{'b'}
output := bytesutil.SafeCopy2dHexUtilBytes(input)
assert.DeepEqual(t, output, [][]byte{{'a'}, {'b'}})
}
func TestToBytes48Array(t *testing.T) {
tests := []struct {
a [][]byte