Skip to content

Commit

Permalink
#1994 add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
olehnikolaiev committed Jan 8, 2025
1 parent 2c1029d commit a571b80
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
2 changes: 1 addition & 1 deletion libethcore/TransactionBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ void TransactionBase::fillFromBytesType2( bytesConstRef _rlpData, CheckTransacti
m_maxPriorityFeePerGas = rlp[2].toInt< u256 >();
m_maxFeePerGas = rlp[3].toInt< u256 >();

auto toCompare = _maxFeePerGasPatchEnabled ? m_maxPriorityFeePerGas : m_maxFeePerGas;
auto toCompare = _maxFeePerGasPatchEnabled ? m_maxFeePerGas : m_maxPriorityFeePerGas;
if ( m_maxPriorityFeePerGas > toCompare )
BOOST_THROW_EXCEPTION( InvalidTransactionFormat() << errinfo_comment(
"maxFeePerGas cannot be less than maxPriorityFeePerGas (The "
Expand Down
57 changes: 57 additions & 0 deletions test/unittests/libweb3jsonrpc/jsonrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3337,6 +3337,63 @@ BOOST_AUTO_TEST_CASE( vInTxnSignature ) {
BOOST_REQUIRE( v < 2 && v >= 0 );
}

BOOST_AUTO_TEST_CASE( maxFeePerGasPatch ) {
std::string _config = c_genesisConfigString;
Json::Value ret;
Json::Reader().parse( _config, ret );

// Set chainID = 151
std::string chainID = "0x97";
ret["params"]["chainID"] = chainID;
time_t eip1559PatchActivationTimestamp = time(nullptr) - 1;
time_t maxFeePerGasPatchActivationTimestamp = time(nullptr) + 10;
ret["skaleConfig"]["sChain"]["MaxFeePerGasPatchTimestamp"] = maxFeePerGasPatchActivationTimestamp;
ret["skaleConfig"]["sChain"]["EIP1559TransactionsPatchTimestamp"] = eip1559PatchActivationTimestamp;

Json::FastWriter fastWriter;
std::string config = fastWriter.write( ret );
JsonRpcFixture fixture( config );

dev::eth::simulateMining( *( fixture.client ), 20 );
string senderAddress = toJS(fixture.coinbase.address());

Json::Value txRefill;
txRefill["to"] = "0x5EdF1e852fdD1B0Bc47C0307EF755C76f4B9c251";
txRefill["from"] = senderAddress;
txRefill["gas"] = "100000";
txRefill["gasPrice"] = fixture.rpcClient->eth_gasPrice();
txRefill["value"] = 1000000000000000000;
string txHash = fixture.rpcClient->eth_sendTransaction( txRefill );
dev::eth::mineTransaction( *( fixture.client ), 1 );

Json::Value receipt = fixture.rpcClient->eth_getTransactionReceipt( txHash );
BOOST_REQUIRE( receipt["status"] == string( "0x1" ) );

// send a txn with maxPriorityFeePerGas > maxFeePerGas before MaxFeePerGasPatchTimestamp
txHash = fixture.rpcClient->eth_sendRawTransaction( "0x02f86d8197808504a817c8018504a817c800827530947d36af85a184e220a656525fcbb9a63b9ab3c12b8080c001a0db2fe04a66fa54bfe9c6e0166d85a31b34cbff10dbde0e0584081aec6bb33c30a06b956a49c52f1460da9f93fc495eaa863ae5a8c91ee9230c2f3976f5e74d4f47" );
dev::eth::mineTransaction( *( fixture.client ), 1 );

receipt = fixture.rpcClient->eth_getTransactionReceipt( txHash );
BOOST_REQUIRE( receipt["status"] == string( "0x1" ) );

Json::Value tx = fixture.rpcClient->eth_getTransactionByHash( txHash );
BOOST_REQUIRE( dev::jsToU256( tx["maxFeePerGas"].asString() ) < dev::jsToU256( tx["maxPriorityFeePerGas"].asString() ) );

sleep( 10 );

// force 1 block to update timestamp
txRefill["to"] = "0xc868AF52a6549c773082A334E5AE232e0Ea3B513";
txRefill["from"] = senderAddress;
txRefill["gas"] = "100000";
txRefill["gasPrice"] = fixture.rpcClient->eth_gasPrice();
txRefill["value"] = 0;
txHash = fixture.rpcClient->eth_sendTransaction( txRefill );
dev::eth::mineTransaction( *( fixture.client ), 1 );

// send a txn with maxPriorityFeePerGas > maxFeePerGas before MaxFeePerGasPatchTimestamp, it should fail
BOOST_REQUIRE_THROW( fixture.rpcClient->eth_sendRawTransaction( "0x02f86d8197018504a817c8018504a817c800827530947d36af85a184e220a656525fcbb9a63b9ab3c12b8080c080a0aea5ff86373cbbbb33c9f3e9a25ceb9a694ee71beff452a4d29903d73fd30ca9a00458d4f7d54be178b42d230cc5a4740540d55b8ca0f9c74c79c1d49f6686b1e6" ), jsonrpc::JsonRpcException ); // INVALID_PARAMS
}

BOOST_AUTO_TEST_CASE( etherbase_generation2 ) {
JsonRpcFixture fixture(c_genesisGeneration2ConfigString, false, false, true);
string etherbase = fixture.rpcClient->eth_coinbase();
Expand Down

0 comments on commit a571b80

Please sign in to comment.