Skip to content

Commit

Permalink
pallet-evm: fix wrong logic in mutate_account_basic (paritytech#6786)
Browse files Browse the repository at this point in the history
* pallet-evm: fix wrong logic in mutate_account_basic

* Add test for mutate account
  • Loading branch information
sorpaas authored Aug 12, 2020
1 parent f6d66db commit 5b809d2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
8 changes: 4 additions & 4 deletions frame/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand Down
20 changes: 20 additions & 0 deletions frame/evm/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
});
});
}

0 comments on commit 5b809d2

Please sign in to comment.