Пример #1
0
def test_to_stdout(tmp_path, capfd):
    path = tmp_path.joinpath('input.json')
    with path.open('w') as fp:
        json.dump(INPUT_JSON, fp)
    _parse_args([path.absolute().as_posix()])
    out, _ = capfd.readouterr()
    output_json = json.loads(out)
    assert 'errors' not in output_json
    assert 'contracts/foo.vy' in output_json['sources']
    assert 'contracts/bar.vy' in output_json['sources']
Пример #2
0
def test_pretty_json(tmp_path, capfd):
    path = tmp_path.joinpath("input.json")
    with path.open("w") as fp:
        json.dump(INPUT_JSON, fp)
    _parse_args([path.absolute().as_posix()])
    out1, _ = capfd.readouterr()
    _parse_args([path.absolute().as_posix(), "--pretty-json"])
    out2, _ = capfd.readouterr()
    assert len(out2) > len(out1)
    assert json.loads(out1) == json.loads(out2)
Пример #3
0
def test_to_stdout(tmp_path, capfd):
    path = tmp_path.joinpath("input.json")
    with path.open("w") as fp:
        json.dump(INPUT_JSON, fp)
    _parse_args([path.absolute().as_posix()])
    out, _ = capfd.readouterr()
    output_json = json.loads(out)
    assert "errors" not in output_json
    assert "contracts/foo.vy" in output_json["sources"]
    assert "contracts/bar.vy" in output_json["sources"]
Пример #4
0
def test_traceback(tmp_path, capfd):
    path = tmp_path.joinpath("input.json")
    input_json = deepcopy(INPUT_JSON)
    del input_json["sources"]
    with path.open("w") as fp:
        json.dump(input_json, fp)
    _parse_args([path.absolute().as_posix()])
    out, _ = capfd.readouterr()
    output_json = json.loads(out)
    assert "errors" in output_json
    with pytest.raises(JSONError):
        _parse_args([path.absolute().as_posix(), "--traceback"])
Пример #5
0
def test_traceback(tmp_path, capfd):
    path = tmp_path.joinpath('input.json')
    input_json = deepcopy(INPUT_JSON)
    del input_json['sources']
    with path.open('w') as fp:
        json.dump(input_json, fp)
    _parse_args([path.absolute().as_posix()])
    out, _ = capfd.readouterr()
    output_json = json.loads(out)
    assert 'errors' in output_json
    with pytest.raises(JSONError):
        _parse_args([path.absolute().as_posix(), '--traceback'])
Пример #6
0
def test_to_file(tmp_path):
    path = tmp_path.joinpath('input.json')
    with path.open('w') as fp:
        json.dump(INPUT_JSON, fp)
    output_path = tmp_path.joinpath('output.json')
    _parse_args([path.absolute().as_posix(), '-o', output_path.absolute().as_posix()])
    assert output_path.exists()
    with output_path.open() as fp:
        output_json = json.load(fp)
    assert 'errors' not in output_json
    assert 'contracts/foo.vy' in output_json['sources']
    assert 'contracts/bar.vy' in output_json['sources']
Пример #7
0
def test_to_file(tmp_path):
    path = tmp_path.joinpath("input.json")
    with path.open("w") as fp:
        json.dump(INPUT_JSON, fp)
    output_path = tmp_path.joinpath("output.json")
    _parse_args(
        [path.absolute().as_posix(), "-o",
         output_path.absolute().as_posix()])
    assert output_path.exists()
    with output_path.open() as fp:
        output_json = json.load(fp)
    assert "errors" not in output_json
    assert "contracts/foo.vy" in output_json["sources"]
    assert "contracts/bar.vy" in output_json["sources"]
