Skip to content

Conversation

@cuteolaf
Copy link
Contributor

@cuteolaf cuteolaf commented Jan 9, 2026

Test coverage highlights:

  • All epoch transition and phase change logic
  • Commit-reveal scheme validation and consensus
  • Weight aggregation and emission distribution
  • Mechanism weight management and Bittensor integration
  • Comprehensive edge case handling

Summary by CodeRabbit

  • Tests
    • Expanded unit test coverage across epoch management, phase transitions, commit‑reveal flows, emission aggregation/distribution, validator metrics/suspicion scenarios, mechanism weight handling, and related edge cases to improve reliability and guard against regressions.

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

Test coverage highlights:
- All epoch transition and phase change logic
- Commit-reveal scheme validation and consensus
- Weight aggregation and emission distribution
- Mechanism weight management and Bittensor integration
- Comprehensive edge case handling
@coderabbitai
Copy link

coderabbitai bot commented Jan 9, 2026

📝 Walkthrough

Walkthrough

Added extensive unit tests across the epoch crate covering aggregator emissions, commit-reveal flows and manager interactions, epoch config/state, and mechanism weight handling; no public APIs or production logic were modified. Tests total ~1,430 added lines.

Changes

Cohort / File(s) Summary
Aggregator tests
crates/epoch/src/aggregator.rs
Added tests for emission merging, multiple-challenge distributions, empty/missing finalized weights, validator suspicion detection, and validator participation metrics. (+277 lines)
Commit-reveal tests
crates/epoch/src/commit_reveal.rs
Added extensive commit/reveal and CommitRevealManager tests: epoch/challenge validation, duplicate/missing commits/reveals, finalize behavior, counters, cleanup, multi-challenge scenarios, and error formatting. (+337 lines)
Core epoch tests
crates/epoch/src/lib.rs
Added #[cfg(test)] tests for EpochConfig defaults, EpochPhase Display/Equality, and EpochState::new initialization. (+42 lines)
Manager tests
crates/epoch/src/manager.rs
Added phase-capability checks, phase duration/transition tests, epoch/block utilities, config update behavior, state cloning, blocks-remaining behavior, and multi-epoch transition tests. (+227 lines)
Mechanism weight tests
crates/epoch/src/mechanism_weights.rs
Added comprehensive tests for weight normalization, burn UID handling, edge cases (zero/negative/very small weights), batch interfaces, mechanism lifecycle (register/submit/list/get/clear/epoch), commit/reveal flows, storage checks, and multi-challenge end-to-end scenarios. (+546 lines)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~30 minutes

Poem

🐇 I hopped through tests both wide and deep,

Emissions measured, and secrets to keep.
Epochs and weights in tidy array,
Commits revealed at the close of day.
The rabbit applauds: "Green lights all the way!"

🚥 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 clearly and specifically summarizes the main change: adding comprehensive unit tests to achieve high code coverage in the epoch module.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% 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 4ed7994 and 13b55b1.

📒 Files selected for processing (1)
  • crates/epoch/src/commit_reveal.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/epoch/src/commit_reveal.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: 0

🧹 Nitpick comments (6)
crates/epoch/src/commit_reveal.rs (3)

609-626: Add assertion to verify cleanup behavior.

The test sets up epochs 0, 1, 2 and calls cleanup_old_epochs(2, 1), but lacks an assertion to verify that epochs 0 and 1 were actually removed. Without verifying the internal state, this test doesn't confirm the cleanup worked correctly.

Consider exposing a method to check state count or use get_or_create to verify which epochs remain.


628-643: Consider adding assertions to verify state creation.

This test verifies that get_or_create can be called twice without panicking, but doesn't assert that the state was actually created or that subsequent calls return the same state. Adding assertions would make this a more meaningful test.


602-607: Replace trivial assert!(true) with meaningful assertion.

assert!(true) provides no value. Consider asserting on an actual property of the manager.

♻️ Suggested improvement
     #[test]
     fn test_commit_reveal_manager_default() {
         let manager = CommitRevealManager::default();
-        // Just verify it can be created
-        assert!(true);
+        // Verify initial state
+        let result = manager.finalize(0, ChallengeId::new(), 0.3, 1);
+        assert!(result.is_err()); // No commits exist
     }
crates/epoch/src/mechanism_weights.rs (3)

1003-1026: Test assertion expectation may fail for edge case.

On line 1025, the test asserts sum == MAX_WEIGHT as u32, but with very small weights (0.001 * 0.01 emission = 0.00001 scaled weight), the individual weights may round to 0, causing only the burn weight to be added. The burn weight calculation uses saturating_sub, which would give MAX_WEIGHT - 0 = MAX_WEIGHT, so the assertion should pass. However, line 1023 uses > 0 instead of !is_empty().

