From 5b809d2516e7297c2f2659de767088cdf2b4b7f5 Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Wed, 12 Aug 2020 12:46:28 +0200 Subject: [PATCH] pallet-evm: fix wrong logic in mutate_account_basic (#6786) * pallet-evm: fix wrong logic in mutate_account_basic * Add test for mutate account --- frame/evm/src/lib.rs | 8 ++++---- frame/evm/src/tests.rs | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/frame/evm/src/lib.rs b/frame/evm/src/lib.rs index 013da0cca97e5..910030383e1ef 100644 --- a/frame/evm/src/lib.rs +++ b/frame/evm/src/lib.rs @@ -438,11 +438,11 @@ impl Module { } } - 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/frame/evm/src/tests.rs b/frame/evm/src/tests.rs index f818ee630b7de..652d6c723b9d3 100644 --- a/frame/evm/src/tests.rs +++ b/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), + }); + }); +}