Optimizations + some improvements (#105)
* Optimizations + some improvements - optimized pkg/core/storage.HeaderHashes - optimized pkg/rpc.performRequest (used json.Encoder) - fixes for pkg/util.ReadVarUint and pkg/util.WriteVarUint - optimized and fix fixed8 (Fixed8DecodeString / MarshalJSON) + tests - optimized and fix uint160 (Bytes / Uint160DecodeString / Equal / MarshalJSON) + tests - optimized and fix uint256 (Bytes / Equal / MarshalJSON) + tests - preallocate for pkg/vm.buildStackOutput - add go.mod / go.sum * update version
This commit is contained in:
parent
c8d7671d26
commit
6ccb518ab0
14 changed files with 205 additions and 101 deletions
|
@ -2,6 +2,7 @@ package util
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
@ -39,19 +40,25 @@ func TestFixed8DecodeString(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestFixed8UnmarshalJSON(t *testing.T) {
|
||||
fl := float64(123.45)
|
||||
str := "123.45"
|
||||
expected, _ := Fixed8DecodeString(str)
|
||||
var testCases = []float64{
|
||||
123.45,
|
||||
-123.45,
|
||||
}
|
||||
|
||||
// UnmarshalJSON should decode floats
|
||||
var u1 Fixed8
|
||||
s, _ := json.Marshal(fl)
|
||||
assert.Nil(t, json.Unmarshal(s, &u1))
|
||||
assert.Equal(t, expected, u1)
|
||||
for _, fl := range testCases {
|
||||
str := strconv.FormatFloat(fl, 'g', -1, 64)
|
||||
expected, _ := Fixed8DecodeString(str)
|
||||
|
||||
// UnmarshalJSON should decode strings
|
||||
var u2 Fixed8
|
||||
s, _ = json.Marshal(str)
|
||||
assert.Nil(t, json.Unmarshal(s, &u2))
|
||||
assert.Equal(t, expected, u2)
|
||||
// UnmarshalJSON should decode floats
|
||||
var u1 Fixed8
|
||||
s, _ := json.Marshal(fl)
|
||||
assert.Nil(t, json.Unmarshal(s, &u1))
|
||||
assert.Equal(t, expected, u1)
|
||||
|
||||
// UnmarshalJSON should decode strings
|
||||
var u2 Fixed8
|
||||
s, _ = json.Marshal(str)
|
||||
assert.Nil(t, json.Unmarshal(s, &u2))
|
||||
assert.Equal(t, expected, u2)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue