diff --git a/substrate/frame/evm/src/lib.rs b/substrate/frame/evm/src/lib.rs index 013da0cca97e5eef9d5dc81e652136c43afbda77..910030383e1efc927097782b1cb52b40e489c66f 100644 --- a/substrate/frame/evm/src/lib.rs +++ b/substrate/frame/evm/src/lib.rs @@ -438,11 +438,11 @@ impl<T: Trait> Module<T> { } } - if current.balance < new.balance { - let diff = new.balance - current.balance; - T::Currency::slash(&account_id, diff.low_u128().unique_saturated_into()); - } else if current.balance > new.balance { + if current.balance > new.balance { let diff = current.balance - new.balance; + T::Currency::slash(&account_id, diff.low_u128().unique_saturated_into()); + } else if current.balance < new.balance { + let diff = new.balance - current.balance; T::Currency::deposit_creating(&account_id, diff.low_u128().unique_saturated_into()); } } diff --git a/substrate/frame/evm/src/tests.rs b/substrate/frame/evm/src/tests.rs index f818ee630b7deaea539559424acf7022f3852afe..652d6c723b9d337ba42fbd62e3445dee64fa253f 100644 --- a/substrate/frame/evm/src/tests.rs +++ b/substrate/frame/evm/src/tests.rs @@ -166,3 +166,23 @@ fn fail_call_return_ok() { )); }); } + +#[test] +fn mutate_account_works() { + new_test_ext().execute_with(|| { + EVM::mutate_account_basic( + &H160::from_str("1000000000000000000000000000000000000001").unwrap(), + Account { + nonce: U256::from(10), + balance: U256::from(1000), + }, + ); + + assert_eq!(EVM::account_basic( + &H160::from_str("1000000000000000000000000000000000000001").unwrap() + ), Account { + nonce: U256::from(10), + balance: U256::from(1000), + }); + }); +}