Skip to content

Commit

Permalink
sharding/utils: Got Tests working again (ethereum#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
nisdas committed May 16, 2018
1 parent c1b5d04 commit 4470434
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
11 changes: 7 additions & 4 deletions sharding/utils/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ func serializeBlob(cb RawBlob) ([]byte, error) {
if chunksNumber == 0 {
paddedbytes := make([]byte, (chunkDataSize - length))
indicatorByte[0] = byte(terminalLength)
if cb.flags.skipEvmExecution {
indicatorByte[0] |= (1 << 7)
}
tempbody = append(indicatorByte, append(cb.data, paddedbytes...)...)
return tempbody, nil
}
Expand Down Expand Up @@ -170,13 +173,13 @@ func Deserialize(collationbody []byte) ([]RawBlob, error) {
length := int64(len(collationbody))
chunksNumber := length / chunkSize
indicatorByte := byte(0)
var tempbody RawBlob
tempbody := RawBlob{}
var deserializedblob []RawBlob

// This separates the byte array into its separate blobs
for i := int64(1); i <= chunksNumber; i++ {
indicatorIndex := (i - 1) * chunkSize
var terminalIndex int64

// Tests if the chunk delimiter is zero, if it is it will append the data chunk
// to tempbody
if collationbody[indicatorIndex] == indicatorByte || collationbody[indicatorIndex] == byte(128) {
Expand All @@ -193,12 +196,12 @@ func Deserialize(collationbody []byte) ([]RawBlob, error) {
} else {
// Since the chunk delimiter in non-zero now we can infer that it is a terminal chunk and
// add it and append to the deserializedblob slice. The tempbody signifies a single deserialized blob
terminalIndex := int64(collationbody[indicatorIndex])
//Check if EVM flag is equal to 1
flagindex := collationbody[indicatorIndex] >> 7
if flagindex == byte(1) {
terminalIndex = int64(collationbody[indicatorIndex]) - 128
tempbody.flags.skipEvmExecution = true
} else {
terminalIndex = int64(collationbody[indicatorIndex])
}
tempbody.data = append(tempbody.data, collationbody[(indicatorIndex+1):(indicatorIndex+1+terminalIndex)]...)
deserializedblob = append(deserializedblob, tempbody)
Expand Down
10 changes: 4 additions & 6 deletions sharding/utils/marshal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestConvertInterface(t *testing.T) {
} */
func TestSize(t *testing.T) {
size := int64(800)
size := int64(8)
blob := buildrawblob(size)
chunksafterSerialize := size / chunkDataSize
terminalchunk := size % chunkDataSize
Expand All @@ -71,9 +71,7 @@ func TestSize(t *testing.T) {
}
func TestSerializeAndDeserializeblob(t *testing.T) {

var testbody interface{}

blob := buildrawblob(10)
blob := buildrawblob(330)

serializedblob, err := Serialize(blob)

Expand All @@ -85,9 +83,9 @@ func TestSerializeAndDeserializeblob(t *testing.T) {
t.Fatalf("Error Serializing blob:%v due to %v", raw, err2)
}

if !reflect.DeepEqual(blob, testbody) {
if !reflect.DeepEqual(blob, raw) {

t.Fatalf("Error Serializing blobs, the serialized and deserialized versions are not the same: %v ------%v ------ %v", blob, serializedblob, testbody)
t.Fatalf("Error Serializing blobs, the serialized and deserialized versions are not the same:\n\n %v \n\n %v \n\n %v", blob, serializedblob, raw)
}

}

0 comments on commit 4470434

Please sign in to comment.