diff --git a/types/FixedArray.go b/types/FixedArray.go index 68194d7..4f2815f 100644 --- a/types/FixedArray.go +++ b/types/FixedArray.go @@ -66,7 +66,7 @@ func (f *FixedArray) Encode(value interface{}) string { case reflect.String: valueStr := value.(string) if strings.HasPrefix(valueStr, "0x") { - return valueStr + return utiles.TrimHex(valueStr) } else { return utiles.BytesToHex([]byte(valueStr)) } diff --git a/types/FixedU8.go b/types/FixedU8.go index 3a4a7ef..bc3808c 100644 --- a/types/FixedU8.go +++ b/types/FixedU8.go @@ -20,8 +20,16 @@ func (s *FixedU8) Process() { } } -func (s *FixedU8) Encode(value string) string { - return utiles.TrimHex(value) +func (s *FixedU8) Encode(value interface{}) string { + switch value.(type) { + case string: + return utiles.TrimHex(value.(string)) + case []byte: + return utiles.TrimHex(utiles.BytesToHex(value.([]byte))) + default: + panic("type error,only support string or []byte") + } + return "" } func (s *FixedU8) TypeStructString() string { diff --git a/types/Uint.go b/types/Uint.go index b619d98..a2189ec 100644 --- a/types/Uint.go +++ b/types/Uint.go @@ -35,6 +35,8 @@ func (u *U8) Encode(value interface{}) string { i = int(v) case float64: i = int(v) + case uint8: + i = int(v) } return utiles.U8Encode(i) } diff --git a/types/types_test.go b/types/types_test.go index 871b7c0..3a2fefc 100644 --- a/types/types_test.go +++ b/types/types_test.go @@ -357,3 +357,10 @@ func TestBitVec(t *testing.T) { assert.EqualValues(t, r[i], m.ProcessAndUpdateData("BitVec")) } } + +func TestFixedArray(t *testing.T) { + ts := []string{"[u8; 16]", "[u8; 16]", "[u8;16]"} + for i, v := range []interface{}{[]byte{2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, []byte{2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, "0x02020202020202020202020202020202"} { + assert.Equal(t, Encode(ts[i], v), "02020202020202020202020202020202", "TestFixedArray Encode fail %s", ts[i]) + } +}