From 1ab9472f7242952dd83e54b2c2b10b01cd4294b2 Mon Sep 17 00:00:00 2001 From: Nick Gheorghita Date: Tue, 15 Jan 2019 09:46:58 +0100 Subject: [PATCH] Remove auto-infer of ENS TLDs --- docs/ens_overview.rst | 5 +++-- ens/constants.py | 2 -- ens/exceptions.py | 7 ------- ens/main.py | 5 ++--- ens/utils.py | 31 +------------------------------ tests/ens/test_setup_address.py | 17 ----------------- tests/ens/test_setup_name.py | 20 +------------------- 7 files changed, 7 insertions(+), 80 deletions(-) diff --git a/docs/ens_overview.rst b/docs/ens_overview.rst index a5c3e6a2fd..89ae116f16 100644 --- a/docs/ens_overview.rst +++ b/docs/ens_overview.rst @@ -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 diff --git a/ens/constants.py b/ens/constants.py index fb7e26a9cb..8ee310bc28 100644 --- a/ens/constants.py +++ b/ens/constants.py @@ -9,6 +9,4 @@ MIN_ETH_LABEL_LENGTH = 7 -DEFAULT_RECOGNIZED_TLDS = ['eth', 'reverse', 'test', 'luxe', 'xyz'] - REVERSE_REGISTRAR_DOMAIN = 'addr.reverse' diff --git a/ens/exceptions.py b/ens/exceptions.py index cf2f82f9e6..913c83f4f9 100644 --- a/ens/exceptions.py +++ b/ens/exceptions.py @@ -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 diff --git a/ens/main.py b/ens/main.py index 75c6d0b9d2..ea27f0fd9a 100644 --- a/ens/main.py +++ b/ens/main.py @@ -20,7 +20,6 @@ address_to_reverse_domain, default, dict_copy, - dot_eth_name, dot_eth_namehash, init_web3, is_valid_name, @@ -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) @@ -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 diff --git a/ens/utils.py b/ens/utils.py index 2b28dc4c3c..0211810fcd 100644 --- a/ens/utils.py +++ b/ens/utils.py @@ -1,7 +1,6 @@ import copy import datetime import functools -import os from eth_utils import ( is_same_address, @@ -14,7 +13,6 @@ ACCEPTABLE_STALE_HOURS, AUCTION_START_GAS_CONSTANT, AUCTION_START_GAS_MARGINAL, - DEFAULT_RECOGNIZED_TLDS, EMPTY_SHA3_BYTES, MIN_ETH_LABEL_LENGTH, REVERSE_REGISTRAR_DOMAIN, @@ -22,7 +20,6 @@ from ens.exceptions import ( InvalidLabel, InvalidName, - InvalidTLD, ) default = object() @@ -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: @@ -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) diff --git a/tests/ens/test_setup_address.py b/tests/ens/test_setup_address.py index e29b544263..3e79a0ce88 100644 --- a/tests/ens/test_setup_address.py +++ b/tests/ens/test_setup_address.py @@ -11,9 +11,6 @@ from ens.constants import ( EMPTY_ADDR_HEX, ) -from ens.exceptions import ( - InvalidTLD, -) from ens.main import ( UnauthorizedError, ) @@ -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', [ diff --git a/tests/ens/test_setup_name.py b/tests/ens/test_setup_name.py index 4532c0b7f3..e1ee9c0d2d 100644 --- a/tests/ens/test_setup_name.py +++ b/tests/ens/test_setup_name.py @@ -1,8 +1,5 @@ import pytest -from ens.exceptions import ( - InvalidTLD, -) from ens.main import ( AddressMismatch, UnauthorizedError, @@ -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): @@ -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):