File tree Expand file tree Collapse file tree 1 file changed +20
-3
lines changed
Expand file tree Collapse file tree 1 file changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -48,15 +48,32 @@ pub struct MockBlock {
4848
4949impl 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
You can’t perform that action at this time.
0 commit comments