< Summary - Combined Code Coverage

Information
Class: NLightning.Bolt11.Models.TaggedFields.PaymentSecretTaggedField
Assembly: NLightning.Bolt11
File(s): /home/runner/work/nlightning/nlightning/src/NLightning.Bolt11/Models/TaggedFields/PaymentSecretTaggedField.cs
Tag: 30_15166811759
Line coverage
95%
Covered lines: 19
Uncovered lines: 1
Coverable lines: 20
Total lines: 77
Line coverage: 95%
Branch coverage
83%
Covered branches: 5
Total branches: 6
Branch coverage: 83.3%
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(...)75%4.03487.5%

File(s)

/home/runner/work/nlightning/nlightning/src/NLightning.Bolt11/Models/TaggedFields/PaymentSecretTaggedField.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 payment secret
 12/// </summary>
 13/// <remarks>
 14/// The payment secret is a 32 byte secret that is used to identify a payment
 15/// </remarks>
 16/// <seealso cref="ITaggedField"/>
 17internal sealed class PaymentSecretTaggedField : ITaggedField
 18{
 144419    public TaggedFieldTypes Type => TaggedFieldTypes.PAYMENT_SECRET;
 17620    internal uint256 Value { get; }
 16821    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>
 16427    internal PaymentSecretTaggedField(uint256 value)
 28    {
 16429        Value = value;
 16430    }
 31
 32    /// <inheritdoc/>
 33    public void WriteToBitWriter(BitWriter bitWriter)
 34    {
 5635        var data = Value.ToBytes();
 5636        if (BitConverter.IsLittleEndian)
 37        {
 5638            Array.Reverse(data);
 39        }
 40
 41        // Write data
 5642        bitWriter.WriteBits(data, Length * 5);
 5643    }
 44
 45    /// <inheritdoc/>
 46    public bool IsValid()
 47    {
 6448        return Value != uint256.Zero;
 49    }
 50
 51    /// <summary>
 52    /// Reads a PaymentSecretTaggedField 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 PaymentSecretTaggedField</returns>
 57    /// <exception cref="ArgumentException">Thrown when the length is invalid</exception>
 58    internal static PaymentSecretTaggedField FromBitReader(BitReader bitReader, short length)
 59    {
 6460        if (length != TaggedFieldConstants.HASH_LENGTH)
 61        {
 062            throw new ArgumentException($"Invalid length for PaymentSecretTaggedField. Expected {TaggedFieldConstants.HA
 63        }
 64
 65        // Read the data from the BitReader
 6466        var data = new byte[(TaggedFieldConstants.HASH_LENGTH * 5 + 7) / 8];
 6467        bitReader.ReadBits(data, length * 5);
 6468        data = data[..^1];
 69
 6470        if (BitConverter.IsLittleEndian)
 71        {
 6472            Array.Reverse(data);
 73        }
 74
 6475        return new PaymentSecretTaggedField(new uint256(data));
 76    }
 77}