mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-22 03:30:35 +00:00
Implement [][]
to [][48]
helper (#11606)
This commit is contained in:
parent
a0c5669511
commit
ead329e610
@ -117,6 +117,16 @@ func ToBytes48(x []byte) [48]byte {
|
||||
return y
|
||||
}
|
||||
|
||||
// ToBytes48Array is a convenience method for converting an array of
|
||||
// byte slices to an array of fixed-sized byte arrays.
|
||||
func ToBytes48Array(x [][]byte) [][48]byte {
|
||||
y := make([][48]byte, len(x))
|
||||
for i := range x {
|
||||
y[i] = ToBytes48(x[i])
|
||||
}
|
||||
return y
|
||||
}
|
||||
|
||||
// ToBytes64 is a convenience method for converting a byte slice to a fix
|
||||
// sized 64 byte array. This method will truncate the input if it is larger
|
||||
// than 64 bytes.
|
||||
|
@ -606,3 +606,31 @@ func TestUint32ToBytes4(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestToBytes48Array(t *testing.T) {
|
||||
tests := []struct {
|
||||
a [][]byte
|
||||
b [][48]byte
|
||||
}{
|
||||
{[][]byte{{0}}, [][48]byte{{0}}},
|
||||
{[][]byte{{253}}, [][48]byte{{253}}},
|
||||
{[][]byte{{254, 255, 255, 255, 255, 255, 255, 127}},
|
||||
[][48]byte{{254, 255, 255, 255, 255, 255, 255, 127}}},
|
||||
{[][]byte{{255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255}},
|
||||
[][48]byte{{255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255}},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
b := bytesutil.ToBytes48Array(tt.a)
|
||||
assert.DeepEqual(t, tt.b, b)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user