2019-07-03 19:37:55 +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/SoltestTypes.h>
|
|
|
|
|
2019-07-21 14:58:48 +00:00
|
|
|
#include <test/libsolidity/util/SoltestErrors.h>
|
|
|
|
|
2019-07-03 19:37:55 +00:00
|
|
|
#include <libdevcore/CommonData.h>
|
|
|
|
|
|
|
|
#include <json/json.h>
|
|
|
|
|
|
|
|
namespace dev
|
|
|
|
{
|
|
|
|
namespace solidity
|
|
|
|
{
|
|
|
|
namespace test
|
|
|
|
{
|
|
|
|
|
2019-07-21 14:58:48 +00:00
|
|
|
using ABITypes = std::vector<ABIType>;
|
|
|
|
|
2019-07-03 19:37:55 +00:00
|
|
|
/**
|
|
|
|
* Utility class that aids conversions from contract ABI types stored in a
|
|
|
|
* Json value to the internal ABIType representation of isoltest.
|
|
|
|
*/
|
|
|
|
class ContractABIUtils
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/// Parses and translates Solidity's ABI types as Json string into
|
|
|
|
/// a list of internal type representations of isoltest.
|
2019-07-21 14:58:48 +00:00
|
|
|
/// Creates parameters from Contract ABI and is used to generate values for
|
|
|
|
/// auto-correction during interactive update routine.
|
2019-10-28 10:39:30 +00:00
|
|
|
static std::optional<ParameterList> parametersFromJsonOutputs(
|
2019-07-21 14:58:48 +00:00
|
|
|
ErrorReporter& _errorReporter,
|
2019-07-03 19:37:55 +00:00
|
|
|
Json::Value const& _contractABI,
|
2019-07-21 14:58:48 +00:00
|
|
|
std::string const& _functionSignature
|
|
|
|
);
|
|
|
|
|
|
|
|
/// Overwrites _targetParameters if ABI types or sizes given
|
|
|
|
/// by _sourceParameters do not match.
|
|
|
|
static void overwriteParameters(
|
|
|
|
ErrorReporter& _errorReporter,
|
|
|
|
ParameterList& _targetParameters,
|
|
|
|
ParameterList const& _sourceParameters
|
|
|
|
);
|
|
|
|
|
|
|
|
/// If parameter count does not match, take types defined _sourceParameters
|
|
|
|
/// and create a warning if so.
|
|
|
|
static ParameterList preferredParameters(
|
|
|
|
ErrorReporter& _errorReporter,
|
|
|
|
ParameterList const& _targetParameters,
|
|
|
|
ParameterList const& _sourceParameters,
|
|
|
|
bytes const& _bytes
|
|
|
|
);
|
2019-07-03 19:37:55 +00:00
|
|
|
|
2019-08-14 19:05:26 +00:00
|
|
|
/// Returns a list of parameters corresponding to the encoding of
|
2019-08-19 12:54:31 +00:00
|
|
|
/// returned values in case of a failure. Creates an additional parameter
|
|
|
|
/// for the error message if _bytes is larger than 68 bytes
|
|
|
|
/// (function_selector + tail_ptr + message_length).
|
|
|
|
static ParameterList failureParameters(bytes const _bytes);
|
2019-08-14 19:05:26 +00:00
|
|
|
|
|
|
|
/// Returns _count parameters with their type set to ABIType::UnsignedDec
|
|
|
|
/// and their size set to 32 bytes.
|
|
|
|
static ParameterList defaultParameters(size_t count = 0);
|
|
|
|
|
|
|
|
/// Calculates the encoding size of given _parameters based
|
|
|
|
/// on the size of their types.
|
|
|
|
static size_t encodingSize(ParameterList const& _paremeters);
|
|
|
|
|
2019-07-03 19:37:55 +00:00
|
|
|
private:
|
|
|
|
/// Parses and translates a single type and returns a list of
|
|
|
|
/// internal type representations of isoltest.
|
|
|
|
/// Types defined by the ABI will translate to ABITypes
|
|
|
|
/// as follows:
|
|
|
|
/// `bool` -> [`Boolean`]
|
|
|
|
/// `uint` -> [`Unsigned`]
|
|
|
|
/// `string` -> [`Unsigned`, `Unsigned`, `String`]
|
|
|
|
/// `bytes` -> [`Unsigned`, `Unsigned`, `HexString`]
|
|
|
|
/// ...
|
2019-07-21 14:58:48 +00:00
|
|
|
static bool appendTypesFromName(
|
|
|
|
Json::Value const& _functionOutput,
|
|
|
|
ABITypes& _inplaceTypes,
|
|
|
|
ABITypes& _dynamicTypes,
|
|
|
|
bool _isCompoundType = false
|
|
|
|
);
|
2019-07-03 19:37:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|