Skip to content

Commit d36d48a

Browse files
authored
[pallet-revive] Allows setting evm balance for non-existing account (#9911)
Allows calling set_evm_balance for a non-existing account on pallet-revive. It is needed by foundry to inject EVM accounts.
1 parent 42510be commit d36d48a

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

prdoc/pr_9911.prdoc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
title: '[pallet-revive] Allows setting evm balance for non-existing account'
2+
doc:
3+
- audience: Runtime User
4+
description: |-
5+
Allows calling set_evm_balance for a non-existing account on pallet-revive.
6+
7+
crates:
8+
- name: pallet-revive
9+
bump: minor

substrate/frame/revive/src/lib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,8 +1645,12 @@ impl<T: Config> Pallet<T> {
16451645
.map_err(|_| <Error<T>>::BalanceConversionFailed)?;
16461646
let account_id = T::AddressMapper::to_account_id(&address);
16471647
T::Currency::set_balance(&account_id, balance);
1648-
AccountInfoOf::<T>::mutate(address, |account| {
1649-
account.as_mut().map(|a| a.dust = dust);
1648+
AccountInfoOf::<T>::mutate(&address, |account| {
1649+
if let Some(account) = account {
1650+
account.dust = dust;
1651+
} else {
1652+
*account = Some(AccountInfo { dust, ..Default::default() });
1653+
}
16501654
});
16511655

16521656
Ok(())

substrate/frame/revive/src/tests/pvm.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,17 @@ fn eth_call_transfer_with_dust_works() {
201201
});
202202
}
203203

204+
#[test]
205+
fn set_evm_balance_for_eoa_works() {
206+
ExtBuilder::default().existential_deposit(200).build().execute_with(|| {
207+
let native_with_dust = BalanceWithDust::new_unchecked::<Test>(100, 10);
208+
let evm_balance = Pallet::<Test>::convert_native_to_evm(native_with_dust);
209+
let _ = Pallet::<Test>::set_evm_balance(&ALICE_ADDR, evm_balance);
210+
211+
assert_eq!(Pallet::<Test>::evm_balance(&ALICE_ADDR), evm_balance);
212+
});
213+
}
214+
204215
#[test]
205216
fn set_evm_balance_works() {
206217
let (binary, _) = compile_module("dummy").unwrap();

0 commit comments

Comments
 (0)