Skip to content

Commit

Permalink
fix developer check (#2306)
Browse files Browse the repository at this point in the history
* fix developer check

* clippy
  • Loading branch information
ermalkaleci authored Aug 2, 2022
1 parent aa12c5d commit 98db250
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
11 changes: 3 additions & 8 deletions modules/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1589,21 +1589,16 @@ impl<T: Config> Pallet<T> {
{
// https://github.com/AcalaNetwork/Acala/blob/af1c277/modules/evm/rpc/src/lib.rs#L176
// when rpc is called, from is empty, allowing the call
published || maintainer == *caller || Self::is_developer_or_contract(caller) || *caller == H160::default()
published || maintainer == *caller || *caller == H160::default() || Self::is_developer_or_contract(caller)
} else {
// contract non exist, we don't override default evm behaviour
true
}
}

fn is_developer_or_contract(caller: &H160) -> bool {
if let Some(AccountInfo { contract_info, .. }) = Accounts::<T>::get(caller) {
let account_id = T::AddressMapping::get_account_id(caller);
contract_info.is_some()
|| !T::Currency::reserved_balance_named(&RESERVE_ID_DEVELOPER_DEPOSIT, &account_id).is_zero()
} else {
false
}
let account_id = T::AddressMapping::get_account_id(caller);
Self::query_developer_status(account_id) || Self::is_contract(caller)
}

fn reserve_storage(caller: &H160, limit: u32) -> DispatchResult {
Expand Down
24 changes: 24 additions & 0 deletions modules/evm/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2282,3 +2282,27 @@ fn auto_publish_works() {
);
});
}

#[test]
fn reserve_deposit_makes_user_developer() {
new_test_ext().execute_with(|| {
let addr = H160(hex!("1100000000000000000000000000000000000011"));
let who = <Runtime as Config>::AddressMapping::get_account_id(&addr);

assert_eq!(Pallet::<Runtime>::is_developer_or_contract(&addr), false);

assert_ok!(<Currencies as MultiCurrency<_>>::transfer(
GetNativeCurrencyId::get(),
&<Runtime as Config>::AddressMapping::get_account_id(&alice()),
&who,
DEVELOPER_DEPOSIT,
));

assert_ok!(<Runtime as Config>::Currency::ensure_reserved_named(
&RESERVE_ID_DEVELOPER_DEPOSIT,
&who,
DEVELOPER_DEPOSIT,
));
assert_eq!(Pallet::<Runtime>::is_developer_or_contract(&addr), true);
})
}

0 comments on commit 98db250

Please sign in to comment.