mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-25 13:47:19 +00:00
4945145b09
Do not use the updated contract state from native Management to perform permissions checks. We need to use the currently executing state instead got from the currently executing VM context until context is unloaded. Close #3471. Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
61 lines
1.8 KiB
Go
61 lines
1.8 KiB
Go
package vm
|
|
|
|
import (
|
|
"math/big"
|
|
"testing"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
"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())
|
|
})
|
|
}
|
|
|
|
func TestContext_BreakPoints(t *testing.T) {
|
|
prog := makeProgram(opcode.CALL, 3, opcode.RET,
|
|
opcode.PUSH2, opcode.PUSH3, opcode.ADD, opcode.RET)
|
|
v := load(prog)
|
|
v.AddBreakPoint(3)
|
|
v.AddBreakPoint(5)
|
|
require.Equal(t, []int{3, 5}, v.Context().BreakPoints())
|
|
|
|
// Preserve the set of breakpoints on Call.
|
|
v.Call(3)
|
|
require.Equal(t, []int{3, 5}, v.Context().BreakPoints())
|
|
|
|
// New context -> clean breakpoints.
|
|
v.loadScriptWithCallingHash(prog, nil, nil, util.Uint160{}, util.Uint160{}, callflag.All, 1, 3, nil)
|
|
require.Equal(t, []int{}, v.Context().BreakPoints())
|
|
}
|