#pragma once
#include <test/libsolidity/util/TestFileParser.h>
#include <test/libsolidity/util/SoltestErrors.h>
#include <test/libsolidity/util/ContractABIUtils.h>
#include <liblangutil/Exceptions.h>
#include <libsolutil/AnsiColorized.h>
#include <libsolutil/CommonData.h>
#include <libsolutil/JSON.h>
#include <json/json.h>
#include <iosfwd>
#include <numeric>
#include <stdexcept>
#include <string>
#include <vector>
namespace solidity::frontend::test
{
class TestFunctionCall
{
public:
enum class RenderMode
{
ExpectedValuesExpectedGas,
ActualValuesExpectedGas,
ExpectedValuesActualGas
};
TestFunctionCall(FunctionCall _call): m_call(std::move(_call)), m_gasCosts(m_call.expectations.gasUsed) {}
std::string format(
ErrorReporter& _errorReporter,
std::string const& _linePrefix = "",
RenderMode _renderMode = RenderMode::ExpectedValuesExpectedGas,
bool const _highlight = false,
bool const _interactivePrint = false
) const;
std::string format(
std::string const& _linePrefix = "",
RenderMode const _renderMode = RenderMode::ExpectedValuesExpectedGas,
bool const _highlight = false
) const
{
ErrorReporter reporter;
return format(reporter, _linePrefix, _renderMode, _highlight);
}
void reset();
FunctionCall const& call() const { return m_call; }
void calledNonExistingFunction() { m_calledNonExistingFunction = true; }
void setFailure(const bool _failure) { m_failure = _failure; }
void setRawBytes(const bytes _rawBytes) { m_rawBytes = _rawBytes; }
void setGasCost(std::string const& _runType, u256 const& _gasCost) { m_gasCosts[_runType] = _gasCost; }
void setContractABI(Json::Value _contractABI) { m_contractABI = std::move(_contractABI); }
void setSideEffects(std::vector<std::string> _sideEffects) { m_call.actualSideEffects = _sideEffects; }
private:
std::string formatBytesParameters(
ErrorReporter& _errorReporter,
bytes const& _bytes,
std::string const& _signature,
ParameterList const& _params,
bool highlight = false,
bool failure = false
) const;
std::string formatFailure(
ErrorReporter& _errorReporter,
FunctionCall const& _call,
bytes const& _output,
bool _renderResult,
bool _highlight
) const;
std::string formatRawParameters(
ParameterList const& _params,
std::string const& _linePrefix = ""
) const;
std::string formatGasExpectations(
std::string const& _linePrefix,
bool _useActualCost,
bool _showDifference
) const;
bool matchesExpectation() const;
FunctionCall m_call;
bytes m_rawBytes = bytes{};
std::map<std::string, u256> m_gasCosts;
bool m_failure = true;
Json::Value m_contractABI = Json::Value{};
bool m_calledNonExistingFunction = false;
};
}