-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BigInteger in Neo.Json #3037
base: HF_Echidna
Are you sure you want to change the base?
BigInteger in Neo.Json #3037
Changes from 7 commits
6b31958
48c2649
186c2ba
eab5b25
776ab64
9ccb97d
458499b
edae719
be973c9
308d33d
19e3111
1214697
58ec583
efa2c34
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,10 +50,7 @@ public static JToken Serialize(StackItem item) | |
} | ||
case Integer num: | ||
{ | ||
var integer = num.GetInteger(); | ||
if (integer > JNumber.MAX_SAFE_INTEGER || integer < JNumber.MIN_SAFE_INTEGER) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hello, #2498. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. He put it in the JNumber. Different exception, but will fail as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was moved to the constructor, that was the bug, when we used parse we allowed it... |
||
throw new InvalidOperationException(); | ||
return (double)integer; | ||
return num.GetInteger(); | ||
} | ||
case Boolean boolean: | ||
{ | ||
|
@@ -65,7 +62,7 @@ public static JToken Serialize(StackItem item) | |
|
||
foreach (var entry in map) | ||
{ | ||
if (!(entry.Key is ByteString)) throw new FormatException(); | ||
if (entry.Key is not ByteString) throw new FormatException(); | ||
|
||
var key = entry.Key.GetString(); | ||
var value = Serialize(entry.Value); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
using System.Numerics; | ||
|
||
namespace Neo.Json.UnitTests | ||
{ | ||
enum Woo | ||
|
@@ -26,20 +28,29 @@ public void SetUp() | |
public void TestAsBoolean() | ||
{ | ||
maxInt.AsBoolean().Should().BeTrue(); | ||
minInt.AsBoolean().Should().BeTrue(); | ||
zero.AsBoolean().Should().BeFalse(); | ||
} | ||
|
||
[TestMethod] | ||
public void TestBigInteger() | ||
{ | ||
((JNumber)BigInteger.One).AsNumber().Should().Be(1); | ||
((JNumber)BigInteger.Zero).AsNumber().Should().Be(0); | ||
((JNumber)BigInteger.MinusOne).AsNumber().Should().Be(-1); | ||
} | ||
Comment on lines
+47
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ping @shargon
Jim8y marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
[TestMethod] | ||
public void TestAsString() | ||
{ | ||
Action action1 = () => new JNumber(double.PositiveInfinity).AsString(); | ||
action1.Should().Throw<FormatException>(); | ||
action1.Should().Throw<ArgumentException>(); | ||
|
||
Action action2 = () => new JNumber(double.NegativeInfinity).AsString(); | ||
action2.Should().Throw<FormatException>(); | ||
action2.Should().Throw<ArgumentException>(); | ||
|
||
Action action3 = () => new JNumber(double.NaN).AsString(); | ||
action3.Should().Throw<FormatException>(); | ||
action3.Should().Throw<ArgumentException>(); | ||
} | ||
|
||
[TestMethod] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
verify this after the next 2?