Skip to content

Commit

Permalink
fix: allow empty-string content (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
helloibis authored Oct 28, 2022
1 parent 83f2ffa commit 43e3ce5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ethpm_types/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def fetch_content(self) -> str:
"""

# NOTE: This is a trapdoor to bypass fetching logic if already available
if self.content:
if self.content is not None:
return self.content

if len(self.urls) == 0:
Expand Down Expand Up @@ -160,7 +160,7 @@ def content_is_valid(self) -> bool:
"""

# NOTE: Per EIP-2678, checksum is not needed if content does not need to be fetched
if self.content:
if self.content is not None:
return True

# NOTE: Per EIP-2678, Checksum is not required if a URL is content addressed.
Expand Down
10 changes: 10 additions & 0 deletions tests/test_corrupt_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ def bad_checksum() -> Source:
)


@pytest.fixture
def empty_source() -> Source:
return Source.parse_obj({"content": ""})


def test_corrupt_source(bad_checksum, no_checksum):
assert not no_checksum.content_is_valid()
assert not bad_checksum.content_is_valid()


def test_empty_source(empty_source):
assert empty_source.fetch_content() == ""
assert empty_source.content_is_valid()

0 comments on commit 43e3ce5

Please sign in to comment.