Пример #8
0
def _parse_args(argv):
    warnings.simplefilter("always")

    if "--standard-json" in argv:
        argv.remove("--standard-json")
        vyper_json._parse_args(argv)
        return

    parser = argparse.ArgumentParser(
        description="Pythonic Smart Contract Language for the EVM",
        formatter_class=argparse.RawTextHelpFormatter,
    )
    parser.add_argument(
        "input_files",
        help="Vyper sourcecode to compile",
        nargs="+",
    )
    parser.add_argument(
        "--version",
        action="version",
        version=vyper.__version__,
    )
    parser.add_argument(
        "--show-gas-estimates",
        help="Show gas estimates in abi and ir output mode.",
        action="store_true",
    )
    parser.add_argument(
        "-f",
        help=format_options_help,
        default="bytecode",
        dest="format",
    )
    parser.add_argument(
        "--storage-layout-file",
        help="Override storage slots provided by compiler",
        dest="storage_layout",
        nargs="+",
    )
    parser.add_argument(
        "--evm-version",
        help=f"Select desired EVM version (default {DEFAULT_EVM_VERSION})",
        choices=list(EVM_VERSIONS),
        default=DEFAULT_EVM_VERSION,
        dest="evm_version",
    )
    parser.add_argument(
        "--no-optimize",
        help="Do not optimize",
        action="store_true",
    )
    parser.add_argument(
        "--traceback-limit",
        help=
        "Set the traceback limit for error messages reported by the compiler",
        type=int,
    )
    parser.add_argument(
        "--debug",
        help="Turn on compiler debug information. "
        "Currently an alias for --traceback-limit but "
        "may add more information in the future",
        action="store_true",
    )
    parser.add_argument(
        "--standard-json",
        help=
        "Switch to standard JSON mode. Use `--standard-json -h` for available options.",
        action="store_true",
    )
    parser.add_argument(
        "--ir-hex",
        action="store_true",
    )
    parser.add_argument("-p",
                        help="Set the root path for contract imports",
                        default=".",
                        dest="root_folder")
    parser.add_argument("-o", help="Set the output path", dest="output_path")

    args = parser.parse_args(argv)

    if args.traceback_limit is not None:
        sys.tracebacklimit = args.traceback_limit
    elif VYPER_TRACEBACK_LIMIT is not None:
        sys.tracebacklimit = VYPER_TRACEBACK_LIMIT
    elif args.debug:
        sys.tracebacklimit = 1000
    else:
        # Python usually defaults sys.tracebacklimit to 1000.  We use a default
        # setting of zero so error printouts only include information about where
        # an error occurred in a Vyper source file.
        sys.tracebacklimit = 0

    if args.ir_hex:
        lll_node.AS_HEX_DEFAULT = True

    output_formats = tuple(uniq(args.format.split(",")))

    compiled = compile_files(
        args.input_files,
        output_formats,
        args.root_folder,
        args.show_gas_estimates,
        args.evm_version,
        args.no_optimize,
        args.storage_layout,
    )

    if args.output_path:
        with open(args.output_path, "w") as f:
            _cli_helper(f, output_formats, compiled)
    else:
        f = sys.stdout
        _cli_helper(f, output_formats, compiled)
Пример #9
0
def _parse_args(argv):
    warnings.simplefilter("always")

    if "--standard-json" in argv:
        argv.remove("--standard-json")
        vyper_json._parse_args(argv)
        return

    parser = argparse.ArgumentParser(
        description="Pythonic Smart Contract Language for the EVM",
        formatter_class=argparse.RawTextHelpFormatter,
    )
    parser.add_argument(
        "input_files",
        help="Vyper sourcecode to compile",
        nargs="+",
    )
    parser.add_argument(
        "--version",
        action="version",
        version=f"{vyper.__version__}+commit.{vyper.__commit__}",
    )
    parser.add_argument(
        "--show-gas-estimates",
        help="Show gas estimates in ir output mode.",
        action="store_true",
    )
    parser.add_argument(
        "-f",
        help=format_options_help,
        default="bytecode",
        dest="format",
    )
    parser.add_argument(
        "--evm-version",
        help=f"Select desired EVM version (default {DEFAULT_EVM_VERSION})",
        choices=list(EVM_VERSIONS),
        default=DEFAULT_EVM_VERSION,
        dest="evm_version",
    )
    parser.add_argument(
        "--traceback-limit",
        help=
        "Set the traceback limit for error messages reported by the compiler",
        type=int,
    )
    parser.add_argument(
        "--debug",
        help="Turn on compiler debug information. "
        "Currently an alias for --traceback-limit but "
        "may add more information in the future",
        action="store_true",
    )
    parser.add_argument(
        "--standard-json",
        help=
        "Switch to standard JSON mode. Use `--standard-json -h` for available options.",
        action="store_true",
    )
    parser.add_argument("-p",
                        help="Set the root path for contract imports",
                        default=".",
                        dest="root_folder")

    args = parser.parse_args(argv)

    if args.traceback_limit is not None:
        sys.tracebacklimit = args.traceback_limit
    elif VYPER_TRACEBACK_LIMIT is not None:
        sys.tracebacklimit = VYPER_TRACEBACK_LIMIT
    elif args.debug:
        sys.tracebacklimit = 1000
    else:
        # Python usually defaults sys.tracebacklimit to 1000.  We use a default
        # setting of zero so error printouts only include information about where
        # an error occurred in a Vyper source file.
        sys.tracebacklimit = 0

    output_formats = tuple(uniq(args.format.split(",")))

    compiled = compile_files(
        args.input_files,
        output_formats,
        args.root_folder,
        args.show_gas_estimates,
        args.evm_version,
    )

    if output_formats == ("combined_json", ):
        print(json.dumps(compiled))
        return

    for contract_data in compiled.values():
        for data in contract_data.values():
            if isinstance(data, (list, dict)):
                print(json.dumps(data))
            else:
                print(data)