Skip to content

Commit

Permalink
test: show nested interfaces work (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Jul 8, 2024
1 parent e2636e1 commit 090e669
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 9 deletions.
4 changes: 3 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ def generate_contracts():
for version in versions:
new_file = PASSING_BASE / f"{file.stem}_{version.replace('.', '')}.vy"
new_file.unlink(missing_ok=True)
new_file.write_text(file.read_text().replace("{{VYPER_VERSION}}", version))
new_file.write_text(
file.read_text(encoding="utf8").replace("{{VYPER_VERSION}}", version)
)


@pytest.fixture
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@view
@external
def read_stuff_nested() -> uint256:
pass
9 changes: 9 additions & 0 deletions tests/contracts/passing_contracts/use_iface.vy
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
# @version ^0.3.3

# Import a local interface.
implements: IFaceNested
from .interfaces import IFace as IFace

# Import from input JSON (ape-config.yaml).
import exampledependency.Dependency as Dep

from .interfaces import IFace2 as IFace2

# Also use IFaceNested to show we can use nested interfaces.
from contracts.passing_contracts.interfaces.nested import IFaceNested as IFaceNested


@external
@view
def read_contract(some_address: address) -> uint256:
myContract: IFace = IFace(some_address)
return myContract.read_stuff()

@view
@external
def read_stuff_nested() -> uint256:
return 1
2 changes: 1 addition & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_cli_flatten(project, contract_name, expected, cli_runner):
arguments.extend([str(file), *end])
result = cli_runner.invoke(cli, arguments, catch_exceptions=False)
assert result.exit_code == 0, result.stderr_bytes
output = file.read_text()
output = file.read_text(encoding="utf8")
for expect in expected:
assert expect in output

Expand Down
5 changes: 3 additions & 2 deletions tests/test_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ def test_get_imports(compiler, project):
builtin_import = "vyper/interfaces/ERC20.json"
local_import = "IFace.vy"
local_from_import = "IFace2.vy"
local_nested_import = "IFaceNested.vy"
dependency_import = "Dependency.vy"

# The source IDs end up as absolute paths because they are in tempdir
Expand All @@ -252,7 +253,7 @@ def test_get_imports(compiler, project):
assert set(actual[contract_37_key]) == {builtin_import}

actual_iface_use = actual[use_iface_key]
for expected in (local_import, local_from_import, dependency_import):
for expected in (local_import, local_from_import, dependency_import, local_nested_import):
assert any(k for k in actual_iface_use if expected in k)

assert actual[use_iface2_key][0].endswith(local_import)
Expand All @@ -268,7 +269,7 @@ def test_pc_map(compiler, project, src, vers):
path = project.sources.lookup(src)
result = list(compiler.compile((path,), project=project))[0]
actual = result.pcmap.root
code = path.read_text()
code = path.read_text(encoding="utf8")
vvm.install_vyper(vers)
cfg = compiler.get_config(project=project)
evm_version = cfg.evm_version
Expand Down
10 changes: 5 additions & 5 deletions tests/test_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def _make_all_files(base: Path, prefix: Optional[Path] = None):
# Hack in in-memory overrides for testing purposes.
text = str(coverage_project.config)
else:
text = file.read_text()
text = file.read_text(encoding="utf8")

src = {name: text.splitlines()}
pytester.makefile(file.suffix, **src)
Expand All @@ -87,7 +87,7 @@ def _make_all_files(base: Path, prefix: Optional[Path] = None):
test_files = {}
for file_path in tests_path.iterdir():
if file_path.name.startswith("test_") and file_path.suffix == ".py":
content = file_path.read_text()
content = file_path.read_text(encoding="utf8")
test_files[file_path.name] = content
num_passes += len(
[
Expand All @@ -104,7 +104,7 @@ def _make_all_files(base: Path, prefix: Optional[Path] = None):
# Check for a conftest.py
conftest = tests_path / "conftest.py"
if conftest.is_file():
pytester.makeconftest(conftest.read_text())
pytester.makeconftest(conftest.read_text(encoding="utf8"))

# Returns expected number of passing tests.
return num_passes, num_failed
Expand Down Expand Up @@ -166,7 +166,7 @@ def _assert_coverage(actual: list[str], expected: list[str]):

def _assert_xml(xml_path: Path):
assert xml_path.is_file()
xml = xml_path.read_text()
xml = xml_path.read_text(encoding="utf8")
assert '<?xml version="1.0" ?>' in xml

# Show is valid XML.
Expand Down Expand Up @@ -198,7 +198,7 @@ def _assert_xml(xml_path: Path):


def _assert_html(index_html: Path):
html = index_html.read_text()
html = index_html.read_text(encoding="utf8")
assert html.startswith("<!DOCTYPE html>")
assert "Generated by Ape Framework" in html
expected_columns = (
Expand Down

0 comments on commit 090e669

Please sign in to comment.