Skip to content

Commit

Permalink
Reducing duplicate code in NodeControllerTests
Browse files Browse the repository at this point in the history
  • Loading branch information
sondreb committed Aug 16, 2020
1 parent f4b3c46 commit ac5e5f2
Showing 1 changed file with 37 additions and 41 deletions.
78 changes: 37 additions & 41 deletions src/Tests/Blockcore.Tests/Controllers/NodeControllerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Blockcore.Base;
using Blockcore.Configuration;
using Blockcore.Connection;
using Blockcore.Consensus;
using Blockcore.Controllers;
using Blockcore.Controllers.Models;
using Blockcore.Interfaces;
Expand Down Expand Up @@ -45,6 +46,7 @@ public class NodeControllerTest : LogsTestBase
private readonly Mock<IPooledTransaction> pooledTransaction;
private readonly Mock<IAsyncProvider> asyncProvider;
private readonly Mock<ISelfEndpointTracker> selfEndpointTracker;
private readonly Mock<IConsensusManager> consensusManager;

private NodeController controller;

Expand All @@ -68,7 +70,12 @@ public NodeControllerTest()
this.pooledTransaction = new Mock<IPooledTransaction>();
this.asyncProvider = new Mock<IAsyncProvider>();
this.selfEndpointTracker = new Mock<ISelfEndpointTracker>();
this.consensusManager = new Mock<IConsensusManager>();

this.CreateNewController();
}

private void CreateNewController() {
this.controller = new NodeController(
this.chainIndexer,
this.chainState.Object,
Expand All @@ -84,7 +91,8 @@ public NodeControllerTest()
this.getUnspentTransaction.Object,
this.networkDifficulty.Object,
this.pooledGetUnspentTransaction.Object,
this.pooledTransaction.Object);
this.pooledTransaction.Object,
this.consensusManager.Object);
}

[Fact]
Expand Down Expand Up @@ -126,10 +134,8 @@ public async Task GetRawTransactionAsync_TransactionCannotBeFound_ReturnsNullAsy
this.blockStore.Setup(b => b.GetTransactionById(txId))
.Returns((Transaction)null)
.Verifiable();
this.controller = new NodeController(this.chainIndexer, this.chainState.Object,
this.connectionManager.Object, this.dateTimeProvider.Object, this.fullNode.Object,
this.LoggerFactory.Object, this.nodeSettings, this.network, this.asyncProvider.Object, this.selfEndpointTracker.Object, this.blockStore.Object, this.getUnspentTransaction.Object,
this.networkDifficulty.Object, this.pooledGetUnspentTransaction.Object, this.pooledTransaction.Object);

this.CreateNewController();

string txid = txId.ToString();
bool verbose = false;
Expand All @@ -150,10 +156,9 @@ public async Task GetRawTransactionAsync_TransactionNotInPooledTransaction_Retur
Transaction transaction = this.CreateTransaction();
this.blockStore.Setup(b => b.GetTransactionById(txId))
.Returns(transaction);
this.controller = new NodeController(this.chainIndexer, this.chainState.Object,
this.connectionManager.Object, this.dateTimeProvider.Object, this.fullNode.Object,
this.LoggerFactory.Object, this.nodeSettings, this.network, this.asyncProvider.Object, this.selfEndpointTracker.Object, this.blockStore.Object, this.getUnspentTransaction.Object,
this.networkDifficulty.Object, this.pooledGetUnspentTransaction.Object, this.pooledTransaction.Object);

this.CreateNewController();

string txid = txId.ToString();
bool verbose = false;

Expand Down Expand Up @@ -189,10 +194,9 @@ public async Task GetRawTransactionAsync_PooledTransactionServiceNotAvailable_Re
Transaction transaction = this.CreateTransaction();
this.blockStore.Setup(b => b.GetTransactionById(txId))
.Returns(transaction);
this.controller = new NodeController(this.chainIndexer, this.chainState.Object,
this.connectionManager.Object, this.dateTimeProvider.Object, this.fullNode.Object,
this.LoggerFactory.Object, this.nodeSettings, this.network, this.asyncProvider.Object, this.selfEndpointTracker.Object, this.blockStore.Object, this.getUnspentTransaction.Object,
this.networkDifficulty.Object, this.pooledGetUnspentTransaction.Object, this.pooledTransaction.Object);

this.CreateNewController();

string txid = txId.ToString();
bool verbose = false;

Expand All @@ -210,10 +214,9 @@ public async Task GetRawTransactionAsync_PooledTransactionAndBlockStoreServiceNo
this.blockStore.Setup(f => f.GetTransactionById(txId))
.Returns((Transaction)null)
.Verifiable();
this.controller = new NodeController(this.chainIndexer, this.chainState.Object,
this.connectionManager.Object, this.dateTimeProvider.Object, this.fullNode.Object,
this.LoggerFactory.Object, this.nodeSettings, this.network, this.asyncProvider.Object, this.selfEndpointTracker.Object, this.blockStore.Object, this.getUnspentTransaction.Object,
this.networkDifficulty.Object, this.pooledGetUnspentTransaction.Object, this.pooledTransaction.Object);

this.CreateNewController();

string txid = txId.ToString();
bool verbose = false;

Expand All @@ -231,10 +234,7 @@ public void DecodeRawTransaction_ReturnsTransaction()
.ReturnsAsync((Transaction)null);
Transaction transaction = this.CreateTransaction();

