Skip to content

Commit

Permalink
fix convertToHex bug (#1088)
Browse files Browse the repository at this point in the history
* fix convertToHex bug

* fix some bug

* fmt code

* fix word error

* fix some bug
  • Loading branch information
lucas7788 authored and laizy committed Oct 8, 2019
1 parent dc367de commit 2848bcd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
18 changes: 13 additions & 5 deletions vm/neovm/types/neovm_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"sort"

"github.com/ontio/ontology/common"
"github.com/ontio/ontology/common/log"
"github.com/ontio/ontology/vm/crossvm_codec"
"github.com/ontio/ontology/vm/neovm/constants"
"github.com/ontio/ontology/vm/neovm/errors"
Expand Down Expand Up @@ -146,7 +147,7 @@ func (self *VmValue) AsBytes() ([]byte, error) {
case arrayType, mapType, structType, interopType:
return nil, errors.ERR_BAD_TYPE
default:
panic("unreacheable!")
panic("unreachable!")
}
}

Expand Down Expand Up @@ -214,6 +215,7 @@ func (self *VmValue) ConvertNeoVmValueHexString() (interface{}, error) {
}
return res, nil
}

func (self *VmValue) convertNeoVmValueHexString(count *int, length *int) (interface{}, error) {
if *count > MAX_COUNT {
return nil, fmt.Errorf("over max parameters convert length")
Expand Down Expand Up @@ -271,7 +273,8 @@ func (self *VmValue) convertNeoVmValueHexString(count *int, length *int) (interf
*length += len(bs)
return common.ToHexString(bs), nil
default:
panic("unreacheable!")
log.Errorf("[ConvertTypes] Invalid Types!, %x", self.valType)
return nil, fmt.Errorf("[ConvertTypes] Invalid Types!, %x", self.valType)
}
}
func (self *VmValue) Deserialize(source *common.ZeroCopySource) error {
Expand Down Expand Up @@ -458,8 +461,10 @@ func (self *VmValue) Serialize(sink *common.ZeroCopySink) error {
return err
}
}
case interopType:
return fmt.Errorf("not support type: interopType")
default:
panic("unreacheable!")
panic("unreachable!")
}
if sink.Size() > constants.MAX_BYTEARRAY_SIZE {
return fmt.Errorf("runtime serialize: can not serialize length over the uplimit")
Expand Down Expand Up @@ -719,14 +724,17 @@ func (self *VmValue) stringify() string {
data += fmt.Sprintf("%x: %s,", key, v.stringify())
}
return fmt.Sprintf("map[%d]{%s}", len(self.mapval.Data), data)
case interopType:
ty := reflect.TypeOf(self.interop.Data).String()
return fmt.Sprintf("interop{type:%s}", ty)
case structType:
data := ""
for _, v := range self.structval.Data {
data += v.stringify() + ", "
}
return fmt.Sprintf("struct[%d]{%s}", len(self.structval.Data), data)
default:
panic("unreacheable!")
panic("unreachable!")
}
return ""
}
Expand Down Expand Up @@ -782,7 +790,7 @@ func (self *VmValue) dump() string {
case interopType:
return fmt.Sprintf("interop[%x]", self.interop.Data)
default:
panic("unreacheable!")
panic("unreachable!")
}
return ""
}
Expand Down
1 change: 1 addition & 0 deletions vm/neovm/types/neovm_value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ func TestSerialize(t *testing.T) {
assert.Nil(t, err)
fmt.Println("res_t:", res_t)
assert.Equal(t, "ffffc58e4ae6b68900", res_t.([]interface{})[0])

}

func TestVmValue_ConvertNeoVmValueHexString(t *testing.T) {
Expand Down

0 comments on commit 2848bcd

Please sign in to comment.