Implementing enforcing gas expectations in isoltest.

Co-authored-by: Daniel Kirchner <daniel@ekpyron.org>
This commit is contained in:
Djordje Mijovic
2021-03-09 21:26:45 +01:00
co-authored by Daniel Kirchner
parent 515f15f7a3
commit aed3832b27
8 changed files with 56 additions and 9 deletions
+16 -4
View File
@@ -49,13 +49,17 @@ SemanticTest::SemanticTest(
string const& _filename,
langutil::EVMVersion _evmVersion,
vector<boost::filesystem::path> const& _vmPaths,
bool enforceViaYul
bool _enforceViaYul,
bool _enforceGasCost,
u256 _enforceGasCostMinValue
):
SolidityExecutionFramework(_evmVersion, _vmPaths),
EVMVersionRestrictedTestCase(_filename),
m_sources(m_reader.sources()),
m_lineOffset(m_reader.lineNumber()),
m_enforceViaYul(enforceViaYul)
m_enforceViaYul(_enforceViaYul),
m_enforceGasCost(_enforceGasCost),
m_enforceGasCostMinValue(_enforceGasCostMinValue)
{
string choice = m_reader.stringSetting("compileViaYul", "default");
if (choice == "also")
@@ -326,15 +330,23 @@ TestCase::TestResult SemanticTest::runTest(
bool SemanticTest::checkGasCostExpectation(TestFunctionCall& io_test, bool _compileViaYul) const
{
if (m_evmVersion != EVMVersion{})
return true;
string setting =
(_compileViaYul ? "ir"s : "legacy"s) +
(m_optimiserSettings == OptimiserSettings::full() ? "Optimized" : "");
if (io_test.call().expectations.gasUsed.count(setting) == 0)
if (
(!m_enforceGasCost || m_gasUsed < m_enforceGasCostMinValue) &&
io_test.call().expectations.gasUsed.count(setting) == 0
)
return true;
io_test.setGasCost(setting, m_gasUsed);
return m_gasUsed == io_test.call().expectations.gasUsed.at(setting);
return
io_test.call().expectations.gasUsed.count(setting) > 0 &&
m_gasUsed == io_test.call().expectations.gasUsed.at(setting);
}
void SemanticTest::printSource(ostream& _stream, string const& _linePrefix, bool _formatted) const
+15 -2
View File
@@ -40,13 +40,24 @@ class SemanticTest: public SolidityExecutionFramework, public EVMVersionRestrict
{
public:
static std::unique_ptr<TestCase> create(Config const& _options)
{ return std::make_unique<SemanticTest>(_options.filename, _options.evmVersion, _options.vmPaths, _options.enforceCompileViaYul); }
{
return std::make_unique<SemanticTest>(
_options.filename,
_options.evmVersion,
_options.vmPaths,
_options.enforceCompileViaYul,
_options.enforceGasCost,
_options.enforceGasCostMinValue
);
}
explicit SemanticTest(
std::string const& _filename,
langutil::EVMVersion _evmVersion,
std::vector<boost::filesystem::path> const& _vmPaths,
bool _enforceViaYul = false
bool _enforceViaYul = false,
bool _enforceGasCost = false,
u256 _enforceGasCostMinValue = 100000
);
TestResult run(std::ostream& _stream, std::string const& _linePrefix = "", bool _formatted = false) override;
@@ -80,6 +91,8 @@ private:
std::map<std::string, Builtin> m_builtins{};
bool m_gasCostFailure = false;
bool m_enforceGasCost = false;
u256 m_enforceGasCostMinValue;
};
}