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

Fix FormatException for systems with European culture (comma decimal separator) #467

Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions neo-modules.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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}
Expand Down
5 changes: 3 additions & 2 deletions src/RpcClient/TransactionManagerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,7 +22,7 @@ public class TransactionManagerFactory
/// </summary>
/// <param name="rpcClient">the RPC client to call NEO RPC API</param>
/// <param name="magic">
/// 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.
/// </param>
public TransactionManagerFactory(RpcClient rpcClient, uint? magic = null)
Expand All @@ -48,7 +49,7 @@ public async Task<TransactionManager> MakeTransactionAsync(byte[] script, Signer
Script = script,
Signers = signers ?? Array.Empty<Signer>(),
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<TransactionAttribute>(),
};

Expand Down
5 changes: 3 additions & 2 deletions src/RpcServer/RpcServerSettings.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.Extensions.Configuration;
using Neo.SmartContract.Native;
using System;
using System.Globalization;
using System.Linq;
using System.Net;

Expand Down Expand Up @@ -47,8 +48,8 @@ public RpcServerSettings(IPAddress bindAddress = null,
this.TrustedAuthorities = trustedAuthorities ?? Array.Empty<string>();
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<string>();
this.MaxConcurrentConnections = maxConcurrentConnections;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Neo.Network.RPC.Tests/UT_RpcClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private void MockResponse(RpcRequest request, RpcResponse response)
ItExpr.Is<HttpRequestMessage>(p => p.Content.ReadAsStringAsync().Result == request.ToJson().ToString()),
ItExpr.IsAny<CancellationToken>()
)
// prepare the expected response of the mocked http call
// prepare the expected response of the mocked http call
.ReturnsAsync(new HttpResponseMessage()
{
StatusCode = HttpStatusCode.OK,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<RootNamespace>Neo.Plugins.RpcServer.Tests</RootNamespace>
<AssemblyName>Neo.Plugins.RpcServer.Tests</AssemblyName>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\RpcServer\RpcServer.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.9.0" />
</ItemGroup>

</Project>
17 changes: 17 additions & 0 deletions tests/Neo.Plugins.RpcServer.Tests/UT_RpcServer.cs
Original file line number Diff line number Diff line change
@@ -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<FormatException>();
}
}
}