From 00fed00119501b519d2ab0254c8d3a0df74f3ccd Mon Sep 17 00:00:00 2001 From: Juliya Smith Date: Tue, 24 Sep 2024 13:01:19 -0500 Subject: [PATCH] test: order --- ape_vyper/flattener.py | 7 +++---- ape_vyper/imports.py | 12 ++++++++---- tests/functional/test_compiler.py | 18 +++++++++--------- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/ape_vyper/flattener.py b/ape_vyper/flattener.py index 8f6415d..5a47400 100644 --- a/ape_vyper/flattener.py +++ b/ape_vyper/flattener.py @@ -71,8 +71,7 @@ def _flatten_source( # Vyper imported interface names come from their file names file_name = import_path.stem # If we have a known alias, ("import X as Y"), use the alias as interface name - iface_name = aliases[file_name] if file_name in aliases else file_name - + import_name = aliases[file_name] if file_name in aliases else file_name dependency = import_info.sub_project if ( dependency is not None @@ -84,7 +83,7 @@ def _flatten_source( for k in dependency.manifest.contract_types.keys() for el in dependency.manifest.contract_types[k].abi ] - interfaces_source += generate_interface(abis, iface_name) + interfaces_source += generate_interface(abis, import_name) continue # Generate an ABI from the source code @@ -121,7 +120,7 @@ def _flatten_source( # Vyper <0.4 interface from folder other than interfaces/ # such as a .vyi file in the contracts folder. abis = source_to_abi(import_path.read_text(encoding="utf8")) - interfaces_source += generate_interface(abis, iface_name) + interfaces_source += generate_interface(abis, import_name) def no_nones(it: Iterable[Optional[str]]) -> Iterable[str]: # Type guard like generator to remove Nones and make mypy happy diff --git a/ape_vyper/imports.py b/ape_vyper/imports.py index f6d63dd..c18f2bc 100644 --- a/ape_vyper/imports.py +++ b/ape_vyper/imports.py @@ -287,9 +287,13 @@ def __contains__(self, item: Union[str, Path]) -> bool: # type: ignore else: return super().__contains__(item) + def __iter__(self): + yield from self.keys() # sorted + def keys(self) -> list[Path]: # type: ignore result = [] - for path in super().keys(): + keys = sorted(list(super().keys())) + for path in keys: if path not in self._request_view: continue @@ -299,18 +303,18 @@ def keys(self) -> list[Path]: # type: ignore def values(self) -> list[list[Import]]: # type: ignore result = [] - for key in self.keys(): + for key in self.keys(): # sorted result.append(self[key]) return result def items(self) -> list[tuple[Path, list[Import]]]: # type: ignore result = [] - for path, import_ls in super().items(): + for path in self.keys(): # sorted if path not in self._request_view: continue - result.append((path, import_ls)) + result.append((path, self[path])) return result diff --git a/tests/functional/test_compiler.py b/tests/functional/test_compiler.py index 4ec4827..07fd984 100644 --- a/tests/functional/test_compiler.py +++ b/tests/functional/test_compiler.py @@ -132,6 +132,15 @@ def _transfer_ownership(new_owner: address): log OwnershipTransferred(old_owner, new_owner) +# Showing importing interface from module. +interface Ballot: + def delegated(addr: address) -> bool: view + +@internal +def moduleMethod2() -> bool: + return True + + # This source is also imported from `zero_four.py` to test # multiple imports across sources during flattening. @@ -145,15 +154,6 @@ def callModule2FunctionFromAnotherSource(role: bytes32) -> bool: return self.moduleMethod2() -# Showing importing interface from module. -interface Ballot: - def delegated(addr: address) -> bool: view - -@internal -def moduleMethod2() -> bool: - return True - - implements: IFaceZeroFour