diff --git a/tests/neo-vm.Tests/Tests/Others/Debugger.json b/tests/neo-vm.Tests/Tests/Others/Debugger.json new file mode 100644 index 00000000..1979c22e --- /dev/null +++ b/tests/neo-vm.Tests/Tests/Others/Debugger.json @@ -0,0 +1,454 @@ +{ + "category": "Others", + "name": "Debugger", + "tests": + [ + { + "name": "Step Into", + "script": "0x5165050053665266", + "steps": + [ + { + "result": + { + "state": "Break", + "invocationStack": + [ + { + "scriptHash": "0x408E0A012B7053EE2045D637FBB54534E8AD4C9A", + "instructionPointer": 0, + "nextInstruction": "PUSH1" + } + ] + } + }, + { + "actions": + [ + "StepInto" + ], + "result": + { + "state": "Break", + "invocationStack": + [ + { + "scriptHash": "0x408E0A012B7053EE2045D637FBB54534E8AD4C9A", + "instructionPointer": 1, + "nextInstruction": "CALL", + "evaluationStack": + [ + { + "type": "Integer", + "value": 1 + } + ] + } + ] + } + }, + { + "actions": + [ + "StepInto" + ], + "result": + { + "state": "Break", + "invocationStack": + [ + { + "scriptHash": "0x408E0A012B7053EE2045D637FBB54534E8AD4C9A", + "instructionPointer": 6, + "nextInstruction": "PUSH2", + "evaluationStack": + [ + { + "type": "Integer", + "value": 1 + } + ] + }, + { + "scriptHash": "0x408E0A012B7053EE2045D637FBB54534E8AD4C9A", + "instructionPointer": 4, + "nextInstruction": "PUSH3" + } + ] + } + }, + { + "actions": + [ + "StepInto" + ], + "result": + { + "state": "Break", + "invocationStack": + [ + { + "scriptHash": "0x408E0A012B7053EE2045D637FBB54534E8AD4C9A", + "instructionPointer": 7, + "nextInstruction": "RET", + "evaluationStack": + [ + { + "type": "Integer", + "value": 2 + }, + { + "type": "Integer", + "value": 1 + } + ] + }, + { + "scriptHash": "0x408E0A012B7053EE2045D637FBB54534E8AD4C9A", + "instructionPointer": 4, + "nextInstruction": "PUSH3" + } + ] + } + }, + { + "actions": + [ + "StepInto" + ], + "result": + { + "state": "Break", + "invocationStack": + [ + { + "scriptHash": "0x408E0A012B7053EE2045D637FBB54534E8AD4C9A", + "instructionPointer": 4, + "nextInstruction": "PUSH3", + "evaluationStack": + [ + { + "type": "Integer", + "value": 2 + }, + { + "type": "Integer", + "value": 1 + } + ] + } + ] + } + }, + { + "actions": + [ + "StepInto" + ], + "result": + { + "state": "Break", + "invocationStack": + [ + { + "scriptHash": "0x408E0A012B7053EE2045D637FBB54534E8AD4C9A", + "instructionPointer": 5, + "nextInstruction": "RET", + "evaluationStack": + [ + { + "type": "Integer", + "value": 3 + }, + { + "type": "Integer", + "value": 2 + }, + { + "type": "Integer", + "value": 1 + } + ] + } + ] + } + }, + { + "actions": + [ + "StepInto" + ], + "result": + { + "state": "Halt", + "resultStack": + [ + { + "type": "Integer", + "value": 3 + }, + { + "type": "Integer", + "value": 2 + }, + { + "type": "Integer", + "value": 1 + } + ] + } + } + ] + }, + { + "name": "Step Out", + "script": "0x5165050053665266", + "steps": + [ + { + "result": + { + "state": "Break", + "invocationStack": + [ + { + "scriptHash": "0x408E0A012B7053EE2045D637FBB54534E8AD4C9A", + "instructionPointer": 0, + "nextInstruction": "PUSH1" + } + ] + } + }, + { + "actions": + [ + "StepInto" + ], + "result": + { + "state": "Break", + "invocationStack": + [ + { + "scriptHash": "0x408E0A012B7053EE2045D637FBB54534E8AD4C9A", + "instructionPointer": 1, + "nextInstruction": "CALL", + "evaluationStack": + [ + { + "type": "Integer", + "value": 1 + } + ] + } + ] + } + }, + { + "actions": + [ + "StepOut" + ], + "result": + { + "state": "Halt", + "resultStack": + [ + { + "type": "Integer", + "value": 3 + }, + { + "type": "Integer", + "value": 2 + }, + { + "type": "Integer", + "value": 1 + } + ] + } + } + ] + }, + { + "name": "Step Over", + "script": "0x5165050053665266", + "steps": + [ + { + "result": + { + "state": "Break", + "invocationStack": + [ + { + "scriptHash": "0x408E0A012B7053EE2045D637FBB54534E8AD4C9A", + "instructionPointer": 0, + "nextInstruction": "PUSH1" + } + ] + } + }, + { + "actions": + [ + "StepInto" + ], + "result": + { + "state": "Break", + "invocationStack": + [ + { + "scriptHash": "0x408E0A012B7053EE2045D637FBB54534E8AD4C9A", + "instructionPointer": 1, + "nextInstruction": "CALL", + "evaluationStack": + [ + { + "type": "Integer", + "value": 1 + } + ] + } + ] + } + }, + { + "actions": + [ + "StepOver" + ], + "result": + { + "state": "Break", + "invocationStack": + [ + { + "scriptHash": "0x408E0A012B7053EE2045D637FBB54534E8AD4C9A", + "instructionPointer": 4, + "nextInstruction": "PUSH3", + "evaluationStack": + [ + { + "type": "Integer", + "value": 2 + }, + { + "type": "Integer", + "value": 1 + } + ] + } + ] + } + }, + { + "actions": + [ + "StepOver" + ], + "result": + { + "state": "Break", + "invocationStack": + [ + { + "scriptHash": "0x408E0A012B7053EE2045D637FBB54534E8AD4C9A", + "instructionPointer": 5, + "nextInstruction": "RET", + "evaluationStack": + [ + { + "type": "Integer", + "value": 3 + }, + { + "type": "Integer", + "value": 2 + }, + { + "type": "Integer", + "value": 1 + } + ] + } + ] + } + }, + { + "actions": + [ + "StepOver" + ], + "result": + { + "state": "Halt", + "resultStack": + [ + { + "type": "Integer", + "value": 3 + }, + { + "type": "Integer", + "value": 2 + }, + { + "type": "Integer", + "value": 1 + } + ] + } + } + ] + }, + { + "name": "Execute", + "script": "0x5165050053665266", + "steps": + [ + { + "result": + { + "state": "Break", + "invocationStack": + [ + { + "scriptHash": "0x408E0A012B7053EE2045D637FBB54534E8AD4C9A", + "instructionPointer": 0, + "nextInstruction": "PUSH1" + } + ] + } + }, + { + "actions": + [ + "Execute" + ], + "result": + { + "state": "Halt", + "resultStack": + [ + { + "type": "Integer", + "value": 3 + }, + { + "type": "Integer", + "value": 2 + }, + { + "type": "Integer", + "value": 1 + } + ] + } + } + ] + } + ] +} \ No newline at end of file diff --git a/tests/neo-vm.Tests/UtDebugger.cs b/tests/neo-vm.Tests/UtDebugger.cs new file mode 100644 index 00000000..dcbdf142 --- /dev/null +++ b/tests/neo-vm.Tests/UtDebugger.cs @@ -0,0 +1,39 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Neo.Test.Types; +using Neo.VM; + +namespace Neo.Test +{ + [TestClass] + public class UtDebugger + { + [TestMethod] + public void TestBreakPoint() + { + using (var engine = new ExecutionEngine(null, Crypto.Default, null, null)) + using (var script = new ScriptBuilder()) + { + script.Emit(OpCode.NOP); + script.Emit(OpCode.NOP); + script.Emit(OpCode.NOP); + script.Emit(OpCode.NOP); + + engine.LoadScript(script.ToArray()); + + var debugger = new Debugger(engine); + + debugger.AddBreakPoint(engine.CurrentContext.ScriptHash, 3); + debugger.AddBreakPoint(engine.CurrentContext.ScriptHash, 4); + debugger.Execute(); + + Assert.AreEqual(3, engine.CurrentContext.InstructionPointer); + Assert.AreEqual(VMState.BREAK, engine.State); + + debugger.RemoveBreakPoint(engine.CurrentContext.ScriptHash, 4); + debugger.Execute(); + + Assert.AreEqual(VMState.HALT, engine.State); + } + } + } +} \ No newline at end of file