Skip to content

Commit ec37813

Browse files
committed
Remove guess_tld optional arg
1 parent 922dfea commit ec37813

File tree

6 files changed

+17
-46
lines changed

6 files changed

+17
-46
lines changed

docs/ens_overview.rst

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,8 @@ Look up the address for an ENS name
6060

6161
assert eth_address == '0x5B2063246F2191f18F2675ceDB8b28102e957458'
6262

63-
64-
# ens.py will assume you want a .eth name if you don't specify a full name
65-
66-
assert ns.address('jasoncarver') == eth_address
63+
# ens.py only support names using one of these recognized TLDs
64+
# ['eth', 'reverse', 'test', 'luxe', 'xyz']
6765

6866

6967
Get name from address

ens/exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,6 @@ class UnderfundedBid(ValueError):
8181

8282
class InvalidTLD(ValueError):
8383
'''
84-
Raised if ...
84+
Raised if name does not contain a recognized TLD.
8585
'''
8686
pass

ens/main.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,14 @@ def fromWeb3(cls, web3, addr=None):
7272
'''
7373
return cls(web3.manager.provider, addr=addr)
7474

75-
# INFERS
76-
def address(self, name, guess_tld=True):
75+
def address(self, name):
7776
'''
7877
Look up the Ethereum address that `name` currently points to.
7978
8079
:param str name: an ENS name to look up
81-
:param bool guess_tld: should `name` be appended with '.eth' if no common TLD found?
8280
:raises InvalidName: if `name` has invalid syntax
8381
'''
84-
if guess_tld:
85-
expanded = dot_eth_name(name)
86-
else:
87-
expanded = name
88-
return self.resolve(expanded, 'addr')
82+
return self.resolve(name, 'addr')
8983

9084
def name(self, address):
9185
'''
@@ -99,7 +93,6 @@ def name(self, address):
9993
return self.resolve(reversed_domain, get='name')
10094
reverse = name
10195

102-
# INFER
10396
@dict_copy
10497
def setup_address(self, name, address=default, transact={}):
10598
'''
@@ -137,7 +130,6 @@ def setup_address(self, name, address=default, transact={}):
137130
resolver = self._set_resolver(name, transact=transact)
138131
return resolver.setAddr(dot_eth_namehash(name), address, transact=transact)
139132

140-
# INFER
141133
@dict_copy
142134
def setup_name(self, name, address=None, transact={}):
143135
'''
@@ -181,7 +173,6 @@ def setup_name(self, name, address=None, transact={}):
181173
self.setup_address(name, address, transact=transact)
182174
return self._setup_reverse(name, address, transact=transact)
183175

184-
# INFER
185176
def resolve(self, name, get='addr'):
186177
normal_name = normalize_name(name)
187178
resolver = self.resolver(normal_name)
@@ -202,7 +193,6 @@ def reverser(self, target_address):
202193
reversed_domain = address_to_reverse_domain(target_address)
203194
return self.resolver(reversed_domain)
204195

205-
# INFER
206196
def owner(self, name):
207197
'''
208198
Get the owner of a name. Note that this may be different from the
@@ -217,7 +207,6 @@ def owner(self, name):
217207
node = dot_eth_namehash(name)
218208
return self.ens.owner(node)
219209

220-
# INFER
221210
@dict_copy
222211
def setup_owner(self, name, new_owner=default, transact={}):
223212
'''

ens/utils.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,18 @@ def is_valid_name(name):
109109
return False
110110

111111

112-
# INFERS
113-
# CAN we get rid of this?
114-
def label_to_name(label, default_tld, recognized_tlds):
112+
def label_to_name(label, recognized_tlds):
115113
label = normalize_name(label)
116114
pieces = label.split('.')
117115
if pieces[-1] not in recognized_tlds:
118-
raise InvalidTLD("no valid tld")
116+
raise InvalidTLD(
117+
f"Label does not have a recognized TLD. TLD must match one of: {recognized_tlds}."
118+
)
119119
return '.'.join(pieces)
120120

121121

122122
def dot_eth_name(label):
123-
return label_to_name(label, 'eth', RECOGNIZED_TLDS)
123+
return label_to_name(label, RECOGNIZED_TLDS)
124124

