Native beacon state: v1 (#10086)

This commit is contained in:
Radosław Kapka
2022-01-24 11:24:38 +01:00
committed by GitHub
parent b4fa626aff
commit 5cc201288d
47 changed files with 1662 additions and 1049 deletions

View File

@@ -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 {

View File

@@ -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)
}