-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add more integrations tests to People chains #499
Open
rockbmb
wants to merge
13
commits into
polkadot-fellows:main
Choose a base branch
from
rockbmb:pallet-identity-root-extrinsics
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+942
−4
Open
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
39a797b
Test `kill_identity` via root origin XCM from relay
rockbmb 79a5016
Test root XCM to add a username authority
rockbmb a74c88f
Complete username authority test for Polkadot
rockbmb 1325e59
Replicate XCM integration tests in Kusama
rockbmb 4752d1c
Apply `cargo fmt`
rockbmb 5d5a710
Merge branch 'main' into pallet-identity-root-extrinsics
rockbmb 90ba7d8
Implement `clippy` fixes
rockbmb 2f38434
Test safety of origin checks in People Kusama
rockbmb 96d46f0
Remove unneeded operation in username authority test
rockbmb a780f51
Add origin check tests to People Polkadot as well
rockbmb e4b993b
Apply formatter
rockbmb 8547326
Merge branch 'main' into pallet-identity-root-extrinsics
rockbmb d28c776
Merge branch 'main' into pallet-identity-root-extrinsics
rockbmb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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,235 @@ 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 = <PeopleKusama as Chain>::Runtime; | ||||||
type PeopleRuntimeEvent = <PeopleKusama as Chain>::RuntimeEvent; | ||||||
|
||||||
let people_kusama_alice = | ||||||
<PeopleKusama as Chain>::RuntimeOrigin::signed(PeopleKusama::account_id_of(ALICE)); | ||||||
|
||||||
let identity_info = IdentityInfo { | ||||||
email: Data::Raw(b"test@test.io".to_vec().try_into().unwrap()), | ||||||
..Default::default() | ||||||
}; | ||||||
let identity: Box<<PeopleRuntime as pallet_identity::Config>::IdentityInformation> = | ||||||
Box::new(identity_info); | ||||||
|
||||||
assert_ok!(<PeopleKusama as PeopleKusamaPallet>::Identity::set_identity( | ||||||
people_kusama_alice, | ||||||
identity | ||||||
)); | ||||||
|
||||||
assert_expected_events!( | ||||||
PeopleKusama, | ||||||
vec![ | ||||||
PeopleRuntimeEvent::Identity(pallet_identity::Event::IdentitySet { .. }) => {}, | ||||||
] | ||||||
); | ||||||
}); | ||||||
|
||||||
let (origin_kind, origin) = (OriginKind::Superuser, <Kusama as Chain>::RuntimeOrigin::root()); | ||||||
|
||||||
Kusama::execute_with(|| { | ||||||
type Runtime = <Kusama as Chain>::Runtime; | ||||||
type RuntimeCall = <Kusama as Chain>::RuntimeCall; | ||||||
type PeopleCall = <PeopleKusama as Chain>::RuntimeCall; | ||||||
type RuntimeEvent = <Kusama as Chain>::RuntimeEvent; | ||||||
type PeopleRuntime = <PeopleKusama as Chain>::Runtime; | ||||||
|
||||||
let kill_identity_call = | ||||||
PeopleCall::Identity(pallet_identity::Call::<PeopleRuntime>::kill_identity { | ||||||
target: people_kusama_runtime::MultiAddress::Id(PeopleKusama::account_id_of(ALICE)), | ||||||
}); | ||||||
|
||||||
let xcm_message = RuntimeCall::XcmPallet(pallet_xcm::Call::<Runtime>::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 = <PeopleKusama as Chain>::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, <Kusama as Chain>::RuntimeOrigin::root(), "rootusername"), | ||||||
]; | ||||||
for (origin_kind, origin, usr) in origins { | ||||||
// First, add a username authority. | ||||||
Kusama::execute_with(|| { | ||||||
type Runtime = <Kusama as Chain>::Runtime; | ||||||
type RuntimeCall = <Kusama as Chain>::RuntimeCall; | ||||||
type RuntimeEvent = <Kusama as Chain>::RuntimeEvent; | ||||||
type PeopleCall = <PeopleKusama as Chain>::RuntimeCall; | ||||||
type PeopleRuntime = <PeopleKusama as Chain>::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::<Runtime>::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 = <PeopleKusama as Chain>::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 = <PeopleKusama as Chain>::RuntimeEvent; | ||||||
|
||||||
assert_ok!(<PeopleKusama as PeopleKusamaPallet>::Identity::set_username_for( | ||||||
<PeopleKusama as Chain>::RuntimeOrigin::signed(people_kusama_alice.clone()), | ||||||
people_kusama_runtime::MultiAddress::Id(people_kusama_bob.clone()), | ||||||
usr.to_owned().into_bytes(), | ||||||
None, | ||||||
)); | ||||||
|
||||||
assert_expected_events!( | ||||||
PeopleKusama, | ||||||
vec![ | ||||||
PeopleRuntimeEvent::Identity(pallet_identity::Event::UsernameQueued { .. }) => {}, | ||||||
] | ||||||
); | ||||||
}); | ||||||
|
||||||
// Accept the given username | ||||||
PeopleKusama::execute_with(|| { | ||||||
type PeopleRuntimeEvent = <PeopleKusama as Chain>::RuntimeEvent; | ||||||
let full_username = [usr.to_owned(), ".suffix1".to_owned()].concat().into_bytes(); | ||||||
|
||||||
assert_ok!(<PeopleKusama as PeopleKusamaPallet>::Identity::accept_username( | ||||||
<PeopleKusama as Chain>::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. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
Kusama::execute_with(|| { | ||||||
type Runtime = <Kusama as Chain>::Runtime; | ||||||
type RuntimeCall = <Kusama as Chain>::RuntimeCall; | ||||||
type RuntimeEvent = <Kusama as Chain>::RuntimeEvent; | ||||||
type PeopleCall = <PeopleKusama as Chain>::RuntimeCall; | ||||||
type PeopleRuntime = <PeopleKusama as Chain>::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::<Runtime>::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 = <PeopleKusama as Chain>::RuntimeEvent; | ||||||
|
||||||
assert_expected_events!( | ||||||
PeopleKusama, | ||||||
vec![ | ||||||
RuntimeEvent::Identity(pallet_identity::Event::AuthorityRemoved { .. }) => {}, | ||||||
RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { success: true, .. }) => {}, | ||||||
] | ||||||
); | ||||||
}); | ||||||
} | ||||||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be removed when we update to XCM v5 in this repo