Skip to content

Commit

Permalink
.NET 5.0 (neo-project#2083)
Browse files Browse the repository at this point in the history
* .NET 5.0

* Update main.yml

* Update main.yml

* Update main.yml

Co-authored-by: Shargon <shargon@gmail.com>
Co-authored-by: Vitor Nazário Coelho <vncoelho@gmail.com>
  • Loading branch information
3 people authored and Shawn committed Jan 8, 2021
1 parent 2d88a6c commit df6b18d
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 109 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
pull_request:

env:
DOTNET_VERSION: 3.1.402
DOTNET_VERSION: 5.0.100

jobs:

Expand All @@ -21,8 +21,8 @@ jobs:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Check format
run: |
dotnet tool install --version 3.2.111002 --tool-path ./ dotnet-format --add-source https://dotnet.myget.org/F/format/api/v3/index.json
./dotnet-format --check --dry-run -v diagnostic
dotnet tool install --version 5.0.142902 --tool-path ./ dotnet-format --add-source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json
./dotnet-format --check -v diagnostic
- name: Test
run: |
find tests -name *.csproj | xargs -I % dotnet add % package coverlet.msbuild
Expand Down
2 changes: 1 addition & 1 deletion src/neo/Cryptography/ECC/ECCurve.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class ECCurve
private ECCurve(BigInteger Q, BigInteger A, BigInteger B, BigInteger N, byte[] G)
{
this.Q = Q;
this.ExpectedECPointLength = (Q.GetBitLength() + 7) / 8;
this.ExpectedECPointLength = ((int)Q.GetBitLength() + 7) / 8;
this.A = new ECFieldElement(A, this);
this.B = new ECFieldElement(B, this);
this.N = N;
Expand Down
4 changes: 2 additions & 2 deletions src/neo/Cryptography/ECC/ECDsa.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public BigInteger[] GenerateSignature(ReadOnlySpan<byte> message)
{
do
{
k = rng.NextBigInteger(curve.N.GetBitLength());
k = rng.NextBigInteger((int)curve.N.GetBitLength());
}
while (k.Sign == 0 || k.CompareTo(curve.N) >= 0);
ECPoint p = ECPoint.Multiply(curve.G, k);
Expand All @@ -67,7 +67,7 @@ public BigInteger[] GenerateSignature(ReadOnlySpan<byte> message)

private static ECPoint SumOfTwoMultiplies(ECPoint P, BigInteger k, ECPoint Q, BigInteger l)
{
int m = Math.Max(k.GetBitLength(), l.GetBitLength());
int m = (int)Math.Max(k.GetBitLength(), l.GetBitLength());
ECPoint Z = P + Q;
ECPoint R = P.Curve.Infinity;
for (int i = m - 1; i >= 0; --i)
Expand Down
4 changes: 2 additions & 2 deletions src/neo/Cryptography/ECC/ECFieldElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public bool Equals(ECFieldElement other)

private static BigInteger[] FastLucasSequence(BigInteger p, BigInteger P, BigInteger Q, BigInteger k)
{
int n = k.GetBitLength();
int n = (int)k.GetBitLength();
int s = k.GetLowestSetBit();

BigInteger Uh = 1;
Expand Down Expand Up @@ -115,7 +115,7 @@ public ECFieldElement Sqrt()
BigInteger P;
do
{
P = rand.NextBigInteger(curve.Q.GetBitLength());
P = rand.NextBigInteger((int)curve.Q.GetBitLength());
}
while (P >= curve.Q || BigInteger.ModPow(P * P - fourQ, legendreExponent, curve.Q) != qMinusOne);
BigInteger[] result = FastLucasSequence(curve.Q, P, Q, k);
Expand Down
2 changes: 1 addition & 1 deletion src/neo/Cryptography/ECC/ECPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public override int GetHashCode()
internal static ECPoint Multiply(ECPoint p, BigInteger k)
{
// floor(log2(k))
int m = k.GetBitLength();
int m = (int)k.GetBitLength();

// width of the Window NAF
sbyte width;
Expand Down
7 changes: 0 additions & 7 deletions src/neo/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,6 @@ public static byte[] Concat(ReadOnlySpan<byte> a, ReadOnlySpan<byte> b)
return buffer;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static int GetBitLength(this BigInteger i)
{
byte[] b = i.ToByteArray();
return (b.Length - 1) * 8 + BitLen(i.Sign > 0 ? b[b.Length - 1] : 255 - b[b.Length - 1]);
}

internal static int GetLowestSetBit(this BigInteger i)
{
if (i.Sign == 0)
Expand Down
25 changes: 0 additions & 25 deletions src/neo/IO/ReferenceEqualityComparer.cs

This file was deleted.

4 changes: 2 additions & 2 deletions src/neo/VM/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ private static JObject ToJson(StackItem item, HashSet<StackItem> context)
switch (item)
{
case Array array:
context ??= new HashSet<StackItem>(ReferenceEqualityComparer.Default);
context ??= new HashSet<StackItem>(ReferenceEqualityComparer.Instance);
if (!context.Add(array)) throw new InvalidOperationException();
json["value"] = new JArray(array.Select(p => ToJson(p, context)));
break;
Expand All @@ -240,7 +240,7 @@ private static JObject ToJson(StackItem item, HashSet<StackItem> context)
json["value"] = integer.GetInteger().ToString();
break;
case Map map:
context ??= new HashSet<StackItem>(ReferenceEqualityComparer.Default);
context ??= new HashSet<StackItem>(ReferenceEqualityComparer.Instance);
if (!context.Add(map)) throw new InvalidOperationException();
json["value"] = new JArray(map.Select(p =>
{
Expand Down
12 changes: 6 additions & 6 deletions src/neo/neo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<VersionPrefix>3.0.0</VersionPrefix>
<VersionSuffix>preview4</VersionSuffix>
<Authors>The Neo Project</Authors>
<TargetFramework>netstandard2.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<AssemblyName>Neo</AssemblyName>
<PackageId>Neo</PackageId>
Expand All @@ -21,14 +21,14 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Akka" Version="1.4.5" />
<PackageReference Include="Akka" Version="1.4.12" />
<PackageReference Include="BouncyCastle.NetCore" Version="1.8.8" />
<PackageReference Include="K4os.Compression.LZ4" Version="1.1.11" />
<PackageReference Include="K4os.Compression.LZ4" Version="1.2.6" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.WebSockets" Version="2.2.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.3" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.3" />
<PackageReference Include="Neo.VM" Version="3.0.0-preview4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
<PackageReference Include="Neo.VM" Version="3.0.0-CI00256" />
</ItemGroup>

</Project>
37 changes: 0 additions & 37 deletions tests/neo.UnitTests/IO/UT_ReferenceEqualityComparer.cs

This file was deleted.

17 changes: 1 addition & 16 deletions tests/neo.UnitTests/UT_Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,6 @@ public void TestGetLowestSetBit()
big4.GetLowestSetBit().Should().Be(63);
}

[TestMethod]
public void TestGetBitLength()
{
new BigInteger(100).GetBitLength().Should().Be(7);
new BigInteger(-100).GetBitLength().Should().Be(7);
new BigInteger(0).GetBitLength().Should().Be(8);
new BigInteger(512).GetBitLength().Should().Be(10);
new BigInteger(short.MinValue).GetBitLength().Should().Be(15);
new BigInteger(short.MaxValue).GetBitLength().Should().Be(15);
new BigInteger(int.MinValue).GetBitLength().Should().Be(31);
new BigInteger(int.MaxValue).GetBitLength().Should().Be(31);
new BigInteger(long.MinValue).GetBitLength().Should().Be(63);
new BigInteger(long.MaxValue).GetBitLength().Should().Be(63);
}

[TestMethod]
public void TestHexToBytes()
{
Expand Down Expand Up @@ -187,7 +172,7 @@ public void TestToHexString()
public void TestGetVersion()
{
string version = typeof(TestMethodAttribute).Assembly.GetVersion();
version.Should().Be("14.0.4701.02");
version.Should().Be("14.0.4908.02");

// assembly without version

Expand Down
14 changes: 7 additions & 7 deletions tests/neo.UnitTests/neo.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<AssemblyName>Neo.UnitTests</AssemblyName>
<RootNamespace>Neo.UnitTests</RootNamespace>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
Expand All @@ -16,12 +16,12 @@

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="2.1.1" />
<PackageReference Include="Moq" Version="4.14.1" />
<PackageReference Include="Akka.TestKit" Version="1.4.5" />
<PackageReference Include="Akka.TestKit.Xunit2" Version="1.4.5" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.1.2" />
<PackageReference Include="MSTest.TestFramework" Version="2.1.2" />
<PackageReference Include="Moq" Version="4.15.1" />
<PackageReference Include="Akka.TestKit" Version="1.4.12" />
<PackageReference Include="Akka.TestKit.Xunit2" Version="1.4.12" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit df6b18d

Please sign in to comment.