From 39a797b731818a1171b12b209d1e77a5c464b3db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Bald=C3=A9?= Date: Fri, 1 Nov 2024 00:52:09 +0000 Subject: [PATCH 01/11] Test `kill_identity` via root origin XCM from relay --- Cargo.lock | 1 + .../people/people-polkadot/Cargo.toml | 3 + .../people/people-polkadot/src/genesis.rs | 9 +- .../people-polkadot/src/tests/governance.rs | 84 +++++++++++++++++++ 4 files changed, 96 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index ef1c6afbbb..23f5b361d5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9749,6 +9749,7 @@ dependencies = [ "parachains-common", "people-polkadot-runtime", "polkadot-emulated-chain", + "polkadot-runtime-constants", "sp-core 34.0.0", ] diff --git a/integration-tests/emulated/chains/parachains/people/people-polkadot/Cargo.toml b/integration-tests/emulated/chains/parachains/people/people-polkadot/Cargo.toml index 8649747813..6414084696 100644 --- a/integration-tests/emulated/chains/parachains/people/people-polkadot/Cargo.toml +++ b/integration-tests/emulated/chains/parachains/people/people-polkadot/Cargo.toml @@ -18,6 +18,9 @@ parachains-common = { workspace = true, default-features = true } cumulus-primitives-core = { workspace = true, default-features = true } emulated-integration-tests-common = { workspace = true } +# Runtimes +polkadot-runtime-constants = { workspace = true, default-features = true } + # Local people-polkadot-runtime = { workspace = true } polkadot-emulated-chain = { workspace = true } diff --git a/integration-tests/emulated/chains/parachains/people/people-polkadot/src/genesis.rs b/integration-tests/emulated/chains/parachains/people/people-polkadot/src/genesis.rs index 557cca546c..18d6917c2f 100644 --- a/integration-tests/emulated/chains/parachains/people/people-polkadot/src/genesis.rs +++ b/integration-tests/emulated/chains/parachains/people/people-polkadot/src/genesis.rs @@ -18,14 +18,21 @@ use sp_core::storage::Storage; // Cumulus use cumulus_primitives_core::ParaId; -use emulated_integration_tests_common::{build_genesis_storage, collators, SAFE_XCM_VERSION}; +use emulated_integration_tests_common::{ + accounts, collators, build_genesis_storage, get_account_id_from_seed, get_from_seed, get_host_config, SAFE_XCM_VERSION +}; use parachains_common::Balance; +use polkadot_runtime_constants::currency::UNITS as DOT; +const ENDOWMENT: u128 = 1_000 * DOT; pub const PARA_ID: u32 = 1004; pub const ED: Balance = people_polkadot_runtime::ExistentialDeposit::get(); pub fn genesis() -> Storage { let genesis_config = people_polkadot_runtime::RuntimeGenesisConfig { + balances: people_polkadot_runtime::BalancesConfig { + balances: accounts::init_balances().iter().cloned().map(|k| (k, ENDOWMENT)).collect(), + }, system: people_polkadot_runtime::SystemConfig::default(), parachain_info: people_polkadot_runtime::ParachainInfoConfig { parachain_id: ParaId::from(PARA_ID), diff --git a/integration-tests/emulated/tests/people/people-polkadot/src/tests/governance.rs b/integration-tests/emulated/tests/people/people-polkadot/src/tests/governance.rs index 11ebf954a3..43f8569461 100644 --- a/integration-tests/emulated/tests/people/people-polkadot/src/tests/governance.rs +++ b/integration-tests/emulated/tests/people/people-polkadot/src/tests/governance.rs @@ -14,8 +14,13 @@ // limitations under the License. use crate::*; +use emulated_integration_tests_common::accounts::ALICE; + use frame_support::sp_runtime::traits::Dispatchable; use polkadot_runtime::governance::pallet_custom_origins::Origin::GeneralAdmin as GeneralAdminOrigin; +use people_polkadot_runtime::people::IdentityInfo; + +use pallet_identity::Data; #[test] fn relay_commands_add_registrar() { @@ -72,3 +77,82 @@ fn relay_commands_add_registrar() { }); } } + +#[test] +fn relay_commands_kill_identity() { + + // To kill an identity, first one must be set + PeoplePolkadot::execute_with(|| { + type PeopleRuntime = ::Runtime; + type PeopleRuntimeEvent = ::RuntimeEvent; + + let people_polkadot_bob = ::RuntimeOrigin::signed(PeoplePolkadot::account_id_of(ALICE)); + + let mut identity_info = ::default(); + identity_info.email = Data::Raw(b"test@test.io".to_vec().try_into().unwrap()); + let identity: Box<::IdentityInformation> = Box::new(identity_info); + + assert_ok!(::Identity::set_identity( + people_polkadot_bob, + identity + )); + + //assert_ok!(add_identity_call.dispatch(people_polkadot_bob)); + + assert_expected_events!( + PeoplePolkadot, + vec![ + PeopleRuntimeEvent::Identity(pallet_identity::Event::IdentitySet { .. }) => {}, + ] + ); + }); + + let (origin_kind, origin) = + (OriginKind::Superuser, ::RuntimeOrigin::root()); + + Polkadot::execute_with(|| { + type Runtime = ::Runtime; + type RuntimeCall = ::RuntimeCall; + type PeopleCall = ::RuntimeCall; + type RuntimeEvent = ::RuntimeEvent; + type PeopleRuntime = ::Runtime; + + let kill_identity_call = + PeopleCall::Identity(pallet_identity::Call::::kill_identity { + target: people_polkadot_runtime::MultiAddress::Id(PeoplePolkadot::account_id_of(ALICE)), + }); + + let xcm_message = RuntimeCall::XcmPallet(pallet_xcm::Call::::send { + dest: bx!(VersionedLocation::from(Location::new(0, [Parachain(1004)]))), + message: bx!(VersionedXcm::from(Xcm(vec![ + UnpaidExecution { weight_limit: Unlimited, check_origin: None }, + Transact { + origin_kind, + require_weight_at_most: Weight::from_parts(5_000_000_000, 500_000), + call: kill_identity_call.encode().into(), + } + ]))), + }); + + assert_ok!(xcm_message.dispatch(origin)); + + assert_expected_events!( + Polkadot, + vec![ + RuntimeEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {}, + ] + ); + }); + + PeoplePolkadot::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + + assert_expected_events!( + PeoplePolkadot, + vec![ + RuntimeEvent::Identity(pallet_identity::Event::IdentityKilled { .. }) => {}, + RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { success: true, .. }) => {}, + ] + ); + }); +} From 79a501694b92826c16f38189cf72fbbb00658023 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Bald=C3=A9?= Date: Fri, 1 Nov 2024 01:17:11 +0000 Subject: [PATCH 02/11] Test root XCM to add a username authority --- .../people-polkadot/src/tests/governance.rs | 62 ++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/integration-tests/emulated/tests/people/people-polkadot/src/tests/governance.rs b/integration-tests/emulated/tests/people/people-polkadot/src/tests/governance.rs index 43f8569461..5e40ed403f 100644 --- a/integration-tests/emulated/tests/people/people-polkadot/src/tests/governance.rs +++ b/integration-tests/emulated/tests/people/people-polkadot/src/tests/governance.rs @@ -128,7 +128,10 @@ fn relay_commands_kill_identity() { UnpaidExecution { weight_limit: Unlimited, check_origin: None }, Transact { origin_kind, - require_weight_at_most: Weight::from_parts(5_000_000_000, 500_000), + // Making the weight's ref time any lower will prevent the XCM from triggering + // execution of the intended extrinsic on the People chain - beware of spurious + // test failure due to this. + require_weight_at_most: Weight::from_parts(12_000_000_000, 500_000), call: kill_identity_call.encode().into(), } ]))), @@ -156,3 +159,60 @@ fn relay_commands_kill_identity() { ); }); } + +#[test] +fn relay_commands_add_username_authority() { + let origins = vec![ + (OriginKind::Xcm, GeneralAdminOrigin.into()), + (OriginKind::Superuser, ::RuntimeOrigin::root()), + ]; + for (origin_kind, origin) in origins { + Polkadot::execute_with(|| { + type Runtime = ::Runtime; + type RuntimeCall = ::RuntimeCall; + type RuntimeEvent = ::RuntimeEvent; + type PeopleCall = ::RuntimeCall; + type PeopleRuntime = ::Runtime; + + let add_username_authority = + PeopleCall::Identity(pallet_identity::Call::::add_username_authority { + authority: people_polkadot_runtime::MultiAddress::Id(PeoplePolkadot::account_id_of(ALICE)), + suffix: b"suffix".into(), + allocation: 10 + }); + + let xcm_message = RuntimeCall::XcmPallet(pallet_xcm::Call::::send { + dest: bx!(VersionedLocation::from(Location::new(0, [Parachain(1004)]))), + message: bx!(VersionedXcm::from(Xcm(vec![ + UnpaidExecution { weight_limit: Unlimited, check_origin: None }, + Transact { + origin_kind, + require_weight_at_most: Weight::from_parts(1_000_000_000, 500_000), + call: add_username_authority.encode().into(), + } + ]))), + }); + + assert_ok!(xcm_message.dispatch(origin)); + + assert_expected_events!( + Polkadot, + vec![ + RuntimeEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {}, + ] + ); + }); + + PeoplePolkadot::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + + assert_expected_events!( + PeoplePolkadot, + vec![ + RuntimeEvent::Identity(pallet_identity::Event::AuthorityAdded { .. }) => {}, + RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { success: true, .. }) => {}, + ] + ); + }); + } +} \ No newline at end of file From a74c88f6e66a1e546bc16cdc1b1207d16a379a5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Bald=C3=A9?= Date: Mon, 4 Nov 2024 12:16:03 +0000 Subject: [PATCH 03/11] Complete username authority test for Polkadot --- .../people/people-polkadot/src/genesis.rs | 2 +- .../people-polkadot/src/tests/governance.rs | 126 +++++++++++++++--- 2 files changed, 110 insertions(+), 18 deletions(-) diff --git a/integration-tests/emulated/chains/parachains/people/people-polkadot/src/genesis.rs b/integration-tests/emulated/chains/parachains/people/people-polkadot/src/genesis.rs index 18d6917c2f..284d96541a 100644 --- a/integration-tests/emulated/chains/parachains/people/people-polkadot/src/genesis.rs +++ b/integration-tests/emulated/chains/parachains/people/people-polkadot/src/genesis.rs @@ -19,7 +19,7 @@ use sp_core::storage::Storage; // Cumulus use cumulus_primitives_core::ParaId; use emulated_integration_tests_common::{ - accounts, collators, build_genesis_storage, get_account_id_from_seed, get_from_seed, get_host_config, SAFE_XCM_VERSION + accounts, collators, build_genesis_storage, SAFE_XCM_VERSION }; use parachains_common::Balance; use polkadot_runtime_constants::currency::UNITS as DOT; diff --git a/integration-tests/emulated/tests/people/people-polkadot/src/tests/governance.rs b/integration-tests/emulated/tests/people/people-polkadot/src/tests/governance.rs index 5e40ed403f..777ce94365 100644 --- a/integration-tests/emulated/tests/people/people-polkadot/src/tests/governance.rs +++ b/integration-tests/emulated/tests/people/people-polkadot/src/tests/governance.rs @@ -14,7 +14,7 @@ // limitations under the License. use crate::*; -use emulated_integration_tests_common::accounts::ALICE; +use emulated_integration_tests_common::accounts::{ALICE, BOB}; use frame_support::sp_runtime::traits::Dispatchable; use polkadot_runtime::governance::pallet_custom_origins::Origin::GeneralAdmin as GeneralAdminOrigin; @@ -80,25 +80,23 @@ fn relay_commands_add_registrar() { #[test] fn relay_commands_kill_identity() { - // To kill an identity, first one must be set PeoplePolkadot::execute_with(|| { type PeopleRuntime = ::Runtime; type PeopleRuntimeEvent = ::RuntimeEvent; - let people_polkadot_bob = ::RuntimeOrigin::signed(PeoplePolkadot::account_id_of(ALICE)); + let people_polkadot_alice = ::RuntimeOrigin::signed(PeoplePolkadot::account_id_of(ALICE)); let mut identity_info = ::default(); identity_info.email = Data::Raw(b"test@test.io".to_vec().try_into().unwrap()); let identity: Box<::IdentityInformation> = Box::new(identity_info); - assert_ok!(::Identity::set_identity( - people_polkadot_bob, + assert_ok!( + ::Identity::set_identity( + people_polkadot_alice, identity )); - //assert_ok!(add_identity_call.dispatch(people_polkadot_bob)); - assert_expected_events!( PeoplePolkadot, vec![ @@ -131,7 +129,7 @@ fn relay_commands_kill_identity() { // Making the weight's ref time any lower will prevent the XCM from triggering // execution of the intended extrinsic on the People chain - beware of spurious // test failure due to this. - require_weight_at_most: Weight::from_parts(12_000_000_000, 500_000), + require_weight_at_most: Weight::from_parts(11_000_000_000, 500_000), call: kill_identity_call.encode().into(), } ]))), @@ -161,12 +159,17 @@ fn relay_commands_kill_identity() { } #[test] -fn relay_commands_add_username_authority() { +fn relay_commands_add_remove_username_authority() { + let people_polkadot_alice = PeoplePolkadot::account_id_of(ALICE); + let people_polkadot_bob = PeoplePolkadot::account_id_of(BOB); + + let origins = vec![ - (OriginKind::Xcm, GeneralAdminOrigin.into()), - (OriginKind::Superuser, ::RuntimeOrigin::root()), + (OriginKind::Xcm, GeneralAdminOrigin.into(), "generaladmin"), + (OriginKind::Superuser, ::RuntimeOrigin::root(), "rootusername"), ]; - for (origin_kind, origin) in origins { + for (origin_kind, origin, usr) in origins { + // First, add a username authority. Polkadot::execute_with(|| { type Runtime = ::Runtime; type RuntimeCall = ::RuntimeCall; @@ -176,24 +179,24 @@ fn relay_commands_add_username_authority() { let add_username_authority = PeopleCall::Identity(pallet_identity::Call::::add_username_authority { - authority: people_polkadot_runtime::MultiAddress::Id(PeoplePolkadot::account_id_of(ALICE)), - suffix: b"suffix".into(), + authority: people_polkadot_runtime::MultiAddress::Id(people_polkadot_alice.clone()), + suffix: b"suffix1".into(), allocation: 10 }); - let xcm_message = RuntimeCall::XcmPallet(pallet_xcm::Call::::send { + let add_authority_xcm_msg = RuntimeCall::XcmPallet(pallet_xcm::Call::::send { dest: bx!(VersionedLocation::from(Location::new(0, [Parachain(1004)]))), message: bx!(VersionedXcm::from(Xcm(vec![ UnpaidExecution { weight_limit: Unlimited, check_origin: None }, Transact { origin_kind, - require_weight_at_most: Weight::from_parts(1_000_000_000, 500_000), + require_weight_at_most: Weight::from_parts(500_000_000, 500_000), call: add_username_authority.encode().into(), } ]))), }); - assert_ok!(xcm_message.dispatch(origin)); + assert_ok!(add_authority_xcm_msg.dispatch(origin.clone())); assert_expected_events!( Polkadot, @@ -203,6 +206,7 @@ fn relay_commands_add_username_authority() { ); }); + // Check events system-parachain-side PeoplePolkadot::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; @@ -214,5 +218,93 @@ fn relay_commands_add_username_authority() { ] ); }); + + // Now, use the previously added username authority to concede a username to an account. + PeoplePolkadot::execute_with(|| { + type PeopleRuntimeEvent = ::RuntimeEvent; + + assert_ok!( + ::Identity::set_username_for( + ::RuntimeOrigin::signed(people_polkadot_alice.clone()), + people_polkadot_runtime::MultiAddress::Id(people_polkadot_bob.clone()), + usr.to_owned().into_bytes().try_into().unwrap(), + None, + )); + + assert_expected_events!( + PeoplePolkadot, + vec![ + PeopleRuntimeEvent::Identity(pallet_identity::Event::UsernameQueued { .. }) => {}, + ] + ); + }); + + // Accept the given username + PeoplePolkadot::execute_with(|| { + type PeopleRuntimeEvent = ::RuntimeEvent; + let full_username = [usr.to_owned(), ".suffix1".to_owned()].concat().into_bytes(); + + assert_ok!( + ::Identity::accept_username( + ::RuntimeOrigin::signed(people_polkadot_bob.clone()), + full_username.try_into().unwrap(), + )); + + assert_expected_events!( + PeoplePolkadot, + vec![ + PeopleRuntimeEvent::Identity(pallet_identity::Event::UsernameSet { .. }) => {}, + ] + ); + }); + + // Now, remove the username authority with another priviledged XCM call. + Polkadot::execute_with(|| { + type Runtime = ::Runtime; + type RuntimeCall = ::RuntimeCall; + type RuntimeEvent = ::RuntimeEvent; + type PeopleCall = ::RuntimeCall; + type PeopleRuntime = ::Runtime; + + let remove_username_authority = + PeopleCall::Identity(pallet_identity::Call::::remove_username_authority { + authority: people_polkadot_runtime::MultiAddress::Id(people_polkadot_alice.clone()), + }); + + let remove_authority_xcm_msg = RuntimeCall::XcmPallet(pallet_xcm::Call::::send { + dest: bx!(VersionedLocation::from(Location::new(0, [Parachain(1004)]))), + message: bx!(VersionedXcm::from(Xcm(vec![ + UnpaidExecution { weight_limit: Unlimited, check_origin: None }, + Transact { + origin_kind, + require_weight_at_most: Weight::from_parts(500_000_000, 500_000), + call: remove_username_authority.encode().into(), + } + ]))), + }); + + assert_ok!(remove_authority_xcm_msg.dispatch(origin)); + + assert_expected_events!( + Polkadot, + vec![ + RuntimeEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {}, + ] + ); + }); + + // Final event check. + PeoplePolkadot::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + + assert_expected_events!( + PeoplePolkadot, + vec![ + RuntimeEvent::Identity(pallet_identity::Event::AuthorityRemoved { .. }) => {}, + RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { success: true, .. }) => {}, + ] + ); + }); + } } \ No newline at end of file From 1325e59db5b0f30ef57e25c140b73b9f601f9380 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Bald=C3=A9?= Date: Mon, 4 Nov 2024 13:37:41 +0000 Subject: [PATCH 04/11] Replicate XCM integration tests in Kusama --- Cargo.lock | 1 + .../people/people-kusama/Cargo.toml | 3 + .../people/people-kusama/src/genesis.rs | 9 +- .../people/people-polkadot/src/genesis.rs | 2 +- .../people-kusama/src/tests/governance.rs | 236 ++++++++++++++++++ 5 files changed, 249 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 23f5b361d5..124a64c2f5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9639,6 +9639,7 @@ dependencies = [ "emulated-integration-tests-common", "frame-support", "kusama-emulated-chain", + "kusama-runtime-constants", "parachains-common", "people-kusama-runtime", "sp-core 34.0.0", diff --git a/integration-tests/emulated/chains/parachains/people/people-kusama/Cargo.toml b/integration-tests/emulated/chains/parachains/people/people-kusama/Cargo.toml index a72f24e626..f6bb6403ee 100644 --- a/integration-tests/emulated/chains/parachains/people/people-kusama/Cargo.toml +++ b/integration-tests/emulated/chains/parachains/people/people-kusama/Cargo.toml @@ -18,6 +18,9 @@ parachains-common = { workspace = true, default-features = true } cumulus-primitives-core = { workspace = true, default-features = true } emulated-integration-tests-common = { workspace = true } +# Runtimes +kusama-runtime-constants = { workspace = true, default-features = true } + # Local people-kusama-runtime = { workspace = true } kusama-emulated-chain = { workspace = true } diff --git a/integration-tests/emulated/chains/parachains/people/people-kusama/src/genesis.rs b/integration-tests/emulated/chains/parachains/people/people-kusama/src/genesis.rs index 53c336d662..73cb416993 100644 --- a/integration-tests/emulated/chains/parachains/people/people-kusama/src/genesis.rs +++ b/integration-tests/emulated/chains/parachains/people/people-kusama/src/genesis.rs @@ -18,14 +18,21 @@ use sp_core::storage::Storage; // Cumulus use cumulus_primitives_core::ParaId; -use emulated_integration_tests_common::{build_genesis_storage, collators, SAFE_XCM_VERSION}; +use emulated_integration_tests_common::{ + accounts, build_genesis_storage, collators, SAFE_XCM_VERSION +}; use parachains_common::Balance; +use kusama_runtime_constants::currency::UNITS as KSM; +const ENDOWMENT: u128 = 1_000 * KSM; pub const PARA_ID: u32 = 1004; pub const ED: Balance = people_kusama_runtime::ExistentialDeposit::get(); pub fn genesis() -> Storage { let genesis_config = people_kusama_runtime::RuntimeGenesisConfig { + balances: people_kusama_runtime::BalancesConfig { + balances: accounts::init_balances().iter().cloned().map(|k| (k, ENDOWMENT)).collect(), + }, system: people_kusama_runtime::SystemConfig::default(), parachain_info: people_kusama_runtime::ParachainInfoConfig { parachain_id: ParaId::from(PARA_ID), diff --git a/integration-tests/emulated/chains/parachains/people/people-polkadot/src/genesis.rs b/integration-tests/emulated/chains/parachains/people/people-polkadot/src/genesis.rs index 284d96541a..8d648ce854 100644 --- a/integration-tests/emulated/chains/parachains/people/people-polkadot/src/genesis.rs +++ b/integration-tests/emulated/chains/parachains/people/people-polkadot/src/genesis.rs @@ -19,7 +19,7 @@ use sp_core::storage::Storage; // Cumulus use cumulus_primitives_core::ParaId; use emulated_integration_tests_common::{ - accounts, collators, build_genesis_storage, SAFE_XCM_VERSION + accounts, build_genesis_storage, collators, SAFE_XCM_VERSION }; use parachains_common::Balance; use polkadot_runtime_constants::currency::UNITS as DOT; diff --git a/integration-tests/emulated/tests/people/people-kusama/src/tests/governance.rs b/integration-tests/emulated/tests/people/people-kusama/src/tests/governance.rs index 8d06089947..65b3f9ae0c 100644 --- a/integration-tests/emulated/tests/people/people-kusama/src/tests/governance.rs +++ b/integration-tests/emulated/tests/people/people-kusama/src/tests/governance.rs @@ -14,8 +14,13 @@ // limitations under the License. use crate::*; +use emulated_integration_tests_common::accounts::{ALICE, BOB}; + use frame_support::sp_runtime::traits::Dispatchable; use kusama_runtime::governance::pallet_custom_origins::Origin::GeneralAdmin as GeneralAdminOrigin; +use people_kusama_runtime::people::IdentityInfo; + +use pallet_identity::Data; #[test] fn relay_commands_add_registrar() { @@ -72,3 +77,234 @@ fn relay_commands_add_registrar() { }); } } + +#[test] +fn relay_commands_kill_identity() { + // To kill an identity, first one must be set + PeopleKusama::execute_with(|| { + type PeopleRuntime = ::Runtime; + type PeopleRuntimeEvent = ::RuntimeEvent; + + let people_kusama_alice = ::RuntimeOrigin::signed(PeopleKusama::account_id_of(ALICE)); + + let mut identity_info = ::default(); + identity_info.email = Data::Raw(b"test@test.io".to_vec().try_into().unwrap()); + let identity: Box<::IdentityInformation> = Box::new(identity_info); + + assert_ok!( + ::Identity::set_identity( + people_kusama_alice, + identity + )); + + assert_expected_events!( + PeopleKusama, + vec![ + PeopleRuntimeEvent::Identity(pallet_identity::Event::IdentitySet { .. }) => {}, + ] + ); + }); + + let (origin_kind, origin) = + (OriginKind::Superuser, ::RuntimeOrigin::root()); + + Kusama::execute_with(|| { + type Runtime = ::Runtime; + type RuntimeCall = ::RuntimeCall; + type PeopleCall = ::RuntimeCall; + type RuntimeEvent = ::RuntimeEvent; + type PeopleRuntime = ::Runtime; + + let kill_identity_call = + PeopleCall::Identity(pallet_identity::Call::::kill_identity { + target: people_kusama_runtime::MultiAddress::Id(PeopleKusama::account_id_of(ALICE)), + }); + + let xcm_message = RuntimeCall::XcmPallet(pallet_xcm::Call::::send { + dest: bx!(VersionedLocation::from(Location::new(0, [Parachain(1004)]))), + message: bx!(VersionedXcm::from(Xcm(vec![ + UnpaidExecution { weight_limit: Unlimited, check_origin: None }, + Transact { + origin_kind, + // Making the weight's ref time any lower will prevent the XCM from triggering + // execution of the intended extrinsic on the People chain - beware of spurious + // test failure due to this. + require_weight_at_most: Weight::from_parts(11_000_000_000, 500_000), + call: kill_identity_call.encode().into(), + } + ]))), + }); + + assert_ok!(xcm_message.dispatch(origin)); + + assert_expected_events!( + Kusama, + vec![ + RuntimeEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {}, + ] + ); + }); + + PeopleKusama::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + + assert_expected_events!( + PeopleKusama, + vec![ + RuntimeEvent::Identity(pallet_identity::Event::IdentityKilled { .. }) => {}, + RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { success: true, .. }) => {}, + ] + ); + }); +} + +#[test] +fn relay_commands_add_remove_username_authority() { + let people_kusama_alice = PeopleKusama::account_id_of(ALICE); + let people_kusama_bob = PeopleKusama::account_id_of(BOB); + + + let origins = vec![ + (OriginKind::Xcm, GeneralAdminOrigin.into(), "generaladmin"), + (OriginKind::Superuser, ::RuntimeOrigin::root(), "rootusername"), + ]; + for (origin_kind, origin, usr) in origins { + // First, add a username authority. + Kusama::execute_with(|| { + type Runtime = ::Runtime; + type RuntimeCall = ::RuntimeCall; + type RuntimeEvent = ::RuntimeEvent; + type PeopleCall = ::RuntimeCall; + type PeopleRuntime = ::Runtime; + + let add_username_authority = + PeopleCall::Identity(pallet_identity::Call::::add_username_authority { + authority: people_kusama_runtime::MultiAddress::Id(people_kusama_alice.clone()), + suffix: b"suffix1".into(), + allocation: 10 + }); + + let add_authority_xcm_msg = RuntimeCall::XcmPallet(pallet_xcm::Call::::send { + dest: bx!(VersionedLocation::from(Location::new(0, [Parachain(1004)]))), + message: bx!(VersionedXcm::from(Xcm(vec![ + UnpaidExecution { weight_limit: Unlimited, check_origin: None }, + Transact { + origin_kind, + require_weight_at_most: Weight::from_parts(500_000_000, 500_000), + call: add_username_authority.encode().into(), + } + ]))), + }); + + assert_ok!(add_authority_xcm_msg.dispatch(origin.clone())); + + assert_expected_events!( + Kusama, + vec![ + RuntimeEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {}, + ] + ); + }); + + // Check events system-parachain-side + PeopleKusama::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + + assert_expected_events!( + PeopleKusama, + vec![ + RuntimeEvent::Identity(pallet_identity::Event::AuthorityAdded { .. }) => {}, + RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { success: true, .. }) => {}, + ] + ); + }); + + // Now, use the previously added username authority to concede a username to an account. + PeopleKusama::execute_with(|| { + type PeopleRuntimeEvent = ::RuntimeEvent; + + assert_ok!( + ::Identity::set_username_for( + ::RuntimeOrigin::signed(people_kusama_alice.clone()), + people_kusama_runtime::MultiAddress::Id(people_kusama_bob.clone()), + usr.to_owned().into_bytes().try_into().unwrap(), + None, + )); + + assert_expected_events!( + PeopleKusama, + vec![ + PeopleRuntimeEvent::Identity(pallet_identity::Event::UsernameQueued { .. }) => {}, + ] + ); + }); + + // Accept the given username + PeopleKusama::execute_with(|| { + type PeopleRuntimeEvent = ::RuntimeEvent; + let full_username = [usr.to_owned(), ".suffix1".to_owned()].concat().into_bytes(); + + assert_ok!( + ::Identity::accept_username( + ::RuntimeOrigin::signed(people_kusama_bob.clone()), + full_username.try_into().unwrap(), + )); + + assert_expected_events!( + PeopleKusama, + vec![ + PeopleRuntimeEvent::Identity(pallet_identity::Event::UsernameSet { .. }) => {}, + ] + ); + }); + + // Now, remove the username authority with another priviledged XCM call. + Kusama::execute_with(|| { + type Runtime = ::Runtime; + type RuntimeCall = ::RuntimeCall; + type RuntimeEvent = ::RuntimeEvent; + type PeopleCall = ::RuntimeCall; + type PeopleRuntime = ::Runtime; + + let remove_username_authority = + PeopleCall::Identity(pallet_identity::Call::::remove_username_authority { + authority: people_kusama_runtime::MultiAddress::Id(people_kusama_alice.clone()), + }); + + let remove_authority_xcm_msg = RuntimeCall::XcmPallet(pallet_xcm::Call::::send { + dest: bx!(VersionedLocation::from(Location::new(0, [Parachain(1004)]))), + message: bx!(VersionedXcm::from(Xcm(vec![ + UnpaidExecution { weight_limit: Unlimited, check_origin: None }, + Transact { + origin_kind, + require_weight_at_most: Weight::from_parts(500_000_000, 500_000), + call: remove_username_authority.encode().into(), + } + ]))), + }); + + assert_ok!(remove_authority_xcm_msg.dispatch(origin)); + + assert_expected_events!( + Kusama, + vec![ + RuntimeEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {}, + ] + ); + }); + + // Final event check. + PeopleKusama::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + + assert_expected_events!( + PeopleKusama, + vec![ + RuntimeEvent::Identity(pallet_identity::Event::AuthorityRemoved { .. }) => {}, + RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { success: true, .. }) => {}, + ] + ); + }); + + } +} \ No newline at end of file From 4752d1c53645a3ea9e8c91412b6695f952dfdaba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Bald=C3=A9?= Date: Mon, 4 Nov 2024 15:58:06 +0000 Subject: [PATCH 05/11] Apply `cargo fmt` --- .../people/people-kusama/src/genesis.rs | 4 +- .../people/people-polkadot/src/genesis.rs | 2 +- .../people-kusama/src/tests/governance.rs | 83 +++++++++-------- .../people-polkadot/src/tests/governance.rs | 89 ++++++++++--------- 4 files changed, 89 insertions(+), 89 deletions(-) diff --git a/integration-tests/emulated/chains/parachains/people/people-kusama/src/genesis.rs b/integration-tests/emulated/chains/parachains/people/people-kusama/src/genesis.rs index 73cb416993..3afd77c956 100644 --- a/integration-tests/emulated/chains/parachains/people/people-kusama/src/genesis.rs +++ b/integration-tests/emulated/chains/parachains/people/people-kusama/src/genesis.rs @@ -19,10 +19,10 @@ use sp_core::storage::Storage; // Cumulus use cumulus_primitives_core::ParaId; use emulated_integration_tests_common::{ - accounts, build_genesis_storage, collators, SAFE_XCM_VERSION + accounts, build_genesis_storage, collators, SAFE_XCM_VERSION, }; -use parachains_common::Balance; use kusama_runtime_constants::currency::UNITS as KSM; +use parachains_common::Balance; const ENDOWMENT: u128 = 1_000 * KSM; pub const PARA_ID: u32 = 1004; diff --git a/integration-tests/emulated/chains/parachains/people/people-polkadot/src/genesis.rs b/integration-tests/emulated/chains/parachains/people/people-polkadot/src/genesis.rs index 8d648ce854..9d63344e2b 100644 --- a/integration-tests/emulated/chains/parachains/people/people-polkadot/src/genesis.rs +++ b/integration-tests/emulated/chains/parachains/people/people-polkadot/src/genesis.rs @@ -19,7 +19,7 @@ use sp_core::storage::Storage; // Cumulus use cumulus_primitives_core::ParaId; use emulated_integration_tests_common::{ - accounts, build_genesis_storage, collators, SAFE_XCM_VERSION + accounts, build_genesis_storage, collators, SAFE_XCM_VERSION, }; use parachains_common::Balance; use polkadot_runtime_constants::currency::UNITS as DOT; diff --git a/integration-tests/emulated/tests/people/people-kusama/src/tests/governance.rs b/integration-tests/emulated/tests/people/people-kusama/src/tests/governance.rs index 65b3f9ae0c..00c244d48d 100644 --- a/integration-tests/emulated/tests/people/people-kusama/src/tests/governance.rs +++ b/integration-tests/emulated/tests/people/people-kusama/src/tests/governance.rs @@ -85,16 +85,17 @@ fn relay_commands_kill_identity() { type PeopleRuntime = ::Runtime; type PeopleRuntimeEvent = ::RuntimeEvent; - let people_kusama_alice = ::RuntimeOrigin::signed(PeopleKusama::account_id_of(ALICE)); + let people_kusama_alice = + ::RuntimeOrigin::signed(PeopleKusama::account_id_of(ALICE)); let mut identity_info = ::default(); identity_info.email = Data::Raw(b"test@test.io".to_vec().try_into().unwrap()); - let identity: Box<::IdentityInformation> = Box::new(identity_info); + let identity: Box<::IdentityInformation> = + Box::new(identity_info); - assert_ok!( - ::Identity::set_identity( - people_kusama_alice, - identity + assert_ok!(::Identity::set_identity( + people_kusama_alice, + identity )); assert_expected_events!( @@ -105,8 +106,7 @@ fn relay_commands_kill_identity() { ); }); - let (origin_kind, origin) = - (OriginKind::Superuser, ::RuntimeOrigin::root()); + let (origin_kind, origin) = (OriginKind::Superuser, ::RuntimeOrigin::root()); Kusama::execute_with(|| { type Runtime = ::Runtime; @@ -163,7 +163,6 @@ fn relay_commands_add_remove_username_authority() { let people_kusama_alice = PeopleKusama::account_id_of(ALICE); let people_kusama_bob = PeopleKusama::account_id_of(BOB); - let origins = vec![ (OriginKind::Xcm, GeneralAdminOrigin.into(), "generaladmin"), (OriginKind::Superuser, ::RuntimeOrigin::root(), "rootusername"), @@ -177,12 +176,13 @@ fn relay_commands_add_remove_username_authority() { type PeopleCall = ::RuntimeCall; type PeopleRuntime = ::Runtime; - let add_username_authority = - PeopleCall::Identity(pallet_identity::Call::::add_username_authority { - authority: people_kusama_runtime::MultiAddress::Id(people_kusama_alice.clone()), - suffix: b"suffix1".into(), - allocation: 10 - }); + let add_username_authority = PeopleCall::Identity(pallet_identity::Call::< + PeopleRuntime, + >::add_username_authority { + authority: people_kusama_runtime::MultiAddress::Id(people_kusama_alice.clone()), + suffix: b"suffix1".into(), + allocation: 10, + }); let add_authority_xcm_msg = RuntimeCall::XcmPallet(pallet_xcm::Call::::send { dest: bx!(VersionedLocation::from(Location::new(0, [Parachain(1004)]))), @@ -223,12 +223,11 @@ fn relay_commands_add_remove_username_authority() { PeopleKusama::execute_with(|| { type PeopleRuntimeEvent = ::RuntimeEvent; - assert_ok!( - ::Identity::set_username_for( - ::RuntimeOrigin::signed(people_kusama_alice.clone()), - people_kusama_runtime::MultiAddress::Id(people_kusama_bob.clone()), - usr.to_owned().into_bytes().try_into().unwrap(), - None, + assert_ok!(::Identity::set_username_for( + ::RuntimeOrigin::signed(people_kusama_alice.clone()), + people_kusama_runtime::MultiAddress::Id(people_kusama_bob.clone()), + usr.to_owned().into_bytes().try_into().unwrap(), + None, )); assert_expected_events!( @@ -244,10 +243,9 @@ fn relay_commands_add_remove_username_authority() { type PeopleRuntimeEvent = ::RuntimeEvent; let full_username = [usr.to_owned(), ".suffix1".to_owned()].concat().into_bytes(); - assert_ok!( - ::Identity::accept_username( - ::RuntimeOrigin::signed(people_kusama_bob.clone()), - full_username.try_into().unwrap(), + assert_ok!(::Identity::accept_username( + ::RuntimeOrigin::signed(people_kusama_bob.clone()), + full_username.try_into().unwrap(), )); assert_expected_events!( @@ -266,23 +264,25 @@ fn relay_commands_add_remove_username_authority() { type PeopleCall = ::RuntimeCall; type PeopleRuntime = ::Runtime; - let remove_username_authority = - PeopleCall::Identity(pallet_identity::Call::::remove_username_authority { - authority: people_kusama_runtime::MultiAddress::Id(people_kusama_alice.clone()), - }); - - let remove_authority_xcm_msg = RuntimeCall::XcmPallet(pallet_xcm::Call::::send { - dest: bx!(VersionedLocation::from(Location::new(0, [Parachain(1004)]))), - message: bx!(VersionedXcm::from(Xcm(vec![ - UnpaidExecution { weight_limit: Unlimited, check_origin: None }, - Transact { - origin_kind, - require_weight_at_most: Weight::from_parts(500_000_000, 500_000), - call: remove_username_authority.encode().into(), - } - ]))), + let remove_username_authority = PeopleCall::Identity(pallet_identity::Call::< + PeopleRuntime, + >::remove_username_authority { + authority: people_kusama_runtime::MultiAddress::Id(people_kusama_alice.clone()), }); + let remove_authority_xcm_msg = + RuntimeCall::XcmPallet(pallet_xcm::Call::::send { + dest: bx!(VersionedLocation::from(Location::new(0, [Parachain(1004)]))), + message: bx!(VersionedXcm::from(Xcm(vec![ + UnpaidExecution { weight_limit: Unlimited, check_origin: None }, + Transact { + origin_kind, + require_weight_at_most: Weight::from_parts(500_000_000, 500_000), + call: remove_username_authority.encode().into(), + } + ]))), + }); + assert_ok!(remove_authority_xcm_msg.dispatch(origin)); assert_expected_events!( @@ -305,6 +305,5 @@ fn relay_commands_add_remove_username_authority() { ] ); }); - } -} \ No newline at end of file +} diff --git a/integration-tests/emulated/tests/people/people-polkadot/src/tests/governance.rs b/integration-tests/emulated/tests/people/people-polkadot/src/tests/governance.rs index 777ce94365..a6edf4a015 100644 --- a/integration-tests/emulated/tests/people/people-polkadot/src/tests/governance.rs +++ b/integration-tests/emulated/tests/people/people-polkadot/src/tests/governance.rs @@ -17,8 +17,8 @@ use crate::*; use emulated_integration_tests_common::accounts::{ALICE, BOB}; use frame_support::sp_runtime::traits::Dispatchable; -use polkadot_runtime::governance::pallet_custom_origins::Origin::GeneralAdmin as GeneralAdminOrigin; use people_polkadot_runtime::people::IdentityInfo; +use polkadot_runtime::governance::pallet_custom_origins::Origin::GeneralAdmin as GeneralAdminOrigin; use pallet_identity::Data; @@ -85,16 +85,17 @@ fn relay_commands_kill_identity() { type PeopleRuntime = ::Runtime; type PeopleRuntimeEvent = ::RuntimeEvent; - let people_polkadot_alice = ::RuntimeOrigin::signed(PeoplePolkadot::account_id_of(ALICE)); + let people_polkadot_alice = + ::RuntimeOrigin::signed(PeoplePolkadot::account_id_of(ALICE)); let mut identity_info = ::default(); identity_info.email = Data::Raw(b"test@test.io".to_vec().try_into().unwrap()); - let identity: Box<::IdentityInformation> = Box::new(identity_info); + let identity: Box<::IdentityInformation> = + Box::new(identity_info); - assert_ok!( - ::Identity::set_identity( - people_polkadot_alice, - identity + assert_ok!(::Identity::set_identity( + people_polkadot_alice, + identity )); assert_expected_events!( @@ -105,8 +106,7 @@ fn relay_commands_kill_identity() { ); }); - let (origin_kind, origin) = - (OriginKind::Superuser, ::RuntimeOrigin::root()); + let (origin_kind, origin) = (OriginKind::Superuser, ::RuntimeOrigin::root()); Polkadot::execute_with(|| { type Runtime = ::Runtime; @@ -117,7 +117,9 @@ fn relay_commands_kill_identity() { let kill_identity_call = PeopleCall::Identity(pallet_identity::Call::::kill_identity { - target: people_polkadot_runtime::MultiAddress::Id(PeoplePolkadot::account_id_of(ALICE)), + target: people_polkadot_runtime::MultiAddress::Id(PeoplePolkadot::account_id_of( + ALICE, + )), }); let xcm_message = RuntimeCall::XcmPallet(pallet_xcm::Call::::send { @@ -163,7 +165,6 @@ fn relay_commands_add_remove_username_authority() { let people_polkadot_alice = PeoplePolkadot::account_id_of(ALICE); let people_polkadot_bob = PeoplePolkadot::account_id_of(BOB); - let origins = vec![ (OriginKind::Xcm, GeneralAdminOrigin.into(), "generaladmin"), (OriginKind::Superuser, ::RuntimeOrigin::root(), "rootusername"), @@ -177,12 +178,13 @@ fn relay_commands_add_remove_username_authority() { type PeopleCall = ::RuntimeCall; type PeopleRuntime = ::Runtime; - let add_username_authority = - PeopleCall::Identity(pallet_identity::Call::::add_username_authority { - authority: people_polkadot_runtime::MultiAddress::Id(people_polkadot_alice.clone()), - suffix: b"suffix1".into(), - allocation: 10 - }); + let add_username_authority = PeopleCall::Identity(pallet_identity::Call::< + PeopleRuntime, + >::add_username_authority { + authority: people_polkadot_runtime::MultiAddress::Id(people_polkadot_alice.clone()), + suffix: b"suffix1".into(), + allocation: 10, + }); let add_authority_xcm_msg = RuntimeCall::XcmPallet(pallet_xcm::Call::::send { dest: bx!(VersionedLocation::from(Location::new(0, [Parachain(1004)]))), @@ -223,12 +225,11 @@ fn relay_commands_add_remove_username_authority() { PeoplePolkadot::execute_with(|| { type PeopleRuntimeEvent = ::RuntimeEvent; - assert_ok!( - ::Identity::set_username_for( - ::RuntimeOrigin::signed(people_polkadot_alice.clone()), - people_polkadot_runtime::MultiAddress::Id(people_polkadot_bob.clone()), - usr.to_owned().into_bytes().try_into().unwrap(), - None, + assert_ok!(::Identity::set_username_for( + ::RuntimeOrigin::signed(people_polkadot_alice.clone()), + people_polkadot_runtime::MultiAddress::Id(people_polkadot_bob.clone()), + usr.to_owned().into_bytes().try_into().unwrap(), + None, )); assert_expected_events!( @@ -244,10 +245,9 @@ fn relay_commands_add_remove_username_authority() { type PeopleRuntimeEvent = ::RuntimeEvent; let full_username = [usr.to_owned(), ".suffix1".to_owned()].concat().into_bytes(); - assert_ok!( - ::Identity::accept_username( - ::RuntimeOrigin::signed(people_polkadot_bob.clone()), - full_username.try_into().unwrap(), + assert_ok!(::Identity::accept_username( + ::RuntimeOrigin::signed(people_polkadot_bob.clone()), + full_username.try_into().unwrap(), )); assert_expected_events!( @@ -266,23 +266,25 @@ fn relay_commands_add_remove_username_authority() { type PeopleCall = ::RuntimeCall; type PeopleRuntime = ::Runtime; - let remove_username_authority = - PeopleCall::Identity(pallet_identity::Call::::remove_username_authority { - authority: people_polkadot_runtime::MultiAddress::Id(people_polkadot_alice.clone()), - }); - - let remove_authority_xcm_msg = RuntimeCall::XcmPallet(pallet_xcm::Call::::send { - dest: bx!(VersionedLocation::from(Location::new(0, [Parachain(1004)]))), - message: bx!(VersionedXcm::from(Xcm(vec![ - UnpaidExecution { weight_limit: Unlimited, check_origin: None }, - Transact { - origin_kind, - require_weight_at_most: Weight::from_parts(500_000_000, 500_000), - call: remove_username_authority.encode().into(), - } - ]))), + let remove_username_authority = PeopleCall::Identity(pallet_identity::Call::< + PeopleRuntime, + >::remove_username_authority { + authority: people_polkadot_runtime::MultiAddress::Id(people_polkadot_alice.clone()), }); + let remove_authority_xcm_msg = + RuntimeCall::XcmPallet(pallet_xcm::Call::::send { + dest: bx!(VersionedLocation::from(Location::new(0, [Parachain(1004)]))), + message: bx!(VersionedXcm::from(Xcm(vec![ + UnpaidExecution { weight_limit: Unlimited, check_origin: None }, + Transact { + origin_kind, + require_weight_at_most: Weight::from_parts(500_000_000, 500_000), + call: remove_username_authority.encode().into(), + } + ]))), + }); + assert_ok!(remove_authority_xcm_msg.dispatch(origin)); assert_expected_events!( @@ -305,6 +307,5 @@ fn relay_commands_add_remove_username_authority() { ] ); }); - } -} \ No newline at end of file +} From 90ba7d86cefc379b0467d1924586c66cf9644114 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Bald=C3=A9?= Date: Mon, 4 Nov 2024 16:43:14 +0000 Subject: [PATCH 06/11] Implement `clippy` fixes --- .../tests/people/people-kusama/src/tests/governance.rs | 8 +++++--- .../tests/people/people-polkadot/src/tests/governance.rs | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/integration-tests/emulated/tests/people/people-kusama/src/tests/governance.rs b/integration-tests/emulated/tests/people/people-kusama/src/tests/governance.rs index 00c244d48d..6989223d2f 100644 --- a/integration-tests/emulated/tests/people/people-kusama/src/tests/governance.rs +++ b/integration-tests/emulated/tests/people/people-kusama/src/tests/governance.rs @@ -88,8 +88,10 @@ fn relay_commands_kill_identity() { let people_kusama_alice = ::RuntimeOrigin::signed(PeopleKusama::account_id_of(ALICE)); - let mut identity_info = ::default(); - identity_info.email = Data::Raw(b"test@test.io".to_vec().try_into().unwrap()); + let identity_info = IdentityInfo { + email: Data::Raw(b"test@test.io".to_vec().try_into().unwrap()), + ..Default::default() + }; let identity: Box<::IdentityInformation> = Box::new(identity_info); @@ -226,7 +228,7 @@ fn relay_commands_add_remove_username_authority() { assert_ok!(::Identity::set_username_for( ::RuntimeOrigin::signed(people_kusama_alice.clone()), people_kusama_runtime::MultiAddress::Id(people_kusama_bob.clone()), - usr.to_owned().into_bytes().try_into().unwrap(), + usr.to_owned().into_bytes(), None, )); diff --git a/integration-tests/emulated/tests/people/people-polkadot/src/tests/governance.rs b/integration-tests/emulated/tests/people/people-polkadot/src/tests/governance.rs index a6edf4a015..ced5a3f3d4 100644 --- a/integration-tests/emulated/tests/people/people-polkadot/src/tests/governance.rs +++ b/integration-tests/emulated/tests/people/people-polkadot/src/tests/governance.rs @@ -88,8 +88,10 @@ fn relay_commands_kill_identity() { let people_polkadot_alice = ::RuntimeOrigin::signed(PeoplePolkadot::account_id_of(ALICE)); - let mut identity_info = ::default(); - identity_info.email = Data::Raw(b"test@test.io".to_vec().try_into().unwrap()); + let identity_info = IdentityInfo { + email: Data::Raw(b"test@test.io".to_vec().try_into().unwrap()), + ..Default::default() + }; let identity: Box<::IdentityInformation> = Box::new(identity_info); @@ -228,7 +230,7 @@ fn relay_commands_add_remove_username_authority() { assert_ok!(::Identity::set_username_for( ::RuntimeOrigin::signed(people_polkadot_alice.clone()), people_polkadot_runtime::MultiAddress::Id(people_polkadot_bob.clone()), - usr.to_owned().into_bytes().try_into().unwrap(), + usr.to_owned().into_bytes(), None, )); From 2f384341885586c9ca0441c494c72bbbf9e28d7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Bald=C3=A9?= Date: Thu, 7 Nov 2024 13:52:09 +0000 Subject: [PATCH 07/11] Test safety of origin checks in People Kusama --- .../people-kusama/src/tests/governance.rs | 238 +++++++++++++++++- 1 file changed, 236 insertions(+), 2 deletions(-) diff --git a/integration-tests/emulated/tests/people/people-kusama/src/tests/governance.rs b/integration-tests/emulated/tests/people/people-kusama/src/tests/governance.rs index 6989223d2f..924915ed5f 100644 --- a/integration-tests/emulated/tests/people/people-kusama/src/tests/governance.rs +++ b/integration-tests/emulated/tests/people/people-kusama/src/tests/governance.rs @@ -14,9 +14,9 @@ // limitations under the License. use crate::*; -use emulated_integration_tests_common::accounts::{ALICE, BOB}; +use emulated_integration_tests_common::accounts::{ALICE, BOB, CHARLIE}; -use frame_support::sp_runtime::traits::Dispatchable; +use frame_support::{traits::ProcessMessageError, sp_runtime::traits::Dispatchable}; use kusama_runtime::governance::pallet_custom_origins::Origin::GeneralAdmin as GeneralAdminOrigin; use people_kusama_runtime::people::IdentityInfo; @@ -78,6 +78,61 @@ fn relay_commands_add_registrar() { } } +#[test] +fn relay_commands_add_registrar_wrong_origin() { + let people_kusama_alice = PeopleKusama::account_id_of(ALICE); + + let (origin_kind, origin) = + (OriginKind::SovereignAccount, ::RuntimeOrigin::signed(people_kusama_alice)); + + let registrar: AccountId = [1; 32].into(); + Kusama::execute_with(|| { + type Runtime = ::Runtime; + type RuntimeCall = ::RuntimeCall; + type RuntimeEvent = ::RuntimeEvent; + type PeopleCall = ::RuntimeCall; + type PeopleRuntime = ::Runtime; + + let add_registrar_call = + PeopleCall::Identity(pallet_identity::Call::::add_registrar { + account: registrar.into(), + }); + + let xcm_message = RuntimeCall::XcmPallet(pallet_xcm::Call::::send { + dest: bx!(VersionedLocation::from(Location::new(0, [Parachain(1004)]))), + message: bx!(VersionedXcm::from(Xcm(vec![ + UnpaidExecution { weight_limit: Unlimited, check_origin: None }, + Transact { + origin_kind, + require_weight_at_most: Weight::from_parts(5_000_000_000, 500_000), + call: add_registrar_call.encode().into(), + } + ]))), + }); + + assert_ok!(xcm_message.dispatch(origin)); + + assert_expected_events!( + Kusama, + vec![ + RuntimeEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {}, + ] + ); + }); + + PeopleKusama::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + + assert_expected_events!( + PeopleKusama, + vec![ + RuntimeEvent::MessageQueue(pallet_message_queue::Event::ProcessingFailed { error: ProcessMessageError::Unsupported, .. }) => {}, + ] + ); + }); + +} + #[test] fn relay_commands_kill_identity() { // To kill an identity, first one must be set @@ -160,6 +215,60 @@ fn relay_commands_kill_identity() { }); } +#[test] +fn relay_commands_kill_identity_wrong_origin() { + let people_kusama_alice = PeopleKusama::account_id_of(BOB); + + let (origin_kind, origin) = + (OriginKind::SovereignAccount, ::RuntimeOrigin::signed(people_kusama_alice)); + + Kusama::execute_with(|| { + type Runtime = ::Runtime; + type RuntimeCall = ::RuntimeCall; + type PeopleCall = ::RuntimeCall; + type RuntimeEvent = ::RuntimeEvent; + type PeopleRuntime = ::Runtime; + + let kill_identity_call = + PeopleCall::Identity(pallet_identity::Call::::kill_identity { + target: people_kusama_runtime::MultiAddress::Id(PeopleKusama::account_id_of(ALICE)), + }); + + let xcm_message = RuntimeCall::XcmPallet(pallet_xcm::Call::::send { + dest: bx!(VersionedLocation::from(Location::new(0, [Parachain(1004)]))), + message: bx!(VersionedXcm::from(Xcm(vec![ + UnpaidExecution { weight_limit: Unlimited, check_origin: None }, + Transact { + origin_kind, + require_weight_at_most: Weight::from_parts(11_000_000_000, 500_000), + call: kill_identity_call.encode().into(), + } + ]))), + }); + + assert_ok!(xcm_message.dispatch(origin)); + + assert_expected_events!( + Kusama, + vec![ + RuntimeEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {}, + ] + ); + }); + + PeopleKusama::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + + assert_expected_events!( + PeopleKusama, + vec![ + RuntimeEvent::MessageQueue(pallet_message_queue::Event::ProcessingFailed { error: ProcessMessageError::Unsupported, .. }) => {}, + ] + ); + }); + +} + #[test] fn relay_commands_add_remove_username_authority() { let people_kusama_alice = PeopleKusama::account_id_of(ALICE); @@ -309,3 +418,128 @@ fn relay_commands_add_remove_username_authority() { }); } } + +#[test] +fn relay_commands_add_remove_username_authority_wrong_origin() { + let people_kusama_alice = PeopleKusama::account_id_of(ALICE); + + let origins = vec![ + (OriginKind::SovereignAccount, ::RuntimeOrigin::signed(people_kusama_alice.clone())), + (OriginKind::Superuser, ::RuntimeOrigin::root()), + ]; + + let mut first: bool = true; + + // The first iteration will fail, but the second succeeds, solely because a username authority + // is needed to test using `remove_username_authority` with an incorrect signed. + for (origin_kind, origin) in origins { + Kusama::execute_with(|| { + type Runtime = ::Runtime; + type RuntimeCall = ::RuntimeCall; + type RuntimeEvent = ::RuntimeEvent; + type PeopleCall = ::RuntimeCall; + type PeopleRuntime = ::Runtime; + + let add_username_authority = PeopleCall::Identity(pallet_identity::Call::< + PeopleRuntime, + >::add_username_authority { + authority: people_kusama_runtime::MultiAddress::Id(people_kusama_alice.clone()), + suffix: b"suffix1".into(), + allocation: 10, + }); + + let add_authority_xcm_msg = RuntimeCall::XcmPallet(pallet_xcm::Call::::send { + dest: bx!(VersionedLocation::from(Location::new(0, [Parachain(1004)]))), + message: bx!(VersionedXcm::from(Xcm(vec![ + UnpaidExecution { weight_limit: Unlimited, check_origin: None }, + Transact { + origin_kind, + require_weight_at_most: Weight::from_parts(500_000_000, 500_000), + call: add_username_authority.encode().into(), + } + ]))), + }); + + assert_ok!(add_authority_xcm_msg.dispatch(origin)); + + assert_expected_events!( + Kusama, + vec![ + RuntimeEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {}, + ] + ); + }); + + // Check events system-parachain-side + PeopleKusama::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + + if first { + assert_expected_events!( + PeopleKusama, + vec![ + RuntimeEvent::MessageQueue(pallet_message_queue::Event::ProcessingFailed { error: ProcessMessageError::Unsupported, .. }) => {}, + ] + ); + + } else { + assert_expected_events!( + PeopleKusama, + vec![ + RuntimeEvent::Identity(pallet_identity::Event::AuthorityAdded { .. }) => {}, + RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { success: true, .. }) => {}, + ] + ); + } + }); + + first = false; + } + + Kusama::execute_with(|| { + type Runtime = ::Runtime; + type RuntimeCall = ::RuntimeCall; + type RuntimeEvent = ::RuntimeEvent; + type PeopleCall = ::RuntimeCall; + type PeopleRuntime = ::Runtime; + + let remove_username_authority = PeopleCall::Identity(pallet_identity::Call::< + PeopleRuntime, + >::remove_username_authority { + authority: people_kusama_runtime::MultiAddress::Id(people_kusama_alice.clone()), + }); + + let remove_authority_xcm_msg = + RuntimeCall::XcmPallet(pallet_xcm::Call::::send { + dest: bx!(VersionedLocation::from(Location::new(0, [Parachain(1004)]))), + message: bx!(VersionedXcm::from(Xcm(vec![ + UnpaidExecution { weight_limit: Unlimited, check_origin: None }, + Transact { + origin_kind: OriginKind::SovereignAccount, + require_weight_at_most: Weight::from_parts(500_000_000, 500_000), + call: remove_username_authority.encode().into(), + } + ]))), + }); + + assert_ok!(remove_authority_xcm_msg.dispatch(::RuntimeOrigin::signed(people_kusama_alice))); + + assert_expected_events!( + Kusama, + vec![ + RuntimeEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {}, + ] + ); + }); + + PeopleKusama::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + + assert_expected_events!( + PeopleKusama, + vec![ + RuntimeEvent::MessageQueue(pallet_message_queue::Event::ProcessingFailed { error: ProcessMessageError::Unsupported, .. }) => {}, + ] + ); + }); +} From 96d46f0f62caa6699999162e8b44b9a1508d8bcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Bald=C3=A9?= Date: Thu, 7 Nov 2024 14:08:58 +0000 Subject: [PATCH 08/11] Remove unneeded operation in username authority test --- .../people-kusama/src/tests/governance.rs | 112 ++++++++---------- 1 file changed, 47 insertions(+), 65 deletions(-) diff --git a/integration-tests/emulated/tests/people/people-kusama/src/tests/governance.rs b/integration-tests/emulated/tests/people/people-kusama/src/tests/governance.rs index 924915ed5f..8bb0c8aa3e 100644 --- a/integration-tests/emulated/tests/people/people-kusama/src/tests/governance.rs +++ b/integration-tests/emulated/tests/people/people-kusama/src/tests/governance.rs @@ -423,79 +423,61 @@ fn relay_commands_add_remove_username_authority() { fn relay_commands_add_remove_username_authority_wrong_origin() { let people_kusama_alice = PeopleKusama::account_id_of(ALICE); - let origins = vec![ - (OriginKind::SovereignAccount, ::RuntimeOrigin::signed(people_kusama_alice.clone())), - (OriginKind::Superuser, ::RuntimeOrigin::root()), - ]; - - let mut first: bool = true; - - // The first iteration will fail, but the second succeeds, solely because a username authority - // is needed to test using `remove_username_authority` with an incorrect signed. - for (origin_kind, origin) in origins { - Kusama::execute_with(|| { - type Runtime = ::Runtime; - type RuntimeCall = ::RuntimeCall; - type RuntimeEvent = ::RuntimeEvent; - type PeopleCall = ::RuntimeCall; - type PeopleRuntime = ::Runtime; - - let add_username_authority = PeopleCall::Identity(pallet_identity::Call::< - PeopleRuntime, - >::add_username_authority { - authority: people_kusama_runtime::MultiAddress::Id(people_kusama_alice.clone()), - suffix: b"suffix1".into(), - allocation: 10, - }); + let (origin_kind, origin) = + (OriginKind::SovereignAccount, ::RuntimeOrigin::signed(people_kusama_alice.clone())); - let add_authority_xcm_msg = RuntimeCall::XcmPallet(pallet_xcm::Call::::send { - dest: bx!(VersionedLocation::from(Location::new(0, [Parachain(1004)]))), - message: bx!(VersionedXcm::from(Xcm(vec![ - UnpaidExecution { weight_limit: Unlimited, check_origin: None }, - Transact { - origin_kind, - require_weight_at_most: Weight::from_parts(500_000_000, 500_000), - call: add_username_authority.encode().into(), - } - ]))), - }); + Kusama::execute_with(|| { + type Runtime = ::Runtime; + type RuntimeCall = ::RuntimeCall; + type RuntimeEvent = ::RuntimeEvent; + type PeopleCall = ::RuntimeCall; + type PeopleRuntime = ::Runtime; - assert_ok!(add_authority_xcm_msg.dispatch(origin)); + let add_username_authority = PeopleCall::Identity(pallet_identity::Call::< + PeopleRuntime, + >::add_username_authority { + authority: people_kusama_runtime::MultiAddress::Id(people_kusama_alice.clone()), + suffix: b"suffix1".into(), + allocation: 10, + }); - assert_expected_events!( - Kusama, - vec![ - RuntimeEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {}, - ] - ); + let add_authority_xcm_msg = RuntimeCall::XcmPallet(pallet_xcm::Call::::send { + dest: bx!(VersionedLocation::from(Location::new(0, [Parachain(1004)]))), + message: bx!(VersionedXcm::from(Xcm(vec![ + UnpaidExecution { weight_limit: Unlimited, check_origin: None }, + Transact { + origin_kind, + require_weight_at_most: Weight::from_parts(500_000_000, 500_000), + call: add_username_authority.encode().into(), + } + ]))), }); - // Check events system-parachain-side - PeopleKusama::execute_with(|| { - type RuntimeEvent = ::RuntimeEvent; + assert_ok!(add_authority_xcm_msg.dispatch(origin)); - if first { - assert_expected_events!( - PeopleKusama, - vec![ - RuntimeEvent::MessageQueue(pallet_message_queue::Event::ProcessingFailed { error: ProcessMessageError::Unsupported, .. }) => {}, - ] - ); - - } else { - assert_expected_events!( - PeopleKusama, - vec![ - RuntimeEvent::Identity(pallet_identity::Event::AuthorityAdded { .. }) => {}, - RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { success: true, .. }) => {}, - ] - ); - } - }); + assert_expected_events!( + Kusama, + vec![ + RuntimeEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {}, + ] + ); + }); - first = false; - } + // Check events system-parachain-side + PeopleKusama::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + + assert_expected_events!( + PeopleKusama, + vec![ + RuntimeEvent::MessageQueue(pallet_message_queue::Event::ProcessingFailed { error: ProcessMessageError::Unsupported, .. }) => {}, + ] + ); + }); + // I mistakenly assumed that to test the removal of an authority would need one to exist. + // However, since the origin check is the very first extrinsic in `remove_username_authority`, + // an authority need not exist to test the safety of the origin check. Kusama::execute_with(|| { type Runtime = ::Runtime; type RuntimeCall = ::RuntimeCall; From a780f517b7936d5e4b0999c7aae74090f3a3bf7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Bald=C3=A9?= Date: Thu, 7 Nov 2024 14:17:44 +0000 Subject: [PATCH 09/11] Add origin check tests to People Polkadot as well --- .../people-polkadot/src/tests/governance.rs | 216 +++++++++++++++++- 1 file changed, 215 insertions(+), 1 deletion(-) diff --git a/integration-tests/emulated/tests/people/people-polkadot/src/tests/governance.rs b/integration-tests/emulated/tests/people/people-polkadot/src/tests/governance.rs index ced5a3f3d4..23286e2892 100644 --- a/integration-tests/emulated/tests/people/people-polkadot/src/tests/governance.rs +++ b/integration-tests/emulated/tests/people/people-polkadot/src/tests/governance.rs @@ -16,7 +16,7 @@ use crate::*; use emulated_integration_tests_common::accounts::{ALICE, BOB}; -use frame_support::sp_runtime::traits::Dispatchable; +use frame_support::{sp_runtime::traits::Dispatchable, traits::ProcessMessageError}; use people_polkadot_runtime::people::IdentityInfo; use polkadot_runtime::governance::pallet_custom_origins::Origin::GeneralAdmin as GeneralAdminOrigin; @@ -78,6 +78,60 @@ fn relay_commands_add_registrar() { } } +#[test] +fn relay_commands_add_registrar_wrong_origin() { + let people_polkadot_alice = PeoplePolkadot::account_id_of(ALICE); + + let (origin_kind, origin) = + (OriginKind::SovereignAccount, ::RuntimeOrigin::signed(people_polkadot_alice)); + + let registrar: AccountId = [1; 32].into(); + Polkadot::execute_with(|| { + type Runtime = ::Runtime; + type RuntimeCall = ::RuntimeCall; + type RuntimeEvent = ::RuntimeEvent; + type PeopleCall = ::RuntimeCall; + type PeopleRuntime = ::Runtime; + + let add_registrar_call = + PeopleCall::Identity(pallet_identity::Call::::add_registrar { + account: registrar.into(), + }); + + let xcm_message = RuntimeCall::XcmPallet(pallet_xcm::Call::::send { + dest: bx!(VersionedLocation::from(Location::new(0, [Parachain(1004)]))), + message: bx!(VersionedXcm::from(Xcm(vec![ + UnpaidExecution { weight_limit: Unlimited, check_origin: None }, + Transact { + origin_kind, + require_weight_at_most: Weight::from_parts(5_000_000_000, 500_000), + call: add_registrar_call.encode().into(), + } + ]))), + }); + + assert_ok!(xcm_message.dispatch(origin)); + + assert_expected_events!( + Polkadot, + vec![ + RuntimeEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {}, + ] + ); + }); + + PeoplePolkadot::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + + assert_expected_events!( + PeoplePolkadot, + vec![ + RuntimeEvent::MessageQueue(pallet_message_queue::Event::ProcessingFailed { error: ProcessMessageError::Unsupported, .. }) => {}, + ] + ); + }); +} + #[test] fn relay_commands_kill_identity() { // To kill an identity, first one must be set @@ -162,6 +216,59 @@ fn relay_commands_kill_identity() { }); } +#[test] +fn relay_commands_kill_identity_wrong_origin() { + let people_polkadot_alice = PeoplePolkadot::account_id_of(BOB); + + let (origin_kind, origin) = + (OriginKind::SovereignAccount, ::RuntimeOrigin::signed(people_polkadot_alice)); + + Polkadot::execute_with(|| { + type Runtime = ::Runtime; + type RuntimeCall = ::RuntimeCall; + type PeopleCall = ::RuntimeCall; + type RuntimeEvent = ::RuntimeEvent; + type PeopleRuntime = ::Runtime; + + let kill_identity_call = + PeopleCall::Identity(pallet_identity::Call::::kill_identity { + target: people_polkadot_runtime::MultiAddress::Id(PeoplePolkadot::account_id_of(ALICE)), + }); + + let xcm_message = RuntimeCall::XcmPallet(pallet_xcm::Call::::send { + dest: bx!(VersionedLocation::from(Location::new(0, [Parachain(1004)]))), + message: bx!(VersionedXcm::from(Xcm(vec![ + UnpaidExecution { weight_limit: Unlimited, check_origin: None }, + Transact { + origin_kind, + require_weight_at_most: Weight::from_parts(11_000_000_000, 500_000), + call: kill_identity_call.encode().into(), + } + ]))), + }); + + assert_ok!(xcm_message.dispatch(origin)); + + assert_expected_events!( + Polkadot, + vec![ + RuntimeEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {}, + ] + ); + }); + + PeoplePolkadot::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + + assert_expected_events!( + PeoplePolkadot, + vec![ + RuntimeEvent::MessageQueue(pallet_message_queue::Event::ProcessingFailed { error: ProcessMessageError::Unsupported, .. }) => {}, + ] + ); + }); +} + #[test] fn relay_commands_add_remove_username_authority() { let people_polkadot_alice = PeoplePolkadot::account_id_of(ALICE); @@ -311,3 +418,110 @@ fn relay_commands_add_remove_username_authority() { }); } } + +#[test] +fn relay_commands_add_remove_username_authority_wrong_origin() { + let people_polkadot_alice = PeoplePolkadot::account_id_of(ALICE); + + let (origin_kind, origin) = + (OriginKind::SovereignAccount, ::RuntimeOrigin::signed(people_polkadot_alice.clone())); + + Polkadot::execute_with(|| { + type Runtime = ::Runtime; + type RuntimeCall = ::RuntimeCall; + type RuntimeEvent = ::RuntimeEvent; + type PeopleCall = ::RuntimeCall; + type PeopleRuntime = ::Runtime; + + let add_username_authority = PeopleCall::Identity(pallet_identity::Call::< + PeopleRuntime, + >::add_username_authority { + authority: people_polkadot_runtime::MultiAddress::Id(people_polkadot_alice.clone()), + suffix: b"suffix1".into(), + allocation: 10, + }); + + let add_authority_xcm_msg = RuntimeCall::XcmPallet(pallet_xcm::Call::::send { + dest: bx!(VersionedLocation::from(Location::new(0, [Parachain(1004)]))), + message: bx!(VersionedXcm::from(Xcm(vec![ + UnpaidExecution { weight_limit: Unlimited, check_origin: None }, + Transact { + origin_kind, + require_weight_at_most: Weight::from_parts(500_000_000, 500_000), + call: add_username_authority.encode().into(), + } + ]))), + }); + + assert_ok!(add_authority_xcm_msg.dispatch(origin)); + + assert_expected_events!( + Polkadot, + vec![ + RuntimeEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {}, + ] + ); + }); + + // Check events system-parachain-side + PeoplePolkadot::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + + assert_expected_events!( + PeoplePolkadot, + vec![ + RuntimeEvent::MessageQueue(pallet_message_queue::Event::ProcessingFailed { error: ProcessMessageError::Unsupported, .. }) => {}, + ] + ); + }); + + // I mistakenly assumed that to test the removal of an authority would need one to exist. + // However, since the origin check is the very first extrinsic in `remove_username_authority`, + // an authority need not exist to test the safety of the origin check. + Polkadot::execute_with(|| { + type Runtime = ::Runtime; + type RuntimeCall = ::RuntimeCall; + type RuntimeEvent = ::RuntimeEvent; + type PeopleCall = ::RuntimeCall; + type PeopleRuntime = ::Runtime; + + let remove_username_authority = PeopleCall::Identity(pallet_identity::Call::< + PeopleRuntime, + >::remove_username_authority { + authority: people_polkadot_runtime::MultiAddress::Id(people_polkadot_alice.clone()), + }); + + let remove_authority_xcm_msg = + RuntimeCall::XcmPallet(pallet_xcm::Call::::send { + dest: bx!(VersionedLocation::from(Location::new(0, [Parachain(1004)]))), + message: bx!(VersionedXcm::from(Xcm(vec![ + UnpaidExecution { weight_limit: Unlimited, check_origin: None }, + Transact { + origin_kind: OriginKind::SovereignAccount, + require_weight_at_most: Weight::from_parts(500_000_000, 500_000), + call: remove_username_authority.encode().into(), + } + ]))), + }); + + assert_ok!(remove_authority_xcm_msg.dispatch(::RuntimeOrigin::signed(people_polkadot_alice))); + + assert_expected_events!( + Polkadot, + vec![ + RuntimeEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {}, + ] + ); + }); + + PeoplePolkadot::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + + assert_expected_events!( + PeoplePolkadot, + vec![ + RuntimeEvent::MessageQueue(pallet_message_queue::Event::ProcessingFailed { error: ProcessMessageError::Unsupported, .. }) => {}, + ] + ); + }); +} From e4b993bdd39df93502a1748cd81e57f93cd9c9b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Bald=C3=A9?= Date: Thu, 7 Nov 2024 15:54:37 +0000 Subject: [PATCH 10/11] Apply formatter --- .../people-kusama/src/tests/governance.rs | 63 ++++++++++--------- .../people-polkadot/src/tests/governance.rs | 63 ++++++++++--------- 2 files changed, 68 insertions(+), 58 deletions(-) diff --git a/integration-tests/emulated/tests/people/people-kusama/src/tests/governance.rs b/integration-tests/emulated/tests/people/people-kusama/src/tests/governance.rs index 8bb0c8aa3e..5ce6845c6d 100644 --- a/integration-tests/emulated/tests/people/people-kusama/src/tests/governance.rs +++ b/integration-tests/emulated/tests/people/people-kusama/src/tests/governance.rs @@ -14,9 +14,9 @@ // limitations under the License. use crate::*; -use emulated_integration_tests_common::accounts::{ALICE, BOB, CHARLIE}; +use emulated_integration_tests_common::accounts::{ALICE, BOB}; -use frame_support::{traits::ProcessMessageError, sp_runtime::traits::Dispatchable}; +use frame_support::{sp_runtime::traits::Dispatchable, traits::ProcessMessageError}; use kusama_runtime::governance::pallet_custom_origins::Origin::GeneralAdmin as GeneralAdminOrigin; use people_kusama_runtime::people::IdentityInfo; @@ -82,8 +82,10 @@ fn relay_commands_add_registrar() { fn relay_commands_add_registrar_wrong_origin() { let people_kusama_alice = PeopleKusama::account_id_of(ALICE); - let (origin_kind, origin) = - (OriginKind::SovereignAccount, ::RuntimeOrigin::signed(people_kusama_alice)); + let (origin_kind, origin) = ( + OriginKind::SovereignAccount, + ::RuntimeOrigin::signed(people_kusama_alice), + ); let registrar: AccountId = [1; 32].into(); Kusama::execute_with(|| { @@ -130,7 +132,6 @@ fn relay_commands_add_registrar_wrong_origin() { ] ); }); - } #[test] @@ -219,8 +220,10 @@ fn relay_commands_kill_identity() { fn relay_commands_kill_identity_wrong_origin() { let people_kusama_alice = PeopleKusama::account_id_of(BOB); - let (origin_kind, origin) = - (OriginKind::SovereignAccount, ::RuntimeOrigin::signed(people_kusama_alice)); + let (origin_kind, origin) = ( + OriginKind::SovereignAccount, + ::RuntimeOrigin::signed(people_kusama_alice), + ); Kusama::execute_with(|| { type Runtime = ::Runtime; @@ -266,7 +269,6 @@ fn relay_commands_kill_identity_wrong_origin() { ] ); }); - } #[test] @@ -423,8 +425,10 @@ fn relay_commands_add_remove_username_authority() { fn relay_commands_add_remove_username_authority_wrong_origin() { let people_kusama_alice = PeopleKusama::account_id_of(ALICE); - let (origin_kind, origin) = - (OriginKind::SovereignAccount, ::RuntimeOrigin::signed(people_kusama_alice.clone())); + let (origin_kind, origin) = ( + OriginKind::SovereignAccount, + ::RuntimeOrigin::signed(people_kusama_alice.clone()), + ); Kusama::execute_with(|| { type Runtime = ::Runtime; @@ -433,13 +437,12 @@ fn relay_commands_add_remove_username_authority_wrong_origin() { type PeopleCall = ::RuntimeCall; type PeopleRuntime = ::Runtime; - let add_username_authority = PeopleCall::Identity(pallet_identity::Call::< - PeopleRuntime, - >::add_username_authority { - authority: people_kusama_runtime::MultiAddress::Id(people_kusama_alice.clone()), - suffix: b"suffix1".into(), - allocation: 10, - }); + let add_username_authority = + PeopleCall::Identity(pallet_identity::Call::::add_username_authority { + authority: people_kusama_runtime::MultiAddress::Id(people_kusama_alice.clone()), + suffix: b"suffix1".into(), + allocation: 10, + }); let add_authority_xcm_msg = RuntimeCall::XcmPallet(pallet_xcm::Call::::send { dest: bx!(VersionedLocation::from(Location::new(0, [Parachain(1004)]))), @@ -491,20 +494,20 @@ fn relay_commands_add_remove_username_authority_wrong_origin() { authority: people_kusama_runtime::MultiAddress::Id(people_kusama_alice.clone()), }); - let remove_authority_xcm_msg = - RuntimeCall::XcmPallet(pallet_xcm::Call::::send { - dest: bx!(VersionedLocation::from(Location::new(0, [Parachain(1004)]))), - message: bx!(VersionedXcm::from(Xcm(vec![ - UnpaidExecution { weight_limit: Unlimited, check_origin: None }, - Transact { - origin_kind: OriginKind::SovereignAccount, - require_weight_at_most: Weight::from_parts(500_000_000, 500_000), - call: remove_username_authority.encode().into(), - } - ]))), - }); + let remove_authority_xcm_msg = RuntimeCall::XcmPallet(pallet_xcm::Call::::send { + dest: bx!(VersionedLocation::from(Location::new(0, [Parachain(1004)]))), + message: bx!(VersionedXcm::from(Xcm(vec![ + UnpaidExecution { weight_limit: Unlimited, check_origin: None }, + Transact { + origin_kind: OriginKind::SovereignAccount, + require_weight_at_most: Weight::from_parts(500_000_000, 500_000), + call: remove_username_authority.encode().into(), + } + ]))), + }); - assert_ok!(remove_authority_xcm_msg.dispatch(::RuntimeOrigin::signed(people_kusama_alice))); + assert_ok!(remove_authority_xcm_msg + .dispatch(::RuntimeOrigin::signed(people_kusama_alice))); assert_expected_events!( Kusama, diff --git a/integration-tests/emulated/tests/people/people-polkadot/src/tests/governance.rs b/integration-tests/emulated/tests/people/people-polkadot/src/tests/governance.rs index 23286e2892..9c3ff3943d 100644 --- a/integration-tests/emulated/tests/people/people-polkadot/src/tests/governance.rs +++ b/integration-tests/emulated/tests/people/people-polkadot/src/tests/governance.rs @@ -82,8 +82,10 @@ fn relay_commands_add_registrar() { fn relay_commands_add_registrar_wrong_origin() { let people_polkadot_alice = PeoplePolkadot::account_id_of(ALICE); - let (origin_kind, origin) = - (OriginKind::SovereignAccount, ::RuntimeOrigin::signed(people_polkadot_alice)); + let (origin_kind, origin) = ( + OriginKind::SovereignAccount, + ::RuntimeOrigin::signed(people_polkadot_alice), + ); let registrar: AccountId = [1; 32].into(); Polkadot::execute_with(|| { @@ -220,8 +222,10 @@ fn relay_commands_kill_identity() { fn relay_commands_kill_identity_wrong_origin() { let people_polkadot_alice = PeoplePolkadot::account_id_of(BOB); - let (origin_kind, origin) = - (OriginKind::SovereignAccount, ::RuntimeOrigin::signed(people_polkadot_alice)); + let (origin_kind, origin) = ( + OriginKind::SovereignAccount, + ::RuntimeOrigin::signed(people_polkadot_alice), + ); Polkadot::execute_with(|| { type Runtime = ::Runtime; @@ -232,7 +236,9 @@ fn relay_commands_kill_identity_wrong_origin() { let kill_identity_call = PeopleCall::Identity(pallet_identity::Call::::kill_identity { - target: people_polkadot_runtime::MultiAddress::Id(PeoplePolkadot::account_id_of(ALICE)), + target: people_polkadot_runtime::MultiAddress::Id(PeoplePolkadot::account_id_of( + ALICE, + )), }); let xcm_message = RuntimeCall::XcmPallet(pallet_xcm::Call::::send { @@ -423,8 +429,10 @@ fn relay_commands_add_remove_username_authority() { fn relay_commands_add_remove_username_authority_wrong_origin() { let people_polkadot_alice = PeoplePolkadot::account_id_of(ALICE); - let (origin_kind, origin) = - (OriginKind::SovereignAccount, ::RuntimeOrigin::signed(people_polkadot_alice.clone())); + let (origin_kind, origin) = ( + OriginKind::SovereignAccount, + ::RuntimeOrigin::signed(people_polkadot_alice.clone()), + ); Polkadot::execute_with(|| { type Runtime = ::Runtime; @@ -433,13 +441,12 @@ fn relay_commands_add_remove_username_authority_wrong_origin() { type PeopleCall = ::RuntimeCall; type PeopleRuntime = ::Runtime; - let add_username_authority = PeopleCall::Identity(pallet_identity::Call::< - PeopleRuntime, - >::add_username_authority { - authority: people_polkadot_runtime::MultiAddress::Id(people_polkadot_alice.clone()), - suffix: b"suffix1".into(), - allocation: 10, - }); + let add_username_authority = + PeopleCall::Identity(pallet_identity::Call::::add_username_authority { + authority: people_polkadot_runtime::MultiAddress::Id(people_polkadot_alice.clone()), + suffix: b"suffix1".into(), + allocation: 10, + }); let add_authority_xcm_msg = RuntimeCall::XcmPallet(pallet_xcm::Call::::send { dest: bx!(VersionedLocation::from(Location::new(0, [Parachain(1004)]))), @@ -491,20 +498,20 @@ fn relay_commands_add_remove_username_authority_wrong_origin() { authority: people_polkadot_runtime::MultiAddress::Id(people_polkadot_alice.clone()), }); - let remove_authority_xcm_msg = - RuntimeCall::XcmPallet(pallet_xcm::Call::::send { - dest: bx!(VersionedLocation::from(Location::new(0, [Parachain(1004)]))), - message: bx!(VersionedXcm::from(Xcm(vec![ - UnpaidExecution { weight_limit: Unlimited, check_origin: None }, - Transact { - origin_kind: OriginKind::SovereignAccount, - require_weight_at_most: Weight::from_parts(500_000_000, 500_000), - call: remove_username_authority.encode().into(), - } - ]))), - }); + let remove_authority_xcm_msg = RuntimeCall::XcmPallet(pallet_xcm::Call::::send { + dest: bx!(VersionedLocation::from(Location::new(0, [Parachain(1004)]))), + message: bx!(VersionedXcm::from(Xcm(vec![ + UnpaidExecution { weight_limit: Unlimited, check_origin: None }, + Transact { + origin_kind: OriginKind::SovereignAccount, + require_weight_at_most: Weight::from_parts(500_000_000, 500_000), + call: remove_username_authority.encode().into(), + } + ]))), + }); - assert_ok!(remove_authority_xcm_msg.dispatch(::RuntimeOrigin::signed(people_polkadot_alice))); + assert_ok!(remove_authority_xcm_msg + .dispatch(::RuntimeOrigin::signed(people_polkadot_alice))); assert_expected_events!( Polkadot, @@ -523,5 +530,5 @@ fn relay_commands_add_remove_username_authority_wrong_origin() { RuntimeEvent::MessageQueue(pallet_message_queue::Event::ProcessingFailed { error: ProcessMessageError::Unsupported, .. }) => {}, ] ); - }); + }); } From 40cfec204ed63045ed4d68b14353399269988084 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Bald=C3=A9?= Date: Thu, 12 Dec 2024 19:15:44 +0000 Subject: [PATCH 11/11] Address PR review --- .../people/people-kusama/src/tests/governance.rs | 13 +++++++++---- .../people/people-polkadot/src/tests/governance.rs | 5 ++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/integration-tests/emulated/tests/people/people-kusama/src/tests/governance.rs b/integration-tests/emulated/tests/people/people-kusama/src/tests/governance.rs index 5ce6845c6d..be3b18acf9 100644 --- a/integration-tests/emulated/tests/people/people-kusama/src/tests/governance.rs +++ b/integration-tests/emulated/tests/people/people-kusama/src/tests/governance.rs @@ -48,6 +48,9 @@ fn relay_commands_add_registrar() { UnpaidExecution { weight_limit: Unlimited, check_origin: None }, Transact { origin_kind, + // TODO: + // This and the below weight data in the XCM can be removed once XCMv5 is + // used. require_weight_at_most: Weight::from_parts(5_000_000_000, 500_000), call: add_registrar_call.encode().into(), } @@ -369,7 +372,7 @@ fn relay_commands_add_remove_username_authority() { ); }); - // Now, remove the username authority with another priviledged XCM call. + // Now, remove the username authority with another privileged XCM call. Kusama::execute_with(|| { type Runtime = ::Runtime; type RuntimeCall = ::RuntimeCall; @@ -390,6 +393,9 @@ fn relay_commands_add_remove_username_authority() { UnpaidExecution { weight_limit: Unlimited, check_origin: None }, Transact { origin_kind, + // TODO: + // this and all other references to `require_weight_at_most` can be + // removed once XCMv5 is in use. require_weight_at_most: Weight::from_parts(500_000_000, 500_000), call: remove_username_authority.encode().into(), } @@ -478,9 +484,8 @@ fn relay_commands_add_remove_username_authority_wrong_origin() { ); }); - // I mistakenly assumed that to test the removal of an authority would need one to exist. - // However, since the origin check is the very first extrinsic in `remove_username_authority`, - // an authority need not exist to test the safety of the origin check. + // Since the origin check is the very first instruction in `remove_username_authority`, an + // authority need not exist to test the safety of the origin check. Kusama::execute_with(|| { type Runtime = ::Runtime; type RuntimeCall = ::RuntimeCall; diff --git a/integration-tests/emulated/tests/people/people-polkadot/src/tests/governance.rs b/integration-tests/emulated/tests/people/people-polkadot/src/tests/governance.rs index 9c3ff3943d..4c3ac649a9 100644 --- a/integration-tests/emulated/tests/people/people-polkadot/src/tests/governance.rs +++ b/integration-tests/emulated/tests/people/people-polkadot/src/tests/governance.rs @@ -373,7 +373,7 @@ fn relay_commands_add_remove_username_authority() { ); }); - // Now, remove the username authority with another priviledged XCM call. + // Now, remove the username authority with another privileged XCM call. Polkadot::execute_with(|| { type Runtime = ::Runtime; type RuntimeCall = ::RuntimeCall; @@ -482,8 +482,7 @@ fn relay_commands_add_remove_username_authority_wrong_origin() { ); }); - // I mistakenly assumed that to test the removal of an authority would need one to exist. - // However, since the origin check is the very first extrinsic in `remove_username_authority`, + // Since the origin check is the very first instruction in `remove_username_authority`, // an authority need not exist to test the safety of the origin check. Polkadot::execute_with(|| { type Runtime = ::Runtime;