Skip to content

Add unit tests for sanity_check.h input validators (opt-in gtest) - #136

Open
parthod0x wants to merge 1 commit into
qubic:mainfrom
parthod0x:test/sanity-check-unit-tests
Open

parthod0x wants to merge 1 commit into
qubic:mainfrom
parthod0x:test/sanity-check-unit-tests

Conversation

@parthod0x

Copy link
Copy Markdown
Contributor

Summary

qubic-cli currently has no unit tests — test_utils.* are interactive, node-connected helpers compiled into the binary, not isolated tests. This adds a first, self-contained gtest suite for the pure input validators in sanity_check.h:

  • isValidIpAddress — accepts well-formed IPv4, rejects out-of-range/malformed;
  • death tests (exit code 1) for the validators that abort on bad input: sanityCheckValidAssetName, sanityCheckTxType, checkValidEpoch, sanityCheckMainAuxStatus, sanityCheckUnitofMeasurement, sanityCheckLoggingMode, sanityCheckExtraDataSize.

11 tests across 8 suites, all passing.

No heavy dependencies

The suite includes only sanity_check.h and supplies the two symbols that header expects from its usual include context (DEFAULT_SEED and a stubbed checkSumIdentity), so it needs neither the core submodule nor the crypto/network code — it compiles and runs on its own.

Opt-in, nothing else changes

Tests are gated behind -DQUBIC_CLI_BUILD_TESTS=ON (default OFF), so the normal build and existing CI are untouched. googletest is pulled in with FetchContent.

cmake -DQUBIC_CLI_BUILD_TESTS=ON -S . -B build
cmake --build build --target qubic-cli-tests && ctest --test-dir build

Intended as a seed others can extend; happy to wire it into CI as a follow-up if that's wanted.

qubic-cli has no unit tests today (test_utils.* are interactive, node-connected
helpers compiled into the binary). This adds a first, self-contained gtest suite
for the pure input validators in sanity_check.h: isValidIpAddress plus death
tests (exit code 1) for the validators that abort on bad input
(sanityCheckValidAssetName, sanityCheckTxType, checkValidEpoch,
sanityCheckMainAuxStatus, sanityCheckUnitofMeasurement, sanityCheckLoggingMode,
sanityCheckExtraDataSize).

The suite needs neither the core submodule nor the crypto/network code: it
includes only sanity_check.h and provides the two symbols that header expects
from its usual include context (DEFAULT_SEED and a stubbed checkSumIdentity).

Tests are opt-in via -DQUBIC_CLI_BUILD_TESTS=ON (default OFF), so the normal
build and existing CI are unchanged; googletest is fetched with FetchContent.

  cmake -DQUBIC_CLI_BUILD_TESTS=ON -S . -B build
  cmake --build build --target qubic-cli-tests && ctest --test-dir build

11 tests across 8 suites, all passing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant