1313*/
1414
1515#include < test/libsolidity/SemanticTest.h>
16+
1617#include < libsolutil/Whiskers.h>
1718#include < libyul/Exceptions.h>
1819#include < test/Common.h>
20+ #include < test/libsolidity/util/BytesUtils.h>
21+
1922#include < boost/algorithm/string.hpp>
2023#include < boost/algorithm/string/predicate.hpp>
2124#include < boost/algorithm/string/trim.hpp>
2528#include < cctype>
2629#include < fstream>
2730#include < memory>
31+ #include < optional>
2832#include < stdexcept>
33+ #include < utility>
2934
3035using namespace std ;
3136using namespace solidity ;
@@ -119,7 +124,13 @@ TestCase::TestResult SemanticTest::run(ostream& _stream, string const& _linePref
119124 return result;
120125}
121126
122- TestCase::TestResult SemanticTest::runTest (ostream& _stream, string const & _linePrefix, bool _formatted, bool _compileViaYul, bool _compileToEwasm)
127+ TestCase::TestResult SemanticTest::runTest (
128+ ostream& _stream,
129+ string const & _linePrefix,
130+ bool _formatted,
131+ bool _compileViaYul,
132+ bool _compileToEwasm
133+ )
123134{
124135 bool success = true ;
125136
@@ -142,21 +153,25 @@ TestCase::TestResult SemanticTest::runTest(ostream& _stream, string const& _line
142153 if (_compileViaYul)
143154 AnsiColorized (_stream, _formatted, {BOLD, CYAN}) << _linePrefix << " Running via Yul:" << endl;
144155
145- for (auto & test: m_tests)
156+ for (TestFunctionCall & test: m_tests)
146157 test.reset ();
147158
148159 map<string, solidity::test::Address> libraries;
149160
150161 bool constructed = false ;
151162
152- for (auto & test: m_tests)
163+ for (TestFunctionCall & test: m_tests)
153164 {
154165 if (constructed)
155166 {
156- soltestAssert (test.call ().kind != FunctionCall::Kind::Library, " Libraries have to be deployed before any other call." );
167+ soltestAssert (
168+ test.call ().kind != FunctionCall::Kind::Library,
169+ " Libraries have to be deployed before any other call."
170+ );
157171 soltestAssert (
158172 test.call ().kind != FunctionCall::Kind::Constructor,
159- " Constructor has to be the first function call expect for library deployments." );
173+ " Constructor has to be the first function call expect for library deployments."
174+ );
160175 }
161176 else if (test.call ().kind == FunctionCall::Kind::Library)
162177 {
@@ -197,6 +212,17 @@ TestCase::TestResult SemanticTest::runTest(ostream& _stream, string const& _line
197212 bytes output;
198213 if (test.call ().kind == FunctionCall::Kind::LowLevel)
199214 output = callLowLevel (test.call ().arguments .rawBytes (), test.call ().value .value );
215+ else if (test.call ().kind == FunctionCall::Kind::Builtin)
216+ {
217+ std::optional<bytes> builtinOutput = m_builtins.at (test.call ().signature )(test.call ());
218+ if (builtinOutput.has_value ())
219+ {
220+ m_transactionSuccessful = true ;
221+ output = builtinOutput.value ();
222+ }
223+ else
224+ m_transactionSuccessful = false ;
225+ }
200226 else
201227 {
202228 soltestAssert (
@@ -241,15 +267,15 @@ TestCase::TestResult SemanticTest::runTest(ostream& _stream, string const& _line
241267 if (!success && (m_runWithYul || !_compileViaYul))
242268 {
243269 AnsiColorized (_stream, _formatted, {BOLD, CYAN}) << _linePrefix << " Expected result:" << endl;
244- for (auto const & test: m_tests)
270+ for (TestFunctionCall const & test: m_tests)
245271 {
246272 ErrorReporter errorReporter;
247273 _stream << test.format (errorReporter, _linePrefix, false , _formatted) << endl;
248274 _stream << errorReporter.format (_linePrefix, _formatted);
249275 }
250276 _stream << endl;
251277 AnsiColorized (_stream, _formatted, {BOLD, CYAN}) << _linePrefix << " Obtained result:" << endl;
252- for (auto const & test: m_tests)
278+ for (TestFunctionCall const & test: m_tests)
253279 {
254280 ErrorReporter errorReporter;
255281 _stream << test.format (errorReporter, _linePrefix, true , _formatted) << endl;
@@ -320,7 +346,7 @@ void SemanticTest::printSource(ostream& _stream, string const& _linePrefix, bool
320346
321347void SemanticTest::printUpdatedExpectations (ostream& _stream, string const &) const
322348{
323- for (auto const & test: m_tests)
349+ for (TestFunctionCall const & test: m_tests)
324350 _stream << test.format (" " , true , false ) << endl;
325351}
326352
@@ -340,12 +366,16 @@ void SemanticTest::printUpdatedSettings(ostream& _stream, string const& _linePre
340366
341367void SemanticTest::parseExpectations (istream& _stream)
342368{
343- TestFileParser parser{_stream};
344- auto functionCalls = parser.parseFunctionCalls (m_lineOffset);
345- std::move (functionCalls.begin (), functionCalls.end (), back_inserter (m_tests));
369+ TestFileParser parser{_stream, m_builtins};
370+ m_tests += parser.parseFunctionCalls (m_lineOffset);
346371}
347372
348- bool SemanticTest::deploy (string const & _contractName, u256 const & _value, bytes const & _arguments, map<string, solidity::test::Address> const & _libraries)
373+ bool SemanticTest::deploy (
374+ string const & _contractName,
375+ u256 const & _value,
376+ bytes const & _arguments,
377+ map<string, solidity::test::Address> const & _libraries
378+ )
349379{
350380 auto output = compileAndRunWithoutCheck (m_sources.sources , _value, _contractName, _arguments, _libraries);
351381 return !output.empty () && m_transactionSuccessful;
0 commit comments