vm/tests: unmarshal Map keys properly in JSON tests

This commit is contained in:
Evgenii Stratonikov 2020-05-20 17:34:32 +03:00
parent 128a99dec2
commit 646c247b31

View file

@ -229,9 +229,11 @@ func (v *vmUTStackItem) toStackItem() StackItem {
items := v.Value.(map[string]vmUTStackItem)
result := NewMapItem()
for k, v := range items {
var item vmUTStackItem
_ = json.Unmarshal([]byte(`"`+k+`"`), &item)
result.Add(item.toStackItem(), v.toStackItem())
item := jsonStringToInteger(k)
if item == nil {
panic(fmt.Sprintf("can't unmarshal StackItem %s", k))
}
result.Add(item, v.toStackItem())
}
return result
case typeInterop:
@ -291,6 +293,14 @@ func execStep(t *testing.T, v *VM, step vmUTStep) {
}
}
func jsonStringToInteger(s string) StackItem {
b, err := decodeHex(s)
if err == nil {
return NewBigIntegerItem(new(big.Int).SetBytes(b))
}
return nil
}
func (v vmUTStackItemType) toLower() vmUTStackItemType {
return vmUTStackItemType(strings.ToLower(string(v)))
}