mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-26 09:42:22 +00:00
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)
|
||||
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)))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue