NBitcoin.Tests/AltcoinTests.cs
/// <summary>
/// This test check if we can scan RPC capabilities
/// </summary>
This test check if we can scan RPC capabilities
This test check if we can scan RPC capabilities
[Fact]
		public void DoesRPCCapabilitiesWellAdvertised()
		{
			using (var builder = NodeBuilderEx.Create())
			{
				var node = builder.CreateNode();
				builder.StartAll();
				node.Generate(node.Network.Consensus.CoinbaseMaturity + 1);
				var rpc = node.CreateRPCClient();
				rpc.ScanRPCCapabilities();
				Assert.NotNull(rpc.Capabilities);
				CheckCapabilities(rpc, "getnetworkinfo", rpc.Capabilities.SupportGetNetworkInfo);
				CheckCapabilities(rpc, "scantxoutset", rpc.Capabilities.SupportScanUTXOSet);
				CheckCapabilities(rpc, "signrawtransactionwithkey", rpc.Capabilities.SupportSignRawTransactionWith);
				CheckCapabilities(rpc, "estimatesmartfee", rpc.Capabilities.SupportEstimateSmartFee);
				try
				{
					var address = rpc.GetNewAddress(new GetNewAddressRequest()
					{
						AddressType = AddressType.Bech32
					});
					Assert.Equal(rpc.Capabilities.SupportSegwit, address.ScriptPubKey.IsScriptType(ScriptType.Witness));
					if (rpc.Capabilities.SupportSegwit)
					{
						Assert.True(builder.Network.Consensus.SupportSegwit, "The node RPC support segwit, but Network.Consensus.SupportSegwit is set to false");
						rpc.SendToAddress(address, Money.Coins(1.0m));
					}
					else
					{
						Assert.False(builder.Network.Consensus.SupportSegwit, "The node RPC does not support segwit, but Network.Consensus.SupportSegwit is set to true (This error can be normal if you are using a old node version)");
					}
				}
				catch (RPCException) when (!rpc.Capabilities.SupportSegwit)
				{
				}
			}
		}
[ Fact ] public void DoesRPCCapabilitiesWellAdvertised ( ) { using ( var builder = NodeBuilderEx . Create ( ) ) { var node = builder . CreateNode ( ) ; builder . StartAll ( ) ; node . Generate ( node . Network . Consensus . CoinbaseMaturity + 1 ) ; var rpc = node . CreateRPCClient ( ) ; rpc . ScanRPCCapabilities ( ) ; Assert . NotNull ( rpc . Capabilities ) ; CheckCapabilities ( rpc , " " , rpc . Capabilities . SupportGetNetworkInfo ) ; CheckCapabilities ( rpc , " " , rpc . Capabilities . SupportScanUTXOSet ) ; CheckCapabilities ( rpc , " " , rpc . Capabilities . SupportSignRawTransactionWith ) ; CheckCapabilities ( rpc , " " , rpc . Capabilities . SupportEstimateSmartFee ) ; try { var address = rpc . GetNewAddress ( new GetNewAddressRequest ( ) { AddressType = AddressType . Bech32 } ) ; Assert . Equal ( rpc . Capabilities . SupportSegwit , address . ScriptPubKey . IsScriptType ( ScriptType . Witness ) ) ; if ( rpc . Capabilities . SupportSegwit ) { Assert . True ( builder . Network . Consensus . SupportSegwit , " " ) ; rpc . SendToAddress ( address , Money . Coins ( 1.0m ) ) ; } else { Assert . False ( builder . Network . Consensus . SupportSegwit , " " ) ; } } catch ( RPCException ) when ( ! rpc . Capabilities . SupportSegwit ) { } } }
This test check if we can scan RPC capabilities
This test check if we can scan RPC capabilities
// If this fail, rpc support segwit but you said it does not