< Summary - Combined Code Coverage

Information
Class: NLightning.Domain.Crypto.ValueObjects.CompactPubKey
Assembly: NLightning.Domain
File(s): /home/runner/work/nlightning/nlightning/src/NLightning.Domain/Crypto/ValueObjects/CompactPubKey.cs
Tag: 36_15743069263
Line coverage
65%
Covered lines: 15
Uncovered lines: 8
Coverable lines: 23
Total lines: 67
Line coverage: 65.2%
Branch coverage
55%
Covered branches: 10
Total branches: 18
Branch coverage: 55.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)66.67%8.83657.14%
op_Implicit(...)100%11100%
op_Implicit(...)100%11100%
op_Implicit(...)100%11100%
op_Implicit(...)100%11100%
op_Inequality(...)100%210%
op_Equality(...)100%210%
ToString()100%11100%
Equals(...)50%12.1860%
Equals(...)50%4.59466.67%
GetHashCode()100%11100%

File(s)

/home/runner/work/nlightning/nlightning/src/NLightning.Domain/Crypto/ValueObjects/CompactPubKey.cs

#LineLine coverage
 1namespace NLightning.Domain.Crypto.ValueObjects;
 2
 3using Constants;
 4using Utils.Extensions;
 5
 6public readonly struct CompactPubKey : IEquatable<CompactPubKey>
 7{
 8    private readonly byte[] _value;
 9
 10    public CompactPubKey(byte[] value)
 11    {
 233212        if (value.Length != CryptoConstants.CompactPubkeyLen)
 013            throw new ArgumentException("PublicKey cannot be empty.", nameof(value));
 14
 233215        if (value[0] != 0x02 && value[0] != 0x03)
 016            throw new ArgumentException("Invalid CompactPubKey format. The first byte must be 0x02 or 0x03.",
 017                                        nameof(value));
 18
 233219        _value = value;
 233220    }
 21
 190422    public static implicit operator CompactPubKey(byte[] bytes) => new(bytes);
 108023    public static implicit operator byte[](CompactPubKey hash) => hash._value;
 24
 72825    public static implicit operator ReadOnlySpan<byte>(CompactPubKey compactPubKey) => compactPubKey._value;
 26
 12427    public static implicit operator ReadOnlyMemory<byte>(CompactPubKey compactPubKey) => compactPubKey._value;
 28
 29    public static bool operator !=(CompactPubKey left, CompactPubKey right)
 30    {
 031        return !left.Equals(right);
 32    }
 33
 34    public static bool operator ==(CompactPubKey left, CompactPubKey right)
 35    {
 036        return left.Equals(right);
 37    }
 38
 4039    public override string ToString() => Convert.ToHexString(_value).ToLowerInvariant();
 40
 41    public bool Equals(CompactPubKey other)
 42    {
 43        // Handle null cases first
 44        // ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
 12445        if (_value is null && other._value is null)
 046            return true;
 47
 48        // ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
 12449        if (_value is null || other._value is null)
 050            return false;
 51
 12452        return _value.SequenceEqual(other._value);
 53    }
 54
 55    public override bool Equals(object? obj)
 56    {
 4457        if (obj is null)
 058            return false;
 59
 4460        return obj is CompactPubKey other && Equals(other);
 61    }
 62
 63    public override int GetHashCode()
 64    {
 9665        return _value.GetByteArrayHashCode();
 66    }
 67}