mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
prepare_report.py: Make parsing more lax to handle output from older compiler versions
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
contract.sol:1:1: Warning: Source file does not specify required compiler version! Consider adding "pragma solidity ^0.4.0;".
|
||||
contract C {}
|
||||
^
|
||||
Spanning multiple lines.
|
||||
|
||||
======= C =======
|
||||
Binary:
|
||||
6060604052600c8060106000396000f360606040526008565b600256
|
||||
@@ -0,0 +1,10 @@
|
||||
contract.sol:1:1: Warning: Source file does not specify required compiler version!Consider adding "pragma solidity ^0.4.8
|
||||
contract C {}
|
||||
^
|
||||
Spanning multiple lines.
|
||||
|
||||
======= C =======
|
||||
Binary:
|
||||
6060604052346000575b60358060166000396000f30060606040525b60005600a165627a7a72305820ccf9337430b4c4f7d6ad41efb10a94411a2af6a9f173ef52daeadd31f4bf11890029
|
||||
Metadata:
|
||||
{"compiler":{"version":"0.4.8+commit.60cc1668.mod.Darwin.appleclang"},"language":"Solidity","output":{"abi":[],"devdoc":{"methods":{}},"userdoc":{"methods":{}}},"settings":{"compilationTarget":{"contract.sol":"C"},"libraries":{},"optimizer":{"enabled":false,"runs":200},"remappings":[]},"sources":{"contract.sol":{"keccak256":"0xbe86d3681a198587296ad6d4a834606197e1a8f8944922c501631b04e21eeba2","urls":["bzzr://af16957d3d86013309d64d3cc572d007b1d8b08a821f2ff366840deb54a78524"]}},"version":1}
|
||||
@@ -32,6 +32,9 @@ STACK_TOO_DEEP_CLI_OUTPUT = load_fixture('stack_too_deep_cli_output.txt')
|
||||
CODE_GENERATION_ERROR_JSON_OUTPUT = load_fixture('code_generation_error_json_output.json')
|
||||
CODE_GENERATION_ERROR_CLI_OUTPUT = load_fixture('code_generation_error_cli_output.txt')
|
||||
|
||||
SOLC_0_4_0_CLI_OUTPUT = load_fixture('solc_0.4.0_cli_output.txt')
|
||||
SOLC_0_4_8_CLI_OUTPUT = load_fixture('solc_0.4.8_cli_output.txt')
|
||||
|
||||
|
||||
class TestPrepareReport_FileReport(unittest.TestCase):
|
||||
def test_format_report(self):
|
||||
@@ -228,6 +231,34 @@ class TestPrepareReport(unittest.TestCase):
|
||||
|
||||
self.assertEqual(parse_standard_json_output(Path('file.sol'), CODE_GENERATION_ERROR_JSON_OUTPUT), expected_report)
|
||||
|
||||
def test_parse_standard_json_output_should_report_missing_if_value_is_just_whitespace(self):
|
||||
compiler_output = dedent("""\
|
||||
{
|
||||
"contracts": {
|
||||
"contract.sol": {
|
||||
"A": {
|
||||
"evm": {"bytecode": {"object": ""}},
|
||||
"metadata": ""
|
||||
},
|
||||
"B": {
|
||||
"evm": {"bytecode": {"object": " "}},
|
||||
"metadata": " "
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
""")
|
||||
|
||||
expected_report = FileReport(
|
||||
file_name=Path('contract.sol'),
|
||||
contract_reports=[
|
||||
ContractReport(contract_name='A', file_name=Path('contract.sol'), bytecode=None, metadata=None),
|
||||
ContractReport(contract_name='B', file_name=Path('contract.sol'), bytecode=None, metadata=None),
|
||||
]
|
||||
)
|
||||
|
||||
self.assertEqual(parse_standard_json_output(Path('contract.sol'), compiler_output), expected_report)
|
||||
|
||||
def test_parse_cli_output(self):
|
||||
expected_report = FileReport(
|
||||
file_name=Path('syntaxTests/scoping/library_inherited2.sol'),
|
||||
@@ -319,3 +350,103 @@ class TestPrepareReport(unittest.TestCase):
|
||||
expected_report = FileReport(file_name=Path('file.sol'), contract_reports=None)
|
||||
|
||||
self.assertEqual(parse_cli_output(Path('file.sol'), CODE_GENERATION_ERROR_CLI_OUTPUT), expected_report)
|
||||
|
||||
def test_parse_cli_output_should_handle_output_from_solc_0_4_0(self):
|
||||
expected_report = FileReport(
|
||||
file_name=Path('contract.sol'),
|
||||
contract_reports=[
|
||||
ContractReport(
|
||||
contract_name='C',
|
||||
file_name=None,
|
||||
bytecode='6060604052600c8060106000396000f360606040526008565b600256',
|
||||
metadata=None,
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
self.assertEqual(parse_cli_output(Path('contract.sol'), SOLC_0_4_0_CLI_OUTPUT), expected_report)
|
||||
|
||||
def test_parse_cli_output_should_handle_output_from_solc_0_4_8(self):
|
||||
expected_report = FileReport(
|
||||
file_name=Path('contract.sol'),
|
||||
contract_reports=[
|
||||
ContractReport(
|
||||
contract_name='C',
|
||||
file_name=None,
|
||||
bytecode='6060604052346000575b60358060166000396000f30060606040525b60005600a165627a7a72305820ccf9337430b4c4f7d6ad41efb10a94411a2af6a9f173ef52daeadd31f4bf11890029',
|
||||
metadata='{"compiler":{"version":"0.4.8+commit.60cc1668.mod.Darwin.appleclang"},"language":"Solidity","output":{"abi":[],"devdoc":{"methods":{}},"userdoc":{"methods":{}}},"settings":{"compilationTarget":{"contract.sol":"C"},"libraries":{},"optimizer":{"enabled":false,"runs":200},"remappings":[]},"sources":{"contract.sol":{"keccak256":"0xbe86d3681a198587296ad6d4a834606197e1a8f8944922c501631b04e21eeba2","urls":["bzzr://af16957d3d86013309d64d3cc572d007b1d8b08a821f2ff366840deb54a78524"]}},"version":1}',
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
self.assertEqual(parse_cli_output(Path('contract.sol'), SOLC_0_4_8_CLI_OUTPUT), expected_report)
|
||||
|
||||
def test_parse_cli_output_should_handle_leading_and_trailing_spaces(self):
|
||||
compiler_output = (
|
||||
' ======= contract.sol : C ======= \n'
|
||||
' Binary: \n'
|
||||
' 60806040523480156 \n'
|
||||
' Metadata: \n'
|
||||
' { } \n'
|
||||
)
|
||||
|
||||
expected_report = FileReport(
|
||||
file_name=Path('contract.sol'),
|
||||
contract_reports=[ContractReport(contract_name='C', file_name=Path('contract.sol'), bytecode='60806040523480156', metadata='{ }')]
|
||||
)
|
||||
|
||||
self.assertEqual(parse_cli_output(Path('contract.sol'), compiler_output), expected_report)
|
||||
|
||||
def test_parse_cli_output_should_handle_empty_bytecode_and_metadata_lines(self):
|
||||
compiler_output = dedent("""\
|
||||
======= contract.sol:C =======
|
||||
Binary:
|
||||
60806040523480156
|
||||
Metadata:
|
||||
|
||||
|
||||
======= contract.sol:D =======
|
||||
Binary:
|
||||
|
||||
Metadata:
|
||||
{}
|
||||
|
||||
|
||||
======= contract.sol:E =======
|
||||
Binary:
|
||||
|
||||
Metadata:
|
||||
|
||||
|
||||
""")
|
||||
|
||||
expected_report = FileReport(
|
||||
file_name=Path('contract.sol'),
|
||||
contract_reports=[
|
||||
ContractReport(contract_name='C', file_name=Path('contract.sol'), bytecode='60806040523480156', metadata=None),
|
||||
ContractReport(contract_name='D', file_name=Path('contract.sol'), bytecode=None, metadata='{}'),
|
||||
ContractReport(contract_name='E', file_name=Path('contract.sol'), bytecode=None, metadata=None),
|
||||
]
|
||||
)
|
||||
|
||||
self.assertEqual(parse_cli_output(Path('contract.sol'), compiler_output), expected_report)
|
||||
|
||||
def test_parse_cli_output_should_handle_link_references_in_bytecode(self):
|
||||
compiler_output = dedent("""\
|
||||
======= contract.sol:C =======
|
||||
Binary:
|
||||
73123456789012345678901234567890123456789073__$fb58009a6b1ecea3b9d99bedd645df4ec3$__5050
|
||||
======= contract.sol:D =======
|
||||
Binary:
|
||||
__$fb58009a6b1ecea3b9d99bedd645df4ec3$__
|
||||
""")
|
||||
|
||||
expected_report = FileReport(
|
||||
file_name=Path('contract.sol'),
|
||||
contract_reports=[
|
||||
ContractReport(contract_name='C', file_name=Path('contract.sol'), bytecode='73123456789012345678901234567890123456789073__$fb58009a6b1ecea3b9d99bedd645df4ec3$__5050', metadata=None),
|
||||
ContractReport(contract_name='D', file_name=Path('contract.sol'), bytecode='__$fb58009a6b1ecea3b9d99bedd645df4ec3$__', metadata=None),
|
||||
]
|
||||
)
|
||||
|
||||
self.assertEqual(parse_cli_output(Path('contract.sol'), compiler_output), expected_report)
|
||||
|
||||
Reference in New Issue
Block a user