mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-05-06 19:55:10 +00:00
vm: fix debugger and add tests
1. `Run()` must be able to continue execution after a breakpoint. 2. VM must stop right before the breakpoint, not after. 3. Initial vm state is NONE, not HALT.
This commit is contained in:
parent
8659fd79e5
commit
a080d24cf5
3 changed files with 52 additions and 11 deletions
42
pkg/vm/debug_test.go
Normal file
42
pkg/vm/debug_test.go
Normal file
|
@ -0,0 +1,42 @@
|
|||
package vm
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestVM_Debug(t *testing.T) {
|
||||
prog := makeProgram(opcode.CALL, 3, opcode.RET,
|
||||
opcode.PUSH2, opcode.PUSH3, opcode.ADD, opcode.RET)
|
||||
t.Run("BreakPoint", func(t *testing.T) {
|
||||
v := load(prog)
|
||||
v.AddBreakPoint(3)
|
||||
v.AddBreakPoint(5)
|
||||
require.NoError(t, v.Run())
|
||||
require.Equal(t, 3, v.Context().NextIP())
|
||||
require.NoError(t, v.Run())
|
||||
require.Equal(t, 5, v.Context().NextIP())
|
||||
require.NoError(t, v.Run())
|
||||
require.Equal(t, 1, v.estack.len)
|
||||
require.Equal(t, big.NewInt(5), v.estack.Top().Value())
|
||||
})
|
||||
t.Run("StepInto", func(t *testing.T) {
|
||||
v := load(prog)
|
||||
require.NoError(t, v.StepInto())
|
||||
require.Equal(t, 3, v.Context().NextIP())
|
||||
require.NoError(t, v.StepOut())
|
||||
require.Equal(t, 2, v.Context().NextIP())
|
||||
require.Equal(t, 1, v.estack.len)
|
||||
require.Equal(t, big.NewInt(5), v.estack.Top().Value())
|
||||
})
|
||||
t.Run("StepOver", func(t *testing.T) {
|
||||
v := load(prog)
|
||||
require.NoError(t, v.StepOver())
|
||||
require.Equal(t, 2, v.Context().NextIP())
|
||||
require.Equal(t, 1, v.estack.len)
|
||||
require.Equal(t, big.NewInt(5), v.estack.Top().Value())
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue