diff --git a/test/ExecutionFramework.cpp b/test/ExecutionFramework.cpp index 1f5bece90..b2a549d88 100644 --- a/test/ExecutionFramework.cpp +++ b/test/ExecutionFramework.cpp @@ -233,7 +233,7 @@ h160 ExecutionFramework::account(size_t _idx) return h160(h256(u256{"0x1212121212121212121212121212120000000012"} + _idx * 0x1000), h160::AlignRight); } -bool ExecutionFramework::addressHasCode(h160 const& _addr) +bool ExecutionFramework::addressHasCode(h160 const& _addr) const { return m_evmcHost->get_code_size(EVMHost::convertToEVMC(_addr)) != 0; } @@ -266,12 +266,12 @@ bytes ExecutionFramework::logData(size_t _logIdx) const return {data.begin(), data.end()}; } -u256 ExecutionFramework::balanceAt(h160 const& _addr) +u256 ExecutionFramework::balanceAt(h160 const& _addr) const { return u256(EVMHost::convertFromEVMC(m_evmcHost->get_balance(EVMHost::convertToEVMC(_addr)))); } -bool ExecutionFramework::storageEmpty(h160 const& _addr) +bool ExecutionFramework::storageEmpty(h160 const& _addr) const { const auto it = m_evmcHost->accounts.find(EVMHost::convertToEVMC(_addr)); if (it != m_evmcHost->accounts.end()) diff --git a/test/ExecutionFramework.h b/test/ExecutionFramework.h index c1d82856a..602ba2337 100644 --- a/test/ExecutionFramework.h +++ b/test/ExecutionFramework.h @@ -268,9 +268,9 @@ protected: /// @returns the (potentially newly created) _ith address. util::h160 account(size_t _i); - u256 balanceAt(util::h160 const& _addr); - bool storageEmpty(util::h160 const& _addr); - bool addressHasCode(util::h160 const& _addr); + u256 balanceAt(util::h160 const& _addr) const; + bool storageEmpty(util::h160 const& _addr) const; + bool addressHasCode(util::h160 const& _addr) const; size_t numLogs() const; size_t numLogTopics(size_t _logIdx) const; diff --git a/test/libsolidity/SemanticTest.cpp b/test/libsolidity/SemanticTest.cpp index 004459277..b56e25703 100644 --- a/test/libsolidity/SemanticTest.cpp +++ b/test/libsolidity/SemanticTest.cpp @@ -40,12 +40,10 @@ using namespace solidity::langutil; using namespace solidity::util; using namespace solidity::util::formatting; using namespace solidity::frontend::test; -using namespace boost; using namespace boost::algorithm; using namespace boost::unit_test; namespace fs = boost::filesystem; - SemanticTest::SemanticTest( string const& _filename, langutil::EVMVersion _evmVersion, @@ -59,13 +57,12 @@ SemanticTest::SemanticTest( EVMVersionRestrictedTestCase(_filename), m_sources(m_reader.sources()), m_lineOffset(m_reader.lineNumber()), + m_builtins(makeBuiltins()), m_enforceViaYul(_enforceViaYul), m_enforceCompileToEwasm(_enforceCompileToEwasm), m_enforceGasCost(_enforceGasCost), - m_enforceGasCostMinValue(std::move(_enforceGasCostMinValue)) + m_enforceGasCostMinValue(move(_enforceGasCostMinValue)) { - initializeBuiltins(); - static set const compileViaYulAllowedValues{"also", "true", "false", "default"}; static set const yulRunTriggers{"also", "true"}; static set const legacyRunTriggers{"also", "false", "default"}; @@ -118,29 +115,37 @@ SemanticTest::SemanticTest( } } -void SemanticTest::initializeBuiltins() +map SemanticTest::makeBuiltins() const { - solAssert(m_builtins.count("smokeTest") == 0, ""); - m_builtins["smokeTest"] = [](FunctionCall const&) -> std::optional - { - return util::toBigEndian(u256(0x1234)); - }; - soltestAssert(m_builtins.count("balance") == 0, ""); - m_builtins["balance"] = [this](FunctionCall const& _call) -> std::optional - { - soltestAssert(_call.arguments.parameters.size() <= 1, "Account address expected."); - h160 address; - if (_call.arguments.parameters.size() == 1) - address = h160(_call.arguments.parameters.at(0).rawString); - else - address = m_contractAddress; - return util::toBigEndian(SolidityExecutionFramework::balanceAt(address)); - }; - soltestAssert(m_builtins.count("storageEmpty") == 0, ""); - m_builtins["storageEmpty"] = [this](FunctionCall const& _call) -> std::optional - { - soltestAssert(_call.arguments.parameters.empty(), "No arguments expected."); - return toBigEndian(u256(storageEmpty(m_contractAddress) ? 1 : 0)); + return { + { + "smokeTest", + [](FunctionCall const&) -> optional + { + return util::toBigEndian(u256(0x1234)); + } + }, + { + "balance", + [this](FunctionCall const& _call) -> optional + { + soltestAssert(_call.arguments.parameters.size() <= 1, "Account address expected."); + h160 address; + if (_call.arguments.parameters.size() == 1) + address = h160(_call.arguments.parameters.at(0).rawString); + else + address = m_contractAddress; + return util::toBigEndian(balanceAt(address)); + } + }, + { + "storageEmpty", + [this](FunctionCall const& _call) -> optional + { + soltestAssert(_call.arguments.parameters.empty(), "No arguments expected."); + return toBigEndian(u256(storageEmpty(m_contractAddress) ? 1 : 0)); + } + } }; } @@ -257,7 +262,7 @@ TestCase::TestResult SemanticTest::runTest( output = callLowLevel(test.call().arguments.rawBytes(), test.call().value.value); else if (test.call().kind == FunctionCall::Kind::Builtin) { - std::optional builtinOutput = m_builtins.at(test.call().signature)(test.call()); + optional builtinOutput = m_builtins.at(test.call().signature)(test.call()); if (builtinOutput.has_value()) { m_transactionSuccessful = true; @@ -296,7 +301,7 @@ TestCase::TestResult SemanticTest::runTest( success = false; test.setFailure(!m_transactionSuccessful); - test.setRawBytes(std::move(output)); + test.setRawBytes(move(output)); test.setContractABI(m_compiler.contractABI(m_compiler.lastContractName(m_sources.mainSourceFile))); } } diff --git a/test/libsolidity/SemanticTest.h b/test/libsolidity/SemanticTest.h index 873357f38..97623cb1c 100644 --- a/test/libsolidity/SemanticTest.h +++ b/test/libsolidity/SemanticTest.h @@ -80,10 +80,11 @@ public: private: TestResult runTest(std::ostream& _stream, std::string const& _linePrefix, bool _formatted, bool _isYulRun, bool _isEwasmRun); bool checkGasCostExpectation(TestFunctionCall& io_test, bool _compileViaYul) const; - void initializeBuiltins(); + std::map makeBuiltins() const; SourceMap m_sources; std::size_t m_lineOffset; std::vector m_tests; + std::map const m_builtins; bool m_testCaseWantsYulRun = false; bool m_testCaseWantsEwasmRun = false; bool m_testCaseWantsLegacyRun = true; @@ -93,8 +94,6 @@ private: bool m_allowNonExistingFunctions = false; bool m_canEnableYulRun = false; bool m_canEnableEwasmRun = false; - std::map m_builtins{}; - bool m_gasCostFailure = false; bool m_enforceGasCost = false; u256 m_enforceGasCostMinValue;