#!/usr/bin/env python3

from dataclasses import asdict
import unittest

from textwrap import dedent

from unittest_helpers import FIXTURE_DIR, load_fixture

# 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 externalTests.parse_eth_gas_report import parse_report, ReportParsingError, ReportValidationError
# pragma pylint: enable=import-error

ETH_GAS_REPORT_GNOSIS_RST_PATH = FIXTURE_DIR / 'eth_gas_report_gnosis.rst'
ETH_GAS_REPORT_GNOSIS_RST_CONTENT = load_fixture(
    ETH_GAS_REPORT_GNOSIS_RST_PATH)


class TestEthGasReport(unittest.TestCase):
    def setUp(self):
        self.maxDiff = 10000

    def test_parse_report(self):
        parsed_report = parse_report(ETH_GAS_REPORT_GNOSIS_RST_CONTENT)

        expected_report = {
            'solc_version':
            '0.8.10',
            'optimize':
            True,
            'runs':
from unittest_helpers import FIXTURE_DIR, LIBSOLIDITY_TEST_DIR, load_fixture, load_libsolidity_test_case

# 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, Statistics
from bytecodecompare.prepare_report import load_source, parse_cli_output, parse_standard_json_output, prepare_compiler_input
# pragma pylint: enable=import-error

SMT_SMOKE_TEST_SOL_PATH = LIBSOLIDITY_TEST_DIR / 'smtCheckerTests/simple/smoke_test.sol'
SMT_SMOKE_TEST_SOL_CODE = load_libsolidity_test_case(SMT_SMOKE_TEST_SOL_PATH)

SMT_CONTRACT_WITH_LF_NEWLINES_SOL_PATH = FIXTURE_DIR / 'smt_contract_with_lf_newlines.sol'
SMT_CONTRACT_WITH_CRLF_NEWLINES_SOL_PATH = FIXTURE_DIR / 'smt_contract_with_crlf_newlines.sol'
SMT_CONTRACT_WITH_CR_NEWLINES_SOL_PATH = FIXTURE_DIR / 'smt_contract_with_cr_newlines.sol'
SMT_CONTRACT_WITH_MIXED_NEWLINES_SOL_PATH = FIXTURE_DIR / 'smt_contract_with_mixed_newlines.sol'
SMT_CONTRACT_WITH_MIXED_NEWLINES_SOL_CODE = load_fixture(
    SMT_CONTRACT_WITH_MIXED_NEWLINES_SOL_PATH)

SYNTAX_SMOKE_TEST_SOL_PATH = LIBSOLIDITY_TEST_DIR / 'syntaxTests/smoke_test.sol'
SYNTAX_SMOKE_TEST_SOL_CODE = load_libsolidity_test_case(
    SYNTAX_SMOKE_TEST_SOL_PATH)

LIBRARY_INHERITED2_SOL_JSON_OUTPUT = load_fixture(
    'library_inherited2_sol_json_output.json')
LIBRARY_INHERITED2_SOL_CLI_OUTPUT = load_fixture(
    'library_inherited2_sol_cli_output.txt')

UNKNOWN_PRAGMA_SOL_JSON_OUTPUT = load_fixture(
    'unknown_pragma_sol_json_output.json')
UNKNOWN_PRAGMA_SOL_CLI_OUTPUT = load_fixture(
    'unknown_pragma_sol_cli_output.txt')
from unittest_helpers import LIBSOLIDITY_TEST_DIR, load_fixture, load_libsolidity_test_case

# 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 FileReport, ContractReport
from bytecodecompare.prepare_report import load_source, parse_standard_json_output, prepare_compiler_input
# pragma pylint: enable=import-error

SMT_SMOKE_TEST_SOL_PATH = LIBSOLIDITY_TEST_DIR / 'smtCheckerTests/simple/smoke_test.sol'
SMT_SMOKE_TEST_SOL_CODE = load_libsolidity_test_case(SMT_SMOKE_TEST_SOL_PATH)

SYNTAX_SMOKE_TEST_SOL_PATH = LIBSOLIDITY_TEST_DIR / 'syntaxTests/smoke_test.sol'
SYNTAX_SMOKE_TEST_SOL_CODE = load_libsolidity_test_case(
    SYNTAX_SMOKE_TEST_SOL_PATH)

LIBRARY_INHERITED2_SOL_JSON_OUTPUT = load_fixture(
    'library_inherited2_sol_json_output.json')

UNKNOWN_PRAGMA_SOL_JSON_OUTPUT = load_fixture(
    'unknown_pragma_sol_json_output.json')


class TestPrepareReport_FileReport(unittest.TestCase):
    def test_format_report(self):
        report = FileReport(
            file_name=Path('syntaxTests/scoping/library_inherited2.sol'),
            contract_reports=[
                ContractReport(
                    contract_name='A',
                    file_name=Path('syntaxTests/smoke_test.sol'),
                    bytecode=None,
                    metadata=None,