< Summary - Combined Code Coverage

Information
Class: NLightning.Domain.Bitcoin.ValueObjects.TxId
Assembly: NLightning.Domain
File(s): /home/runner/work/NLightning/NLightning/src/NLightning.Domain/Bitcoin/ValueObjects/TxId.cs
Tag: 57_24045730253
Line coverage
35%
Covered lines: 10
Uncovered lines: 18
Coverable lines: 28
Total lines: 74
Line coverage: 35.7%
Branch coverage
41%
Covered branches: 5
Total branches: 12
Branch coverage: 41.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_IsZero()100%210%
get_IsOne()100%210%
.ctor(...)50%2.06275%
get_Zero()100%11100%
get_One()100%210%
op_Implicit(...)100%11100%
op_Implicit(...)100%11100%
op_Implicit(...)100%210%
op_Implicit(...)100%210%
op_Inequality(...)100%210%
op_Equality(...)100%11100%
Equals(...)50%12.1860%
Equals(...)0%620%
GetHashCode()100%210%
ToString()100%210%

File(s)

/home/runner/work/NLightning/NLightning/src/NLightning.Domain/Bitcoin/ValueObjects/TxId.cs

#LineLine coverage
 1namespace NLightning.Domain.Bitcoin.ValueObjects;
 2
 3using Crypto.Constants;
 4using Utils.Extensions;
 5
 6public readonly struct TxId : IEquatable<TxId>
 7{
 8    private readonly byte[] _value;
 9
 010    public bool IsZero => _value.SequenceEqual(Zero._value);
 011    public bool IsOne => _value.SequenceEqual(One._value);
 12
 13    public TxId(byte[] hash)
 14    {
 40015        if (hash.Length < CryptoConstants.Sha256HashLen)
 016            throw new ArgumentException("TxId cannot be empty.", nameof(hash));
 17
 40018        _value = hash;
 40019    }
 20
 7221    public static TxId Zero => new byte[CryptoConstants.Sha256HashLen];
 22
 023    public static TxId One => new byte[]
 024    {
 025        1, 1, 1, 1, 1, 1, 1, 1,
 026        1, 1, 1, 1, 1, 1, 1, 1,
 027        1, 1, 1, 1, 1, 1, 1, 1,
 028        1, 1, 1, 1, 1, 1, 1, 1,
 029    };
 30
 38831    public static implicit operator TxId(byte[] bytes) => new(bytes);
 22432    public static implicit operator byte[](TxId txId) => txId._value;
 033    public static implicit operator ReadOnlyMemory<byte>(TxId compactPubKey) => compactPubKey._value;
 034    public static implicit operator ReadOnlySpan<byte>(TxId compactPubKey) => compactPubKey._value;
 35
 36    public static bool operator !=(TxId left, TxId right)
 37    {
 038        return !left.Equals(right);
 39    }
 40
 41    public static bool operator ==(TxId left, TxId right)
 42    {
 7243        return left.Equals(right);
 44    }
 45
 46    public bool Equals(TxId other)
 47    {
 48        // Handle null cases first
 49        // ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
 7650        if (_value is null && other._value is null)
 051            return true;
 52
 53        // ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
 7654        if (_value is null || other._value is null)
 055            return false;
 56
 7657        return _value.SequenceEqual(other._value);
 58    }
 59
 60    public override bool Equals(object? obj)
 61    {
 062        return obj is TxId other && Equals(other);
 63    }
 64
 65    public override int GetHashCode()
 66    {
 067        return _value.GetByteArrayHashCode();
 68    }
 69
 70    public override string ToString()
 71    {
 072        return Convert.ToHexString(_value).ToLowerInvariant();
 73    }
 74}