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.
This commit is contained in:
chromatic 2023-06-27 17:57:10 -07:00
parent 502a8a93ce
commit 1c0cab74dd
3 changed files with 27 additions and 11 deletions

View File

@ -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();

View File

@ -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

View File

@ -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);