diff --git a/src/Stratis.FederatedPeg.Features.FederationGateway/Interfaces/IBlockTip.cs b/src/Stratis.FederatedPeg.Features.FederationGateway/Interfaces/IBlockTip.cs index b9787ad8b9d..222a4b2dd44 100644 --- a/src/Stratis.FederatedPeg.Features.FederationGateway/Interfaces/IBlockTip.cs +++ b/src/Stratis.FederatedPeg.Features.FederationGateway/Interfaces/IBlockTip.cs @@ -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; } diff --git a/src/Stratis.FederatedPeg.Tests/BlockTipModelTests.cs b/src/Stratis.FederatedPeg.Tests/BlockTipModelTests.cs new file mode 100644 index 00000000000..7d7c2dc1197 --- /dev/null +++ b/src/Stratis.FederatedPeg.Tests/BlockTipModelTests.cs @@ -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(asJson); + + reconverted.Hash.Should().Be(blockTip.Hash); + reconverted.Height.Should().Be(blockTip.Height); + } + } +}