Skip to content

Conversation

@cuteolaf
Copy link
Contributor

@cuteolaf cuteolaf commented Jan 9, 2026

Summary by CodeRabbit

  • Tests
    • Expanded unit test coverage across core modules to validate configuration defaults, cryptographic signing/seed behavior, error conversions and serialization error paths, message and resource validations, schema descriptions and migration checks, state behaviors and versioned state migration, and ID/address formatting and uniqueness.

✏️ Tip: You can customize this high-level summary in your review settings.

Add 58 new tests across platform-core covering previously uncovered code paths:

- challenge.rs: Test ChallengeConfig::with_mechanism builder method
- crypto.rs: Add tests for seed fallback, sign_bytes, sign_data/hash_data serialization paths
- error.rs: Add conversion tests for io::Error, bincode::Error (serialization failures),
  and serde_json::Error, plus error display formatting
- message.rs: Test TaskProgressMessage, ChallengeContainerConfig validation (docker_image,
  timeouts, CPU/memory limits), MechanismWeightConfig builders, and development mode check
- schema_guard.rs: Test schema description methods, error formatting for SchemaMismatch
  and MissingVersion, const_hash determinism, and migration path verification
- state.rs: Test default_timestamp, production_default, total_stake calculation
  (active-only), max_validators enforcement, and claim_job exhaustion
- state_versioning.rs: Test ValidatorInfoLegacy migration, ChainStateV2 migration,
  version error paths (too old, deserialization failures, unknown versions)
- types.rs: Add tests for Hotkey SS58 conversion (roundtrip and invalid input),
  ChallengeId::from_uuid/default uniqueness
@coderabbitai
Copy link

coderabbitai bot commented Jan 9, 2026

📝 Walkthrough

Walkthrough

Adds extensive unit tests across eight core modules (challenge, crypto, error, message, schema_guard, state, state_versioning, types). All changes are test-only under #[cfg(test)]; no production code or public API modifications.

Changes

Cohort / File(s) Change Summary
Core test additions
crates/core/src/challenge.rs, crates/core/src/crypto.rs, crates/core/src/error.rs, crates/core/src/message.rs, crates/core/src/schema_guard.rs, crates/core/src/state.rs, crates/core/src/state_versioning.rs, crates/core/src/types.rs
Added numerous unit tests covering: ChallengeConfig behavior; keypair seed derivation, signing, and serialization error propagation; MiniChainError conversions and Display; message creation/validation and resource/time bounds; schema descriptions, hashes, and migration error formatting; state initialization, validator/job behaviors, and versioning migration/round-trips; Hotkey/SS58 and ChallengeId tests. No production/API changes.

Sequence Diagram(s)

(omitted — changes are test-only and do not introduce new multi-component control flows)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • v1.0.0 Platform #2 — touches crates/core/src/schema_guard.rs and relates to schema description/formatting validated by the new tests.

Poem

🐰 I hop through tests with a twitch and a twitch,
Asserting seeds, states, and schema stitch by stitch.
Keys sign in moonlight, migrations pass through,
I nibble at bugs till the build says it's true.
🥕 Hooray for coverage — a rabbit's small pitch!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: comprehensive unit tests added across multiple core modules without any production code modifications.
Docstring Coverage ✅ Passed Docstring coverage is 96.83% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 810559e and f4594fe.

📒 Files selected for processing (1)
  • crates/core/src/crypto.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/core/src/crypto.rs

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
crates/core/src/crypto.rs (1)

321-335: Remove the hard-coded “production sudo mnemonic” from tests (secret exposure).
Having what’s labeled as a production mnemonic in-repo is effectively publishing a private key. Replace with a non-production test vector (or derive from a public key only), and rotate any real secrets immediately if this mnemonic was ever used.

🧹 Nitpick comments (1)
crates/core/src/message.rs (1)

1548-1702: Make env-var-sensitive tests deterministic (DEVELOPMENT_MODE can break whitelist/validate tests).
Several tests in this module assume DEVELOPMENT_MODE is unset/false; if CI sets it, whitelist/validation assertions will flip. Also, test_is_development_mode currently doesn’t assert behavior.

Suggestion: add a small helper that locks + sets/unsets DEVELOPMENT_MODE, runs the assertion, then restores the previous value; use it in whitelist/validate tests and in test_is_development_mode.

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 138fbf9 and 446af5a.

