mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-03 08:37:37 +00:00
sharding/utils: Fixed serialization tests(#92)
Former-commit-id: 7bc42f4bf78f03ddecd07d309699e5771bf2e501 [formerly 9367511015a33dd13d1c605c7d4da94617a0138d] Former-commit-id: 0dd05673b86cee96f5b5d436b58584d9c78c3e0b
This commit is contained in:
parent
0cf0c8b8d8
commit
e46714c9a8
@ -58,7 +58,6 @@ func serializeBlob(cb interface{}) ([]byte, error) {
|
||||
length := int64(len(blob))
|
||||
terminalLength := length % chunkDataSize
|
||||
chunksNumber := length / chunkDataSize
|
||||
finalchunkIndex := length - 1
|
||||
indicatorByte := make([]byte, 1)
|
||||
indicatorByte[0] = 0
|
||||
tempbody := []byte{}
|
||||
@ -114,7 +113,7 @@ func serializeBlob(cb interface{}) ([]byte, error) {
|
||||
indicatorByte[0] = byte(terminalLength)
|
||||
tempbody = append(tempbody,
|
||||
append(indicatorByte,
|
||||
blob[chunkDataSize*chunksNumber-1:finalchunkIndex]...)...)
|
||||
blob[chunkDataSize*chunksNumber:length]...)...)
|
||||
|
||||
emptyBytes := make([]byte, (chunkDataSize - terminalLength))
|
||||
tempbody = append(tempbody, emptyBytes...)
|
||||
@ -172,6 +171,12 @@ func Deserialize(collationbody []byte, rawtx interface{}) error {
|
||||
|
||||
// Since the chunk delimiter in non-zero now we can infer that it is a terminal chunk and
|
||||
// add it and append to the rawtx slice. The tempbody signifies a deserialized blob
|
||||
} else if collationbody[indicatorIndex] == byte(1) {
|
||||
|
||||
tempbody = append(tempbody, collationbody[(indicatorIndex+1)])
|
||||
deserializedblob = append(deserializedblob, convertbyteToInterface(tempbody))
|
||||
tempbody = []byte{}
|
||||
|
||||
} else {
|
||||
terminalIndex := int64(collationbody[indicatorIndex])
|
||||
tempbody = append(tempbody, collationbody[(indicatorIndex+1):(indicatorIndex+1+terminalIndex)]...)
|
||||
|
@ -3,6 +3,7 @@ package utils
|
||||
import (
|
||||
"math/rand"
|
||||
"reflect"
|
||||
//"runtime"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@ -61,7 +62,7 @@ func TestSerializeAndDeserializeblob(t *testing.T) {
|
||||
|
||||
var testbody interface{}
|
||||
|
||||
blob := buildtxblobs(31)
|
||||
blob := buildtxblobs(1000)
|
||||
|
||||
serializedblob, err := Serialize(blob)
|
||||
|
||||
@ -75,7 +76,7 @@ func TestSerializeAndDeserializeblob(t *testing.T) {
|
||||
|
||||
if !reflect.DeepEqual(blob, testbody) {
|
||||
|
||||
t.Fatalf("Error Serializing blobs, the serialized and deserialized versions are not the same: %v ------ %v", blob, testbody)
|
||||
t.Fatalf("Error Serializing blobs, the serialized and deserialized versions are not the same: %v ------%v ------ %v", blob, serializedblob, testbody)
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user