use a tor service instance variable to allow using a mocked TorService in testing

This commit is contained in:
julian 2023-09-08 12:32:04 -06:00
parent 6cf88d22b5
commit 03a849d61f

View file

@ -1,6 +1,7 @@
import 'dart:convert'; import 'dart:convert';
import 'dart:io'; import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:socks5_proxy/socks_client.dart'; import 'package:socks5_proxy/socks_client.dart';
import 'package:stackwallet/services/tor_service.dart'; import 'package:stackwallet/services/tor_service.dart';
import 'package:stackwallet/utilities/logger.dart'; import 'package:stackwallet/utilities/logger.dart';
@ -16,6 +17,10 @@ class Response {
} }
class HTTP { class HTTP {
/// Visible for testing so we can override with a mock TorService
@visibleForTesting
TorService torService = TorService.sharedInstance;
Future<Response> get({ Future<Response> get({
required Uri url, required Uri url,
Map<String, String>? headers, Map<String, String>? headers,
@ -26,8 +31,8 @@ class HTTP {
if (routeOverTor) { if (routeOverTor) {
SocksTCPClient.assignToHttpClient(httpClient, [ SocksTCPClient.assignToHttpClient(httpClient, [
ProxySettings( ProxySettings(
TorService.sharedInstance.proxyInfo.host, torService.proxyInfo.host,
TorService.sharedInstance.proxyInfo.port, torService.proxyInfo.port,
), ),
]); ]);
} }
@ -68,8 +73,8 @@ class HTTP {
if (routeOverTor) { if (routeOverTor) {
SocksTCPClient.assignToHttpClient(httpClient, [ SocksTCPClient.assignToHttpClient(httpClient, [
ProxySettings( ProxySettings(
TorService.sharedInstance.proxyInfo.host, torService.proxyInfo.host,
TorService.sharedInstance.proxyInfo.port, torService.proxyInfo.port,
), ),
]); ]);
} }