Skip to content

Commit

Permalink
sharding/client : Adding Size Test (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
nisdas committed May 16, 2018
1 parent 2c0a181 commit ecebff2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
4 changes: 2 additions & 2 deletions sharding/client/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func Serialize(rawtx []interface{}) ([]byte, error) {
data := rawtx[i]
refinedData, err := serializeBlob(data)
if err != nil {
return nil, fmt.Errorf("Error: %v", err)
return nil, fmt.Errorf("Error: %v at index: %v %v %v", err, i, data, rawtx)
}
serialisedData = append(serialisedData, refinedData...)

Expand Down Expand Up @@ -174,7 +174,7 @@ func Deserializebody(collationbody []byte, rawtx interface{}) error {

}

rawtx = convertbyteToInterface(deserializedblob)
*rawtx.(*interface{}) = convertbyteToInterface(deserializedblob)

return nil

Expand Down
39 changes: 34 additions & 5 deletions sharding/client/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,18 @@ import (

var testbody interface{}

func buildblob(size int64) []byte {
func buildtxblobs(size int64) []interface{} {
tempbody := make([]interface{}, size)
for i := int64(0); i < size; i++ {
tempbody[i] = buildblob(size)

}
return tempbody
}

func buildblob(size int64) []interface{} {

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

Expand All @@ -29,17 +38,37 @@ func TestConvertInterface(t *testing.T) {
}

}
func TestSize(t *testing.T) {
size := int64(20)
blob := buildtxblobs(size)
chunksafterSerialize := size / chunkDataSize
terminalchunk := size % chunkDataSize
if terminalchunk != 0 {
chunksafterSerialize = chunksafterSerialize + 1
}
sizeafterSerialize := chunksafterSerialize * chunkSize
serializedblob, err := Serialize(blob)
if err != nil {
t.Fatalf("Error Serializing blob:%v %v", err, serializedblob)
}

if int64(len(serializedblob)) != sizeafterSerialize {

t.Fatalf("Error Serializing blob,Lengths are not the same: %v , %v", int64(len(serializedblob)), sizeafterSerialize)

}

}
func TestSerializeblob(t *testing.T) {

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

serializedblob, err := serializeBlob(blob)

if err != nil {
t.Fatalf("Error Serializing blob:%v %v", err, serializedblob)
}
test := &testbody
//test := &testbody
//runtime.Breakpoint()
err2 := Deserializebody(serializedblob, &testbody)
if err2 != nil {
Expand All @@ -48,7 +77,7 @@ func TestSerializeblob(t *testing.T) {

if !reflect.DeepEqual(blob, testbody) {

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

}

0 comments on commit ecebff2

Please sign in to comment.