Skip to content

Commit 8360d4c

Browse files
committed
Set the empty contract create value to Anyone
1 parent 3487221 commit 8360d4c

File tree

5 files changed

+28
-22
lines changed

5 files changed

+28
-22
lines changed

domains/client/domain-operator/src/tests.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ async fn test_evm_domain_create_contracts_with_allow_list() {
393393

394394
// Wait until list is updated
395395
produce_blocks_until!(ferdie, alice, {
396-
alice.evm_contract_creation_allowed_by().as_ref() == Some(&allow_list)
396+
alice.evm_contract_creation_allowed_by() == allow_list
397397
})
398398
.await
399399
.unwrap();
@@ -579,7 +579,7 @@ async fn test_evm_domain_create_contracts_with_allow_list() {
579579

580580
// Wait until list is updated
581581
produce_blocks_until!(ferdie, alice, {
582-
alice.evm_contract_creation_allowed_by().as_ref() == Some(&allow_list)
582+
alice.evm_contract_creation_allowed_by() == allow_list
583583
})
584584
.await
585585
.unwrap();
@@ -769,7 +769,7 @@ async fn test_evm_domain_create_contracts_with_allow_list() {
769769

770770
// Wait until list is updated
771771
produce_blocks_until!(ferdie, alice, {
772-
alice.evm_contract_creation_allowed_by().as_ref() == Some(&allow_list)
772+
alice.evm_contract_creation_allowed_by() == allow_list
773773
})
774774
.await
775775
.unwrap();
@@ -4647,8 +4647,9 @@ async fn test_domain_sudo_calls() {
46474647
produce_blocks!(ferdie, alice, 3).await.unwrap();
46484648

46494649
// check initial contract allow list
4650-
assert!(
4651-
alice.evm_contract_creation_allowed_by() == Some(PermissionedActionAllowedBy::Anyone),
4650+
assert_eq!(
4651+
alice.evm_contract_creation_allowed_by(),
4652+
PermissionedActionAllowedBy::Anyone,
46524653
"initial contract allow list should be anyone"
46534654
);
46544655

@@ -4683,7 +4684,7 @@ async fn test_domain_sudo_calls() {
46834684

46844685
// Wait until list is updated
46854686
produce_blocks_until!(ferdie, alice, {
4686-
alice.evm_contract_creation_allowed_by().as_ref() == Some(&allow_list)
4687+
alice.evm_contract_creation_allowed_by() == allow_list
46874688
})
46884689
.await
46894690
.unwrap();
@@ -4713,7 +4714,7 @@ async fn test_domain_sudo_calls() {
47134714

47144715
// Wait until list is updated
47154716
produce_blocks_until!(ferdie, alice, {
4716-
alice.evm_contract_creation_allowed_by().as_ref() == Some(&allow_list)
4717+
alice.evm_contract_creation_allowed_by() == allow_list
47174718
})
47184719
.await
47194720
.unwrap();
@@ -4743,7 +4744,7 @@ async fn test_domain_sudo_calls() {
47434744

47444745
// Wait until list is updated
47454746
produce_blocks_until!(ferdie, alice, {
4746-
alice.evm_contract_creation_allowed_by().as_ref() == Some(&allow_list)
4747+
alice.evm_contract_creation_allowed_by() == allow_list
47474748
})
47484749
.await
47494750
.unwrap();
@@ -4773,7 +4774,7 @@ async fn test_domain_sudo_calls() {
47734774

47744775
// Wait until list is updated
47754776
produce_blocks_until!(ferdie, alice, {
4776-
alice.evm_contract_creation_allowed_by().as_ref() == Some(&allow_list)
4777+
alice.evm_contract_creation_allowed_by() == allow_list
47774778
})
47784779
.await
47794780
.unwrap();

domains/pallets/evm-tracker/src/lib.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use sp_domains::PermissionedActionAllowedBy;
3131

3232
#[frame_support::pallet]
3333
mod pallet {
34+
use codec::Codec;
3435
use frame_support::pallet_prelude::*;
3536
use frame_system::pallet_prelude::*;
3637
use sp_core::U256;
@@ -55,7 +56,16 @@ mod pallet {
5556
// be updated.
5657
#[pallet::storage]
5758
pub(super) type ContractCreationAllowedBy<T: Config> =
58-
StorageValue<_, PermissionedActionAllowedBy<T::AccountId>, OptionQuery>;
59+
StorageValue<_, PermissionedActionAllowedBy<T::AccountId>, ValueQuery, DefaultToAnyone>;
60+
61+
/// Default value for ContractCreationAllowedBy if it is not set.
62+
pub struct DefaultToAnyone;
63+
64+
impl<AccountId: Codec + Clone> Get<PermissionedActionAllowedBy<AccountId>> for DefaultToAnyone {
65+
fn get() -> PermissionedActionAllowedBy<AccountId> {
66+
PermissionedActionAllowedBy::Anyone
67+
}
68+
}
5969

6070
/// Pallet EVM account nonce tracker.
6171
#[pallet::pallet]
@@ -100,23 +110,17 @@ impl<T: Config> Pallet<T> {
100110

101111
/// Returns true if the account is allowed to create contracts.
102112
pub fn is_allowed_to_create_contracts(signer: &T::AccountId) -> bool {
103-
// Unlike domain instantiation, no storage value means "anyone can create contracts".
104-
ContractCreationAllowedBy::<T>::get()
105-
.map(|allowed_by| allowed_by.is_allowed(signer))
106-
.unwrap_or(true)
113+
ContractCreationAllowedBy::<T>::get().is_allowed(signer)
107114
}
108115

109116
/// Returns true if the account is allowed to create contracts.
110117
pub fn is_allowed_to_create_unsigned_contracts() -> bool {
111-
// Unlike domain instantiation, no storage value means "anyone can create contracts".
112-
ContractCreationAllowedBy::<T>::get()
113-
.map(|allowed_by| allowed_by.is_anyone_allowed())
114-
.unwrap_or(true)
118+
ContractCreationAllowedBy::<T>::get().is_anyone_allowed()
115119
}
116120

117121
/// Returns the current contract creation allow list.
118122
/// Mainly used in tests.
119-
pub fn contract_creation_allowed_by() -> Option<PermissionedActionAllowedBy<T::AccountId>> {
123+
pub fn contract_creation_allowed_by() -> PermissionedActionAllowedBy<T::AccountId> {
120124
ContractCreationAllowedBy::<T>::get()
121125
}
122126
}

domains/test/primitives/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ sp_api::decl_runtime_apis! {
4242
pub trait EvmOnchainStateApi
4343
{
4444
/// Returns the current EVM contract creation allow list.
45-
/// Returns `None` if this is not an EVM domain, or if the allow list isn't set (allow all).
45+
/// Returns `None` if this is not an EVM domain.
4646
fn evm_contract_creation_allowed_by() -> Option<PermissionedActionAllowedBy<EthereumAccountId>>;
4747
}
4848
}

domains/test/runtime/evm/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1651,7 +1651,7 @@ impl_runtime_apis! {
16511651

16521652
impl domain_test_primitives::EvmOnchainStateApi<Block> for Runtime {
16531653
fn evm_contract_creation_allowed_by() -> Option<PermissionedActionAllowedBy<EthereumAccountId>> {
1654-
EVMNoncetracker::contract_creation_allowed_by()
1654+
Some(EVMNoncetracker::contract_creation_allowed_by())
16551655
}
16561656
}
16571657

domains/test/service/src/domain.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,11 +432,12 @@ where
432432
/// Returns `None` if this is not an EVM domain, or if the allow list isn't set (allow all).
433433
pub fn evm_contract_creation_allowed_by(
434434
&self,
435-
) -> Option<PermissionedActionAllowedBy<EthereumAccountId>> {
435+
) -> PermissionedActionAllowedBy<EthereumAccountId> {
436436
self.client
437437
.runtime_api()
438438
.evm_contract_creation_allowed_by(self.client.info().best_hash)
439439
.expect("Failed to get EVM contact creation allow list")
440+
.expect("Should be an EVM domain")
440441
}
441442
}
442443

0 commit comments

Comments
 (0)