mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
298 lines
13 KiB
Plaintext
298 lines
13 KiB
Plaintext
<%@ page class="AdminNodeServerTestPage" %>
|
|
<%@ page form="true" %>
|
|
<%@ page compressed="true" %>
|
|
<%@ page baseClass="PageRequestMessagedHandler" %>
|
|
<%@ header include="PageRequestMessagedHandler.h" %>
|
|
<%!
|
|
|
|
#include "../controller/NodeServer.h"
|
|
#include "../controller/User.h"
|
|
#include "../controller/HederaTopic.h"
|
|
#include "../lib/DataTypeConverter.h"
|
|
#include "../lib/Profiler.h"
|
|
#include "../lib/JsonRPCRequest.h"
|
|
#include "../model/gradido/Transaction.h"
|
|
|
|
#include "Poco/Thread.h"
|
|
#include "Poco/DateTime.h"
|
|
#include "Poco/JSON/Stringifier.h"
|
|
|
|
enum PageType
|
|
{
|
|
PAGE_CHOOSE_TEST,
|
|
PAGE_RUN_4_SET_TEST,
|
|
PAGE_GET_TRANSACTION_RPC_CALL
|
|
};
|
|
|
|
%>
|
|
<%%
|
|
const char* pageName = "Node Server Test";
|
|
PageType page = PAGE_CHOOSE_TEST;
|
|
Poco::AutoPtr<controller::NodeServer> node_server;
|
|
Poco::AutoPtr<controller::User> user;
|
|
Poco::AutoPtr<controller::HederaTopic> hedera_topic;
|
|
int hedera_timeout = 9;
|
|
|
|
bool steps[6]; memset(steps, 1, 6 * sizeof(bool));
|
|
|
|
|
|
if(!form.empty())
|
|
{
|
|
auto node_server_id_string = form.get("test-node-servers", "");
|
|
if(node_server_id_string != "") {
|
|
int node_server_id = 0;
|
|
if(DataTypeConverter::NUMBER_PARSE_OKAY == DataTypeConverter::strToInt(node_server_id_string, node_server_id )) {
|
|
node_server = controller::NodeServer::load(node_server_id);
|
|
}
|
|
}
|
|
auto topic_id_string = form.get("test-hedera-topic", "");
|
|
if(topic_id_string != "") {
|
|
int topic_id = 0;
|
|
if(DataTypeConverter::NUMBER_PARSE_OKAY == DataTypeConverter::strToInt(topic_id_string, topic_id)) {
|
|
hedera_topic = controller::HederaTopic::load(topic_id);
|
|
}
|
|
}
|
|
auto test_timeout_string = form.get("test-timeout", "");
|
|
if(test_timeout_string != "") {
|
|
DataTypeConverter::strToInt(test_timeout_string, hedera_timeout);
|
|
}
|
|
auto submit = form.get("submit", "");
|
|
if(submit == "Run 4-Test") {
|
|
page = PAGE_RUN_4_SET_TEST;
|
|
} else if(submit == "json-rpc getTransactions") {
|
|
page = PAGE_GET_TRANSACTION_RPC_CALL;
|
|
}
|
|
std::string step_temp;
|
|
for(int i = 0; i < 6; i++) {
|
|
std::string name = "step-";
|
|
name += std::to_string(i+2);
|
|
step_temp = form.get(name, "");
|
|
if(step_temp == "1") {
|
|
steps[i] = true;
|
|
} else {
|
|
steps[i] = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
auto node_servers = controller::NodeServer::load(model::table::NODE_SERVER_GRADIDO_NODE);
|
|
auto hedera_topics = controller::HederaTopic::listAll();
|
|
|
|
%><%@ include file="header_large.cpsp" %>
|
|
<%= getErrorsHtml() %>
|
|
<div class="center-form-container">
|
|
<!-- Tab links -->
|
|
<div class="tab">
|
|
<button class="tablinks <% if(PAGE_RUN_4_SET_TEST == page) { %> active <% } %>" onclick="openTab(event, 'test-4')">Test 4-Set (2 AddMember, Creation, Transfer)</button>
|
|
<button class="tablinks <% if(PAGE_GET_TRANSACTION_RPC_CALL == page) { %> active <% } %>" onclick="openTab(event, 'gn-jsonrpc')" title="call via json-rpc to gradido node with getTransactions">getTransactions</button>
|
|
</div>
|
|
<div id="test-4" class="tabcontent" <% if(PAGE_RUN_4_SET_TEST == page) { %> style="display:block" <% } %>>
|
|
<div class="center-form-title">
|
|
<h3>Test 4-Set (2 AddMember, Creation, Transfer)</</h3>
|
|
</div>
|
|
<div class="center-form-form">
|
|
<form method="POST" action="<%= getBaseUrl() %>/adminNodeServerTest">
|
|
<p>1. Create two new accounts and show user public keys for comparisation</p>
|
|
<p><input class="form-checkbox" type="checkbox" <% if(steps[0]) { %> checked="checked" <% } %> name="step-2" value="1"/> 2. Send a add-member transaction to hedera topic with one signature (first user)</p>
|
|
<p><input class="form-checkbox" type="checkbox" <% if(steps[1]) { %> checked="checked" <% } %> name="step-3" value="1"/> 3. Send a add-member transaction to hedera topic with two signatures (first user and second user)</p>
|
|
<p><input class="form-checkbox" type="checkbox" <% if(steps[2]) { %> checked="checked" <% } %> name="step-4" value="1"/> 4. Send a creation transaction to second user, signed by first user</p>
|
|
<p><input class="form-checkbox" type="checkbox" <% if(steps[3]) { %> checked="checked" <% } %> name="step-5" value="1"/> 5. Send a transfer transaction from second user to first user signed by second user</p>
|
|
<p><input class="form-checkbox" type="checkbox" <% if(steps[4]) { %> checked="checked" <% } %> name="step-6" value="1"/> 6. Wait x seconds to give hedera time to process transactions</p>
|
|
<p><input class="form-checkbox" type="checkbox" <% if(steps[5]) { %> checked="checked" <% } %> name="step-7" value="1"/> 7. Ask choosen node for transaction and print result</p>
|
|
|
|
<label class="form-label" for="test-node-servers">Node Server for tests</label>
|
|
<% if(node_servers.size() == 0) { %>
|
|
<a href="<%= getBaseUrl() %>/nodes"><span class="link-title">Edit Node-Servers</span></a>
|
|
<% } %>
|
|
<select name="test-node-servers" id="test-node-servers">
|
|
<% for(auto it = node_servers.begin(); it != node_servers.end(); it++) {
|
|
auto model = (*it)->getModel();
|
|
%>
|
|
<option title="<%= model->toString() %>" value="<%= model->getID() %>" <% if(!node_server.isNull() && node_server->getModel()->getID() == model->getID()) {%>selected="selected"<% } %>><%= model->getUrlWithPort() %>, group: <%= model->getGroupId() %></option>
|
|
<% } %>
|
|
</select>
|
|
<label class="form-label" for="test-hedera-topic">Hedera Topic for tests</label>
|
|
<% if(hedera_topics.size() == 0) { %>
|
|
<a href="<%= getBaseUrl() %>/topic"><span class="link-title">Edit Hedera-Topics</span></a>
|
|
<% } %>
|
|
<select name="test-hedera-topic" id="test-hedera-topic">
|
|
<% for(auto it = hedera_topics.begin(); it != hedera_topics.end(); it++) {
|
|
auto model = (*it)->getModel();
|
|
auto hedera_account = (*it)->getAutoRenewAccount();
|
|
if(hedera_account->getModel()->getNetworkType() != ServerConfig::HEDERA_TESTNET) {
|
|
continue;
|
|
}
|
|
%>
|
|
<option title="<%= model->toString() %>" value="<%= model->getID() %>" <% if(!hedera_topic.isNull() && hedera_topic->getModel()->getID() == model->getID()) {%>selected="selected"<% } %>><%= model->getName() %>, group: <%= model->getGroupId() %></option>
|
|
<% } %>
|
|
</select>
|
|
<label class="form-label" for="test-timeout">Timeout waiting for hedera in seconds</label>
|
|
<input name="test-timeout" id="test-timeout" type="number" value="<%= hedera_timeout %>"> seconds
|
|
<input class="center-form-submit form-button" type="submit" name="submit" value="Run 4-Test">
|
|
</form>
|
|
</div>
|
|
</div>
|
|
<div id="gn-jsonrpc" class="tabcontent" <% if(PAGE_GET_TRANSACTION_RPC_CALL == page) { %> style="display:block" <% } %>>
|
|
<div class="center-form-title">
|
|
<h3>Test 4-Set (2 AddMember, Creation, Transfer)</</h3>
|
|
</div>
|
|
<div class="center-form-form">
|
|
<form method="POST" action="<%= getBaseUrl() %>/adminNodeServerTest">
|
|
<label class="form-label" for="test-node-servers">Node Server to call</label>
|
|
<% if(node_servers.size() == 0) { %>
|
|
<a href="<%= getBaseUrl() %>/nodes"><span class="link-title">Edit Node-Servers</span></a>
|
|
<% } %>
|
|
<select name="test-node-servers" id="test-node-servers">
|
|
<% for(auto it = node_servers.begin(); it != node_servers.end(); it++) {
|
|
auto model = (*it)->getModel();
|
|
%>
|
|
<option title="<%= model->toString() %>" value="<%= model->getID() %>" <% if(!node_server.isNull() && node_server->getModel()->getID() == model->getID()) {%>selected="selected"<% } %>><%= model->getUrlWithPort() %>, group: <%= model->getGroupId() %></option>
|
|
<% } %>
|
|
</select>
|
|
<input class="center-form-submit form-button" type="submit" name="submit" value="json-rpc getTransactions">
|
|
</form>
|
|
</div>
|
|
</div>
|
|
<% if(PAGE_RUN_4_SET_TEST == page && !hedera_topic.isNull() && !node_server.isNull()) { %>
|
|
<ul>
|
|
<li>
|
|
<p>1. Create two new accounts and show user public keys for comparisation: </p>
|
|
<%
|
|
Profiler time2;
|
|
auto group_id = hedera_topic->getModel()->getGroupId();
|
|
auto user_group = controller::Group::load(group_id);
|
|
auto mnemonic_type = ServerConfig::MNEMONIC_BIP0039_SORTED_ORDER;
|
|
|
|
std::string password1 = "hsaj(2askaslASlllak3wjjeudsaj";
|
|
auto user_1 = controller::User::create("testEmail@google.de", "Max", "Mustermann", group_id);
|
|
auto passphrase_1 = Passphrase::generate(&ServerConfig::g_Mnemonic_WordLists[mnemonic_type]);
|
|
auto gradido_key_pair_1 = KeyPairEd25519::create(passphrase_1);
|
|
user_1->setGradidoKeyPair(gradido_key_pair_1);
|
|
user_1->login(password1);
|
|
|
|
std::string password2 = "uweia8saiSale,dsasA";
|
|
auto user_2 = controller::User::create("testEmail2@google.de", "MJax", "Mustrermann", group_id);
|
|
auto passphrase_2 = Passphrase::generate(&ServerConfig::g_Mnemonic_WordLists[mnemonic_type]);
|
|
auto gradido_key_pair_2 = KeyPairEd25519::create(passphrase_2);
|
|
user_2->setGradidoKeyPair(gradido_key_pair_2);
|
|
user_2->login(password2);
|
|
%>
|
|
<p>User 1: <%= user_1->getPublicHex() %></p>
|
|
<p>User 2: <%= user_2->getPublicHex() %></p>
|
|
<p>Time: <%= time2.string() %>
|
|
</li>
|
|
<li>
|
|
<p>2. Send a add-member transaction to hedera topic with one signature (first user)</p>
|
|
<%
|
|
time2.reset();
|
|
if(!steps[0]) { %>
|
|
<p>skipped</p>
|
|
<% } else {
|
|
auto transaction1 = model::gradido::Transaction::createGroupMemberUpdate(user_1, user_group);
|
|
transaction1->getTransactionBody()->getGroupMemberUpdate()->setMinSignatureCount(1);
|
|
transaction1->sign(user_1);
|
|
auto transaction1_json = transaction1->getTransactionAsJson(true);
|
|
%>
|
|
<p><%= DataTypeConverter::replaceNewLineWithBr(transaction1_json) %></p>
|
|
<% } %>
|
|
<p>Time: <%= time2.string() %>
|
|
</li>
|
|
<li>
|
|
<p>3. Send a add-member transaction to hedera topic with two signatures (first user and second user)</p>
|
|
<%
|
|
time2.reset();
|
|
if(!steps[1]) { %>
|
|
<p>skipped</p>
|
|
<% } else {
|
|
auto transaction2 = model::gradido::Transaction::createGroupMemberUpdate(user_2, user_group);
|
|
transaction2->getTransactionBody()->getGroupMemberUpdate()->setMinSignatureCount(2);
|
|
transaction2->sign(user_2);
|
|
transaction2->sign(user_1);
|
|
auto transaction2_json = transaction2->getTransactionAsJson(true);
|
|
%>
|
|
<p><%= DataTypeConverter::replaceNewLineWithBr(transaction2_json) %></p>
|
|
<% } %>
|
|
<p>Time: <%= time2.string() %>
|
|
</li>
|
|
<li>
|
|
<p>4. Send a creation transaction to second user, signed by first user</p>
|
|
<%
|
|
time2.reset();
|
|
if(!steps[2]) { %>
|
|
<p>skipped</p>
|
|
<% } else {
|
|
auto transaction3 = model::gradido::Transaction::createCreation(user_2, 10000000, Poco::DateTime(), "Test Creation");
|
|
transaction3->sign(user_1);
|
|
auto transaction3_json = transaction3->getTransactionAsJson(true);
|
|
%>
|
|
<p><%= DataTypeConverter::replaceNewLineWithBr(transaction3_json) %></p>
|
|
<% } %>
|
|
<p>Time: <%= time2.string() %></p>
|
|
</li>
|
|
<li>
|
|
<p>5. Send a transfer transaction from second user to first user signed by second user</p>
|
|
<%
|
|
time2.reset();
|
|
if(!steps[3]) { %>
|
|
<p>skipped</p>
|
|
<% } else {
|
|
auto user_1_pubkey = user_1->getModel()->getPublicKeyCopy();
|
|
auto transaction4 = model::gradido::Transaction::createTransfer(user_2, user_1_pubkey, user_group, 5000000, "Test Transfer");
|
|
auto transaction4_json = transaction4[0]->getTransactionAsJson(true);
|
|
%>
|
|
<p><%= DataTypeConverter::replaceNewLineWithBr(transaction4_json) %></p>
|
|
<% } %>
|
|
<p>Time: <%= time2.string() %></p>
|
|
</li>
|
|
<li>
|
|
<p>6. Wait <%= hedera_timeout %> seconds to give hedera time to process transactions</p>
|
|
<% if(!steps[4]) { %>
|
|
<p>skipped</p>
|
|
<% } else {
|
|
Poco::Thread::sleep(hedera_timeout * 1000);
|
|
} %>
|
|
</li>
|
|
<li>
|
|
<p>7. Ask choosen node for transaction and print result</p>
|
|
<% time2.reset();
|
|
if(!steps[5] || node_server.isNull()) {
|
|
%><p>skipped</p>
|
|
<% } else {
|
|
auto node_server_model = node_server->getModel();
|
|
JsonRPCRequest jsonrpc(node_server_model->getUrl(), node_server_model->getPort());
|
|
Poco::JSON::Object params;
|
|
params.set("groupAlias", user_group->getModel()->getAlias());
|
|
params.set("lastKnownSequenceNumber", 0);
|
|
auto gn_answear = jsonrpc.request("getTransactions", params);
|
|
if(!gn_answear.isNull()) {
|
|
std::stringstream ss;
|
|
Poco::JSON::Stringifier::stringify(gn_answear, ss, 4, -1, Poco::JSON_PRESERVE_KEY_ORDER); %>
|
|
<%= DataTypeConverter::replaceNewLineWithBr(ss.str()) %><%
|
|
}
|
|
} %>
|
|
<p>Time: <%= time2.string() %></p>
|
|
</li>
|
|
</ul>
|
|
<% } else if(PAGE_GET_TRANSACTION_RPC_CALL == page && !node_server.isNull()) {
|
|
Profiler time3;
|
|
auto node_server_model = node_server->getModel();
|
|
auto user_group = controller::Group::load(node_server_model->getGroupId());
|
|
JsonRPCRequest jsonrpc(node_server_model->getUrl(), node_server_model->getPort());
|
|
Poco::JSON::Object params;
|
|
params.set("groupAlias", user_group->getModel()->getAlias());
|
|
params.set("lastKnownSequenceNumber", 0);
|
|
auto gn_answear = jsonrpc.request("getTransactions", params);
|
|
if(!gn_answear.isNull()) {
|
|
std::stringstream ss;
|
|
Poco::JSON::Stringifier::stringify(gn_answear, ss, 4, -1, Poco::JSON_PRESERVE_KEY_ORDER);
|
|
//printf("result: %s\n", ss.str().data());%>
|
|
<%= DataTypeConverter::replaceNewLineWithBr(ss.str()) %><%
|
|
}
|
|
%>
|
|
<p>Time: <%= time3.string() %></p>
|
|
<% } %>
|
|
|
|
</div>
|
|
<script type="text/javascript" src="<%= ServerConfig::g_php_serverPath %>/js/tabs.js"></script>
|
|
<%@ include file="footer.cpsp" %>
|