Skip to content

Commit ca39eb3

Browse files
committed
graph: Implement mock methods for MockBlock
1 parent d5f5d5f commit ca39eb3

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

graph/src/blockchain/mock.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,32 @@ pub struct MockBlock {
4848

4949
impl Block for MockBlock {
5050
fn ptr(&self) -> BlockPtr {
51-
todo!()
51+
test_ptr(self.number as i32)
5252
}
5353

5454
fn parent_ptr(&self) -> Option<BlockPtr> {
55-
todo!()
55+
if self.number == 0 {
56+
None
57+
} else {
58+
Some(test_ptr(self.number as i32 - 1))
59+
}
5660
}
5761

5862
fn timestamp(&self) -> BlockTime {
59-
todo!()
63+
BlockTime::for_test(&self.ptr())
64+
}
65+
}
66+
67+
pub fn test_ptr(n: BlockNumber) -> BlockPtr {
68+
test_ptr_reorged(n, 0)
69+
}
70+
71+
pub fn test_ptr_reorged(n: BlockNumber, reorg_n: u32) -> BlockPtr {
72+
let mut hash = H256::from_low_u64_be(n as u64);
73+
hash[0..4].copy_from_slice(&reorg_n.to_be_bytes());
74+
BlockPtr {
75+
hash: hash.into(),
76+
number: n,
6077
}
6178
}
6279

0 commit comments

Comments
 (0)