Skip to content

Commit

Permalink
sharding/utils: Fixed serialization tests(#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
nisdas committed May 16, 2018
1 parent 108d9e2 commit 9367511
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
9 changes: 7 additions & 2 deletions sharding/utils/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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...)
Expand Down Expand Up @@ -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)]...)
Expand Down
5 changes: 3 additions & 2 deletions sharding/utils/marshal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package utils
import (
"math/rand"
"reflect"
//"runtime"
"testing"
)

Expand Down Expand Up @@ -61,7 +62,7 @@ func TestSerializeAndDeserializeblob(t *testing.T) {

var testbody interface{}

blob := buildtxblobs(31)
blob := buildtxblobs(1000)

serializedblob, err := Serialize(blob)

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

}

0 comments on commit 9367511

Please sign in to comment.