1 /* 2 This file is part of solidity. 3 4 solidity is free software: you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation, either version 3 of the License, or 7 (at your option) any later version. 8 9 solidity is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License 15 along with solidity. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 /** 18 * Unit tests for the compiler itself. 19 */ 20 21 #include <test/libsolidity/AnalysisFramework.h> 22 #include <test/Metadata.h> 23 #include <test/Common.h> 24 25 #include <boost/test/unit_test.hpp> 26 27 using namespace std; 28 29 namespace solidity::frontend::test 30 { 31 BOOST_FIXTURE_TEST_SUITE(SolidityCompiler,AnalysisFramework)32BOOST_FIXTURE_TEST_SUITE(SolidityCompiler, AnalysisFramework) 33 34 BOOST_AUTO_TEST_CASE(does_not_include_creation_time_only_internal_functions) 35 { 36 char const* sourceCode = R"( 37 contract C { 38 uint x; 39 constructor() { f(); } 40 function f() internal { unchecked { for (uint i = 0; i < 10; ++i) x += 3 + i; } } 41 } 42 )"; 43 compiler().setOptimiserSettings(solidity::test::CommonOptions::get().optimize); 44 BOOST_REQUIRE(success(sourceCode)); 45 BOOST_REQUIRE_MESSAGE(compiler().compile(), "Compiling contract failed"); 46 bytes const& creationBytecode = solidity::test::bytecodeSansMetadata(compiler().object("C").bytecode); 47 bytes const& runtimeBytecode = solidity::test::bytecodeSansMetadata(compiler().runtimeObject("C").bytecode); 48 BOOST_CHECK(creationBytecode.size() >= 90); 49 BOOST_CHECK(creationBytecode.size() <= 120); 50 BOOST_CHECK(runtimeBytecode.size() >= 10); 51 BOOST_CHECK(runtimeBytecode.size() <= 30); 52 } 53 54 BOOST_AUTO_TEST_SUITE_END() 55 56 } 57