Skip to content

Commit 6191afc

Browse files
evanlinjinclaude
andcommitted
docs(core): address review feedback on docs and tests
Address suggestions by @nymius: - Add `Returns` and `Errors` doc sections to `CheckPoint::from_blocks` - Add test assertions for chain integrity after failed push and chain length after successful push Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 254a6cd commit 6191afc

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

crates/core/src/checkpoint.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,15 @@ where
283283

284284
/// Construct from an iterator of block data.
285285
///
286+
/// # Returns
287+
///
288+
/// Returns the checkpoint chain tip on success.
289+
///
290+
/// # Errors
291+
///
286292
/// Returns `Err(None)` if `blocks` doesn't yield any data. If the blocks are not in ascending
287-
/// height order, or there are any `prev_blockhash` mismatches, then returns an `Err(..)`
288-
/// containing the last checkpoint that would have been extended.
293+
/// height order, or there are any `prev_blockhash` mismatches, then returns `Err(Some(..))`
294+
/// containing the last checkpoint that was successfully extended.
289295
pub fn from_blocks(blocks: impl IntoIterator<Item = (u32, D)>) -> Result<Self, Option<Self>> {
290296
let mut blocks = blocks.into_iter();
291297
let (height, data) = blocks.next().ok_or(None)?;

crates/core/tests/test_checkpoint.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,10 @@ fn checkpoint_push_fails_conflicting_prev_blockhash() {
456456
result.unwrap_err().eq_ptr(&cp),
457457
"should return self on error"
458458
);
459+
460+
// Verify the original checkpoint at 100 is still intact
461+
assert_eq!(cp.height(), 100);
462+
assert_eq!(cp.hash(), hash!("block_100"));
459463
}
460464

461465
/// Test that push succeeds when prev_blockhash matches self's hash for contiguous height.
@@ -485,6 +489,11 @@ fn checkpoint_push_succeeds_matching_prev_blockhash() {
485489
let new_cp = result.unwrap();
486490
assert_eq!(new_cp.height(), 101);
487491
assert_eq!(new_cp.hash(), hash!("block_101"));
492+
assert_eq!(
493+
new_cp.iter().count(),
494+
2,
495+
"should have 2 checkpoints (100, 101)"
496+
);
488497
}
489498

490499
/// Test that push creates a placeholder for non-contiguous heights with prev_blockhash.

0 commit comments

Comments
 (0)