def test_prepare_compiler_input_for_json_preserves_newlines(self): expected_compiler_input = { 'language': 'Solidity', 'sources': { str(SMT_CONTRACT_WITH_MIXED_NEWLINES_SOL_PATH): { 'content': "pragma experimental SMTChecker;\n" "\n" "contract C {\r" "}\r\n" }, }, 'settings': { 'optimizer': {'enabled': True}, 'outputSelection': {'*': {'*': ['evm.bytecode.object', 'metadata']}}, 'modelChecker': {'engine': 'none'}, } } (command_line, compiler_input) = prepare_compiler_input( Path('solc'), SMT_CONTRACT_WITH_MIXED_NEWLINES_SOL_PATH, optimize=True, force_no_optimize_yul=False, interface=CompilerInterface.STANDARD_JSON, smt_use=SMTUse.DISABLE, metadata_option_supported=True, ) self.assertEqual(command_line, ['solc', '--standard-json']) self.assertEqual(json.loads(compiler_input), expected_compiler_input)
def test_prepare_compiler_input_should_work_with_standard_json_interface(self): expected_compiler_input = { 'language': 'Solidity', 'sources': { str(SMT_SMOKE_TEST_SOL_PATH): {'content': SMT_SMOKE_TEST_SOL_CODE}, }, 'settings': { 'optimizer': {'enabled': True}, 'outputSelection': {'*': {'*': ['evm.bytecode.object', 'metadata']}}, 'modelChecker': {'engine': 'none'}, } } (command_line, compiler_input) = prepare_compiler_input( Path('solc'), SMT_SMOKE_TEST_SOL_PATH, optimize=True, force_no_optimize_yul=False, interface=CompilerInterface.STANDARD_JSON, smt_use=SMTUse.DISABLE, metadata_option_supported=True, ) self.assertEqual(command_line, ['solc', '--standard-json']) self.assertEqual(json.loads(compiler_input), expected_compiler_input)
def test_prepare_compiler_input(self): expected_compiler_input = { 'language': 'Solidity', 'sources': { str(SMT_SMOKE_TEST_SOL_PATH): { 'content': SMT_SMOKE_TEST_SOL_CODE }, }, 'settings': { 'optimizer': { 'enabled': True }, 'outputSelection': { '*': { '*': ['evm.bytecode.object', 'metadata'] } }, 'modelChecker': { 'engine': 'none' }, } } (command_line, compiler_input) = prepare_compiler_input( Path('solc'), SMT_SMOKE_TEST_SOL_PATH, optimize=True, ) self.assertEqual(command_line, ['solc', '--standard-json']) self.assertEqual(json.loads(compiler_input), expected_compiler_input)
def test_prepare_compiler_input_for_cli_preserves_newlines(self): (_command_line, compiler_input) = prepare_compiler_input( Path('solc'), SMT_CONTRACT_WITH_MIXED_NEWLINES_SOL_PATH, optimize=True, interface=CompilerInterface.CLI, ) self.assertEqual(compiler_input, SMT_CONTRACT_WITH_MIXED_NEWLINES_SOL_CODE)
def test_prepare_compiler_input_for_cli_preserves_newlines(self): (_command_line, compiler_input) = prepare_compiler_input( Path('solc'), SMT_CONTRACT_WITH_MIXED_NEWLINES_SOL_PATH, optimize=True, force_no_optimize_yul=True, interface=CompilerInterface.CLI, smt_use=SMTUse.DISABLE, metadata_option_supported=True, ) self.assertEqual(compiler_input, SMT_CONTRACT_WITH_MIXED_NEWLINES_SOL_CODE)
def test_prepare_compiler_input_should_work_with_cli_interface(self): (command_line, compiler_input) = prepare_compiler_input( Path('solc'), SMT_SMOKE_TEST_SOL_PATH, optimize=True, interface=CompilerInterface.CLI, ) self.assertEqual(command_line, [ 'solc', str(SMT_SMOKE_TEST_SOL_PATH), '--bin', '--metadata', '--model-checker-engine', 'none', '--optimize' ]) self.assertEqual(compiler_input, SMT_SMOKE_TEST_SOL_CODE)
def test_prepare_compiler_input_for_cli_should_not_use_metadata_option_if_not_supported(self): (command_line, compiler_input) = prepare_compiler_input( Path('solc'), SMT_SMOKE_TEST_SOL_PATH, optimize=True, force_no_optimize_yul=False, interface=CompilerInterface.CLI, smt_use=SMTUse.PRESERVE, metadata_option_supported=False, ) self.assertEqual( command_line, ['solc', str(SMT_SMOKE_TEST_SOL_PATH), '--bin', '--optimize'], ) self.assertEqual(compiler_input, SMT_SMOKE_TEST_SOL_CODE)
def test_prepare_compiler_input_for_cli_should_handle_force_no_optimize_yul_flag(self): (command_line, compiler_input) = prepare_compiler_input( Path('solc'), SMT_SMOKE_TEST_SOL_PATH, optimize=False, force_no_optimize_yul=True, interface=CompilerInterface.CLI, smt_use=SMTUse.DISABLE, metadata_option_supported=True, ) self.assertEqual( command_line, ['solc', str(SMT_SMOKE_TEST_SOL_PATH), '--bin', '--metadata', '--no-optimize-yul', '--model-checker-engine', 'none'], ) self.assertEqual(compiler_input, SMT_SMOKE_TEST_SOL_CODE)