< Summary - Combined Code Coverage

Information
Class: NLightning.Domain.Crypto.ValueObjects.Hash
Assembly: NLightning.Domain
File(s): /home/runner/work/nlightning/nlightning/src/NLightning.Domain/Crypto/ValueObjects/Hash.cs
Tag: 36_15743069263
Line coverage
31%
Covered lines: 6
Uncovered lines: 13
Coverable lines: 19
Total lines: 53
Line coverage: 31.5%
Branch coverage
7%
Covered branches: 1
Total branches: 14
Branch coverage: 7.1%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Empty()100%11100%
.ctor(...)50%2.26260%
op_Implicit(...)100%11100%
op_Implicit(...)100%210%
op_Implicit(...)100%11100%
ToString()100%210%
Equals(...)0%7280%
Equals(...)0%2040%
GetHashCode()100%210%

File(s)

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

#LineLine coverage
 1namespace NLightning.Domain.Crypto.ValueObjects;
 2
 3using Constants;
 4using Utils.Extensions;
 5
 6public readonly struct Hash : IEquatable<Hash>
 7{
 8    private readonly byte[] _value;
 369    public static Hash Empty => new(new byte[CryptoConstants.Sha256HashLen]);
 10
 11    public Hash(byte[] value)
 12    {
 95213        if (value.Length < CryptoConstants.Sha256HashLen)
 014            throw new ArgumentOutOfRangeException(nameof(value), value.Length,
 015                                                  $"Hash must have {CryptoConstants.Sha256HashLen} bytes.");
 16
 95217        _value = value;
 95218    }
 19
 91620    public static implicit operator Hash(byte[] bytes) => new(bytes);
 021    public static implicit operator byte[](Hash hash) => hash._value;
 22
 13223    public static implicit operator ReadOnlyMemory<byte>(Hash hash) => hash._value;
 24
 025    public override string ToString() => Convert.ToHexString(_value).ToLowerInvariant();
 26
 27    public bool Equals(Hash other)
 28    {
 29        // Handle null cases first
 30        // ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
 031        if (_value is null && other._value is null)
 032            return true;
 33
 34        // ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
 035        if (_value is null || other._value is null)
 036            return false;
 37
 038        return _value.SequenceEqual(other._value);
 39    }
 40
 41    public override bool Equals(object? obj)
 42    {
 043        if (obj is null)
 044            return false;
 45
 046        return obj is Hash other && Equals(other);
 47    }
 48
 49    public override int GetHashCode()
 50    {
 051        return _value.GetByteArrayHashCode();
 52    }
 53}