Skip to content

Commit

Permalink
test: order
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Sep 24, 2024
1 parent a9b00c0 commit 00fed00
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
7 changes: 3 additions & 4 deletions ape_vyper/flattener.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions ape_vyper/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
18 changes: 9 additions & 9 deletions tests/functional/test_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down

0 comments on commit 00fed00

Please sign in to comment.