Skip to content

Commit b468003

Browse files
committed
fix: add unit test for hexbits
1 parent 07413e7 commit b468003

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

tests/test_hexbits.py

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import unittest
2+
3+
from eth_validator_watcher.duties import hex_to_sparse_bitset
4+
5+
6+
class HexBitsTestCase(unittest.TestCase):
7+
"""Test case for hex_to_sparse_bitset function."""
8+
9+
def test_hex_to_sparse_bitset_zero(self) -> None:
10+
"""Test hex_to_sparse_bitset() with a zero hex value."""
11+
result = hex_to_sparse_bitset("0x00")
12+
self.assertEqual(result, set())
13+
14+
def test_hex_to_sparse_bitset_with_prefix(self) -> None:
15+
"""Test hex_to_sparse_bitset() with 0x prefix."""
16+
# 0000 0101
17+
result = hex_to_sparse_bitset("0x05")
18+
self.assertEqual(result, {5, 7})
19+
20+
def test_hex_to_sparse_bitset_without_prefix(self) -> None:
21+
"""Test hex_to_sparse_bitset() without 0x prefix."""
22+
# 0000 0101
23+
result = hex_to_sparse_bitset("05")
24+
self.assertEqual(result, {5, 7})
25+
26+
def test_hex_to_sparse_bitset_complex(self) -> None:
27+
"""Test hex_to_sparse_bitset() with a complex hex value."""
28+
# 1010 0101
29+
result = hex_to_sparse_bitset("0xA5")
30+
self.assertEqual(result, {0, 2, 5, 7})
31+
32+
def test_hex_to_sparse_bitset_multi_byte(self) -> None:
33+
"""Test hex_to_sparse_bitset() with a multi-byte hex value."""
34+
# 0001 0010 0011 0100
35+
result = hex_to_sparse_bitset("0x1234")
36+
self.assertEqual(result, {3, 6, 10, 11, 13})
37+
38+
39+
if __name__ == "__main__":
40+
unittest.main()

0 commit comments

Comments
 (0)