HwiClient does not use IProcessBridge.
MODIFY
WalletWasabi.Tests/UnitTests/Hwi/DefaultResponseTests.cs
WalletWasabi.Tests/UnitTests/Hwi/DefaultResponseTests.cs
@@ -10,6 +10,7 @@ using WalletWasabi.Hwi.Exceptions;
using WalletWasabi.Hwi.Models;
using WalletWasabi.Hwi.Parsers;
using WalletWasabi.Hwi.ProcessBridge;
+using WalletWasabi.Microservices;
using Xunit;
namespace WalletWasabi.Tests.UnitTests.Hwi
@@ -120,22 +121,22 @@ namespace WalletWasabi.Tests.UnitTests.Hwi
[Fact]
public async Task HwiProcessBridgeTestAsync()
{
- HwiProcessBridge pb = new HwiProcessBridge();
+ var pb = new HwiProcessBridge(MicroserviceHelpers.GetBinaryPath("hwi"), new ProcessInvoker());
using var cts = new CancellationTokenSource(ReasonableRequestTimeout);
- var res = await pb.SendCommandAsync("enumerate", false, cts.Token);
+ var res = await pb.SendCommandAsync("enumerate", openConsole: false, cts.Token);
Assert.NotEmpty(res.response);
}
[Fact]
public async Task OpenConsoleDoesntThrowAsync()
{
- HwiProcessBridge pb = new HwiProcessBridge();
+ var pb = new HwiProcessBridge(MicroserviceHelpers.GetBinaryPath("hwi"), new ProcessInvoker());
using var cts = new CancellationTokenSource(ReasonableRequestTimeout);
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
- var res = await pb.SendCommandAsync("enumerate", true, cts.Token);
+ var res = await pb.SendCommandAsync("enumerate", openConsole: true, cts.Token);
Assert.NotEmpty(res.response);
}
else

MODIFY
WalletWasabi.Tests/UnitTests/Hwi/HwiProcessBridgeMock.cs
WalletWasabi.Tests/UnitTests/Hwi/HwiProcessBridgeMock.cs
@@ -6,11 +6,12 @@ using System.Threading;
using System.Threading.Tasks;
using WalletWasabi.Hwi.Models;
using WalletWasabi.Hwi.Parsers;
+using WalletWasabi.Hwi.ProcessBridge;
using WalletWasabi.Microservices;
namespace WalletWasabi.Tests.UnitTests.Hwi
{
- public class HwiProcessBridgeMock : IProcessBridge
+ public class HwiProcessBridgeMock : IHwiProcessInvoker
{
public HwiProcessBridgeMock(HardwareWalletModels model)
{

MODIFY
WalletWasabi/Hwi/HwiClient.cs
WalletWasabi/Hwi/HwiClient.cs
@@ -23,10 +23,10 @@ namespace WalletWasabi.Hwi
{
#region ConstructorsAndInitializers
- public HwiClient(Network network, IProcessBridge bridge = null)
+ public HwiClient(Network network, IHwiProcessInvoker bridge = null)
{
Network = Guard.NotNull(nameof(network), network);
- Bridge = bridge ?? new HwiProcessBridge();
+ Bridge = bridge ?? new HwiProcessBridge(MicroserviceHelpers.GetBinaryPath("hwi"), new ProcessInvoker());
}
#endregion ConstructorsAndInitializers
@@ -34,7 +34,7 @@ namespace WalletWasabi.Hwi
#region PropertiesAndMembers
public Network Network { get; }
- public IProcessBridge Bridge { get; }
+ public IHwiProcessInvoker Bridge { get; }
#endregion PropertiesAndMembers

MODIFY
WalletWasabi/Hwi/ProcessBridge/HwiProcessBridge.cs
WalletWasabi/Hwi/ProcessBridge/HwiProcessBridge.cs
using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.IO;
-using System.Runtime.InteropServices;
-using System.Text;
using System.Threading;
using System.Threading.Tasks;
-using WalletWasabi.Helpers;
-using WalletWasabi.Interfaces;
-using WalletWasabi.Logging;
using WalletWasabi.Microservices;
namespace WalletWasabi.Hwi.ProcessBridge
{
- public class HwiProcessBridge : Microservices.ProcessBridge
+ public class HwiProcessBridge : IHwiProcessInvoker
{
- public HwiProcessBridge() : base(MicroserviceHelpers.GetBinaryPath("hwi"))
+ public HwiProcessBridge(string processPath, ProcessInvoker processInvoker)
{
+ ProcessPath = processPath;
+ ProcessInvoker = processInvoker;
}
- public new async Task<(string response, int exitCode)> SendCommandAsync(string arguments, bool openConsole, CancellationToken cancel)
+ private string ProcessPath { get; }
+ private ProcessInvoker ProcessInvoker { get; }
+
+ public async Task<(string response, int exitCode)> SendCommandAsync(string arguments, bool openConsole, CancellationToken cancel)
{
- var (responseString, exitCode) = await base.SendCommandAsync(arguments, openConsole, cancel).ConfigureAwait(false);
+ var process = ProcessBuilder.BuildProcessInstance(ProcessPath, arguments, openConsole);
+
+ (string rawResponse, int exitCode) = await ProcessInvoker.SendCommandAsync(process, cancel).ConfigureAwait(false);
- string modifiedResponseString;
+ string response;
if (!openConsole)
{
- modifiedResponseString = responseString;
+ response = rawResponse;
}
else
{
- modifiedResponseString = exitCode == 0
+ response = exitCode == 0
? "{\"success\":\"true\"}"
: $"{{\"success\":\"false\",\"error\":\"Process terminated with exit code: {exitCode}.\"}}";
}
- return (modifiedResponseString, exitCode);
+ return (response, exitCode);
+ }
}
+
+ public interface IHwiProcessInvoker
+ {
+ Task<(string response, int exitCode)> SendCommandAsync(string arguments, bool openConsole, CancellationToken cancel);
}
}

HwiClient does not use IProcessBridge.