this.controller = new NodeController(this.chainIndexer, this.chainState.Object,
this.connectionManager.Object, this.dateTimeProvider.Object, this.fullNode.Object,
this.LoggerFactory.Object, this.nodeSettings, this.network, this.asyncProvider.Object, this.selfEndpointTracker.Object, this.blockStore.Object, this.getUnspentTransaction.Object,
this.networkDifficulty.Object, this.pooledGetUnspentTransaction.Object, this.pooledTransaction.Object);
this.CreateNewController();

var json = (JsonResult)this.controller.DecodeRawTransaction(new DecodeRawTransactionModel() { RawHex = transaction.ToHex() });
var resultModel = (TransactionVerboseModel)json.Value;
Expand Down Expand Up @@ -403,11 +403,11 @@ public async Task GetTxOutAsync_NotIncludeInMempool_UnspentTransactionNotFound_R
public async Task GetTxOutAsync_NotIncludeInMempool_GetUnspentTransactionNotAvailable_ReturnsNullAsync()
{
var txId = new uint256(1243124);
this.controller = new NodeController(this.chainIndexer, this.chainState.Object,
this.connectionManager.Object, this.dateTimeProvider.Object, this.fullNode.Object,
this.LoggerFactory.Object, this.nodeSettings, this.network, this.asyncProvider.Object, this.selfEndpointTracker.Object, this.blockStore.Object, this.getUnspentTransaction.Object,
this.networkDifficulty.Object, this.pooledGetUnspentTransaction.Object, this.pooledTransaction.Object);

this.CreateNewController();

string txid = txId.ToString();

uint vout = 0;
bool includeMemPool = false;

Expand All @@ -423,10 +423,9 @@ public async Task GetTxOutAsync_IncludeMempool_UnspentTransactionNotFound_Return
this.pooledGetUnspentTransaction.Setup(s => s.GetUnspentTransactionAsync(new OutPoint(txId, 0)))
.ReturnsAsync((UnspentOutput)null)
.Verifiable();
this.controller = new NodeController(this.chainIndexer, this.chainState.Object,
this.connectionManager.Object, this.dateTimeProvider.Object, this.fullNode.Object,
this.LoggerFactory.Object, this.nodeSettings, this.network, this.asyncProvider.Object, this.selfEndpointTracker.Object, this.blockStore.Object, this.getUnspentTransaction.Object,
this.networkDifficulty.Object, this.pooledGetUnspentTransaction.Object, this.pooledTransaction.Object);

this.CreateNewController();

string txid = txId.ToString();
uint vout = 0;
bool includeMemPool = true;
Expand All @@ -441,10 +440,9 @@ public async Task GetTxOutAsync_IncludeMempool_UnspentTransactionNotFound_Return
public async Task GetTxOutAsync_IncludeMempool_PooledGetUnspentTransactionNotAvailable_UnspentTransactionNotFound_ReturnsNullAsync()
{
var txId = new uint256(1243124);
this.controller = new NodeController(this.chainIndexer, this.chainState.Object,
this.connectionManager.Object, this.dateTimeProvider.Object, this.fullNode.Object,
this.LoggerFactory.Object, this.nodeSettings, this.network, this.asyncProvider.Object, this.selfEndpointTracker.Object, this.blockStore.Object, this.getUnspentTransaction.Object,
this.networkDifficulty.Object, this.pooledGetUnspentTransaction.Object, this.pooledTransaction.Object);

this.CreateNewController();

string txid = txId.ToString();
uint vout = 0;
bool includeMemPool = true;
Expand All @@ -463,10 +461,9 @@ public async Task GetTxOutAsync_NotIncludeInMempool_UnspentTransactionFound_Retu
this.getUnspentTransaction.Setup(s => s.GetUnspentTransactionAsync(new OutPoint(txId, 0)))
.ReturnsAsync(unspentOutputs)
.Verifiable();
this.controller = new NodeController(this.chainIndexer, this.chainState.Object,
this.connectionManager.Object, this.dateTimeProvider.Object, this.fullNode.Object,
this.LoggerFactory.Object, this.nodeSettings, this.network, this.asyncProvider.Object, this.selfEndpointTracker.Object, this.blockStore.Object, this.getUnspentTransaction.Object,
this.networkDifficulty.Object, this.pooledGetUnspentTransaction.Object, this.pooledTransaction.Object);

this.CreateNewController();

string txid = txId.ToString();
uint vout = 0;
bool includeMemPool = false;
Expand All @@ -491,10 +488,9 @@ public async Task GetTxOutAsync_IncludeInMempool_UnspentTransactionFound_Returns
this.pooledGetUnspentTransaction.Setup(s => s.GetUnspentTransactionAsync(new OutPoint(txId, 0)))
.ReturnsAsync(unspentOutputs)
.Verifiable();
this.controller = new NodeController(this.chainIndexer, this.chainState.Object,
this.connectionManager.Object, this.dateTimeProvider.Object, this.fullNode.Object,
this.LoggerFactory.Object, this.nodeSettings, this.network, this.asyncProvider.Object, this.selfEndpointTracker.Object, this.blockStore.Object, this.getUnspentTransaction.Object,
this.networkDifficulty.Object, this.pooledGetUnspentTransaction.Object, this.pooledTransaction.Object);

this.CreateNewController();

string txid = txId.ToString();
uint vout = 0;
bool includeMemPool = true;
Expand Down

0 comments on commit ac5e5f2

Please sign in to comment.