def test_keyerror_becomes_jsonerror(): input_json = deepcopy(INPUT_JSON) del input_json["sources"] with pytest.raises(KeyError): compile_from_input_dict(input_json) with pytest.raises(JSONError): compile_json(input_json)
def get_abi(contract_source: str, name: str) -> Dict: """ Given a contract source and name, returns a dict of {name: abi} This function is deprecated in favor of `brownie.project.compiler.get_abi` """ input_json = { "language": "Vyper", "sources": { name: { "content": contract_source } }, "settings": { "outputSelection": { "*": { "*": ["abi"] } } }, } if _active_version == Version(vyper.__version__): try: compiled = vyper_json.compile_json(input_json) except VyperException as exc: raise exc.with_traceback(None) else: try: compiled = vvm.compile_standard(input_json, vyper_version=_active_version) except vvm.exceptions.VyperError as exc: raise CompilerError(exc, "vyper") return {name: compiled["contracts"][name][name]["abi"]}
def compile_from_input_json(input_json: Dict, silent: bool = True, allow_paths: Optional[str] = None) -> Dict: """ Compiles contracts from a standard input json. Args: input_json: vyper input json silent: verbose reporting allow_paths: compiler allowed filesystem import path Returns: standard compiler output json """ version = get_version() if not silent: print("Compiling contracts...") print(f" Vyper version: {version}") if version < Version("0.1.0-beta.17"): outputs = input_json["settings"]["outputSelection"]["*"]["*"] outputs.remove("userdoc") outputs.remove("devdoc") if version == Version(vyper.__version__): try: return vyper_json.compile_json(input_json, root_path=allow_paths) except VyperException as exc: raise exc.with_traceback(None) else: try: return vvm.compile_standard(input_json, base_path=allow_paths, vyper_version=version) except vvm.exceptions.VyperError as exc: raise CompilerError(exc, "vyper")
def get_abi(contract_source: str, name: str) -> Dict: """Given a contract source and name, returns a dict of {name: abi}""" compiled = vyper_json.compile_json( { "language": "Vyper", "sources": {name: {"content": contract_source}}, "settings": {"outputSelection": {"*": {"*": ["abi"]}}}, } ) return {name: compiled["contracts"][name][name]["abi"]}
def get_abi(contract_source: str, name: str) -> Dict: """ Given a contract source and name, returns a dict of {name: abi} This function is deprecated in favor of `brownie.project.compiler.get_abi` """ compiled = vyper_json.compile_json( { "language": "Vyper", "sources": {name: {"content": contract_source}}, "settings": {"outputSelection": {"*": {"*": ["abi"]}}}, } ) return {name: compiled["contracts"][name][name]["abi"]}
def compile_from_input_json(input_json: Dict, silent: bool = True, allow_paths: Optional[str] = None) -> Dict: """ Compiles contracts from a standard input json. Args: input_json: solc input json silent: verbose reporting allow_paths: compiler allowed filesystem import path Returns: standard compiler output json """ if not silent: print("Compiling contracts...") print(f" Vyper version: {get_version()}") return vyper_json.compile_json(input_json, root_path=allow_paths)
def test_bad_json(): with pytest.raises(JSONError): compile_json("this probably isn't valid JSON, is it")
def test_input_formats(): assert compile_json(INPUT_JSON) == compile_json(json.dumps(INPUT_JSON))