Skip to content

Commit

Permalink
fix the serialisation of the hash, add test (stratisproject#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
monsieurleberre authored Nov 12, 2018
1 parent 0f0e080 commit 15660b2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
using NBitcoin;
using Newtonsoft.Json;
using Stratis.Bitcoin.Utilities;
using Stratis.Bitcoin.Utilities.JsonConverters;

namespace Stratis.FederatedPeg.Features.FederationGateway.Interfaces
{
public interface IBlockTip
{
[JsonConverter(typeof(UInt256JsonConverter))]
uint256 Hash { get; }

int Height { get; }
Expand Down
36 changes: 36 additions & 0 deletions src/Stratis.FederatedPeg.Tests/BlockTipModelTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Text;
using FluentAssertions;
using Newtonsoft.Json;
using Stratis.FederatedPeg.Features.FederationGateway.Interfaces;
using Stratis.FederatedPeg.Features.FederationGateway.Models;
using Stratis.FederatedPeg.Tests.Utils;
using Xunit;

namespace Stratis.FederatedPeg.Tests
{
public class BlockTipModelTests
{
public static IBlockTip PrepareBlockTip()
{
var blockHash = TestingValues.GetUint256();
var blockHeight = TestingValues.GetPositiveInt();

var blockTip = new BlockTipModel(blockHash, blockHeight);
return blockTip;
}

[Fact]
public void ShouldSerialiseAsJson()
{
var blockTip = PrepareBlockTip();
var asJson = blockTip.ToString();

var reconverted = JsonConvert.DeserializeObject<BlockTipModel>(asJson);

reconverted.Hash.Should().Be(blockTip.Hash);
reconverted.Height.Should().Be(blockTip.Height);
}
}
}

0 comments on commit 15660b2

Please sign in to comment.