Skip to content

Commit

Permalink
fix simple name optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
Carbon225 committed Nov 27, 2023
1 parent 3baaa2d commit 39f35a6
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 8 deletions.
14 changes: 6 additions & 8 deletions ens_normalize/normalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -905,16 +905,14 @@ def ens_process(input: str,
- `normalizations`: list of `NormalizableSequence` objects or `None` if `do_normalizations` is `False`
"""
if SIMPLE_NAME_REGEX.match(input) is not None:
tokens = [TokenValid(cps=[ord(c) for c in input])]

return ENSProcessResult(
normalized=input,
beautified=input,
tokens=tokens,
cured=None,
cures=None,
normalized=input if do_normalize else None,
beautified=input if do_beautify else None,
tokens=[TokenValid(cps=[ord(c) for c in input])] if do_tokenize else None,
cured=input if do_cure else None,
cures=[] if do_cure else None,
error=None,
normalizations=[],
normalizations=[] if do_normalizations else None,
)

tokens: List[Token] = []
Expand Down
101 changes: 101 additions & 0 deletions tests/test_normalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,3 +423,104 @@ def test_is_normalizable():
assert is_ens_normalizable('nick.eth')
assert not is_ens_normalizable('ni_ck.eth')
assert is_ens_normalizable('')


def test_simple_name_optimization():
r = ens_process(
'abc123',
do_normalize=False,
do_beautify=False,
do_tokenize=False,
do_normalizations=False,
do_cure=False,
)
assert r.normalized is None
assert r.beautified is None
assert r.tokens is None
assert r.cured is None
assert r.cures is None
assert r.error is None
assert r.normalizations is None

r = ens_process(
'abc123',
do_normalize=True,
do_beautify=False,
do_tokenize=False,
do_normalizations=False,
do_cure=False,
)
assert r.normalized == 'abc123'
assert r.beautified is None
assert r.tokens is None
assert r.cured is None
assert r.cures is None
assert r.error is None
assert r.normalizations is None

r = ens_process(
'abc123',
do_normalize=False,
do_beautify=True,
do_tokenize=False,
do_normalizations=False,
do_cure=False,
)
assert r.normalized is None
assert r.beautified == 'abc123'
assert r.tokens is None
assert r.cured is None
assert r.cures is None
assert r.error is None
assert r.normalizations is None

r = ens_process(
'abc123',
do_normalize=False,
do_beautify=False,
do_tokenize=True,
do_normalizations=False,
do_cure=False,
)
assert r.normalized is None
assert r.beautified is None
assert r.tokens is not None
assert r.cured is None
assert r.cures is None
assert r.error is None
assert r.normalizations is None

r = ens_process(
'abc123',
do_normalize=False,
do_beautify=False,
do_tokenize=False,
do_normalizations=True,
do_cure=False,
)

assert r.normalized is None
assert r.beautified is None
assert r.tokens is None
assert r.cured is None
assert r.cures is None
assert r.error is None
assert r.normalizations is not None
assert len(r.normalizations) == 0

r = ens_process(
'abc123',
do_normalize=False,
do_beautify=False,
do_tokenize=False,
do_normalizations=False,
do_cure=True,
)
assert r.normalized is None
assert r.beautified is None
assert r.tokens is None
assert r.cured == 'abc123'
assert r.cures is not None
assert len(r.cures) == 0
assert r.error is None
assert r.normalizations is None

0 comments on commit 39f35a6

Please sign in to comment.