2020-09-27 12:40:11 +03:00
|
|
|
/*
|
2021-01-31 19:51:00 +03:00
|
|
|
* Copyright (C) 2018-2021 QuasarApp.
|
2020-09-27 12:40:11 +03:00
|
|
|
* Distributed under the lgplv3 software license, see the accompanying
|
|
|
|
* Everyone is permitted to copy and distribute verbatim copies
|
|
|
|
* of this license document, but changing it is not allowed.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2020-09-15 21:16:35 +03:00
|
|
|
#include "networknodetest.h"
|
|
|
|
#include "networknodeunittests.h"
|
|
|
|
#include "testutils.h"
|
|
|
|
|
|
|
|
#include <networknode.h>
|
|
|
|
#include <keystorage.h>
|
|
|
|
#include <ping.h>
|
|
|
|
#include <qsecretrsa2048.h>
|
2021-01-13 18:35:44 +03:00
|
|
|
#include <keystoragetest.h>
|
2020-09-15 21:16:35 +03:00
|
|
|
|
2020-09-15 22:07:49 +03:00
|
|
|
class TestingNetworkClient: public QH::NetworkNode {
|
2020-09-15 21:16:35 +03:00
|
|
|
|
|
|
|
|
|
|
|
// AbstractNode interface
|
|
|
|
public:
|
2020-09-16 15:10:13 +03:00
|
|
|
const QH::PKG::Ping& getPing() const {
|
2020-09-15 21:16:35 +03:00
|
|
|
return _ping;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2020-11-11 23:03:18 +03:00
|
|
|
void incomingData(QH::PKG::AbstractData *pkg, const QH::NodeId &sender) {
|
2020-09-15 21:16:35 +03:00
|
|
|
Q_UNUSED(sender);
|
|
|
|
|
2020-09-16 15:10:13 +03:00
|
|
|
auto ping = dynamic_cast<QH::PKG::Ping*>(pkg);
|
2020-09-15 21:16:35 +03:00
|
|
|
if (ping)
|
2020-09-21 16:50:31 +03:00
|
|
|
_ping.setAnsver(ping->ansver());
|
2020-09-15 21:16:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2020-09-16 15:10:13 +03:00
|
|
|
QH::PKG::Ping _ping;
|
2020-09-15 21:16:35 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
NetworkNodeTest::NetworkNodeTest() {
|
|
|
|
_nodeA = new TestingNetworkClient();
|
2020-09-15 22:07:49 +03:00
|
|
|
_nodeB = new QH::NetworkNode();
|
2020-09-15 21:16:35 +03:00
|
|
|
_nodeC = new TestingNetworkClient();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
NetworkNodeTest::~NetworkNodeTest() {
|
2021-02-01 15:10:57 +03:00
|
|
|
_nodeA->softDelete();
|
|
|
|
_nodeB->softDelete();
|
|
|
|
_nodeC->softDelete();
|
2020-09-15 21:16:35 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void NetworkNodeTest::test() {
|
|
|
|
QVERIFY(dbTest());
|
|
|
|
QVERIFY(powerTest());
|
|
|
|
QVERIFY(connectNetworkTest());
|
|
|
|
QVERIFY(transportDataTest());
|
|
|
|
|
|
|
|
// QVERIFY(performanceTest());
|
|
|
|
// QVERIFY(securityTest());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool NetworkNodeTest::powerTest() {
|
2020-09-15 22:07:49 +03:00
|
|
|
auto _nodeAPtr = new QH::NetworkNode();
|
2020-09-15 21:16:35 +03:00
|
|
|
|
|
|
|
if (!_nodeAPtr->run(TEST_LOCAL_HOST, TEST_PORT, "powerTest")) {
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2021-02-01 15:10:57 +03:00
|
|
|
_nodeAPtr->softDelete();
|
2020-09-15 21:16:35 +03:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool NetworkNodeTest::dbTest() {
|
|
|
|
auto node = new NetworkNodeUnitTests;
|
|
|
|
|
|
|
|
if (!node->test()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-02-01 15:10:57 +03:00
|
|
|
node->softDelete();
|
2020-09-15 21:16:35 +03:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool NetworkNodeTest::connectNetworkTest() {
|
|
|
|
int nodeAPort = TEST_PORT + 0;
|
|
|
|
int nodeBPort = TEST_PORT + 1;
|
|
|
|
int nodeCPort = TEST_PORT + 2;
|
|
|
|
|
|
|
|
|
2020-09-15 22:07:49 +03:00
|
|
|
auto _nodeAPtr = dynamic_cast<QH::NetworkNode*>(_nodeA);
|
|
|
|
auto _nodeBPtr = dynamic_cast<QH::NetworkNode*>(_nodeB);
|
|
|
|
auto _nodeCPtr = dynamic_cast<QH::NetworkNode*>(_nodeC);
|
2020-09-15 21:16:35 +03:00
|
|
|
|
|
|
|
if (!_nodeAPtr->run(TEST_LOCAL_HOST, nodeAPort, "TestNodeA")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!_nodeBPtr->run(TEST_LOCAL_HOST, nodeBPort, "TestNodeB")) {
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
if (!_nodeCPtr->run(TEST_LOCAL_HOST, nodeCPort, "TestNodeC")) {
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
auto nodeA = _nodeAPtr->nodeId();
|
|
|
|
auto nodeB = _nodeBPtr->nodeId();
|
|
|
|
auto nodeC = _nodeCPtr->nodeId();
|
|
|
|
|
|
|
|
|
|
|
|
auto addNodeRequest = [_nodeAPtr, nodeBPort, nodeCPort, _nodeBPtr, nodeC]() {
|
2020-09-15 22:07:49 +03:00
|
|
|
_nodeAPtr->addNode(QH::HostAddress(TEST_LOCAL_HOST, nodeBPort));
|
|
|
|
_nodeBPtr->addNode(QH::HostAddress(TEST_LOCAL_HOST, nodeCPort));
|
2020-09-15 21:16:35 +03:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
auto checkNode = [_nodeAPtr, _nodeBPtr](){
|
|
|
|
return _nodeAPtr->confirmendCount() && _nodeBPtr->confirmendCount();
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!funcPrivateConnect(addNodeRequest, checkNode)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// need to wait for add node
|
|
|
|
|
|
|
|
auto request = [_nodeAPtr, nodeC]() {
|
|
|
|
return _nodeAPtr->ping(nodeC);
|
|
|
|
};
|
|
|
|
|
|
|
|
auto client = dynamic_cast<TestingNetworkClient*>(_nodeAPtr);
|
|
|
|
|
|
|
|
auto check = [client](){
|
|
|
|
return client->getPing().ansver();
|
|
|
|
};
|
|
|
|
|
|
|
|
return funcPrivateConnect(request, check);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool NetworkNodeTest::transportDataTest() {
|
|
|
|
auto coreNode = getCoreNode();
|
|
|
|
|
|
|
|
auto network = generateNetworkNode(30);
|
|
|
|
|
|
|
|
if (!(network.size() && coreNode->confirmendCount() == 30)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool NetworkNodeTest::performanceTest() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool NetworkNodeTest::securityTest() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-01-13 18:35:44 +03:00
|
|
|
bool NetworkNodeTest::testICtypto() {
|
|
|
|
// check
|
|
|
|
if (!validationCrypto<QH::QSecretRSA2048>()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-09-15 21:16:35 +03:00
|
|
|
|
|
|
|
|