From 090e669ebb1aa02bcb3663ed15e109e21813cda4 Mon Sep 17 00:00:00 2001 From: antazoey Date: Mon, 8 Jul 2024 15:45:59 -0500 Subject: [PATCH] test: show nested interfaces work (#123) --- tests/conftest.py | 4 +++- .../passing_contracts/interfaces/nested/IFaceNested.vy | 4 ++++ tests/contracts/passing_contracts/use_iface.vy | 9 +++++++++ tests/test_cli.py | 2 +- tests/test_compiler.py | 5 +++-- tests/test_coverage.py | 10 +++++----- 6 files changed, 25 insertions(+), 9 deletions(-) create mode 100644 tests/contracts/passing_contracts/interfaces/nested/IFaceNested.vy diff --git a/tests/conftest.py b/tests/conftest.py index 76589955..e2ce1825 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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 diff --git a/tests/contracts/passing_contracts/interfaces/nested/IFaceNested.vy b/tests/contracts/passing_contracts/interfaces/nested/IFaceNested.vy new file mode 100644 index 00000000..daea8ea9 --- /dev/null +++ b/tests/contracts/passing_contracts/interfaces/nested/IFaceNested.vy @@ -0,0 +1,4 @@ +@view +@external +def read_stuff_nested() -> uint256: + pass diff --git a/tests/contracts/passing_contracts/use_iface.vy b/tests/contracts/passing_contracts/use_iface.vy index 76aa4e8d..b29c6fff 100644 --- a/tests/contracts/passing_contracts/use_iface.vy +++ b/tests/contracts/passing_contracts/use_iface.vy @@ -1,6 +1,7 @@ # @version ^0.3.3 # Import a local interface. +implements: IFaceNested from .interfaces import IFace as IFace # Import from input JSON (ape-config.yaml). @@ -8,9 +9,17 @@ 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 diff --git a/tests/test_cli.py b/tests/test_cli.py index 7bfcf24e..4f68f5f7 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -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 diff --git a/tests/test_compiler.py b/tests/test_compiler.py index da2eb94b..395bf009 100644 --- a/tests/test_compiler.py +++ b/tests/test_compiler.py @@ -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 @@ -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) @@ -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 diff --git a/tests/test_coverage.py b/tests/test_coverage.py index 420a6280..64229ed6 100644 --- a/tests/test_coverage.py +++ b/tests/test_coverage.py @@ -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) @@ -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( [ @@ -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 @@ -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 '' in xml # Show is valid XML. @@ -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("") assert "Generated by Ape Framework" in html expected_columns = (