Skip to content
Permalink
Browse files

Apply lints to Libplanet.Tests project

  • Loading branch information...
dahlia committed Jun 29, 2019
1 parent f3689da commit 9a5617ab4dd9449b62a4beedcbccb28e811fedf5
@@ -26,7 +26,10 @@ public void CanMine()
Assert.Equal(0, _fx.Genesis.Index);
Assert.Equal(0, _fx.Genesis.Difficulty);
Assert.Null(_fx.Genesis.PreviousHash);
Assert.Equal(new DateTimeOffset(2018, 11, 29, 0, 0, 0, TimeSpan.Zero), _fx.Genesis.Timestamp);
Assert.Equal(
new DateTimeOffset(2018, 11, 29, 0, 0, 0, TimeSpan.Zero),
_fx.Genesis.Timestamp
);
Assert.Equal(
new Address("21744f4f08db23e044178dafb8273aeb5ebe6644"),
_fx.Genesis.Miner);
@@ -49,7 +52,10 @@ public void CanMine()
Assert.Equal(1, _fx.Next.Index);
Assert.Equal(1, _fx.Next.Difficulty);
Assert.Equal(_fx.Genesis.Hash, _fx.Next.PreviousHash);
Assert.Equal(new DateTimeOffset(2018, 11, 30, 0, 0, 0, TimeSpan.Zero), _fx.Next.Timestamp);
Assert.Equal(
new DateTimeOffset(2018, 11, 30, 0, 0, 0, TimeSpan.Zero),
_fx.Next.Timestamp
);
Assert.Equal(
new Address("21744f4f08db23e044178dafb8273aeb5ebe6644"),
_fx.Next.Miner);
@@ -186,11 +192,7 @@ public void EvaluateActionsPerTx()
Transaction<DumbAction>.Create(
0,
_fx.TxFixture.PrivateKey1,
new[]
{
MakeAction(addresses[0], 'A'),
MakeAction(addresses[1], 'B'),
}
new[] { MakeAction(addresses[0], 'A'), MakeAction(addresses[1], 'B') }
),
Transaction<DumbAction>.Create(
0,
@@ -216,10 +218,7 @@ public void EvaluateActionsPerTx()
{
ActionEvaluation<DumbAction> eval = pair.Item2;
Assert.Equal(blockIdx1Txs[expect.Item1], pair.Item1);
Assert.Equal(
blockIdx1Txs[expect.Item1].Actions[expect.Item2],
eval.Action
);
Assert.Equal(blockIdx1Txs[expect.Item1].Actions[expect.Item2], eval.Action);
Assert.Equal(expect.Item4, eval.InputContext.Signer);
Assert.Equal(GenesisMinerAddress, eval.InputContext.Miner);
Assert.Equal(blockIdx1.Index, eval.InputContext.BlockIndex);
@@ -231,10 +230,7 @@ public void EvaluateActionsPerTx()
),
randomValue
);
Assert.Equal(
expect.Item3,
addresses.Select(eval.OutputStates.GetState)
);
Assert.Equal(expect.Item3, addresses.Select(eval.OutputStates.GetState));
}

IImmutableDictionary<Address, object> dirty1 = blockIdx1
@@ -289,12 +285,15 @@ public void EvaluateActionsPerTx()
{
(0, 0, new[] { "A,D", "B", "C", null, null }, _fx.TxFixture.Address1),
(1, 0, new[] { "A,D", "B", "C", "E", null }, _fx.TxFixture.Address2),
(2, 0, new[] { "A,D", "B", "C", "E", "RecordRehearsal:False" }, _fx.TxFixture.Address3),
(
2,
0,
new[] { "A,D", "B", "C", "E", "RecordRehearsal:False" },
_fx.TxFixture.Address3
),
};
Assert.Equal(expectations.Length, pairs.Length);
foreach (
var (expect, pair) in expectations.Zip(pairs, ValueTuple.Create)
)
foreach (var (expect, pair) in expectations.Zip(pairs, ValueTuple.Create))
{
ActionEvaluation<DumbAction> eval = pair.Item2;
Assert.Equal(blockIdx2Txs[expect.Item1], pair.Item1);
@@ -313,10 +312,7 @@ public void EvaluateActionsPerTx()
),
randomValue
);
Assert.Equal(
expect.Item3,
addresses.Select(eval.OutputStates.GetState)
);
Assert.Equal(expect.Item3, addresses.Select(eval.OutputStates.GetState));
}

IImmutableDictionary<Address, object> dirty2 = blockIdx2
@@ -4,6 +4,8 @@
using Libplanet.Crypto;
using Xunit;

using static Libplanet.Tests.TestUtils;

