Esempio n. 1
0
def generate_inline_sources(compiler_output: Dict[str, Any],
                            sources_dir: Path) -> Iterable[Dict[str, str]]:
    for path in compiler_output.keys():
        contract_type = path.split("/")[-1].split(".")[0]
        yield b.inline_source(contract_type,
                              compiler_output,
                              package_root_dir=sources_dir)
Esempio n. 2
0
def test_builder_with_inline_source(owned_package, monkeypatch):
    root, _, compiler_output = owned_package

    monkeypatch.chdir(root)
    manifest = build(BASE_MANIFEST, inline_source("Owned", compiler_output),
                     validate())

    expected = assoc(
        BASE_MANIFEST,
        "sources",
        {
            "./Owned.sol":
            """pragma solidity ^0.4.24;\n\ncontract Owned {\n    address"""
            """ owner;\n    \n    modifier onlyOwner { require(msg.sender == owner); _; }\n\n    """
            """constructor() public {\n        owner = msg.sender;\n    }\n}"""
        },
    )
    assert manifest == expected
def test_builder_with_inline_source(owned_package, monkeypatch):
    root, _, compiler_output = owned_package

    monkeypatch.chdir(root)
    manifest = build(BASE_MANIFEST, inline_source("Owned", compiler_output),
                     validate())

    expected = assoc(
        BASE_MANIFEST,
        "sources",
        {
            "./Owned.sol": {
                "content": OWNED_CONTRACT,
                "installPath": "./Owned.sol",
                "type": "solidity",
            }
        },
    )
    assert manifest == expected
def test_builder_with_inline_source_with_package_root_dir_arg(owned_package):
    root, _, compiler_output = owned_package

    manifest = build(
        BASE_MANIFEST,
        inline_source("Owned", compiler_output, package_root_dir=root),
        validate(),
    )
    expected = assoc(
        BASE_MANIFEST,
        "sources",
        {
            "./Owned.sol": {
                "content": OWNED_CONTRACT,
                "installPath": "./Owned.sol",
                "type": "solidity",
            }
        },
    )
    print(manifest)
    print('-')
    print(expected)
    assert manifest == expected
Esempio n. 5
0
def build_inline_sources(
        contract_types: Iterable[str], solc_output: Dict[str, Any],
        contracts_dir: Path) -> Iterable[Callable[..., Manifest]]:
    return (b.inline_source(ctype, solc_output, contracts_dir)
            for ctype in contract_types)