-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Neo.Compiler.CSharp.TestContracts | ||
{ | ||
public class Contract_Overflow : SmartContract.Framework.SmartContract | ||
{ | ||
public static int Add(int a, int b) => a + b; | ||
public static int Mul(int a, int b) => a * b; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
tests/Neo.Compiler.CSharp.UnitTests/TestingArtifacts/Contract_Overflow.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using Neo.Cryptography.ECC; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Numerics; | ||
|
||
namespace Neo.SmartContract.Testing; | ||
|
||
public abstract class Contract_Overflow(Neo.SmartContract.Testing.SmartContractInitialize initialize) : Neo.SmartContract.Testing.SmartContract(initialize), IContractInfo | ||
{ | ||
#region Compiled data | ||
|
||
public static Neo.SmartContract.Manifest.ContractManifest Manifest => Neo.SmartContract.Manifest.ContractManifest.Parse(@"{""name"":""Contract_Overflow"",""groups"":[],""features"":{},""supportedstandards"":[],""abi"":{""methods"":[{""name"":""add"",""parameters"":[{""name"":""a"",""type"":""Integer""},{""name"":""b"",""type"":""Integer""}],""returntype"":""Integer"",""offset"":0,""safe"":false},{""name"":""mul"",""parameters"":[{""name"":""a"",""type"":""Integer""},{""name"":""b"",""type"":""Integer""}],""returntype"":""Integer"",""offset"":53,""safe"":false}],""events"":[]},""permissions"":[],""trusts"":[],""extra"":{""nef"":{""optimization"":""All""}}}"); | ||
|
||
/// <summary> | ||
/// Optimization: "All" | ||
/// </summary> | ||
public static Neo.SmartContract.NefFile Nef => Neo.IO.Helper.AsSerializable<Neo.SmartContract.NefFile>(Convert.FromBase64String(@"TkVGM1Rlc3RpbmdFbmdpbmUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGpXAAJ4eZ5KAgAAAIAuBCIKSgL///9/Mh4D/////wAAAACRSgL///9/MgwDAAAAAAEAAACfQFcAAnh5oEoCAAAAgC4EIgpKAv///38yHgP/////AAAAAJFKAv///38yDAMAAAAAAQAAAJ9AhqjPTQ==")); | ||
|
||
#endregion | ||
|
||
#region Unsafe methods | ||
|
||
/// <summary> | ||
/// Unsafe method | ||
/// </summary> | ||
[DisplayName("add")] | ||
public abstract BigInteger? Add(BigInteger? a, BigInteger? b); | ||
|
||
/// <summary> | ||
/// Unsafe method | ||
/// </summary> | ||
[DisplayName("mul")] | ||
public abstract BigInteger? Mul(BigInteger? a, BigInteger? b); | ||
|
||
#endregion | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Neo.SmartContract.Testing; | ||
using Neo.SmartContract.Testing.Exceptions; | ||
using System.Numerics; | ||
|
||
namespace Neo.Compiler.CSharp.UnitTests | ||
{ | ||
[TestClass] | ||
public class UnitTest_Overflow : DebugAndTestBase<Contract_Overflow> | ||
{ | ||
[TestMethod] | ||
public void Test_Add() | ||
{ | ||
Assert.AreEqual(unchecked(int.MinValue - 1), Contract.Add(int.MinValue, -1)); | ||
Assert.AreEqual(unchecked(int.MaxValue + 1), Contract.Add(int.MaxValue, 1)); | ||
Assert.AreEqual(unchecked(int.MinValue - int.MaxValue), Contract.Add(int.MinValue, -int.MaxValue)); | ||
Assert.AreEqual(unchecked(int.MaxValue - int.MinValue), Contract.Add(int.MaxValue, unchecked(-int.MinValue))); | ||
} | ||
|
||
[TestMethod] | ||
public void Test_Mul() | ||
{ | ||
Assert.AreEqual(unchecked(int.MinValue * 2), Contract.Mul(int.MinValue, 2)); | ||
Assert.AreEqual(unchecked(int.MinValue * (-2)), Contract.Mul(int.MinValue, -2)); | ||
Assert.AreEqual(unchecked(int.MaxValue * 2), Contract.Mul(int.MaxValue, 2)); | ||
Assert.AreEqual(unchecked(int.MaxValue * (-2)), Contract.Mul(int.MaxValue, -2)); | ||
Assert.AreEqual(unchecked(int.MinValue * int.MaxValue), Contract.Mul(int.MinValue, int.MaxValue)); | ||
Assert.AreEqual(unchecked(int.MinValue * (-int.MaxValue)), Contract.Mul(int.MinValue, -int.MaxValue)); | ||
Assert.AreEqual(unchecked((-int.MinValue) * int.MaxValue), Contract.Mul(unchecked(-int.MinValue), int.MaxValue)); | ||
} | ||
} | ||
} |