diff --git a/sdk/tests/integration/ClientIntegrationTest.cc b/sdk/tests/integration/ClientIntegrationTest.cc index 712a1ee4d..fc21a9405 100644 --- a/sdk/tests/integration/ClientIntegrationTest.cc +++ b/sdk/tests/integration/ClientIntegrationTest.cc @@ -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 #include #include #include #include +#include +#include +#include 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; } @@ -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 networksMap; + // unordered_map networkAccountsMap; + // unordered_map::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"; @@ -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 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(); +} \ No newline at end of file