namespace Libplanet.Tests.Crypto
{
public class SymmetricKeyTest
@@ -19,8 +21,14 @@ public class SymmetricKeyTest
[Fact]
public void DecryptTest()
{
var ciphertext = ByteUtil.ParseHex(
"1881342a2930cdc2734ae15e143a09fe5b0a5f113b0e2fcfc8d56f23c508a2890d7139c592cf4e4c76758a9b2317cb94");
byte[] ciphertext =
{
0x18, 0x81, 0x34, 0x2a, 0x29, 0x30, 0xcd, 0xc2, 0x73, 0x4a,
0xe1, 0x5e, 0x14, 0x3a, 0x09, 0xfe, 0x5b, 0x0a, 0x5f, 0x11,
0x3b, 0x0e, 0x2f, 0xcf, 0xc8, 0xd5, 0x6f, 0x23, 0xc5, 0x08,
0xa2, 0x89, 0x0d, 0x71, 0x39, 0xc5, 0x92, 0xcf, 0x4e, 0x4c,
0x76, 0x75, 0x8a, 0x9b, 0x23, 0x17, 0xcb, 0x94,
};
var expected = Encoding.ASCII.GetBytes("a secret message");
var aes = new SymmetricKey(KeyBytes);
var actual = aes.Decrypt(ciphertext);
@@ -8,8 +8,16 @@
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<IsTestProject>true</IsTestProject>
<LangVersion>7.1</LangVersion>
<CodeAnalysisRuleSet>..\Libplanet.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>

<ItemGroup>
<AdditionalFiles Include="..\Menees.Analyzers.Settings.xml">
<Link>Menees.Analyzers.Settings.xml</Link>
</AdditionalFiles>
<AdditionalFiles Include="..\stylecop.json" />
</ItemGroup>

<PropertyGroup Condition=" '$(MSBuildRuntimeType)'=='Mono' And
'$(BuildingByReSharper)'!='true'">
<TargetFramework>net461</TargetFramework>
@@ -20,6 +28,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Menees.Analyzers.2017" Version="2.0.3">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.1.0" />
<PackageReference Include="Serilog.Enrichers.Thread" Version="3.0.0" />
<PackageReference Include="Serilog.Sinks.XUnit" Version="1.0.7" />
@@ -39,10 +39,12 @@ public class SwarmTest : IDisposable

public SwarmTest(ITestOutputHelper output)
{
const string outputTemplate =
"{Timestamp:HH:mm:ss}[@{SwarmId}][{ThreadId}] - {Message}";
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.Enrich.WithThreadId()
.WriteTo.TestOutput(output, outputTemplate: "{Timestamp:HH:mm:ss}[@{SwarmId}][{ThreadId}] - {Message}")
.WriteTo.TestOutput(output, outputTemplate: outputTemplate)
.CreateLogger()
.ForContext<SwarmTest>();

@@ -249,9 +251,18 @@ public async Task CanExchangePeer()
await EnsureExchange(a, c);
await EnsureExchange(a, b);

Assert.Equal(new[] { b.AsPeer, c.AsPeer }.ToImmutableHashSet(), a.ToImmutableHashSet());
Assert.Equal(new[] { a.AsPeer, c.AsPeer }.ToImmutableHashSet(), b.ToImmutableHashSet());
Assert.Equal(new[] { a.AsPeer, b.AsPeer }.ToImmutableHashSet(), c.ToImmutableHashSet());
Assert.Equal(
new[] { b.AsPeer, c.AsPeer }.ToImmutableHashSet(),
a.ToImmutableHashSet()
);
Assert.Equal(
new[] { a.AsPeer, c.AsPeer }.ToImmutableHashSet(),
b.ToImmutableHashSet()
);
Assert.Equal(
new[] { a.AsPeer, b.AsPeer }.ToImmutableHashSet(),
c.ToImmutableHashSet()
);

lastDistA = a.LastDistributed;
aAsPeer = a.AsPeer;
@@ -963,7 +974,11 @@ public async Task Preload()
return task;
}

private async Task EnsureRecvAsync(Swarm swarm, Peer peer = null, DateTimeOffset? lastReceived = null)
private async Task EnsureRecvAsync(
Swarm swarm,
Peer peer = null,
DateTimeOffset? lastReceived = null
)
{
Log.Debug($"Waiting to ensure recv... [{swarm.AsPeer}]");
while (true)
@@ -29,7 +29,12 @@ public FileStoreTest()
public void ReturnTransactionPath()
{
Assert.Equal(
Path.Combine(_fx.Path, "tx", "45a2", "2187e2d8850bb357886958bc3e8560929ccc886958bc3e8560929ccc9ccc"),
Path.Combine(
_fx.Path,
"tx",
"45a2",
"2187e2d8850bb357886958bc3e8560929ccc886958bc3e8560929ccc9ccc"
),
_fileStore.GetTransactionPath(_fx.TxId1)
);
}
@@ -38,7 +43,12 @@ public void ReturnTransactionPath()
public void ReturnBlockPath()
{
Assert.Equal(
Path.Combine(_fx.Path, "blocks", "45a2", "2187e2d8850bb357886958bc3e8560929ccc886958bc3e8560929ccc9ccc"),
Path.Combine(
_fx.Path,
"blocks",
"45a2",
"2187e2d8850bb357886958bc3e8560929ccc886958bc3e8560929ccc9ccc"
),
_fileStore.GetBlockPath(_fx.Hash1)
);
}
@@ -47,7 +57,11 @@ public void ReturnBlockPath()
public void ReturnStagedTransactionPath()
{
Assert.Equal(
Path.Combine(_fx.Path, "stage", "45a22187e2d8850bb357886958bc3e8560929ccc886958bc3e8560929ccc9ccc"),
Path.Combine(
_fx.Path,
"stage",
"45a22187e2d8850bb357886958bc3e8560929ccc886958bc3e8560929ccc9ccc"
),
_fileStore.GetStagedTransactionPath(_fx.TxId1)
);
}
@@ -63,7 +77,12 @@ public void ReturnStatesPath()
0x9c, 0xcc,
});
Assert.Equal(
Path.Combine(_fx.Path, "states", "45a2", "2187e2d8850bb357886958bc3e8560929ccc886958bc3e8560929ccc9ccc"),
Path.Combine(
_fx.Path,
"states",
"45a2",
"2187e2d8850bb357886958bc3e8560929ccc886958bc3e8560929ccc9ccc"
),
_fileStore.GetStatesPath(hash)
);
}
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?>
<Menees.Analyzers.Settings>
<MaxLineColumns>100</MaxLineColumns>
<MaxMethodLines>200</MaxMethodLines>
</Menees.Analyzers.Settings>

0 comments on commit 9a5617a

Please sign in to comment.
You can’t perform that action at this time.