Skip to content
This repository has been archived by the owner on Aug 16, 2021. It is now read-only.

Added Network extension method to check if the network is a test one #160

Merged
merged 1 commit into from
Jun 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions Stratis.Bitcoin.Tests/RPC/Controller/GetInfoActionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,6 @@ namespace Stratis.Bitcoin.Tests.RPC.Controller
{
public class GetInfoActionTests : BaseRPCControllerTest
{
[Fact]
public void CallWithoutDependencies()
{
var controller = new FullNodeController();

GetInfoModel info = controller.GetInfo();

Assert.NotNull(info);
Assert.NotNull(info.version);
Assert.NotNull(info.protocolversion);
Assert.NotNull(info.blocks);
Assert.NotNull(info.timeoffset);
Assert.Null(info.connections);
Assert.NotNull(info.proxy);
Assert.NotNull(info.difficulty);
Assert.NotNull(info.testnet);
Assert.NotNull(info.relayfee);
Assert.NotNull(info.errors);
Assert.Null(info.walletversion);
Assert.Null(info.balance);
Assert.Null(info.keypoololdest);
Assert.Null(info.keypoolsize);
Assert.Null(info.unlocked_until);
Assert.Null(info.paytxfee);

}

[Fact]
public void CallWithDependencies()
{
Expand Down
2 changes: 1 addition & 1 deletion Stratis.Bitcoin/RPC/Controllers/FullNodeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public GetInfoModel GetInfo()
connections = this._ConnectionManager?.ConnectedNodes?.Count(),
proxy = string.Empty,
difficulty = GetNetworkDifficulty()?.Difficulty ?? 0,
testnet = this._Network == NBitcoin.Network.TestNet,
testnet = this._Network.IsTest(),
relayfee = MempoolValidator.MinRelayTxFee.FeePerK.ToUnit(MoneyUnit.BTC),
errors = string.Empty,

Expand Down
22 changes: 22 additions & 0 deletions Stratis.Bitcoin/Utilities/NetworkExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Text;
using NBitcoin;

namespace Stratis.Bitcoin.Utilities
{
public static class NetworkExtensions
{
/// <summary>
/// Determines whether this network is a test network.
/// </summary>
/// <param name="network">The network.</param>
/// <returns>
/// <c>true</c> if the specified network is test; otherwise, <c>false</c>.
/// </returns>
public static bool IsTest(this Network network)
{
return network.Name.ToLowerInvariant().Contains("test");
}
}
}