Add REST implementation for Validator's ProposeBeaconBlock (#11731)

* WIP

* WIP

* WIP

* Add tests

* WIP

* Add more tests

* Address DeepSource errors

* Remove unused param

* Add more tests

* Address PR comments

* Address PR comments

* Fix formatting

* Remove unused parameter

* Fix TestLittleEndianBytesToBigInt

Co-authored-by: Radosław Kapka <rkapka@wp.pl>
This commit is contained in:
Patrice Vignola
2022-12-12 02:39:51 -08:00
committed by GitHub
parent 09619c388f
commit fa01ee5eba
26 changed files with 3176 additions and 38 deletions

View File

@@ -4,6 +4,7 @@ package bytesutil
import (
"encoding/binary"
"fmt"
"math/big"
"math/bits"
"regexp"
@@ -438,3 +439,9 @@ func IsRoot(root []byte) bool {
func IsValidRoot(root []byte) bool {
return IsRoot(root) && !ZeroRoot(root)
}
// LittleEndianBytesToBigInt takes bytes of a number stored as little-endian and returns a big integer
func LittleEndianBytesToBigInt(bytes []byte) *big.Int {
// Integers are stored as little-endian, but big.Int expects big-endian. So we need to reverse the byte order before decoding.
return new(big.Int).SetBytes(ReverseByteOrder(bytes))
}

View File

@@ -2,7 +2,9 @@ package bytesutil_test
import (
"bytes"
"encoding/binary"
"fmt"
"math/big"
"reflect"
"testing"
@@ -634,3 +636,11 @@ func TestToBytes48Array(t *testing.T) {
assert.DeepEqual(t, tt.b, b)
}
}
func TestLittleEndianBytesToBigInt(t *testing.T) {
bytes := make([]byte, 8)
binary.LittleEndian.PutUint64(bytes, 1234567890)
converted := bytesutil.LittleEndianBytesToBigInt(bytes)
expected := new(big.Int).SetInt64(1234567890)
assert.DeepEqual(t, expected, converted)
}