Skip to content

Commit 8d04f53

Browse files
committed
fix(cardano-blockchain-types): testdoc
Signed-off-by: bkioshn <[email protected]>
1 parent 347045a commit 8d04f53

File tree

1 file changed

+46
-43
lines changed
  • rust/cardano-blockchain-types/src

1 file changed

+46
-43
lines changed

rust/cardano-blockchain-types/src/point.rs

Lines changed: 46 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,12 @@ impl Point {
8989
///
9090
/// # Examples
9191
///
92-
/// ```rs
93-
/// use cardano_chain_follower::Point;
92+
/// ```
93+
/// use cardano_blockchain_types::Point;
9494
///
9595
/// let slot = 42;
96-
/// let hash = vec![0; 32];
97-
/// let point = Point::new(slot, hash);
96+
/// let hash = [0; 32];
97+
/// let point = Point::new(slot.into(), hash.into());
9898
/// ```
9999
#[must_use]
100100
pub fn new(slot: Slot, hash: Blake2bHash<32>) -> Self {
@@ -119,11 +119,11 @@ impl Point {
119119
///
120120
/// # Examples
121121
///
122-
/// ```rs
123-
/// use cardano_chain_follower::Point;
122+
/// ```
123+
/// use cardano_blockchain_types::Point;
124124
///
125125
/// let slot = 42;
126-
/// let point = Point::fuzzy(slot);
126+
/// let point = Point::fuzzy(slot.into());
127127
/// ```
128128
#[must_use]
129129
pub fn fuzzy(slot: Slot) -> Self {
@@ -157,11 +157,11 @@ impl Point {
157157
///
158158
/// # Examples
159159
///
160-
/// ```rs
161-
/// use cardano_chain_follower::Point;
160+
/// ```
161+
/// use cardano_blockchain_types::Point;
162162
///
163163
/// let slot = 42;
164-
/// let point = Point::fuzzy(slot);
164+
/// let point = Point::fuzzy(slot.into());
165165
///
166166
/// assert!(point.is_fuzzy());
167167
/// ```
@@ -184,11 +184,11 @@ impl Point {
184184
///
185185
/// # Examples
186186
///
187-
/// ```rs
188-
/// use cardano_chain_follower::Point;
187+
/// ```
188+
/// use cardano_blockchain_types::Point;
189189
///
190190
/// let slot = 42;
191-
/// let point = Point::fuzzy(slot);
191+
/// let point = Point::fuzzy(slot.into());
192192
///
193193
/// assert!(!point.is_origin());
194194
/// ```
@@ -206,10 +206,10 @@ impl Point {
206206
///
207207
/// # Examples
208208
///
209-
/// ```rs
210-
/// use cardano_chain_follower::Point;
209+
/// ```
210+
/// use cardano_blockchain_types::Point;
211211
///
212-
/// let point = Point::fuzzy(0);
212+
/// let point = Point::fuzzy(0.into());
213213
///
214214
/// assert!(point.is_unknown());
215215
/// ```
@@ -227,10 +227,10 @@ impl Point {
227227
///
228228
/// # Examples
229229
///
230-
/// ```rs
231-
/// use cardano_chain_follower::Point;
230+
/// ```
231+
/// use cardano_blockchain_types::Point;
232232
///
233-
/// let point = Point::fuzzy(0);
233+
/// let point = Point::fuzzy(0.into());
234234
///
235235
/// assert!(!point.is_tip());
236236
/// ```
@@ -254,13 +254,13 @@ impl Point {
254254
///
255255
/// # Examples
256256
///
257-
/// ```rs
258-
/// use cardano_chain_follower::{Point, ORIGIN_POINT};
257+
/// ```
258+
/// use cardano_blockchain_types::Point;
259259
///
260-
/// let specific_point = Point::new(42, vec![0; 32]);
261-
/// assert_eq!(specific_point.slot_or_default(), 42);
260+
/// let specific_point = Point::new(42.into(), [0; 32].into());
261+
/// assert_eq!(specific_point.slot_or_default(), 42.into());
262262
///
263-
/// let origin_point = ORIGIN_POINT;
263+
/// let origin_point = Point::ORIGIN;
264264
/// assert_eq!(origin_point.slot_or_default(), 0.into()); // assuming 0 is the default
265265
/// ```
266266
#[must_use]
@@ -278,20 +278,23 @@ impl Point {
278278
///
279279
/// # Examples
280280
///
281-
/// ```rs
282-
/// use cardano_chain_follower::{Point, ORIGIN_POINT};
281+
/// ```
282+
/// use cardano_blockchain_types::Point;
283283
///
284-
/// let specific_point = Point::new(42, vec![1, 2, 3]);
285-
/// assert_eq!(specific_point.hash_or_default(), vec![1, 2, 3]);
284+
/// let specific_point = Point::new(42.into(), [0; 32].into());
285+
/// assert_eq!(specific_point.hash_or_default(), Some([0; 32].into()));
286286
///
287-
/// let origin_point = ORIGIN_POINT;
288-
/// assert_eq!(origin_point.hash_or_default(), Vec::new());
287+
/// let origin_point = Point::ORIGIN;
288+
/// assert_eq!(origin_point.hash_or_default(), None);
289289
/// ```
290290
#[must_use]
291-
pub fn hash_or_default(&self) -> Vec<u8> {
291+
pub fn hash_or_default(&self) -> Option<Hash<32>> {
292292
match &self.0 {
293-
pallas::network::miniprotocols::Point::Specific(_, hash) => hash.clone(),
294-
pallas::network::miniprotocols::Point::Origin => Vec::new(),
293+
pallas::network::miniprotocols::Point::Specific(_, hash) => {
294+
Some(Hash::from(hash.as_slice()))
295+
},
296+
// Origin has empty hash, so set it to None
297+
pallas::network::miniprotocols::Point::Origin => None,
295298
}
296299
}
297300

@@ -308,15 +311,15 @@ impl Point {
308311
///
309312
/// # Examples
310313
///
311-
/// ```rs
312-
/// use cardano_chain_follower::Point;
314+
/// ```
315+
/// use cardano_blockchain_types::Point;
313316
///
314-
/// let point1 = Point::new(42, vec![1, 2, 3]);
315-
/// let point2 = Point::new(42, vec![1, 2, 3]);
317+
/// let point1 = Point::new(42.into(), [0; 32].into());
318+
/// let point2 = Point::new(42.into(), [0; 32].into());
316319
/// assert!(point1.strict_eq(&point2));
317320
///
318-
/// let point3 = Point::new(42, vec![1, 2, 3]);
319-
/// let point4 = Point::new(43, vec![1, 2, 3]);
321+
/// let point3 = Point::new(42.into(), [0; 32].into());
322+
/// let point4 = Point::new(43.into(), [0; 32].into());
320323
/// assert!(!point3.strict_eq(&point4));
321324
/// ```
322325
#[must_use]
@@ -362,10 +365,10 @@ impl Display for Point {
362365

363366
let slot = self.slot_or_default();
364367
let hash = self.hash_or_default();
365-
if hash.is_empty() {
366-
return write!(f, "Point @ Probe:{slot:?}");
368+
match hash {
369+
Some(hash) => write!(f, "Point @ {slot:?}:{}", hex::encode(hash)),
370+
None => write!(f, "Point @ {slot:?}"),
367371
}
368-
write!(f, "Point @ {slot:?}:{}", hex::encode(hash))
369372
}
370373
}
371374

@@ -493,7 +496,7 @@ mod tests {
493496
fn test_get_hash_simple() {
494497
let point1 = Point::new(100u64.into(), [8; 32].into());
495498

496-
assert_eq!(point1.hash_or_default(), vec![8; 32]);
499+
assert_eq!(point1.hash_or_default(), Some([8; 32].into()));
497500
}
498501

499502
#[test]

0 commit comments

Comments
 (0)