File tree Expand file tree Collapse file tree 3 files changed +42
-1
lines changed Expand file tree Collapse file tree 3 files changed +42
-1
lines changed Original file line number Diff line number Diff line change @@ -361,9 +361,21 @@ pub enum EthRequest {
361361 SetRpcUrl ( String ) ,
362362
363363 /// Modifies the balance of an account.
364- #[ serde( rename = "anvil_setBalance" , alias = "hardhat_setBalance" ) ]
364+ #[ serde(
365+ rename = "anvil_setBalance" ,
366+ alias = "hardhat_setBalance" ,
367+ alias = "tenderly_setBalance"
368+ ) ]
365369 SetBalance ( Address , #[ serde( deserialize_with = "deserialize_number" ) ] U256 ) ,
366370
371+ /// Increases the balance of an account.
372+ #[ serde(
373+ rename = "anvil_addBalance" ,
374+ alias = "hardhat_addBalance" ,
375+ alias = "tenderly_addBalance"
376+ ) ]
377+ AddBalance ( Address , #[ serde( deserialize_with = "deserialize_number" ) ] U256 ) ,
378+
367379 /// Modifies the ERC20 balance of an account.
368380 #[ serde(
369381 rename = "anvil_dealERC20" ,
Original file line number Diff line number Diff line change @@ -356,6 +356,9 @@ impl EthApi {
356356 EthRequest :: SetBalance ( addr, val) => {
357357 self . anvil_set_balance ( addr, val) . await . to_rpc_result ( )
358358 }
359+ EthRequest :: AddBalance ( addr, val) => {
360+ self . anvil_add_balance ( addr, val) . await . to_rpc_result ( )
361+ }
359362 EthRequest :: DealERC20 ( addr, token_addr, val) => {
360363 self . anvil_deal_erc20 ( addr, token_addr, val) . await . to_rpc_result ( )
361364 }
@@ -1856,6 +1859,16 @@ impl EthApi {
18561859 Ok ( ( ) )
18571860 }
18581861
1862+ /// Increases the balance of an account.
1863+ ///
1864+ /// Handler for RPC call: `anvil_addBalance`
1865+ pub async fn anvil_add_balance ( & self , address : Address , balance : U256 ) -> Result < ( ) > {
1866+ node_info ! ( "anvil_addBalance" ) ;
1867+ let current_balance = self . backend . get_balance ( address, None ) . await ?;
1868+ self . backend . set_balance ( address, current_balance + balance) . await ?;
1869+ Ok ( ( ) )
1870+ }
1871+
18591872 /// Deals ERC20 tokens to a address
18601873 ///
18611874 /// Handler for RPC call: `anvil_dealERC20`
Original file line number Diff line number Diff line change @@ -1490,6 +1490,22 @@ async fn test_set_erc20_balance() {
14901490 assert_eq ! ( new_balance, value) ;
14911491}
14921492
1493+ #[ tokio:: test( flavor = "multi_thread" ) ]
1494+ async fn test_add_balance ( ) {
1495+ let config: NodeConfig = fork_config ( ) ;
1496+ let address = config. genesis_accounts [ 0 ] . address ( ) ;
1497+ let ( api, _handle) = spawn ( config) . await ;
1498+
1499+ let start_balance = U256 :: from ( 100_000_u64 ) ;
1500+ api. anvil_set_balance ( address, start_balance) . await . unwrap ( ) ;
1501+
1502+ let balance_increase = U256 :: from ( 50_000_u64 ) ;
1503+ api. anvil_add_balance ( address, balance_increase) . await . unwrap ( ) ;
1504+
1505+ let new_balance = api. balance ( address, None ) . await . unwrap ( ) ;
1506+ assert_eq ! ( new_balance, start_balance + balance_increase) ;
1507+ }
1508+
14931509#[ tokio:: test( flavor = "multi_thread" ) ]
14941510async fn test_reset_updates_cache_path_when_rpc_url_not_provided ( ) {
14951511 let config: NodeConfig = fork_config ( ) ;
You can’t perform that action at this time.
0 commit comments