public void CallWithDependencies() { string dir = AssureEmptyDir("TestData/GetInfoActionTests/CallWithDependencies"); IFullNode fullNode = this.BuildServicedNode(dir); FullNodeController controller = fullNode.Services.ServiceProvider.GetService <FullNodeController>(); Assert.NotNull(fullNode.NodeService <INetworkDifficulty>(true)); GetInfoModel info = controller.GetInfo(); uint expectedProtocolVersion = (uint)NodeSettings.Default().ProtocolVersion; var expectedRelayFee = MempoolValidator.MinRelayTxFee.FeePerK.ToUnit(NBitcoin.MoneyUnit.BTC); Assert.NotNull(info); Assert.Equal(0, info.blocks); Assert.NotEqual <uint>(0, info.version); Assert.Equal(expectedProtocolVersion, info.protocolversion); Assert.Equal(0, info.timeoffset); Assert.Equal(0, info.connections); Assert.NotNull(info.proxy); Assert.Equal(0, info.difficulty); Assert.False(info.testnet); Assert.Equal(expectedRelayFee, info.relayfee); Assert.Empty(info.errors); }
public void CallWithDependencies() { string dir = CreateTestDir(this); IFullNode fullNode = this.BuildServicedNode(dir); FullNodeController controller = fullNode.Services.ServiceProvider.GetService <FullNodeController>(); Assert.NotNull(fullNode.NodeService <INetworkDifficulty>(true)); GetInfoModel info = controller.GetInfo(); NodeSettings nodeSettings = NodeSettings.Default(); uint expectedProtocolVersion = (uint)nodeSettings.ProtocolVersion; var expectedRelayFee = nodeSettings.MinRelayTxFeeRate.FeePerK.ToUnit(NBitcoin.MoneyUnit.BTC); Assert.NotNull(info); Assert.Equal(0, info.Blocks); Assert.NotEqual <uint>(0, info.Version); Assert.Equal(expectedProtocolVersion, info.ProtocolVersion); Assert.Equal(0, info.TimeOffset); Assert.Equal(0, info.Connections); Assert.NotNull(info.Proxy); Assert.Equal(0, info.Difficulty); Assert.False(info.Testnet); Assert.Equal(expectedRelayFee, info.RelayFee); Assert.Empty(info.Errors); }
public void GetInfo_NoNetworkDifficulty_ReturnsModel() { this.controller = new FullNodeController(this.LoggerFactory.Object, this.pooledTransaction.Object, this.pooledGetUnspentTransaction.Object, this.getUnspentTransaction.Object, null, this.consensusLoop.Object, this.fullNode.Object, this.nodeSettings, this.network, this.chain, this.chainState.Object, this.connectionManager.Object); GetInfoModel model = this.controller.GetInfo(); Assert.Equal(0, model.Difficulty); }
public async Task Stop_WithoutFullNode_DoesNotThrowExceptionAsync() { IFullNode fullNode = null; this.controller = new FullNodeController(this.LoggerFactory.Object, this.pooledTransaction.Object, this.pooledGetUnspentTransaction.Object, this.getUnspentTransaction.Object, this.networkDifficulty.Object, this.consensusLoop.Object, fullNode, this.nodeSettings, this.network, this.chain, this.chainState.Object, this.connectionManager.Object); await this.controller.Stop().ConfigureAwait(false); }
public void GetInfo_NoChainState_ReturnsModel() { IChainState chainState = null; this.controller = new FullNodeController(this.LoggerFactory.Object, this.pooledTransaction.Object, this.pooledGetUnspentTransaction.Object, this.getUnspentTransaction.Object, this.networkDifficulty.Object, this.consensusLoop.Object, this.fullNode.Object, this.nodeSettings, this.network, this.chain, chainState, this.connectionManager.Object); var model = this.controller.GetInfo(); Assert.Equal(0, model.Blocks); }
public async Task GetTxOutAsync_IncludeMempool_PooledGetUnspentTransactionNotAvailable_UnspentTransactionNotFound_ReturnsNullAsync() { var txId = new uint256(1243124); this.controller = new FullNodeController(this.LoggerFactory.Object, this.pooledTransaction.Object, null, this.getUnspentTransaction.Object, this.networkDifficulty.Object, this.consensusLoop.Object, this.fullNode.Object, this.nodeSettings, this.network, this.chain, this.chainState.Object, this.connectionManager.Object); GetTxOutModel result = await this.controller.GetTxOutAsync(txId.ToString(), 0, true).ConfigureAwait(false); Assert.Null(result); }
public void GetBlockHeader_ChainNull_ReturnsNull() { this.chain = null; this.controller = new FullNodeController(this.LoggerFactory.Object, this.pooledTransaction.Object, this.pooledGetUnspentTransaction.Object, this.getUnspentTransaction.Object, this.networkDifficulty.Object, this.consensusLoop.Object, this.fullNode.Object, this.nodeSettings, this.network, this.chain, this.chainState.Object, this.connectionManager.Object); BlockHeaderModel result = this.controller.GetBlockHeader("", true); Assert.Null(result); }
public void GetInfo_NoSettings_ReturnsModel() { this.nodeSettings = null; this.controller = new FullNodeController(this.LoggerFactory.Object, this.pooledTransaction.Object, this.pooledGetUnspentTransaction.Object, this.getUnspentTransaction.Object, this.networkDifficulty.Object, this.consensusLoop.Object, this.fullNode.Object, this.nodeSettings, this.network, this.chain, this.chainState.Object, this.connectionManager.Object); GetInfoModel model = this.controller.GetInfo(); Assert.Equal((uint)NodeSettings.SupportedProtocolVersion, model.ProtocolVersion); Assert.Equal(0, model.RelayFee); }
public void GetInfo_MainNet_ReturnsInfoModel() { this.network = KnownNetworks.Main; this.controller = new FullNodeController(this.LoggerFactory.Object, this.pooledTransaction.Object, this.pooledGetUnspentTransaction.Object, this.getUnspentTransaction.Object, this.networkDifficulty.Object, this.consensusLoop.Object, this.fullNode.Object, this.nodeSettings, this.network, this.chain, this.chainState.Object, this.connectionManager.Object); GetInfoModel model = this.controller.GetInfo(); Assert.False(model.Testnet); }
public void GetInfo_NoVersion_ReturnsModel() { this.fullNode.Setup(f => f.Version) .Returns((Version)null); this.controller = new FullNodeController(this.LoggerFactory.Object, this.pooledTransaction.Object, this.pooledGetUnspentTransaction.Object, this.getUnspentTransaction.Object, this.networkDifficulty.Object, this.consensusLoop.Object, this.fullNode.Object, this.nodeSettings, this.network, this.chain, this.chainState.Object, this.connectionManager.Object); GetInfoModel model = this.controller.GetInfo(); Assert.Equal((uint)0, model.Version); }
public async Task GetTaskAsync_Verbose_ReturnsTransactionVerboseModelAsync() { // Add the 'txindex' setting, otherwise the transactions won't be found. this.nodeSettings.ConfigReader.MergeInto(new TextFileConfiguration("-txindex=1")); this.chainState.Setup(c => c.ConsensusTip) .Returns(this.chain.Tip); ChainedHeader block = this.chain.GetHeader(1); Transaction transaction = this.CreateTransaction(); var txId = new uint256(12142124); this.pooledTransaction.Setup(p => p.GetTransaction(txId)) .ReturnsAsync(transaction); this.blockStore.Setup(b => b.GetBlockIdByTransactionId(txId)) .Returns(block.HashBlock); this.controller = new FullNodeController(this.LoggerFactory.Object, this.pooledTransaction.Object, this.pooledGetUnspentTransaction.Object, this.getUnspentTransaction.Object, this.networkDifficulty.Object, this.fullNode.Object, this.nodeSettings, this.network, this.chain, this.chainState.Object, this.connectionManager.Object, this.consensusManager.Object, this.blockStore.Object); TransactionModel result = await this.controller.GetRawTransactionAsync(txId.ToString(), true).ConfigureAwait(false); Assert.NotNull(result); var model = Assert.IsType <TransactionVerboseModel>(result); Assert.Equal(transaction.GetHash().ToString(), model.TxId); Assert.Equal(transaction.GetSerializedSize(), model.Size); Assert.Equal(transaction.Version, model.Version); Assert.Equal((uint)transaction.LockTime, model.LockTime); Assert.Equal(transaction.ToHex(), model.Hex); Assert.Equal(block.HashBlock.ToString(), model.BlockHash); Assert.Equal(3, model.Confirmations); Assert.Equal(Utils.DateTimeToUnixTime(block.Header.BlockTime), model.Time); Assert.Equal(Utils.DateTimeToUnixTime(block.Header.BlockTime), model.BlockTime); Assert.NotEmpty(model.VIn); Vin input = model.VIn[0]; var expectedInput = new Vin(transaction.Inputs[0].PrevOut, transaction.Inputs[0].Sequence, transaction.Inputs[0].ScriptSig); Assert.Equal(expectedInput.Coinbase, input.Coinbase); Assert.Equal(expectedInput.ScriptSig, input.ScriptSig); Assert.Equal(expectedInput.Sequence, input.Sequence); Assert.Equal(expectedInput.TxId, input.TxId); Assert.Equal(expectedInput.VOut, input.VOut); Assert.NotEmpty(model.VOut); Vout output = model.VOut[0]; var expectedOutput = new Vout(0, transaction.Outputs[0], this.network); Assert.Equal(expectedOutput.Value, output.Value); Assert.Equal(expectedOutput.N, output.N); Assert.Equal(expectedOutput.ScriptPubKey.Hex, output.ScriptPubKey.Hex); }
public void GetInfo_NoConnectionManager_ReturnsModel() { IConnectionManager connectionManager = null; this.controller = new FullNodeController(this.LoggerFactory.Object, this.pooledTransaction.Object, this.pooledGetUnspentTransaction.Object, this.getUnspentTransaction.Object, this.networkDifficulty.Object, this.consensusLoop.Object, this.fullNode.Object, this.nodeSettings, this.network, this.chain, this.chainState.Object, connectionManager); GetInfoModel model = this.controller.GetInfo(); Assert.Equal(0, model.TimeOffset); Assert.Null(model.Connections); }
public void GetInfo_NoChainTip_ReturnsModel() { this.chainState.Setup(c => c.ConsensusTip) .Returns((ChainedHeader)null); this.controller = new FullNodeController(this.LoggerFactory.Object, this.pooledTransaction.Object, this.pooledGetUnspentTransaction.Object, this.getUnspentTransaction.Object, this.networkDifficulty.Object, this.consensusLoop.Object, this.fullNode.Object, this.nodeSettings, this.network, this.chain, this.chainState.Object, this.connectionManager.Object); GetInfoModel model = this.controller.GetInfo(); Assert.Equal(0, model.Blocks); }
public async Task GetRawTransactionAsync_PooledTransactionAndBlockStoreServiceNotAvailable_ReturnsNullAsync() { var txId = new uint256(12142124); this.fullNode.Setup(f => f.NodeFeature <IBlockStore>(false)) .Returns(default(IBlockStore)) .Verifiable(); this.controller = new FullNodeController(this.LoggerFactory.Object, null, this.pooledGetUnspentTransaction.Object, this.getUnspentTransaction.Object, this.networkDifficulty.Object, this.consensusLoop.Object, this.fullNode.Object, this.nodeSettings, this.network, this.chain, this.chainState.Object, this.connectionManager.Object); TransactionModel result = await this.controller.GetRawTransactionAsync(txId.ToString(), 0).ConfigureAwait(false); Assert.Null(result); this.fullNode.Verify(); }
public FullNodeControllerTest() { this.fullNode = new Mock <IFullNode>(); this.chainState = new Mock <IChainState>(); this.connectionManager = new Mock <IConnectionManager>(); this.network = Network.TestNet; this.chain = WalletTestsHelpers.GenerateChainWithHeight(3, this.network); this.nodeSettings = new NodeSettings(); this.pooledTransaction = new Mock <IPooledTransaction>(); this.pooledGetUnspentTransaction = new Mock <IPooledGetUnspentTransaction>(); this.getUnspentTransaction = new Mock <IGetUnspentTransaction>(); this.consensusLoop = new Mock <IConsensusLoop>(); this.networkDifficulty = new Mock <INetworkDifficulty>(); this.controller = new FullNodeController(this.LoggerFactory.Object, this.pooledTransaction.Object, this.pooledGetUnspentTransaction.Object, this.getUnspentTransaction.Object, this.networkDifficulty.Object, this.consensusLoop.Object, this.fullNode.Object, this.nodeSettings, this.network, this.chain, this.chainState.Object, this.connectionManager.Object); }
public async Task GetRawTransactionAsync_PooledTransactionServiceNotAvailable_ReturnsTransactionFromBlockStoreAsync() { var txId = new uint256(12142124); Transaction transaction = this.CreateTransaction(); this.blockStore.Setup(b => b.GetTrxAsync(txId)) .ReturnsAsync(transaction); this.controller = new FullNodeController(this.LoggerFactory.Object, null, this.pooledGetUnspentTransaction.Object, this.getUnspentTransaction.Object, this.networkDifficulty.Object, this.consensusLoop.Object, this.fullNode.Object, this.nodeSettings, this.network, this.chain, this.chainState.Object, this.connectionManager.Object, this.blockStore.Object); TransactionModel result = await this.controller.GetRawTransactionAsync(txId.ToString(), 0).ConfigureAwait(false); Assert.NotNull(result); var model = Assert.IsType <TransactionBriefModel>(result); Assert.Equal(transaction.ToHex(), model.Hex); }
public FullNodeControllerTest() { this.nodeLifeTime = new Mock <INodeLifetime>(); this.fullNode = new Mock <IFullNode>(); this.fullNode.SetupGet(p => p.NodeLifetime).Returns(this.nodeLifeTime.Object); this.chainState = new Mock <IChainState>(); this.connectionManager = new Mock <IConnectionManager>(); this.network = KnownNetworks.TestNet; this.chain = WalletTestsHelpers.GenerateChainWithHeight(3, this.network); this.nodeSettings = new NodeSettings(this.Network); this.pooledTransaction = new Mock <IPooledTransaction>(); this.pooledGetUnspentTransaction = new Mock <IPooledGetUnspentTransaction>(); this.getUnspentTransaction = new Mock <IGetUnspentTransaction>(); this.networkDifficulty = new Mock <INetworkDifficulty>(); this.consensusManager = new Mock <IConsensusManager>(); this.blockStore = new Mock <IBlockStore>(); this.controller = new FullNodeController(this.LoggerFactory.Object, this.pooledTransaction.Object, this.pooledGetUnspentTransaction.Object, this.getUnspentTransaction.Object, this.networkDifficulty.Object, this.fullNode.Object, this.nodeSettings, this.network, this.chain, this.chainState.Object, this.connectionManager.Object, this.consensusManager.Object, this.blockStore.Object); }
public async Task GetRawTransactionAsync_PooledTransactionAndBlockStoreServiceNotAvailable_ReturnsNullAsync() { var txId = new uint256(12142124); this.blockStore.Setup(f => f.GetTransactionById(txId)) .Returns((Transaction)null) .Verifiable(); this.controller = new FullNodeController(this.LoggerFactory.Object, null, this.pooledGetUnspentTransaction.Object, this.getUnspentTransaction.Object, this.networkDifficulty.Object, this.fullNode.Object, this.nodeSettings, this.network, this.chain, this.chainState.Object, this.connectionManager.Object, this.consensusManager.Object, this.blockStore.Object); RPCServerException exception = await Assert.ThrowsAsync <RPCServerException>(async() => { TransactionModel result = await this.controller.GetRawTransactionAsync(txId.ToString(), false).ConfigureAwait(false); }); Assert.NotNull(exception); Assert.Equal("No such mempool transaction. Use -txindex to enable blockchain transaction queries.", exception.Message); this.blockStore.Verify(); }
public async Task GetTxOutAsync_IncludeInMempool_UnspentTransactionFound_ReturnsModelAsync() { var txId = new uint256(1243124); Transaction transaction = this.CreateTransaction(); var unspentOutputs = new UnspentOutputs(1, transaction); this.pooledGetUnspentTransaction.Setup(s => s.GetUnspentTransactionAsync(txId)) .ReturnsAsync(unspentOutputs) .Verifiable(); this.controller = new FullNodeController(this.LoggerFactory.Object, this.pooledTransaction.Object, this.pooledGetUnspentTransaction.Object, this.getUnspentTransaction.Object, this.networkDifficulty.Object, this.consensusLoop.Object, this.fullNode.Object, this.nodeSettings, this.network, this.chain, this.chainState.Object, this.connectionManager.Object); GetTxOutModel model = await this.controller.GetTxOutAsync(txId.ToString(), 0, true).ConfigureAwait(false); this.pooledGetUnspentTransaction.Verify(); Assert.Equal(this.chain.Tip.HashBlock, model.BestBlock); Assert.True(model.Coinbase); Assert.Equal(3, model.Confirmations); Assert.Equal(new ScriptPubKey(transaction.Outputs[0].ScriptPubKey, this.network).Hex, model.ScriptPubKey.Hex); Assert.Equal(transaction.Outputs[0].Value, model.Value); }
public void GetInfo_TestNet_ReturnsInfoModel() { this.nodeSettings = new NodeSettings(protocolVersion: ProtocolVersion.NO_BLOOM_VERSION, args: new[] { "-minrelaytxfeerate=1000" }); this.controller = new FullNodeController(this.LoggerFactory.Object, this.pooledTransaction.Object, this.pooledGetUnspentTransaction.Object, this.getUnspentTransaction.Object, this.networkDifficulty.Object, this.consensusLoop.Object, this.fullNode.Object, this.nodeSettings, this.network, this.chain, this.chainState.Object, this.connectionManager.Object); this.fullNode.Setup(f => f.Version) .Returns(new Version(15, 0)); this.networkDifficulty.Setup(n => n.GetNetworkDifficulty()) .Returns(new Target(121221121212)); this.chainState.Setup(c => c.ConsensusTip) .Returns(this.chain.Tip); this.connectionManager.Setup(c => c.ConnectedPeers) .Returns(new TestReadOnlyNetworkPeerCollection()); GetInfoModel model = this.controller.GetInfo(); Assert.Equal((uint)14999899, model.Version); Assert.Equal((uint)ProtocolVersion.NO_BLOOM_VERSION, model.ProtocolVersion); Assert.Equal(3, model.Blocks); Assert.Equal(0, model.TimeOffset); Assert.Equal(0, model.Connections); Assert.Empty(model.Proxy); Assert.Equal(new Target(121221121212).Difficulty, model.Difficulty); Assert.True(model.Testnet); Assert.Equal(0.00001m, model.RelayFee); Assert.Empty(model.Errors); Assert.Null(model.WalletVersion); Assert.Null(model.Balance); Assert.Null(model.KeypoolOldest); Assert.Null(model.KeypoolSize); Assert.Null(model.UnlockedUntil); Assert.Null(model.PayTxFee); }
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); }