vm/tests: unmarshal Map keys properly in JSON tests
This commit is contained in:
parent
128a99dec2
commit
646c247b31
1 changed files with 13 additions and 3 deletions
|
@ -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)))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue