Skip to content

Commit

Permalink
Merge pull request #753 from AElfProject/enhancement-code-quality-dev
Browse files Browse the repository at this point in the history
Fix issue #296 & remove unused lib
  • Loading branch information
rosona authored Dec 28, 2018
2 parents 0f33316 + c9ce9f9 commit e80a036
Show file tree
Hide file tree
Showing 51 changed files with 138 additions and 424 deletions.
8 changes: 1 addition & 7 deletions AElf.ABI.CSharp.Tests/ABITest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.IO;
using ServiceStack;
using Google.Protobuf;
using AElf.ABI.CSharp;
using Xunit;
Expand Down Expand Up @@ -30,12 +29,7 @@ public void Test()

public static byte[] GetCode(string filePath)
{
byte[] code;
using (var file = File.OpenRead(Path.GetFullPath(filePath)))
{
code = file.ReadFully();
}
return code;
return File.ReadAllBytes(Path.GetFullPath(filePath));
}
}
}
1 change: 0 additions & 1 deletion AElf.ABI.CSharp.Tests/AElf.ABI.CSharp.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
<PackageReference Include="xunit.frameworks.autofac" Version="0.1.0" />
<PackageReference Include="xunit.runner.console" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<PackageReference Include="ServiceStack" Version="5.1.0" />
<PackageReference Include="Google.Protobuf" Version="3.6.0" />
</ItemGroup>
<ItemGroup>
Expand Down
3 changes: 1 addition & 2 deletions AElf.Benchmark/AElf.Benchmark.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
<ProjectReference Include="..\AElf.Contracts.Genesis\AElf.Contracts.Genesis.csproj" />
<ProjectReference Include="..\AElf.Execution\AElf.Execution.csproj" />
<ProjectReference Include="..\AElf.Kernel\AElf.Kernel.csproj" />
<ProjectReference Include="..\AElf.Runtime.CSharp\AElf.Runtime.CSharp.csproj"/>
<ProjectReference Include="..\AElf.Runtime.CSharp\AElf.Runtime.CSharp.csproj" />
<ProjectReference Include="..\AElf.Sdk.CSharp\AElf.Sdk.CSharp.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.3.0" />
<PackageReference Include="ServiceStack" Version="5.1.0" />
</ItemGroup>
</Project>
21 changes: 19 additions & 2 deletions AElf.Benchmark/BenchmarkOptions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System.Collections.Generic;
using AElf.Database;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CommandLine;
using Newtonsoft.Json;

namespace AElf.Benchmark
{
Expand All @@ -9,6 +12,7 @@ public enum BenchmarkMethod
EvenGroup,
GenerateAccounts
}

public class BenchmarkOptions
{
[Option(HelpText = "The directory where store the sdk dll file (usually named AElf.Sdk.CSharp.dll).")]
Expand Down Expand Up @@ -56,5 +60,18 @@ public BenchmarkMethod BenchmarkMethod
return BenchmarkMethod.EvenGroup;
}
}

public override string ToString()
{
var options = new StringBuilder();
var json = JsonConvert.SerializeObject(this);
var dictionary = JsonConvert.DeserializeObject<Dictionary<string, object>>(json);
foreach (var (key, value) in dictionary)
{
options.Append($"{key}: {value}{Environment.NewLine}");
}

return options.ToString().TrimEnd(Environment.NewLine.ToCharArray());
}
}
}
28 changes: 3 additions & 25 deletions AElf.Benchmark/BenchmarkTps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@
using AElf.ChainController;
using AElf.SmartContract;
using AElf.Execution;
using AElf.Execution.Scheduling;
using AElf.Types.CSharp;
using Google.Protobuf;
using NLog;
using ServiceStack;
using ServiceStack.Text;
using AElf.Common;
using AElf.Execution.Execution;

Expand All @@ -38,18 +35,7 @@ public class Benchmarks
private Hash ChainId { get; }
private int _incrementId;

public byte[] SmartContractZeroCode
{
get
{
byte[] code;
using (FileStream file = File.OpenRead(Path.GetFullPath(Path.Combine(_options.DllDir, _options.ZeroContractDll))))
{
code = file.ReadFully();
}
return code;
}
}
public byte[] SmartContractZeroCode => File.ReadAllBytes(Path.GetFullPath(Path.Combine(_options.DllDir, _options.ZeroContractDll)));

public Benchmarks(IStateManager stateManager, IChainCreationService chainCreationService,
IChainContextService chainContextService, ISmartContractService smartContractService,
Expand All @@ -73,17 +59,10 @@ public Benchmarks(IStateManager stateManager, IChainCreationService chainCreatio
};

_dataGenerater = new TransactionDataGenerator(options);
byte[] code;
using (FileStream file = File.OpenRead(Path.GetFullPath(options.DllDir + "/" + options.ContractDll)))
{
code = file.ReadFully();
}
var code = File.ReadAllBytes(Path.GetFullPath(options.DllDir + "/" + options.ContractDll));
_contractHash = Prepare(code).Result;

}



public async Task BenchmarkEvenGroup()
{
var resDict = new Dictionary<string, double>();
Expand All @@ -96,8 +75,7 @@ public async Task BenchmarkEvenGroup()
resDict.Add(res.Key, res.Value);
}

_logger.Info("Benchmark report \n \t Configuration: \n" +
string.Join("\n", _options.ToStringDictionary().Select(option => string.Format("\t {0} - {1}", option.Key, option.Value))) +
_logger.Info("Benchmark report \n \t Configuration: \n" + _options +
"\n\n\n\t Benchmark result:\n" + string.Join("\n", resDict.Select(kv=> "\t" + kv.Key + ": " + kv.Value)));
}
catch (Exception e)
Expand Down
5 changes: 2 additions & 3 deletions AElf.Benchmark/TransactionDataGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using Akka.Util.Internal.Collections;
using Google.Protobuf;
using Org.BouncyCastle.Security;
using ServiceStack;

namespace AElf.Benchmark
{
Expand Down Expand Up @@ -161,8 +160,8 @@ public bool ReadFromFile(string path)
}

var sr = new StreamReader(filePath);
_maxTxNumber = sr.ReadLine().ToInt();
_maxGroupNumber = sr.ReadLine().ToInt();
_maxTxNumber = int.Parse(sr.ReadLine());
_maxGroupNumber = int.Parse(sr.ReadLine());

if (_maxGroupNumber <= 0 || _maxTxNumber <= 0 || _maxTxNumber < _maxGroupNumber)
{
Expand Down
2 changes: 1 addition & 1 deletion AElf.CLI2/aelf-sdk
1 change: 0 additions & 1 deletion AElf.ChainController.Rpc/AElf.ChainController.Rpc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<PackageReference Include="Google.Protobuf" Version="3.6.0" />
<PackageReference Include="Easy.MessageHub" Version="3.4.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
<PackageReference Include="ServiceStack" Version="5.1.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AElf.ChainController\AElf.ChainController.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using Google.Protobuf;
using Google.Protobuf.WellKnownTypes;
using NLog;
using ServiceStack;

// ReSharper disable once CheckNamespace
namespace AElf.ChainController
Expand Down
5 changes: 5 additions & 0 deletions AElf.Common/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,10 @@ public static byte[] DecodeBase58(this string value)
{
return Base58CheckEncoding.DecodePlain(value);
}

public static bool IsNullOrEmpty(this string value)
{
return string.IsNullOrEmpty(value);
}
}
}
9 changes: 1 addition & 8 deletions AElf.Contracts.Authorization.Tests/AuthorizationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
using AElf.Kernel.Types.Transaction;
using AElf.Types.CSharp;
using Google.Protobuf;
using Google.Protobuf.WellKnownTypes;
using NLog;
using ServiceStack;
using Xunit;
using Xunit.Frameworks.Autofac;

Expand Down Expand Up @@ -404,11 +401,7 @@ public void Release()

private Transaction CreateDemoTxn(Address msig)
{
byte[] code;
using (var file = File.OpenRead(Path.GetFullPath("../../../../AElf.Contracts.Token/bin/Debug/netstandard2.0/AElf.Contracts.Token.dll")))
{
code = file.ReadFully();
}
var code = File.ReadAllBytes(Path.GetFullPath("../../../../AElf.Contracts.Token/bin/Debug/netstandard2.0/AElf.Contracts.Token.dll"));
var tx = new Transaction
{
From = msig,
Expand Down
26 changes: 5 additions & 21 deletions AElf.Contracts.Authorization.Tests/MockSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@
using AElf.Kernel;
using AElf.SmartContract;
using Google.Protobuf;
using ServiceStack;
using AElf.Common;
using AElf.Database;
using AElf.Common;
using AElf.Kernel.Managers;
using AElf.Runtime.CSharp;
using AElf.SmartContract.Metadata;
using NLog;

namespace AElf.Contracts.Authorization.Tests
Expand Down Expand Up @@ -84,30 +81,17 @@ public byte[] AuthorizationCode
{
get
{
byte[] code = null;
using (FileStream file = File.OpenRead(Path.GetFullPath(
"../../../../AElf.Contracts.Authorization/bin/Debug/netstandard2.0/AElf.Contracts.Authorization.dll"))
)
{
code = file.ReadFully();
}

return code;
var filePath = Path.GetFullPath("../../../../AElf.Contracts.Authorization/bin/Debug/netstandard2.0/AElf.Contracts.Authorization.dll");
return File.ReadAllBytes(filePath);
}
}

public byte[] SCZeroContractCode
{
get
{
byte[] code = null;
using (FileStream file = File.OpenRead(Path.GetFullPath(
"../../../../AElf.Contracts.Genesis/bin/Debug/netstandard2.0/AElf.Contracts.Genesis.dll")))
{
code = file.ReadFully();
}

return code;
var filePath = Path.GetFullPath("../../../../AElf.Contracts.Genesis/bin/Debug/netstandard2.0/AElf.Contracts.Genesis.dll");
return File.ReadAllBytes(filePath);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
Expand All @@ -8,7 +8,6 @@
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="Moq" Version="4.10.1" />
<PackageReference Include="ServiceStack" Version="5.4.0" />
<PackageReference Include="Shouldly" Version="3.0.2" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.frameworks.autofac" Version="0.1.0" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.IO;
using System.Linq;
using AElf.Kernel;
using ServiceStack;
using Google.Protobuf;
using AElf.SmartContract;
using AElf.Types.CSharp;
Expand Down
11 changes: 1 addition & 10 deletions AElf.Contracts.Consensus.Tests/MockSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using AElf.ChainController;
using AElf.SmartContract;
using Google.Protobuf;
using ServiceStack;
using AElf.Common;
using AElf.Kernel.Managers;

Expand Down Expand Up @@ -52,15 +51,7 @@ public MockSetup(IStateManager stateManager, ISmartContractService smartContract

public byte[] GetContractCode(string contractName)
{
byte[] code;
using (var file =
File.OpenRead(
Path.GetFullPath($"../../../../{contractName}/bin/Debug/netstandard2.0/{contractName}.dll")))
{
code = file.ReadFully();
}

return code;
return File.ReadAllBytes(Path.GetFullPath($"../../../../{contractName}/bin/Debug/netstandard2.0/{contractName}.dll"));
}

private async Task Init()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@
<PackageReference Include="xunit.frameworks.autofac" Version="0.1.0" />
<PackageReference Include="xunit.runner.console" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<PackageReference Include="ServiceStack" Version="5.1.0" />
</ItemGroup>
</Project>
19 changes: 4 additions & 15 deletions AElf.Contracts.Genesis.Tests/ContractZeroTest.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
using System.IO;
using AElf.Kernel;
using AElf.SmartContract;
using AElf.Types.CSharp;
using Xunit.Frameworks.Autofac;
using Xunit;
using ServiceStack;
using AElf.Common;
using Google.Protobuf;

namespace AElf.Contracts.Genesis.Tests
{
Expand All @@ -21,24 +18,16 @@ private byte[] Code
{
get
{
byte[] code;
using (var file = File.OpenRead(Path.GetFullPath("../../../../AElf.Contracts.Token/bin/Debug/netstandard2.0/AElf.Contracts.Token.dll")))
{
code = file.ReadFully();
}
return code;
var filePath = Path.GetFullPath("../../../../AElf.Contracts.Token/bin/Debug/netstandard2.0/AElf.Contracts.Token.dll");
return File.ReadAllBytes(filePath);
}
}
private byte[] CodeNew
{
get
{
byte[] code;
using (var file = File.OpenRead(Path.GetFullPath("../../../../AElf.Benchmark.TestContract/bin/Debug/netstandard2.0/AElf.Benchmark.TestContract.dll")))
{
code = file.ReadFully();
}
return code;
var filePath = Path.GetFullPath("../../../../AElf.Benchmark.TestContract/bin/Debug/netstandard2.0/AElf.Benchmark.TestContract.dll");
return File.ReadAllBytes(filePath);
}
}

Expand Down
17 changes: 3 additions & 14 deletions AElf.Contracts.Genesis.Tests/MockSetup.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Reflection;
using AElf.Kernel;
using AElf.ChainController;
using AElf.SmartContract;
using AElf.Kernel.KernelAccount;
using AElf.Kernel.Managers;
using AElf.Execution;
using Google.Protobuf;
using ServiceStack;
using AElf.Common;
using AElf.Execution.Execution;

Expand Down Expand Up @@ -74,12 +67,8 @@ private byte[] SmartContractZeroCode
{
get
{
byte[] code;
using (var file = File.OpenRead(Path.GetFullPath("../../../../AElf.Contracts.Genesis/bin/Debug/netstandard2.0/AElf.Contracts.Genesis.dll")))
{
code = file.ReadFully();
}
return code;
var filePath = Path.GetFullPath("../../../../AElf.Contracts.Genesis/bin/Debug/netstandard2.0/AElf.Contracts.Genesis.dll");
return File.ReadAllBytes(filePath);
}
}

Expand Down
Loading

0 comments on commit e80a036

Please sign in to comment.