Browse Source

Working template magic for void function.

cl-refactor
Christian 10 years ago
parent
commit
4664544894
  1. 41
      test/solidityEndToEndTest.cpp

41
test/solidityEndToEndTest.cpp

@ -65,9 +65,10 @@ public:
template <class CppFunction, class... Args> template <class CppFunction, class... Args>
void testSolidityAgainstCpp(byte _index, CppFunction const& _cppFunction, Args const&... _arguments) void testSolidityAgainstCpp(byte _index, CppFunction const& _cppFunction, Args const&... _arguments)
{ {
pair<bytes, bytes> result = callImplementations(_index, _cppFunction, _arguments...); bytes solidityResult = callContractFunction(_index, _arguments...);
BOOST_CHECK_MESSAGE(result.first == result.second, "Computed values do not match." bytes cppResult = callCppAndEncodeResult(_cppFunction, _arguments...);
"\nSolidity: " + toHex(result.first) + "\nC++: " + toHex(result.second)); BOOST_CHECK_MESSAGE(solidityResult == cppResult, "Computed values do not match."
"\nSolidity: " + toHex(solidityResult) + "\nC++: " + toHex(cppResult));
} }
template <class CppFunction, class... Args> template <class CppFunction, class... Args>
@ -76,27 +77,15 @@ public:
{ {
for (u256 argument = _rangeStart; argument < _rangeEnd; ++argument) for (u256 argument = _rangeStart; argument < _rangeEnd; ++argument)
{ {
pair<bytes, bytes> result = callImplementations(_index, _cppFunction, argument); bytes solidityResult = callContractFunction(_index, argument);
BOOST_CHECK_MESSAGE(result.first == result.second, "Computed values do not match." bytes cppResult = callCppAndEncodeResult(_cppFunction, argument);
"\nSolidity: " + toHex(result.first) + "\nC++: " + toHex(result.second) + BOOST_CHECK_MESSAGE(solidityResult == cppResult, "Computed values do not match."
"\nSolidity: " + toHex(solidityResult) + "\nC++: " + toHex(cppResult) +
"\nArgument: " + toHex(toBigEndian(argument))); "\nArgument: " + toHex(toBigEndian(argument)));
} }
} }
private: private:
template <class CppFunction, class... Args>
pair<bytes, bytes> callImplementations(byte _solidityIndex, CppFunction const& _cppFunction,
Args const&... _arguments)
{
bytes solidityResult = callContractFunction(_solidityIndex, _arguments...);
bytes cppResult;
if (is_void<decltype(_cppFunction(_arguments...))>::value)
_cppFunction(_arguments...);
else
cppResult = toBigEndian(_cppFunction(_arguments...));
return make_pair(solidityResult, cppResult);
}
template <class FirstArg, class... Args> template <class FirstArg, class... Args>
bytes argsToBigEndian(FirstArg const& _firstArg, Args const&... _followingArgs) const bytes argsToBigEndian(FirstArg const& _firstArg, Args const&... _followingArgs) const
{ {
@ -105,6 +94,20 @@ private:
bytes argsToBigEndian() const { return bytes(); } bytes argsToBigEndian() const { return bytes(); }
template <class CppFunction, class... Args>
auto callCppAndEncodeResult(CppFunction const& _cppFunction, Args const&... _arguments)
-> typename enable_if<is_void<decltype(_cppFunction(_arguments...))>::value, bytes>::type
{
_cppFunction(_arguments...);
return bytes();
}
template <class CppFunction, class... Args>
auto callCppAndEncodeResult(CppFunction const& _cppFunction, Args const&... _arguments)
-> typename enable_if<!is_void<decltype(_cppFunction(_arguments...))>::value, bytes>::type
{
return toBigEndian(_cppFunction(_arguments...));
}
void sendMessage(bytes const& _data, bool _isCreation) void sendMessage(bytes const& _data, bool _isCreation)
{ {
eth::Executive executive(m_state); eth::Executive executive(m_state);

Loading…
Cancel
Save