Skip to content

Commit 1b0889c

Browse files
committed
Add tests for contract allow lists
1 parent bd03483 commit 1b0889c

File tree

16 files changed

+791
-114
lines changed

16 files changed

+791
-114
lines changed

Cargo.lock

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/pallet-domains/src/domain_registry.rs

Lines changed: 199 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ mod tests {
391391
use frame_support::{assert_err, assert_ok};
392392
use hex_literal::hex;
393393
use sp_domains::storage::RawGenesis;
394-
use sp_domains::RuntimeObject;
394+
use sp_domains::{EvmDomainRuntimeConfig, PermissionedActionAllowedBy, RuntimeObject};
395395
use sp_runtime::traits::Convert;
396396
use sp_std::vec;
397397
use sp_version::RuntimeVersion;
@@ -726,4 +726,202 @@ mod tests {
726726
);
727727
});
728728
}
729+
730+
#[test]
731+
fn test_domain_instantiation_evm_contract_allow_list() {
732+
let creator = 1u128;
733+
let created_at = 0u64;
734+
// Construct a valid default domain config
735+
let mut domain_config_params = DomainConfigParams {
736+
domain_name: "evm-domain".to_owned(),
737+
runtime_id: 0,
738+
maybe_bundle_limit: None,
739+
bundle_slot_probability: (1, 1),
740+
operator_allow_list: OperatorAllowList::Anyone,
741+
initial_balances: vec![(
742+
AccountId20Converter::convert(AccountId20::from(hex!(
743+
"f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac"
744+
))),
745+
1_000_000 * SSC,
746+
)],
747+
domain_runtime_config: Default::default(),
748+
};
749+
750+
let mut ext = new_test_ext();
751+
ext.execute_with(|| {
752+
assert_eq!(NextDomainId::<Test>::get(), 0.into());
753+
// Register runtime id
754+
RuntimeRegistry::<Test>::insert(
755+
domain_config_params.runtime_id,
756+
RuntimeObject {
757+
runtime_name: "evm".to_owned(),
758+
runtime_type: Default::default(),
759+
runtime_upgrades: 0,
760+
hash: Default::default(),
761+
raw_genesis: RawGenesis::dummy(vec![1, 2, 3, 4]),
762+
version: RuntimeVersion {
763+
spec_name: "test".into(),
764+
spec_version: 1,
765+
impl_version: 1,
766+
transaction_version: 1,
767+
..Default::default()
768+
},
769+
created_at: Default::default(),
770+
updated_at: Default::default(),
771+
instance_count: 0,
772+
},
773+
);
774+
775+
// Set enough fund to creator
776+
Balances::make_free_balance_be(
777+
&creator,
778+
<Test as Config>::DomainInstantiationDeposit::get()
779+
// for domain total issuance
780+
+ 1_000_000 * SSC
781+
+ <Test as pallet_balances::Config>::ExistentialDeposit::get(),
782+
);
783+
784+
// should be successful
785+
let domain_id =
786+
do_instantiate_domain::<Test>(domain_config_params.clone(), creator, created_at)
787+
.unwrap();
788+
let domain_obj = DomainRegistry::<Test>::get(domain_id).unwrap();
789+
790+
assert_eq!(domain_obj.owner_account_id, creator);
791+
assert_eq!(domain_obj.created_at, created_at);
792+
assert_eq!(
793+
domain_obj.domain_config,
794+
into_domain_config::<Test>(domain_config_params.clone()).unwrap()
795+
);
796+
assert_eq!(
797+
domain_obj
798+
.domain_config
799+
.domain_runtime_config
800+
.initial_contract_creation_allow_list(),
801+
Some(&PermissionedActionAllowedBy::Anyone),
802+
"anyone should be allowed to create contracts by default"
803+
);
804+
805+
// Set empty list
806+
let mut list = vec![];
807+
domain_config_params.domain_runtime_config = EvmDomainRuntimeConfig {
808+
initial_contract_creation_allow_list: PermissionedActionAllowedBy::Accounts(
809+
list.clone(),
810+
),
811+
}
812+
.into();
813+
814+
// Set enough fund to creator
815+
Balances::make_free_balance_be(
816+
&creator,
817+
<Test as Config>::DomainInstantiationDeposit::get()
818+
// for domain total issuance
819+
+ 1_000_000 * SSC
820+
+ <Test as pallet_balances::Config>::ExistentialDeposit::get(),
821+
);
822+
823+
// should be successful
824+
let domain_id =
825+
do_instantiate_domain::<Test>(domain_config_params.clone(), creator, created_at)
826+
.unwrap();
827+
let domain_obj = DomainRegistry::<Test>::get(domain_id).unwrap();
828+
829+
assert_eq!(domain_obj.owner_account_id, creator);
830+
assert_eq!(domain_obj.created_at, created_at);
831+
assert_eq!(
832+
domain_obj.domain_config,
833+
into_domain_config::<Test>(domain_config_params.clone()).unwrap()
834+
);
835+
assert_eq!(
836+
domain_obj
837+
.domain_config
838+
.domain_runtime_config
839+
.initial_contract_creation_allow_list(),
840+
Some(&PermissionedActionAllowedBy::Accounts(list)),
841+
"empty list should work"
842+
);
843+
844+
// Set 1 account in list
845+
list = vec![hex!("0102030405060708091011121314151617181920").into()];
846+
domain_config_params.domain_runtime_config = EvmDomainRuntimeConfig {
847+
initial_contract_creation_allow_list: PermissionedActionAllowedBy::Accounts(
848+
list.clone(),
849+
),
850+
}
851+
.into();
852+
853+
// Set enough fund to creator
854+
Balances::make_free_balance_be(
855+
&creator,
856+
<Test as Config>::DomainInstantiationDeposit::get()
857+
// for domain total issuance
858+
+ 1_000_000 * SSC
859+
+ <Test as pallet_balances::Config>::ExistentialDeposit::get(),
860+
);
861+
862+
// should be successful
863+
let domain_id =
864+
do_instantiate_domain::<Test>(domain_config_params.clone(), creator, created_at)
865+
.unwrap();
866+
let domain_obj = DomainRegistry::<Test>::get(domain_id).unwrap();
867+
868+
assert_eq!(domain_obj.owner_account_id, creator);
869+
assert_eq!(domain_obj.created_at, created_at);
870+
assert_eq!(
871+
domain_obj.domain_config,
872+
into_domain_config::<Test>(domain_config_params.clone()).unwrap()
873+
);
874+
assert_eq!(
875+
domain_obj
876+
.domain_config
877+
.domain_runtime_config
878+
.initial_contract_creation_allow_list(),
879+
Some(&PermissionedActionAllowedBy::Accounts(list)),
880+
"1 account list should work"
881+
);
882+
883+
// Set multi account list
884+
list = vec![
885+
hex!("0102030405060708091011121314151617181920").into(),
886+
hex!("1102030405060708091011121314151617181920").into(),
887+
hex!("2102030405060708091011121314151617181920").into(),
888+
];
889+
domain_config_params.domain_runtime_config = EvmDomainRuntimeConfig {
890+
initial_contract_creation_allow_list: PermissionedActionAllowedBy::Accounts(
891+
list.clone(),
892+
),
893+
}
894+
.into();
895+
896+
// Set enough fund to creator
897+
Balances::make_free_balance_be(
898+
&creator,
899+
<Test as Config>::DomainInstantiationDeposit::get()
900+
// for domain total issuance
901+
+ 1_000_000 * SSC
902+
+ <Test as pallet_balances::Config>::ExistentialDeposit::get(),
903+
);
904+
905+
// should be successful
906+
let domain_id =
907+
do_instantiate_domain::<Test>(domain_config_params.clone(), creator, created_at)
908+
.unwrap();
909+
let domain_obj = DomainRegistry::<Test>::get(domain_id).unwrap();
910+
911+
assert_eq!(domain_obj.owner_account_id, creator);
912+
assert_eq!(domain_obj.created_at, created_at);
913+
assert_eq!(
914+
domain_obj.domain_config,
915+
into_domain_config::<Test>(domain_config_params.clone()).unwrap()
916+
);
917+
assert_eq!(
918+
domain_obj
919+
.domain_config
920+
.domain_runtime_config
921+
.initial_contract_creation_allow_list(),
922+
Some(&PermissionedActionAllowedBy::Accounts(list)),
923+
"multi account list should work"
924+
);
925+
});
926+
}
729927
}

