Merge pull request #10680 from ethereum/more-features-in-prepare-report

More features in prepare_report.py
This commit is contained in:
chriseth
2021-02-03 11:51:51 +01:00
committed by GitHub
3 changed files with 167 additions and 43 deletions
@@ -9,7 +9,7 @@ from unittest_helpers import FIXTURE_DIR, LIBSOLIDITY_TEST_DIR, load_fixture, lo
# NOTE: This test file file only works with scripts/ added to PYTHONPATH so pylint can't find the imports
# pragma pylint: disable=import-error
from bytecodecompare.prepare_report import CompilerInterface, FileReport, ContractReport, SMTUse
from bytecodecompare.prepare_report import CompilerInterface, FileReport, ContractReport, SMTUse, Statistics
from bytecodecompare.prepare_report import load_source, parse_cli_output, parse_standard_json_output, prepare_compiler_input
# pragma pylint: enable=import-error
@@ -99,6 +99,58 @@ class TestFileReport(PrepareReportTestBase):
self.assertEqual(report.format_report(), '')
class TestPrepareReport_Statistics(unittest.TestCase):
def test_initialization(self):
self.assertEqual(Statistics(), Statistics(0, 0, 0, 0, 0))
def test_aggregate_bytecode_and_metadata_present(self):
statistics = Statistics()
statistics.aggregate(FileReport(file_name=Path('F'), contract_reports=[ContractReport('C', 'c.sol', 'B', 'M')]))
self.assertEqual(statistics, Statistics(1, 1, 0, 0, 0))
def test_aggregate_bytecode_missing(self):
statistics = Statistics()
statistics.aggregate(FileReport(file_name=Path('F'), contract_reports=[ContractReport('C', 'c.sol', None, 'M')]))
self.assertEqual(statistics, Statistics(1, 1, 0, 1, 0))
def test_aggregate_metadata_missing(self):
statistics = Statistics()
statistics.aggregate(FileReport(file_name=Path('F'), contract_reports=[ContractReport('C', 'c.sol', 'B', None)]))
self.assertEqual(statistics, Statistics(1, 1, 0, 0, 1))
def test_aggregate_no_contract_reports(self):
statistics = Statistics()
statistics.aggregate(FileReport(file_name=Path('F'), contract_reports=[]))
self.assertEqual(statistics, Statistics(1, 0, 0, 0, 0))
def test_aggregate_missing_contract_report_list(self):
statistics = Statistics()
statistics.aggregate(FileReport(file_name=Path('F'), contract_reports=None))
self.assertEqual(statistics, Statistics(1, 0, 1, 0, 0))
def test_aggregate_multiple_contract_reports(self):
statistics = Statistics()
statistics.aggregate(FileReport(file_name=Path('F'), contract_reports=[
ContractReport('C', 'c.sol', 'B', 'M'),
ContractReport('C', 'c.sol', None, 'M'),
ContractReport('C', 'c.sol', 'B', None),
ContractReport('C', 'c.sol', None, None),
]))
self.assertEqual(statistics, Statistics(1, 4, 0, 2, 2))
def test_str(self):
statistics = Statistics()
statistics.aggregate(FileReport(file_name=Path('F'), contract_reports=[
ContractReport('C', 'c.sol', 'B', 'M'),
ContractReport('C', 'c.sol', None, 'M'),
ContractReport('C', 'c.sol', 'B', None),
ContractReport('C', 'c.sol', None, None),
]))
statistics.aggregate(FileReport(file_name=Path('F'), contract_reports=None))
self.assertEqual(statistics, Statistics(2, 4, 1, 2, 2))
self.assertEqual(str(statistics), "test cases: 2, contracts: 4+, errors: 1, missing bytecode: 2, missing metadata: 2")
class TestLoadSource(PrepareReportTestBase):
def test_load_source_should_strip_smt_pragmas_if_requested(self):