< Summary - Combined Code Coverage

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

File(s)

/home/runner/work/nlightning/nlightning/src/NLightning.Bolt11/Models/TaggedFields/ExpiryTimeTaggedField.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 expiry time
 11/// </summary>
 12/// <remarks>
 13/// The expiry time is the time in seconds after which the invoice is invalid.
 14/// </remarks>
 15/// <seealso cref="ITaggedField"/>
 16public sealed class ExpiryTimeTaggedField : ITaggedField
 17{
 32018    public TaggedFieldTypes Type => TaggedFieldTypes.EXPIRY_TIME;
 21219    internal int Value { get; }
 9620    public short Length { get; }
 21
 22    /// <summary>
 23    /// Initializes a new instance of the <see cref="ExpiryTimeTaggedField"/> class.
 24    /// </summary>
 25    /// <param name="value">The Expiry Time in seconds</param>
 10026    internal ExpiryTimeTaggedField(int value)
 27    {
 10028        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
 10031        Length = (short)((BitOperations.Log2((uint)Value) + 1 + 4) / 5);
 10032    }
 33
 34    /// <inheritdoc/>
 35    public void WriteToBitWriter(BitWriter bitWriter)
 36    {
 37        // Write data
 3238        bitWriter.WriteInt32AsBits(Value, Length * 5);
 3239    }
 40
 41    /// <inheritdoc/>
 42    public bool IsValid()
 43    {
 2444        return Value > 0;
 45    }
 46
 47    /// <summary>
 48    /// Reads a ExpiryTimeTaggedField 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 ExpiryTimeTaggedField</returns>
 53    /// <exception cref="ArgumentException">Thrown when the length is invalid</exception>
 54    internal static ExpiryTimeTaggedField FromBitReader(BitReader bitReader, short length)
 55    {
 4056        if (length <= 0)
 57        {
 458            throw new ArgumentException("Invalid length for ExpiryTimeTaggedField. Length must be greater than 0", nameo
 59        }
 60
 61        // Read the data from the BitReader
 3662        var value = bitReader.ReadInt32FromBits(length * 5);
 63
 3664        return new ExpiryTimeTaggedField(value);
 65    }
 66}