Merge pull request #808 from nspcc-dev/fix-map-serialization
vm: make map serialization more compatible with C#
This commit is contained in:
commit
0d482ceb7f
2 changed files with 16 additions and 2 deletions
|
@ -74,8 +74,8 @@ func serializeItemTo(item StackItem, w *io.BinWriter, seen map[StackItem]bool) {
|
|||
w.WriteBytes([]byte{byte(mapT)})
|
||||
w.WriteVarUint(uint64(len(t.value)))
|
||||
for k, v := range t.value {
|
||||
serializeItemTo(v, w, seen)
|
||||
serializeItemTo(makeStackItem(k), w, seen)
|
||||
serializeItemTo(v, w, seen)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -128,8 +128,8 @@ func DecodeBinaryStackItem(r *io.BinReader) StackItem {
|
|||
size := int(r.ReadVarUint())
|
||||
m := NewMapItem()
|
||||
for i := 0; i < size; i++ {
|
||||
value := DecodeBinaryStackItem(r)
|
||||
key := DecodeBinaryStackItem(r)
|
||||
value := DecodeBinaryStackItem(r)
|
||||
if r.Err != nil {
|
||||
break
|
||||
}
|
||||
|
|
|
@ -678,6 +678,20 @@ func TestSerializeMap(t *testing.T) {
|
|||
require.Equal(t, item.value, vm.estack.Top().value.(*MapItem).value)
|
||||
}
|
||||
|
||||
func TestSerializeMapCompat(t *testing.T) {
|
||||
// Create a map, push key and value, add KV to map, serialize.
|
||||
progHex := "c776036b65790576616c7565c468154e656f2e52756e74696d652e53657269616c697a65"
|
||||
resHex := "820100036b6579000576616c7565"
|
||||
prog, err := hex.DecodeString(progHex)
|
||||
require.NoError(t, err)
|
||||
res, err := hex.DecodeString(resHex)
|
||||
require.NoError(t, err)
|
||||
|
||||
vm := load(prog)
|
||||
runVM(t, vm)
|
||||
assert.Equal(t, res, vm.estack.Pop().Bytes())
|
||||
}
|
||||
|
||||
func TestSerializeInterop(t *testing.T) {
|
||||
vm := load(getSerializeProg())
|
||||
item := NewInteropItem("kek")
|
||||
|
|
Loading…
Reference in a new issue