mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-08 23:18:15 -05:00
Native beacon state: v1 (#10086)
This commit is contained in:
@@ -228,6 +228,16 @@ func SafeCopy2dBytes(ary [][]byte) [][]byte {
|
||||
return nil
|
||||
}
|
||||
|
||||
// SafeCopy2d32Bytes will copy and return a non-nil 2d byte array, otherwise it returns nil.
|
||||
func SafeCopy2d32Bytes(ary [][32]byte) [][32]byte {
|
||||
if ary != nil {
|
||||
copied := make([][32]byte, len(ary))
|
||||
copy(copied, ary)
|
||||
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 {
|
||||
|
||||
@@ -507,3 +507,12 @@ func TestReverseByteOrder(t *testing.T) {
|
||||
assert.Equal(t, bytes.Equal(input, []byte{0, 1, 2, 3, 4, 5}), true)
|
||||
assert.Equal(t, bytes.Equal(expectedResult, output), true)
|
||||
}
|
||||
|
||||
func TestSafeCopy2d32Bytes(t *testing.T) {
|
||||
input := make([][32]byte, 2)
|
||||
input[0] = bytesutil.ToBytes32([]byte{'a'})
|
||||
input[1] = bytesutil.ToBytes32([]byte{'b'})
|
||||
output := bytesutil.SafeCopy2d32Bytes(input)
|
||||
assert.Equal(t, false, &input == &output, "No copy was made")
|
||||
assert.DeepEqual(t, input, output)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user