コード例 #1
0
def test_evm_version():
    # should compile differently because of SELFBALANCE
    input_json = deepcopy(INPUT_JSON)
    input_json['settings']['evmVersion'] = "byzantium"
    compiled = compile_from_input_dict(input_json)
    input_json['settings']['evmVersion'] = "istanbul"
    assert compiled != compile_from_input_dict(input_json)
コード例 #2
0
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)
コード例 #3
0
def test_relative_import_paths():
    input_json = deepcopy(INPUT_JSON)
    input_json['sources']['contracts/potato/baz/baz.vy'] = {
        'content': """from ... import foo"""
    }
    input_json['sources']['contracts/potato/baz/potato.vy'] = {
        'content': """from . import baz"""
    }
    input_json['sources']['contracts/potato/footato.vy'] = {
        'content': """from baz import baz"""
    }
    compile_from_input_dict(input_json)
コード例 #4
0
def test_source_ids_increment():
    input_json = deepcopy(INPUT_JSON)
    input_json['outputSelection'] = {'*': ['evm.deployedBytecode.sourceMap']}
    result, _ = compile_from_input_dict(input_json)
    assert result['contracts/bar.vy']['source_map'][
        'pc_pos_map_compressed'].startswith('-1:-1:0')
    assert result['contracts/foo.vy']['source_map'][
        'pc_pos_map_compressed'].startswith('-1:-1:1')
コード例 #5
0
def test_exc_handler_to_dict_syntax():
    input_json = deepcopy(INPUT_JSON)
    input_json['sources']['badcode.vy'] = {'content': BAD_SYNTAX_CODE}
    result, _ = compile_from_input_dict(input_json, exc_handler_to_dict)
    assert 'errors' in result
    assert len(result['errors']) == 1
    error = result['errors'][0]
    assert error['component'] == "parser"
    assert error['type'] == "PythonSyntaxException"
コード例 #6
0
def test_exc_handler_to_dict_syntax():
    input_json = deepcopy(INPUT_JSON)
    input_json["sources"]["badcode.vy"] = {"content": BAD_SYNTAX_CODE}
    result, _ = compile_from_input_dict(input_json, exc_handler_to_dict)
    assert "errors" in result
    assert len(result["errors"]) == 1
    error = result["errors"][0]
    assert error["component"] == "parser"
    assert error["type"] == "SyntaxException"
コード例 #7
0
def test_exc_handler_to_dict_compiler():
    input_json = deepcopy(INPUT_JSON)
    input_json['sources']['badcode.vy'] = {'content': BAD_COMPILER_CODE}
    result, _ = compile_from_input_dict(input_json, exc_handler_to_dict)
    assert sorted(result.keys()) == ['compiler', 'errors']
    assert result['compiler'] == f"vyper-{vyper.__version__}"
    assert len(result['errors']) == 1
    error = result['errors'][0]
    assert error['component'] == "compiler"
    assert error['type'] == "TypeMismatchException"
コード例 #8
0
def test_source_ids_increment():
    input_json = deepcopy(INPUT_JSON)
    input_json["settings"]["outputSelection"] = {
        "*": ["evm.deployedBytecode.sourceMap"]
    }
    result, _ = compile_from_input_dict(input_json)
    assert result["contracts/bar.vy"]["source_map"][
        "pc_pos_map_compressed"].startswith("-1:-1:0")
    assert result["contracts/foo.vy"]["source_map"][
        "pc_pos_map_compressed"].startswith("-1:-1:1")
コード例 #9
0
def test_exc_handler_to_dict_compiler():
    input_json = deepcopy(INPUT_JSON)
    input_json["sources"]["badcode.vy"] = {"content": BAD_COMPILER_CODE}
    result, _ = compile_from_input_dict(input_json, exc_handler_to_dict)
    assert sorted(result.keys()) == ["compiler", "errors"]
    assert result["compiler"] == f"vyper-{vyper.__version__}"
    assert len(result["errors"]) == 1
    error = result["errors"][0]
    assert error["component"] == "compiler"
    assert error["type"] == "InvalidType"
コード例 #10
0
def test_exc_handler_raises_syntax():
    input_json = deepcopy(INPUT_JSON)
    input_json['sources']['badcode.vy'] = {'content': BAD_SYNTAX_CODE}
    with pytest.raises(PythonSyntaxException):
        compile_from_input_dict(input_json, exc_handler_raises)
コード例 #11
0
def test_wrong_language():
    with pytest.raises(JSONError):
        compile_from_input_dict({'language': "Solidity"})
コード例 #12
0
def test_root_folder_not_exists():
    with pytest.raises(FileNotFoundError):
        compile_from_input_dict({}, root_folder="/path/that/does/not/exist")
コード例 #13
0
def test_outputs():
    result, _ = compile_from_input_dict(INPUT_JSON)
    assert sorted(result.keys()) == ['contracts/bar.vy', 'contracts/foo.vy']
    assert sorted(result['contracts/bar.vy'].keys()) == sorted(
        TRANSLATE_MAP.values())
コード例 #14
0
def test_exc_handler_raises_compiler():
    input_json = deepcopy(INPUT_JSON)
    input_json['sources']['badcode.vy'] = {'content': BAD_COMPILER_CODE}
    with pytest.raises(TypeMismatchException):
        compile_from_input_dict(input_json, exc_handler_raises)
コード例 #15
0
def test_exc_handler_raises_syntax():
    input_json = deepcopy(INPUT_JSON)
    input_json["sources"]["badcode.vy"] = {"content": BAD_SYNTAX_CODE}
    with pytest.raises(SyntaxException):
        compile_from_input_dict(input_json, exc_handler_raises)
コード例 #16
0
def test_exc_handler_raises_compiler():
    input_json = deepcopy(INPUT_JSON)
    input_json["sources"]["badcode.vy"] = {"content": BAD_COMPILER_CODE}
    with pytest.raises(InvalidType):
        compile_from_input_dict(input_json, exc_handler_raises)