From e891851348322107585faef2d037de0d6ec53046 Mon Sep 17 00:00:00 2001 From: Luchuan Date: Thu, 30 Apr 2020 19:07:04 +0800 Subject: [PATCH] add try-catch failure ut (#261) --- .../TestClasses/Contract_TryCatch.cs | 29 +++++++++++++++++++ .../UnitTest_TryCatch.cs | 15 ++++++++++ 2 files changed, 44 insertions(+) diff --git a/tests/Neo.Compiler.MSIL.UnitTests/TestClasses/Contract_TryCatch.cs b/tests/Neo.Compiler.MSIL.UnitTests/TestClasses/Contract_TryCatch.cs index e6b579335..c4b9d0e81 100644 --- a/tests/Neo.Compiler.MSIL.UnitTests/TestClasses/Contract_TryCatch.cs +++ b/tests/Neo.Compiler.MSIL.UnitTests/TestClasses/Contract_TryCatch.cs @@ -130,6 +130,35 @@ public static object tryCatch() return v; } + public static object tryWithTwoFinally() + { + int v = 0; + try + { + try + { + v++; + } + catch + { + v += 2; + } + finally + { + v += 3; + } + } + catch + { + v += 4; + } + finally + { + v += 5; + } + return v; + } + public static object throwcall() { throw new System.Exception(); diff --git a/tests/Neo.Compiler.MSIL.UnitTests/UnitTest_TryCatch.cs b/tests/Neo.Compiler.MSIL.UnitTests/UnitTest_TryCatch.cs index 2e931ab66..30c4b06e1 100644 --- a/tests/Neo.Compiler.MSIL.UnitTests/UnitTest_TryCatch.cs +++ b/tests/Neo.Compiler.MSIL.UnitTests/UnitTest_TryCatch.cs @@ -107,5 +107,20 @@ public void Test_TryCatch() Console.WriteLine("result = " + num.ToBigInteger().ToString()); Assert.AreEqual(num.ToBigInteger(), 3); } + + [TestMethod] + public void Test_TryWithTwoFinally() + { + var testengine = new TestEngine(); + testengine.AddEntryScript("./TestClasses/Contract_TryCatch.cs"); + testengine.ScriptEntry.DumpNEF(); + var result = testengine.ExecuteTestCaseStandard("tryWithTwoFinally"); + Console.WriteLine("state=" + testengine.State + " result on stack= " + result.Count); + var value = result.Pop(); + Console.WriteLine("result:" + value.Type + " " + value.ToString()); + var num = value as Neo.VM.Types.Integer; + Console.WriteLine("result = " + num.ToBigInteger().ToString()); + Assert.AreEqual(num.ToBigInteger(), 9); + } } }