Skip to content

Commit

Permalink
test: integ test
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Sep 10, 2024
1 parent 8cc1f5e commit 4a1ab63
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
10 changes: 1 addition & 9 deletions src/ape_pm/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,7 @@ def compile(

code = src_path.read_text()
source_id = source_ids[path]
try:
# NOTE: Always set the source ID to the source of the JSON file
# to avoid manifest corruptions later on.
contract_type = self.compile_code(code, project=project, sourceId=source_id)
except CompilerError as err:
logger.warning(
f"Unable to parse {ContractType.__name__} from '{source_id}'. Reason: {err}"
)
continue
contract_type = self.compile_code(code, project=project, sourceId=source_id)

# NOTE: Try getting name/ ID from code-JSON first.
# That's why this is not part of `**kwargs` in `compile_code()`.
Expand Down
27 changes: 27 additions & 0 deletions tests/integration/cli/test_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,33 @@ def test_compile_when_sources_change(ape_cli, runner, integ_project, clean_cache
assert "contracts/Interface.json" not in result.output


@skip_projects_except("multiple-interfaces")
def test_compile_when_sources_change_problematically(ape_cli, runner, integ_project, clean_cache):
"""
There was a bug when sources changes but had errors, that the old sources continued
to be used and the errors were swallowed.
"""
source_path = integ_project.contracts_folder / "Interface.json"
content = source_path.read_text()
assert "bar" in content, "Test setup failed - unexpected content"

result = runner.invoke(
ape_cli, ("compile", "--project", f"{integ_project.path}"), catch_exceptions=False
)
assert result.exit_code == 0, result.output

# Change the contents of a file in a problematic way.
source_path = integ_project.contracts_folder / "Interface.json"
modified_source_text = source_path.read_text().replace("{", "BRACKET")
source_path.unlink()
source_path.touch()
source_path.write_text(modified_source_text, encoding="utf8")
result = runner.invoke(
ape_cli, ("compile", "--project", f"{integ_project.path}"), catch_exceptions=False
)
assert result.exit_code != 0, result.output


@skip_projects_except("multiple-interfaces")
def test_compile_when_contract_type_collision(ape_cli, runner, integ_project, clean_cache):
source_path = integ_project.contracts_folder / "Interface.json"
Expand Down

0 comments on commit 4a1ab63

Please sign in to comment.