From 4e5c5354265eaeb48ccc15d084718f7e1ee22650 Mon Sep 17 00:00:00 2001 From: nisdas Date: Fri, 4 May 2018 19:03:17 +0800 Subject: [PATCH] sharding/client: Fixing Tests (#92) Former-commit-id: 85e659f3ea43c983f8df54ab8a3150a560b2dbf8 [formerly 2c0a181754a07dbda855d1da8042a09c9e9a040d] Former-commit-id: 0198766ea1336efff88b9292b6ee1b53ef86b000 --- sharding/client/utils.go | 6 +++--- sharding/client/utils_test.go | 19 ++++++++++--------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/sharding/client/utils.go b/sharding/client/utils.go index 5c113fe16..a5909a98c 100644 --- a/sharding/client/utils.go +++ b/sharding/client/utils.go @@ -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 @@ -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 @@ -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{} diff --git a/sharding/client/utils_test.go b/sharding/client/utils_test.go index eee961510..2617dc50a 100644 --- a/sharding/client/utils_test.go +++ b/sharding/client/utils_test.go @@ -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()) } @@ -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) } }