From 98db2503daaee80140d3f4d7c1d9abaf142a8f3e Mon Sep 17 00:00:00 2001 From: Ermal Kaleci Date: Wed, 3 Aug 2022 01:35:35 +0200 Subject: [PATCH] fix developer check (#2306) * fix developer check * clippy --- modules/evm/src/lib.rs | 11 +++-------- modules/evm/src/tests.rs | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/modules/evm/src/lib.rs b/modules/evm/src/lib.rs index 75df7fff06..f6140b5d28 100644 --- a/modules/evm/src/lib.rs +++ b/modules/evm/src/lib.rs @@ -1589,7 +1589,7 @@ impl Pallet { { // 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 @@ -1597,13 +1597,8 @@ impl Pallet { } fn is_developer_or_contract(caller: &H160) -> bool { - if let Some(AccountInfo { contract_info, .. }) = Accounts::::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 { diff --git a/modules/evm/src/tests.rs b/modules/evm/src/tests.rs index d207853ce1..24c88302b1 100644 --- a/modules/evm/src/tests.rs +++ b/modules/evm/src/tests.rs @@ -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 = ::AddressMapping::get_account_id(&addr); + + assert_eq!(Pallet::::is_developer_or_contract(&addr), false); + + assert_ok!(>::transfer( + GetNativeCurrencyId::get(), + &::AddressMapping::get_account_id(&alice()), + &who, + DEVELOPER_DEPOSIT, + )); + + assert_ok!(::Currency::ensure_reserved_named( + &RESERVE_ID_DEVELOPER_DEPOSIT, + &who, + DEVELOPER_DEPOSIT, + )); + assert_eq!(Pallet::::is_developer_or_contract(&addr), true); + }) +}