Skip to content

Commit

Permalink
Merge pull request #1516 from greymistcube/hotfix/hash-algorithm-type…
Browse files Browse the repository at this point in the history
…-json-converter

Hotfix hash algorithm type json converter
  • Loading branch information
greymistcube committed Oct 8, 2021
2 parents f00e10c + c819809 commit 279076d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
14 changes: 14 additions & 0 deletions Libplanet.Extensions.Cocona.Tests/UtilsTest.cs
Expand Up @@ -2,6 +2,9 @@
using System.Collections.Immutable;
using System.Globalization;
using System.Linq;
using System.Security.Cryptography;
using Libplanet.Blocks;
using Libplanet.Tests;
using Xunit;

namespace Libplanet.Extensions.Cocona.Tests
Expand All @@ -28,6 +31,17 @@ public void TestHumanReadable()
Assert.Equal(dummyClass.SampleDateTimeOffset, dummyClass2.SampleDateTimeOffset);
}

[Fact]
public void TestHumanReadableHashAlgorithmField()
{
Block<Utils.DummyAction> genesisBlock = TestUtils.MineGenesisBlock<Utils.DummyAction>(
index => HashAlgorithmType.Of<SHA256>(), TestUtils.GenesisMiner);

// FIXME: More tests should be added once variable hash gets implemented.
Assert.Matches(
"\"HashAlgorithm\":[\\s]+\"SHA256\",", Utils.SerializeHumanReadable(genesisBlock));
}

private class DummyClass
{
public DummyClass()
Expand Down
8 changes: 4 additions & 4 deletions Libplanet.Extensions.Cocona/Utils.cs
Expand Up @@ -227,19 +227,19 @@ private class DateTimeOffsetJsonConverter : JsonConverter<DateTimeOffset>

private class HashAlgorithmTypeConverter : JsonConverter<HashAlgorithmType>
{
// FIXME: Placeholder implementation.
public override HashAlgorithmType Read(
ref Utf8JsonReader reader,
Type typeToConvert,
JsonSerializerOptions options)
=>
HashAlgorithmType.Of<SHA256>();
=> HashAlgorithmType.Of<SHA256>();

// FIXME: Placeholder implementation.
public override void Write(
Utf8JsonWriter writer,
HashAlgorithmType value,
JsonSerializerOptions options)
{
}
=> writer.WriteStringValue(nameof(SHA256));
}
}
}

0 comments on commit 279076d

Please sign in to comment.