Skip to content

Commit e7a3814

Browse files
committed
Unit test.
1 parent e0c837b commit e7a3814

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

test/libsolidity/SolidityEndToEndTest.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,34 @@ struct SolidityEndToEndTestExecutionFramework: public SolidityExecutionFramework
8484

8585
BOOST_FIXTURE_TEST_SUITE(SolidityEndToEndTest, SolidityEndToEndTestExecutionFramework)
8686

87+
BOOST_AUTO_TEST_CASE(creation_code_optimizer)
88+
{
89+
string codeC = R"(
90+
contract C {
91+
constructor(uint x) {
92+
if (x == 0xFFFFFFFFFFFFFFFF42)
93+
revert();
94+
}
95+
}
96+
)";
97+
string codeD = R"(
98+
contract D {
99+
function f() public pure returns (bytes memory) {
100+
return type(C).creationCode;
101+
}
102+
}
103+
)";
104+
105+
m_metadataHash = CompilerStack::MetadataHash::None;
106+
ALSO_VIA_YUL({
107+
bytes bytecodeC = compileContract(codeC);
108+
reset();
109+
compileAndRun(codeC + codeD);
110+
ABI_CHECK(callContractFunction("f()"), encodeArgs(0x20, bytecodeC.size()) + encode(bytecodeC, false));
111+
m_doEwasmTestrun = false;
112+
})
113+
}
114+
87115
unsigned constexpr roundTo32(unsigned _num)
88116
{
89117
return (_num + 31) / 32 * 32;

test/libsolidity/SolidityExecutionFramework.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ bytes SolidityExecutionFramework::multiSourceCompileContract(
6262
m_compiler.enableEvmBytecodeGeneration(!m_compileViaYul);
6363
m_compiler.enableIRGeneration(m_compileViaYul);
6464
m_compiler.setRevertStringBehaviour(m_revertStrings);
65+
m_compiler.setMetadataHash(m_metadataHash);
6566
if (!m_compiler.compile())
6667
{
6768
// The testing framework expects an exception for

test/libsolidity/SolidityExecutionFramework.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,12 @@ class SolidityExecutionFramework: public solidity::test::ExecutionFramework
7575
/// the latter only if it is forced.
7676
static std::string addPreamble(std::string const& _sourceCode);
7777
protected:
78-
79-
solidity::frontend::CompilerStack m_compiler;
78+
using CompilerStack = solidity::frontend::CompilerStack;
79+
CompilerStack m_compiler;
8080
bool m_compileViaYul = false;
8181
bool m_compileToEwasm = false;
8282
bool m_showMetadata = false;
83+
CompilerStack::MetadataHash m_metadataHash = CompilerStack::MetadataHash::IPFS;
8384
RevertStrings m_revertStrings = RevertStrings::Default;
8485
};
8586

0 commit comments

Comments
 (0)