mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Improved error messages for EndToEnd tests.
This commit is contained in:
parent
ccb689701e
commit
8e4f242274
@ -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;
|
||||
@ -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)
|
||||
|
@ -131,6 +131,8 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
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)); }
|
||||
@ -293,6 +295,12 @@ protected:
|
||||
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
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -24,7 +24,7 @@
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include "../ExecutionFramework.h"
|
||||
#include <test/ExecutionFramework.h>
|
||||
|
||||
#include <libsolidity/interface/CompilerStack.h>
|
||||
#include <libsolidity/interface/Exceptions.h>
|
||||
|
Loading…
Reference in New Issue
Block a user