Skip to content

Commit

Permalink
.NET 6.0 (#2627)
Browse files Browse the repository at this point in the history
* .NET 6.0

* Fix opcode prices

* Fix UPnP

* Update main.yml

* Update akka

* Fix UT for Microsoft.EntityFrameworkCore.Sqlite 6.0.0
  • Loading branch information
erikzhang authored Nov 12, 2021
1 parent 02cae38 commit ae09b76
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 41 deletions.
5 changes: 2 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: 5.0.100
DOTNET_VERSION: 6.0.x

jobs:

Expand All @@ -21,8 +21,7 @@ jobs:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Check format
run: |
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
dotnet format --verify-no-changes --verbosity diagnostic
- name: Test
run: |
find tests -name *.csproj | xargs -I % dotnet add % package coverlet.msbuild
Expand Down
25 changes: 10 additions & 15 deletions src/neo/Network/UPnP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Sockets;
using System.Text;
using System.Xml;
Expand Down Expand Up @@ -95,11 +96,7 @@ private static string GetServiceUrl(string resp)
try
{
XmlDocument desc = new() { XmlResolver = null };
HttpWebRequest request = WebRequest.CreateHttp(resp);
using (WebResponse response = request.GetResponse())
{
desc.Load(response.GetResponseStream());
}
desc.Load(resp);
XmlNamespaceManager nsMgr = new(desc.NameTable);
nsMgr.AddNamespace("tns", "urn:schemas-upnp-org:device-1-0");
XmlNode typen = desc.SelectSingleNode("//tns:device/tns:deviceType/text()", nsMgr);
Expand Down Expand Up @@ -180,17 +177,15 @@ private static XmlDocument SOAPRequest(string url, string soap, string function)
soap +
"</s:Body>" +
"</s:Envelope>";
HttpWebRequest r = WebRequest.CreateHttp(url);
r.Method = "POST";
byte[] b = Encoding.UTF8.GetBytes(req);
r.Headers["SOAPACTION"] = "\"urn:schemas-upnp-org:service:WANIPConnection:1#" + function + "\"";
r.ContentType = "text/xml; charset=\"utf-8\"";
using Stream reqs = r.GetRequestStream();
reqs.Write(b, 0, b.Length);
using HttpRequestMessage request = new(HttpMethod.Post, url);
request.Headers.Add("SOAPACTION", $"\"urn:schemas-upnp-org:service:WANIPConnection:1#{function}\"");
request.Headers.Add("Content-Type", "text/xml; charset=\"utf-8\"");
request.Content = new StringContent(req);
using HttpClient http = new();
using HttpResponseMessage response = http.Send(request);
using Stream stream = response.EnsureSuccessStatusCode().Content.ReadAsStream();
XmlDocument resp = new() { XmlResolver = null };
WebResponse wres = r.GetResponse();
using Stream ress = wres.GetResponseStream();
resp.Load(ress);
resp.Load(stream);
return resp;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/neo/SmartContract/ApplicationEngine.OpCodePrices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ partial class ApplicationEngine
[OpCode.MIN] = 1 << 3,
[OpCode.MAX] = 1 << 3,
[OpCode.WITHIN] = 1 << 3,
[OpCode.PACKMAP] = 1 << 11,
[OpCode.PACKSTRUCT] = 1 << 11,
[OpCode.PACK] = 1 << 11,
[OpCode.UNPACK] = 1 << 11,
[OpCode.NEWARRAY0] = 1 << 4,
Expand Down
5 changes: 5 additions & 0 deletions src/neo/Wallets/NEP6/NEP6Wallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ public KeyPair DecryptKey(string nep2key)
return new KeyPair(GetPrivateKeyFromNEP2(nep2key, password, ProtocolSettings.AddressVersion, Scrypt.N, Scrypt.R, Scrypt.P));
}

public override void Delete()
{
if (File.Exists(Path)) File.Delete(Path);
}

public override bool DeleteAccount(UInt160 scriptHash)
{
lock (accounts)
Expand Down
6 changes: 6 additions & 0 deletions src/neo/Wallets/SQLite/UserWallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,12 @@ public override WalletAccount CreateAccount(UInt160 scriptHash)
return account;
}

public override void Delete()
{
using WalletDataContext ctx = new(Path);
ctx.Database.EnsureDeleted();
}

public override bool DeleteAccount(UInt160 scriptHash)
{
UserWalletAccount account;
Expand Down
5 changes: 5 additions & 0 deletions src/neo/Wallets/Wallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ public abstract class Wallet
/// <returns>The created account.</returns>
public abstract WalletAccount CreateAccount(UInt160 scriptHash);

/// <summary>
/// Deletes the entire database of the wallet.
/// </summary>
public abstract void Delete();

/// <summary>
/// Deletes an account from the wallet.
/// </summary>
Expand Down
12 changes: 6 additions & 6 deletions src/neo/neo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<PropertyGroup>
<Copyright>2015-2021 The Neo Project</Copyright>
<AssemblyTitle>Neo</AssemblyTitle>
<VersionPrefix>3.0.3</VersionPrefix>
<VersionPrefix>3.1.0</VersionPrefix>
<Authors>The Neo Project</Authors>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<AssemblyName>Neo</AssemblyName>
<PackageId>Neo</PackageId>
Expand All @@ -25,11 +25,11 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Akka" Version="1.4.26" />
<PackageReference Include="Akka" Version="1.4.28" />
<PackageReference Include="BouncyCastle.NetCore" Version="1.8.8" />
<PackageReference Include="K4os.Compression.LZ4" Version="1.2.12" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.10" />
<PackageReference Include="Neo.VM" Version="3.0.1" />
<PackageReference Include="K4os.Compression.LZ4" Version="1.2.15" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.0" />
<PackageReference Include="Neo.VM" Version="3.1.0" />
</ItemGroup>

</Project>
8 changes: 0 additions & 8 deletions tests/neo.UnitTests/TestUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,5 @@ public static T CopyMsgBySerialization<T>(T serializableObj, T newObj) where T :

return newObj;
}

public static void DeleteFile(string file)
{
if (File.Exists(file))
{
File.Delete(file);
}
}
}
}
4 changes: 2 additions & 2 deletions tests/neo.UnitTests/Wallets/NEP6/UT_NEP6Wallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,8 @@ public void TestMigrate()
NEP6Wallet nw = NEP6Wallet.Migrate(npath, path, "123", ProtocolSettings.Default);
bool result = nw.Contains(testScriptHash);
Assert.AreEqual(true, result);
if (File.Exists(path)) File.Delete(path);
if (File.Exists(npath)) File.Delete(npath);
uw.Delete();
nw.Delete();
}

[TestMethod]
Expand Down
4 changes: 2 additions & 2 deletions tests/neo.UnitTests/Wallets/SQLite/UT_UserWallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static void Setup(TestContext ctx)
[ClassCleanup]
public static void Cleanup()
{
TestUtils.DeleteFile(path);
wallet.Delete();
}

[TestMethod]
Expand Down Expand Up @@ -141,7 +141,7 @@ public void TestCreateAndOpenSecureString()
Action action = () => UserWallet.Open(myPath, ss, ProtocolSettings.Default);
action.Should().Throw<CryptographicException>();

TestUtils.DeleteFile(myPath);
w1.Delete();
}

[TestMethod]
Expand Down
4 changes: 4 additions & 0 deletions tests/neo.UnitTests/Wallets/UT_Wallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ public override WalletAccount CreateAccount(UInt160 scriptHash)
return account;
}

public override void Delete()
{
}

public override bool DeleteAccount(UInt160 scriptHash)
{
return accounts.Remove(scriptHash);
Expand Down
10 changes: 5 additions & 5 deletions tests/neo.UnitTests/neo.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<AssemblyName>Neo.UnitTests</AssemblyName>
<RootNamespace>Neo.UnitTests</RootNamespace>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Akka.TestKit" Version="1.4.26" />
<PackageReference Include="Akka.TestKit.Xunit2" Version="1.4.26" />
<PackageReference Include="FluentAssertions" Version="6.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="Akka.TestKit" Version="1.4.28" />
<PackageReference Include="Akka.TestKit.Xunit2" Version="1.4.28" />
<PackageReference Include="FluentAssertions" Version="6.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="Moq" Version="4.16.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.7" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.7" />
Expand Down

0 comments on commit ae09b76

Please sign in to comment.