< 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: 36_15743069263
Line coverage
64%
Covered lines: 18
Uncovered lines: 10
Coverable lines: 28
Total lines: 74
Line coverage: 64.2%
Branch coverage
50%
Covered branches: 6
Total branches: 12
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_IsZero()100%210%
get_IsOne()100%210%
.ctor(...)50%2.06275%
get_Zero()100%11100%
get_One()100%11100%
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(...)50%22100%
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    {
 54815        if (hash.Length < CryptoConstants.Sha256HashLen)
 016            throw new ArgumentException("TxId cannot be empty.", nameof(hash));
 17
 54818        _value = hash;
 54819    }
 20
 14421    public static TxId Zero => new byte[CryptoConstants.Sha256HashLen];
 22
 4823    public static TxId One => new byte[]
 4824    {
 4825        1, 1, 1, 1, 1, 1, 1, 1,
 4826        1, 1, 1, 1, 1, 1, 1, 1,
 4827        1, 1, 1, 1, 1, 1, 1, 1,
 4828        1, 1, 1, 1, 1, 1, 1, 1,
 4829    };
 30
 50831    public static implicit operator TxId(byte[] bytes) => new(bytes);
 24832    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    {
 12043        return left.Equals(right);
 44    }
 45
 46    public bool Equals(TxId other)
 47    {
 48        // Handle null cases first
 49        // ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
 13250        if (_value is null && other._value is null)
 051            return true;
 52
 53        // ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
 13254        if (_value is null || other._value is null)
 055            return false;
 56
 13257        return _value.SequenceEqual(other._value);
 58    }
 59
 60    public override bool Equals(object? obj)
 61    {
 862        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}