File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change 1
1
import pytest
2
2
3
- from trinity .utils .humanize import humanize_elapsed
3
+ from trinity .utils .humanize import humanize_elapsed , humanize_hash
4
4
5
5
6
6
SECOND = 1
39
39
def test_humanize_elapsed (seconds , expected ):
40
40
actual = humanize_elapsed (seconds )
41
41
assert actual == expected
42
+
43
+
44
+ @pytest .mark .parametrize (
45
+ 'hash32,expected' ,
46
+ (
47
+ (bytes (range (32 )), '000102..1d1e1f' ),
48
+ )
49
+ )
50
+ def test_humanize_hash (hash32 , expected ):
51
+ assert humanize_hash (hash32 ) == expected
Original file line number Diff line number Diff line change 1
1
from typing import Iterator
2
2
3
+ from eth_typing import Hash32
4
+
3
5
4
6
def humanize_elapsed (seconds : int ) -> str :
5
7
return '' .join (_humanize_elapsed (seconds ))
@@ -44,3 +46,12 @@ def _humanize_elapsed(seconds: int) -> Iterator[str]:
44
46
return
45
47
46
48
remainder %= duration
49
+
50
+
51
+ DISPLAY_HASH_BYTES = 3
52
+
53
+
54
+ def humanize_hash (value : Hash32 ) -> str :
55
+ head = value [:DISPLAY_HASH_BYTES ]
56
+ tail = value [- 1 * DISPLAY_HASH_BYTES :]
57
+ return f"{ head .hex ()} ..{ tail .hex ()} "
You can’t perform that action at this time.
0 commit comments