< Summary - Combined Code Coverage

Information
Class: NLightning.Bolt11.Models.TaggedFields.DescriptionHashTaggedField
Assembly: NLightning.Bolt11
File(s): /home/runner/work/nlightning/nlightning/src/NLightning.Bolt11/Models/TaggedFields/DescriptionHashTaggedField.cs
Tag: 30_15166811759
Line coverage
100%
Covered lines: 20
Uncovered lines: 0
Coverable lines: 20
Total lines: 77
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Type()100%11100%
get_Value()100%11100%
get_Length()100%11100%
.ctor(...)100%11100%
WriteToBitWriter(...)100%22100%
IsValid()100%11100%
FromBitReader(...)100%44100%

File(s)

/home/runner/work/nlightning/nlightning/src/NLightning.Bolt11/Models/TaggedFields/DescriptionHashTaggedField.cs

#LineLine coverage
 1using NBitcoin;
 2
 3namespace NLightning.Bolt11.Models.TaggedFields;
 4
 5using Common.Utils;
 6using Constants;
 7using Enums;
 8using Interfaces;
 9
 10/// <summary>
 11/// Tagged field for the description hash
 12/// </summary>
 13/// <remarks>
 14/// The description hash is a 32 byte hash that is used to identify a description
 15/// </remarks>
 16/// <seealso cref="ITaggedField"/>
 17internal sealed class DescriptionHashTaggedField : ITaggedField
 18{
 55219    public TaggedFieldTypes Type => TaggedFieldTypes.DESCRIPTION_HASH;
 9620    internal uint256 Value { get; }
 8021    public short Length => TaggedFieldConstants.HASH_LENGTH;
 22
 23    /// <summary>
 24    /// Initializes a new instance of the <see cref="DescriptionHashTaggedField"/> class.
 25    /// </summary>
 26    /// <param name="value">The Description Hash</param>
 7227    internal DescriptionHashTaggedField(uint256 value)
 28    {
 7229        Value = value;
 7230    }
 31
 32    /// <inheritdoc/>
 33    public void WriteToBitWriter(BitWriter bitWriter)
 34    {
 2835        var data = Value.ToBytes();
 2836        if (BitConverter.IsLittleEndian)
 37        {
 2838            Array.Reverse(data);
 39        }
 40
 41        // Write data
 2842        bitWriter.WriteBits(data, Length * 5);
 2843    }
 44
 45    /// <inheritdoc/>
 46    public bool IsValid()
 47    {
 3648        return Value != uint256.Zero;
 49    }
 50
 51    /// <summary>
 52    /// Reads a DescriptionHashTaggedField from a BitReader
 53    /// </summary>
 54    /// <param name="bitReader">The BitReader to read from</param>
 55    /// <param name="length">The length of the field</param>
 56    /// <returns>The DescriptionHashTaggedField</returns>
 57    /// <exception cref="ArgumentException">Thrown when the length is invalid</exception>
 58    internal static DescriptionHashTaggedField FromBitReader(BitReader bitReader, short length)
 59    {
 3660        if (length != TaggedFieldConstants.HASH_LENGTH)
 61        {
 462            throw new ArgumentException($"Invalid length for DescriptionHashTaggedField. Expected {TaggedFieldConstants.
 63        }
 64
 65        // Read the data from the BitReader
 3266        var data = new byte[(TaggedFieldConstants.HASH_LENGTH * 5 + 7) / 8];
 3267        bitReader.ReadBits(data, length * 5);
 3268        data = data[..^1];
 69
 3270        if (BitConverter.IsLittleEndian)
 71        {
 3272            Array.Reverse(data);
 73        }
 74
 3275        return new DescriptionHashTaggedField(new uint256(data));
 76    }
 77}