diff --git a/.github/workflows/zxc-build-library.yaml b/.github/workflows/zxc-build-library.yaml index 2fcda8ce8..4eb38b2d4 100644 --- a/.github/workflows/zxc-build-library.yaml +++ b/.github/workflows/zxc-build-library.yaml @@ -39,7 +39,7 @@ jobs: sudo apt-get update sudo apt-get install -y --allow-downgrades \ ca-certificates \ - curl=7.81.0-1ubuntu1.13 \ + curl=7.81.0-1ubuntu1.14 \ gnupg \ lsb-release sudo mkdir -p /etc/apt/keyrings diff --git a/sdk/main/include/Client.h b/sdk/main/include/Client.h index bb283a55d..0d185b794 100644 --- a/sdk/main/include/Client.h +++ b/sdk/main/include/Client.h @@ -121,6 +121,14 @@ class Client */ void close(); + /** + * Replace all nodes in this Client with a new set of nodes from the Hedera network. + * + * @param networkMap The map with string representation of node addresses with their corresponding accountId. + * @return A reference to this Client object with the newly-set operator account ID from the map. + */ + Client& setNetwork(const std::unordered_map& networkMap); + /** * Set the length of time a request sent by this Client can be processed before it times out. * diff --git a/sdk/main/src/Client.cc b/sdk/main/src/Client.cc index 9639c0748..2f07762d1 100644 --- a/sdk/main/src/Client.cc +++ b/sdk/main/src/Client.cc @@ -174,6 +174,7 @@ Client Client::forNetwork(const std::unordered_map& netw { Client client; client.mImpl->mNetwork = std::make_shared(internal::Network::forNetwork(networkMap)); + client.mImpl->mMirrorNetwork = nullptr; return client; } @@ -209,6 +210,14 @@ void Client::close() } } +//----- +Client& Client::setNetwork(const std::unordered_map& networkMap) +{ + mImpl->mNetwork = std::make_shared(internal::Network::forNetwork(networkMap)); + mImpl->mMirrorNetwork = nullptr; + return *this; +} + //----- Client& Client::setRequestTimeout(const std::chrono::duration& timeout) { diff --git a/sdk/tests/integration/ClientIntegrationTest.cc b/sdk/tests/integration/ClientIntegrationTest.cc index 4112822b3..8a8ca118e 100644 --- a/sdk/tests/integration/ClientIntegrationTest.cc +++ b/sdk/tests/integration/ClientIntegrationTest.cc @@ -17,25 +17,38 @@ * limitations under the License. * */ +#include "AccountBalance.h" +#include "AccountBalanceQuery.h" #include "AccountCreateTransaction.h" #include "AccountId.h" +#include "AccountInfo.h" +#include "AccountInfoQuery.h" +#include "BaseIntegrationTest.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 +class ClientIntegrationTest : public BaseIntegrationTest { protected: [[nodiscard]] inline const std::string_view& getJsonNetworkTag() const { return mJsonNetworkTag; } @@ -47,22 +60,12 @@ class ClientIntegrationTest : public ::testing::Test [[nodiscard]] inline const AccountId& getAccountId() const { return mAccountId; } [[nodiscard]] inline const std::string getPathToJSON() const { return mFilePath.string(); } - [[nodiscard]] inline const std::chrono::milliseconds getNegativeBackoffTime() const { return mNegativeBackoffTime; } - [[nodiscard]] inline const std::chrono::milliseconds getZeroBackoffTime() const { return mZeroBackoffTime; } - [[nodiscard]] inline const std::chrono::milliseconds getBelowMinBackoffTime() const { return mBelowMinBackoffTime; } - [[nodiscard]] inline const std::chrono::milliseconds getAboveMaxBackoffTime() const { return mAboveMaxBackoffTime; } - private: const std::string_view mJsonNetworkTag = "network"; const std::string_view mJsonOperatorTag = "operator"; const std::string_view mJsonAccountIdTag = "accountId"; const std::string_view mJsonPrivateKeyTag = "privateKey"; - const std::chrono::milliseconds mNegativeBackoffTime = std::chrono::milliseconds(-1); - const std::chrono::milliseconds mZeroBackoffTime = std::chrono::milliseconds(0); - const std::chrono::milliseconds mBelowMinBackoffTime = DEFAULT_MIN_BACKOFF - std::chrono::milliseconds(1); - const std::chrono::milliseconds mAboveMaxBackoffTime = DEFAULT_MAX_BACKOFF + std::chrono::milliseconds(1); - const std::string_view mAccountIdStr = "0.0.3"; const AccountId mAccountId = AccountId::fromString("0.0.3"); const std::filesystem::path mFilePath = (std::filesystem::current_path() / "local_node.json").string(); @@ -124,52 +127,36 @@ TEST_F(ClientIntegrationTest, ConnectToLocalNode) } //----- -TEST_F(ClientIntegrationTest, SetInvalidMinBackoff) +TEST_F(ClientIntegrationTest, SetNetworkIsWorkingCorrectly) { // Given - std::unordered_map networkMap; - Client client = Client::forNetwork(networkMap); - - // When / Then - EXPECT_THROW(client.setMinBackoff(getNegativeBackoffTime()), std::invalid_argument); // INVALID_ARGUMENT - EXPECT_THROW(client.setMinBackoff(getAboveMaxBackoffTime()), std::invalid_argument); // INVALID_ARGUMENT -} + const AccountId accountId_3 = AccountId::fromString("0.0.3"); + const AccountId accountId_4 = AccountId::fromString("0.0.4"); + const AccountId accountId_5 = AccountId::fromString("0.0.5"); + const AccountId accountId_6 = AccountId::fromString("0.0.6"); + const AccountId accountId_7 = AccountId::fromString("0.0.7"); + + AccountBalance accountBalance_3; + AccountBalance accountBalance_4; + AccountBalance accountBalance_5; + AccountBalance accountBalance_6; + AccountBalance accountBalance_7; -//----- -TEST_F(ClientIntegrationTest, SetValidMinBackoff) -{ - // Given std::unordered_map networkMap; - Client client = Client::forNetwork(networkMap); + networkMap.insert(std::pair("34.94.106.61:50211", accountId_3)); + networkMap.insert(std::pair("35.237.119.55:50211", accountId_4)); + networkMap.insert(std::pair("35.245.27.193:50211", accountId_5)); - // When / Then - EXPECT_NO_THROW(client.setMinBackoff(getZeroBackoffTime())); - EXPECT_NO_THROW(client.setMinBackoff(DEFAULT_MIN_BACKOFF)); - EXPECT_NO_THROW(client.setMinBackoff(DEFAULT_MAX_BACKOFF)); -} - -//----- -TEST_F(ClientIntegrationTest, SetInvalidMaxBackoff) -{ - // Given - std::unordered_map networkMap; Client client = Client::forNetwork(networkMap); // When / Then - EXPECT_THROW(client.setMaxBackoff(getNegativeBackoffTime()), std::invalid_argument); // INVALID_ARGUMENT - EXPECT_THROW(client.setMaxBackoff(getZeroBackoffTime()), std::invalid_argument); // INVALID_ARGUMENT - EXPECT_THROW(client.setMaxBackoff(getBelowMinBackoffTime()), std::invalid_argument); // INVALID_ARGUMENT - EXPECT_THROW(client.setMaxBackoff(getAboveMaxBackoffTime()), std::invalid_argument); // INVALID_ARGUMENT -} + std::unordered_map newNetworkMap; + newNetworkMap.insert(std::pair("35.237.119.55:50211", accountId_6)); + newNetworkMap.insert(std::pair("35.245.27.193:50211", accountId_7)); -//----- -TEST_F(ClientIntegrationTest, SetValidMaxBackoff) -{ - // Given - std::unordered_map networkMap; - Client client = Client::forNetwork(networkMap); + client.setNetwork(newNetworkMap); // When / Then - EXPECT_NO_THROW(client.setMaxBackoff(DEFAULT_MIN_BACKOFF)); - EXPECT_NO_THROW(client.setMaxBackoff(DEFAULT_MAX_BACKOFF)); -} \ No newline at end of file + ASSERT_NO_THROW(accountBalance_6 = AccountBalanceQuery().setAccountId(accountId_6).execute(client)); + ASSERT_NO_THROW(accountBalance_7 = AccountBalanceQuery().setAccountId(accountId_7).execute(client)); +} diff --git a/sdk/tests/unit/ClientTest.cc b/sdk/tests/unit/ClientTest.cc index 96686d7ea..d6db74f3c 100644 --- a/sdk/tests/unit/ClientTest.cc +++ b/sdk/tests/unit/ClientTest.cc @@ -42,10 +42,20 @@ class ClientTest : public ::testing::Test return mTestNetworkUpdatePeriod; } + [[nodiscard]] inline const std::chrono::milliseconds getNegativeBackoffTime() const { return mNegativeBackoffTime; } + [[nodiscard]] inline const std::chrono::milliseconds getZeroBackoffTime() const { return mZeroBackoffTime; } + [[nodiscard]] inline const std::chrono::milliseconds getBelowMinBackoffTime() const { return mBelowMinBackoffTime; } + [[nodiscard]] inline const std::chrono::milliseconds getAboveMaxBackoffTime() const { return mAboveMaxBackoffTime; } + private: const AccountId mAccountId = AccountId(10ULL); const std::unique_ptr mPrivateKey = ED25519PrivateKey::generatePrivateKey(); const std::chrono::duration mTestNetworkUpdatePeriod = std::chrono::seconds(2); + + const std::chrono::milliseconds mNegativeBackoffTime = std::chrono::milliseconds(-1); + const std::chrono::milliseconds mZeroBackoffTime = std::chrono::milliseconds(0); + const std::chrono::milliseconds mBelowMinBackoffTime = DEFAULT_MIN_BACKOFF - std::chrono::milliseconds(1); + const std::chrono::milliseconds mAboveMaxBackoffTime = DEFAULT_MAX_BACKOFF + std::chrono::milliseconds(1); }; //----- @@ -108,3 +118,54 @@ TEST_F(ClientTest, SetNetworkUpdatePeriod) // Then EXPECT_EQ(client.getNetworkUpdatePeriod(), getTestNetworkUpdatePeriod()); } + +//----- +TEST_F(ClientTest, SetInvalidMinBackoff) +{ + // Given + std::unordered_map networkMap; + Client client = Client::forNetwork(networkMap); + + // When / Then + EXPECT_THROW(client.setMinBackoff(getNegativeBackoffTime()), std::invalid_argument); // INVALID_ARGUMENT + EXPECT_THROW(client.setMinBackoff(getAboveMaxBackoffTime()), std::invalid_argument); // INVALID_ARGUMENT +} + +//----- +TEST_F(ClientTest, SetValidMinBackoff) +{ + // Given + std::unordered_map networkMap; + Client client = Client::forNetwork(networkMap); + + // When / Then + EXPECT_NO_THROW(client.setMinBackoff(getZeroBackoffTime())); + EXPECT_NO_THROW(client.setMinBackoff(DEFAULT_MIN_BACKOFF)); + EXPECT_NO_THROW(client.setMinBackoff(DEFAULT_MAX_BACKOFF)); +} + +//----- +TEST_F(ClientTest, SetInvalidMaxBackoff) +{ + // Given + std::unordered_map networkMap; + Client client = Client::forNetwork(networkMap); + + // When / Then + EXPECT_THROW(client.setMaxBackoff(getNegativeBackoffTime()), std::invalid_argument); // INVALID_ARGUMENT + EXPECT_THROW(client.setMaxBackoff(getZeroBackoffTime()), std::invalid_argument); // INVALID_ARGUMENT + EXPECT_THROW(client.setMaxBackoff(getBelowMinBackoffTime()), std::invalid_argument); // INVALID_ARGUMENT + EXPECT_THROW(client.setMaxBackoff(getAboveMaxBackoffTime()), std::invalid_argument); // INVALID_ARGUMENT +} + +//----- +TEST_F(ClientTest, SetValidMaxBackoff) +{ + // Given + std::unordered_map networkMap; + Client client = Client::forNetwork(networkMap); + + // When / Then + EXPECT_NO_THROW(client.setMaxBackoff(DEFAULT_MIN_BACKOFF)); + EXPECT_NO_THROW(client.setMaxBackoff(DEFAULT_MAX_BACKOFF)); +} \ No newline at end of file