Skip to content

Commit

Permalink
Merge branch 'v3.19.0' into feature/1719-eip1559
Browse files Browse the repository at this point in the history
  • Loading branch information
olehnikolaiev authored May 7, 2024
2 parents 3181ea4 + 55f1b96 commit d7ba751
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
20 changes: 19 additions & 1 deletion libweb3jsonrpc/Eth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -871,11 +871,29 @@ Json::Value Eth::eth_getFilterLogs( string const& _filterId ) {

Json::Value Eth::eth_getLogs( Json::Value const& _json ) {
try {
return toJson( client()->logs( toLogFilter( _json ) ) );
LogFilter filter = toLogFilter( _json );
if ( !_json["blockHash"].isNull() ) {
if ( !_json["fromBlock"].isNull() || !_json["toBlock"].isNull() )
BOOST_THROW_EXCEPTION( JsonRpcException( Errors::ERROR_RPC_INVALID_PARAMS,
"fromBlock and toBlock are not allowed if blockHash is present" ) );
string strHash = _json["blockHash"].asString();
if ( strHash.empty() )
throw std::invalid_argument( "blockHash cannot be an empty string" );
uint64_t number = m_eth.numberFromHash( jsToFixed< 32 >( strHash ) );
if ( number == PendingBlock )
BOOST_THROW_EXCEPTION( JsonRpcException( Errors::ERROR_RPC_INVALID_PARAMS,
"A block with this hash does not exist in the database. If this is an old "
"block, try connecting to an archive node" ) );
filter.withEarliest( number );
filter.withLatest( number );
}
return toJson( client()->logs( filter ) );
} catch ( const TooBigResponse& ) {
BOOST_THROW_EXCEPTION( JsonRpcException( Errors::ERROR_RPC_INVALID_PARAMS,
"Log response size exceeded. Maximum allowed number of requested blocks is " +
to_string( this->client()->chainParams().getLogsBlocksLimit ) ) );
} catch ( const JsonRpcException& ) {
throw;
} catch ( ... ) {
BOOST_THROW_EXCEPTION( JsonRpcException( Errors::ERROR_RPC_INVALID_PARAMS ) );
}
Expand Down
32 changes: 32 additions & 0 deletions test/unittests/libweb3jsonrpc/jsonrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2186,6 +2186,38 @@ contract Logger{
BOOST_REQUIRE_NO_THROW( Json::Value res = fixture.rpcClient->eth_getFilterChanges(filterId) );
}

// test blockHash parameter
BOOST_AUTO_TEST_CASE( getLogs_blockHash ) {
JsonRpcFixture fixture;
dev::eth::simulateMining( *( fixture.client ), 1 );

string latestHash = fixture.rpcClient->eth_getBlockByNumber("latest", false)["hash"].asString();

Json::Value req;
req["blockHash"] = "xyz";
BOOST_REQUIRE_THROW( Json::Value logs = fixture.rpcClient->eth_getLogs(req), std::exception );

req["blockHash"] = Json::Value(Json::arrayValue);
BOOST_REQUIRE_THROW( Json::Value logs = fixture.rpcClient->eth_getLogs(req), std::exception );

req["fromBlock"] = 1;
req["toBlock"] = 1;
BOOST_REQUIRE_THROW( Json::Value logs = fixture.rpcClient->eth_getLogs(req), std::exception );

req["blockHash"] = latestHash;
BOOST_REQUIRE_THROW( Json::Value logs = fixture.rpcClient->eth_getLogs(req), std::exception );

req.removeMember("fromBlock");
req.removeMember("toBlock");
BOOST_REQUIRE_NO_THROW( Json::Value logs = fixture.rpcClient->eth_getLogs(req) );

req["blockHash"] = "0x88df016429689c079f3b2f6ad39fa052532c56795b733da78a91ebe6a713944b";
BOOST_REQUIRE_THROW( Json::Value logs = fixture.rpcClient->eth_getLogs(req), std::exception );

req["blockHash"] = "";
BOOST_REQUIRE_THROW( Json::Value logs = fixture.rpcClient->eth_getLogs(req), std::exception );
}

BOOST_AUTO_TEST_CASE( estimate_gas_low_gas_txn ) {
JsonRpcFixture fixture;
dev::eth::simulateMining( *( fixture.client ), 10 );
Expand Down

0 comments on commit d7ba751

Please sign in to comment.