2019-02-06 11:10:05 +00:00
|
|
|
/*
|
|
|
|
This file is part of solidity.
|
|
|
|
solidity is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
solidity is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <test/libsolidity/util/TestFileParser.h>
|
2019-02-21 00:50:41 +00:00
|
|
|
#include <test/libsolidity/util/TestFunctionCall.h>
|
2019-02-06 11:10:05 +00:00
|
|
|
#include <test/libsolidity/SolidityExecutionFramework.h>
|
|
|
|
#include <test/libsolidity/AnalysisFramework.h>
|
|
|
|
#include <test/TestCase.h>
|
|
|
|
#include <liblangutil/Exceptions.h>
|
2020-01-06 10:52:23 +00:00
|
|
|
#include <libsolutil/AnsiColorized.h>
|
2019-02-06 11:10:05 +00:00
|
|
|
|
|
|
|
#include <iosfwd>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <utility>
|
|
|
|
|
2019-12-23 15:50:30 +00:00
|
|
|
namespace solidity::frontend::test
|
2019-02-06 11:10:05 +00:00
|
|
|
{
|
|
|
|
|
2021-04-29 23:09:36 +00:00
|
|
|
struct AnnotatedEventSignature
|
|
|
|
{
|
|
|
|
std::string signature;
|
|
|
|
std::vector<std::string> indexedTypes;
|
|
|
|
std::vector<std::string> nonIndexedTypes;
|
|
|
|
};
|
|
|
|
|
2019-02-06 11:10:05 +00:00
|
|
|
/**
|
|
|
|
* Class that represents a semantic test (or end-to-end test) and allows running it as part of the
|
|
|
|
* boost unit test environment or isoltest. It reads the Solidity source and an additional comment
|
|
|
|
* section from the given file. This comment section should define a set of functions to be called
|
|
|
|
* and an expected result they return after being executed.
|
|
|
|
*/
|
2019-04-01 13:31:48 +00:00
|
|
|
class SemanticTest: public SolidityExecutionFramework, public EVMVersionRestrictedTestCase
|
2019-02-06 11:10:05 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
static std::unique_ptr<TestCase> create(Config const& _options)
|
2021-01-29 13:07:22 +00:00
|
|
|
{
|
|
|
|
return std::make_unique<SemanticTest>(
|
|
|
|
_options.filename,
|
|
|
|
_options.evmVersion,
|
|
|
|
_options.vmPaths,
|
2020-11-19 21:32:35 +00:00
|
|
|
_options.enforceCompileToEwasm,
|
2021-01-29 13:07:22 +00:00
|
|
|
_options.enforceGasCost,
|
|
|
|
_options.enforceGasCostMinValue
|
|
|
|
);
|
|
|
|
}
|
2019-02-06 11:10:05 +00:00
|
|
|
|
2021-01-29 09:55:34 +00:00
|
|
|
explicit SemanticTest(
|
|
|
|
std::string const& _filename,
|
|
|
|
langutil::EVMVersion _evmVersion,
|
|
|
|
std::vector<boost::filesystem::path> const& _vmPaths,
|
2020-11-19 21:32:35 +00:00
|
|
|
bool _enforceCompileToEwasm = false,
|
2021-01-29 13:07:22 +00:00
|
|
|
bool _enforceGasCost = false,
|
|
|
|
u256 _enforceGasCostMinValue = 100000
|
2021-01-29 09:55:34 +00:00
|
|
|
);
|
2019-02-06 11:10:05 +00:00
|
|
|
|
2019-05-07 13:33:22 +00:00
|
|
|
TestResult run(std::ostream& _stream, std::string const& _linePrefix = "", bool _formatted = false) override;
|
2019-03-18 13:08:56 +00:00
|
|
|
void printSource(std::ostream &_stream, std::string const& _linePrefix = "", bool _formatted = false) const override;
|
2019-02-06 11:10:05 +00:00
|
|
|
void printUpdatedExpectations(std::ostream& _stream, std::string const& _linePrefix = "") const override;
|
2020-04-17 20:24:33 +00:00
|
|
|
void printUpdatedSettings(std::ostream& _stream, std::string const& _linePrefix = "") override;
|
2019-02-06 11:10:05 +00:00
|
|
|
|
|
|
|
/// Instantiates a test file parser that parses the additional comment section at the end of
|
|
|
|
/// the input stream \param _stream. Each function call is represented using a `FunctionCallTest`
|
|
|
|
/// and added to the list of call to be executed when `run()` is called.
|
|
|
|
/// Throws if parsing expectations failed.
|
|
|
|
void parseExpectations(std::istream& _stream);
|
|
|
|
|
|
|
|
/// Compiles and deploys currently held source.
|
|
|
|
/// Returns true if deployment was successful, false otherwise.
|
2019-12-23 15:50:30 +00:00
|
|
|
bool deploy(std::string const& _contractName, u256 const& _value, bytes const& _arguments, std::map<std::string, solidity::test::Address> const& _libraries = {});
|
2021-01-08 03:45:19 +00:00
|
|
|
|
2019-02-21 00:50:41 +00:00
|
|
|
private:
|
2020-11-19 21:32:35 +00:00
|
|
|
TestResult runTest(std::ostream& _stream, std::string const& _linePrefix, bool _formatted, bool _isYulRun, bool _isEwasmRun);
|
2021-03-09 20:26:36 +00:00
|
|
|
bool checkGasCostExpectation(TestFunctionCall& io_test, bool _compileViaYul) const;
|
2021-05-20 23:11:29 +00:00
|
|
|
std::map<std::string, Builtin> makeBuiltins();
|
2021-04-28 21:35:59 +00:00
|
|
|
std::vector<SideEffectHook> makeSideEffectHooks() const;
|
2021-04-29 23:09:36 +00:00
|
|
|
std::vector<std::string> eventSideEffectHook(FunctionCall const&) const;
|
|
|
|
std::optional<AnnotatedEventSignature> matchEvent(util::h256 const& hash) const;
|
|
|
|
static std::string formatEventParameter(std::optional<AnnotatedEventSignature> _signature, bool _indexed, size_t _index, bytes const& _data);
|
2020-06-18 10:31:55 +00:00
|
|
|
SourceMap m_sources;
|
2019-07-13 10:04:22 +00:00
|
|
|
std::size_t m_lineOffset;
|
2019-02-21 00:50:41 +00:00
|
|
|
std::vector<TestFunctionCall> m_tests;
|
2021-05-01 03:13:08 +00:00
|
|
|
std::map<std::string, Builtin> const m_builtins;
|
2021-04-28 21:35:59 +00:00
|
|
|
std::vector<SideEffectHook> const m_sideEffectHooks;
|
2022-05-13 16:41:55 +00:00
|
|
|
bool m_testCaseWantsYulRun = true;
|
2020-11-19 21:32:35 +00:00
|
|
|
bool m_testCaseWantsEwasmRun = false;
|
|
|
|
bool m_testCaseWantsLegacyRun = true;
|
|
|
|
bool m_enforceCompileToEwasm = false;
|
2020-02-04 15:01:30 +00:00
|
|
|
bool m_runWithABIEncoderV1Only = false;
|
2020-03-06 00:22:51 +00:00
|
|
|
bool m_allowNonExistingFunctions = false;
|
2020-11-19 21:32:35 +00:00
|
|
|
bool m_canEnableYulRun = false;
|
|
|
|
bool m_canEnableEwasmRun = false;
|
2021-03-09 20:26:36 +00:00
|
|
|
bool m_gasCostFailure = false;
|
2021-01-29 13:07:22 +00:00
|
|
|
bool m_enforceGasCost = false;
|
|
|
|
u256 m_enforceGasCostMinValue;
|
2019-02-06 11:10:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|