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

Commit

Permalink
Merge pull request #160 from bokobza/master
Browse files Browse the repository at this point in the history
Added Network extension method to check if the network is a test one
  • Loading branch information
bokobza authored Jun 14, 2017
2 parents 1bb155d + 9fb0977 commit c3b231d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 28 deletions.
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");
}
}
}

0 comments on commit c3b231d

Please sign in to comment.