From 1c0cab74dd92960cc41220f564c0c79374c85345 Mon Sep 17 00:00:00 2001 From: chromatic Date: Tue, 27 Jun 2023 17:57:10 -0700 Subject: [PATCH] Allow PaymentServer a parametric server name While the default server name is almost always what we want, given that it is unique to main or testnet and the default data directory, defaulting to this value during tests is not always what we want, especially if there's production data or the path is not available (think of a CI system). Switch the test to provide a fixed server name at the point of constructing the PaymentServer object. Addresses GH #3285. --- src/qt/paymentserver.cpp | 33 +++++++++++++++++++++--------- src/qt/paymentserver.h | 3 +++ src/qt/test/paymentservertests.cpp | 2 +- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/qt/paymentserver.cpp b/src/qt/paymentserver.cpp index 2278c695a..e6c19d1bb 100644 --- a/src/qt/paymentserver.cpp +++ b/src/qt/paymentserver.cpp @@ -298,13 +298,7 @@ bool PaymentServer::ipcSendCommandLine() return fResult; } -PaymentServer::PaymentServer(QObject* parent, bool startLocalServer) : - QObject(parent), - saveURIs(true), - uriServer(0), - netManager(0), - optionsModel(0) -{ +void PaymentServer::initializeServer(QObject* parent, QString ipcServerName, bool startLocalServer) { // Verify that the version of the library that we linked against is // compatible with the version of the headers we compiled against. GOOGLE_PROTOBUF_VERIFY_VERSION; @@ -315,13 +309,11 @@ PaymentServer::PaymentServer(QObject* parent, bool startLocalServer) : if (parent) parent->installEventFilter(this); - QString name = ipcServerName(); - if (startLocalServer) { uriServer = new QLocalServer(this); - if (!uriServer->listen(name)) { + if (!uriServer->listen(ipcServerName)) { // constructor is called early in init, so don't use "Q_EMIT message()" here QMessageBox::critical(0, tr("Payment request error"), tr("Cannot start dogecoin: click-to-pay handler")); @@ -333,6 +325,27 @@ PaymentServer::PaymentServer(QObject* parent, bool startLocalServer) : } } +PaymentServer::PaymentServer(QObject* parent, bool startLocalServer) : + QObject(parent), + saveURIs(true), + uriServer(0), + netManager(0), + optionsModel(0) +{ + this->initializeServer(parent, ipcServerName(), startLocalServer); +} + + +PaymentServer::PaymentServer(QObject* parent, QString ipcServerName, bool startLocalServer) : + QObject(parent), + saveURIs(true), + uriServer(0), + netManager(0), + optionsModel(0) +{ + this->initializeServer(parent, ipcServerName, startLocalServer); +} + PaymentServer::~PaymentServer() { google::protobuf::ShutdownProtobufLibrary(); diff --git a/src/qt/paymentserver.h b/src/qt/paymentserver.h index 7c6d4507f..b230bea81 100644 --- a/src/qt/paymentserver.h +++ b/src/qt/paymentserver.h @@ -73,6 +73,7 @@ public: // parent should be QApplication object PaymentServer(QObject* parent, bool startLocalServer = true); + PaymentServer(QObject* parent, QString ipcServerName, bool startLocalServer = true); ~PaymentServer(); // Load root certificate authorities. Pass NULL (default) @@ -138,6 +139,8 @@ private: void initNetManager(); bool saveURIs; // true during startup + + void initializeServer(QObject* parent, QString ipcServerName, bool startLocalServer); QLocalServer* uriServer; QNetworkAccessManager* netManager; // Used to fetch payment requests diff --git a/src/qt/test/paymentservertests.cpp b/src/qt/test/paymentservertests.cpp index 484fd571e..7d2e64619 100644 --- a/src/qt/test/paymentservertests.cpp +++ b/src/qt/test/paymentservertests.cpp @@ -67,7 +67,7 @@ void PaymentServerTests::paymentServerTests() { SelectParams(CBaseChainParams::MAIN); OptionsModel optionsModel; - PaymentServer* server = new PaymentServer(NULL, false); + PaymentServer* server = new PaymentServer(NULL, QString("testIPCServer"), false); X509_STORE* caStore = X509_STORE_new(); X509_STORE_add_cert(caStore, parse_b64der_cert(caCert1_BASE64)); PaymentServer::LoadRootCAs(caStore);