]> Untitled Git - bdk/commitdiff
docs(core): address review feedback on docs and tests
author志宇 <hello@evanlinjin.me>
Thu, 5 Mar 2026 06:03:40 +0000 (06:03 +0000)
committer志宇 <hello@evanlinjin.me>
Wed, 22 Apr 2026 04:48:19 +0000 (04:48 +0000)
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>
crates/core/src/checkpoint.rs
crates/core/tests/test_checkpoint.rs

index 842949b4f016d86a0c3ae4bafce5fd0824ad77b2..2a4944a51ff73569ec97c45663fcb9e4d2cd6c5f 100644 (file)
@@ -283,9 +283,15 @@ where
 
     /// Construct from an iterator of block data.
     ///
+    /// # Returns
+    ///
+    /// Returns the checkpoint chain tip on success.
+    ///
+    /// # Errors
+    ///
     /// Returns `Err(None)` if `blocks` doesn't yield any data. If the blocks are not in ascending
-    /// height order, or there are any `prev_blockhash` mismatches, then returns an `Err(..)`
-    /// containing the last checkpoint that would have been extended.
+    /// height order, or there are any `prev_blockhash` mismatches, then returns `Err(Some(..))`
+    /// containing the last checkpoint that was successfully extended.
     pub fn from_blocks(blocks: impl IntoIterator<Item = (u32, D)>) -> Result<Self, Option<Self>> {
         let mut blocks = blocks.into_iter();
         let (height, data) = blocks.next().ok_or(None)?;
index f43bbd5ae27a8ce8ac52c5be7d98df524482fe9f..fb5048e09d68299e96eb1e713299c6a500be7a6f 100644 (file)
@@ -456,6 +456,10 @@ fn checkpoint_push_fails_conflicting_prev_blockhash() {
         result.unwrap_err().eq_ptr(&cp),
         "should return self on error"
     );
+
+    // Verify the original checkpoint at 100 is still intact
+    assert_eq!(cp.height(), 100);
+    assert_eq!(cp.hash(), hash!("block_100"));
 }
 
 /// 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() {
     let new_cp = result.unwrap();
     assert_eq!(new_cp.height(), 101);
     assert_eq!(new_cp.hash(), hash!("block_101"));
+    assert_eq!(
+        new_cp.iter().count(),
+        2,
+        "should have 2 checkpoints (100, 101)"
+    );
 }
 
 /// Test that push creates a placeholder for non-contiguous heights with prev_blockhash.