aboutsummaryrefslogtreecommitdiffstats
path: root/solidityEndToEndTest.cpp
diff options
context:
space:
mode:
authorChristian <c@ethdev.com>2014-11-11 18:41:23 +0800
committerChristian <c@ethdev.com>2014-11-11 18:41:49 +0800
commit381bec82848ced1bf906f8f8c324f9ce13ba354b (patch)
treee6e13f57caf953556e53d866bf5fef5a428ac682 /solidityEndToEndTest.cpp
parentf0dd0d797e5cff8ba4e864ea8963266dd2ecd719 (diff)
downloaddexon-solidity-381bec82848ced1bf906f8f8c324f9ce13ba354b.tar.gz
dexon-solidity-381bec82848ced1bf906f8f8c324f9ce13ba354b.tar.zst
dexon-solidity-381bec82848ced1bf906f8f8c324f9ce13ba354b.zip
Working template magic for void function.
Diffstat (limited to 'solidityEndToEndTest.cpp')
-rw-r--r--solidityEndToEndTest.cpp41
1 files changed, 22 insertions, 19 deletions
diff --git a/solidityEndToEndTest.cpp b/solidityEndToEndTest.cpp
index 123d6798..85fd707c 100644
--- a/solidityEndToEndTest.cpp
+++ b/solidityEndToEndTest.cpp
@@ -65,9 +65,10 @@ public:
template <class CppFunction, class... Args>
void testSolidityAgainstCpp(byte _index, CppFunction const& _cppFunction, Args const&... _arguments)
{
- pair<bytes, bytes> result = callImplementations(_index, _cppFunction, _arguments...);
- BOOST_CHECK_MESSAGE(result.first == result.second, "Computed values do not match."
- "\nSolidity: " + toHex(result.first) + "\nC++: " + toHex(result.second));
+ bytes solidityResult = callContractFunction(_index, _arguments...);
+ bytes cppResult = callCppAndEncodeResult(_cppFunction, _arguments...);
+ BOOST_CHECK_MESSAGE(solidityResult == cppResult, "Computed values do not match."
+ "\nSolidity: " + toHex(solidityResult) + "\nC++: " + toHex(cppResult));
}
template <class CppFunction, class... Args>
@@ -76,27 +77,15 @@ public:
{
for (u256 argument = _rangeStart; argument < _rangeEnd; ++argument)
{
- pair<bytes, bytes> result = callImplementations(_index, _cppFunction, argument);
- BOOST_CHECK_MESSAGE(result.first == result.second, "Computed values do not match."
- "\nSolidity: " + toHex(result.first) + "\nC++: " + toHex(result.second) +
+ bytes solidityResult = callContractFunction(_index, argument);
+ bytes cppResult = callCppAndEncodeResult(_cppFunction, argument);
+ BOOST_CHECK_MESSAGE(solidityResult == cppResult, "Computed values do not match."
+ "\nSolidity: " + toHex(solidityResult) + "\nC++: " + toHex(cppResult) +
"\nArgument: " + toHex(toBigEndian(argument)));
}
}
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>
bytes argsToBigEndian(FirstArg const& _firstArg, Args const&... _followingArgs) const
{
@@ -105,6 +94,20 @@ private:
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)
{
eth::Executive executive(m_state);