Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions test/libsolidity/SemanticTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,41 @@ SemanticTest::SemanticTest(
parseExpectations(m_reader.stream());
soltestAssert(!m_tests.empty(), "No tests specified in " + _filename);

// Validate that gas expectations only reference pipelines the test actually runs.
// E.g. a test with compileViaYul: true should not have gas legacy: expectations.
for (auto const& test: m_tests)
{
auto checkNoStaleGasKey = [&](std::string const& _key)
{
if (
test.call().expectations.gasUsedExcludingCode.count(_key) ||
test.call().expectations.gasUsedForCodeDeposit.count(_key)
)
BOOST_THROW_EXCEPTION(std::runtime_error(
"Test has gas expectation for \"" + _key + "\", "
"but the corresponding pipeline is not enabled "
"(compileViaYul: " + compileViaYul +
", compileViaSSACFG: " + (m_testCaseWantsSSACFGRun ? "true" : "false") + ")."
));
};

if (!m_testCaseWantsLegacyRun)
{
checkNoStaleGasKey("legacy");
checkNoStaleGasKey("legacyOptimized");
}
if (!m_testCaseWantsYulRun)
{
checkNoStaleGasKey("ir");
checkNoStaleGasKey("irOptimized");
}
if (!m_testCaseWantsSSACFGRun)
{
checkNoStaleGasKey("ssaCFG");
checkNoStaleGasKey("ssaCFGOptimized");
}
}

if (m_enforceGasCost)
{
m_compiler.setMetadataFormat(CompilerStack::MetadataFormat::NoMetadata);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,3 @@ contract C {
// gas irOptimized: 137891
// test2(uint8[][]): 0x20, 2, 0x40, 0x80, 1, 7, 2, 8, 9
// gas irOptimized: 164249
// gas legacyOptimized: 120228
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,3 @@ contract Test {
// compileViaYul: true
// ----
// test() -> 0x20
// gas legacy: 131966
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@ contract Test {
// compileViaYul: true
// ----
// test() -> 0x0500
// gas legacy: 131966
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,3 @@ contract Test {
// compileViaYul: true
// ----
// test() -> FAILURE
// gas legacy: 131966
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,4 @@ contract C {
// constructor() ->
// gas irOptimized: 73171
// gas irOptimized code: 291200
// gas legacy: 83499
// gas legacy code: 408800
// f() -> -1, 1