From e71cc04c70c06b25a12a7087c9b66494c74adbb5 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 20 May 2020 15:02:01 +0300 Subject: [PATCH] vm/tests: unmarshal VM state in JSON tests properly --- pkg/vm/json_test.go | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/pkg/vm/json_test.go b/pkg/vm/json_test.go index 9f00992a5..7771ce556 100644 --- a/pkg/vm/json_test.go +++ b/pkg/vm/json_test.go @@ -44,7 +44,7 @@ type ( } vmUTExecutionEngineState struct { - State vmUTState `json:"state"` + State State `json:"state"` ResultStack []vmUTStackItem `json:"resultStack"` InvocationStack []vmUTExecutionContextState `json:"invocationStack"` } @@ -61,8 +61,6 @@ type ( Result vmUTExecutionEngineState `json:"result"` } - vmUTState State - vmUTStackItemType string ) @@ -138,8 +136,8 @@ func testFile(t *testing.T, filename string) { for i := range test.Steps { execStep(t, vm, test.Steps[i]) result := test.Steps[i].Result - require.Equal(t, State(result.State), vm.state) - if result.State == vmUTState(faultState) { // do not compare stacks on fault + require.Equal(t, result.State, vm.state) + if result.State == faultState { // do not compare stacks on fault continue } @@ -280,20 +278,6 @@ func execStep(t *testing.T, v *VM, step vmUTStep) { } } -func (v *vmUTState) UnmarshalJSON(data []byte) error { - switch s := string(data); s { - case `"Break"`: - *v = vmUTState(breakState) - case `"Fault"`: - *v = vmUTState(faultState) - case `"Halt"`: - *v = vmUTState(haltState) - default: - panic(fmt.Sprintf("invalid state: %s", s)) - } - return nil -} - func (v *vmUTScript) UnmarshalJSON(data []byte) error { var ops []string if err := json.Unmarshal(data, &ops); err != nil {