From 22791272bf08ca36cd2efadbf27feb8222749818 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Thu, 21 May 2020 09:38:12 +0300 Subject: [PATCH] vm/tests: compare static slot contents in JSON tests Make use of "staticFields" test field to compare vm static slots. Also remove altStack because it is doesn't exist. --- pkg/vm/json_test.go | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/pkg/vm/json_test.go b/pkg/vm/json_test.go index aed485a9b..4069025cf 100644 --- a/pkg/vm/json_test.go +++ b/pkg/vm/json_test.go @@ -39,8 +39,8 @@ type ( vmUTExecutionContextState struct { Instruction string `json:"nextInstruction"` InstructionPointer int `json:"instructionPointer"` - AStack []vmUTStackItem `json:"altStack"` EStack []vmUTStackItem `json:"evaluationStack"` + StaticFields []vmUTStackItem `json:"staticFields"` } vmUTExecutionEngineState struct { @@ -166,7 +166,7 @@ func testFile(t *testing.T, filename string) { require.Equal(t, op, opcode.Opcode(ctx.prog[ctx.nextip])) } compareStacks(t, s.EStack, vm.estack) - compareStacks(t, s.AStack, vm.astack) + compareSlots(t, s.StaticFields, vm.static) } } @@ -207,20 +207,32 @@ func compareItems(t *testing.T, a, b StackItem) { } func compareStacks(t *testing.T, expected []vmUTStackItem, actual *Stack) { + compareItemArrays(t, expected, actual.Len(), func(i int) StackItem { return actual.Peek(i).Item() }) +} + +func compareSlots(t *testing.T, expected []vmUTStackItem, actual *Slot) { + if actual == nil && len(expected) == 0 { + return + } + require.NotNil(t, actual) + compareItemArrays(t, expected, actual.Size(), actual.Get) +} + +func compareItemArrays(t *testing.T, expected []vmUTStackItem, n int, getItem func(i int) StackItem) { if expected == nil { return } - require.Equal(t, len(expected), actual.Len()) + require.Equal(t, len(expected), n) for i, item := range expected { - e := actual.Peek(i) - require.NotNil(t, e) + it := getItem(i) + require.NotNil(t, it) if item.Type == typeInterop { - require.IsType(t, (*InteropItem)(nil), e.value) + require.IsType(t, (*InteropItem)(nil), it) continue } - compareItems(t, item.toStackItem(), e.value) + compareItems(t, item.toStackItem(), it) } }