Skip to content

Commit

Permalink
Test coverage for existing parsing and formatting functionality of ga…
Browse files Browse the repository at this point in the history
…s expectations
  • Loading branch information
cameel committed Feb 21, 2024
1 parent f4105a9 commit a9a870d
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 12 deletions.
70 changes: 58 additions & 12 deletions test/libsolidity/util/TestFileParserTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,18 @@ std::vector<FunctionCall> parse(std::string const& _source, std::map<std::string
}

void testFunctionCall(
FunctionCall const& _call,
FunctionCall::DisplayMode _mode,
std::string _signature = "",
bool _failure = true,
bytes _arguments = bytes{},
bytes _expectations = bytes{},
FunctionValue _value = { 0 },
std::string _argumentComment = "",
std::string _expectationComment = "",
std::vector<std::string> _rawArguments = std::vector<std::string>{},
bool _isConstructor = false,
bool _isLibrary = false
FunctionCall const& _call,
FunctionCall::DisplayMode _mode,
std::string _signature = "",
bool _failure = true,
bytes _arguments = bytes{},
bytes _expectations = bytes{},
FunctionValue _value = { 0 },
std::string _argumentComment = "",
std::string _expectationComment = "",
std::vector<std::string> _rawArguments = std::vector<std::string>{},
bool _isConstructor = false,
bool _isLibrary = false
)
{
BOOST_REQUIRE_EQUAL(_call.expectations.failure, _failure);
Expand Down Expand Up @@ -1063,6 +1063,52 @@ BOOST_AUTO_TEST_CASE(call_effects)
BOOST_CHECK_THROW(parse(source, builtins), std::exception);
}

BOOST_AUTO_TEST_CASE(gas)
{
char const* source = R"(
// f() ->
// gas ir: 3245
// gas legacy: 5000
// gas legacyOptimized: 0
)";
auto const calls = parse(source);
BOOST_REQUIRE_EQUAL(calls.size(), 1);
BOOST_REQUIRE_EQUAL(calls[0].expectations.failure, false);
BOOST_TEST(calls[0].expectations.gasUsed == (std::map<std::string, u256>{
{"ir", 3245},
{"legacy", 5000},
{"legacyOptimized", 0},
}));
}

BOOST_AUTO_TEST_CASE(gas_before_call)
{
char const* source = R"(
// gas ir: 3245
// f() ->
)";
BOOST_REQUIRE_THROW(parse(source), TestParserError);
}

BOOST_AUTO_TEST_CASE(gas_invalid_run_type)
{
char const* source = R"(
// f() ->
// gas ir: 3245
// gas experimental: 5000
)";
BOOST_REQUIRE_THROW(parse(source), TestParserError);
}

BOOST_AUTO_TEST_CASE(gas_duplicate_run_type)
{
char const* source = R"(
// f() ->
// gas ir: 3245
// gas ir: 3245
)";
BOOST_REQUIRE_THROW(parse(source), TestParserError);
}
BOOST_AUTO_TEST_SUITE_END()

}
28 changes: 28 additions & 0 deletions test/libsolidity/util/TestFunctionCallTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,34 @@ BOOST_AUTO_TEST_CASE(format_failure_singleline)
BOOST_REQUIRE_EQUAL(test.format(), "// f(uint8): 1 -> FAILURE");
}

BOOST_AUTO_TEST_CASE(format_gas)
{
FunctionCall call{
"f()",
FunctionValue{0},
FunctionCallArgs{},
FunctionCallExpectations{
std::vector<Parameter>{},
false, // failure
"some comment",
{
{"ir", 3245},
{"legacy", 5000},
{"legacy optimized", 0},
},
}
};
call.omitsArrow = false;

BOOST_REQUIRE_EQUAL(
TestFunctionCall(call).format(),
"// f() -> #some comment#\n"
"// gas ir: 3245\n"
"// gas legacy: 5000\n"
"// gas legacy optimized: 0"
);
}

BOOST_AUTO_TEST_SUITE_END()

}

0 comments on commit a9a870d

Please sign in to comment.