From 6c2abe6ce2cca831b0503e6c25ed62d488a9cfa4 Mon Sep 17 00:00:00 2001 From: Robin Date: Sat, 16 Jan 2021 17:10:45 +0100 Subject: [PATCH 1/3] Fix FormatException for systems with European culture (comma decimal separator). --- src/RpcClient/TransactionManagerFactory.cs | 5 +++-- src/RpcServer/RpcServerSettings.cs | 5 +++-- .../Neo.Network.RPC.Tests/Neo.Network.RPC.Tests.csproj | 1 + tests/Neo.Network.RPC.Tests/UT_RpcClient.cs | 10 +++++++++- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/RpcClient/TransactionManagerFactory.cs b/src/RpcClient/TransactionManagerFactory.cs index 92e50b310..a2a568fb5 100644 --- a/src/RpcClient/TransactionManagerFactory.cs +++ b/src/RpcClient/TransactionManagerFactory.cs @@ -2,6 +2,7 @@ using Neo.Network.RPC.Models; using Neo.SmartContract.Native; using System; +using System.Globalization; using System.Threading.Tasks; namespace Neo.Network.RPC @@ -21,7 +22,7 @@ public class TransactionManagerFactory /// /// the RPC client to call NEO RPC API /// - /// the network Magic value to use when signing transactions. + /// the network Magic value to use when signing transactions. /// Defaults to ProtocolSettings.Default.Magic if not specified. /// public TransactionManagerFactory(RpcClient rpcClient, uint? magic = null) @@ -48,7 +49,7 @@ public async Task MakeTransactionAsync(byte[] script, Signer Script = script, Signers = signers ?? Array.Empty(), ValidUntilBlock = blockCount - 1 + Transaction.MaxValidUntilBlockIncrement, - SystemFee = (long)BigDecimal.Parse(invokeResult.GasConsumed.ToString(), NativeContract.GAS.Decimals).Value, + SystemFee = (long)BigDecimal.Parse(invokeResult.GasConsumed.ToString(CultureInfo.InvariantCulture), NativeContract.GAS.Decimals).Value, Attributes = attributes ?? Array.Empty(), }; diff --git a/src/RpcServer/RpcServerSettings.cs b/src/RpcServer/RpcServerSettings.cs index 4a61070ee..d92aa1ec0 100644 --- a/src/RpcServer/RpcServerSettings.cs +++ b/src/RpcServer/RpcServerSettings.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.Configuration; using Neo.SmartContract.Native; using System; +using System.Globalization; using System.Linq; using System.Net; @@ -47,8 +48,8 @@ public RpcServerSettings(IPAddress bindAddress = null, this.TrustedAuthorities = trustedAuthorities ?? Array.Empty(); this.RpcUser = rpcUser; this.RpcPass = rpcPass; - this.MaxGasInvoke = (long)BigDecimal.Parse(maxGasInvoke.ToString(), NativeContract.GAS.Decimals).Value; - this.MaxFee = (long)BigDecimal.Parse(maxFee.ToString(), NativeContract.GAS.Decimals).Value; + this.MaxGasInvoke = (long)BigDecimal.Parse(maxGasInvoke.ToString(CultureInfo.InvariantCulture), NativeContract.GAS.Decimals).Value; + this.MaxFee = (long)BigDecimal.Parse(maxFee.ToString(CultureInfo.InvariantCulture), NativeContract.GAS.Decimals).Value; this.DisabledMethods = disabledMethods ?? Array.Empty(); this.MaxConcurrentConnections = maxConcurrentConnections; } diff --git a/tests/Neo.Network.RPC.Tests/Neo.Network.RPC.Tests.csproj b/tests/Neo.Network.RPC.Tests/Neo.Network.RPC.Tests.csproj index 3209d575a..a4bf8333b 100644 --- a/tests/Neo.Network.RPC.Tests/Neo.Network.RPC.Tests.csproj +++ b/tests/Neo.Network.RPC.Tests/Neo.Network.RPC.Tests.csproj @@ -12,6 +12,7 @@ + diff --git a/tests/Neo.Network.RPC.Tests/UT_RpcClient.cs b/tests/Neo.Network.RPC.Tests/UT_RpcClient.cs index bc90da031..1975fb89c 100644 --- a/tests/Neo.Network.RPC.Tests/UT_RpcClient.cs +++ b/tests/Neo.Network.RPC.Tests/UT_RpcClient.cs @@ -13,6 +13,7 @@ using System.Net.Http; using System.Threading; using System.Threading.Tasks; +using Neo.Plugins; namespace Neo.Network.RPC.Tests { @@ -45,7 +46,7 @@ private void MockResponse(RpcRequest request, RpcResponse response) ItExpr.Is(p => p.Content.ReadAsStringAsync().Result == request.ToJson().ToString()), ItExpr.IsAny() ) - // prepare the expected response of the mocked http call + // prepare the expected response of the mocked http call .ReturnsAsync(new HttpResponseMessage() { StatusCode = HttpStatusCode.OK, @@ -78,6 +79,13 @@ public void TestConstructorByUrlAndDispose() action.Should().NotThrow(); } + [TestMethod] + public void TestRpcServerSettingsConstructorForFormatException() + { + Action act = () => new RpcServerSettings(maxGasInvoke: 123456m); + act.Should().NotThrow(); + } + [TestMethod] public void TestConstructorWithBasicAuth() { From baeb89d21e3018e616c286cfc60d7b482618d23b Mon Sep 17 00:00:00 2001 From: Robin Date: Sun, 17 Jan 2021 11:56:57 +0100 Subject: [PATCH 2/3] Move unit test to different test project: Neo.Plugins.RpcServer.Tests. --- neo-modules.sln | 7 +++++++ .../Neo.Network.RPC.Tests.csproj | 1 - tests/Neo.Network.RPC.Tests/UT_RpcClient.cs | 8 -------- .../Neo.Plugins.RpcServer.Tests.csproj | 16 ++++++++++++++++ .../Neo.Plugins.RpcServer.Tests/UT_RpcServer.cs | 17 +++++++++++++++++ 5 files changed, 40 insertions(+), 9 deletions(-) create mode 100644 tests/Neo.Plugins.RpcServer.Tests/Neo.Plugins.RpcServer.Tests.csproj create mode 100644 tests/Neo.Plugins.RpcServer.Tests/UT_RpcServer.cs diff --git a/neo-modules.sln b/neo-modules.sln index 9fb7bec63..fd25f6af5 100644 --- a/neo-modules.sln +++ b/neo-modules.sln @@ -34,6 +34,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Neo.Plugins.StateService.Te EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dBFT", "src\dBFT\dBFT.csproj", "{90185D3E-4813-4BC1-98FE-26FD34311403}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Neo.Plugins.RpcServer.Tests", "tests\Neo.Plugins.RpcServer.Tests\Neo.Plugins.RpcServer.Tests.csproj", "{0DDAF738-0FD3-40A7-A433-C514BCDDF542}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -96,6 +98,10 @@ Global {90185D3E-4813-4BC1-98FE-26FD34311403}.Debug|Any CPU.Build.0 = Debug|Any CPU {90185D3E-4813-4BC1-98FE-26FD34311403}.Release|Any CPU.ActiveCfg = Release|Any CPU {90185D3E-4813-4BC1-98FE-26FD34311403}.Release|Any CPU.Build.0 = Release|Any CPU + {0DDAF738-0FD3-40A7-A433-C514BCDDF542}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0DDAF738-0FD3-40A7-A433-C514BCDDF542}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0DDAF738-0FD3-40A7-A433-C514BCDDF542}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0DDAF738-0FD3-40A7-A433-C514BCDDF542}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -115,6 +121,7 @@ Global {149822EC-4E0C-425F-A032-4196B615BFEB} = {59D802AB-C552-422A-B9C3-64D329FBCDCC} {DCEBBF09-C26B-47C8-A024-F1FF7601BEAF} = {59D802AB-C552-422A-B9C3-64D329FBCDCC} {90185D3E-4813-4BC1-98FE-26FD34311403} = {97E81C78-1637-481F-9485-DA1225E94C23} + {0DDAF738-0FD3-40A7-A433-C514BCDDF542} = {59D802AB-C552-422A-B9C3-64D329FBCDCC} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {61D3ADE6-BBFC-402D-AB42-1C71C9F9EDE3} diff --git a/tests/Neo.Network.RPC.Tests/Neo.Network.RPC.Tests.csproj b/tests/Neo.Network.RPC.Tests/Neo.Network.RPC.Tests.csproj index a4bf8333b..3209d575a 100644 --- a/tests/Neo.Network.RPC.Tests/Neo.Network.RPC.Tests.csproj +++ b/tests/Neo.Network.RPC.Tests/Neo.Network.RPC.Tests.csproj @@ -12,7 +12,6 @@ - diff --git a/tests/Neo.Network.RPC.Tests/UT_RpcClient.cs b/tests/Neo.Network.RPC.Tests/UT_RpcClient.cs index 1975fb89c..c3a2917aa 100644 --- a/tests/Neo.Network.RPC.Tests/UT_RpcClient.cs +++ b/tests/Neo.Network.RPC.Tests/UT_RpcClient.cs @@ -13,7 +13,6 @@ using System.Net.Http; using System.Threading; using System.Threading.Tasks; -using Neo.Plugins; namespace Neo.Network.RPC.Tests { @@ -79,13 +78,6 @@ public void TestConstructorByUrlAndDispose() action.Should().NotThrow(); } - [TestMethod] - public void TestRpcServerSettingsConstructorForFormatException() - { - Action act = () => new RpcServerSettings(maxGasInvoke: 123456m); - act.Should().NotThrow(); - } - [TestMethod] public void TestConstructorWithBasicAuth() { diff --git a/tests/Neo.Plugins.RpcServer.Tests/Neo.Plugins.RpcServer.Tests.csproj b/tests/Neo.Plugins.RpcServer.Tests/Neo.Plugins.RpcServer.Tests.csproj new file mode 100644 index 000000000..ef86a9969 --- /dev/null +++ b/tests/Neo.Plugins.RpcServer.Tests/Neo.Plugins.RpcServer.Tests.csproj @@ -0,0 +1,16 @@ + + + + Neo.Plugins.RpcServer.Tests + Neo.Plugins.RpcServer.Tests + + + + + + + + + + + diff --git a/tests/Neo.Plugins.RpcServer.Tests/UT_RpcServer.cs b/tests/Neo.Plugins.RpcServer.Tests/UT_RpcServer.cs new file mode 100644 index 000000000..74c8a8e30 --- /dev/null +++ b/tests/Neo.Plugins.RpcServer.Tests/UT_RpcServer.cs @@ -0,0 +1,17 @@ +using System; +using FluentAssertions; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace Neo.Plugins.RpcServer.Tests +{ + [TestClass] + public class UT_RpcServer + { + [TestMethod] + public void TestRpcServerSettingsConstructorForFormatException() + { + Action act = () => new RpcServerSettings(maxGasInvoke: 123456m); + act.Should().NotThrow(); + } + } +} From 76c0120fddc1705fc02831f353b9d2a55fa875ed Mon Sep 17 00:00:00 2001 From: Shargon Date: Sun, 17 Jan 2021 14:46:33 +0100 Subject: [PATCH 3/3] Add rpc server test to workflow --- .github/workflows/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index dbd8a7082..a056aee75 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -28,6 +28,7 @@ jobs: sudo apt-get --assume-yes install libleveldb-dev libsnappy-dev libc6-dev find tests -name *.csproj | xargs -I % dotnet add % package coverlet.msbuild dotnet test tests/Neo.Network.RPC.Tests /p:CollectCoverage=true /p:CoverletOutput=${GITHUB_WORKSPACE}/coverage/ + dotnet test tests/Neo.Plugins.RpcServer.Tests /p:CollectCoverage=true /p:CoverletOutput=${GITHUB_WORKSPACE}/coverage/lcov /p:MergeWith=${GITHUB_WORKSPACE}/coverage/coverage.json /p:CoverletOutputFormat=lcov dotnet test tests/Neo.Plugins.Storage.Tests /p:CollectCoverage=true /p:CoverletOutput=${GITHUB_WORKSPACE}/coverage/lcov /p:MergeWith=${GITHUB_WORKSPACE}/coverage/coverage.json /p:CoverletOutputFormat=lcov dotnet test tests/Neo.Plugins.StateService.Tests /p:CollectCoverage=true /p:CoverletOutput=${GITHUB_WORKSPACE}/coverage/lcov /p:MergeWith=${GITHUB_WORKSPACE}/coverage/coverage.json /p:CoverletOutputFormat=lcov dotnet test tests/Neo.Plugins.OracleService.Tests /p:CollectCoverage=true /p:CoverletOutput=${GITHUB_WORKSPACE}/coverage/lcov /p:MergeWith=${GITHUB_WORKSPACE}/coverage/coverage.json /p:CoverletOutputFormat=lcov