Skip to content

Commit

Permalink
Fix BigInteger (#433)
Browse files Browse the repository at this point in the history
* Fix BigInteger

* Parse from variable

Co-authored-by: Luchuan <luchuan@ngd.neo.org>
  • Loading branch information
shargon and Tommo-L authored Jan 16, 2021
1 parent 5f0c001 commit 3caea8f
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Neo.Compiler.MSIL/MSIL/Conv_Multi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,21 @@ private int ConvertCall(OpCode src, NeoMethod to, List<MethodToken> methodTokens
Insert1(VM.OpCode.SYSCALL, "", to, BitConverter.GetBytes(ApplicationEngine.System_Binary_Atoi));
return 0;
}
else if (src.tokenMethod == "System.Numerics.BigInteger System.Numerics.BigInteger::get_One()")
{
ConvertPushNumber(1, null, to);
return 0;
}
else if (src.tokenMethod == "System.Numerics.BigInteger System.Numerics.BigInteger::get_MinusOne()")
{
ConvertPushNumber(-1, null, to);
return 0;
}
else if (src.tokenMethod == "System.Numerics.BigInteger System.Numerics.BigInteger::get_Zero()")
{
ConvertPushNumber(0, null, to);
return 0;
}
}

if (calltype == 0)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.Runtime.CompilerServices;

namespace Neo.Compiler.MSIL.UnitTests.TestClasses
{
class Contract_Types_BigInteger : SmartContract.Framework.SmartContract
{
public static BigInteger Zero() { return BigInteger.Zero; }
public static BigInteger One() { return BigInteger.One; }
public static BigInteger MinusOne() { return BigInteger.MinusOne; }
public static BigInteger Parse(string value) { return BigInteger.Parse(value); }
}
}
35 changes: 35 additions & 0 deletions tests/Neo.Compiler.MSIL.UnitTests/UnitTest_Types.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,41 @@ public void bool_Test()
Assert.AreEqual(0, ((Integer)item).GetInteger());
}

[TestMethod]
public void bigInteer_Test()
{
var testengine = new TestEngine();
testengine.AddEntryScript("./TestClasses/Contract_Types_BigInteger.cs");

// static vars

var result = testengine.ExecuteTestCaseStandard("zero");
var item = result.Pop();

Assert.IsInstanceOfType(item, typeof(Integer));
Assert.AreEqual(BigInteger.Zero, ((Integer)item).GetInteger());

testengine.Reset();
result = testengine.ExecuteTestCaseStandard("one");
item = result.Pop();
Assert.IsInstanceOfType(item, typeof(Integer));
Assert.AreEqual(BigInteger.One, ((Integer)item).GetInteger());

testengine.Reset();
result = testengine.ExecuteTestCaseStandard("minusOne");
item = result.Pop();
Assert.IsInstanceOfType(item, typeof(Integer));
Assert.AreEqual(BigInteger.MinusOne, ((Integer)item).GetInteger());

// Parse

testengine.Reset();
result = testengine.ExecuteTestCaseStandard("parse", "456");
item = result.Pop();
Assert.IsInstanceOfType(item, typeof(Integer));
Assert.AreEqual(456, item.GetInteger());
}

[TestMethod]
public void sbyte_Test()
{
Expand Down

0 comments on commit 3caea8f

Please sign in to comment.