Skip to content

Commit

Permalink
167: Add test SelectHealtyNode in ClientIntegrationTest suite.
Browse files Browse the repository at this point in the history
Signed-off-by: Deyan Zhekov <[email protected]>
  • Loading branch information
deyanzz committed Jun 29, 2023
1 parent 63b7e03 commit 3f792ea
Showing 1 changed file with 105 additions and 0 deletions.
105 changes: 105 additions & 0 deletions sdk/tests/integration/ClientIntegrationTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,36 @@
*/
#include "AccountCreateTransaction.h"
#include "AccountId.h"
#include "AccountInfo.h"
#include "AccountInfoQuery.h"
#include "Client.h"
#include "ED25519PrivateKey.h"
#include "Hbar.h"
#include "PublicKey.h"
#include "TransactionReceipt.h"
#include "TransactionRecord.h"
#include "TransactionResponse.h"
#include "TransferTransaction.h"
#include "exceptions/UninitializedException.h"
#include "impl/Utilities.h"

#include <filesystem>
#include <fstream>
#include <gtest/gtest.h>
#include <iostream>
#include <nlohmann/json.hpp>
#include <string>
#include <string_view>
#include <unordered_map>

using json = nlohmann::json;
using namespace std;
using namespace Hedera;

class ClientIntegrationTest : public ::testing::Test
{
protected:
// [[nodiscard]] inline const Client& getTestClient() const { return mClient; }
[[nodiscard]] inline const std::string_view& getJsonNetworkTag() const { return mJsonNetworkTag; }
[[nodiscard]] inline const std::string_view& getJsonOperatorTag() const { return mJsonOperatorTag; }
[[nodiscard]] inline const std::string_view& getJsonAccountIdTag() const { return mJsonAccountIdTag; }
Expand All @@ -48,7 +58,52 @@ class ClientIntegrationTest : public ::testing::Test
[[nodiscard]] inline const AccountId& getAccountId() const { return mAccountId; }
[[nodiscard]] inline const std::string getPathToJSON() const { return mFilePath.string(); }

// void SetUp()
// {
// const string_view networkTag = "network";
// const string_view operatorTag = "operator";
// const string_view accountIdTag = "accountId";
// const string_view privateKeyTag = "privateKey";

// const string testPathToJSON = (filesystem::current_path() / "local_node.json").string();

// ifstream testInputFile(testPathToJSON, ios::in);

// unordered_map<string, string> networksMap;
// unordered_map<string, AccountId> networkAccountsMap;
// unordered_map<string, string>::iterator it;

// json jsonData = json::parse(testInputFile);
// jsonData[networkTag].get_to(networksMap);

// for (it = networksMap.begin(); it != networksMap.end(); it++)
// {
// const string_view accountIdStr = (*it).first;
// const string nodeAddressString = (*it).second;

// networkAccountsMap.try_emplace(nodeAddressString, AccountId::fromString(accountIdStr));
// }

// AccountId operatorAccountId;
// string operatorAccountPrivateKey;

// if (jsonData[operatorTag][accountIdTag].is_string() && jsonData[operatorTag][privateKeyTag].is_string())
// {
// string operatorAccountIdStr = jsonData[operatorTag][accountIdTag];
// operatorAccountPrivateKey = jsonData[operatorTag][privateKeyTag];

// operatorAccountId = AccountId::fromString(operatorAccountIdStr);
// }

// testInputFile.close();

// mClient = Client::forNetwork(networkAccountsMap);
// mClient.setOperator(operatorAccountId, ED25519PrivateKey::fromString(operatorAccountPrivateKey).get());
// }

private:
// Client mClient;

const std::string_view mJsonNetworkTag = "network";
const std::string_view mJsonOperatorTag = "operator";
const std::string_view mJsonAccountIdTag = "accountId";
Expand Down Expand Up @@ -113,3 +168,53 @@ TEST_F(ClientIntegrationTest, ConnectToLocalNode)
EXPECT_NE(client.getOperatorPublicKey(), nullptr);
EXPECT_FALSE(newAccountId.toString().empty());
}

//-----
TEST_F(ClientIntegrationTest, SelectHealtyNode)
{
// Given
const std::unique_ptr<PrivateKey> myPrivateKey = ED25519PrivateKey::fromString(
"302e020100300506032b6570042204202e000363977258a41f418cf84a7df9cf1e8ae98b72de86803e64846defa43054");
const Hbar amount(-1);
const AccountId myAccountId = AccountId::fromString("0.0.1359");
const AccountId newAccountId = AccountId::fromString("0.0.8918");

cout << "!!! Got myAccountId & newAccountId !!!" << endl << endl;

Client client = Client::forTestnet();
client.setOperator(myAccountId, myPrivateKey.get());

cout << "!!! START !!!" << endl << endl;
cout << std::chrono::system_clock::now().time_since_epoch().count() << endl << endl;

for (int i = 0; i < 1000; i++)
{
try
{
cout << "START for-loop !!!" << endl;

TransactionReceipt txReceipt;
EXPECT_NO_THROW(txReceipt = TransferTransaction()
.addHbarTransfer(myAccountId, amount)
.addHbarTransfer(newAccountId, amount.negated())
.freezeWith(client)
.sign(myPrivateKey.get())
.execute(client)
.getReceipt(client));

cout << "The transfer receipt for iteration " << (int)txReceipt.getStatus() << " is" << endl;

AccountInfo accountInfo;
EXPECT_NO_THROW(accountInfo = AccountInfoQuery().setAccountId(newAccountId).execute(client));

cout << "First Account accountInfo: " << accountInfo.mBalance.toTinybars() << endl;
}
catch (const std::exception&)
{
throw std::invalid_argument("DAMN");
}
}

cout << "!!! END !!!" << endl << endl;
cout << std::chrono::system_clock::now().time_since_epoch().count();
}

0 comments on commit 3f792ea

Please sign in to comment.