Skip to content
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
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Original file line number Diff line number Diff line change
Expand Up @@ -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 kusama_runtime_constants::currency::UNITS as KSM;
use parachains_common::Balance;

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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Original file line number Diff line number Diff line change
Expand Up @@ -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 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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Copy link
Contributor

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

// 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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 = <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, .. }) => {},
]
);
});
}
}
Loading
Loading