♻️ Minor style improvement
         // Should still handle small weights
-        assert!(mech_weights.uids.len() > 0);
+        assert!(!mech_weights.uids.is_empty());
         let sum: u32 = mech_weights.weights.iter().map(|w| *w as u32).sum();
         assert_eq!(sum, MAX_WEIGHT as u32);

1090-1123: Same style nit: prefer !is_empty() over len() > 0.

Lines 1121 uses uids.len() > 0 which is idiomatic but Clippy recommends !is_empty().

♻️ Minor style improvement
         let (mech_id, uids, weights) = &all[0];
         assert_eq!(*mech_id, 5);
-        assert!(uids.len() > 0);
+        assert!(!uids.is_empty());
         assert_eq!(uids.len(), weights.len());

862-867: Replace trivial assert!(true) with meaningful assertion.

Same issue as in commit_reveal.rs - this assertion provides no value.

♻️ Suggested improvement
     #[test]
     fn test_mechanism_commit_reveal_manager_default() {
         let manager = MechanismCommitRevealManager::default();
-        // Just verify it can be created
-        assert!(true);
+        // Verify initial state
+        assert!(!manager.all_revealed());
+        assert!(manager.get_all_commitments().is_empty());
     }
📜 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 4e96e50.

📒 Files selected for processing (5)
  • crates/epoch/src/aggregator.rs
  • crates/epoch/src/commit_reveal.rs
  • crates/epoch/src/lib.rs
  • crates/epoch/src/manager.rs
  • crates/epoch/src/mechanism_weights.rs
🧰 Additional context used
🧬 Code graph analysis (1)
crates/epoch/src/manager.rs (1)
crates/epoch/src/lib.rs (2)
  • default (43-52)
  • new (95-103)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Test
🔇 Additional comments (4)
crates/epoch/src/lib.rs (1)

158-198: LGTM!

Clean unit tests covering the core types' defaults, display formatting, equality, and initialization. The assertions correctly match the implementation.

crates/epoch/src/aggregator.rs (1)

293-570: LGTM!

Comprehensive test coverage for the weight aggregator including edge cases like zero emission, missing weights, empty challenges, and validator metrics. The tests correctly validate expected behavior and error conditions.

crates/epoch/src/manager.rs (1)

256-483: LGTM!

Thorough test coverage for the epoch manager including phase transitions, block calculations, and edge cases like multi-epoch jumps. The tests correctly validate the state machine behavior.

crates/epoch/src/mechanism_weights.rs (1)

593-1137: Overall: Excellent test coverage.

The tests comprehensively cover edge cases including zero/negative weights, missing hotkeys, UID 0 handling, emission clamping, rounding behavior, and the complete commit-reveal workflow. Good job exercising the various code paths.

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: 0

🧹 Nitpick comments (1)
crates/epoch/src/commit_reveal.rs (1)

326-326: Remove unused import.

The Arc import is not used anywhere in the test module.

♻️ Proposed fix
-    use std::sync::Arc;
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4e96e50 and 4ed7994.

📒 Files selected for processing (2)
  • crates/epoch/src/commit_reveal.rs
  • crates/epoch/src/mechanism_weights.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Clippy
🔇 Additional comments (2)
crates/epoch/src/commit_reveal.rs (1)

394-729: Excellent test coverage!

This comprehensive test suite thoroughly exercises the commit-reveal implementation, covering happy paths, error conditions, edge cases, and manager lifecycle. The tests validate:

  • Epoch and challenge validation
  • Duplicate submission prevention
  • Missing commitment/reveal handling
  • Validator threshold enforcement
  • Multi-challenge scenarios
  • Cleanup operations
  • Error message formatting

This aligns well with the PR's goal of achieving 95%+ test coverage.

crates/epoch/src/mechanism_weights.rs (1)

594-1138: Outstanding comprehensive test coverage!

This extensive test suite provides thorough coverage of the mechanism weight management system, including:

  • Emission weight edge cases (zero, full, clamping)
  • Hotkey-to-UID mapping and fallback behavior
  • UID 0 (burn address) handling
  • Weight calculation accuracy and rounding
  • Commit-reveal workflow (matching/mismatched reveals, missing commitments)
  • Manager operations (registration, submission, retrieval, cleanup)
  • Multi-mechanism and multi-challenge scenarios
  • Complete end-to-end workflow validation

The tests systematically cover edge cases and integration scenarios, strongly supporting the PR's 95%+ coverage goal.

@echobt echobt merged commit ceb4984 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