From 82e56b3febe1d4645400746fc46c1fad675eec62 Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Fri, 31 Jul 2020 16:35:44 +0200 Subject: [PATCH 1/2] pallet-evm: fix wrong logic in mutate_account_basic --- frame/evm/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/frame/evm/src/lib.rs b/frame/evm/src/lib.rs index 0dcc4526c7fbc..2956adb56fec9 100644 --- a/frame/evm/src/lib.rs +++ b/frame/evm/src/lib.rs @@ -441,11 +441,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()); } } From 9cfec93536c922644c5954d81c2427b569260ee5 Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Thu, 6 Aug 2020 21:12:46 +0200 Subject: [PATCH 2/2] Add test for mutate account --- frame/evm/src/tests.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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), + }); + }); +}