Skip to content
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

.NET 5.0 #2083

Merged
merged 10 commits into from
Dec 17, 2020
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -198,7 +198,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 @@ -213,7 +213,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>preview3</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-CI00251" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
erikzhang marked this conversation as resolved.
Show resolved Hide resolved
<PackageReference Include="Neo.VM" Version="3.0.0-CI00255" />
</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