125125

126126
def name_to_label(name, registrar):
@@ -193,8 +193,7 @@ def dot_eth_namehash(name):
193193
In normal operation, generating the namehash is handled
194194
behind the scenes. For advanced usage, it is a helpful utility.
195195
196-
!!This will add '.eth' to name if no TLD given. Also, it normalizes the name with
197-
`nameprep
196+
This normalizes the name with `nameprep
198197
<https://github.com/ethereum/EIPs/blob/master/EIPS/eip-137.md#name-syntax>`_
199198
before hashing.
200199

tests/ens/test_setup_address.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@
3333
'tester.eth',
3434
'0x2a7ac1c833d35677c2ff34a908951de142cc1653de6080ad4e38f4c9cc00aafe',
3535
),
36-
# (
37-
# 'tester',
38-
# 'tester.eth',
39-
# '0x2a7ac1c833d35677c2ff34a908951de142cc1653de6080ad4e38f4c9cc00aafe',
40-
# ),
4136
(
4237
'TESTER.eth',
4338
'TESTER.eth',
@@ -74,14 +69,8 @@ def test_set_address(ens, name, full_name, namehash_hex, TEST_ADDRESS):
7469
ens.setup_address(name, TEST_ADDRESS)
7570
assert is_same_address(ens.address(name), TEST_ADDRESS)
7671

77-
# WHAT? AND VERIFY IN TEST_SETUP_NAME.py
78-
# check that .eth is only appended if guess_tld is True
7972
namehash = Web3.toBytes(hexstr=namehash_hex)
8073
normal_name = ens.nameprep(full_name)
81-
if ens.nameprep(name) == normal_name:
82-
assert is_same_address(ens.address(name, guess_tld=False), TEST_ADDRESS)
83-
else:
84-
assert ens.address(name, guess_tld=False) is None
8574

8675
# check that the correct namehash is set:
8776
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):
10392
),
10493
)
10594
def test_set_address_raises_exception_with_invalid_or_missing_tld(ens, name, TEST_ADDRESS):
106-
# assert ens.address(name) is None
107-
owner = ens.owner('tester.eth')
108-
with pytest.raises(InvalidTLD, match="no valid tld"):
95+
with pytest.raises(InvalidTLD, match="Label does not have a recognized TLD."):
10996
ens.setup_address(name, TEST_ADDRESS)
11097

11198

@@ -184,7 +171,10 @@ def test_set_resolver_leave_default(ens, TEST_ADDRESS):
184171
eth = ens.web3.eth
185172
num_transactions = eth.getTransactionCount(owner)
186173

187-
ens.setup_address('leave-default-resolver.tester.eth', '0x5B2063246F2191f18F2675ceDB8b28102e957458')
174+
ens.setup_address(
175+
'leave-default-resolver.tester.eth',
176+
'0x5B2063246F2191f18F2675ceDB8b28102e957458'
177+
)
188178

189179
# should skip setting the owner and setting the default resolver, and only
190180
# set the name in the default resolver to point to the new address

tests/ens/test_setup_name.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,6 @@ def test_setup_name(ens, name, normalized_name, namehash_hex):
6464
ens.setup_name(name, address)
6565
assert ens.name(address) == normalized_name
6666

67-
# check that .eth is only appended if guess_tld is True
68-
if ens.nameprep(name) != normalized_name:
69-
assert ens.address(name, guess_tld=False) is None
70-
7167
# check that the correct namehash is set:
7268
node = Web3.toBytes(hexstr=namehash_hex)
7369
assert ens.resolver(normalized_name).addr(node) == address
@@ -92,8 +88,7 @@ def test_setup_name(ens, name, normalized_name, namehash_hex):
9288
def test_cannot_setup_name_with_missing_or_invalid_tld(ens, name):
9389
address = ens.web3.eth.accounts[3]
9490
assert not ens.name(address)
95-
owner = ens.owner('tester.eth')
96-
with pytest.raises(InvalidTLD, match="no valid tld"):
91+
with pytest.raises(InvalidTLD, match="Label does not have a recognized TLD."):
9792
ens.setup_name(name, address)
9893

9994

0 commit comments

Comments
 (0)