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) items := v.Value.(map[string]vmUTStackItem)
result := NewMapItem() result := NewMapItem()
for k, v := range items { for k, v := range items {
var item vmUTStackItem item := jsonStringToInteger(k)
_ = json.Unmarshal([]byte(`"`+k+`"`), &item) if item == nil {
result.Add(item.toStackItem(), v.toStackItem()) panic(fmt.Sprintf("can't unmarshal StackItem %s", k))
}
result.Add(item, v.toStackItem())
} }
return result return result
case typeInterop: 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 { func (v vmUTStackItemType) toLower() vmUTStackItemType {
return vmUTStackItemType(strings.ToLower(string(v))) return vmUTStackItemType(strings.ToLower(string(v)))
} }