Skip to content

[Good First Issue]: Replace manual membership loop with std::any_of in NetworkIntegrationTests.cc #1280

@rwalworth

Description

@rwalworth

🆕🐥 First-Time Friendly

This issue is especially welcoming for people who are new to contributing to the Hiero C++ SDK.

We know that opening your first pull request can feel like a big step.
Issues labeled Good First Issue are designed to make that experience easier, clearer, and more comfortable.

No prior knowledge of Hiero, Hedera, or distributed ledger technology is required.
Just a basic familiarity with C++ and Git is more than enough to get started.


👾 Description of the Issue

The file:

src/sdk/tests/integration/NetworkIntegrationTests.cc

contains a test called GetNodeAccountIdsForExecuteReturnsHealthyNodes. Inside that test, there is a nested loop that checks whether each returned AccountId exists somewhere in the network map:

for (const auto& accountId : accountIds)
{
    bool found = false;
    for (const auto& [url, mapAccountId] : networkMap)
    {
        if (accountId == mapAccountId) { found = true; break; }
    }
    EXPECT_TRUE(found);
}

This pattern uses a mutable found flag and a manual inner loop to perform a membership check. The C++ standard library already provides std::any_of for exactly this purpose, and it is used in other parts of the SDK codebase. The current code is correct, but can be simplified to be more idiomatic.


💡 Proposed Solution

Replace the manual inner loop with std::any_of from <algorithm>, removing the mutable found variable:

for (const auto& accountId : accountIds)
{
    const bool found = std::any_of(networkMap.cbegin(),
                                   networkMap.cend(),
                                   [&accountId](const auto& entry) { return entry.second == accountId; });
    EXPECT_TRUE(found);
}

This change:

  • Does not modify any test logic or assertions
  • Does not change any SDK behavior or public APIs
  • Removes the mutable found flag
  • Matches the coding style used elsewhere in the SDK

👩‍💻 Implementation Steps (End-to-End)

  • Open src/sdk/tests/integration/NetworkIntegrationTests.cc
  • Locate the test GetNodeAccountIdsForExecuteReturnsHealthyNodes
  • Find the nested loop block (shown above in the description)
  • Replace the inner for loop and bool found = false; with the std::any_of version shown in the proposed solution
  • Verify <algorithm> is included at the top of the file — if it is not already present, add #include <algorithm> with the other standard library includes
  • Confirm the test still compiles and passes (CI will run automatically when you open a PR)

The change touches only this one test function in this one file.


✅ Acceptance Criteria

To merge a pull request for this issue:

  • Scope: Changes are limited to the loop replacement in NetworkIntegrationTests.cc
  • Behavior: No SDK behavior, test logic, or assertions are changed
  • Tests: Existing CI checks pass
  • Review: All code review feedback addressed

📋 Step-by-Step Contribution Guide

To help your first contribution go as smoothly as possible, we recommend following these steps:

  • Comment /assign to request the issue
  • Wait for assignment
  • Fork the repository and create a branch
  • Set up the project by following the instructions in README.md
  • Make the requested changes
  • Sign each commit using -s -S
  • Push your branch and open a pull request

Read Workflow Guide for step-by-step workflow guidance.
Read README.md for setup instructions.

❗ Pull requests cannot be merged without S and s signed commits.
See the Signing Guide.


🤔 Additional Information

If you need help, reach out to the @hiero-ledger/hiero-sdk-good-first-issue-support team.

You can also join our community on Discord:
Hiero-SDK-C++

Maintainers are happy to help first-time contributors succeed!

Metadata

Metadata

Labels

kind: testingAdding or improving unit tests, integration tests, or test infrastructurepriority: lowNon-urgent tasks, nice-to-have improvements, or minor issuesskill: good first issueSimple, well-scoped tasks ideal for someone new to the repository or open sourcestatus: in progressSomeone is actively working on this issue

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions