Skip to content

Commit

Permalink
add try-catch failure ut (#261)
Browse files Browse the repository at this point in the history
  • Loading branch information
Luchuan committed Apr 30, 2020
1 parent 0ffbe6a commit e891851
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/Neo.Compiler.MSIL.UnitTests/TestClasses/Contract_TryCatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
15 changes: 15 additions & 0 deletions tests/Neo.Compiler.MSIL.UnitTests/UnitTest_TryCatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

0 comments on commit e891851

Please sign in to comment.