< Summary - Combined Code Coverage

Information
Class: NLightning.Domain.ValueObjects.Network
Assembly: NLightning.Domain
File(s): /home/runner/work/nlightning/nlightning/src/NLightning.Domain/ValueObjects/Network.cs
Tag: 30_15166811759
Line coverage
83%
Covered lines: 31
Uncovered lines: 6
Coverable lines: 37
Total lines: 92
Line coverage: 83.7%
Branch coverage
54%
Covered branches: 12
Total branches: 22
Branch coverage: 54.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
get_Name()100%11100%
.ctor(...)100%11100%
get_ChainHash()100%66100%
ToString()100%11100%
op_Implicit(...)100%11100%
op_Implicit(...)100%11100%
op_Implicit(...)50%6.84671.43%
op_Implicit(...)33.33%6.84671.43%
Equals(...)50%22100%
Equals(...)100%11100%
Equals(...)0%620%
GetHashCode()100%210%
op_Equality(...)100%11100%
op_Inequality(...)100%11100%

File(s)

/home/runner/work/nlightning/nlightning/src/NLightning.Domain/ValueObjects/Network.cs

#LineLine coverage
 1namespace NLightning.Domain.ValueObjects;
 2
 3using Protocol.Constants;
 4
 5public readonly struct Network : IEquatable<Network>, IEquatable<NBitcoin.Network>
 6{
 247    public static readonly Network MAINNET = new(NetworkConstants.MAINNET);
 248    public static readonly Network TESTNET = new(NetworkConstants.TESTNET);
 249    public static readonly Network REGTEST = new(NetworkConstants.REGTEST);
 2410    public static readonly Network SIGNET = new(NetworkConstants.SIGNET);
 11
 99212    public string Name { get; }
 13
 14    public Network(string name)
 15    {
 46816        Name = name;
 46817    }
 18
 19    public ChainHash ChainHash
 20    {
 21        get
 22        {
 3623            return Name switch
 3624            {
 2425                NetworkConstants.MAINNET => ChainConstants.MAIN,
 426                NetworkConstants.TESTNET => ChainConstants.TESTNET,
 427                NetworkConstants.REGTEST => ChainConstants.REGTEST,
 428                _ => throw new Exception("Chain not supported.")
 3629            };
 30        }
 31    }
 32
 433    public override string ToString() => Name;
 34
 35    #region Implicit Conversions
 436    public static implicit operator string(Network network) => network.Name;
 23637    public static implicit operator Network(string value) => new(value);
 38
 39    public static implicit operator NBitcoin.Network(Network network)
 40    {
 18441        return network.Name switch
 18442        {
 18043            NetworkConstants.MAINNET => NBitcoin.Network.Main,
 444            NetworkConstants.TESTNET => NBitcoin.Network.TestNet,
 045            NetworkConstants.REGTEST => NBitcoin.Network.RegTest,
 046            _ => throw new ArgumentException("Unsupported network type", nameof(network)),
 18447        };
 48    }
 49    public static implicit operator Network(NBitcoin.Network network)
 50    {
 4451        return network.Name switch
 4452        {
 4053            "Main" => MAINNET,
 454            "TestNet" => TESTNET,
 055            "RegTest" => REGTEST,
 056            _ => throw new ArgumentException("Unsupported network type", nameof(network)),
 4457        };
 58    }
 59    #endregion
 60
 61    #region Equality
 62    public override bool Equals(object? obj)
 63    {
 5664        return obj is Network network && Name == network.Name;
 65    }
 66
 67    public bool Equals(Network other)
 68    {
 3269        return Name == other.Name;
 70    }
 71
 72    public bool Equals(NBitcoin.Network? other)
 73    {
 074        return other is not null && ((byte[])ChainHash).SequenceEqual(other.GenesisHash.ToBytes());
 75    }
 76
 77    public override int GetHashCode()
 78    {
 079        return Name.GetHashCode();
 80    }
 81
 82    public static bool operator ==(Network left, Network right)
 83    {
 19684        return left.Name == right.Name;
 85    }
 86
 87    public static bool operator !=(Network left, Network right)
 88    {
 6889        return !(left == right);
 90    }
 91    #endregion
 92}