diff --git a/test/libsolidity/SolidityOptimizer.cpp b/test/libsolidity/SolidityOptimizer.cpp index b5ce6f2af..9c6f8f65e 100644 --- a/test/libsolidity/SolidityOptimizer.cpp +++ b/test/libsolidity/SolidityOptimizer.cpp @@ -630,6 +630,43 @@ BOOST_AUTO_TEST_CASE(optimise_multi_stores) BOOST_CHECK_EQUAL(numInstructions(m_optimizedBytecode, Instruction::SSTORE), 8); } +BOOST_AUTO_TEST_CASE(optimise_constant_to_codecopy) +{ + char const* sourceCode = R"( + contract C { + // We use the state variable so that the functions won't be deemed identical + // and be optimised out to the same implementation. + uint a; + function f() public returns (uint) { + a = 1; + // This cannot be represented well with the `CalculateMethod`, + // hence the decision will be between `LiteralMethod` and `CopyMethod`. + return 0x1234123412431234123412412342112341234124312341234124; + } + function g() public returns (uint) { + a = 2; + return 0x1234123412431234123412412342112341234124312341234124; + } + function h() public returns (uint) { + a = 3; + return 0x1234123412431234123412412342112341234124312341234124; + } + function i() public returns (uint) { + a = 4; + return 0x1234123412431234123412412342112341234124312341234124; + } + } + )"; + compileBothVersions(sourceCode, 0, "C", 50); + compareVersions("f()"); + compareVersions("g()"); + compareVersions("h()"); + compareVersions("i()"); + // This is counting in the deployed code. + BOOST_CHECK_EQUAL(numInstructions(m_nonOptimizedBytecode, Instruction::CODECOPY), 0); + BOOST_CHECK_EQUAL(numInstructions(m_optimizedBytecode, Instruction::CODECOPY), 4); +} + BOOST_AUTO_TEST_SUITE_END() }