crates/sp-domains-fraud-proof/Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,14 @@ thiserror = { version = "2.0.0", default-features = false }
4545
domain-block-preprocessor = { version = "0.1.0", path = "../../domains/client/block-preprocessor" }
4646
domain-test-service = { version = "0.1.0", path = "../../domains/test/service" }
4747
ethereum = "0.15.0"
48-
fp-rpc = { version = "3.0.0-dev", git = "https://github.com/autonomys/frontier", rev = "f80f9e2bad338f3bf3854b256b3c4edea23e5968", features = ['default'] }
49-
fp-self-contained = { version = "1.0.0-dev", git = "https://github.com/autonomys/frontier", rev = "f80f9e2bad338f3bf3854b256b3c4edea23e5968", features = ['default'] }
48+
evm-domain-test-runtime = { version = "0.1.0", path = "../../domains/test/runtime/evm" }
49+
fp-rpc = { version = "3.0.0-dev", git = "https://github.com/autonomys/frontier", rev = "f80f9e2bad338f3bf3854b256b3c4edea23e5968" }
50+
fp-self-contained = { version = "1.0.0-dev", git = "https://github.com/autonomys/frontier", rev = "f80f9e2bad338f3bf3854b256b3c4edea23e5968" }
5051
frame-system = { default-features = false, git = "https://github.com/subspace/polkadot-sdk", rev = "94a1a8143a89bbe9f938c1939ff68abc1519a305" }
5152
futures = "0.3.31"
5253
libsecp256k1 = { version = "0.7.1", features = ["static-context", "hmac"] }
5354
pallet-balances = { git = "https://github.com/subspace/polkadot-sdk", rev = "94a1a8143a89bbe9f938c1939ff68abc1519a305" }
54-
pallet-ethereum = { git = "https://github.com/autonomys/frontier", rev = "f80f9e2bad338f3bf3854b256b3c4edea23e5968", features = ['default'] }
55+
pallet-ethereum = { git = "https://github.com/autonomys/frontier", rev = "f80f9e2bad338f3bf3854b256b3c4edea23e5968" }
5556
rand = { version = "0.8.5", features = ["min_const_gen"] }
5657
rlp = "0.5.2"
5758
sp-core = { default-features = false, git = "https://github.com/subspace/polkadot-sdk", rev = "94a1a8143a89bbe9f938c1939ff68abc1519a305" }

0 commit comments

Comments
 (0)