< 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: 57_24045730253
Line coverage
20%
Covered lines: 6
Uncovered lines: 23
Coverable lines: 29
Total lines: 64
Line coverage: 20.6%
Branch coverage
3%
Covered branches: 1
Total branches: 26
Branch coverage: 3.8%
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%
op_Implicit(...)100%210%
ToString()100%210%
ToString()100%210%
Equals(...)0%7280%
Equals(...)0%7280%
Equals(...)0%2040%
Equals(...)0%2040%
GetHashCode()100%210%
GetHashCode()100%210%
op_Equality(...)100%210%
op_Inequality(...)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;
 609    public static Hash Empty => new(new byte[CryptoConstants.Sha256HashLen]);
 10
 11    public Hash(byte[] value)
 12    {
 126013        if (value.Length < CryptoConstants.Sha256HashLen)
 014            throw new ArgumentOutOfRangeException(nameof(value), value.Length,
 015                                                  $"Hash must have {CryptoConstants.Sha256HashLen} bytes.");
 16
 126017        _value = value;
 126018    }
 19
 120020    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;
 024    public static implicit operator ReadOnlySpan<byte>(Hash hash) => hash._value;
 025
 026    public override string ToString() => Convert.ToHexString(_value).ToLowerInvariant();
 27
 28    public bool Equals(Hash other)
 29    {
 30        // Handle null cases first
 031        // ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
 032        if (_value is null && other._value is null)
 033            return true;
 34
 035        // ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
 036        if (_value is null || other._value is null)
 037            return false;
 038
 039        return _value.SequenceEqual(other._value);
 40    }
 41
 42    public override bool Equals(object? obj)
 043    {
 044        if (obj is null)
 045            return false;
 046
 047        return obj is Hash other && Equals(other);
 48    }
 49
 50    public override int GetHashCode()
 051    {
 052        return _value.GetByteArrayHashCode();
 53    }
 54
 55    public static bool operator ==(Hash left, Hash right)
 56    {
 057        return left.Equals(right);
 58    }
 59
 60    public static bool operator !=(Hash left, Hash right)
 61    {
 062        return !(left == right);
 63    }
 64}