Skip to content

Commit

Permalink
Merge pull request #1985 from skalenetwork/bug/1963-wrong-max-fee-per…
Browse files Browse the repository at this point in the history
…-gas

#1963 fix max fee per gas in json rpc representation
  • Loading branch information
olehnikolaiev authored Sep 11, 2024
2 parents fbe0107 + 519ff02 commit 070d3a2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
6 changes: 3 additions & 3 deletions libweb3jsonrpc/JsonHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ Json::Value toJson( dev::eth::Transaction const& _t, std::pair< h256, unsigned >
}
res["accessList"].append( accessList );
}
if ( _t.txType() != dev::eth::TransactionType::Type1 ) {
if ( _t.txType() == dev::eth::TransactionType::Type2 ) {
res["maxPriorityFeePerGas"] = toJS( _t.maxPriorityFeePerGas() );
res["maxFeePerGas"] = toJS( _t.maxFeePerGas() );
}
Expand Down Expand Up @@ -366,7 +366,7 @@ Json::Value toJson( dev::eth::Transaction const& _t ) {
}
res["accessList"].append( accessList );
}
if ( _t.txType() != dev::eth::TransactionType::Type1 ) {
if ( _t.txType() == dev::eth::TransactionType::Type2 ) {
res["maxPriorityFeePerGas"] = toJS( _t.maxPriorityFeePerGas() );
res["maxFeePerGas"] = toJS( _t.maxFeePerGas() );
}
Expand Down Expand Up @@ -421,7 +421,7 @@ Json::Value toJson( dev::eth::LocalisedTransaction const& _t ) {
}
if ( _t.txType() != dev::eth::TransactionType::Type1 ) {
res["maxPriorityFeePerGas"] = toJS( _t.maxPriorityFeePerGas() );
res["maxFeePerGas"] = toJS( _t.maxPriorityFeePerGas() );
res["maxFeePerGas"] = toJS( _t.maxFeePerGas() );
}
}
}
Expand Down
13 changes: 7 additions & 6 deletions test/unittests/libweb3jsonrpc/jsonrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3226,7 +3226,7 @@ BOOST_AUTO_TEST_CASE( eip1559Transactions ) {

// send 1 WEI from 0x5EdF1e852fdD1B0Bc47C0307EF755C76f4B9c251 to 0x7D36aF85A184E220A656525fcBb9A63B9ab3C12b
// encoded type 2 txn
txHash = fixture.rpcClient->eth_sendRawTransaction( "0x02f8c98197808504a817c8008504a817c800827530947d36af85a184e220a656525fcbb9a63b9ab3c12b0180f85bf85994de0b295669a9fd93d5f28d9ec85e40f4cb697baef842a00000000000000000000000000000000000000000000000000000000000000003a0000000000000000000000000000000000000000000000000000000000000000780a0f1a407dfc1a9f782001d89f617e9b3a2f295378533784fb39960dea60beea2d0a05ac3da2946554ba3d5721850f4f89ee7a0c38e4acab7130908e7904d13174388" );
txHash = fixture.rpcClient->eth_sendRawTransaction( "0x02f8c98197808504a817c8018504a817c800827530947d36af85a184e220a656525fcbb9a63b9ab3c12b0180f85bf85994de0b295669a9fd93d5f28d9ec85e40f4cb697baef842a00000000000000000000000000000000000000000000000000000000000000003a0000000000000000000000000000000000000000000000000000000000000000701a005bd1eedc509a8e94cfcfc84d0b5fd53a0888a475274cbeee321047da5d139f8a00e7f0dd8b5277766d447ea51b7d8f571dc8bb57ff95c068c58f5b6fe9089dde8" );
auto pendingTransactions = fixture.rpcClient->eth_pendingTransactions();
BOOST_REQUIRE( pendingTransactions.isArray() && pendingTransactions.size() == 1);
BOOST_REQUIRE( pendingTransactions[0]["type"] == "0x2" );
Expand All @@ -3235,9 +3235,8 @@ BOOST_AUTO_TEST_CASE( eip1559Transactions ) {
dev::eth::mineTransaction( *( fixture.client ), 1 );

// compare with txn hash from geth
BOOST_REQUIRE( txHash == "0x7bd586e93e3012577de4ba33e3b887baf520cbb92c5dd10996b262f9c5c8f747" );
std::cout << dev::toHexPrefixed( fixture.client->transactions( 4 )[0].toBytes() ) << '\n';
BOOST_REQUIRE( dev::toHexPrefixed( fixture.client->transactions( 4 )[0].toBytes() ) == "0x02f8c98197808504a817c8008504a817c800827530947d36af85a184e220a656525fcbb9a63b9ab3c12b0180f85bf85994de0b295669a9fd93d5f28d9ec85e40f4cb697baef842a00000000000000000000000000000000000000000000000000000000000000003a0000000000000000000000000000000000000000000000000000000000000000780a0f1a407dfc1a9f782001d89f617e9b3a2f295378533784fb39960dea60beea2d0a05ac3da2946554ba3d5721850f4f89ee7a0c38e4acab7130908e7904d13174388" );
BOOST_REQUIRE( txHash == "0xde30b1c26b89e20f6426a87b9427381f9e79e2bb80f992a6f2e1b4dccfa345de" );
BOOST_REQUIRE( dev::toHexPrefixed( fixture.client->transactions( 4 )[0].toBytes() ) == "0x02f8c98197808504a817c8018504a817c800827530947d36af85a184e220a656525fcbb9a63b9ab3c12b0180f85bf85994de0b295669a9fd93d5f28d9ec85e40f4cb697baef842a00000000000000000000000000000000000000000000000000000000000000003a0000000000000000000000000000000000000000000000000000000000000000701a005bd1eedc509a8e94cfcfc84d0b5fd53a0888a475274cbeee321047da5d139f8a00e7f0dd8b5277766d447ea51b7d8f571dc8bb57ff95c068c58f5b6fe9089dde8" );

BOOST_REQUIRE( fixture.rpcClient->eth_getBalance( "0x7D36aF85A184E220A656525fcBb9A63B9ab3C12b", "latest" ) == "0x1" );

Expand Down Expand Up @@ -3269,21 +3268,23 @@ BOOST_AUTO_TEST_CASE( eip1559Transactions ) {
BOOST_REQUIRE( result["accessList"].isArray() );
BOOST_REQUIRE( result.isMember( "maxPriorityFeePerGas" ) && result["maxPriorityFeePerGas"].isString() );
BOOST_REQUIRE( result.isMember( "maxFeePerGas" ) && result["maxFeePerGas"].isString() );
BOOST_REQUIRE( result["maxPriorityFeePerGas"] == "0x4a817c801" );
BOOST_REQUIRE( result["maxFeePerGas"] == "0x4a817c800" );

result = fixture.rpcClient->eth_getTransactionByBlockHashAndIndex( blockHash, "0x0" );
BOOST_REQUIRE( result["hash"].asString() == txHash );
BOOST_REQUIRE( result["type"] == "0x2" );
BOOST_REQUIRE( toJS( jsToInt( result["yParity"].asString() ) + 35 + 2 * fixture.client->chainParams().chainID ) == result["v"].asString() );
BOOST_REQUIRE( result["accessList"].isArray() );
BOOST_REQUIRE( result["maxPriorityFeePerGas"] == "0x4a817c800" );
BOOST_REQUIRE( result["maxPriorityFeePerGas"] == "0x4a817c801" );
BOOST_REQUIRE( result["maxFeePerGas"] == "0x4a817c800" );

result = fixture.rpcClient->eth_getTransactionByBlockNumberAndIndex( "0x4", "0x0" );
BOOST_REQUIRE( result["hash"].asString() == txHash );
BOOST_REQUIRE( result["type"] == "0x2" );
BOOST_REQUIRE( toJS( jsToInt( result["yParity"].asString() ) + 35 + 2 * fixture.client->chainParams().chainID ) == result["v"].asString() );
BOOST_REQUIRE( result["accessList"].isArray() );
BOOST_REQUIRE( result["maxPriorityFeePerGas"] == "0x4a817c800" );
BOOST_REQUIRE( result["maxPriorityFeePerGas"] == "0x4a817c801" );
BOOST_REQUIRE( result["maxFeePerGas"] == "0x4a817c800" );

BOOST_REQUIRE_NO_THROW( fixture.rpcClient->eth_getBlockByNumber( "0x0", false ) );
Expand Down

0 comments on commit 070d3a2

Please sign in to comment.