From 466454489402399ff9b5d1145cae7a7f58d1e90b Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 11 Nov 2014 11:41:23 +0100 Subject: [PATCH] Working template magic for void function. --- test/solidityEndToEndTest.cpp | 41 +++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/test/solidityEndToEndTest.cpp b/test/solidityEndToEndTest.cpp index 123d67988..85fd707c3 100644 --- a/test/solidityEndToEndTest.cpp +++ b/test/solidityEndToEndTest.cpp @@ -65,9 +65,10 @@ public: template void testSolidityAgainstCpp(byte _index, CppFunction const& _cppFunction, Args const&... _arguments) { - pair 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 @@ -76,27 +77,15 @@ public: { for (u256 argument = _rangeStart; argument < _rangeEnd; ++argument) { - pair 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 - pair callImplementations(byte _solidityIndex, CppFunction const& _cppFunction, - Args const&... _arguments) - { - bytes solidityResult = callContractFunction(_solidityIndex, _arguments...); - bytes cppResult; - if (is_void::value) - _cppFunction(_arguments...); - else - cppResult = toBigEndian(_cppFunction(_arguments...)); - return make_pair(solidityResult, cppResult); - } - template bytes argsToBigEndian(FirstArg const& _firstArg, Args const&... _followingArgs) const { @@ -105,6 +94,20 @@ private: bytes argsToBigEndian() const { return bytes(); } + template + auto callCppAndEncodeResult(CppFunction const& _cppFunction, Args const&... _arguments) + -> typename enable_if::value, bytes>::type + { + _cppFunction(_arguments...); + return bytes(); + } + template + auto callCppAndEncodeResult(CppFunction const& _cppFunction, Args const&... _arguments) + -> typename enable_if::value, bytes>::type + { + return toBigEndian(_cppFunction(_arguments...)); + } + void sendMessage(bytes const& _data, bool _isCreation) { eth::Executive executive(m_state);