From 2848bcd35b00ae38932a376b3ac12694038849f5 Mon Sep 17 00:00:00 2001 From: lucas Date: Tue, 8 Oct 2019 22:30:21 +0800 Subject: [PATCH] fix convertToHex bug (#1088) * fix convertToHex bug * fix some bug * fmt code * fix word error * fix some bug --- vm/neovm/types/neovm_value.go | 18 +++++++++++++----- vm/neovm/types/neovm_value_test.go | 1 + 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/vm/neovm/types/neovm_value.go b/vm/neovm/types/neovm_value.go index 151280a9ab..6947bfc934 100644 --- a/vm/neovm/types/neovm_value.go +++ b/vm/neovm/types/neovm_value.go @@ -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" @@ -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!") } } @@ -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") @@ -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 { @@ -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") @@ -719,6 +724,9 @@ 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 { @@ -726,7 +734,7 @@ func (self *VmValue) stringify() string { } return fmt.Sprintf("struct[%d]{%s}", len(self.structval.Data), data) default: - panic("unreacheable!") + panic("unreachable!") } return "" } @@ -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 "" } diff --git a/vm/neovm/types/neovm_value_test.go b/vm/neovm/types/neovm_value_test.go index 12ed7f6c76..0e93ee94d7 100644 --- a/vm/neovm/types/neovm_value_test.go +++ b/vm/neovm/types/neovm_value_test.go @@ -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) {