Add Mock BitcoinStore for Unit tests.
MODIFY
WalletWasabi.Tests/UnitTests/Transactions/PayjoinTests.cs
WalletWasabi.Tests/UnitTests/Transactions/PayjoinTests.cs
@@ -405,11 +405,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
}
var coinsView = new CoinsView(scoins);
- var dataDir = Path.Combine(Global.Instance.DataDir, EnvironmentHelpers.GetCallerFileName());
-
- var bitcoinStore = new BitcoinStore(Path.Combine(dataDir, EnvironmentHelpers.GetMethodName()), Network.Main, new IndexStore(Network.Main, new SmartHeaderChain()), new AllTransactionStore(), new MempoolService());
-
- bitcoinStore.InitializeAsync().Wait();
+ var bitcoinStore = new BitcoinStoreMock();
return new TransactionFactory(Network.Main, keyManager, coinsView, bitcoinStore, password, allowUnconfirmed);
}

MODIFY
WalletWasabi.Tests/UnitTests/Transactions/TransactionFactoryTests.cs
WalletWasabi.Tests/UnitTests/Transactions/TransactionFactoryTests.cs
@@ -218,11 +218,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
var coinsView = new CoinsView(scoins.ToArray());
- var dataDir = Path.Combine(Global.Instance.DataDir, EnvironmentHelpers.GetCallerFileName());
-
- var bitcoinStore = new BitcoinStore(Path.Combine(dataDir, EnvironmentHelpers.GetMethodName()), Network.Main, new IndexStore(Network.Main, new SmartHeaderChain()), new AllTransactionStore(), new MempoolService());
-
- bitcoinStore.InitializeAsync().Wait();
+ var bitcoinStore = new BitcoinStoreMock();
var transactionFactory = new TransactionFactory(Network.Main, keyManager, coinsView, bitcoinStore, password);
@@ -625,11 +621,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
}
var coinsView = new CoinsView(scoins);
- var dataDir = Path.Combine(Global.Instance.DataDir, EnvironmentHelpers.GetCallerFileName());
-
- var bitcoinStore = new BitcoinStore(Path.Combine(dataDir, EnvironmentHelpers.GetMethodName()), Network.Main, new IndexStore(Network.Main, new SmartHeaderChain()), new AllTransactionStore(), new MempoolService());
-
- bitcoinStore.InitializeAsync().Wait();
+ var bitcoinStore = new BitcoinStoreMock();
var transactionFactory = new TransactionFactory(Network.Main, keyManager, coinsView, bitcoinStore, password);

MODIFY
WalletWasabi/Blockchain/Transactions/AllTransactionStore.cs
WalletWasabi/Blockchain/Transactions/AllTransactionStore.cs
@@ -186,7 +186,7 @@ namespace WalletWasabi.Blockchain.Transactions
#region Accessors
- public bool TryGetTransaction(uint256 hash, out SmartTransaction sameStx)
+ public virtual bool TryGetTransaction(uint256 hash, out SmartTransaction sameStx)
{
lock (Lock)
{

ADD
WalletWasabi/Blockchain/Transactions/AllTransactionStoreMock.cs
+using NBitcoin;
+
+namespace WalletWasabi.Blockchain.Transactions
+{
+ public class AllTransactionStoreMock : AllTransactionStore
+ {
+ public override bool TryGetTransaction(uint256 hash, out SmartTransaction sameStx)
+ {
+ sameStx = null;
+ return false;
+ }
+ }
+}

MODIFY
WalletWasabi/Stores/BitcoinStore.cs
WalletWasabi/Stores/BitcoinStore.cs
@@ -35,6 +35,14 @@ namespace WalletWasabi.Stores
MempoolService = mempoolService;
}
+ /// <summary>
+ /// Special constructor used by the mock version.
+ /// </summary>
+ internal BitcoinStore()
+ {
+ TransactionStore = new AllTransactionStoreMock();
+ }
+
public bool IsInitialized { get; private set; }
private string WorkFolderPath { get; }
public Network Network { get; }

ADD
WalletWasabi/Stores/BitcoinStoreMock.cs
+namespace WalletWasabi.Stores
+{
+ /// <summary>
+ /// This class provides a Mock version of <see cref="BitcoinStore"/> for
+ /// Unit-tests that only need a dummy version of the class.
+ /// </summary>
+ public class BitcoinStoreMock : BitcoinStore
+ {
+ public BitcoinStoreMock() : base()
+ {
+ }
+ }
+}

Add Mock BitcoinStore for Unit tests.