Skip to content

Commit

Permalink
Improved error messages for EndToEnd tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
chriseth authored and axic committed Sep 25, 2017
1 parent ccb6897 commit 8e4f242
Show file tree
Hide file tree
Showing 4 changed files with 884 additions and 824 deletions.
28 changes: 28 additions & 0 deletions test/ExecutionFramework.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include <libdevcore/CommonIO.h>
#include <test/ExecutionFramework.h>

#include <boost/algorithm/string/replace.hpp>

using namespace std;
using namespace dev;
using namespace dev::test;
Expand Down Expand Up @@ -54,6 +56,32 @@ ExecutionFramework::ExecutionFramework() :
m_rpc.test_rewindToBlock(0);
}

std::pair<bool, string> ExecutionFramework::compareAndCreateMessage(
bytes const& _result,
bytes const& _expectation
)
{
if (_result == _expectation)
return std::make_pair(true, std::string{});
std::string message =
"Invalid encoded data\n"
" Result Expectation\n";
auto resultHex = boost::replace_all_copy(toHex(_result), "0", ".");
auto expectedHex = boost::replace_all_copy(toHex(_expectation), "0", ".");
for (size_t i = 0; i < std::max(resultHex.size(), expectedHex.size()); i += 0x40)
{
std::string result{i >= resultHex.size() ? string{} : resultHex.substr(i, 0x40)};
std::string expected{i > expectedHex.size() ? string{} : expectedHex.substr(i, 0x40)};
message +=
(result == expected ? " " : " X ") +
result +
std::string(0x41 - result.size(), ' ') +
expected +
"\n";
}
return make_pair(false, message);
}

void ExecutionFramework::sendMessage(bytes const& _data, bool _isCreation, u256 const& _value)
{
if (m_showMessages)
Expand Down
8 changes: 8 additions & 0 deletions test/ExecutionFramework.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ class ExecutionFramework
}
}

static std::pair<bool, std::string> compareAndCreateMessage(bytes const& _result, bytes const& _expectation);

static bytes encode(bool _value) { return encode(byte(_value)); }
static bytes encode(int _value) { return encode(u256(_value)); }
static bytes encode(size_t _value) { return encode(u256(_value)); }
Expand Down Expand Up @@ -293,6 +295,12 @@ class ExecutionFramework
u256 m_gasUsed;
};

#define ABI_CHECK(result, expectation) do { \
auto abiCheckResult = ExecutionFramework::compareAndCreateMessage((result), (expectation)); \
BOOST_CHECK_MESSAGE(abiCheckResult.first, abiCheckResult.second); \
} while (0)


}
} // end namespaces

Loading

0 comments on commit 8e4f242

Please sign in to comment.