< Summary - Combined Code Coverage

Information
Class: NLightning.Bolt11.Models.TaggedFields.MinFinalCltvExpiryTaggedField
Assembly: NLightning.Bolt11
File(s): /home/runner/work/nlightning/nlightning/src/NLightning.Bolt11/Models/TaggedFields/MinFinalCltvExpiryTaggedField.cs
Tag: 30_15166811759
Line coverage
92%
Covered lines: 13
Uncovered lines: 1
Coverable lines: 14
Total lines: 66
Line coverage: 92.8%
Branch coverage
50%
Covered branches: 1
Total branches: 2
Branch coverage: 50%
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%11100%
IsValid()100%11100%
FromBitReader(...)50%2.06275%

File(s)

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

#LineLine coverage
 1using System.Numerics;
 2
 3namespace NLightning.Bolt11.Models.TaggedFields;
 4
 5using Common.Utils;
 6using Enums;
 7using Interfaces;
 8
 9/// <summary>
 10/// Tagged field for the minimum final cltv expiry
 11/// </summary>
 12/// <remarks>
 13/// The minimum final cltv expiry is a 4 byte field that specifies the minimum number of blocks that the receiver should
 14/// </remarks>
 15/// <seealso cref="ITaggedField"/>
 16internal sealed class MinFinalCltvExpiryTaggedField : ITaggedField
 17{
 13618    public TaggedFieldTypes Type => TaggedFieldTypes.MIN_FINAL_CLTV_EXPIRY;
 10019    internal ushort Value { get; }
 7220    public short Length { get; }
 21
 22    /// <summary>
 23    /// Initializes a new instance of the <see cref="MinFinalCltvExpiryTaggedField"/> class.
 24    /// </summary>
 25    /// <param name="value">The Expiry Time in seconds</param>
 4826    internal MinFinalCltvExpiryTaggedField(ushort value)
 27    {
 4828        Value = value;
 29        // Calculate the length of the field by getting the number of bits needed to represent the value plus 1
 30        // then add 4 to round up to the next multiple of 5 and divide by 5 to get the number of bytes
 4831        Length = (short)((BitOperations.Log2(Value) + 1 + 4) / 5);
 4832    }
 33
 34    /// <inheritdoc/>
 35    public void WriteToBitWriter(BitWriter bitWriter)
 36    {
 37        // Write data
 2438        bitWriter.WriteUInt16AsBits(Value, Length * 5);
 2439    }
 40
 41    /// <inheritdoc/>
 42    public bool IsValid()
 43    {
 444        return Value > 0;
 45    }
 46
 47    /// <summary>
 48    /// Reads a MinFinalCltvExpiryTaggedField from a BitReader
 49    /// </summary>
 50    /// <param name="bitReader">The BitReader to read from</param>
 51    /// <param name="length">The length of the field</param>
 52    /// <returns>The MinFinalCltvExpiryTaggedField</returns>
 53    /// <exception cref="ArgumentException">Thrown when the length is invalid</exception>
 54    internal static MinFinalCltvExpiryTaggedField FromBitReader(BitReader bitReader, short length)
 55    {
 456        if (length <= 0)
 57        {
 058            throw new ArgumentException("Invalid length for MinFinalCltvExpiryTaggedField. Length must be greater than 0
 59        }
 60
 61        // Read the data from the BitReader
 462        var value = bitReader.ReadUInt16FromBits(length * 5);
 63
 464        return new MinFinalCltvExpiryTaggedField(value);
 65    }
 66}