diff --git a/docs/ens_overview.rst b/docs/ens_overview.rst index 1b74958f20..a5c3e6a2fd 100644 --- a/docs/ens_overview.rst +++ b/docs/ens_overview.rst @@ -60,10 +60,8 @@ Look up the address for an ENS name assert eth_address == '0x5B2063246F2191f18F2675ceDB8b28102e957458' - - # ens.py will assume you want a .eth name if you don't specify a full name - - assert ns.address('jasoncarver') == eth_address + # ens.py only support names using one of these recognized TLDs + # ['eth', 'reverse', 'test', 'luxe', 'xyz'] Get name from address diff --git a/ens/exceptions.py b/ens/exceptions.py index 905cfac351..cf2f82f9e6 100644 --- a/ens/exceptions.py +++ b/ens/exceptions.py @@ -81,6 +81,6 @@ class UnderfundedBid(ValueError): class InvalidTLD(ValueError): ''' - Raised if ... + Raised if name does not contain a recognized TLD. ''' pass diff --git a/ens/main.py b/ens/main.py index b2ba28d2eb..75c6d0b9d2 100644 --- a/ens/main.py +++ b/ens/main.py @@ -72,20 +72,14 @@ def fromWeb3(cls, web3, addr=None): ''' return cls(web3.manager.provider, addr=addr) - # INFERS - def address(self, name, guess_tld=True): + def address(self, name): ''' Look up the Ethereum address that `name` currently points to. :param str name: an ENS name to look up - :param bool guess_tld: should `name` be appended with '.eth' if no common TLD found? :raises InvalidName: if `name` has invalid syntax ''' - if guess_tld: - expanded = dot_eth_name(name) - else: - expanded = name - return self.resolve(expanded, 'addr') + return self.resolve(name, 'addr') def name(self, address): ''' @@ -99,7 +93,6 @@ def name(self, address): return self.resolve(reversed_domain, get='name') reverse = name - # INFER @dict_copy def setup_address(self, name, address=default, transact={}): ''' @@ -137,7 +130,6 @@ def setup_address(self, name, address=default, transact={}): resolver = self._set_resolver(name, transact=transact) return resolver.setAddr(dot_eth_namehash(name), address, transact=transact) - # INFER @dict_copy def setup_name(self, name, address=None, transact={}): ''' @@ -181,7 +173,6 @@ def setup_name(self, name, address=None, transact={}): self.setup_address(name, address, transact=transact) return self._setup_reverse(name, address, transact=transact) - # INFER def resolve(self, name, get='addr'): normal_name = normalize_name(name) resolver = self.resolver(normal_name) @@ -202,7 +193,6 @@ def reverser(self, target_address): reversed_domain = address_to_reverse_domain(target_address) return self.resolver(reversed_domain) - # INFER def owner(self, name): ''' Get the owner of a name. Note that this may be different from the @@ -217,7 +207,6 @@ def owner(self, name): node = dot_eth_namehash(name) return self.ens.owner(node) - # INFER @dict_copy def setup_owner(self, name, new_owner=default, transact={}): ''' diff --git a/ens/utils.py b/ens/utils.py index 673ca74b4b..91f18a513c 100644 --- a/ens/utils.py +++ b/ens/utils.py @@ -109,18 +109,18 @@ def is_valid_name(name): return False -# INFERS -# CAN we get rid of this? -def label_to_name(label, default_tld, recognized_tlds): +def label_to_name(label, recognized_tlds): label = normalize_name(label) pieces = label.split('.') if pieces[-1] not in recognized_tlds: - raise InvalidTLD("no valid tld") + raise InvalidTLD( + f"Label does not have a recognized TLD. TLD must match one of: {recognized_tlds}." + ) return '.'.join(pieces) def dot_eth_name(label): - return label_to_name(label, 'eth', RECOGNIZED_TLDS) + return label_to_name(label, RECOGNIZED_TLDS) def name_to_label(name, registrar): @@ -193,8 +193,7 @@ def dot_eth_namehash(name): In normal operation, generating the namehash is handled behind the scenes. For advanced usage, it is a helpful utility. - !!This will add '.eth' to name if no TLD given. Also, it normalizes the name with - `nameprep + This normalizes the name with `nameprep `_ before hashing. diff --git a/tests/ens/test_setup_address.py b/tests/ens/test_setup_address.py index bbe41f57a3..547a032335 100644 --- a/tests/ens/test_setup_address.py +++ b/tests/ens/test_setup_address.py @@ -33,11 +33,6 @@ 'tester.eth', '0x2a7ac1c833d35677c2ff34a908951de142cc1653de6080ad4e38f4c9cc00aafe', ), - # ( - # 'tester', - # 'tester.eth', - # '0x2a7ac1c833d35677c2ff34a908951de142cc1653de6080ad4e38f4c9cc00aafe', - # ), ( 'TESTER.eth', 'TESTER.eth', @@ -74,14 +69,8 @@ def test_set_address(ens, name, full_name, namehash_hex, TEST_ADDRESS): ens.setup_address(name, TEST_ADDRESS) assert is_same_address(ens.address(name), TEST_ADDRESS) - # WHAT? AND VERIFY IN TEST_SETUP_NAME.py - # check that .eth is only appended if guess_tld is True namehash = Web3.toBytes(hexstr=namehash_hex) normal_name = ens.nameprep(full_name) - if ens.nameprep(name) == normal_name: - assert is_same_address(ens.address(name, guess_tld=False), TEST_ADDRESS) - else: - assert ens.address(name, guess_tld=False) is None # check that the correct namehash is set: assert is_same_address(ens.resolver(normal_name).addr(namehash), TEST_ADDRESS) @@ -103,9 +92,7 @@ def test_set_address(ens, name, full_name, namehash_hex, TEST_ADDRESS): ), ) def test_set_address_raises_exception_with_invalid_or_missing_tld(ens, name, TEST_ADDRESS): - # assert ens.address(name) is None - owner = ens.owner('tester.eth') - with pytest.raises(InvalidTLD, match="no valid tld"): + with pytest.raises(InvalidTLD, match="Label does not have a recognized TLD."): ens.setup_address(name, TEST_ADDRESS) @@ -184,7 +171,10 @@ def test_set_resolver_leave_default(ens, TEST_ADDRESS): eth = ens.web3.eth num_transactions = eth.getTransactionCount(owner) - ens.setup_address('leave-default-resolver.tester.eth', '0x5B2063246F2191f18F2675ceDB8b28102e957458') + ens.setup_address( + 'leave-default-resolver.tester.eth', + '0x5B2063246F2191f18F2675ceDB8b28102e957458' + ) # should skip setting the owner and setting the default resolver, and only # set the name in the default resolver to point to the new address diff --git a/tests/ens/test_setup_name.py b/tests/ens/test_setup_name.py index 73a917d775..4808d3c2c5 100644 --- a/tests/ens/test_setup_name.py +++ b/tests/ens/test_setup_name.py @@ -64,10 +64,6 @@ def test_setup_name(ens, name, normalized_name, namehash_hex): ens.setup_name(name, address) assert ens.name(address) == normalized_name - # check that .eth is only appended if guess_tld is True - if ens.nameprep(name) != normalized_name: - assert ens.address(name, guess_tld=False) is None - # check that the correct namehash is set: node = Web3.toBytes(hexstr=namehash_hex) assert ens.resolver(normalized_name).addr(node) == address @@ -92,8 +88,7 @@ def test_setup_name(ens, name, normalized_name, namehash_hex): def test_cannot_setup_name_with_missing_or_invalid_tld(ens, name): address = ens.web3.eth.accounts[3] assert not ens.name(address) - owner = ens.owner('tester.eth') - with pytest.raises(InvalidTLD, match="no valid tld"): + with pytest.raises(InvalidTLD, match="Label does not have a recognized TLD."): ens.setup_name(name, address)