forked from ethereum/web3.py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_get_registry.py
53 lines (46 loc) · 1.39 KB
/
test_get_registry.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import pytest
from unittest.mock import (
patch,
)
from ens import (
ENS,
)
from web3 import (
Web3,
)
def test_resolver_empty(ens):
with patch.object(ens.ens.caller, "resolver", return_value=None):
assert ens.resolver("") is None
@pytest.mark.parametrize(
"address, expected_reverse",
[
(
"0x1111111111111111111111111111111111111111",
"1111111111111111111111111111111111111111.addr.reverse",
),
(
"0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413",
"bb9bc244d798123fde783fcc1c72d3bb8c189413.addr.reverse",
),
],
)
def test_reverse_domain(address, expected_reverse, address_conversion_func):
address = address_conversion_func(address)
assert ENS.reverse_domain(address) == expected_reverse
@pytest.mark.parametrize(
"label, expected_hash",
[
("eth", "0x4f5b812789fc606be1b3b16908db13fc7a9adf7ca72641f84d75b47069d3d7f0"),
("ETH", "0x4f5b812789fc606be1b3b16908db13fc7a9adf7ca72641f84d75b47069d3d7f0"),
("a.b", ValueError),
],
)
def test_labelhash(ens, label, expected_hash):
if isinstance(expected_hash, type):
with pytest.raises(expected_hash):
ens.labelhash(label)
else:
labelhash = ens.labelhash(label)
assert isinstance(labelhash, bytes)
hash_hex = Web3.to_hex(labelhash)
assert hash_hex == expected_hash