From 412582dc7881a5568e2e286ca2710518ce6b4cee Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 5 Nov 2019 17:04:14 +0300 Subject: [PATCH] vm: add more serialization tests --- pkg/vm/vm_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/pkg/vm/vm_test.go b/pkg/vm/vm_test.go index 0af1144a0..599b930f6 100644 --- a/pkg/vm/vm_test.go +++ b/pkg/vm/vm_test.go @@ -300,6 +300,19 @@ func TestSerializeStruct(t *testing.T) { require.Equal(t, item.value, vm.estack.Top().Array()) } +func TestDeserializeUnknown(t *testing.T) { + prog := append(getSyscallProg("Neo.Runtime.Deserialize"), byte(RET)) + vm := load(prog) + + data, err := serializeItem(NewBigIntegerItem(123)) + require.NoError(t, err) + + data[0] = 0xFF + vm.estack.PushVal(data) + + checkVMFailed(t, vm) +} + func TestSerializeMap(t *testing.T) { vm := load(getSerializeProg()) item := NewMapItem() @@ -314,6 +327,17 @@ func TestSerializeMap(t *testing.T) { require.Equal(t, item.value, vm.estack.Top().value.(*MapItem).value) } +func TestSerializeInterop(t *testing.T) { + vm := load(getSerializeProg()) + item := NewInteropItem("kek") + + vm.estack.Push(&Element{value: item}) + + err := vm.Step() + require.Error(t, err) + require.True(t, vm.HasFailed()) +} + func callNTimes(n uint16) []byte { return makeProgram( PUSHBYTES2, Instruction(n), Instruction(n>>8), // little-endian