Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions prdoc/pr_9911.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
title: '[pallet-revive] Allows setting evm balance for non-existing account'
doc:
- audience: Runtime User
description: |-
Allows calling set_evm_balance for a non-existing account on pallet-revive.

crates:
- name: pallet-revive
bump: minor
8 changes: 6 additions & 2 deletions substrate/frame/revive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1566,8 +1566,12 @@ where
.map_err(|_| <Error<T>>::BalanceConversionFailed)?;
let account_id = T::AddressMapper::to_account_id(&address);
T::Currency::set_balance(&account_id, balance);
AccountInfoOf::<T>::mutate(address, |account| {
account.as_mut().map(|a| a.dust = dust);
AccountInfoOf::<T>::mutate(&address, |account| {
if let Some(account) = account {
account.dust = dust;
} else {
*account = Some(AccountInfo { dust, ..Default::default() });
}
});

Ok(())
Expand Down
11 changes: 11 additions & 0 deletions substrate/frame/revive/src/tests/pvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,17 @@ fn eth_call_transfer_with_dust_works() {
});
}

#[test]
fn set_evm_balance_for_eoa_works() {
ExtBuilder::default().existential_deposit(200).build().execute_with(|| {
let native_with_dust = BalanceWithDust::new_unchecked::<Test>(100, 10);
let evm_balance = Pallet::<Test>::convert_native_to_evm(native_with_dust);
let _ = Pallet::<Test>::set_evm_balance(&ALICE_ADDR, evm_balance);

assert_eq!(Pallet::<Test>::evm_balance(&ALICE_ADDR), evm_balance);
});
}

#[test]
fn set_evm_balance_works() {
let (binary, _) = compile_module("dummy").unwrap();
Expand Down
Loading