Skip to content

Commit

Permalink
Remove auto-infer of ENS TLDs
Browse files Browse the repository at this point in the history
  • Loading branch information
njgheorghita committed Jan 15, 2019
1 parent 11d06e2 commit 1ab9472
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 80 deletions.
5 changes: 3 additions & 2 deletions docs/ens_overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ Look up the address for an ENS name

assert eth_address == '0x5B2063246F2191f18F2675ceDB8b28102e957458'

# ens.py only support names using one of these recognized TLDs
# ['eth', 'reverse', 'test', 'luxe', 'xyz']

The ``ENS`` module has no opinion as to which TLD you can use,
but will not infer a TLD if it is not provided with the name.


Get name from address
Expand Down
2 changes: 0 additions & 2 deletions ens/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,4 @@

MIN_ETH_LABEL_LENGTH = 7

DEFAULT_RECOGNIZED_TLDS = ['eth', 'reverse', 'test', 'luxe', 'xyz']

REVERSE_REGISTRAR_DOMAIN = 'addr.reverse'
7 changes: 0 additions & 7 deletions ens/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,3 @@ class UnderfundedBid(ValueError):
as your intent to bid.
'''
pass


class InvalidTLD(ValueError):
'''
Raised if name does not contain a recognized TLD.
'''
pass
5 changes: 2 additions & 3 deletions ens/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
address_to_reverse_domain,
default,
dict_copy,
dot_eth_name,
dot_eth_namehash,
init_web3,
is_valid_name,
Expand Down Expand Up @@ -265,7 +264,7 @@ def _first_owner(self, name):
'''
owner = None
unowned = []
pieces = dot_eth_name(name).split('.')
pieces = normalize_name(name).split('.')
while pieces and not owner:
name = '.'.join(pieces)
owner = self.owner(name)
Expand Down Expand Up @@ -301,7 +300,7 @@ def _set_resolver(self, name, resolver_addr=None, transact={}):
@dict_copy
def _setup_reverse(self, name, address, transact={}):
if name:
name = dot_eth_name(name)
name = normalize_name(name)
else:
name = ''
transact['from'] = address
Expand Down
31 changes: 1 addition & 30 deletions ens/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import copy
import datetime
import functools
import os

from eth_utils import (
is_same_address,
Expand All @@ -14,15 +13,13 @@
ACCEPTABLE_STALE_HOURS,
AUCTION_START_GAS_CONSTANT,
AUCTION_START_GAS_MARGINAL,
DEFAULT_RECOGNIZED_TLDS,
EMPTY_SHA3_BYTES,
MIN_ETH_LABEL_LENGTH,
REVERSE_REGISTRAR_DOMAIN,
)
from ens.exceptions import (
InvalidLabel,
InvalidName,
InvalidTLD,
)

default = object()
Expand Down Expand Up @@ -109,32 +106,6 @@ def is_valid_name(name):
return False


def label_to_name(label, recognized_tlds):
label = normalize_name(label)
pieces = label.split('.')
if pieces[-1] not in recognized_tlds:
raise InvalidTLD(
f"The label: {label} has an unsupported TLD of {pieces[-1]}. "
f"ENS.py by default supports the following TLDs: {recognized_tlds}. "
"If you'd like to use an unsupported TLD, please set the environment variable: "
"'ENS_RECOGNIZED_TLDS' to a string of desired TLDs separated by a colon (:)."
)
return '.'.join(pieces)


def dot_eth_name(label):
recognized_tlds = get_recognized_tlds()
return label_to_name(label, recognized_tlds)


def get_recognized_tlds():
if 'ENS_RECOGNIZED_TLDS' in os.environ:
override_tlds = os.environ['ENS_RECOGNIZED_TLDS'].split(':')
return set(DEFAULT_RECOGNIZED_TLDS + override_tlds)
else:
return DEFAULT_RECOGNIZED_TLDS


def name_to_label(name, registrar):
name = normalize_name(name)
if '.' not in name:
Expand Down Expand Up @@ -214,7 +185,7 @@ def dot_eth_namehash(name):
:rtype: bytes
:raises InvalidName: if ``name`` has invalid syntax
'''
expanded_name = dot_eth_name(name)
expanded_name = normalize_name(name)
return name_to_hash(expanded_name)


Expand Down
17 changes: 0 additions & 17 deletions tests/ens/test_setup_address.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
from ens.constants import (
EMPTY_ADDR_HEX,
)
from ens.exceptions import (
InvalidTLD,
)
from ens.main import (
UnauthorizedError,
)
Expand Down Expand Up @@ -82,20 +79,6 @@ def test_set_address(ens, name, full_name, namehash_hex, TEST_ADDRESS):
assert ens.address(name) is None


@pytest.mark.parametrize(
'name',
(
'tester',
'tester.com',
'TESTER',
'lots.of.subdomains.tester',
),
)
def test_set_address_raises_exception_with_invalid_or_missing_tld(ens, name, TEST_ADDRESS):
with pytest.raises(InvalidTLD, match="ENS.py by default supports the following TLDs"):
ens.setup_address(name, TEST_ADDRESS)


@pytest.mark.parametrize(
'name, equivalent',
[
Expand Down
20 changes: 1 addition & 19 deletions tests/ens/test_setup_name.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import pytest

from ens.exceptions import (
InvalidTLD,
)
from ens.main import (
AddressMismatch,
UnauthorizedError,
Expand Down Expand Up @@ -78,21 +75,6 @@ def test_setup_name(ens, name, normalized_name, namehash_hex):
assert not ens.address(name)


@pytest.mark.parametrize(
'name',
(
'tester',
'tester.com',
'lots.of.subdomains.tester',
),
)
def test_cannot_setup_name_with_missing_or_invalid_tld(ens, name):
address = ens.web3.eth.accounts[3]
assert not ens.name(address)
with pytest.raises(InvalidTLD, match="ENS.py by default supports the following TLDs"):
ens.setup_name(name, address)


def test_cannot_set_name_on_mismatch_address(ens, TEST_ADDRESS):
ens.setup_address('mismatch-reverse.tester.eth', TEST_ADDRESS)
with pytest.raises(AddressMismatch):
Expand Down Expand Up @@ -130,7 +112,7 @@ def test_setup_name_unowned_exception(ens):

def test_setup_name_unauthorized(ens, TEST_ADDRESS):
with pytest.raises(UnauthorizedError):
ens.setup_name('root-owned-tld.eth', TEST_ADDRESS)
ens.setup_name('root-owned-tld', TEST_ADDRESS)


def test_setup_reverse_dict_unmodified(ens):
Expand Down

0 comments on commit 1ab9472

Please sign in to comment.