Skip to content

Commit

Permalink
graph: Implement mock methods for MockBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
incrypto32 committed Dec 19, 2024
1 parent d5f5d5f commit ca39eb3
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions graph/src/blockchain/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,32 @@ pub struct MockBlock {

impl Block for MockBlock {
fn ptr(&self) -> BlockPtr {
todo!()
test_ptr(self.number as i32)
}

fn parent_ptr(&self) -> Option<BlockPtr> {
todo!()
if self.number == 0 {
None
} else {
Some(test_ptr(self.number as i32 - 1))
}
}

fn timestamp(&self) -> BlockTime {
todo!()
BlockTime::for_test(&self.ptr())
}
}

pub fn test_ptr(n: BlockNumber) -> BlockPtr {
test_ptr_reorged(n, 0)
}

pub fn test_ptr_reorged(n: BlockNumber, reorg_n: u32) -> BlockPtr {
let mut hash = H256::from_low_u64_be(n as u64);
hash[0..4].copy_from_slice(&reorg_n.to_be_bytes());
BlockPtr {
hash: hash.into(),
number: n,
}
}

Expand Down

0 comments on commit ca39eb3

Please sign in to comment.