< Summary - Combined Code Coverage

Information
Class: NLightning.Domain.Protocol.ValueObjects.ChainHash
Assembly: NLightning.Domain
File(s): /home/runner/work/nlightning/nlightning/src/NLightning.Domain/Protocol/ValueObjects/ChainHash.cs
Tag: 36_15743069263
Line coverage
85%
Covered lines: 12
Uncovered lines: 2
Coverable lines: 14
Total lines: 60
Line coverage: 85.7%
Branch coverage
50%
Covered branches: 2
Total branches: 4
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Value()100%11100%
.ctor(...)100%22100%
op_Implicit(...)100%11100%
op_Implicit(...)100%11100%
op_Implicit(...)100%11100%
op_Inequality(...)100%11100%
op_Equality(...)100%11100%
Equals(...)100%11100%
Equals(...)0%620%
GetHashCode()100%210%

File(s)

/home/runner/work/nlightning/nlightning/src/NLightning.Domain/Protocol/ValueObjects/ChainHash.cs

#LineLine coverage
 1namespace NLightning.Domain.Protocol.ValueObjects;
 2
 3using Crypto.Constants;
 4using Domain.Interfaces;
 5
 6/// <summary>
 7/// Represents a chain hash.
 8/// </summary>
 9/// <remarks>
 10/// A chain hash is a 32-byte hash used to identify a chain.
 11/// </remarks>
 12public readonly struct ChainHash : IEquatable<ChainHash>, IValueObject
 13{
 26014    public byte[] Value { get; }
 15
 16    /// <summary>
 17    /// Initializes a new instance of the <see cref="ChainHash"/> struct.
 18    /// </summary>
 19    /// <param name="value">The value of the chain hash.</param>
 20    /// <exception cref="ArgumentOutOfRangeException">Thrown when the value is not 32 bytes.</exception>
 21    public ChainHash(ReadOnlySpan<byte> value)
 22    {
 10823        if (value.Length != CryptoConstants.Sha256HashLen)
 24        {
 425            throw new ArgumentOutOfRangeException(nameof(value),
 426                                                  $"ChainHash must be {CryptoConstants.Sha256HashLen} bytes");
 27        }
 28
 10429        Value = value.ToArray();
 10430    }
 31
 2432    public static implicit operator byte[](ChainHash c) => c.Value;
 1233    public static implicit operator ReadOnlyMemory<byte>(ChainHash c) => c.Value;
 834    public static implicit operator ChainHash(byte[] value) => new(value);
 35
 36    public static bool operator !=(ChainHash left, ChainHash right)
 37    {
 838        return !left.Equals(right);
 39    }
 40
 41    public static bool operator ==(ChainHash left, ChainHash right)
 42    {
 843        return left.Equals(right);
 44    }
 45
 46    public bool Equals(ChainHash other)
 47    {
 11248        return Value.SequenceEqual(other.Value);
 49    }
 50
 51    public override bool Equals(object? obj)
 52    {
 053        return obj is ChainHash other && Equals(other);
 54    }
 55
 56    public override int GetHashCode()
 57    {
 058        return Value.GetHashCode();
 59    }
 60}