mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-08 23:18:15 -05:00
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:
@@ -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))
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user