mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Changing enforceGasCost functionality.
This commit is contained in:
parent
2b14efbbcc
commit
06171a3100
@ -103,8 +103,8 @@ CommonOptions::CommonOptions(std::string _caption):
|
||||
("no-smt", po::bool_switch(&disableSMT), "disable SMT checker")
|
||||
("optimize", po::bool_switch(&optimize), "enables optimization")
|
||||
("enforce-via-yul", po::bool_switch(&enforceViaYul), "Enforce compiling all tests via yul to see if additional tests can be activated.")
|
||||
("enforce-gas-cost", po::bool_switch(&enforceGasTest), "Enforce gas cost expectations in semantic tests.")
|
||||
("enforce-gas-cost-min-value", po::value(&enforceGasTestMinValue), "Threshold value when enforcing gas cost expectations.")
|
||||
("enforce-gas-cost", po::bool_switch(&enforceGasTest), "Enforce checking gas cost in semantic tests.")
|
||||
("enforce-gas-cost-min-value", po::value(&enforceGasTestMinValue), "Threshold value to enforce adding gas checks to a test.")
|
||||
("abiencoderv1", po::bool_switch(&useABIEncoderV1), "enables abi encoder v1")
|
||||
("show-messages", po::bool_switch(&showMessages), "enables message output")
|
||||
("show-metadata", po::bool_switch(&showMetadata), "enables metadata output");
|
||||
@ -122,12 +122,19 @@ void CommonOptions::validate() const
|
||||
ConfigException,
|
||||
"Invalid test path specified."
|
||||
);
|
||||
assertThrow(
|
||||
!enforceGasTest || evmVersion() == langutil::EVMVersion{},
|
||||
ConfigException,
|
||||
"Gas costs can only be enforced on latest evm version."
|
||||
);
|
||||
|
||||
if (enforceGasTest)
|
||||
{
|
||||
assertThrow(
|
||||
evmVersion() == langutil::EVMVersion{},
|
||||
ConfigException,
|
||||
"Gas costs can only be enforced on latest evm version."
|
||||
);
|
||||
assertThrow(
|
||||
useABIEncoderV1 == false,
|
||||
ConfigException,
|
||||
"Gas costs can only be enforced on abi encoder v2."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
bool CommonOptions::parse(int argc, char const* const* argv)
|
||||
|
@ -76,8 +76,8 @@ int registerTests(
|
||||
solidity::test::CommonOptions::get().evmVersion(),
|
||||
solidity::test::CommonOptions::get().vmPaths,
|
||||
_enforceViaYul,
|
||||
/* enforceGasCost */ false,
|
||||
0
|
||||
solidity::test::CommonOptions::get().enforceGasTest,
|
||||
solidity::test::CommonOptions::get().enforceGasTestMinValue
|
||||
};
|
||||
if (fs::is_directory(fullpath))
|
||||
{
|
||||
|
@ -115,9 +115,9 @@ SemanticTest::SemanticTest(
|
||||
parseExpectations(m_reader.stream());
|
||||
soltestAssert(!m_tests.empty(), "No tests specified in " + _filename);
|
||||
|
||||
if (_evmVersion == EVMVersion{})
|
||||
if (m_enforceGasCost)
|
||||
{
|
||||
m_compiler.setVersionType(CompilerStack::VersionType::Empty);
|
||||
m_compiler.setMetadataFormat(CompilerStack::MetadataFormat::NoMetadata);
|
||||
m_compiler.setMetadataHash(CompilerStack::MetadataHash::None);
|
||||
}
|
||||
}
|
||||
@ -342,20 +342,21 @@ bool SemanticTest::checkGasCostExpectation(TestFunctionCall& io_test, bool _comp
|
||||
(_compileViaYul ? "ir"s : "legacy"s) +
|
||||
(m_optimiserSettings == OptimiserSettings::full() ? "Optimized" : "");
|
||||
|
||||
// We don't check gas if evm is not set to default version
|
||||
// or in case we run abiencoderv1
|
||||
// We don't check gas if enforce gas cost is not active
|
||||
// or test is run with abi encoder v1 only
|
||||
// or gas used less than threshold for enforcing feature
|
||||
// or setting is "ir" and it's not included in expectations
|
||||
if (
|
||||
m_evmVersion != EVMVersion{} ||
|
||||
solidity::test::CommonOptions::get().useABIEncoderV1 ||
|
||||
!m_enforceGasCost ||
|
||||
(
|
||||
(!m_enforceGasCost || setting == "ir" || m_gasUsed < m_enforceGasCostMinValue) &&
|
||||
(setting == "ir" || m_gasUsed < m_enforceGasCostMinValue) &&
|
||||
io_test.call().expectations.gasUsed.count(setting) == 0
|
||||
)
|
||||
)
|
||||
return true;
|
||||
|
||||
solAssert(!m_runWithABIEncoderV1Only, "");
|
||||
|
||||
io_test.setGasCost(setting, m_gasUsed);
|
||||
return
|
||||
io_test.call().expectations.gasUsed.count(setting) > 0 &&
|
||||
|
Loading…
Reference in New Issue
Block a user