< Summary - Combined Code Coverage

Information
Class: NLightning.Bolt11.Models.TaggedFields.PayeePubKeyTaggedField
Assembly: NLightning.Bolt11
File(s): /home/runner/work/nlightning/nlightning/src/NLightning.Bolt11/Models/TaggedFields/PayeePubKeyTaggedField.cs
Tag: 49_19945309242
Line coverage
100%
Covered lines: 16
Uncovered lines: 0
Coverable lines: 16
Total lines: 68
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/PayeePubKeyTaggedField.cs

#LineLine coverage
 1using NBitcoin;
 2
 3namespace NLightning.Bolt11.Models.TaggedFields;
 4
 5using Constants;
 6using Domain.Utils;
 7using Enums;
 8using Interfaces;
 9
 10/// <summary>
 11/// Tagged field for the payee public key
 12/// </summary>
 13/// <remarks>
 14/// The payee public key is a 33-byte public key used to identify the payee
 15/// </remarks>
 16/// <seealso cref="ITaggedField"/>
 17internal sealed class PayeePubKeyTaggedField : ITaggedField
 18{
 51619    public TaggedFieldTypes Type => TaggedFieldTypes.PayeePubKey;
 12020    internal PubKey Value { get; }
 9621    public short Length => TaggedFieldConstants.PayeePubkeyLength;
 22
 23    /// <summary>
 24    /// Initializes a new instance of the <see cref="ExpiryTimeTaggedField"/> class.
 25    /// </summary>
 26    /// <param name="value">The Expiry Time in seconds</param>
 12827    internal PayeePubKeyTaggedField(PubKey value)
 28    {
 12829        Value = value;
 12830    }
 31
 32    /// <inheritdoc/>
 33    public void WriteToBitWriter(BitWriter bitWriter)
 34    {
 35        // Write data
 3236        bitWriter.WriteBits(Value.ToBytes(), Length * 5);
 3237    }
 38
 39    /// <inheritdoc/>
 40    public bool IsValid()
 41    {
 6842        return true;
 43    }
 44
 45    /// <summary>
 46    /// Reads a PayeePubKeyTaggedField from a BitReader
 47    /// </summary>
 48    /// <param name="bitReader">The BitReader to read from</param>
 49    /// <param name="length">The length of the field</param>
 50    /// <returns>The PayeePubKeyTaggedField</returns>
 51    /// <exception cref="ArgumentException">Thrown when the length is invalid</exception>
 52    internal static PayeePubKeyTaggedField FromBitReader(BitReader bitReader, short length)
 53    {
 3254        if (length != TaggedFieldConstants.PayeePubkeyLength)
 455            throw new ArgumentException(
 456                $"Invalid length for {nameof(PayeePubKeyTaggedField)}. Expected {TaggedFieldConstants.PayeePubkeyLength}
 57
 58        // Read the data from the BitReader
 59        // For 53 groups of 5 bits = 265 bits, we need 34 bytes to read, with one padding byte
 2860        var data = new byte[(length * 5 + 7) / 8];
 2861        bitReader.ReadBits(data, length * 5);
 62
 63        // Remove the padding byte
 2864        data = data[..^1];
 65
 2866        return new PayeePubKeyTaggedField(new PubKey(data));
 67    }
 68}