-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.py
37 lines (27 loc) · 1.06 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import unittest
from typing import List, NamedTuple
import multihash
def h(s: str) -> bytes:
return bytes(bytearray.fromhex(s))
class Representation(NamedTuple):
"""A map of bytes to its known correct binary representation."""
value: multihash.MultiHash
binary: bytes
class TestMultiHash(unittest.TestCase):
# Example values from the multihash website and specification
# https://multiformats.io/multihash/
# https://github.com/multiformats/multihash/blob/master/README.md
examples: List[Representation] = [
Representation(
multihash.MultiHash(0x12, 0x20, h('41dd7b6443542e75701aa98a0c235951a28a0d851b11564d20022ab11d2589a8')),
h('122041dd7b6443542e75701aa98a0c235951a28a0d851b11564d20022ab11d2589a8')
),
]
all: List[Representation] = examples
def test_decode(self) -> None:
value: multihash.MultiHash
binary: bytes
for (value, binary) in TestMultiHash.all:
self.assertEqual(multihash.decode(binary), value)
if __name__ == '__main__':
unittest.main()