Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

Commit

Permalink
Merge pull request #5868 from ethereum/importres
Browse files Browse the repository at this point in the history
return importBlockFailed ImportResult in test_importRawBlock
  • Loading branch information
winsvega authored Dec 23, 2019
2 parents 255a75e + f2869fc commit 31db6db
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [1.9.0] - Unreleased

- Added: [#5868](https://github.com/ethereum/aleth/pull/5868) `test_importRawBlock` RPC method reports the detailed reason when import fails.

## [1.8.0] - 2019-12-16

- Added: [#5699](https://github.com/ethereum/aleth/pull/5699) EIP 2046: Reduced gas cost for static calls made to precompiles.
Expand Down Expand Up @@ -116,6 +120,7 @@
- Fixed: [#5181](https://github.com/ethereum/aleth/issues/5181) Fix building on PowerPC architecture where -mtune=generic is not available.


[1.9.0]: https://github.com/ethereum/aleth/compare/v1.8.0...master
[1.8.0]: https://github.com/ethereum/aleth/releases/tag/v1.8.0
[1.7.2]: https://github.com/ethereum/aleth/releases/tag/v1.7.2
[1.7.1]: https://github.com/ethereum/aleth/releases/tag/v1.7.1
Expand Down
120 changes: 119 additions & 1 deletion libweb3jsonrpc/Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <jsonrpccpp/common/errors.h>
#include <jsonrpccpp/common/exception.h>
#include <libdevcore/CommonJS.h>
#include <libethcore/Exceptions.h>
#include <libethereum/ChainParams.h>
#include <libethereum/ClientTest.h>

Expand All @@ -20,6 +21,114 @@ Test::Test(eth::Client& _eth): m_eth(_eth) {}

namespace
{
string importResultToErrorMessage(ImportResult _res)
{
switch (_res)
{
case ImportResult::AlreadyInChain:
return "AlreadyInChain";
case ImportResult::AlreadyKnown:
return "AlreadyKnown";
case ImportResult::BadChain:
return "BadChain";
case ImportResult::FutureTimeKnown:
return "FutureTimeKnown";
case ImportResult::FutureTimeUnknown:
return "FutureTimeUnknown";
case ImportResult::Malformed:
return "Malformed";
case ImportResult::OverbidGasPrice:
return "OverbidGasPrice";
case ImportResult::Success:
return "Success";
case ImportResult::UnknownParent:
return "UnknownParent";
case ImportResult::ZeroSignature:
return "ZeroSignature";
default:
return "ImportResult unhandled case";
}
}

string exceptionToErrorMessage(boost::exception_ptr _e)
{
string ret;
try
{
boost::rethrow_exception(_e);
}
catch (ExtraDataTooBig const&)
{
ret = "ExtraData too big.";
}
catch (InvalidDifficulty const&)
{
ret = "Invalid Difficulty.";
}
catch (InvalidGasLimit const&)
{
ret = "Invalid Block GasLimit.";
}
catch (BlockGasLimitReached const&)
{
ret = "Block GasLimit reached.";
}
catch (TooMuchGasUsed const&)
{
ret = "Too much gas used.";
}
catch (InvalidNumber const&)
{
ret = "Invalid number.";
}
catch (InvalidLogBloom const&)
{
ret = "Invalid log bloom.";
}
catch (InvalidTimestamp const&)
{
ret = "Invalid timestamp.";
}
catch (InvalidBlockNonce const&)
{
ret = "Invalid block nonce.";
}
catch (UnknownParent const&)
{
ret = "Unknown parent.";
}
catch (InvalidUnclesHash const&)
{
ret = "Invalid uncles hash.";
}
catch (InvalidTransactionsRoot const&)
{
ret = "Invalid transactions root.";
}
catch (InvalidStateRoot const&)
{
ret = "Invalid state root.";
}
catch (InvalidGasUsed const&)
{
ret = "Invalid gas used.";
}
catch (InvalidReceiptsStateRoot const&)
{
ret = "Invalid receipts state root.";
}
catch (InvalidParentHash const&)
{
ret = "Invalid parent hash.";
}
catch (...)
{
ret = "Unknown error.";
}
return ret;
}


string logEntriesToLogHash(eth::LogEntries const& _logs)
{
RLPStream s;
Expand Down Expand Up @@ -125,7 +234,16 @@ std::string Test::test_importRawBlock(string const& _blockRLP)
catch (ImportBlockFailed const& e)
{
cwarn << diagnostic_information(e);
throw JsonRpcException("Block import failed.");

string detailedError;
if (auto nested = boost::get_error_info<errinfo_nestedException>(e))
detailedError = exceptionToErrorMessage(*nested);
else if (auto importResult = boost::get_error_info<errinfo_importResult>(e))
detailedError = importResultToErrorMessage(*importResult);
else
detailedError = "No nested info, no import result info detected on the exception";

throw JsonRpcException("Block import failed: " + detailedError);
}
catch (std::exception const& e)
{
Expand Down
2 changes: 1 addition & 1 deletion test/jsontests
Submodule jsontests updated 23 files
+6 −6 BlockchainTests/GeneralStateTests/stQuadraticComplexityTest/Call1MB1024Calldepth.json
+247 −0 BlockchainTests/GeneralStateTests/stQuadraticComplexityTest/Call20KbytesContract50_1.json
+247 −0 BlockchainTests/GeneralStateTests/stQuadraticComplexityTest/Call20KbytesContract50_2.json
+247 −0 BlockchainTests/GeneralStateTests/stQuadraticComplexityTest/Call20KbytesContract50_3.json
+6 −6 BlockchainTests/GeneralStateTests/stQuadraticComplexityTest/Call50000.json
+6 −6 BlockchainTests/GeneralStateTests/stQuadraticComplexityTest/Call50000_ecrec.json
+6 −6 BlockchainTests/GeneralStateTests/stQuadraticComplexityTest/Call50000_identity.json
+6 −6 BlockchainTests/GeneralStateTests/stQuadraticComplexityTest/Call50000_identity2.json
+6 −6 BlockchainTests/GeneralStateTests/stQuadraticComplexityTest/Call50000_rip160.json
+6 −6 BlockchainTests/GeneralStateTests/stQuadraticComplexityTest/Call50000_sha256.json
+0 −247 BlockchainTests/GeneralStateTests/stQuadraticComplexityTest/Call50000bytesContract50_1.json
+0 −247 BlockchainTests/GeneralStateTests/stQuadraticComplexityTest/Call50000bytesContract50_2.json
+0 −247 BlockchainTests/GeneralStateTests/stQuadraticComplexityTest/Call50000bytesContract50_3.json
+6 −6 BlockchainTests/GeneralStateTests/stQuadraticComplexityTest/Callcode50000.json
+6 −6 BlockchainTests/GeneralStateTests/stQuadraticComplexityTest/Create1000.json
+6 −6 BlockchainTests/GeneralStateTests/stQuadraticComplexityTest/Create1000Byzantium.json
+6 −6 BlockchainTests/GeneralStateTests/stQuadraticComplexityTest/QuadraticComplexitySolidity_CallDataCopy.json
+6 −6 BlockchainTests/GeneralStateTests/stQuadraticComplexityTest/Return50000.json
+6 −6 BlockchainTests/GeneralStateTests/stQuadraticComplexityTest/Return50000_2.json
+554 −0 BlockchainTests/GeneralStateTests/stSelfBalance/selfBalanceCallTypes.json
+116 −0 GeneralStateTests/stSelfBalance/selfBalanceCallTypes.json
+3 −0 PRLOG.md
+135 −0 src/GeneralStateTestsFiller/stSelfBalance/selfBalanceCallTypesFiller.json

0 comments on commit 31db6db

Please sign in to comment.