📒 Files selected for processing (8)
  • crates/core/src/challenge.rs
  • crates/core/src/crypto.rs
  • crates/core/src/error.rs
  • crates/core/src/message.rs
  • crates/core/src/schema_guard.rs
  • crates/core/src/state.rs
  • crates/core/src/state_versioning.rs
  • crates/core/src/types.rs
🧰 Additional context used
🧬 Code graph analysis (2)
crates/core/src/types.rs (1)
crates/challenge-sdk/src/types.rs (5)
  • test_challenge_id_from_uuid (472-477)
  • from_uuid (16-18)
  • test_challenge_id_default (313-317)
  • default (27-29)
  • default (78-87)
crates/core/src/state.rs (3)
crates/consensus/src/stake_governance.rs (1)
  • block_height (349-351)
crates/core/src/state_versioning.rs (1)
  • create_test_state (305-308)
crates/core/src/types.rs (5)
  • new (70-72)
  • new (118-120)
  • new (141-150)
  • new (199-204)
  • new (239-249)
🔇 Additional comments (14)
crates/core/src/challenge.rs (1)

234-241: LGTM! Well-focused test for the builder method.

The test correctly validates that with_mechanism sets the mechanism_id while preserving default values for other configuration fields.

crates/core/src/state.rs (5)

454-460: LGTM! Validates timestamp initialization.

The test appropriately checks that default_timestamp() returns a timestamp close to the current time with a reasonable 5-second tolerance.


462-468: LGTM! Validates production defaults.

The test correctly verifies that production_default() initializes with block_height 0, subnet_id 100, and a non-zero sudo key.


470-505: LGTM! Comprehensive stake calculation tests.

These two tests effectively validate:

  • Total stake sums correctly across all active validators
  • Inactive validators are properly excluded from the total

The approach of manually inserting an inactive validator (line 500) is appropriate since add_validator would reject it.


507-529: LGTM! Validates max validator limit enforcement.

The test properly verifies that exceeding max_validators returns a Consensus error, ensuring the system enforces capacity limits.


531-549: LGTM! Thorough job claiming edge case coverage.

The test validates:

  • Claiming returns None when no jobs exist
  • Claiming succeeds when a job is available
  • Claiming returns None when all jobs are already assigned
crates/core/src/state_versioning.rs (3)

439-482: LGTM! Validates legacy migration behavior.

These tests effectively verify:

  • ValidatorInfoLegacy migrates correctly with x25519_pubkey defaulting to None
  • ChainStateV2 migrates to current format while preserving registered_hotkeys

484-517: LGTM! Validates smart deserialization strategies.

These tests confirm that deserialize_state_smart correctly handles:

  • Direct V2 state deserialization
  • Versioned (current format) deserialization

519-593: LGTM! Comprehensive error path coverage.

These tests validate proper error handling for:

  • Version too old (below MIN_SUPPORTED_VERSION)
  • V1/V2 deserialization failures with invalid data
  • Unknown version numbers
  • Complete deserialization failure with incompatible format

The error assertions properly verify both the error type and message content.

crates/core/src/error.rs (1)

69-110: LGTM! Comprehensive error handling validation.

The tests effectively cover:

  • From trait implementations for io::Error, bincode::Error, and serde_json::Error
  • Proper error variant mapping (Internal, Serialization)
  • Display trait output for various error types

The bincode error test (lines 83-90) is particularly well-crafted, creating a realistic error by serializing to a buffer that's too small.

crates/core/src/types.rs (3)

491-499: LGTM! Validates SS58 address roundtrip.

The test correctly verifies that a Hotkey can be converted to SS58 format and back, preserving the original value.


501-505: LGTM! Validates SS58 error handling.

The test properly confirms that from_ss58 returns None for invalid or empty addresses.


507-521: LGTM! Validates ChallengeId behavior.

These tests effectively verify:

  • from_uuid preserves the UUID value
  • Display formatting matches the UUID string representation
  • default() generates unique IDs (important for avoiding collisions)
crates/core/src/schema_guard.rs (1)

374-493: Added schema-guard tests look solid and low-flake.
Good coverage for formatting/determinism/registry invariants without being overly brittle.

@echobt echobt merged commit 5adb7ba into PlatformNetwork:main Jan 9, 2026
6 checks passed
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.

2 participants