From cfffe4f8cb40d8f8789756e09dc24f502922534c Mon Sep 17 00:00:00 2001 From: Christopher Schuchardt Date: Wed, 10 Jan 2024 09:36:02 -0500 Subject: [PATCH] Convert to Neo.Json and Neo.ConsoleService to `dotnet` standard 2.1 (#3044) * fixes #3038 * removed websocket port from configs * Removed wsport from settings * Converted neo.json to dotnet standard 2.1 * fix tests * fix workflow * added false to tests * removed unused files * Fixed TryGetValue * converted Neo.ConsoleService to standard * fixed warning * fixes for dotnet * fixed warning * Fixed header * Fixed settings and added in shargons request * convert neto to standard * fixed getBit size * Fixed bitlen and Murmur128 * fixes * contractask update * Remove IsExternalInit * Unify LangVersion * Remove comments * Remove more comments * Revert main.yml * Revert neo changes * fix targetFramework * revert revert main.yml --------- Co-authored-by: Shargon --- .github/workflows/main.yml | 1 + src/Directory.Build.props | 2 +- src/Neo.CLI/Neo.CLI.csproj | 1 + src/Neo.CLI/Settings.cs | 42 +++++++++---------- src/Neo.ConsoleService/ConsoleServiceBase.cs | 4 +- .../Neo.ConsoleService.csproj | 1 + src/Neo.Json/JArray.cs | 2 +- src/Neo.Json/JBoolean.cs | 2 +- src/Neo.Json/JNumber.cs | 2 +- src/Neo.Json/JObject.cs | 2 +- src/Neo.Json/JString.cs | 4 +- src/Neo.Json/Neo.Json.csproj | 5 +++ src/Neo.Json/OrderedDictionary.cs | 4 ++ src/Neo.VM/Neo.VM.csproj | 1 - src/Neo/Neo.csproj | 1 + .../Neo.ConsoleService.Tests.csproj | 2 + .../Neo.Json.UnitTests.csproj | 2 + tests/Neo.Json.UnitTests/UT_JObject.cs | 2 +- tests/Neo.UnitTests/Neo.UnitTests.csproj | 2 + tests/Neo.VM.Tests/Neo.VM.Tests.csproj | 1 - 20 files changed, 51 insertions(+), 32 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 521cbc5611..781a2b8dce 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -36,6 +36,7 @@ jobs: uses: coverallsapp/github-action@master with: github-token: ${{ secrets.GITHUB_TOKEN }} + path-to-lcov: ./coverage/lcov.net7.0.info # MyGet isn't working # PublishMyGet: diff --git a/src/Directory.Build.props b/src/Directory.Build.props index ff4bd977bf..35a8fa289c 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -4,8 +4,8 @@ 2015-2023 The Neo Project 3.6.2 + 11.0 The Neo Project - net7.0 neo.png https://github.com/neo-project/neo MIT diff --git a/src/Neo.CLI/Neo.CLI.csproj b/src/Neo.CLI/Neo.CLI.csproj index 757a8ea64e..8c638d6c2a 100644 --- a/src/Neo.CLI/Neo.CLI.csproj +++ b/src/Neo.CLI/Neo.CLI.csproj @@ -1,6 +1,7 @@ + net7.0 Neo.CLI neo-cli Exe diff --git a/src/Neo.CLI/Settings.cs b/src/Neo.CLI/Settings.cs index ba884fa56f..7625db58f5 100644 --- a/src/Neo.CLI/Settings.cs +++ b/src/Neo.CLI/Settings.cs @@ -51,10 +51,10 @@ public static Settings Default public Settings(IConfigurationSection section) { - this.Logger = new(section.GetSection("Logger")); - this.Storage = new(section.GetSection("Storage")); - this.P2P = new(section.GetSection("P2P")); - this.UnlockWallet = new(section.GetSection("UnlockWallet")); + Logger = new(section.GetSection(nameof(Logger))); + Storage = new(section.GetSection(nameof(Storage))); + P2P = new(section.GetSection(nameof(P2P))); + UnlockWallet = new(section.GetSection(nameof(UnlockWallet))); } } @@ -66,21 +66,21 @@ public class LoggerSettings public LoggerSettings(IConfigurationSection section) { - this.Path = section.GetValue("Path", "Logs")!; - this.ConsoleOutput = section.GetValue("ConsoleOutput", false); - this.Active = section.GetValue("Active", false); + Path = section.GetValue(nameof(Path), "Logs")!; + ConsoleOutput = section.GetValue(nameof(ConsoleOutput), false); + Active = section.GetValue(nameof(Active), false); } } public class StorageSettings { - public string Engine { get; } - public string Path { get; } + public string Engine { get; } = string.Empty; + public string Path { get; } = string.Empty; public StorageSettings(IConfigurationSection section) { - this.Engine = section.GetValue("Engine", "LevelDBStore")!; - this.Path = section.GetValue("Path", "Data_LevelDB_{0}")!; + Engine = section.GetValue(nameof(Engine), "LevelDBStore")!; + Path = section.GetValue(nameof(Path), "Data_LevelDB_{0}")!; } } @@ -93,26 +93,26 @@ public class P2PSettings public P2PSettings(IConfigurationSection section) { - this.Port = section.GetValue("Port", 10333); - this.MinDesiredConnections = section.GetValue("MinDesiredConnections", Peer.DefaultMinDesiredConnections); - this.MaxConnections = section.GetValue("MaxConnections", Peer.DefaultMaxConnections); - this.MaxConnectionsPerAddress = section.GetValue("MaxConnectionsPerAddress", 3); + Port = section.GetValue(nameof(Port), 10333); + MinDesiredConnections = section.GetValue(nameof(MinDesiredConnections), Peer.DefaultMinDesiredConnections); + MaxConnections = section.GetValue(nameof(MaxConnections), Peer.DefaultMaxConnections); + MaxConnectionsPerAddress = section.GetValue(nameof(MaxConnectionsPerAddress), 3); } } public class UnlockWalletSettings { - public string? Path { get; } - public string? Password { get; } - public bool IsActive { get; } + public string Path { get; } = string.Empty; + public string Password { get; } = string.Empty; + public bool IsActive { get; } = false; public UnlockWalletSettings(IConfigurationSection section) { if (section.Exists()) { - this.Path = section.GetValue("Path", ""); - this.Password = section.GetValue("Password", ""); - this.IsActive = bool.Parse(section.GetValue("IsActive", "false")!); + Path = section.GetValue(nameof(Path), string.Empty)!; + Password = section.GetValue(nameof(Password), string.Empty)!; + IsActive = section.GetValue(nameof(IsActive), false); } } } diff --git a/src/Neo.ConsoleService/ConsoleServiceBase.cs b/src/Neo.ConsoleService/ConsoleServiceBase.cs index 2ca62db2a2..daa9d9f061 100644 --- a/src/Neo.ConsoleService/ConsoleServiceBase.cs +++ b/src/Neo.ConsoleService/ConsoleServiceBase.cs @@ -489,8 +489,10 @@ public void Run(string[] args) } else { - Debug.Assert(OperatingSystem.IsWindows()); + Debug.Assert(Environment.OSVersion.Platform == PlatformID.Win32NT); +#pragma warning disable CA1416 ServiceBase.Run(new ServiceProxy(this)); +#pragma warning restore CA1416 } } diff --git a/src/Neo.ConsoleService/Neo.ConsoleService.csproj b/src/Neo.ConsoleService/Neo.ConsoleService.csproj index 5c2fd653ad..1971a40790 100644 --- a/src/Neo.ConsoleService/Neo.ConsoleService.csproj +++ b/src/Neo.ConsoleService/Neo.ConsoleService.csproj @@ -1,6 +1,7 @@ + netstandard2.1;net7.0 Neo.ConsoleService enable diff --git a/src/Neo.Json/JArray.cs b/src/Neo.Json/JArray.cs index 30ac7c83a2..903f29941b 100644 --- a/src/Neo.Json/JArray.cs +++ b/src/Neo.Json/JArray.cs @@ -123,7 +123,7 @@ internal override void Write(Utf8JsonWriter writer) writer.WriteEndArray(); } - public override JArray Clone() + public override JToken Clone() { var cloned = new JArray(); diff --git a/src/Neo.Json/JBoolean.cs b/src/Neo.Json/JBoolean.cs index 0ca4901a86..05cb36a89d 100644 --- a/src/Neo.Json/JBoolean.cs +++ b/src/Neo.Json/JBoolean.cs @@ -63,7 +63,7 @@ internal override void Write(Utf8JsonWriter writer) writer.WriteBooleanValue(Value); } - public override JBoolean Clone() + public override JToken Clone() { return this; } diff --git a/src/Neo.Json/JNumber.cs b/src/Neo.Json/JNumber.cs index 6c73a01b37..479303cfb5 100644 --- a/src/Neo.Json/JNumber.cs +++ b/src/Neo.Json/JNumber.cs @@ -109,7 +109,7 @@ internal override void Write(Utf8JsonWriter writer) writer.WriteNumberValue(Value); } - public override JNumber Clone() + public override JToken Clone() { return this; } diff --git a/src/Neo.Json/JObject.cs b/src/Neo.Json/JObject.cs index adc6755b5e..c5666e9112 100644 --- a/src/Neo.Json/JObject.cs +++ b/src/Neo.Json/JObject.cs @@ -76,7 +76,7 @@ internal override void Write(Utf8JsonWriter writer) /// Creates a copy of the current JSON object. /// /// A copy of the current JSON object. - public override JObject Clone() + public override JToken Clone() { var cloned = new JObject(); diff --git a/src/Neo.Json/JString.cs b/src/Neo.Json/JString.cs index f6c5d155f3..c9466c26a6 100644 --- a/src/Neo.Json/JString.cs +++ b/src/Neo.Json/JString.cs @@ -70,7 +70,7 @@ public override T AsEnum(T defaultValue = default, bool ignoreCase = false) public override T GetEnum(bool ignoreCase = false) { T result = Enum.Parse(Value, ignoreCase); - if (!Enum.IsDefined(result)) throw new InvalidCastException(); + if (!Enum.IsDefined(typeof(T), result)) throw new InvalidCastException(); return result; } @@ -79,7 +79,7 @@ internal override void Write(Utf8JsonWriter writer) writer.WriteStringValue(Value); } - public override JString Clone() + public override JToken Clone() { return this; } diff --git a/src/Neo.Json/Neo.Json.csproj b/src/Neo.Json/Neo.Json.csproj index b814851216..0687960683 100644 --- a/src/Neo.Json/Neo.Json.csproj +++ b/src/Neo.Json/Neo.Json.csproj @@ -1,9 +1,14 @@ + netstandard2.1;net7.0 enable enable NEO;JSON + + + + diff --git a/src/Neo.Json/OrderedDictionary.cs b/src/Neo.Json/OrderedDictionary.cs index 244121f304..0913bda44e 100644 --- a/src/Neo.Json/OrderedDictionary.cs +++ b/src/Neo.Json/OrderedDictionary.cs @@ -90,6 +90,8 @@ public bool Remove(TKey key) return collection.Remove(key); } +#pragma warning disable CS8767 + public bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value) { if (collection.TryGetValue(key, out var entry)) @@ -101,6 +103,8 @@ public bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value) return false; } +#pragma warning restore CS8767 + void ICollection>.Add(KeyValuePair item) { Add(item.Key, item.Value); diff --git a/src/Neo.VM/Neo.VM.csproj b/src/Neo.VM/Neo.VM.csproj index add3762a3e..5e7e071b22 100644 --- a/src/Neo.VM/Neo.VM.csproj +++ b/src/Neo.VM/Neo.VM.csproj @@ -2,7 +2,6 @@ netstandard2.1;net7.0 - 9.0 true enable diff --git a/src/Neo/Neo.csproj b/src/Neo/Neo.csproj index f798cf1701..d15345dcbf 100644 --- a/src/Neo/Neo.csproj +++ b/src/Neo/Neo.csproj @@ -1,6 +1,7 @@ + net7.0 true NEO;AntShares;Blockchain;Smart Contract diff --git a/tests/Neo.ConsoleService.Tests/Neo.ConsoleService.Tests.csproj b/tests/Neo.ConsoleService.Tests/Neo.ConsoleService.Tests.csproj index b4b29127f6..3b3ae00b49 100644 --- a/tests/Neo.ConsoleService.Tests/Neo.ConsoleService.Tests.csproj +++ b/tests/Neo.ConsoleService.Tests/Neo.ConsoleService.Tests.csproj @@ -1,7 +1,9 @@ + net7.0 neo_cli.Tests + false diff --git a/tests/Neo.Json.UnitTests/Neo.Json.UnitTests.csproj b/tests/Neo.Json.UnitTests/Neo.Json.UnitTests.csproj index 893602f33c..eeb3177eb8 100644 --- a/tests/Neo.Json.UnitTests/Neo.Json.UnitTests.csproj +++ b/tests/Neo.Json.UnitTests/Neo.Json.UnitTests.csproj @@ -1,7 +1,9 @@ + net7.0 enable + false diff --git a/tests/Neo.Json.UnitTests/UT_JObject.cs b/tests/Neo.Json.UnitTests/UT_JObject.cs index a3d5bc01b4..e3660a7d3e 100644 --- a/tests/Neo.Json.UnitTests/UT_JObject.cs +++ b/tests/Neo.Json.UnitTests/UT_JObject.cs @@ -117,7 +117,7 @@ public void TestGetNull() [TestMethod] public void TestClone() { - var bobClone = bob.Clone(); + var bobClone = (JObject)bob.Clone(); bobClone.Should().NotBeSameAs(bob); foreach (var key in bobClone.Properties.Keys) { diff --git a/tests/Neo.UnitTests/Neo.UnitTests.csproj b/tests/Neo.UnitTests/Neo.UnitTests.csproj index 8c1216740b..e39fc1d6fb 100644 --- a/tests/Neo.UnitTests/Neo.UnitTests.csproj +++ b/tests/Neo.UnitTests/Neo.UnitTests.csproj @@ -1,7 +1,9 @@ + net7.0 true + false diff --git a/tests/Neo.VM.Tests/Neo.VM.Tests.csproj b/tests/Neo.VM.Tests/Neo.VM.Tests.csproj index b86f27296a..1020d1c55a 100644 --- a/tests/Neo.VM.Tests/Neo.VM.Tests.csproj +++ b/tests/Neo.VM.Tests/Neo.VM.Tests.csproj @@ -2,7 +2,6 @@ net7.0 - 9.0 Neo.Test true false