Skip to content

Commit

Permalink
fix: return contract container
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Oct 27, 2023
1 parent 98e4b57 commit bd0d2ac
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/ape/managers/compilers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from ethpm_types.source import Content

from ape.api import CompilerAPI
from ape.contracts import ContractContainer
from ape.exceptions import ApeAttributeError, CompilerError, ContractLogicError
from ape.logging import logger
from ape.managers.base import BaseManager
Expand Down Expand Up @@ -180,7 +181,7 @@ def compile(self, contract_filepaths: List[Path]) -> Dict[str, ContractType]:

return contract_types_dict

def compile_source(self, compiler_name: str, code: str, **kwargs) -> ContractType:
def compile_source(self, compiler_name: str, code: str, **kwargs) -> ContractContainer:
"""
Compile the given program.
Expand All @@ -197,10 +198,11 @@ def compile_source(self, compiler_name: str, code: str, **kwargs) -> ContractTyp
such as the ``contractName`` when using the JSON compiler.
Returns:
``ContractType``: A compile contract artifact.
``ContractContainer``: A contract container ready to be deployed.
"""
if compiler := self.get_compiler(compiler_name):
return compiler.compile_code(code, **kwargs)
contract_type = compiler.compile_code(code, **kwargs)
return ContractContainer(contract_type=contract_type)

names = [x.name for x in self.registered_compilers.values()]
similar = difflib.get_close_matches(compiler_name, names, cutoff=0.6)
Expand Down
4 changes: 2 additions & 2 deletions tests/functional/test_compilers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from pathlib import Path

import pytest
from ethpm_types import ContractType

from ape.contracts import ContractContainer
from ape.exceptions import APINotImplementedError, CompilerError
from tests.conftest import skip_if_plugin_installed

Expand Down Expand Up @@ -95,4 +95,4 @@ def test_contract_type_collision(compilers, project_with_contract, mock_compiler
def test_compile_source(compilers):
code = '[{"name":"foo","type":"fallback", "stateMutability":"nonpayable"}]'
actual = compilers.compile_source("ethpm", code)
assert isinstance(actual, ContractType)
assert isinstance(actual, ContractContainer)

0 comments on commit bd0d2ac

Please sign in to comment.