Skip to content

Commit

Permalink
sharding/client: Fixing Tests (#92)
Browse files Browse the repository at this point in the history
Former-commit-id: 85e659f3ea43c983f8df54ab8a3150a560b2dbf8 [formerly 2c0a181]
Former-commit-id: 0198766
  • Loading branch information
nisdas committed May 16, 2018
1 parent 1df5683 commit 4e5c535
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
6 changes: 3 additions & 3 deletions sharding/client/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func Serialize(rawtx []interface{}) ([]byte, error) {
}

// Deserializebody results in the Collation body being deserialised and separated into its respective interfaces.
func Deserializebody(collationbody []byte, rawtx []interface{}) error {
func Deserializebody(collationbody []byte, rawtx interface{}) error {

length := int64(len(collationbody))
chunksNumber := length / chunkSize
Expand All @@ -155,7 +155,7 @@ func Deserializebody(collationbody []byte, rawtx []interface{}) error {
deserializedblob := []byte{}

// This separates the collation body into its respective transaction blobs
for i := int64(1); i <= chunksNumber+1; i++ {
for i := int64(1); i <= chunksNumber; i++ {
indicatorIndex := (i - 1) * chunkSize
// Tests if the chunk delimiter is zero, if it is it will append the data chunk
// to tempbody
Expand All @@ -166,7 +166,7 @@ func Deserializebody(collationbody []byte, rawtx []interface{}) error {
// add it and append to the rawtx slice. The tempbody signifies a deserialized blob
} else {
terminalIndex := int64(collationbody[indicatorIndex])
tempbody = append(tempbody, collationbody[(indicatorIndex+1):(indicatorIndex+2+terminalIndex)]...)
tempbody = append(tempbody, collationbody[(indicatorIndex+1):(indicatorIndex+1+terminalIndex)]...)
deserializedblob = append(deserializedblob, tempbody...)
tempbody = []byte{}

Expand Down
19 changes: 10 additions & 9 deletions sharding/client/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ package client
import (
"math/rand"
"reflect"
"runtime"
//"runtime"
"testing"
)

var testbody []interface{}
var testbody interface{}

func buildblob() []byte {
func buildblob(size int64) []byte {

tempbody := make([]byte, 500)
for i := int64(0); i < 500; i++ {
tempbody := make([]byte, size)
for i := int64(0); i < size; i++ {
tempbody[i] = byte(rand.Int())

}
Expand All @@ -32,22 +32,23 @@ func TestConvertInterface(t *testing.T) {

func TestSerializeblob(t *testing.T) {

blob := buildblob()
blob := buildblob(20)

serializedblob, err := serializeBlob(blob)

if err != nil {
t.Fatalf("Error Serializing blob:%v %v", err, serializedblob)
}
runtime.Breakpoint()
err2 := Deserializebody(serializedblob, testbody)
test := &testbody
//runtime.Breakpoint()
err2 := Deserializebody(serializedblob, &testbody)
if err2 != nil {
t.Fatalf("Error Serializing blob:%v", err2)
}

if !reflect.DeepEqual(blob, testbody) {

t.Fatalf("Error Serializing blob with %v %v", blob, testbody)
t.Fatalf("Error Serializing blob with %v %v %v", blob, test, &testbody)
}

}

0 comments on commit 4e5c535

Please sign in to comment.