From 9de660bc20722b63d0bc5e0176eae70a1954d92d Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Thu, 16 Nov 2023 20:16:25 +0000 Subject: [PATCH 001/102] create initial structure --- Cargo.lock | 40 +++++ Cargo.toml | 2 + .../people/people-rococo/Cargo.toml | 25 +++ .../people/people-rococo/src/genesis.rs | 70 ++++++++ .../people/people-rococo/src/lib.rs | 55 +++++++ .../networks/rococo-system/Cargo.toml | 1 + .../networks/rococo-system/src/lib.rs | 6 +- .../tests/people/people-rococo/Cargo.toml | 34 ++++ .../tests/people/people-rococo/src/lib.rs | 61 +++++++ .../people/people-rococo/src/tests/mod.rs | 16 ++ .../people-rococo/src/tests/teleport.rs | 154 ++++++++++++++++++ 11 files changed, 463 insertions(+), 1 deletion(-) create mode 100644 cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/Cargo.toml create mode 100644 cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/genesis.rs create mode 100644 cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/lib.rs create mode 100644 cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/Cargo.toml create mode 100644 cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/lib.rs create mode 100644 cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/mod.rs create mode 100644 cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs diff --git a/Cargo.lock b/Cargo.lock index cbf3d76586e8..968f6dcc4c40 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11792,6 +11792,45 @@ dependencies = [ "substrate-wasm-builder", ] +[[package]] +name = "people-rococo-emulated-chain" +version = "0.0.0" +dependencies = [ + "cumulus-primitives-core", + "emulated-integration-tests-common", + "frame-support", + "parachains-common", + "people-rococo-runtime", + "rococo-emulated-chain", + "serde_json", + "sp-core", + "sp-runtime", +] + +[[package]] +name = "people-rococo-integration-tests" +version = "1.0.0" +dependencies = [ + "assert_matches", + "asset-test-utils", + "emulated-integration-tests-common", + "frame-support", + "pallet-asset-conversion", + "pallet-assets", + "pallet-balances", + "pallet-message-queue", + "pallet-xcm", + "parachains-common", + "parity-scale-codec", + "penpal-runtime", + "people-rococo-runtime", + "rococo-runtime", + "rococo-system-emulated-network", + "sp-runtime", + "staging-xcm", + "staging-xcm-executor", +] + [[package]] name = "people-rococo-runtime" version = "1.0.0" @@ -14803,6 +14842,7 @@ dependencies = [ "bridge-hub-rococo-emulated-chain", "emulated-integration-tests-common", "penpal-emulated-chain", + "people-rococo-emulated-chain", "rococo-emulated-chain", ] diff --git a/Cargo.toml b/Cargo.toml index cf537bdef613..b8d7d0f884d0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -64,6 +64,7 @@ members = [ "cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend", "cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo", "cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend", + "cumulus/parachains/integration-tests/emulated/tests/people/people-rococo", "cumulus/parachains/integration-tests/emulated/common", "cumulus/parachains/integration-tests/emulated/chains/relays/rococo", "cumulus/parachains/integration-tests/emulated/chains/relays/westend", @@ -71,6 +72,7 @@ members = [ "cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend", "cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-rococo", "cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-westend", + "cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo", "cumulus/parachains/integration-tests/emulated/networks/rococo-system", "cumulus/parachains/integration-tests/emulated/networks/rococo-westend-system", "cumulus/parachains/integration-tests/emulated/networks/westend-system", diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/Cargo.toml b/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/Cargo.toml new file mode 100644 index 000000000000..e48ee5b30636 --- /dev/null +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/Cargo.toml @@ -0,0 +1,25 @@ +[package] +name = "people-rococo-emulated-chain" +version = "0.0.0" +authors.workspace = true +edition.workspace = true +license = "Apache-2.0" +description = "People Rococo emulated chain" +publish = false + +[dependencies] +serde_json = "1.0.104" + +# Substrate +sp-core = { path = "../../../../../../../../substrate/primitives/core", default-features = false } +sp-runtime = { path = "../../../../../../../../substrate/primitives/runtime", default-features = false } +frame-support = { path = "../../../../../../../../substrate/frame/support", default-features = false } + +# Polakadot +parachains-common = { path = "../../../../../../../parachains/common" } + +# Cumulus +cumulus-primitives-core = { path = "../../../../../../../primitives/core", default-features = false } +emulated-integration-tests-common = { path = "../../../../common", default-features = false } +people-rococo-runtime = { path = "../../../../../../runtimes/people/people-rococo" } +rococo-emulated-chain = { path = "../../../relays/rococo" } diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/genesis.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/genesis.rs new file mode 100644 index 000000000000..c19d05ec7307 --- /dev/null +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/genesis.rs @@ -0,0 +1,70 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Substrate +use sp_core::storage::Storage; + +// Cumulus +use emulated_integration_tests_common::{ + accounts, build_genesis_storage, collators, SAFE_XCM_VERSION, +}; +use parachains_common::Balance; + +pub const PARA_ID: u32 = 1000; +pub const ED: Balance = parachains_common::rococo::currency::EXISTENTIAL_DEPOSIT; + +pub fn genesis() -> Storage { + let genesis_config = asset_hub_rococo_runtime::RuntimeGenesisConfig { + system: asset_hub_rococo_runtime::SystemConfig::default(), + balances: asset_hub_rococo_runtime::BalancesConfig { + balances: accounts::init_balances() + .iter() + .cloned() + .map(|k| (k, ED * 4096 * 4096)) + .collect(), + }, + parachain_info: asset_hub_rococo_runtime::ParachainInfoConfig { + parachain_id: PARA_ID.into(), + ..Default::default() + }, + collator_selection: asset_hub_rococo_runtime::CollatorSelectionConfig { + invulnerables: collators::invulnerables().iter().cloned().map(|(acc, _)| acc).collect(), + candidacy_bond: ED * 16, + ..Default::default() + }, + session: asset_hub_rococo_runtime::SessionConfig { + keys: collators::invulnerables() + .into_iter() + .map(|(acc, aura)| { + ( + acc.clone(), // account id + acc, // validator id + asset_hub_rococo_runtime::SessionKeys { aura }, // session keys + ) + }) + .collect(), + }, + polkadot_xcm: asset_hub_rococo_runtime::PolkadotXcmConfig { + safe_xcm_version: Some(SAFE_XCM_VERSION), + ..Default::default() + }, + ..Default::default() + }; + + build_genesis_storage( + &genesis_config, + asset_hub_rococo_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), + ) +} diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/lib.rs new file mode 100644 index 000000000000..5e6fd7fcb7b9 --- /dev/null +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/lib.rs @@ -0,0 +1,55 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +pub mod genesis; + +// Substrate +use frame_support::traits::OnInitialize; + +// Cumulus +use emulated_integration_tests_common::{ + impl_accounts_helpers_for_parachain, impl_assert_events_helpers_for_parachain, + impl_assets_helpers_for_parachain, impl_foreign_assets_helpers_for_parachain, impls::Parachain, + xcm_emulator::decl_test_parachains, +}; +use rococo_emulated_chain::Rococo; + +// AssetHubRococo Parachain declaration +decl_test_parachains! { + pub struct PeopleRococo { + genesis = genesis::genesis(), + on_init = { + people_rococo_runtime::AuraExt::on_initialize(1); + }, + runtime = people_rococo_runtime, + core = { + XcmpMessageHandler: people_rococo_runtime::XcmpQueue, + LocationToAccountId: people_rococo_runtime::xcm_config::LocationToAccountId, + ParachainInfo: people_rococo_runtime::ParachainInfo, + }, + pallets = { + PolkadotXcm: people_rococo_runtime::PolkadotXcm, + Assets: people_rococo_runtime::Assets, + ForeignAssets: people_rococo_runtime::ForeignAssets, + PoolAssets: people_rococo_runtime::PoolAssets, + AssetConversion: people_rococo_runtime::AssetConversion, + Balances: people_rococo_runtime::Balances, + } + }, +} + +// PeopleRococo implementation +impl_accounts_helpers_for_parachain!(AssetHubRococo); +impl_assert_events_helpers_for_parachain!(AssetHubRococo, false); diff --git a/cumulus/parachains/integration-tests/emulated/networks/rococo-system/Cargo.toml b/cumulus/parachains/integration-tests/emulated/networks/rococo-system/Cargo.toml index 713cc2ecdbb2..55ce75535c84 100644 --- a/cumulus/parachains/integration-tests/emulated/networks/rococo-system/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/networks/rococo-system/Cargo.toml @@ -13,4 +13,5 @@ emulated-integration-tests-common = { path = "../../common", default-features = rococo-emulated-chain = { path = "../../chains/relays/rococo" } asset-hub-rococo-emulated-chain = { path = "../../chains/parachains/assets/asset-hub-rococo" } bridge-hub-rococo-emulated-chain = { path = "../../chains/parachains/bridges/bridge-hub-rococo" } +people-rococo-emulated-chain = { path = "../../chains/parachains/people/people-rococo" } penpal-emulated-chain = { path = "../../chains/parachains/testing/penpal" } diff --git a/cumulus/parachains/integration-tests/emulated/networks/rococo-system/src/lib.rs b/cumulus/parachains/integration-tests/emulated/networks/rococo-system/src/lib.rs index ad22185fa703..70f23ef8260c 100644 --- a/cumulus/parachains/integration-tests/emulated/networks/rococo-system/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/networks/rococo-system/src/lib.rs @@ -16,11 +16,13 @@ pub use asset_hub_rococo_emulated_chain; pub use bridge_hub_rococo_emulated_chain; pub use penpal_emulated_chain; +pub use people_rococo_emulated_chain; pub use rococo_emulated_chain; use asset_hub_rococo_emulated_chain::AssetHubRococo; use bridge_hub_rococo_emulated_chain::BridgeHubRococo; use penpal_emulated_chain::{PenpalA, PenpalB}; +use people_rococo_emulated_chain::PeopleRococo; use rococo_emulated_chain::Rococo; // Cumulus @@ -37,6 +39,7 @@ decl_test_networks! { BridgeHubRococo, PenpalA, PenpalB, + PeopleRococo, ], bridge = () }, @@ -47,5 +50,6 @@ decl_test_sender_receiver_accounts_parameter_types! { AssetHubRococoPara { sender: ALICE, receiver: BOB }, BridgeHubRococoPara { sender: ALICE, receiver: BOB }, PenpalAPara { sender: ALICE, receiver: BOB }, - PenpalBPara { sender: ALICE, receiver: BOB } + PenpalBPara { sender: ALICE, receiver: BOB }, + PeopleRococoPara { sender: ALICE, receiver: BOB } } diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/Cargo.toml b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/Cargo.toml new file mode 100644 index 000000000000..b201fb5f0f06 --- /dev/null +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/Cargo.toml @@ -0,0 +1,34 @@ +[package] +name = "people-rococo-integration-tests" +version = "1.0.0" +authors.workspace = true +edition.workspace = true +license = "Apache-2.0" +description = "People Rococo runtime integration tests with xcm-emulator" +publish = false + +[dependencies] +codec = { package = "parity-scale-codec", version = "3.4.0", default-features = false } +assert_matches = "1.5.0" + +# Substrate +sp-runtime = { path = "../../../../../../../substrate/primitives/runtime", default-features = false} +frame-support = { path = "../../../../../../../substrate/frame/support", default-features = false} +pallet-balances = { path = "../../../../../../../substrate/frame/balances", default-features = false} +pallet-assets = { path = "../../../../../../../substrate/frame/assets", default-features = false} +pallet-asset-conversion = { path = "../../../../../../../substrate/frame/asset-conversion", default-features = false} +pallet-message-queue = { path = "../../../../../../../substrate/frame/message-queue", default-features = false } + +# Polkadot +xcm = { package = "staging-xcm", path = "../../../../../../../polkadot/xcm", default-features = false} +pallet-xcm = { path = "../../../../../../../polkadot/xcm/pallet-xcm", default-features = false} +xcm-executor = { package = "staging-xcm-executor", path = "../../../../../../../polkadot/xcm/xcm-executor", default-features = false} +rococo-runtime = { path = "../../../../../../../polkadot/runtime/rococo" } + +# Cumulus +asset-test-utils = { path = "../../../../../runtimes/assets/test-utils" } +parachains-common = { path = "../../../../../../parachains/common" } +people-rococo-runtime = { path = "../../../../../runtimes/people/people-rococo" } +emulated-integration-tests-common = { path = "../../../common", default-features = false } +penpal-runtime = { path = "../../../../../runtimes/testing/penpal" } +rococo-system-emulated-network ={ path = "../../../networks/rococo-system" } diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/lib.rs new file mode 100644 index 000000000000..5a87620fa678 --- /dev/null +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/lib.rs @@ -0,0 +1,61 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +mod tests; + +pub use codec::Encode; + +// Substrate +pub use frame_support::{ + assert_err, assert_ok, + pallet_prelude::Weight, + sp_runtime::{AccountId32, DispatchError, DispatchResult}, + traits::fungibles::Inspect, +}; + +// Polkadot +pub use xcm::{ + prelude::{AccountId32 as AccountId32Junction, *}, + v3::{Error, NetworkId::Rococo as RococoId}, +}; + +// Cumulus +pub use asset_test_utils::xcm_helpers; +pub use emulated_integration_tests_common::{ + test_parachain_is_trusted_teleporter, + xcm_emulator::{ + assert_expected_events, bx, helpers::weight_within_threshold, Chain, Parachain as Para, + RelayChain as Relay, Test, TestArgs, TestContext, TestExt, + }, + xcm_helpers::{xcm_transact_paid_execution, xcm_transact_unpaid_execution}, + PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3, +}; +pub use parachains_common::{AccountId, Balance}; +pub use rococo_system_emulated_network::{ + people_rococo_emulated_chain::{ + genesis::ED as ASSET_HUB_ROCOCO_ED, PeopleRococoParaPallet as AssetHubRococoPallet, + }, + rococo_emulated_chain::{genesis::ED as ROCOCO_ED, RococoRelayPallet as RococoPallet}, + PenpalAPara as PenpalA, PeopleRococoPara as PeopleRococo, + PeopleRococoParaReceiver as PeopleRococoReceiver, PeopleRococoParaSender as PeopleRococoSender, + RococoRelay as Rococo, RococoRelayReceiver as RococoReceiver, + RococoRelaySender as RococoSender, +}; + +pub type RelayToSystemParaTest = Test; +pub type RelayToParaTest = Test; +pub type SystemParaToRelayTest = Test; +pub type SystemParaToParaTest = Test; +pub type ParaToSystemParaTest = Test; diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/mod.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/mod.rs new file mode 100644 index 000000000000..516ec37cc10a --- /dev/null +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/mod.rs @@ -0,0 +1,16 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +mod teleport; diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs new file mode 100644 index 000000000000..304002a75093 --- /dev/null +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs @@ -0,0 +1,154 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use crate::*; + +use people_rococo_runtime::xcm_config::XcmConfig as PeopleRococoXcmConfig; +use rococo_runtime::xcm_config::XcmConfig as RococoXcmConfig; + +fn relay_origin_assertions(t: RelayToSystemParaTest) { + type RuntimeEvent = ::RuntimeEvent; + + Rococo::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(631_531_000, 7_186))); + + assert_expected_events!( + Rococo, + vec![ + // Amount to teleport is withdrawn from Sender + RuntimeEvent::Balances(pallet_balances::Event::Withdraw { who, amount }) => { + who: *who == t.sender.account_id, + amount: *amount == t.args.amount, + }, + // Amount to teleport is deposited in Relay's `CheckAccount` + RuntimeEvent::Balances(pallet_balances::Event::Deposit { who, amount }) => { + who: *who == ::XcmPallet::check_account(), + amount: *amount == t.args.amount, + }, + ] + ); +} + +fn relay_dest_assertions(t: SystemParaToRelayTest) { + type RuntimeEvent = ::RuntimeEvent; + + Rococo::assert_ump_queue_processed( + true, + Some(PeopleRococo::para_id()), + Some(Weight::from_parts(307_225_000, 7_186)), + ); + + assert_expected_events!( + Rococo, + vec![ + // Amount is withdrawn from Relay Chain's `CheckAccount` + RuntimeEvent::Balances(pallet_balances::Event::Withdraw { who, amount }) => { + who: *who == ::XcmPallet::check_account(), + amount: *amount == t.args.amount, + }, + // Amount minus fees are deposited in Receiver's account + RuntimeEvent::Balances(pallet_balances::Event::Deposit { who, .. }) => { + who: *who == t.receiver.account_id, + }, + ] + ); +} + +fn relay_dest_assertions_fail(_t: SystemParaToRelayTest) { + Rococo::assert_ump_queue_processed( + false, + Some(PeopleRococo::para_id()), + Some(Weight::from_parts(157_718_000, 3_593)), + ); +} + +fn para_origin_assertions(t: SystemParaToRelayTest) { + type RuntimeEvent = ::RuntimeEvent; + + PeopleRococo::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts( + 720_053_000, + 7_203, + ))); + + PeopleRococo::assert_parachain_system_ump_sent(); + + assert_expected_events!( + PeopleRococo, + vec![ + // Amount is withdrawn from Sender's account + RuntimeEvent::Balances(pallet_balances::Event::Withdraw { who, amount }) => { + who: *who == t.sender.account_id, + amount: *amount == t.args.amount, + }, + ] + ); +} + +fn para_dest_assertions(t: RelayToSystemParaTest) { + type RuntimeEvent = ::RuntimeEvent; + + PeopleRococo::assert_dmp_queue_complete(Some(Weight::from_parts(157_718_000, 3593))); + + assert_expected_events!( + PeopleRococo, + vec![ + // Amount minus fees are deposited in Receiver's account + RuntimeEvent::Balances(pallet_balances::Event::Deposit { who, .. }) => { + who: *who == t.receiver.account_id, + }, + ] + ); +} + +fn relay_limited_teleport_assets(t: RelayToSystemParaTest) -> DispatchResult { + ::XcmPallet::limited_teleport_assets( + t.signed_origin, + bx!(t.args.dest.into()), + bx!(t.args.beneficiary.into()), + bx!(t.args.assets.into()), + t.args.fee_asset_item, + t.args.weight_limit, + ) +} + +fn relay_teleport_assets(t: RelayToSystemParaTest) -> DispatchResult { + ::XcmPallet::teleport_assets( + t.signed_origin, + bx!(t.args.dest.into()), + bx!(t.args.beneficiary.into()), + bx!(t.args.assets.into()), + t.args.fee_asset_item, + ) +} + +fn system_para_limited_teleport_assets(t: SystemParaToRelayTest) -> DispatchResult { + ::PolkadotXcm::limited_teleport_assets( + t.signed_origin, + bx!(t.args.dest.into()), + bx!(t.args.beneficiary.into()), + bx!(t.args.assets.into()), + t.args.fee_asset_item, + t.args.weight_limit, + ) +} + +fn system_para_teleport_assets(t: SystemParaToRelayTest) -> DispatchResult { + ::PolkadotXcm::teleport_assets( + t.signed_origin, + bx!(t.args.dest.into()), + bx!(t.args.beneficiary.into()), + bx!(t.args.assets.into()), + t.args.fee_asset_item, + ) +} From 0f3d4a13b0c9fd45434d2b61bdeae047b1075d58 Mon Sep 17 00:00:00 2001 From: Richard Melkonian <35300528+0xmovses@users.noreply.github.com> Date: Mon, 20 Nov 2023 11:14:56 +0000 Subject: [PATCH 002/102] Update cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/genesis.rs Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> --- .../chains/parachains/people/people-rococo/src/genesis.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/genesis.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/genesis.rs index c19d05ec7307..e43cb4609203 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/genesis.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/genesis.rs @@ -22,7 +22,7 @@ use emulated_integration_tests_common::{ }; use parachains_common::Balance; -pub const PARA_ID: u32 = 1000; +pub const PARA_ID: u32 = 1004; pub const ED: Balance = parachains_common::rococo::currency::EXISTENTIAL_DEPOSIT; pub fn genesis() -> Storage { From 71eafe0aeaee920aa0bb4026b1cef8cf71026ffc Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Mon, 20 Nov 2023 15:18:31 +0000 Subject: [PATCH 003/102] updates --- Cargo.lock | 2 ++ .../people/people-rococo/src/genesis.rs | 25 ++++++++++--------- .../people/people-rococo/src/lib.rs | 10 +++----- .../tests/people/people-rococo/Cargo.toml | 2 ++ .../people/people-rococo/src/tests/mod.rs | 1 + .../people-rococo/src/tests/reap_identity.rs | 23 +++++++++++++++++ .../runtimes/people/people-rococo/src/lib.rs | 2 +- 7 files changed, 46 insertions(+), 19 deletions(-) create mode 100644 cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs diff --git a/Cargo.lock b/Cargo.lock index 968f6dcc4c40..ead0718b3a94 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11818,12 +11818,14 @@ dependencies = [ "pallet-asset-conversion", "pallet-assets", "pallet-balances", + "pallet-identity", "pallet-message-queue", "pallet-xcm", "parachains-common", "parity-scale-codec", "penpal-runtime", "people-rococo-runtime", + "polkadot-primitives", "rococo-runtime", "rococo-system-emulated-network", "sp-runtime", diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/genesis.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/genesis.rs index e43cb4609203..934ed406eab4 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/genesis.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/genesis.rs @@ -13,6 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +use cumulus_primitives_core::ParaId; // Substrate use sp_core::storage::Storage; @@ -26,37 +27,37 @@ pub const PARA_ID: u32 = 1004; pub const ED: Balance = parachains_common::rococo::currency::EXISTENTIAL_DEPOSIT; pub fn genesis() -> Storage { - let genesis_config = asset_hub_rococo_runtime::RuntimeGenesisConfig { - system: asset_hub_rococo_runtime::SystemConfig::default(), - balances: asset_hub_rococo_runtime::BalancesConfig { + let genesis_config = people_rococo_runtime::RuntimeGenesisConfig { + system: people_rococo_runtime::SystemConfig::default(), + balances: people_rococo_runtime::BalancesConfig { balances: accounts::init_balances() .iter() .cloned() .map(|k| (k, ED * 4096 * 4096)) .collect(), }, - parachain_info: asset_hub_rococo_runtime::ParachainInfoConfig { - parachain_id: PARA_ID.into(), + parachain_info: people_rococo_runtime::ParachainInfoConfig { + parachain_id: ParaId::from(PARA_ID), ..Default::default() }, - collator_selection: asset_hub_rococo_runtime::CollatorSelectionConfig { + collator_selection: people_rococo_runtime::CollatorSelectionConfig { invulnerables: collators::invulnerables().iter().cloned().map(|(acc, _)| acc).collect(), candidacy_bond: ED * 16, ..Default::default() }, - session: asset_hub_rococo_runtime::SessionConfig { + session: people_rococo_runtime::SessionConfig { keys: collators::invulnerables() .into_iter() .map(|(acc, aura)| { ( - acc.clone(), // account id - acc, // validator id - asset_hub_rococo_runtime::SessionKeys { aura }, // session keys + acc.clone(), // account id + acc, // validator id + people_rococo_runtime::SessionKeys { aura }, // session keys ) }) .collect(), }, - polkadot_xcm: asset_hub_rococo_runtime::PolkadotXcmConfig { + polkadot_xcm: people_rococo_runtime::PolkadotXcmConfig { safe_xcm_version: Some(SAFE_XCM_VERSION), ..Default::default() }, @@ -65,6 +66,6 @@ pub fn genesis() -> Storage { build_genesis_storage( &genesis_config, - asset_hub_rococo_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), + people_rococo_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), ) } diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/lib.rs index 5e6fd7fcb7b9..6ecf7fb346cb 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/lib.rs @@ -41,15 +41,13 @@ decl_test_parachains! { }, pallets = { PolkadotXcm: people_rococo_runtime::PolkadotXcm, - Assets: people_rococo_runtime::Assets, - ForeignAssets: people_rococo_runtime::ForeignAssets, - PoolAssets: people_rococo_runtime::PoolAssets, - AssetConversion: people_rococo_runtime::AssetConversion, Balances: people_rococo_runtime::Balances, + Identity: people_rococo_runtime::Identity, + IdentityMigrator: people_rococo_runtime::IdentityMigrator, } }, } // PeopleRococo implementation -impl_accounts_helpers_for_parachain!(AssetHubRococo); -impl_assert_events_helpers_for_parachain!(AssetHubRococo, false); +impl_accounts_helpers_for_parachain!(PeopleRococo); +impl_assert_events_helpers_for_parachain!(PeopleRococo, false); diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/Cargo.toml b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/Cargo.toml index b201fb5f0f06..817eb591b8a1 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/Cargo.toml @@ -18,12 +18,14 @@ pallet-balances = { path = "../../../../../../../substrate/frame/balances", defa pallet-assets = { path = "../../../../../../../substrate/frame/assets", default-features = false} pallet-asset-conversion = { path = "../../../../../../../substrate/frame/asset-conversion", default-features = false} pallet-message-queue = { path = "../../../../../../../substrate/frame/message-queue", default-features = false } +pallet-identity = { path = "../../../../../../../substrate/frame/identity", default-features = false } # Polkadot xcm = { package = "staging-xcm", path = "../../../../../../../polkadot/xcm", default-features = false} pallet-xcm = { path = "../../../../../../../polkadot/xcm/pallet-xcm", default-features = false} xcm-executor = { package = "staging-xcm-executor", path = "../../../../../../../polkadot/xcm/xcm-executor", default-features = false} rococo-runtime = { path = "../../../../../../../polkadot/runtime/rococo" } +polkadot-primitives = { path = "../../../../../../../polkadot/primitives" } # Cumulus asset-test-utils = { path = "../../../../../runtimes/assets/test-utils" } diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/mod.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/mod.rs index 516ec37cc10a..80c00021ca53 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/mod.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/mod.rs @@ -13,4 +13,5 @@ // See the License for the specific language governing permissions and // limitations under the License. +mod reap_identity; mod teleport; diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs new file mode 100644 index 000000000000..75993f38614c --- /dev/null +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -0,0 +1,23 @@ +use crate::*; +use pallet_identity::Data; +use people_rococo_runtime::{people::IdentityInfo, RuntimeOrigin}; +use rococo_runtime::MaxAdditionalFields; + +fn ten() -> IdentityInfo { + IdentityInfo { + display: Data::Raw(b"ten".to_vec().try_into().unwrap()), + legal: Data::Raw(b"The Right Ordinal Ten, Esq.".to_vec().try_into().unwrap()), + ..Default::default() + } +} + +#[test] +fn reap_identity_unreserves_deposit() { + type RuntimeEvent = ::RuntimeEvent; + let ten_info = ten(); + + assert_ok!(::Identity::set_identity( + RuntimeOrigin::signed(AccountId32::from([10; 32])), + Box::new(ten_info.clone()) + )); +} diff --git a/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs b/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs index 2b8253fece97..ff4d976a437b 100644 --- a/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs @@ -18,7 +18,7 @@ #[cfg(feature = "std")] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -mod people; +pub mod people; mod weights; pub mod xcm_config; From 92d9d63e28840c7e66f51f03bed6d0935d1fd536 Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Mon, 20 Nov 2023 16:37:21 +0000 Subject: [PATCH 004/102] parachain set identity --- .../tests/people/people-rococo/src/lib.rs | 2 +- .../people-rococo/src/tests/reap_identity.rs | 22 ++++++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/lib.rs index 5a87620fa678..32a0f23b62cb 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/lib.rs @@ -45,7 +45,7 @@ pub use emulated_integration_tests_common::{ pub use parachains_common::{AccountId, Balance}; pub use rococo_system_emulated_network::{ people_rococo_emulated_chain::{ - genesis::ED as ASSET_HUB_ROCOCO_ED, PeopleRococoParaPallet as AssetHubRococoPallet, + genesis::ED as PEOPLE_ROCOCO_ED, PeopleRococoParaPallet as PeopleRococoPallet, }, rococo_emulated_chain::{genesis::ED as ROCOCO_ED, RococoRelayPallet as RococoPallet}, PenpalAPara as PenpalA, PeopleRococoPara as PeopleRococo, diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index 75993f38614c..021c08eb92f8 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -7,17 +7,27 @@ fn ten() -> IdentityInfo { IdentityInfo { display: Data::Raw(b"ten".to_vec().try_into().unwrap()), legal: Data::Raw(b"The Right Ordinal Ten, Esq.".to_vec().try_into().unwrap()), - ..Default::default() + web: Data::Raw(b"https://ten.io".to_vec().try_into().unwrap()), + matrix: Data::Raw(b"@ten:matrix.org".to_vec().try_into().unwrap()), + email: Data::Raw(b"ten@gmail.com".to_vec().try_into().unwrap()), + pgp_fingerprint: None, + image: Data::Raw(b"ten.png".to_vec().try_into().unwrap()), + twitter: Data::Raw(b"@ten".to_vec().try_into().unwrap()), + github: Data::Raw(b"ten".to_vec().try_into().unwrap()), + discord: Data::Raw(b"ten#0000".to_vec().try_into().unwrap()), } } #[test] -fn reap_identity_unreserves_deposit() { +fn parachain_set_identity() { + // Init values for System Parachain type RuntimeEvent = ::RuntimeEvent; let ten_info = ten(); - assert_ok!(::Identity::set_identity( - RuntimeOrigin::signed(AccountId32::from([10; 32])), - Box::new(ten_info.clone()) - )); + PeopleRococo::execute_with(|| { + assert_ok!(::Identity::set_identity( + RuntimeOrigin::signed(PeopleRococoSender::get()), + Box::new(ten_info.clone()) + )); + }); } From 1908d75d16d547b0fd975a82d9e857ce11c4def9 Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Mon, 20 Nov 2023 17:19:38 +0000 Subject: [PATCH 005/102] assert has_idenity --- .../people/people-rococo/src/lib.rs | 3 +- .../tests/people/people-rococo/src/lib.rs | 5 +- .../people-rococo/src/tests/reap_identity.rs | 47 ++++++++++++++----- 3 files changed, 38 insertions(+), 17 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/lib.rs index 6ecf7fb346cb..1b17862d24db 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/lib.rs @@ -21,8 +21,7 @@ use frame_support::traits::OnInitialize; // Cumulus use emulated_integration_tests_common::{ impl_accounts_helpers_for_parachain, impl_assert_events_helpers_for_parachain, - impl_assets_helpers_for_parachain, impl_foreign_assets_helpers_for_parachain, impls::Parachain, - xcm_emulator::decl_test_parachains, + impls::Parachain, xcm_emulator::decl_test_parachains, }; use rococo_emulated_chain::Rococo; diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/lib.rs index 32a0f23b62cb..cec1e23c9fbd 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/lib.rs @@ -13,8 +13,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -mod tests; - pub use codec::Encode; // Substrate @@ -59,3 +57,6 @@ pub type RelayToParaTest = Test; pub type SystemParaToRelayTest = Test; pub type SystemParaToParaTest = Test; pub type ParaToSystemParaTest = Test; + +#[cfg(test)] +mod tests; diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index 021c08eb92f8..f6c474128777 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -1,33 +1,54 @@ use crate::*; use pallet_identity::Data; -use people_rococo_runtime::{people::IdentityInfo, RuntimeOrigin}; +use people_rococo_runtime::{ + people::{IdentityField, IdentityInfo}, + RuntimeOrigin, +}; use rococo_runtime::MaxAdditionalFields; fn ten() -> IdentityInfo { IdentityInfo { - display: Data::Raw(b"ten".to_vec().try_into().unwrap()), - legal: Data::Raw(b"The Right Ordinal Ten, Esq.".to_vec().try_into().unwrap()), - web: Data::Raw(b"https://ten.io".to_vec().try_into().unwrap()), - matrix: Data::Raw(b"@ten:matrix.org".to_vec().try_into().unwrap()), - email: Data::Raw(b"ten@gmail.com".to_vec().try_into().unwrap()), + display: Data::Raw(b"xcm-test".to_vec().try_into().unwrap()), + legal: Data::Raw(b"The Right Ordinal Xcm Test, Esq.".to_vec().try_into().unwrap()), + web: Data::Raw(b"https://xcm-test.io".to_vec().try_into().unwrap()), + matrix: Data::Raw(b"@xcm-test:matrix.org".to_vec().try_into().unwrap()), + email: Data::Raw(b"xcm-test@gmail.com".to_vec().try_into().unwrap()), pgp_fingerprint: None, - image: Data::Raw(b"ten.png".to_vec().try_into().unwrap()), - twitter: Data::Raw(b"@ten".to_vec().try_into().unwrap()), - github: Data::Raw(b"ten".to_vec().try_into().unwrap()), - discord: Data::Raw(b"ten#0000".to_vec().try_into().unwrap()), + image: Data::Raw(b"xcm-test.png".to_vec().try_into().unwrap()), + twitter: Data::Raw(b"@xcm-test".to_vec().try_into().unwrap()), + github: Data::Raw(b"xcm-test".to_vec().try_into().unwrap()), + discord: Data::Raw(b"xcm-test#0042".to_vec().try_into().unwrap()), } } #[test] fn parachain_set_identity() { - // Init values for System Parachain - type RuntimeEvent = ::RuntimeEvent; let ten_info = ten(); - PeopleRococo::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; assert_ok!(::Identity::set_identity( RuntimeOrigin::signed(PeopleRococoSender::get()), Box::new(ten_info.clone()) )); + + assert_expected_events!( + PeopleRococo, + vec![ + RuntimeEvent::Identity(pallet_identity::Event::IdentitySet { ..}) => {}, + ] + ); + + assert!(::Identity::has_identity( + &PeopleRococoSender::get(), + IdentityField::Display as u64, + )); + assert!(::Identity::has_identity( + &PeopleRococoSender::get(), + IdentityField::Legal as u64, + )); + assert!(::Identity::has_identity( + &PeopleRococoSender::get(), + IdentityField::Web as u64, + )); }); } From 7d201534bc42c490e8b9c6e88d0ba67acbe2e14f Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Mon, 20 Nov 2023 19:15:42 +0000 Subject: [PATCH 006/102] reap identity --- .../people-rococo/src/tests/reap_identity.rs | 58 +++++++++++++++++-- polkadot/xcm/procedural/tests/ui.rs | 2 +- .../src/chain_head/subscription/inner.rs | 2 +- .../utils/wasm-builder/src/wasm_project.rs | 2 +- 4 files changed, 57 insertions(+), 7 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index f6c474128777..f0b8e7b007fc 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -1,12 +1,12 @@ use crate::*; use pallet_identity::Data; +use people_rococo_runtime::people::{BasicDeposit, ByteDeposit, SubAccountDeposit}; use people_rococo_runtime::{ people::{IdentityField, IdentityInfo}, RuntimeOrigin, }; -use rococo_runtime::MaxAdditionalFields; -fn ten() -> IdentityInfo { +fn identity() -> IdentityInfo { IdentityInfo { display: Data::Raw(b"xcm-test".to_vec().try_into().unwrap()), legal: Data::Raw(b"The Right Ordinal Xcm Test, Esq.".to_vec().try_into().unwrap()), @@ -21,14 +21,21 @@ fn ten() -> IdentityInfo { } } +fn deposit(id: &IdentityInfo) -> u64 { + let base_deposit: u64 = BasicDeposit::get() as u64; + let byte_deposit: u64 = + ByteDeposit::get() as u64 * TryInto::::try_into(id.encoded_size()).unwrap(); + base_deposit + byte_deposit +} + #[test] fn parachain_set_identity() { - let ten_info = ten(); + let ident_info = identity(); PeopleRococo::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; assert_ok!(::Identity::set_identity( RuntimeOrigin::signed(PeopleRococoSender::get()), - Box::new(ten_info.clone()) + Box::new(ident_info.clone()) )); assert_expected_events!( @@ -52,3 +59,46 @@ fn parachain_set_identity() { )); }); } + +#[test] +fn reap_identity() { + let ident_info = identity(); + let id_deposit = deposit(&ident_info); + let subs_deposit = SubAccountDeposit::get() as u64; + PeopleRococo::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + + let bal_before = + ::Balances::free_balance(PeopleRococoSender::get()); + println!("bal_before: {}", bal_before); + + // 1. Set the identity + assert_ok!(::Identity::set_identity( + RuntimeOrigin::signed(PeopleRococoSender::get()), + Box::new(ident_info.clone()) + )); + + // 2. Set the subs + assert_ok!(::Identity::set_subs( + RuntimeOrigin::signed(PeopleRococoSender::get()), + vec![(PeopleRococoSender::get(), Data::Raw(vec![40; 1].try_into().unwrap()))] + )); + + let bal_after_set_subs = + ::Balances::free_balance(PeopleRococoSender::get()); + assert_eq!(bal_after_set_subs, (bal_before as u64 - id_deposit - subs_deposit).into()); + + // 3. Reap the identity + assert_ok!(::Identity::reap_identity( + &PeopleRococoSender::get() + )); + assert!(::Identity::identity( + &PeopleRococoSender::get() + ) + .is_none()); + + let bal_after_reap = + ::Balances::free_balance(PeopleRococoSender::get()); + assert_eq!(bal_after_reap, bal_before); // no change in free balance, deposits were refunded by reap + }); +} diff --git a/polkadot/xcm/procedural/tests/ui.rs b/polkadot/xcm/procedural/tests/ui.rs index a6ec35d0862a..fef7c95c6142 100644 --- a/polkadot/xcm/procedural/tests/ui.rs +++ b/polkadot/xcm/procedural/tests/ui.rs @@ -21,7 +21,7 @@ fn ui() { // Only run the ui tests when `RUN_UI_TESTS` is set. if std::env::var("RUN_UI_TESTS").is_err() { - return; + return } // As trybuild is using `cargo check`, we don't need the real WASM binaries. diff --git a/substrate/client/rpc-spec-v2/src/chain_head/subscription/inner.rs b/substrate/client/rpc-spec-v2/src/chain_head/subscription/inner.rs index abd42ad96785..2b250f3dc2cf 100644 --- a/substrate/client/rpc-spec-v2/src/chain_head/subscription/inner.rs +++ b/substrate/client/rpc-spec-v2/src/chain_head/subscription/inner.rs @@ -763,7 +763,7 @@ impl> SubscriptionsInner { // blocks. for hash in hashes.clone() { if !sub.contains_block(hash) { - return Err(SubscriptionManagementError::BlockHashAbsent); + return Err(SubscriptionManagementError::BlockHashAbsent) } } diff --git a/substrate/utils/wasm-builder/src/wasm_project.rs b/substrate/utils/wasm-builder/src/wasm_project.rs index 2e6f671c45ed..9c25d1aba3cf 100644 --- a/substrate/utils/wasm-builder/src/wasm_project.rs +++ b/substrate/utils/wasm-builder/src/wasm_project.rs @@ -916,7 +916,7 @@ fn generate_rerun_if_changed_instructions( while let Some(dependency) = dependencies.pop() { // Ignore all dev dependencies if dependency.kind == DependencyKind::Development { - continue; + continue } let path_or_git_dep = From dffefa1072a01775bc866f5f485329f52e58f223 Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Mon, 20 Nov 2023 23:04:19 +0000 Subject: [PATCH 007/102] updates xcm tests --- .../emulated/chains/relays/rococo/src/lib.rs | 1 + .../people-rococo/src/tests/identity.rs | 137 ++++++++++++++++++ .../people/people-rococo/src/tests/mod.rs | 2 +- .../people-rococo/src/tests/reap_identity.rs | 104 ------------- 4 files changed, 139 insertions(+), 105 deletions(-) create mode 100644 cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/identity.rs delete mode 100644 cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs diff --git a/cumulus/parachains/integration-tests/emulated/chains/relays/rococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/chains/relays/rococo/src/lib.rs index 7ace96147106..573c14c3f79b 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/relays/rococo/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/relays/rococo/src/lib.rs @@ -37,6 +37,7 @@ decl_test_relay_chains! { Sudo: rococo_runtime::Sudo, Balances: rococo_runtime::Balances, Hrmp: rococo_runtime::Hrmp, + Identity: rococo_runtime::Identity, } }, } diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/identity.rs new file mode 100644 index 000000000000..aabdfe49ad1f --- /dev/null +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/identity.rs @@ -0,0 +1,137 @@ +use crate::*; +use emulated_integration_tests_common::xcm_emulator::Get; +use pallet_identity::{legacy::IdentityInfo, Data}; +use people_rococo_runtime::people::IdentityInfo as IdentityInfoParachain; +use people_rococo_runtime::people::{BasicDeposit, ByteDeposit, SubAccountDeposit}; +use rococo_runtime::MaxAdditionalFields; +use rococo_system_emulated_network::rococo_emulated_chain::RococoRelayPallet; +use rococo_system_emulated_network::{RococoRelay, RococoRelaySender}; +use sp_runtime::BoundedVec; + +fn identity_relay() -> IdentityInfo { + IdentityInfo { + display: Data::Raw(b"xcm-test".to_vec().try_into().unwrap()), + additional: Default::default(), + legal: Default::default(), + web: Default::default(), + riot: Default::default(), + email: Default::default(), + pgp_fingerprint: None, + image: Default::default(), + twitter: Default::default(), + } +} + +fn identity_parachain() -> IdentityInfoParachain { + IdentityInfoParachain { + display: Data::Raw(b"xcm-test".to_vec().try_into().unwrap()), + legal: Data::Raw(b"The Right Ordinal Xcm Test, Esq.".to_vec().try_into().unwrap()), + web: Data::Raw(b"https://xcm-test.io".to_vec().try_into().unwrap()), + matrix: Data::Raw(b"@xcm-test:matrix.org".to_vec().try_into().unwrap()), + email: Data::Raw(b"xcm-test@gmail.com".to_vec().try_into().unwrap()), + pgp_fingerprint: None, + image: Data::Raw(b"xcm-test.png".to_vec().try_into().unwrap()), + twitter: Data::Raw(b"@xcm-test".to_vec().try_into().unwrap()), + github: Data::Raw(b"xcm-test".to_vec().try_into().unwrap()), + discord: Data::Raw(b"xcm-test#0042".to_vec().try_into().unwrap()), + } +} + +#[test] +fn reap_identity() { + let mut bal_before: Balance = 0_u128; + + // Set identity and Subs on Relay Chain + RococoRelay::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + + // 1. Set identity on Relay Chain + assert_ok!(::Identity::set_identity( + rococo_runtime::RuntimeOrigin::signed(RococoRelaySender::get()), + Box::new(identity_relay()) + )); + assert_expected_events!( + RococoRelay, + vec![ + RuntimeEvent::Identity(pallet_identity::Event::IdentitySet { .. }) => {}, + ] + ); + + // 2. Set sub-identity on Relay Chain + assert_ok!(::Identity::set_subs( + rococo_runtime::RuntimeOrigin::signed(RococoRelaySender::get()), + vec![(RococoRelaySender::get(), Data::Raw(vec![40; 1].try_into().unwrap()))], + )); + assert_expected_events!( + RococoRelay, + vec![ + RuntimeEvent::Balances(pallet_balances::Event::Reserved { .. }) => {}, + RuntimeEvent::Identity(pallet_identity::Event::IdentitySet { .. }) => {}, + RuntimeEvent::Balances(pallet_balances::Event::Reserved { .. }) => {}, + ] + ); + }); + + // Set identity and Subs on Parachain with zero deposit + PeopleRococo::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + + bal_before = + ::Balances::free_balance(PeopleRococoSender::get()); + + // 3. Set identity on Parachain + assert_ok!(::Identity::set_identity( + people_rococo_runtime::RuntimeOrigin::signed(PeopleRococoSender::get()), + Box::new(identity_parachain()) + )); + assert_expected_events!( + PeopleRococo, + vec![ + RuntimeEvent::Identity(pallet_identity::Event::IdentitySet { .. }) => {}, + ] + ); + + // 4. Set sub-identity on Parachain + assert_ok!(::Identity::set_subs( + people_rococo_runtime::RuntimeOrigin::signed(PeopleRococoSender::get()), + vec![(PeopleRococoSender::get(), Data::Raw(vec![0; 1].try_into().unwrap()))], + )); + assert_expected_events!( + PeopleRococo, + vec![ + RuntimeEvent::Balances(pallet_balances::Event::Reserved { .. }) => {}, + RuntimeEvent::Identity(pallet_identity::Event::IdentitySet { .. }) => {}, + RuntimeEvent::Balances(pallet_balances::Event::Reserved { .. }) => {}, + ] + ); + }); + + // reap_identity on Relay Chain + RococoRelay::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + + let bal_before = + ::Balances::free_balance(PeopleRococoSender::get()); + + // 5. Reap identity on Parachain + assert_ok!(::Identity::reap_identity( + &RococoRelaySender::get(), + )); + assert_expected_events!( + RococoRelay, + vec![ + RuntimeEvent::Balances(pallet_balances::Event::Unreserved { .. }) => {}, + ] + ); + assert!(::Identity::identity(&RococoRelaySender::get()) + .is_none()); + }); + + // verify deposits on Parachain + PeopleRococo::execute_with(|| { + let bal_after = + ::Balances::free_balance(PeopleRococoSender::get()); + let deposit_amount = bal_after - bal_before; + assert_eq!(deposit_amount, 0); + }); +} diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/mod.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/mod.rs index 80c00021ca53..2ec0f59c93ce 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/mod.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/mod.rs @@ -13,5 +13,5 @@ // See the License for the specific language governing permissions and // limitations under the License. -mod reap_identity; +mod identity; mod teleport; diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs deleted file mode 100644 index f0b8e7b007fc..000000000000 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ /dev/null @@ -1,104 +0,0 @@ -use crate::*; -use pallet_identity::Data; -use people_rococo_runtime::people::{BasicDeposit, ByteDeposit, SubAccountDeposit}; -use people_rococo_runtime::{ - people::{IdentityField, IdentityInfo}, - RuntimeOrigin, -}; - -fn identity() -> IdentityInfo { - IdentityInfo { - display: Data::Raw(b"xcm-test".to_vec().try_into().unwrap()), - legal: Data::Raw(b"The Right Ordinal Xcm Test, Esq.".to_vec().try_into().unwrap()), - web: Data::Raw(b"https://xcm-test.io".to_vec().try_into().unwrap()), - matrix: Data::Raw(b"@xcm-test:matrix.org".to_vec().try_into().unwrap()), - email: Data::Raw(b"xcm-test@gmail.com".to_vec().try_into().unwrap()), - pgp_fingerprint: None, - image: Data::Raw(b"xcm-test.png".to_vec().try_into().unwrap()), - twitter: Data::Raw(b"@xcm-test".to_vec().try_into().unwrap()), - github: Data::Raw(b"xcm-test".to_vec().try_into().unwrap()), - discord: Data::Raw(b"xcm-test#0042".to_vec().try_into().unwrap()), - } -} - -fn deposit(id: &IdentityInfo) -> u64 { - let base_deposit: u64 = BasicDeposit::get() as u64; - let byte_deposit: u64 = - ByteDeposit::get() as u64 * TryInto::::try_into(id.encoded_size()).unwrap(); - base_deposit + byte_deposit -} - -#[test] -fn parachain_set_identity() { - let ident_info = identity(); - PeopleRococo::execute_with(|| { - type RuntimeEvent = ::RuntimeEvent; - assert_ok!(::Identity::set_identity( - RuntimeOrigin::signed(PeopleRococoSender::get()), - Box::new(ident_info.clone()) - )); - - assert_expected_events!( - PeopleRococo, - vec![ - RuntimeEvent::Identity(pallet_identity::Event::IdentitySet { ..}) => {}, - ] - ); - - assert!(::Identity::has_identity( - &PeopleRococoSender::get(), - IdentityField::Display as u64, - )); - assert!(::Identity::has_identity( - &PeopleRococoSender::get(), - IdentityField::Legal as u64, - )); - assert!(::Identity::has_identity( - &PeopleRococoSender::get(), - IdentityField::Web as u64, - )); - }); -} - -#[test] -fn reap_identity() { - let ident_info = identity(); - let id_deposit = deposit(&ident_info); - let subs_deposit = SubAccountDeposit::get() as u64; - PeopleRococo::execute_with(|| { - type RuntimeEvent = ::RuntimeEvent; - - let bal_before = - ::Balances::free_balance(PeopleRococoSender::get()); - println!("bal_before: {}", bal_before); - - // 1. Set the identity - assert_ok!(::Identity::set_identity( - RuntimeOrigin::signed(PeopleRococoSender::get()), - Box::new(ident_info.clone()) - )); - - // 2. Set the subs - assert_ok!(::Identity::set_subs( - RuntimeOrigin::signed(PeopleRococoSender::get()), - vec![(PeopleRococoSender::get(), Data::Raw(vec![40; 1].try_into().unwrap()))] - )); - - let bal_after_set_subs = - ::Balances::free_balance(PeopleRococoSender::get()); - assert_eq!(bal_after_set_subs, (bal_before as u64 - id_deposit - subs_deposit).into()); - - // 3. Reap the identity - assert_ok!(::Identity::reap_identity( - &PeopleRococoSender::get() - )); - assert!(::Identity::identity( - &PeopleRococoSender::get() - ) - .is_none()); - - let bal_after_reap = - ::Balances::free_balance(PeopleRococoSender::get()); - assert_eq!(bal_after_reap, bal_before); // no change in free balance, deposits were refunded by reap - }); -} From cebde915d942ef908c1ecb6ddc504b5e2bb3be67 Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Mon, 20 Nov 2023 23:29:25 +0000 Subject: [PATCH 008/102] assert deposit amount non zero --- .../emulated/tests/people/people-rococo/src/tests/mod.rs | 2 +- .../src/tests/{identity.rs => reap_identity.rs} | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) rename cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/{identity.rs => reap_identity.rs} (96%) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/mod.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/mod.rs index 2ec0f59c93ce..80c00021ca53 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/mod.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/mod.rs @@ -13,5 +13,5 @@ // See the License for the specific language governing permissions and // limitations under the License. -mod identity; +mod reap_identity; mod teleport; diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs similarity index 96% rename from cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/identity.rs rename to cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index aabdfe49ad1f..4ad34009d843 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -2,11 +2,9 @@ use crate::*; use emulated_integration_tests_common::xcm_emulator::Get; use pallet_identity::{legacy::IdentityInfo, Data}; use people_rococo_runtime::people::IdentityInfo as IdentityInfoParachain; -use people_rococo_runtime::people::{BasicDeposit, ByteDeposit, SubAccountDeposit}; use rococo_runtime::MaxAdditionalFields; use rococo_system_emulated_network::rococo_emulated_chain::RococoRelayPallet; use rococo_system_emulated_network::{RococoRelay, RococoRelaySender}; -use sp_runtime::BoundedVec; fn identity_relay() -> IdentityInfo { IdentityInfo { @@ -131,7 +129,7 @@ fn reap_identity() { PeopleRococo::execute_with(|| { let bal_after = ::Balances::free_balance(PeopleRococoSender::get()); - let deposit_amount = bal_after - bal_before; - assert_eq!(deposit_amount, 0); + let deposit_amount = bal_before - bal_after; + assert!(deposit_amount as u64 > 0); }); } From 84e6ed50ef8272691217af9c1053f9d63265a482 Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Tue, 21 Nov 2023 15:24:22 +0000 Subject: [PATCH 009/102] set identity zero deposit --- .../people-rococo/src/tests/reap_identity.rs | 81 ++++++++++++------- substrate/frame/identity/src/lib.rs | 27 ++++--- 2 files changed, 67 insertions(+), 41 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index 4ad34009d843..5939cae65cee 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -1,10 +1,16 @@ use crate::*; use emulated_integration_tests_common::xcm_emulator::Get; -use pallet_identity::{legacy::IdentityInfo, Data}; +use frame_support::pallet_prelude::ConstU32; +use frame_support::BoundedVec; +use pallet_identity::{ + legacy::IdentityInfo, types::Registration, Data, IdentityOf, SubsOf, SuperOf, +}; use people_rococo_runtime::people::IdentityInfo as IdentityInfoParachain; +use people_rococo_runtime::IdentityMigrator; use rococo_runtime::MaxAdditionalFields; use rococo_system_emulated_network::rococo_emulated_chain::RococoRelayPallet; use rococo_system_emulated_network::{RococoRelay, RococoRelaySender}; +use sp_runtime::traits::Zero; fn identity_relay() -> IdentityInfo { IdentityInfo { @@ -37,12 +43,23 @@ fn identity_parachain() -> IdentityInfoParachain { #[test] fn reap_identity() { - let mut bal_before: Balance = 0_u128; + let mut bal_before_relaychain: Balance = 0_u128; + let mut bal_after_relaychain: Balance = 0_u128; + let mut relay_chain_fee: Balance = 0_u128; + + let mut bal_before_parachain: Balance = 0_u128; + let mut bal_after_parachain: Balance = 0_u128; + let mut parachain_fee: Balance = 0_u128; + + let identity_info = identity_parachain(); // Set identity and Subs on Relay Chain RococoRelay::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; + bal_before_relaychain = + ::Balances::free_balance(RococoRelaySender::get()); + // 1. Set identity on Relay Chain assert_ok!(::Identity::set_identity( rococo_runtime::RuntimeOrigin::signed(RococoRelaySender::get()), @@ -68,27 +85,37 @@ fn reap_identity() { RuntimeEvent::Balances(pallet_balances::Event::Reserved { .. }) => {}, ] ); + + bal_after_relaychain = + ::Balances::free_balance(RococoRelaySender::get()); + println!( + "Balances: Relaychain before: {}, Relaychain after: {}", + bal_before_relaychain, bal_after_relaychain + ); + relay_chain_fee = bal_before_relaychain - bal_after_relaychain; + println!("Relay Chain Fee: {}", relay_chain_fee); }); - // Set identity and Subs on Parachain with zero deposit + // Set identity and Subs on Parachain with Zero deposit PeopleRococo::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; - bal_before = + bal_before_parachain = ::Balances::free_balance(PeopleRococoSender::get()); - // 3. Set identity on Parachain - assert_ok!(::Identity::set_identity( - people_rococo_runtime::RuntimeOrigin::signed(PeopleRococoSender::get()), - Box::new(identity_parachain()) - )); - assert_expected_events!( - PeopleRococo, - vec![ - RuntimeEvent::Identity(pallet_identity::Event::IdentitySet { .. }) => {}, - ] + let bal_after_mutate = + ::Balances::free_balance(PeopleRococoSender::get()); + println!( + "Balances: Parachain before: {}, Parachain after: {}", + bal_before_parachain, bal_after_mutate ); + // 3. Set identity on Parachain with zero deposit + assert_ok!(::Identity::set_identity_no_deposit( + &PeopleRococoSender::get(), + identity_parachain() + )); + // 4. Set sub-identity on Parachain assert_ok!(::Identity::set_subs( people_rococo_runtime::RuntimeOrigin::signed(PeopleRococoSender::get()), @@ -98,20 +125,24 @@ fn reap_identity() { PeopleRococo, vec![ RuntimeEvent::Balances(pallet_balances::Event::Reserved { .. }) => {}, - RuntimeEvent::Identity(pallet_identity::Event::IdentitySet { .. }) => {}, - RuntimeEvent::Balances(pallet_balances::Event::Reserved { .. }) => {}, ] ); + + bal_after_parachain = + ::Balances::free_balance(PeopleRococoSender::get()); + println!( + "Balances: Parachain before: {}, Parachain after: {}", + bal_before_parachain, bal_after_parachain + ); + parachain_fee = bal_before_parachain - bal_after_parachain; + println!("Parachain Fee: {}", parachain_fee); }); // reap_identity on Relay Chain RococoRelay::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; - let bal_before = - ::Balances::free_balance(PeopleRococoSender::get()); - - // 5. Reap identity on Parachain + // 5. Reap identity on Relaychain assert_ok!(::Identity::reap_identity( &RococoRelaySender::get(), )); @@ -123,13 +154,7 @@ fn reap_identity() { ); assert!(::Identity::identity(&RococoRelaySender::get()) .is_none()); - }); - - // verify deposits on Parachain - PeopleRococo::execute_with(|| { - let bal_after = - ::Balances::free_balance(PeopleRococoSender::get()); - let deposit_amount = bal_before - bal_after; - assert!(deposit_amount as u64 > 0); + assert!(::Identity::super_of(&RococoRelaySender::get()) + .is_none()); }); } diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index 133f9eeb4bef..492b088e94ca 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -76,7 +76,7 @@ mod benchmarking; pub mod legacy; #[cfg(test)] mod tests; -mod types; +pub mod types; pub mod weights; use codec::Encode; @@ -162,7 +162,7 @@ pub mod pallet { /// TWOX-NOTE: OK ― `AccountId` is a secure hash. #[pallet::storage] #[pallet::getter(fn identity)] - pub(super) type IdentityOf = StorageMap< + pub type IdentityOf = StorageMap< _, Twox64Concat, T::AccountId, @@ -174,7 +174,7 @@ pub mod pallet { /// context. If the account is not some other account's sub-identity, then just `None`. #[pallet::storage] #[pallet::getter(fn super_of)] - pub(super) type SuperOf = + pub type SuperOf = StorageMap<_, Blake2_128Concat, T::AccountId, (T::AccountId, Data), OptionQuery>; /// Alternative "sub" identities of this account. @@ -184,7 +184,7 @@ pub mod pallet { /// TWOX-NOTE: OK ― `AccountId` is a secure hash. #[pallet::storage] #[pallet::getter(fn subs_of)] - pub(super) type SubsOf = StorageMap< + pub type SubsOf = StorageMap< _, Twox64Concat, T::AccountId, @@ -505,14 +505,16 @@ pub mod pallet { let item = (reg_index, Judgement::FeePaid(registrar.fee)); match id.judgements.binary_search_by_key(®_index, |x| x.0) { - Ok(i) => + Ok(i) => { if id.judgements[i].1.is_sticky() { - return Err(Error::::StickyJudgement.into()) + return Err(Error::::StickyJudgement.into()); } else { id.judgements[i] = item - }, - Err(i) => - id.judgements.try_insert(i, item).map_err(|_| Error::::TooManyRegistrars)?, + } + }, + Err(i) => { + id.judgements.try_insert(i, item).map_err(|_| Error::::TooManyRegistrars)? + }, } T::Currency::reserve(&sender, registrar.fee)?; @@ -554,7 +556,7 @@ pub mod pallet { let fee = if let Judgement::FeePaid(fee) = id.judgements.remove(pos).1 { fee } else { - return Err(Error::::JudgementGiven.into()) + return Err(Error::::JudgementGiven.into()); }; let err_amount = T::Currency::unreserve(&sender, fee); @@ -700,7 +702,7 @@ pub mod pallet { let mut id = >::get(&target).ok_or(Error::::InvalidTarget)?; if T::Hashing::hash_of(&id.info) != identity { - return Err(Error::::JudgementForDifferentIdentity.into()) + return Err(Error::::JudgementForDifferentIdentity.into()); } let item = (reg_index, judgement); @@ -1005,8 +1007,7 @@ impl Pallet { Ok((new_id_deposit, new_subs_deposit)) } - /// Set an identity with zero deposit. Only used for benchmarking that involves `rejig_deposit`. - #[cfg(feature = "runtime-benchmarks")] + /// Set an identity with zero deposit. Used for benchmarking and XCM emulator tests, involves `rejig_deposit`. pub fn set_identity_no_deposit( who: &T::AccountId, info: T::IdentityInformation, From a7620933ae55d6e0080e03c17cd35821ba0deb36 Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Tue, 21 Nov 2023 17:55:21 +0000 Subject: [PATCH 010/102] add test args --- .../tests/people/people-rococo/src/lib.rs | 37 +++ .../people-rococo/src/tests/reap_identity.rs | 52 +--- .../people-rococo/src/tests/teleport.rs | 258 ++++++++++++++++++ 3 files changed, 310 insertions(+), 37 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/lib.rs index cec1e23c9fbd..1c2f50452638 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/lib.rs @@ -58,5 +58,42 @@ pub type SystemParaToRelayTest = Test; pub type SystemParaToParaTest = Test; pub type ParaToSystemParaTest = Test; +/// Returns a `TestArgs` instance to be used for the Relay Chain across integration tests +pub fn relay_test_args( + dest: MultiLocation, + beneficiary_id: AccountId32, + amount: Balance, +) -> TestArgs { + TestArgs { + dest, + beneficiary: AccountId32Junction { network: None, id: beneficiary_id.into() }.into(), + amount, + assets: (Here, amount).into(), + asset_id: None, + fee_asset_item: 0, + weight_limit: WeightLimit::Unlimited, + } +} + +/// Returns a `TestArgs` instance to be used by parachains across integration tests +pub fn para_test_args( + dest: MultiLocation, + beneficiary_id: AccountId32, + amount: Balance, + assets: MultiAssets, + asset_id: Option, + fee_asset_item: u32, +) -> TestArgs { + TestArgs { + dest, + beneficiary: AccountId32Junction { network: None, id: beneficiary_id.into() }.into(), + amount, + assets, + asset_id, + fee_asset_item, + weight_limit: WeightLimit::Unlimited, + } +} + #[cfg(test)] mod tests; diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index 5939cae65cee..11c5bec7a255 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -1,16 +1,11 @@ use crate::*; use emulated_integration_tests_common::xcm_emulator::Get; -use frame_support::pallet_prelude::ConstU32; -use frame_support::BoundedVec; -use pallet_identity::{ - legacy::IdentityInfo, types::Registration, Data, IdentityOf, SubsOf, SuperOf, -}; +use pallet_identity::{legacy::IdentityInfo, Data}; use people_rococo_runtime::people::IdentityInfo as IdentityInfoParachain; -use people_rococo_runtime::IdentityMigrator; use rococo_runtime::MaxAdditionalFields; -use rococo_system_emulated_network::rococo_emulated_chain::RococoRelayPallet; -use rococo_system_emulated_network::{RococoRelay, RococoRelaySender}; -use sp_runtime::traits::Zero; +use rococo_system_emulated_network::{ + rococo_emulated_chain::RococoRelayPallet, RococoRelay, RococoRelaySender, +}; fn identity_relay() -> IdentityInfo { IdentityInfo { @@ -45,13 +40,12 @@ fn identity_parachain() -> IdentityInfoParachain { fn reap_identity() { let mut bal_before_relaychain: Balance = 0_u128; let mut bal_after_relaychain: Balance = 0_u128; - let mut relay_chain_fee: Balance = 0_u128; let mut bal_before_parachain: Balance = 0_u128; let mut bal_after_parachain: Balance = 0_u128; - let mut parachain_fee: Balance = 0_u128; - let identity_info = identity_parachain(); + let identity_relaychain = identity_relay(); + let identity_parachain = identity_parachain(); // Set identity and Subs on Relay Chain RococoRelay::execute_with(|| { @@ -63,7 +57,7 @@ fn reap_identity() { // 1. Set identity on Relay Chain assert_ok!(::Identity::set_identity( rococo_runtime::RuntimeOrigin::signed(RococoRelaySender::get()), - Box::new(identity_relay()) + Box::new(identity_relaychain) )); assert_expected_events!( RococoRelay, @@ -88,12 +82,6 @@ fn reap_identity() { bal_after_relaychain = ::Balances::free_balance(RococoRelaySender::get()); - println!( - "Balances: Relaychain before: {}, Relaychain after: {}", - bal_before_relaychain, bal_after_relaychain - ); - relay_chain_fee = bal_before_relaychain - bal_after_relaychain; - println!("Relay Chain Fee: {}", relay_chain_fee); }); // Set identity and Subs on Parachain with Zero deposit @@ -103,23 +91,16 @@ fn reap_identity() { bal_before_parachain = ::Balances::free_balance(PeopleRococoSender::get()); - let bal_after_mutate = - ::Balances::free_balance(PeopleRococoSender::get()); - println!( - "Balances: Parachain before: {}, Parachain after: {}", - bal_before_parachain, bal_after_mutate - ); - // 3. Set identity on Parachain with zero deposit assert_ok!(::Identity::set_identity_no_deposit( &PeopleRococoSender::get(), - identity_parachain() + identity_parachain.clone() )); // 4. Set sub-identity on Parachain assert_ok!(::Identity::set_subs( people_rococo_runtime::RuntimeOrigin::signed(PeopleRococoSender::get()), - vec![(PeopleRococoSender::get(), Data::Raw(vec![0; 1].try_into().unwrap()))], + vec![(PeopleRococoSender::get(), Data::Raw(vec![40; 1].try_into().unwrap()))], )); assert_expected_events!( PeopleRococo, @@ -130,19 +111,13 @@ fn reap_identity() { bal_after_parachain = ::Balances::free_balance(PeopleRococoSender::get()); - println!( - "Balances: Parachain before: {}, Parachain after: {}", - bal_before_parachain, bal_after_parachain - ); - parachain_fee = bal_before_parachain - bal_after_parachain; - println!("Parachain Fee: {}", parachain_fee); + let fees = bal_before_parachain - bal_after_parachain; + assert_eq!(bal_before_parachain - fees, bal_after_parachain); }); - // reap_identity on Relay Chain + // 5. reap_identity on Relay Chain RococoRelay::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; - - // 5. Reap identity on Relaychain assert_ok!(::Identity::reap_identity( &RococoRelaySender::get(), )); @@ -156,5 +131,8 @@ fn reap_identity() { .is_none()); assert!(::Identity::super_of(&RococoRelaySender::get()) .is_none()); + let bal_after_reap = + ::Balances::free_balance(RococoRelaySender::get()); + assert_eq!(bal_after_reap, bal_before_relaychain) }); } diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs index 304002a75093..0d1a8e54963b 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs @@ -152,3 +152,261 @@ fn system_para_teleport_assets(t: SystemParaToRelayTest) -> DispatchResult { t.args.fee_asset_item, ) } + +/// Limited Teleport of native asset from Relay Chain to the System Parachain should work +#[test] +fn limited_teleport_native_assets_from_relay_to_system_para_works() { + // Init values for Relay Chain + let amount_to_send: Balance = ROCOCO_ED * 1000; + let dest = Rococo::child_location_of(PeopleRococo::para_id()); + let beneficiary_id = PeopleRococoReceiver::get(); + let test_args = TestContext { + sender: RococoSender::get(), + receiver: PeopleRococoReceiver::get(), + args: relay_test_args(dest, beneficiary_id, amount_to_send), + }; + + let mut test = RelayToSystemParaTest::new(test_args); + + let sender_balance_before = test.sender.balance; + let receiver_balance_before = test.receiver.balance; + + test.set_assertion::(relay_origin_assertions); + test.set_assertion::(para_dest_assertions); + test.set_dispatchable::(relay_limited_teleport_assets); + + let delivery_fees = Rococo::execute_with(|| { + xcm_helpers::transfer_assets_delivery_fees::< + ::XcmSender, + >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) + }); + + let sender_balance_after = test.sender.balance; + let receiver_balance_after = test.receiver.balance; + + // Sender's balance is reduced + assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); + // Receiver's balance is increased + assert!(receiver_balance_after > receiver_balance_before); +} + +/// Limited Teleport of native asset from System Parachain to Relay Chain +/// should work when there is enough balance in Relay Chain's `CheckAccount` +#[test] +fn limited_teleport_native_assets_back_from_system_para_to_relay_works() { + // Dependency - Relay Chain's `CheckAccount` should have enough balance + limited_teleport_native_assets_from_relay_to_system_para_works(); + + // Init values for Relay Chain + let amount_to_send: Balance = PEOPLE_ROCOCO_ED * 1000; + let destination = PeopleRococo::parent_location(); + let beneficiary_id = RococoReceiver::get(); + let assets = (Parent, amount_to_send).into(); + + let test_args = TestContext { + sender: PeopleRococoSender::get(), + receiver: RococoReceiver::get(), + args: para_test_args(destination, beneficiary_id, amount_to_send, assets, None, 0), + }; + + let mut test = SystemParaToRelayTest::new(test_args); + + let sender_balance_before = test.sender.balance; + let receiver_balance_before = test.receiver.balance; + + test.set_assertion::(para_origin_assertions); + test.set_assertion::(relay_dest_assertions); + test.set_dispatchable::(system_para_limited_teleport_assets); + test.assert(); + + let sender_balance_after = test.sender.balance; + let receiver_balance_after = test.receiver.balance; + + let delivery_fees = PeopleRococo::execute_with(|| { + xcm_helpers::transfer_assets_delivery_fees::< + ::XcmSender, + >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) + }); + + // Sender's balance is reduced + assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); + // Receiver's balance is increased + assert!(receiver_balance_after > receiver_balance_before); +} + +/// Limited Teleport of native asset from System Parachain to Relay Chain +/// should't work when there is not enough balance in Relay Chain's `CheckAccount` +#[test] +fn limited_teleport_native_assets_from_system_para_to_relay_fails() { + // Init values for Relay Chain + let amount_to_send: Balance = PEOPLE_ROCOCO_ED * 1000; + let destination = PeopleRococo::parent_location().into(); + let beneficiary_id = RococoReceiver::get().into(); + let assets = (Parent, amount_to_send).into(); + + let test_args = TestContext { + sender: PeopleRococoSender::get(), + receiver: RococoReceiver::get(), + args: para_test_args(destination, beneficiary_id, amount_to_send, assets, None, 0), + }; + + let mut test = SystemParaToRelayTest::new(test_args); + + let sender_balance_before = test.sender.balance; + let receiver_balance_before = test.receiver.balance; + + test.set_assertion::(para_origin_assertions); + test.set_assertion::(relay_dest_assertions_fail); + test.set_dispatchable::(system_para_limited_teleport_assets); + test.assert(); + + let sender_balance_after = test.sender.balance; + let receiver_balance_after = test.receiver.balance; + + let delivery_fees = PeopleRococo::execute_with(|| { + xcm_helpers::transfer_assets_delivery_fees::< + ::XcmSender, + >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) + }); + + // Sender's balance is reduced + assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); + // Receiver's balance does not change + assert_eq!(receiver_balance_after, receiver_balance_before); +} + +/// Teleport of native asset from Relay Chain to the System Parachain should work +#[test] +fn teleport_native_assets_from_relay_to_system_para_works() { + // Init values for Relay Chain + let amount_to_send: Balance = ROCOCO_ED * 1000; + let dest = Rococo::child_location_of(PeopleRococo::para_id()); + let beneficiary_id = PeopleRococoReceiver::get(); + let test_args = TestContext { + sender: RococoSender::get(), + receiver: PeopleRococoReceiver::get(), + args: relay_test_args(dest, beneficiary_id, amount_to_send), + }; + + let mut test = RelayToSystemParaTest::new(test_args); + + let sender_balance_before = test.sender.balance; + let receiver_balance_before = test.receiver.balance; + + test.set_assertion::(relay_origin_assertions); + test.set_assertion::(para_dest_assertions); + test.set_dispatchable::(relay_teleport_assets); + test.assert(); + + let delivery_fees = Rococo::execute_with(|| { + xcm_helpers::transfer_assets_delivery_fees::< + ::XcmSender, + >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) + }); + + let sender_balance_after = test.sender.balance; + let receiver_balance_after = test.receiver.balance; + + // Sender's balance is reduced + assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); + // Receiver's balance is increased + assert!(receiver_balance_after > receiver_balance_before); +} + +/// Teleport of native asset from System Parachains to the Relay Chain +/// should work when there is enough balance in Relay Chain's `CheckAccount` +#[test] +fn teleport_native_assets_back_from_system_para_to_relay_works() { + // Dependency - Relay Chain's `CheckAccount` should have enough balance + teleport_native_assets_from_relay_to_system_para_works(); + + // Init values for Relay Chain + let amount_to_send: Balance = PEOPLE_ROCOCO_ED * 1000; + let destination = PeopleRococo::parent_location(); + let beneficiary_id = RococoReceiver::get(); + let assets = (Parent, amount_to_send).into(); + + let test_args = TestContext { + sender: PeopleRococoSender::get(), + receiver: RococoReceiver::get(), + args: para_test_args(destination, beneficiary_id, amount_to_send, assets, None, 0), + }; + + let mut test = SystemParaToRelayTest::new(test_args); + + let sender_balance_before = test.sender.balance; + let receiver_balance_before = test.receiver.balance; + + test.set_assertion::(para_origin_assertions); + test.set_assertion::(relay_dest_assertions); + test.set_dispatchable::(system_para_teleport_assets); + test.assert(); + + let sender_balance_after = test.sender.balance; + let receiver_balance_after = test.receiver.balance; + + let delivery_fees = PeopleRococo::execute_with(|| { + xcm_helpers::transfer_assets_delivery_fees::< + ::XcmSender, + >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) + }); + + // Sender's balance is reduced + assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); + // Receiver's balance is increased + assert!(receiver_balance_after > receiver_balance_before); +} + +/// Teleport of native asset from System Parachain to Relay Chain +/// shouldn't work when there is not enough balance in Relay Chain's `CheckAccount` +#[test] +fn teleport_native_assets_from_system_para_to_relay_fails() { + // Init values for Relay Chain + let amount_to_send: Balance = PEOPLE_ROCOCO_ED * 1000; + let destination = PeopleRococo::parent_location(); + let beneficiary_id = RococoReceiver::get(); + let assets = (Parent, amount_to_send).into(); + + let test_args = TestContext { + sender: PeopleRococoSender::get(), + receiver: RococoReceiver::get(), + args: para_test_args(destination, beneficiary_id, amount_to_send, assets, None, 0), + }; + + let mut test = SystemParaToRelayTest::new(test_args); + + let sender_balance_before = test.sender.balance; + let receiver_balance_before = test.receiver.balance; + + test.set_assertion::(para_origin_assertions); + test.set_assertion::(relay_dest_assertions_fail); + test.set_dispatchable::(system_para_teleport_assets); + test.assert(); + + let delivery_fees = PeopleRococo::execute_with(|| { + xcm_helpers::transfer_assets_delivery_fees::< + ::XcmSender, + >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) + }); + + let sender_balance_after = test.sender.balance; + let receiver_balance_after = test.receiver.balance; + + // Sender's balance is reduced + assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); + // Receiver's balance does not change + assert_eq!(receiver_balance_after, receiver_balance_before); +} + +// #[test] +// fn teleport_to_other_system_parachains_works() { +// let amount = PEOPLE_ROCOCO_ED * 100; +// let native_asset: MultiAssets = (Parent, amount).into(); +// +// test_parachain_is_trusted_teleporter!( +// PeopleRococo, // Origin +// PeopleRococoXcmConfig, // XCM Configuration +// vec![BridgeHubRococo], // Destinations +// (native_asset, amount) +// ); +// } From 2a970c26e4706ef3993803208e62879c226d71d7 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Tue, 21 Nov 2023 18:04:29 +0000 Subject: [PATCH 011/102] ".git/.scripts/commands/fmt/fmt.sh" --- substrate/frame/identity/src/lib.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index 492b088e94ca..996536404f7d 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -505,16 +505,14 @@ pub mod pallet { let item = (reg_index, Judgement::FeePaid(registrar.fee)); match id.judgements.binary_search_by_key(®_index, |x| x.0) { - Ok(i) => { + Ok(i) => if id.judgements[i].1.is_sticky() { return Err(Error::::StickyJudgement.into()); } else { id.judgements[i] = item - } - }, - Err(i) => { - id.judgements.try_insert(i, item).map_err(|_| Error::::TooManyRegistrars)? - }, + }, + Err(i) => + id.judgements.try_insert(i, item).map_err(|_| Error::::TooManyRegistrars)?, } T::Currency::reserve(&sender, registrar.fee)?; @@ -1007,7 +1005,8 @@ impl Pallet { Ok((new_id_deposit, new_subs_deposit)) } - /// Set an identity with zero deposit. Used for benchmarking and XCM emulator tests, involves `rejig_deposit`. + /// Set an identity with zero deposit. Used for benchmarking and XCM emulator tests, involves + /// `rejig_deposit`. pub fn set_identity_no_deposit( who: &T::AccountId, info: T::IdentityInformation, From aeec8ef5101c1beace06a0abc9ec572cf405ff2a Mon Sep 17 00:00:00 2001 From: Richard Melkonian <35300528+0xmovses@users.noreply.github.com> Date: Wed, 22 Nov 2023 13:14:45 +0000 Subject: [PATCH 012/102] Update cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> --- .../tests/people/people-rococo/src/tests/reap_identity.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index 11c5bec7a255..5732c75b0525 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -129,8 +129,7 @@ fn reap_identity() { ); assert!(::Identity::identity(&RococoRelaySender::get()) .is_none()); - assert!(::Identity::super_of(&RococoRelaySender::get()) - .is_none()); + assert_eq!(::Identity::subs_of(&RococoRelaySender::get()), vec![]); let bal_after_reap = ::Balances::free_balance(RococoRelaySender::get()); assert_eq!(bal_after_reap, bal_before_relaychain) From 319b3aeabc0249f2ae7a95e080a9212f7098d1d4 Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Wed, 22 Nov 2023 13:15:33 +0000 Subject: [PATCH 013/102] address petrowski feedback --- .../people/people-rococo/src/genesis.rs | 7 -- .../emulated/chains/relays/rococo/src/lib.rs | 1 + .../people-rococo/src/tests/reap_identity.rs | 110 +++++++++++------- substrate/frame/identity/src/lib.rs | 12 +- 4 files changed, 74 insertions(+), 56 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/genesis.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/genesis.rs index 934ed406eab4..f0e8d62f47ce 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/genesis.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/genesis.rs @@ -29,13 +29,6 @@ pub const ED: Balance = parachains_common::rococo::currency::EXISTENTIAL_DEPOSIT pub fn genesis() -> Storage { let genesis_config = people_rococo_runtime::RuntimeGenesisConfig { system: people_rococo_runtime::SystemConfig::default(), - balances: people_rococo_runtime::BalancesConfig { - balances: accounts::init_balances() - .iter() - .cloned() - .map(|k| (k, ED * 4096 * 4096)) - .collect(), - }, parachain_info: people_rococo_runtime::ParachainInfoConfig { parachain_id: ParaId::from(PARA_ID), ..Default::default() diff --git a/cumulus/parachains/integration-tests/emulated/chains/relays/rococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/chains/relays/rococo/src/lib.rs index 573c14c3f79b..71a5cba1ce5c 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/relays/rococo/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/relays/rococo/src/lib.rs @@ -38,6 +38,7 @@ decl_test_relay_chains! { Balances: rococo_runtime::Balances, Hrmp: rococo_runtime::Hrmp, Identity: rococo_runtime::Identity, + IdentityMigrator: rococo_runtime::IdentityMigrator, } }, } diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index 5732c75b0525..893dbdf67512 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -1,23 +1,26 @@ use crate::*; use emulated_integration_tests_common::xcm_emulator::Get; use pallet_identity::{legacy::IdentityInfo, Data}; -use people_rococo_runtime::people::IdentityInfo as IdentityInfoParachain; -use rococo_runtime::MaxAdditionalFields; +use people_rococo_runtime::people::{ + BasicDeposit as BasicDepositParachain, ByteDeposit as ByteDepositParachain, + IdentityInfo as IdentityInfoParachain, +}; +use rococo_runtime::{BasicDeposit, ByteDeposit, MaxAdditionalFields, SubAccountDeposit}; use rococo_system_emulated_network::{ - rococo_emulated_chain::RococoRelayPallet, RococoRelay, RococoRelaySender, + rococo_emulated_chain::RococoRelayPallet, RococoRelay, RococoRelayReceiver, RococoRelaySender, }; fn identity_relay() -> IdentityInfo { IdentityInfo { display: Data::Raw(b"xcm-test".to_vec().try_into().unwrap()), - additional: Default::default(), - legal: Default::default(), - web: Default::default(), - riot: Default::default(), - email: Default::default(), + legal: Data::Raw(b"The Right Ordinal Xcm Test, Esq.".to_vec().try_into().unwrap()), + web: Data::Raw(b"https://xcm-test.io".to_vec().try_into().unwrap()), + email: Data::Raw(b"xcm-test@gmail.com".to_vec().try_into().unwrap()), pgp_fingerprint: None, - image: Default::default(), - twitter: Default::default(), + image: Data::Raw(b"xcm-test.png".to_vec().try_into().unwrap()), + twitter: Data::Raw(b"@xcm-test".to_vec().try_into().unwrap()), + riot: Default::default(), + additional: Default::default(), } } @@ -36,14 +39,21 @@ fn identity_parachain() -> IdentityInfoParachain { } } -#[test] -fn reap_identity() { - let mut bal_before_relaychain: Balance = 0_u128; - let mut bal_after_relaychain: Balance = 0_u128; +fn id_deposit_parachain(id: &IdentityInfoParachain) -> Balance { + let base_deposit = BasicDepositParachain::get(); + let byte_deposit = + ByteDepositParachain::get() * TryInto::::try_into(id.encoded_size()).unwrap(); + base_deposit + byte_deposit +} - let mut bal_before_parachain: Balance = 0_u128; - let mut bal_after_parachain: Balance = 0_u128; +fn id_deposit_relaychain(id: &IdentityInfo) -> Balance { + let base_deposit = BasicDeposit::get(); + let byte_deposit = ByteDeposit::get() * TryInto::::try_into(id.encoded_size()).unwrap(); + base_deposit + byte_deposit +} +#[test] +fn reap_identity() { let identity_relaychain = identity_relay(); let identity_parachain = identity_parachain(); @@ -51,75 +61,87 @@ fn reap_identity() { RococoRelay::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; - bal_before_relaychain = - ::Balances::free_balance(RococoRelaySender::get()); - // 1. Set identity on Relay Chain assert_ok!(::Identity::set_identity( rococo_runtime::RuntimeOrigin::signed(RococoRelaySender::get()), - Box::new(identity_relaychain) + Box::new(identity_relaychain.clone()) )); assert_expected_events!( RococoRelay, vec![ RuntimeEvent::Identity(pallet_identity::Event::IdentitySet { .. }) => {}, + RuntimeEvent::Balances(pallet_balances::Event::Reserved { .. }) => {}, ] ); // 2. Set sub-identity on Relay Chain assert_ok!(::Identity::set_subs( rococo_runtime::RuntimeOrigin::signed(RococoRelaySender::get()), - vec![(RococoRelaySender::get(), Data::Raw(vec![40; 1].try_into().unwrap()))], + vec![(RococoRelayReceiver::get(), Data::Raw(vec![40; 1].try_into().unwrap()))], )); assert_expected_events!( RococoRelay, vec![ - RuntimeEvent::Balances(pallet_balances::Event::Reserved { .. }) => {}, RuntimeEvent::Identity(pallet_identity::Event::IdentitySet { .. }) => {}, RuntimeEvent::Balances(pallet_balances::Event::Reserved { .. }) => {}, ] ); - bal_after_relaychain = - ::Balances::free_balance(RococoRelaySender::get()); + let reserved_bal = ::Balances::reserved_balance( + RococoRelaySender::get(), + ); + let total_deposit = SubAccountDeposit::get() + id_deposit_relaychain(&identity_relaychain); + + // The reserved balance should equal the calculated total deposit + assert_eq!(reserved_bal, total_deposit); }); // Set identity and Subs on Parachain with Zero deposit PeopleRococo::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; - bal_before_parachain = + let free_bal = ::Balances::free_balance(PeopleRococoSender::get()); + //let total_deposit = SubAccountDeposit::get() + id_deposit_parachain(&identity_parachain); + let reserved_bal = ::Balances::reserved_balance( + PeopleRococoSender::get(), + ); - // 3. Set identity on Parachain with zero deposit + //total balance at Genesis should be zero + assert_eq!(reserved_bal + free_bal, 0); + + // 3. Set identity on Parachain assert_ok!(::Identity::set_identity_no_deposit( &PeopleRococoSender::get(), identity_parachain.clone() )); // 4. Set sub-identity on Parachain - assert_ok!(::Identity::set_subs( - people_rococo_runtime::RuntimeOrigin::signed(PeopleRococoSender::get()), - vec![(PeopleRococoSender::get(), Data::Raw(vec![40; 1].try_into().unwrap()))], + assert_ok!(::Identity::set_sub_no_deposit( + &PeopleRococoSender::get(), + PeopleRococoReceiver::get(), )); - assert_expected_events!( - PeopleRococo, - vec![ - RuntimeEvent::Balances(pallet_balances::Event::Reserved { .. }) => {}, - ] + + // No events get triggered when calling set_sub_no_deposit + + // No amount should be reserved as deposit amounts are set to 0. + let reserved_bal = ::Balances::reserved_balance( + PeopleRococoSender::get(), ); + assert_eq!(reserved_bal, 0); - bal_after_parachain = - ::Balances::free_balance(PeopleRococoSender::get()); - let fees = bal_before_parachain - bal_after_parachain; - assert_eq!(bal_before_parachain - fees, bal_after_parachain); + assert!(::Identity::identity( + &PeopleRococoSender::get() + ) + .is_some()); }); // 5. reap_identity on Relay Chain RococoRelay::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; - assert_ok!(::Identity::reap_identity( - &RococoRelaySender::get(), + assert_ok!(::IdentityMigrator::reap_identity( + rococo_runtime::RuntimeOrigin::signed(RococoRelaySender::get()), + RococoRelaySender::get(), )); assert_expected_events!( RococoRelay, @@ -129,9 +151,9 @@ fn reap_identity() { ); assert!(::Identity::identity(&RococoRelaySender::get()) .is_none()); - assert_eq!(::Identity::subs_of(&RococoRelaySender::get()), vec![]); - let bal_after_reap = - ::Balances::free_balance(RococoRelaySender::get()); - assert_eq!(bal_after_reap, bal_before_relaychain) + assert!(::Identity::super_of(&RococoRelaySender::get()) + .is_none()); + + // assert balances }); } diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index 996536404f7d..bbf169513e6e 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -505,14 +505,16 @@ pub mod pallet { let item = (reg_index, Judgement::FeePaid(registrar.fee)); match id.judgements.binary_search_by_key(®_index, |x| x.0) { - Ok(i) => + Ok(i) => { if id.judgements[i].1.is_sticky() { return Err(Error::::StickyJudgement.into()); } else { id.judgements[i] = item - }, - Err(i) => - id.judgements.try_insert(i, item).map_err(|_| Error::::TooManyRegistrars)?, + } + }, + Err(i) => { + id.judgements.try_insert(i, item).map_err(|_| Error::::TooManyRegistrars)? + }, } T::Currency::reserve(&sender, registrar.fee)?; @@ -1023,7 +1025,7 @@ impl Pallet { } /// Set subs with zero deposit. Only used for benchmarking that involves `rejig_deposit`. - #[cfg(feature = "runtime-benchmarks")] + //#[cfg(feature = "runtime-benchmarks")] pub fn set_sub_no_deposit(who: &T::AccountId, sub: T::AccountId) -> DispatchResult { use frame_support::BoundedVec; let subs = BoundedVec::<_, T::MaxSubAccounts>::try_from(vec![sub]).unwrap(); From 13d9d18135e30720ea5edf4f58abbf13f830874f Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Wed, 22 Nov 2023 14:03:15 +0000 Subject: [PATCH 014/102] assert on subs_of --- .../people/people-rococo/src/tests/reap_identity.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index 893dbdf67512..44be550ae2f1 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -1,5 +1,6 @@ use crate::*; use emulated_integration_tests_common::xcm_emulator::Get; +use frame_support::BoundedVec; use pallet_identity::{legacy::IdentityInfo, Data}; use people_rococo_runtime::people::{ BasicDeposit as BasicDepositParachain, ByteDeposit as ByteDepositParachain, @@ -77,7 +78,7 @@ fn reap_identity() { // 2. Set sub-identity on Relay Chain assert_ok!(::Identity::set_subs( rococo_runtime::RuntimeOrigin::signed(RococoRelaySender::get()), - vec![(RococoRelayReceiver::get(), Data::Raw(vec![40; 1].try_into().unwrap()))], + vec![(RococoRelayReceiver::get(), Data::Raw(vec![42; 1].try_into().unwrap()))], )); assert_expected_events!( RococoRelay, @@ -129,11 +130,13 @@ fn reap_identity() { PeopleRococoSender::get(), ); assert_eq!(reserved_bal, 0); - assert!(::Identity::identity( &PeopleRococoSender::get() ) .is_some()); + let tuple_subs = + ::Identity::subs_of(&PeopleRococoSender::get()); + assert!(tuple_subs.1.len() > 0); }); // 5. reap_identity on Relay Chain @@ -151,8 +154,9 @@ fn reap_identity() { ); assert!(::Identity::identity(&RococoRelaySender::get()) .is_none()); - assert!(::Identity::super_of(&RococoRelaySender::get()) - .is_none()); + let tuple_subs = + ::Identity::subs_of(&RococoRelaySender::get()); + assert!(tuple_subs.1.len() == 0); // assert balances }); From b92de0a8c55194476c88bbdc4c0f2fd0d417a3ed Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Wed, 22 Nov 2023 17:00:04 +0000 Subject: [PATCH 015/102] add asserts on parachain --- .../people-rococo/src/tests/reap_identity.rs | 54 +++++++++++++++---- polkadot/runtime/rococo/src/lib.rs | 6 +-- substrate/frame/identity/src/lib.rs | 10 ++-- 3 files changed, 52 insertions(+), 18 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index 44be550ae2f1..4ce021d6860f 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -1,14 +1,19 @@ use crate::*; use emulated_integration_tests_common::xcm_emulator::Get; -use frame_support::BoundedVec; +use frame_support::{dispatch::RawOrigin::Root, BoundedVec}; use pallet_identity::{legacy::IdentityInfo, Data}; -use people_rococo_runtime::people::{ - BasicDeposit as BasicDepositParachain, ByteDeposit as ByteDepositParachain, - IdentityInfo as IdentityInfoParachain, +use pallet_xcm::Origin; +use people_rococo_runtime::{ + people::{ + BasicDeposit as BasicDepositParachain, ByteDeposit as ByteDepositParachain, + IdentityInfo as IdentityInfoParachain, SubAccountDeposit as SubAccountDepositParachain, + }, + OriginCaller, }; use rococo_runtime::{BasicDeposit, ByteDeposit, MaxAdditionalFields, SubAccountDeposit}; use rococo_system_emulated_network::{ - rococo_emulated_chain::RococoRelayPallet, RococoRelay, RococoRelayReceiver, RococoRelaySender, + rococo_emulated_chain, rococo_emulated_chain::RococoRelayPallet, RococoRelay, + RococoRelayReceiver, RococoRelaySender, }; fn identity_relay() -> IdentityInfo { @@ -57,6 +62,7 @@ fn id_deposit_relaychain(id: &IdentityInfo) -> Balance { fn reap_identity() { let identity_relaychain = identity_relay(); let identity_parachain = identity_parachain(); + let mut total_deposit = 0_u128; // Set identity and Subs on Relay Chain RococoRelay::execute_with(|| { @@ -91,7 +97,7 @@ fn reap_identity() { let reserved_bal = ::Balances::reserved_balance( RococoRelaySender::get(), ); - let total_deposit = SubAccountDeposit::get() + id_deposit_relaychain(&identity_relaychain); + total_deposit = SubAccountDeposit::get() + id_deposit_relaychain(&identity_relaychain); // The reserved balance should equal the calculated total deposit assert_eq!(reserved_bal, total_deposit); @@ -142,8 +148,13 @@ fn reap_identity() { // 5. reap_identity on Relay Chain RococoRelay::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; + let reserved_balance = ::Balances::reserved_balance( + RococoRelaySender::get(), + ); + //before reap reserved balance should be equal to total deposit + assert_eq!(reserved_balance, total_deposit); assert_ok!(::IdentityMigrator::reap_identity( - rococo_runtime::RuntimeOrigin::signed(RococoRelaySender::get()), + rococo_runtime::RuntimeOrigin::root(), RococoRelaySender::get(), )); assert_expected_events!( @@ -156,8 +167,33 @@ fn reap_identity() { .is_none()); let tuple_subs = ::Identity::subs_of(&RococoRelaySender::get()); - assert!(tuple_subs.1.len() == 0); + assert_eq!(tuple_subs.1.len(), 0); + + let reserved_balance = ::Balances::reserved_balance( + RococoRelaySender::get(), + ); + // after reap reserved balance should be 0 + assert_eq!(reserved_balance, 0); + }); + + // 6. assert on Parachain + PeopleRococo::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + + let reserved_bal = ::Balances::reserved_balance( + PeopleRococoSender::get(), + ); + + let total_deposit_parachain = + id_deposit_parachain(&identity_parachain) + SubAccountDepositParachain::get(); + + // reserved balance should be equal to total deposit calculated on the Parachain + assert_eq!(reserved_bal, total_deposit_parachain); + + let free_bal = + ::Balances::free_balance(PeopleRococoSender::get()); - // assert balances + // Atleast a single Existential Deposit should be free + assert!(free_bal > PEOPLE_ROCOCO_ED); }); } diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 277c9981dab8..35c1a759aa32 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -75,7 +75,7 @@ use frame_support::{ weights::{ConstantMultiplier, WeightMeter}, PalletId, }; -use frame_system::EnsureRoot; +use frame_system::{EnsureRoot, EnsureSigned}; use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId}; use pallet_identity::legacy::IdentityInfo; use pallet_im_online::sr25519::AuthorityId as ImOnlineId; @@ -225,7 +225,7 @@ pub struct OriginPrivilegeCmp; impl PrivilegeCmp for OriginPrivilegeCmp { fn cmp_privilege(left: &OriginCaller, right: &OriginCaller) -> Option { if left == right { - return Some(Ordering::Equal) + return Some(Ordering::Equal); } match (left, right) { @@ -2290,7 +2290,7 @@ mod remote_tests { #[tokio::test] async fn run_migrations() { if var("RUN_MIGRATION_TESTS").is_err() { - return + return; } sp_tracing::try_init_simple(); diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index bbf169513e6e..08bb861a1ff2 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -505,16 +505,14 @@ pub mod pallet { let item = (reg_index, Judgement::FeePaid(registrar.fee)); match id.judgements.binary_search_by_key(®_index, |x| x.0) { - Ok(i) => { + Ok(i) => if id.judgements[i].1.is_sticky() { return Err(Error::::StickyJudgement.into()); } else { id.judgements[i] = item - } - }, - Err(i) => { - id.judgements.try_insert(i, item).map_err(|_| Error::::TooManyRegistrars)? - }, + }, + Err(i) => + id.judgements.try_insert(i, item).map_err(|_| Error::::TooManyRegistrars)?, } T::Currency::reserve(&sender, registrar.fee)?; From 627509088eb77f010579e86b525c742081878b95 Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Wed, 22 Nov 2023 17:44:55 +0000 Subject: [PATCH 016/102] check unreserved amount --- .../people/people-rococo/src/tests/reap_identity.rs | 10 +++++++++- substrate/frame/identity/src/lib.rs | 12 +++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index 4ce021d6860f..f7534644d29a 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -160,7 +160,10 @@ fn reap_identity() { assert_expected_events!( RococoRelay, vec![ - RuntimeEvent::Balances(pallet_balances::Event::Unreserved { .. }) => {}, + RuntimeEvent::Balances(pallet_balances::Event::Unreserved { who, amount }) => { + who: *who == RococoRelaySender::get(), + amount: *amount == total_deposit, + }, ] ); assert!(::Identity::identity(&RococoRelaySender::get()) @@ -179,6 +182,11 @@ fn reap_identity() { // 6. assert on Parachain PeopleRococo::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; + let free_bal = + ::Balances::free_balance(PeopleRococoSender::get()); + + //Prior to reaping free balance was zero. If Free balance is > 0, then assets were teleported + assert!(free_bal > 0); let reserved_bal = ::Balances::reserved_balance( PeopleRococoSender::get(), diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index 08bb861a1ff2..73df0c6e5ca3 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -76,7 +76,7 @@ mod benchmarking; pub mod legacy; #[cfg(test)] mod tests; -pub mod types; +mod types; pub mod weights; use codec::Encode; @@ -505,14 +505,16 @@ pub mod pallet { let item = (reg_index, Judgement::FeePaid(registrar.fee)); match id.judgements.binary_search_by_key(®_index, |x| x.0) { - Ok(i) => + Ok(i) => { if id.judgements[i].1.is_sticky() { return Err(Error::::StickyJudgement.into()); } else { id.judgements[i] = item - }, - Err(i) => - id.judgements.try_insert(i, item).map_err(|_| Error::::TooManyRegistrars)?, + } + }, + Err(i) => { + id.judgements.try_insert(i, item).map_err(|_| Error::::TooManyRegistrars)? + }, } T::Currency::reserve(&sender, registrar.fee)?; From 9072f050eb6bac9203c5252eb4e036b648416a77 Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Wed, 22 Nov 2023 18:15:52 +0000 Subject: [PATCH 017/102] add xcm feature, cleanup --- .../people/people-rococo/src/genesis.rs | 4 +--- .../parachains/people/people-rococo/src/lib.rs | 1 - .../tests/people/people-rococo/Cargo.toml | 2 +- .../people-rococo/src/tests/reap_identity.rs | 18 ++++-------------- polkadot/runtime/rococo/src/lib.rs | 16 ++++++++-------- substrate/frame/identity/Cargo.toml | 1 + substrate/frame/identity/src/lib.rs | 3 ++- 7 files changed, 17 insertions(+), 28 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/genesis.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/genesis.rs index f0e8d62f47ce..28a90fab8523 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/genesis.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/genesis.rs @@ -18,9 +18,7 @@ use cumulus_primitives_core::ParaId; use sp_core::storage::Storage; // Cumulus -use emulated_integration_tests_common::{ - accounts, build_genesis_storage, collators, SAFE_XCM_VERSION, -}; +use emulated_integration_tests_common::{build_genesis_storage, collators, SAFE_XCM_VERSION}; use parachains_common::Balance; pub const PARA_ID: u32 = 1004; diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/lib.rs index 1b17862d24db..85c295fa25f7 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/lib.rs @@ -23,7 +23,6 @@ use emulated_integration_tests_common::{ impl_accounts_helpers_for_parachain, impl_assert_events_helpers_for_parachain, impls::Parachain, xcm_emulator::decl_test_parachains, }; -use rococo_emulated_chain::Rococo; // AssetHubRococo Parachain declaration decl_test_parachains! { diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/Cargo.toml b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/Cargo.toml index 817eb591b8a1..13853a22167c 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/Cargo.toml @@ -18,7 +18,7 @@ pallet-balances = { path = "../../../../../../../substrate/frame/balances", defa pallet-assets = { path = "../../../../../../../substrate/frame/assets", default-features = false} pallet-asset-conversion = { path = "../../../../../../../substrate/frame/asset-conversion", default-features = false} pallet-message-queue = { path = "../../../../../../../substrate/frame/message-queue", default-features = false } -pallet-identity = { path = "../../../../../../../substrate/frame/identity", default-features = false } +pallet-identity = { path = "../../../../../../../substrate/frame/identity", default-features = false, features = ["xcm-emulator"] } # Polkadot xcm = { package = "staging-xcm", path = "../../../../../../../polkadot/xcm", default-features = false} diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index f7534644d29a..ba2d1e56810f 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -1,19 +1,12 @@ use crate::*; -use emulated_integration_tests_common::xcm_emulator::Get; -use frame_support::{dispatch::RawOrigin::Root, BoundedVec}; use pallet_identity::{legacy::IdentityInfo, Data}; -use pallet_xcm::Origin; -use people_rococo_runtime::{ - people::{ - BasicDeposit as BasicDepositParachain, ByteDeposit as ByteDepositParachain, - IdentityInfo as IdentityInfoParachain, SubAccountDeposit as SubAccountDepositParachain, - }, - OriginCaller, +use people_rococo_runtime::people::{ + BasicDeposit as BasicDepositParachain, ByteDeposit as ByteDepositParachain, + IdentityInfo as IdentityInfoParachain, SubAccountDeposit as SubAccountDepositParachain, }; use rococo_runtime::{BasicDeposit, ByteDeposit, MaxAdditionalFields, SubAccountDeposit}; use rococo_system_emulated_network::{ - rococo_emulated_chain, rococo_emulated_chain::RococoRelayPallet, RococoRelay, - RococoRelayReceiver, RococoRelaySender, + rococo_emulated_chain::RococoRelayPallet, RococoRelay, RococoRelayReceiver, RococoRelaySender, }; fn identity_relay() -> IdentityInfo { @@ -105,8 +98,6 @@ fn reap_identity() { // Set identity and Subs on Parachain with Zero deposit PeopleRococo::execute_with(|| { - type RuntimeEvent = ::RuntimeEvent; - let free_bal = ::Balances::free_balance(PeopleRococoSender::get()); //let total_deposit = SubAccountDeposit::get() + id_deposit_parachain(&identity_parachain); @@ -181,7 +172,6 @@ fn reap_identity() { // 6. assert on Parachain PeopleRococo::execute_with(|| { - type RuntimeEvent = ::RuntimeEvent; let free_bal = ::Balances::free_balance(PeopleRococoSender::get()); diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 35c1a759aa32..a382ba299c68 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -75,7 +75,7 @@ use frame_support::{ weights::{ConstantMultiplier, WeightMeter}, PalletId, }; -use frame_system::{EnsureRoot, EnsureSigned}; +use frame_system::EnsureRoot; use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId}; use pallet_identity::legacy::IdentityInfo; use pallet_im_online::sr25519::AuthorityId as ImOnlineId; @@ -827,19 +827,19 @@ impl InstanceFilter for ProxyType { ), ProxyType::IdentityJudgement => matches!( c, - RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. }) | - RuntimeCall::Utility(..) + RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. }) + | RuntimeCall::Utility(..) ), ProxyType::CancelProxy => { matches!(c, RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. })) }, ProxyType::Auction => matches!( c, - RuntimeCall::Auctions { .. } | - RuntimeCall::Crowdloan { .. } | - RuntimeCall::Registrar { .. } | - RuntimeCall::Multisig(..) | - RuntimeCall::Slots { .. } + RuntimeCall::Auctions { .. } + | RuntimeCall::Crowdloan { .. } + | RuntimeCall::Registrar { .. } + | RuntimeCall::Multisig(..) + | RuntimeCall::Slots { .. } ), ProxyType::Society => matches!(c, RuntimeCall::Society(..)), ProxyType::OnDemandOrdering => matches!(c, RuntimeCall::OnDemandAssignmentProvider(..)), diff --git a/substrate/frame/identity/Cargo.toml b/substrate/frame/identity/Cargo.toml index 309c0aab5500..b931076ae3ed 100644 --- a/substrate/frame/identity/Cargo.toml +++ b/substrate/frame/identity/Cargo.toml @@ -28,6 +28,7 @@ pallet-balances = { path = "../balances" } sp-core = { path = "../../primitives/core" } [features] +xcm-emulator = [] default = [ "std" ] std = [ "codec/std", diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index 73df0c6e5ca3..a9e7a9450d82 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -1009,6 +1009,7 @@ impl Pallet { /// Set an identity with zero deposit. Used for benchmarking and XCM emulator tests, involves /// `rejig_deposit`. + #[cfg(feature = "xcm-emulator")] pub fn set_identity_no_deposit( who: &T::AccountId, info: T::IdentityInformation, @@ -1025,7 +1026,7 @@ impl Pallet { } /// Set subs with zero deposit. Only used for benchmarking that involves `rejig_deposit`. - //#[cfg(feature = "runtime-benchmarks")] + #[cfg(any(feature = "xcm-emulator", feature = "runtime-benchmarks"))] pub fn set_sub_no_deposit(who: &T::AccountId, sub: T::AccountId) -> DispatchResult { use frame_support::BoundedVec; let subs = BoundedVec::<_, T::MaxSubAccounts>::try_from(vec![sub]).unwrap(); From 10da8af32df376557e0dd377d20021d2cf294fc3 Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Wed, 22 Nov 2023 18:21:03 +0000 Subject: [PATCH 018/102] remove redundant comment --- .../tests/people/people-rococo/src/tests/reap_identity.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index ba2d1e56810f..3f91074a09d2 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -100,7 +100,6 @@ fn reap_identity() { PeopleRococo::execute_with(|| { let free_bal = ::Balances::free_balance(PeopleRococoSender::get()); - //let total_deposit = SubAccountDeposit::get() + id_deposit_parachain(&identity_parachain); let reserved_bal = ::Balances::reserved_balance( PeopleRococoSender::get(), ); From b5e4b3e669f30f19105e5df8123519d56dd7a10f Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Wed, 22 Nov 2023 18:23:54 +0000 Subject: [PATCH 019/102] ".git/.scripts/commands/fmt/fmt.sh" --- .../people-rococo/src/tests/reap_identity.rs | 3 ++- polkadot/runtime/rococo/src/lib.rs | 14 +++++++------- substrate/frame/identity/src/lib.rs | 10 ++++------ 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index 3f91074a09d2..919417679f6f 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -174,7 +174,8 @@ fn reap_identity() { let free_bal = ::Balances::free_balance(PeopleRococoSender::get()); - //Prior to reaping free balance was zero. If Free balance is > 0, then assets were teleported + //Prior to reaping free balance was zero. If Free balance is > 0, then assets were + // teleported assert!(free_bal > 0); let reserved_bal = ::Balances::reserved_balance( diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index a382ba299c68..d1b1e23bac06 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -827,19 +827,19 @@ impl InstanceFilter for ProxyType { ), ProxyType::IdentityJudgement => matches!( c, - RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. }) - | RuntimeCall::Utility(..) + RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. }) | + RuntimeCall::Utility(..) ), ProxyType::CancelProxy => { matches!(c, RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. })) }, ProxyType::Auction => matches!( c, - RuntimeCall::Auctions { .. } - | RuntimeCall::Crowdloan { .. } - | RuntimeCall::Registrar { .. } - | RuntimeCall::Multisig(..) - | RuntimeCall::Slots { .. } + RuntimeCall::Auctions { .. } | + RuntimeCall::Crowdloan { .. } | + RuntimeCall::Registrar { .. } | + RuntimeCall::Multisig(..) | + RuntimeCall::Slots { .. } ), ProxyType::Society => matches!(c, RuntimeCall::Society(..)), ProxyType::OnDemandOrdering => matches!(c, RuntimeCall::OnDemandAssignmentProvider(..)), diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index a9e7a9450d82..dd608ac26bf8 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -505,16 +505,14 @@ pub mod pallet { let item = (reg_index, Judgement::FeePaid(registrar.fee)); match id.judgements.binary_search_by_key(®_index, |x| x.0) { - Ok(i) => { + Ok(i) => if id.judgements[i].1.is_sticky() { return Err(Error::::StickyJudgement.into()); } else { id.judgements[i] = item - } - }, - Err(i) => { - id.judgements.try_insert(i, item).map_err(|_| Error::::TooManyRegistrars)? - }, + }, + Err(i) => + id.judgements.try_insert(i, item).map_err(|_| Error::::TooManyRegistrars)?, } T::Currency::reserve(&sender, registrar.fee)?; From 65da33ed36a92fc1244d65672eb158aaa1d9567f Mon Sep 17 00:00:00 2001 From: Richard Melkonian <35300528+0xmovses@users.noreply.github.com> Date: Wed, 22 Nov 2023 21:52:01 +0000 Subject: [PATCH 020/102] Update cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> --- .../tests/people/people-rococo/src/tests/reap_identity.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index 919417679f6f..076ac36ce08c 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -28,7 +28,7 @@ fn identity_parachain() -> IdentityInfoParachain { display: Data::Raw(b"xcm-test".to_vec().try_into().unwrap()), legal: Data::Raw(b"The Right Ordinal Xcm Test, Esq.".to_vec().try_into().unwrap()), web: Data::Raw(b"https://xcm-test.io".to_vec().try_into().unwrap()), - matrix: Data::Raw(b"@xcm-test:matrix.org".to_vec().try_into().unwrap()), + matrix: Data::None, email: Data::Raw(b"xcm-test@gmail.com".to_vec().try_into().unwrap()), pgp_fingerprint: None, image: Data::Raw(b"xcm-test.png".to_vec().try_into().unwrap()), From 386744fb4726a2dca3dfe8b28b11ad1a06ad63e1 Mon Sep 17 00:00:00 2001 From: Richard Melkonian <35300528+0xmovses@users.noreply.github.com> Date: Wed, 22 Nov 2023 21:52:11 +0000 Subject: [PATCH 021/102] Update cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> --- .../tests/people/people-rococo/src/tests/reap_identity.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index 076ac36ce08c..442279bd200c 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -33,8 +33,8 @@ fn identity_parachain() -> IdentityInfoParachain { pgp_fingerprint: None, image: Data::Raw(b"xcm-test.png".to_vec().try_into().unwrap()), twitter: Data::Raw(b"@xcm-test".to_vec().try_into().unwrap()), - github: Data::Raw(b"xcm-test".to_vec().try_into().unwrap()), - discord: Data::Raw(b"xcm-test#0042".to_vec().try_into().unwrap()), + github: Data::None, + discord: Data::None, } } From a6312dbc89856815b1fcba9036f054fa6587d13d Mon Sep 17 00:00:00 2001 From: Richard Melkonian <35300528+0xmovses@users.noreply.github.com> Date: Wed, 22 Nov 2023 21:52:26 +0000 Subject: [PATCH 022/102] Update cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> --- .../tests/people/people-rococo/src/tests/reap_identity.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index 442279bd200c..65dfe232668c 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -192,6 +192,6 @@ fn reap_identity() { ::Balances::free_balance(PeopleRococoSender::get()); // Atleast a single Existential Deposit should be free - assert!(free_bal > PEOPLE_ROCOCO_ED); + assert!(free_bal >= PEOPLE_ROCOCO_ED); }); } From 5e3e9a305fcb479ac430d7a4cbd08cab453fc645 Mon Sep 17 00:00:00 2001 From: Richard Melkonian <35300528+0xmovses@users.noreply.github.com> Date: Wed, 22 Nov 2023 21:52:39 +0000 Subject: [PATCH 023/102] Update substrate/frame/identity/src/lib.rs Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> --- substrate/frame/identity/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index dd608ac26bf8..977685635459 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -554,7 +554,7 @@ pub mod pallet { let fee = if let Judgement::FeePaid(fee) = id.judgements.remove(pos).1 { fee } else { - return Err(Error::::JudgementGiven.into()); + return Err(Error::::JudgementGiven.into()) }; let err_amount = T::Currency::unreserve(&sender, fee); From e8e88d12ab1739fe6ed2ee0b93cceabc429e8ba2 Mon Sep 17 00:00:00 2001 From: Richard Melkonian <35300528+0xmovses@users.noreply.github.com> Date: Wed, 22 Nov 2023 21:52:46 +0000 Subject: [PATCH 024/102] Update substrate/frame/identity/src/lib.rs Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> --- substrate/frame/identity/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index 977685635459..ba26eef8d881 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -700,7 +700,7 @@ pub mod pallet { let mut id = >::get(&target).ok_or(Error::::InvalidTarget)?; if T::Hashing::hash_of(&id.info) != identity { - return Err(Error::::JudgementForDifferentIdentity.into()); + return Err(Error::::JudgementForDifferentIdentity.into()) } let item = (reg_index, judgement); From 41b3564b8bf5745b34c1d72e06a01bfbee9673f9 Mon Sep 17 00:00:00 2001 From: Richard Melkonian <35300528+0xmovses@users.noreply.github.com> Date: Wed, 22 Nov 2023 21:53:37 +0000 Subject: [PATCH 025/102] Update polkadot/runtime/rococo/src/lib.rs Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> --- polkadot/runtime/rococo/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index d1b1e23bac06..aa6e115434a4 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -2290,7 +2290,7 @@ mod remote_tests { #[tokio::test] async fn run_migrations() { if var("RUN_MIGRATION_TESTS").is_err() { - return; + return } sp_tracing::try_init_simple(); From 21ce617b0aed12095073dccc253cdb5868642ca6 Mon Sep 17 00:00:00 2001 From: Richard Melkonian <35300528+0xmovses@users.noreply.github.com> Date: Wed, 22 Nov 2023 21:53:57 +0000 Subject: [PATCH 026/102] Update polkadot/runtime/rococo/src/lib.rs Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> --- polkadot/runtime/rococo/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index aa6e115434a4..277c9981dab8 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -225,7 +225,7 @@ pub struct OriginPrivilegeCmp; impl PrivilegeCmp for OriginPrivilegeCmp { fn cmp_privilege(left: &OriginCaller, right: &OriginCaller) -> Option { if left == right { - return Some(Ordering::Equal); + return Some(Ordering::Equal) } match (left, right) { From 1e2ab6dd6bb34937f5b04c48b802fdbfe98bafe6 Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Wed, 22 Nov 2023 22:16:22 +0000 Subject: [PATCH 027/102] add some printlns --- .../people-rococo/src/tests/reap_identity.rs | 12 ++++++++++++ substrate/frame/identity/src/lib.rs | 16 +++++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index 65dfe232668c..a1f7d529ca7d 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -138,10 +138,13 @@ fn reap_identity() { // 5. reap_identity on Relay Chain RococoRelay::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; + let free_bal_before_reap = + ::Balances::free_balance(RococoRelaySender::get()); let reserved_balance = ::Balances::reserved_balance( RococoRelaySender::get(), ); //before reap reserved balance should be equal to total deposit + println!("reserved_balance: {:?}, total_deposit: {:?}", reserved_balance, total_deposit); assert_eq!(reserved_balance, total_deposit); assert_ok!(::IdentityMigrator::reap_identity( rococo_runtime::RuntimeOrigin::root(), @@ -167,12 +170,21 @@ fn reap_identity() { ); // after reap reserved balance should be 0 assert_eq!(reserved_balance, 0); + let free_bal_after_reap = + ::Balances::free_balance(RococoRelaySender::get()); + + println!( + "free_bal_before_reap: {:?}, free_bal_after_reap: {:?}", + free_bal_before_reap, free_bal_after_reap + ); + //assert!(free_bal_after_reap > free_bal_before_reap); }); // 6. assert on Parachain PeopleRococo::execute_with(|| { let free_bal = ::Balances::free_balance(PeopleRococoSender::get()); + println!("free_bal: {:?}", free_bal); //Prior to reaping free balance was zero. If Free balance is > 0, then assets were // teleported diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index ba26eef8d881..e1169f4d3ecf 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -505,14 +505,16 @@ pub mod pallet { let item = (reg_index, Judgement::FeePaid(registrar.fee)); match id.judgements.binary_search_by_key(®_index, |x| x.0) { - Ok(i) => + Ok(i) => { if id.judgements[i].1.is_sticky() { return Err(Error::::StickyJudgement.into()); } else { id.judgements[i] = item - }, - Err(i) => - id.judgements.try_insert(i, item).map_err(|_| Error::::TooManyRegistrars)?, + } + }, + Err(i) => { + id.judgements.try_insert(i, item).map_err(|_| Error::::TooManyRegistrars)? + }, } T::Currency::reserve(&sender, registrar.fee)?; @@ -554,7 +556,7 @@ pub mod pallet { let fee = if let Judgement::FeePaid(fee) = id.judgements.remove(pos).1 { fee } else { - return Err(Error::::JudgementGiven.into()) + return Err(Error::::JudgementGiven.into()); }; let err_amount = T::Currency::unreserve(&sender, fee); @@ -700,7 +702,7 @@ pub mod pallet { let mut id = >::get(&target).ok_or(Error::::InvalidTarget)?; if T::Hashing::hash_of(&id.info) != identity { - return Err(Error::::JudgementForDifferentIdentity.into()) + return Err(Error::::JudgementForDifferentIdentity.into()); } let item = (reg_index, judgement); @@ -1007,7 +1009,7 @@ impl Pallet { /// Set an identity with zero deposit. Used for benchmarking and XCM emulator tests, involves /// `rejig_deposit`. - #[cfg(feature = "xcm-emulator")] + #[cfg(any(feature = "xcm-emulator", feature = "runtime-benchmarks"))] pub fn set_identity_no_deposit( who: &T::AccountId, info: T::IdentityInformation, From 98cb721b47b504d270a38bbd77149bf9b2b47c4b Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Wed, 22 Nov 2023 22:37:43 +0000 Subject: [PATCH 028/102] assert parachain processes msg queue --- .../people-rococo/src/tests/reap_identity.rs | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index a1f7d529ca7d..a4879ffb83ae 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -144,7 +144,6 @@ fn reap_identity() { RococoRelaySender::get(), ); //before reap reserved balance should be equal to total deposit - println!("reserved_balance: {:?}, total_deposit: {:?}", reserved_balance, total_deposit); assert_eq!(reserved_balance, total_deposit); assert_ok!(::IdentityMigrator::reap_identity( rococo_runtime::RuntimeOrigin::root(), @@ -173,18 +172,26 @@ fn reap_identity() { let free_bal_after_reap = ::Balances::free_balance(RococoRelaySender::get()); - println!( - "free_bal_before_reap: {:?}, free_bal_after_reap: {:?}", - free_bal_before_reap, free_bal_after_reap - ); - //assert!(free_bal_after_reap > free_bal_before_reap); + // free balance should be greater than before reap + assert!(free_bal_after_reap > free_bal_before_reap); }); // 6. assert on Parachain PeopleRococo::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + assert_expected_events!( + PeopleRococo, + vec![ + RuntimeEvent::Balances(pallet_balances::Event::Deposit { .. }) => {}, + RuntimeEvent::Balances(pallet_balances::Event::Endowed { .. }) => {}, + RuntimeEvent::Balances(pallet_balances::Event::Reserved { .. }) => {}, + RuntimeEvent::Balances(pallet_balances::Event::Reserved { .. }) => {}, + RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { .. }) => {}, + ] + ); + let free_bal = ::Balances::free_balance(PeopleRococoSender::get()); - println!("free_bal: {:?}", free_bal); //Prior to reaping free balance was zero. If Free balance is > 0, then assets were // teleported From 7670e4db57e3abf25d457c39bf81f516503eac8c Mon Sep 17 00:00:00 2001 From: Richard Melkonian <35300528+0xmovses@users.noreply.github.com> Date: Wed, 22 Nov 2023 22:41:10 +0000 Subject: [PATCH 029/102] Update substrate/frame/identity/src/lib.rs Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> --- substrate/frame/identity/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index e1169f4d3ecf..77f58c36410a 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -507,7 +507,7 @@ pub mod pallet { match id.judgements.binary_search_by_key(®_index, |x| x.0) { Ok(i) => { if id.judgements[i].1.is_sticky() { - return Err(Error::::StickyJudgement.into()); + return Err(Error::::StickyJudgement.into()) } else { id.judgements[i] = item } From e90f35194e3be17b69af077ff4f7d543b7762fe6 Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Wed, 22 Nov 2023 22:57:16 +0000 Subject: [PATCH 030/102] assert additional events --- .../people/people-rococo/src/tests/reap_identity.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index a4879ffb83ae..2345a91ed772 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -182,11 +182,11 @@ fn reap_identity() { assert_expected_events!( PeopleRococo, vec![ - RuntimeEvent::Balances(pallet_balances::Event::Deposit { .. }) => {}, - RuntimeEvent::Balances(pallet_balances::Event::Endowed { .. }) => {}, - RuntimeEvent::Balances(pallet_balances::Event::Reserved { .. }) => {}, - RuntimeEvent::Balances(pallet_balances::Event::Reserved { .. }) => {}, - RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { .. }) => {}, + RuntimeEvent::Balances(pallet_balances::Event::Deposit { ..}) => {}, + RuntimeEvent::Balances(pallet_balances::Event::Endowed { ..}) => {}, + RuntimeEvent::Balances(pallet_balances::Event::Reserved { ..}) => {}, + RuntimeEvent::Balances(pallet_balances::Event::Reserved { ..}) => {}, + RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { ..}) => {}, ] ); From 9fbc89e440ab88083035d6ee393b25e7860a2829 Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Thu, 23 Nov 2023 20:09:34 +0000 Subject: [PATCH 031/102] assert on inner enum vals --- .../people-rococo/src/tests/reap_identity.rs | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index 2345a91ed772..8ce4a9f299a6 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -179,33 +179,34 @@ fn reap_identity() { // 6. assert on Parachain PeopleRococo::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; + let free_bal = + ::Balances::free_balance(PeopleRococoSender::get()); + let reserved_bal = ::Balances::reserved_balance( + PeopleRococoSender::get(), + ); + let id_deposit = id_deposit_parachain(&identity_parachain); + let subs_deposit = SubAccountDepositParachain::get(); + let total_deposit = subs_deposit + id_deposit; + assert_expected_events!( PeopleRococo, vec![ RuntimeEvent::Balances(pallet_balances::Event::Deposit { ..}) => {}, RuntimeEvent::Balances(pallet_balances::Event::Endowed { ..}) => {}, - RuntimeEvent::Balances(pallet_balances::Event::Reserved { ..}) => {}, - RuntimeEvent::Balances(pallet_balances::Event::Reserved { ..}) => {}, + RuntimeEvent::Balances(pallet_balances::Event::Reserved { who, amount }) => { + who: *who == PeopleRococoSender::get(), + amount: *amount == id_deposit, + }, + RuntimeEvent::Balances(pallet_balances::Event::Reserved { who, amount }) => { + who: *who == PeopleRococoSender::get(), + amount: *amount == subs_deposit, + }, RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { ..}) => {}, ] ); - let free_bal = - ::Balances::free_balance(PeopleRococoSender::get()); - - //Prior to reaping free balance was zero. If Free balance is > 0, then assets were - // teleported - assert!(free_bal > 0); - - let reserved_bal = ::Balances::reserved_balance( - PeopleRococoSender::get(), - ); - - let total_deposit_parachain = - id_deposit_parachain(&identity_parachain) + SubAccountDepositParachain::get(); - // reserved balance should be equal to total deposit calculated on the Parachain - assert_eq!(reserved_bal, total_deposit_parachain); + assert_eq!(reserved_bal, total_deposit); let free_bal = ::Balances::free_balance(PeopleRococoSender::get()); From 72b38e2f4aa081f8a983b2b2bbe8c96edeee1b36 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Thu, 23 Nov 2023 20:12:54 +0000 Subject: [PATCH 032/102] ".git/.scripts/commands/fmt/fmt.sh" --- substrate/frame/identity/src/lib.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index 77f58c36410a..849d968661da 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -505,16 +505,14 @@ pub mod pallet { let item = (reg_index, Judgement::FeePaid(registrar.fee)); match id.judgements.binary_search_by_key(®_index, |x| x.0) { - Ok(i) => { + Ok(i) => if id.judgements[i].1.is_sticky() { return Err(Error::::StickyJudgement.into()) } else { id.judgements[i] = item - } - }, - Err(i) => { - id.judgements.try_insert(i, item).map_err(|_| Error::::TooManyRegistrars)? - }, + }, + Err(i) => + id.judgements.try_insert(i, item).map_err(|_| Error::::TooManyRegistrars)?, } T::Currency::reserve(&sender, registrar.fee)?; From 0d1c309941f2be714f3b3773930dbf0575a7f97f Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Thu, 23 Nov 2023 20:24:13 +0000 Subject: [PATCH 033/102] fmt --- .../people/people-rococo/src/tests/reap_identity.rs | 2 -- substrate/frame/identity/src/lib.rs | 10 +++++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index 8ce4a9f299a6..f8368e0f3647 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -179,8 +179,6 @@ fn reap_identity() { // 6. assert on Parachain PeopleRococo::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; - let free_bal = - ::Balances::free_balance(PeopleRococoSender::get()); let reserved_bal = ::Balances::reserved_balance( PeopleRococoSender::get(), ); diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index 849d968661da..9350ab30ec4c 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -162,7 +162,7 @@ pub mod pallet { /// TWOX-NOTE: OK ― `AccountId` is a secure hash. #[pallet::storage] #[pallet::getter(fn identity)] - pub type IdentityOf = StorageMap< + pub(super) type IdentityOf = StorageMap< _, Twox64Concat, T::AccountId, @@ -174,7 +174,7 @@ pub mod pallet { /// context. If the account is not some other account's sub-identity, then just `None`. #[pallet::storage] #[pallet::getter(fn super_of)] - pub type SuperOf = + pub(super) type SuperOf = StorageMap<_, Blake2_128Concat, T::AccountId, (T::AccountId, Data), OptionQuery>; /// Alternative "sub" identities of this account. @@ -184,7 +184,7 @@ pub mod pallet { /// TWOX-NOTE: OK ― `AccountId` is a secure hash. #[pallet::storage] #[pallet::getter(fn subs_of)] - pub type SubsOf = StorageMap< + pub(super) type SubsOf = StorageMap< _, Twox64Concat, T::AccountId, @@ -554,7 +554,7 @@ pub mod pallet { let fee = if let Judgement::FeePaid(fee) = id.judgements.remove(pos).1 { fee } else { - return Err(Error::::JudgementGiven.into()); + return Err(Error::::JudgementGiven.into()) }; let err_amount = T::Currency::unreserve(&sender, fee); @@ -700,7 +700,7 @@ pub mod pallet { let mut id = >::get(&target).ok_or(Error::::InvalidTarget)?; if T::Hashing::hash_of(&id.info) != identity { - return Err(Error::::JudgementForDifferentIdentity.into()); + return Err(Error::::JudgementForDifferentIdentity.into()) } let item = (reg_index, judgement); From 7b35c9fe7a6bc139c19f590020facc30535ff8d1 Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Thu, 23 Nov 2023 20:30:17 +0000 Subject: [PATCH 034/102] fmt --- polkadot/xcm/procedural/tests/ui.rs | 2 +- .../client/rpc-spec-v2/src/chain_head/subscription/inner.rs | 2 +- substrate/utils/wasm-builder/src/wasm_project.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/polkadot/xcm/procedural/tests/ui.rs b/polkadot/xcm/procedural/tests/ui.rs index fef7c95c6142..a6ec35d0862a 100644 --- a/polkadot/xcm/procedural/tests/ui.rs +++ b/polkadot/xcm/procedural/tests/ui.rs @@ -21,7 +21,7 @@ fn ui() { // Only run the ui tests when `RUN_UI_TESTS` is set. if std::env::var("RUN_UI_TESTS").is_err() { - return + return; } // As trybuild is using `cargo check`, we don't need the real WASM binaries. diff --git a/substrate/client/rpc-spec-v2/src/chain_head/subscription/inner.rs b/substrate/client/rpc-spec-v2/src/chain_head/subscription/inner.rs index 2b250f3dc2cf..abd42ad96785 100644 --- a/substrate/client/rpc-spec-v2/src/chain_head/subscription/inner.rs +++ b/substrate/client/rpc-spec-v2/src/chain_head/subscription/inner.rs @@ -763,7 +763,7 @@ impl> SubscriptionsInner { // blocks. for hash in hashes.clone() { if !sub.contains_block(hash) { - return Err(SubscriptionManagementError::BlockHashAbsent) + return Err(SubscriptionManagementError::BlockHashAbsent); } } diff --git a/substrate/utils/wasm-builder/src/wasm_project.rs b/substrate/utils/wasm-builder/src/wasm_project.rs index 9c25d1aba3cf..2e6f671c45ed 100644 --- a/substrate/utils/wasm-builder/src/wasm_project.rs +++ b/substrate/utils/wasm-builder/src/wasm_project.rs @@ -916,7 +916,7 @@ fn generate_rerun_if_changed_instructions( while let Some(dependency) = dependencies.pop() { // Ignore all dev dependencies if dependency.kind == DependencyKind::Development { - continue + continue; } let path_or_git_dep = From 472d20307fec7ff9da5b85d91162f165a2a0bad2 Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Fri, 24 Nov 2023 09:54:02 +0000 Subject: [PATCH 035/102] assert IdentityMigrator events --- Cargo.lock | 1 + .../emulated/tests/people/people-rococo/Cargo.toml | 1 + .../tests/people/people-rococo/src/tests/reap_identity.rs | 8 ++++++++ 3 files changed, 10 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index ead0718b3a94..3905938d28c1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11826,6 +11826,7 @@ dependencies = [ "penpal-runtime", "people-rococo-runtime", "polkadot-primitives", + "polkadot-runtime-common", "rococo-runtime", "rococo-system-emulated-network", "sp-runtime", diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/Cargo.toml b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/Cargo.toml index 13853a22167c..98d4f3a87c6d 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/Cargo.toml @@ -26,6 +26,7 @@ pallet-xcm = { path = "../../../../../../../polkadot/xcm/pallet-xcm", default-fe xcm-executor = { package = "staging-xcm-executor", path = "../../../../../../../polkadot/xcm/xcm-executor", default-features = false} rococo-runtime = { path = "../../../../../../../polkadot/runtime/rococo" } polkadot-primitives = { path = "../../../../../../../polkadot/primitives" } +polkadot-runtime-common = { path = "../../../../../../../polkadot/runtime/common"} # Cumulus asset-test-utils = { path = "../../../../../runtimes/assets/test-utils" } diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index f8368e0f3647..e17900d8b785 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -199,6 +199,14 @@ fn reap_identity() { who: *who == PeopleRococoSender::get(), amount: *amount == subs_deposit, }, + RuntimeEvent::IdentityMigrator( + polkadot_runtime_common::identity_migrator::Event::DepositUpdated { + who, identity, subs + }) => { + who: *who == PeopleRococoSender::get(), + identity: *identity == id_deposit, + subs: *subs == subs_deposit, + }, RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { ..}) => {}, ] ); From 342454e25f1ff4b62ab22e3b18fce4417ad577c0 Mon Sep 17 00:00:00 2001 From: Richard Melkonian <35300528+0xmovses@users.noreply.github.com> Date: Fri, 24 Nov 2023 12:28:55 +0000 Subject: [PATCH 036/102] Update cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Dónal Murray --- .../people-rococo/src/tests/reap_identity.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index e17900d8b785..bafd7e67f50b 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -1,3 +1,18 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + use crate::*; use pallet_identity::{legacy::IdentityInfo, Data}; use people_rococo_runtime::people::{ From 1bca9e79c4f7a05bd83297d1c9f098bca8d16910 Mon Sep 17 00:00:00 2001 From: Richard Melkonian <35300528+0xmovses@users.noreply.github.com> Date: Fri, 24 Nov 2023 12:30:28 +0000 Subject: [PATCH 037/102] Update cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/Cargo.toml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Dónal Murray --- .../emulated/chains/parachains/people/people-rococo/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/Cargo.toml b/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/Cargo.toml index e48ee5b30636..36fef849ddbf 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "people-rococo-emulated-chain" -version = "0.0.0" +version = "0.1.0" authors.workspace = true edition.workspace = true license = "Apache-2.0" From c29d8f724b0ca4db41f98ae67eba76e4cc501453 Mon Sep 17 00:00:00 2001 From: Richard Melkonian <35300528+0xmovses@users.noreply.github.com> Date: Fri, 24 Nov 2023 12:30:39 +0000 Subject: [PATCH 038/102] Update cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/Cargo.toml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Dónal Murray --- .../emulated/tests/people/people-rococo/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/Cargo.toml b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/Cargo.toml index 98d4f3a87c6d..e2633d758c97 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "people-rococo-integration-tests" -version = "1.0.0" +version = "0.1.0" authors.workspace = true edition.workspace = true license = "Apache-2.0" From 11d0a6a4ca085bac75d4ad86ea2e78aeb1c908e4 Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Fri, 24 Nov 2023 12:34:12 +0000 Subject: [PATCH 039/102] version 0 cargo.lock --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3905938d28c1..974a238293cc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11794,7 +11794,7 @@ dependencies = [ [[package]] name = "people-rococo-emulated-chain" -version = "0.0.0" +version = "0.1.0" dependencies = [ "cumulus-primitives-core", "emulated-integration-tests-common", @@ -11809,7 +11809,7 @@ dependencies = [ [[package]] name = "people-rococo-integration-tests" -version = "1.0.0" +version = "0.1.0" dependencies = [ "assert_matches", "asset-test-utils", From 880f611f50c38224a6a219bec111e88100378592 Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Mon, 27 Nov 2023 18:13:38 +0000 Subject: [PATCH 040/102] Add filter, update weights --- .../tests/people/people-rococo/src/lib.rs | 1 + .../people-rococo/src/tests/teleport.rs | 129 +----------------- cumulus/xcm/xcm-emulator/src/lib.rs | 1 + polkadot/runtime/rococo/constants/src/lib.rs | 2 + polkadot/runtime/rococo/src/xcm_config.rs | 3 + .../xcm/xcm-builder/src/currency_adapter.rs | 1 + 6 files changed, 11 insertions(+), 126 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/lib.rs index 1c2f50452638..caa6311de65b 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/lib.rs @@ -52,6 +52,7 @@ pub use rococo_system_emulated_network::{ RococoRelaySender as RococoSender, }; + pub type RelayToSystemParaTest = Test; pub type RelayToParaTest = Test; pub type SystemParaToRelayTest = Test; diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs index 0d1a8e54963b..255671ea6c8f 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs @@ -20,8 +20,7 @@ use rococo_runtime::xcm_config::XcmConfig as RococoXcmConfig; fn relay_origin_assertions(t: RelayToSystemParaTest) { type RuntimeEvent = ::RuntimeEvent; - - Rococo::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(631_531_000, 7_186))); + Rococo::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(627_959_000, 7_200))); assert_expected_events!( Rococo, @@ -98,7 +97,7 @@ fn para_origin_assertions(t: SystemParaToRelayTest) { fn para_dest_assertions(t: RelayToSystemParaTest) { type RuntimeEvent = ::RuntimeEvent; - PeopleRococo::assert_dmp_queue_complete(Some(Weight::from_parts(157_718_000, 3593))); + PeopleRococo::assert_dmp_queue_complete(Some(Weight::from_parts(162_456_000, 0))); assert_expected_events!( PeopleRococo, @@ -174,6 +173,7 @@ fn limited_teleport_native_assets_from_relay_to_system_para_works() { test.set_assertion::(relay_origin_assertions); test.set_assertion::(para_dest_assertions); test.set_dispatchable::(relay_limited_teleport_assets); + test.assert(); let delivery_fees = Rococo::execute_with(|| { xcm_helpers::transfer_assets_delivery_fees::< @@ -275,129 +275,6 @@ fn limited_teleport_native_assets_from_system_para_to_relay_fails() { assert_eq!(receiver_balance_after, receiver_balance_before); } -/// Teleport of native asset from Relay Chain to the System Parachain should work -#[test] -fn teleport_native_assets_from_relay_to_system_para_works() { - // Init values for Relay Chain - let amount_to_send: Balance = ROCOCO_ED * 1000; - let dest = Rococo::child_location_of(PeopleRococo::para_id()); - let beneficiary_id = PeopleRococoReceiver::get(); - let test_args = TestContext { - sender: RococoSender::get(), - receiver: PeopleRococoReceiver::get(), - args: relay_test_args(dest, beneficiary_id, amount_to_send), - }; - - let mut test = RelayToSystemParaTest::new(test_args); - - let sender_balance_before = test.sender.balance; - let receiver_balance_before = test.receiver.balance; - - test.set_assertion::(relay_origin_assertions); - test.set_assertion::(para_dest_assertions); - test.set_dispatchable::(relay_teleport_assets); - test.assert(); - - let delivery_fees = Rococo::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::< - ::XcmSender, - >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) - }); - - let sender_balance_after = test.sender.balance; - let receiver_balance_after = test.receiver.balance; - - // Sender's balance is reduced - assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); - // Receiver's balance is increased - assert!(receiver_balance_after > receiver_balance_before); -} - -/// Teleport of native asset from System Parachains to the Relay Chain -/// should work when there is enough balance in Relay Chain's `CheckAccount` -#[test] -fn teleport_native_assets_back_from_system_para_to_relay_works() { - // Dependency - Relay Chain's `CheckAccount` should have enough balance - teleport_native_assets_from_relay_to_system_para_works(); - - // Init values for Relay Chain - let amount_to_send: Balance = PEOPLE_ROCOCO_ED * 1000; - let destination = PeopleRococo::parent_location(); - let beneficiary_id = RococoReceiver::get(); - let assets = (Parent, amount_to_send).into(); - - let test_args = TestContext { - sender: PeopleRococoSender::get(), - receiver: RococoReceiver::get(), - args: para_test_args(destination, beneficiary_id, amount_to_send, assets, None, 0), - }; - - let mut test = SystemParaToRelayTest::new(test_args); - - let sender_balance_before = test.sender.balance; - let receiver_balance_before = test.receiver.balance; - - test.set_assertion::(para_origin_assertions); - test.set_assertion::(relay_dest_assertions); - test.set_dispatchable::(system_para_teleport_assets); - test.assert(); - - let sender_balance_after = test.sender.balance; - let receiver_balance_after = test.receiver.balance; - - let delivery_fees = PeopleRococo::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::< - ::XcmSender, - >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) - }); - - // Sender's balance is reduced - assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); - // Receiver's balance is increased - assert!(receiver_balance_after > receiver_balance_before); -} - -/// Teleport of native asset from System Parachain to Relay Chain -/// shouldn't work when there is not enough balance in Relay Chain's `CheckAccount` -#[test] -fn teleport_native_assets_from_system_para_to_relay_fails() { - // Init values for Relay Chain - let amount_to_send: Balance = PEOPLE_ROCOCO_ED * 1000; - let destination = PeopleRococo::parent_location(); - let beneficiary_id = RococoReceiver::get(); - let assets = (Parent, amount_to_send).into(); - - let test_args = TestContext { - sender: PeopleRococoSender::get(), - receiver: RococoReceiver::get(), - args: para_test_args(destination, beneficiary_id, amount_to_send, assets, None, 0), - }; - - let mut test = SystemParaToRelayTest::new(test_args); - - let sender_balance_before = test.sender.balance; - let receiver_balance_before = test.receiver.balance; - - test.set_assertion::(para_origin_assertions); - test.set_assertion::(relay_dest_assertions_fail); - test.set_dispatchable::(system_para_teleport_assets); - test.assert(); - - let delivery_fees = PeopleRococo::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::< - ::XcmSender, - >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) - }); - - let sender_balance_after = test.sender.balance; - let receiver_balance_after = test.receiver.balance; - - // Sender's balance is reduced - assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); - // Receiver's balance does not change - assert_eq!(receiver_balance_after, receiver_balance_before); -} - // #[test] // fn teleport_to_other_system_parachains_works() { // let amount = PEOPLE_ROCOCO_ED * 100; diff --git a/cumulus/xcm/xcm-emulator/src/lib.rs b/cumulus/xcm/xcm-emulator/src/lib.rs index f2e4ff397c45..5580c51b6e75 100644 --- a/cumulus/xcm/xcm-emulator/src/lib.rs +++ b/cumulus/xcm/xcm-emulator/src/lib.rs @@ -1498,6 +1498,7 @@ where pub fn set_assertion(&mut self, assertion: fn(Self)) { let chain_name = std::any::type_name::(); self.hops_assertion.insert(chain_name.to_string(), assertion); + } /// Stores a dispatchable in a particular Chain pub fn set_dispatchable(&mut self, dispatchable: fn(Self) -> DispatchResult) { diff --git a/polkadot/runtime/rococo/constants/src/lib.rs b/polkadot/runtime/rococo/constants/src/lib.rs index 2f641d60fc8b..295931d71ae8 100644 --- a/polkadot/runtime/rococo/constants/src/lib.rs +++ b/polkadot/runtime/rococo/constants/src/lib.rs @@ -111,6 +111,8 @@ pub mod system_parachain { pub const CONTRACTS_ID: u32 = 1002; /// Encointer parachain ID. pub const ENCOINTER_ID: u32 = 1003; + /// People parachain ID. + pub const PEOPLE_ID: u32 = 1004; /// BridgeHub parachain ID. pub const BRIDGE_HUB_ID: u32 = 1013; diff --git a/polkadot/runtime/rococo/src/xcm_config.rs b/polkadot/runtime/rococo/src/xcm_config.rs index c8f8f59dae99..db343684b4d3 100644 --- a/polkadot/runtime/rococo/src/xcm_config.rs +++ b/polkadot/runtime/rococo/src/xcm_config.rs @@ -118,6 +118,7 @@ parameter_types! { pub const Contracts: MultiLocation = Parachain(CONTRACTS_ID).into_location(); pub const Encointer: MultiLocation = Parachain(ENCOINTER_ID).into_location(); pub const BridgeHub: MultiLocation = Parachain(BRIDGE_HUB_ID).into_location(); + pub const People: MultiLocation = Parachain(PEOPLE_ID).into_location(); pub const Tick: MultiLocation = Parachain(100).into_location(); pub const Trick: MultiLocation = Parachain(110).into_location(); pub const Track: MultiLocation = Parachain(120).into_location(); @@ -128,6 +129,7 @@ parameter_types! { pub const RocForContracts: (MultiAssetFilter, MultiLocation) = (Roc::get(), Contracts::get()); pub const RocForEncointer: (MultiAssetFilter, MultiLocation) = (Roc::get(), Encointer::get()); pub const RocForBridgeHub: (MultiAssetFilter, MultiLocation) = (Roc::get(), BridgeHub::get()); + pub const RocForPeople: (MultiAssetFilter, MultiLocation) = (Roc::get(), People::get()); pub const MaxInstructions: u32 = 100; pub const MaxAssetsIntoHolding: u32 = 64; } @@ -139,6 +141,7 @@ pub type TrustedTeleporters = ( xcm_builder::Case, xcm_builder::Case, xcm_builder::Case, + xcm_builder::Case, ); match_types! { diff --git a/polkadot/xcm/xcm-builder/src/currency_adapter.rs b/polkadot/xcm/xcm-builder/src/currency_adapter.rs index 8ecf1dee72db..119091f320c7 100644 --- a/polkadot/xcm/xcm-builder/src/currency_adapter.rs +++ b/polkadot/xcm/xcm-builder/src/currency_adapter.rs @@ -213,6 +213,7 @@ impl< log::trace!(target: "xcm::currency_adapter", "withdraw_asset what: {:?}, who: {:?}", what, who); // Check we handle this asset. let amount = Matcher::matches_fungible(what).ok_or(Error::AssetNotHandled)?; + log::trace!(target: "xcm::currency_adapter", "amount to convert_location with Account Id"); let who = AccountIdConverter::convert_location(who).ok_or(Error::AccountIdConversionFailed)?; Currency::withdraw(&who, amount, WithdrawReasons::TRANSFER, AllowDeath) From 3b3454c51d6aa26764f4fb47dfe9f1f4adfe3186 Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Mon, 27 Nov 2023 19:37:42 +0000 Subject: [PATCH 041/102] update amounts and weights, all tests passing --- .../parachains/people/people-rococo/src/genesis.rs | 3 ++- .../emulated/tests/people/people-rococo/Cargo.toml | 3 +++ .../people/people-rococo/src/tests/teleport.rs | 14 ++++++++------ polkadot/xcm/xcm-builder/src/currency_adapter.rs | 1 - 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/genesis.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/genesis.rs index 28a90fab8523..5ca98e4d1ce5 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/genesis.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/genesis.rs @@ -18,7 +18,8 @@ use cumulus_primitives_core::ParaId; use sp_core::storage::Storage; // Cumulus -use emulated_integration_tests_common::{build_genesis_storage, collators, SAFE_XCM_VERSION}; +use emulated_integration_tests_common::{build_genesis_storage, accounts, collators, + SAFE_XCM_VERSION}; use parachains_common::Balance; pub const PARA_ID: u32 = 1004; diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/Cargo.toml b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/Cargo.toml index e2633d758c97..0d37cca64d02 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/Cargo.toml @@ -7,6 +7,9 @@ license = "Apache-2.0" description = "People Rococo runtime integration tests with xcm-emulator" publish = false +[features] +teleport_tests = [] + [dependencies] codec = { package = "parity-scale-codec", version = "3.4.0", default-features = false } assert_matches = "1.5.0" diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs index 255671ea6c8f..eec94041d679 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs @@ -45,7 +45,7 @@ fn relay_dest_assertions(t: SystemParaToRelayTest) { Rococo::assert_ump_queue_processed( true, Some(PeopleRococo::para_id()), - Some(Weight::from_parts(307_225_000, 7_186)), + Some(Weight::from_parts(304_266_000, 7_186)), ); assert_expected_events!( @@ -76,8 +76,8 @@ fn para_origin_assertions(t: SystemParaToRelayTest) { type RuntimeEvent = ::RuntimeEvent; PeopleRococo::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts( - 720_053_000, - 7_203, + 600_000_000, + 7_000, ))); PeopleRococo::assert_parachain_system_ump_sent(); @@ -194,11 +194,13 @@ fn limited_teleport_native_assets_from_relay_to_system_para_works() { /// should work when there is enough balance in Relay Chain's `CheckAccount` #[test] fn limited_teleport_native_assets_back_from_system_para_to_relay_works() { + // Dependency - Relay Chain's `CheckAccount` should have enough balance limited_teleport_native_assets_from_relay_to_system_para_works(); - // Init values for Relay Chain - let amount_to_send: Balance = PEOPLE_ROCOCO_ED * 1000; + // Init values for Relay Chain, we set this amount because + // there are no balances in PeopleRococo created at genesis. + let amount_to_send: Balance = ROCOCO_ED * 1000; let destination = PeopleRococo::parent_location(); let beneficiary_id = RococoReceiver::get(); let assets = (Parent, amount_to_send).into(); @@ -239,7 +241,7 @@ fn limited_teleport_native_assets_back_from_system_para_to_relay_works() { #[test] fn limited_teleport_native_assets_from_system_para_to_relay_fails() { // Init values for Relay Chain - let amount_to_send: Balance = PEOPLE_ROCOCO_ED * 1000; + let amount_to_send: Balance = ROCOCO_ED * 1000; let destination = PeopleRococo::parent_location().into(); let beneficiary_id = RococoReceiver::get().into(); let assets = (Parent, amount_to_send).into(); diff --git a/polkadot/xcm/xcm-builder/src/currency_adapter.rs b/polkadot/xcm/xcm-builder/src/currency_adapter.rs index 119091f320c7..8ecf1dee72db 100644 --- a/polkadot/xcm/xcm-builder/src/currency_adapter.rs +++ b/polkadot/xcm/xcm-builder/src/currency_adapter.rs @@ -213,7 +213,6 @@ impl< log::trace!(target: "xcm::currency_adapter", "withdraw_asset what: {:?}, who: {:?}", what, who); // Check we handle this asset. let amount = Matcher::matches_fungible(what).ok_or(Error::AssetNotHandled)?; - log::trace!(target: "xcm::currency_adapter", "amount to convert_location with Account Id"); let who = AccountIdConverter::convert_location(who).ok_or(Error::AccountIdConversionFailed)?; Currency::withdraw(&who, amount, WithdrawReasons::TRANSFER, AllowDeath) From 6d868e1592b20c4b3d8ea96a037c0904ec7d9ee9 Mon Sep 17 00:00:00 2001 From: Richard Melkonian <35300528+0xmovses@users.noreply.github.com> Date: Tue, 28 Nov 2023 11:08:07 +0000 Subject: [PATCH 042/102] Update cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/lib.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Dónal Murray --- .../emulated/chains/parachains/people/people-rococo/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/lib.rs index 85c295fa25f7..a07ae1438436 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/lib.rs @@ -24,7 +24,7 @@ use emulated_integration_tests_common::{ impls::Parachain, xcm_emulator::decl_test_parachains, }; -// AssetHubRococo Parachain declaration +// PeopleRococo Parachain declaration decl_test_parachains! { pub struct PeopleRococo { genesis = genesis::genesis(), From ee8d510bf7531d09aa6ccf7eae4b40fc887823a8 Mon Sep 17 00:00:00 2001 From: Richard Melkonian <35300528+0xmovses@users.noreply.github.com> Date: Tue, 28 Nov 2023 12:15:08 +0000 Subject: [PATCH 043/102] Update cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Dónal Murray --- .../tests/people/people-rococo/src/tests/reap_identity.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index bafd7e67f50b..c20639c29a3a 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -67,7 +67,7 @@ fn id_deposit_relaychain(id: &IdentityInfo) -> Balance { } #[test] -fn reap_identity() { +fn on_reap_identity_works() { let identity_relaychain = identity_relay(); let identity_parachain = identity_parachain(); let mut total_deposit = 0_u128; From 8f54f7b7c65a0c853c93dfefb2112054349ff19f Mon Sep 17 00:00:00 2001 From: Richard Melkonian <35300528+0xmovses@users.noreply.github.com> Date: Tue, 28 Nov 2023 12:43:08 +0000 Subject: [PATCH 044/102] Update cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Dónal Murray --- .../tests/people/people-rococo/src/tests/reap_identity.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index c20639c29a3a..11cf06daee2d 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -145,9 +145,9 @@ fn on_reap_identity_works() { &PeopleRococoSender::get() ) .is_some()); - let tuple_subs = + let (_, sub_accounts) = ::Identity::subs_of(&PeopleRococoSender::get()); - assert!(tuple_subs.1.len() > 0); + assert!(sub_accounts.len() > 0); }); // 5. reap_identity on Relay Chain From b4e826e109d78ddca2266222155d55320201329f Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Tue, 28 Nov 2023 11:08:32 +0000 Subject: [PATCH 045/102] updates --- .../people/people-rococo/src/genesis.rs | 5 ++--- .../parachains/people/people-rococo/src/lib.rs | 3 ++- .../tests/people/people-rococo/src/lib.rs | 2 ++ .../people/people-rococo/src/tests/teleport.rs | 15 +++++++++------ 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/genesis.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/genesis.rs index 5ca98e4d1ce5..bc1dcbd08d1d 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/genesis.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/genesis.rs @@ -13,13 +13,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -use cumulus_primitives_core::ParaId; // Substrate use sp_core::storage::Storage; // Cumulus -use emulated_integration_tests_common::{build_genesis_storage, accounts, collators, - SAFE_XCM_VERSION}; +use emulated_integration_tests_common::{build_genesis_storage, collators, SAFE_XCM_VERSION}; +use cumulus_primitives_core::ParaId; use parachains_common::Balance; pub const PARA_ID: u32 = 1004; diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/lib.rs index a07ae1438436..5fc553f96edb 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/lib.rs @@ -21,8 +21,9 @@ use frame_support::traits::OnInitialize; // Cumulus use emulated_integration_tests_common::{ impl_accounts_helpers_for_parachain, impl_assert_events_helpers_for_parachain, - impls::Parachain, xcm_emulator::decl_test_parachains, + impls::Parachain, xcm_emulator::decl_test_parachains, impl_assets_helpers_for_parachain, }; +use rococo_emulated_chain::Rococo; // PeopleRococo Parachain declaration decl_test_parachains! { diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/lib.rs index caa6311de65b..586bebafc19b 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/lib.rs @@ -53,6 +53,8 @@ pub use rococo_system_emulated_network::{ }; +pub const ASSET_ID: u32 = 1; +pub const ASSET_MIN_BALANCE: u128 = 1000; pub type RelayToSystemParaTest = Test; pub type RelayToParaTest = Test; pub type SystemParaToRelayTest = Test; diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs index eec94041d679..71f0e1c8d0c2 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs @@ -13,6 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +use emulated_integration_tests_common::accounts; use crate::*; use people_rococo_runtime::xcm_config::XcmConfig as PeopleRococoXcmConfig; @@ -194,19 +195,20 @@ fn limited_teleport_native_assets_from_relay_to_system_para_works() { /// should work when there is enough balance in Relay Chain's `CheckAccount` #[test] fn limited_teleport_native_assets_back_from_system_para_to_relay_works() { - // Dependency - Relay Chain's `CheckAccount` should have enough balance limited_teleport_native_assets_from_relay_to_system_para_works(); - // Init values for Relay Chain, we set this amount because - // there are no balances in PeopleRococo created at genesis. - let amount_to_send: Balance = ROCOCO_ED * 1000; + let amount_to_send: Balance = PEOPLE_ROCOCO_ED * 1000; let destination = PeopleRococo::parent_location(); let beneficiary_id = RococoReceiver::get(); let assets = (Parent, amount_to_send).into(); + + // set sender to PeopleRococoReceiver because they just received + // assets from limited_teleport call above. PeopleRococo has + // no balances on Genesis. let test_args = TestContext { - sender: PeopleRococoSender::get(), + sender: PeopleRococoReceiver::get(), receiver: RococoReceiver::get(), args: para_test_args(destination, beneficiary_id, amount_to_send, assets, None, 0), }; @@ -214,6 +216,7 @@ fn limited_teleport_native_assets_back_from_system_para_to_relay_works() { let mut test = SystemParaToRelayTest::new(test_args); let sender_balance_before = test.sender.balance; + println!("sender_balance_before: {:?}", sender_balance_before); let receiver_balance_before = test.receiver.balance; test.set_assertion::(para_origin_assertions); @@ -247,7 +250,7 @@ fn limited_teleport_native_assets_from_system_para_to_relay_fails() { let assets = (Parent, amount_to_send).into(); let test_args = TestContext { - sender: PeopleRococoSender::get(), + sender: PeopleRococoReceiver::get(), receiver: RococoReceiver::get(), args: para_test_args(destination, beneficiary_id, amount_to_send, assets, None, 0), }; From 12840efab7a1946c47a5d9b32271f5601261038c Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Tue, 28 Nov 2023 12:17:28 +0000 Subject: [PATCH 046/102] address pr feedback --- .../emulated/common/src/lib.rs | 44 ++++++++++++++++++- .../tests/assets/asset-hub-rococo/src/lib.rs | 37 ---------------- .../src/tests/reserve_transfer.rs | 1 + .../asset-hub-rococo/src/tests/teleport.rs | 1 + .../tests/assets/asset-hub-westend/src/lib.rs | 36 --------------- .../tests/people/people-rococo/Cargo.toml | 7 +-- .../tests/people/people-rococo/src/lib.rs | 35 --------------- .../people-rococo/src/tests/teleport.rs | 16 +++---- substrate/frame/identity/Cargo.toml | 2 +- substrate/frame/identity/src/lib.rs | 4 +- 10 files changed, 55 insertions(+), 128 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/common/src/lib.rs b/cumulus/parachains/integration-tests/emulated/common/src/lib.rs index 952b053f2aa2..dcdd8bb60095 100644 --- a/cumulus/parachains/integration-tests/emulated/common/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/common/src/lib.rs @@ -31,14 +31,16 @@ use sp_runtime::{ }; // Polakdot -use parachains_common::BlockNumber; +use parachains_common::{Balance, BlockNumber}; use polkadot_runtime_parachains::configuration::HostConfiguration; -use xcm; +use xcm::prelude::{MultiLocation, MultiAssets, WeightLimit, AccountId32 as AccountId32Junction, Here}; // Cumulus use parachains_common::{AccountId, AssetHubPolkadotAuraId, AuraId}; use polkadot_primitives::{AssignmentId, ValidatorId}; use polkadot_service::chain_spec::get_authority_keys_from_seed_no_beefy; +use sp_core::crypto::AccountId32; +use xcm_emulator::TestArgs; pub const XCM_V2: u32 = 2; pub const XCM_V3: u32 = 3; @@ -83,6 +85,44 @@ pub fn get_host_config() -> HostConfiguration { } } + +/// Returns a `TestArgs` instance to be used for the Relay Chain across integration tests +pub fn relay_test_args( + dest: MultiLocation, + beneficiary_id: AccountId32, + amount: Balance, +) -> TestArgs { + TestArgs { + dest, + beneficiary: AccountId32Junction { network: None, id: beneficiary_id.into() }.into(), + amount, + assets: (Here, amount).into(), + asset_id: None, + fee_asset_item: 0, + weight_limit: WeightLimit::Unlimited, + } +} + +/// Returns a `TestArgs` instance to be used by parachains across integration tests +pub fn para_test_args( + dest: MultiLocation, + beneficiary_id: AccountId32, + amount: Balance, + assets: MultiAssets, + asset_id: Option, + fee_asset_item: u32, +) -> TestArgs { + TestArgs { + dest, + beneficiary: AccountId32Junction { network: None, id: beneficiary_id.into() }.into(), + amount, + assets, + asset_id, + fee_asset_item, + weight_limit: WeightLimit::Unlimited, + } +} + /// Helper function used in tests to build the genesis storage using given RuntimeGenesisConfig and /// code Used in `legacy_vs_json_check` submods to verify storage building with JSON patch against /// building with RuntimeGenesisConfig struct. diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/lib.rs index 3ff8c37c6465..721f8b511ea6 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/lib.rs @@ -66,42 +66,5 @@ pub type SystemParaToRelayTest = Test; pub type SystemParaToParaTest = Test; pub type ParaToSystemParaTest = Test; -/// Returns a `TestArgs` instance to be used for the Relay Chain across integration tests -pub fn relay_test_args( - dest: MultiLocation, - beneficiary_id: AccountId32, - amount: Balance, -) -> TestArgs { - TestArgs { - dest, - beneficiary: AccountId32Junction { network: None, id: beneficiary_id.into() }.into(), - amount, - assets: (Here, amount).into(), - asset_id: None, - fee_asset_item: 0, - weight_limit: WeightLimit::Unlimited, - } -} - -/// Returns a `TestArgs` instance to be used by parachains across integration tests -pub fn para_test_args( - dest: MultiLocation, - beneficiary_id: AccountId32, - amount: Balance, - assets: MultiAssets, - asset_id: Option, - fee_asset_item: u32, -) -> TestArgs { - TestArgs { - dest, - beneficiary: AccountId32Junction { network: None, id: beneficiary_id.into() }.into(), - amount, - assets, - asset_id, - fee_asset_item, - weight_limit: WeightLimit::Unlimited, - } -} - #[cfg(test)] mod tests; diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs index d0e9b72176bc..b10036037d17 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs @@ -15,6 +15,7 @@ use crate::*; use asset_hub_rococo_runtime::xcm_config::XcmConfig as AssetHubRococoXcmConfig; +use emulated_integration_tests_common::{para_test_args, relay_test_args}; use penpal_runtime::xcm_config::XcmConfig as PenpalRococoXcmConfig; use rococo_runtime::xcm_config::XcmConfig as RococoXcmConfig; diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs index f8017f7a1c54..8391e64670e0 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs @@ -15,6 +15,7 @@ use crate::*; use asset_hub_rococo_runtime::xcm_config::XcmConfig as AssetHubRococoXcmConfig; +use emulated_integration_tests_common::{para_test_args, relay_test_args}; use rococo_runtime::xcm_config::XcmConfig as RococoXcmConfig; fn relay_origin_assertions(t: RelayToSystemParaTest) { diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/lib.rs index 83a867e6ae31..00a8e9ba5b0e 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/lib.rs @@ -65,41 +65,5 @@ pub type RelayToSystemParaTest = Test; pub type SystemParaToRelayTest = Test; pub type SystemParaToParaTest = Test; -/// Returns a `TestArgs` instance to be used for the Relay Chain across integration tests -pub fn relay_test_args(amount: Balance) -> TestArgs { - TestArgs { - dest: Westend::child_location_of(AssetHubWestend::para_id()), - beneficiary: AccountId32Junction { - network: None, - id: AssetHubWestendReceiver::get().into(), - } - .into(), - amount, - assets: (Here, amount).into(), - asset_id: None, - fee_asset_item: 0, - weight_limit: WeightLimit::Unlimited, - } -} - -/// Returns a `TestArgs` instance to be used for the System Parachain across integration tests -pub fn system_para_test_args( - dest: MultiLocation, - beneficiary_id: AccountId32, - amount: Balance, - assets: MultiAssets, - asset_id: Option, -) -> TestArgs { - TestArgs { - dest, - beneficiary: AccountId32Junction { network: None, id: beneficiary_id.into() }.into(), - amount, - assets, - asset_id, - fee_asset_item: 0, - weight_limit: WeightLimit::Unlimited, - } -} - #[cfg(test)] mod tests; diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/Cargo.toml b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/Cargo.toml index 0d37cca64d02..ad97f5184e11 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/Cargo.toml @@ -7,9 +7,6 @@ license = "Apache-2.0" description = "People Rococo runtime integration tests with xcm-emulator" publish = false -[features] -teleport_tests = [] - [dependencies] codec = { package = "parity-scale-codec", version = "3.4.0", default-features = false } assert_matches = "1.5.0" @@ -21,12 +18,12 @@ pallet-balances = { path = "../../../../../../../substrate/frame/balances", defa pallet-assets = { path = "../../../../../../../substrate/frame/assets", default-features = false} pallet-asset-conversion = { path = "../../../../../../../substrate/frame/asset-conversion", default-features = false} pallet-message-queue = { path = "../../../../../../../substrate/frame/message-queue", default-features = false } -pallet-identity = { path = "../../../../../../../substrate/frame/identity", default-features = false, features = ["xcm-emulator"] } +pallet-identity = { path = "../../../../../../../substrate/frame/identity", default-features = false, features =["xcm-emulator"] } # Polkadot xcm = { package = "staging-xcm", path = "../../../../../../../polkadot/xcm", default-features = false} pallet-xcm = { path = "../../../../../../../polkadot/xcm/pallet-xcm", default-features = false} -xcm-executor = { package = "staging-xcm-executor", path = "../../../../../../../polkadot/xcm/xcm-executor", default-features = false} +xcm-executor = { package = "staging-xcm-executor", path = "../../../../../../../polkadot/xcm/xcm-executor", default-features = false } rococo-runtime = { path = "../../../../../../../polkadot/runtime/rococo" } polkadot-primitives = { path = "../../../../../../../polkadot/primitives" } polkadot-runtime-common = { path = "../../../../../../../polkadot/runtime/common"} diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/lib.rs index 586bebafc19b..02a584e1a574 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/lib.rs @@ -61,42 +61,7 @@ pub type SystemParaToRelayTest = Test; pub type SystemParaToParaTest = Test; pub type ParaToSystemParaTest = Test; -/// Returns a `TestArgs` instance to be used for the Relay Chain across integration tests -pub fn relay_test_args( - dest: MultiLocation, - beneficiary_id: AccountId32, - amount: Balance, -) -> TestArgs { - TestArgs { - dest, - beneficiary: AccountId32Junction { network: None, id: beneficiary_id.into() }.into(), - amount, - assets: (Here, amount).into(), - asset_id: None, - fee_asset_item: 0, - weight_limit: WeightLimit::Unlimited, - } -} -/// Returns a `TestArgs` instance to be used by parachains across integration tests -pub fn para_test_args( - dest: MultiLocation, - beneficiary_id: AccountId32, - amount: Balance, - assets: MultiAssets, - asset_id: Option, - fee_asset_item: u32, -) -> TestArgs { - TestArgs { - dest, - beneficiary: AccountId32Junction { network: None, id: beneficiary_id.into() }.into(), - amount, - assets, - asset_id, - fee_asset_item, - weight_limit: WeightLimit::Unlimited, - } -} #[cfg(test)] mod tests; diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs index 71f0e1c8d0c2..095df38eb53d 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs @@ -13,9 +13,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -use emulated_integration_tests_common::accounts; use crate::*; - +use emulated_integration_tests_common::{para_test_args, relay_test_args}; use people_rococo_runtime::xcm_config::XcmConfig as PeopleRococoXcmConfig; use rococo_runtime::xcm_config::XcmConfig as RococoXcmConfig; @@ -216,7 +215,6 @@ fn limited_teleport_native_assets_back_from_system_para_to_relay_works() { let mut test = SystemParaToRelayTest::new(test_args); let sender_balance_before = test.sender.balance; - println!("sender_balance_before: {:?}", sender_balance_before); let receiver_balance_before = test.receiver.balance; test.set_assertion::(para_origin_assertions); @@ -250,32 +248,30 @@ fn limited_teleport_native_assets_from_system_para_to_relay_fails() { let assets = (Parent, amount_to_send).into(); let test_args = TestContext { - sender: PeopleRococoReceiver::get(), + sender: PeopleRococoSender::get(), receiver: RococoReceiver::get(), args: para_test_args(destination, beneficiary_id, amount_to_send, assets, None, 0), }; let mut test = SystemParaToRelayTest::new(test_args); - let sender_balance_before = test.sender.balance; let receiver_balance_before = test.receiver.balance; test.set_assertion::(para_origin_assertions); test.set_assertion::(relay_dest_assertions_fail); test.set_dispatchable::(system_para_limited_teleport_assets); - test.assert(); - let sender_balance_after = test.sender.balance; let receiver_balance_after = test.receiver.balance; - let delivery_fees = PeopleRococo::execute_with(|| { + let _delivery_fees = PeopleRococo::execute_with(|| { xcm_helpers::transfer_assets_delivery_fees::< ::XcmSender, >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) }); - // Sender's balance is reduced - assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); + // We don't check of sender's balance is reduced because they have no balance + // at genesis. + // Receiver's balance does not change assert_eq!(receiver_balance_after, receiver_balance_before); } diff --git a/substrate/frame/identity/Cargo.toml b/substrate/frame/identity/Cargo.toml index b931076ae3ed..8f4901d4026f 100644 --- a/substrate/frame/identity/Cargo.toml +++ b/substrate/frame/identity/Cargo.toml @@ -28,8 +28,8 @@ pallet-balances = { path = "../balances" } sp-core = { path = "../../primitives/core" } [features] -xcm-emulator = [] default = [ "std" ] +xcm-emulator = [] std = [ "codec/std", "enumflags2/std", diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index 9350ab30ec4c..b220f8dab990 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -1007,7 +1007,7 @@ impl Pallet { /// Set an identity with zero deposit. Used for benchmarking and XCM emulator tests, involves /// `rejig_deposit`. - #[cfg(any(feature = "xcm-emulator", feature = "runtime-benchmarks"))] + #[cfg(any(feature = "runtime-benchmarks", feature = "xcm-emulator"))] pub fn set_identity_no_deposit( who: &T::AccountId, info: T::IdentityInformation, @@ -1024,7 +1024,7 @@ impl Pallet { } /// Set subs with zero deposit. Only used for benchmarking that involves `rejig_deposit`. - #[cfg(any(feature = "xcm-emulator", feature = "runtime-benchmarks"))] + #[cfg(any(feature = "runtime-benchmarks", feature = "xcm-emulator"))] pub fn set_sub_no_deposit(who: &T::AccountId, sub: T::AccountId) -> DispatchResult { use frame_support::BoundedVec; let subs = BoundedVec::<_, T::MaxSubAccounts>::try_from(vec![sub]).unwrap(); From 7ccfff32dad02609039166efcff8990715f9d230 Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Tue, 28 Nov 2023 12:43:46 +0000 Subject: [PATCH 047/102] add type aliases --- .../people/people-rococo/src/lib.rs | 3 +- .../people-rococo/src/tests/reap_identity.rs | 78 ++++++++++--------- .../people-rococo/src/tests/teleport.rs | 19 ----- 3 files changed, 42 insertions(+), 58 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/lib.rs index 5fc553f96edb..a07ae1438436 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/lib.rs @@ -21,9 +21,8 @@ use frame_support::traits::OnInitialize; // Cumulus use emulated_integration_tests_common::{ impl_accounts_helpers_for_parachain, impl_assert_events_helpers_for_parachain, - impls::Parachain, xcm_emulator::decl_test_parachains, impl_assets_helpers_for_parachain, + impls::Parachain, xcm_emulator::decl_test_parachains, }; -use rococo_emulated_chain::Rococo; // PeopleRococo Parachain declaration decl_test_parachains! { diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index 11cf06daee2d..23701fca48a8 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -14,16 +14,23 @@ // limitations under the License. use crate::*; -use pallet_identity::{legacy::IdentityInfo, Data}; +use pallet_identity::{legacy::IdentityInfo, Data, Event as IdentityEvent}; +use pallet_balances::Event as BalancesEvent; use people_rococo_runtime::people::{ BasicDeposit as BasicDepositParachain, ByteDeposit as ByteDepositParachain, IdentityInfo as IdentityInfoParachain, SubAccountDeposit as SubAccountDepositParachain, }; -use rococo_runtime::{BasicDeposit, ByteDeposit, MaxAdditionalFields, SubAccountDeposit}; +use rococo_runtime::{BasicDeposit, ByteDeposit, MaxAdditionalFields, SubAccountDeposit, RuntimeOrigin as RococoOrigin}; use rococo_system_emulated_network::{ rococo_emulated_chain::RococoRelayPallet, RococoRelay, RococoRelayReceiver, RococoRelaySender, }; +type RococoIdentity = ::Identity; +type RococoBalances = ::Balances; +type RococoIdentityMigrator = ::IdentityMigrator; +type PeopleRococoIdentity = ::Identity; +type PeopleRococoBalances = ::Balances; + fn identity_relay() -> IdentityInfo { IdentityInfo { display: Data::Raw(b"xcm-test".to_vec().try_into().unwrap()), @@ -77,32 +84,32 @@ fn on_reap_identity_works() { type RuntimeEvent = ::RuntimeEvent; // 1. Set identity on Relay Chain - assert_ok!(::Identity::set_identity( - rococo_runtime::RuntimeOrigin::signed(RococoRelaySender::get()), + assert_ok!(RococoIdentity::set_identity( + RococoOrigin::signed(RococoRelaySender::get()), Box::new(identity_relaychain.clone()) )); assert_expected_events!( RococoRelay, vec![ - RuntimeEvent::Identity(pallet_identity::Event::IdentitySet { .. }) => {}, - RuntimeEvent::Balances(pallet_balances::Event::Reserved { .. }) => {}, + RuntimeEvent::Identity(IdentityEvent::IdentitySet { .. }) => {}, + RuntimeEvent::Balances(BalancesEvent::Reserved { .. }) => {}, ] ); // 2. Set sub-identity on Relay Chain - assert_ok!(::Identity::set_subs( - rococo_runtime::RuntimeOrigin::signed(RococoRelaySender::get()), + assert_ok!(RococoIdentity::set_subs( + RococoOrigin::signed(RococoRelaySender::get()), vec![(RococoRelayReceiver::get(), Data::Raw(vec![42; 1].try_into().unwrap()))], )); assert_expected_events!( RococoRelay, vec![ - RuntimeEvent::Identity(pallet_identity::Event::IdentitySet { .. }) => {}, - RuntimeEvent::Balances(pallet_balances::Event::Reserved { .. }) => {}, + RuntimeEvent::Identity(IdentityEvent::IdentitySet { .. }) => {}, + RuntimeEvent::Balances(BalancesEvent::Reserved { .. }) => {}, ] ); - let reserved_bal = ::Balances::reserved_balance( + let reserved_bal = RococoBalances::reserved_balance( RococoRelaySender::get(), ); total_deposit = SubAccountDeposit::get() + id_deposit_relaychain(&identity_relaychain); @@ -114,8 +121,8 @@ fn on_reap_identity_works() { // Set identity and Subs on Parachain with Zero deposit PeopleRococo::execute_with(|| { let free_bal = - ::Balances::free_balance(PeopleRococoSender::get()); - let reserved_bal = ::Balances::reserved_balance( + PeopleRococoBalances::free_balance(PeopleRococoSender::get()); + let reserved_bal = PeopleRococoBalances::reserved_balance( PeopleRococoSender::get(), ); @@ -123,13 +130,13 @@ fn on_reap_identity_works() { assert_eq!(reserved_bal + free_bal, 0); // 3. Set identity on Parachain - assert_ok!(::Identity::set_identity_no_deposit( + assert_ok!(PeopleRococoIdentity::set_identity_no_deposit( &PeopleRococoSender::get(), identity_parachain.clone() )); // 4. Set sub-identity on Parachain - assert_ok!(::Identity::set_sub_no_deposit( + assert_ok!(PeopleRococoIdentity::set_sub_no_deposit( &PeopleRococoSender::get(), PeopleRococoReceiver::get(), )); @@ -137,11 +144,11 @@ fn on_reap_identity_works() { // No events get triggered when calling set_sub_no_deposit // No amount should be reserved as deposit amounts are set to 0. - let reserved_bal = ::Balances::reserved_balance( + let reserved_bal = PeopleRococoBalances::reserved_balance( PeopleRococoSender::get(), ); assert_eq!(reserved_bal, 0); - assert!(::Identity::identity( + assert!(PeopleRococoIdentity::identity( &PeopleRococoSender::get() ) .is_some()); @@ -154,47 +161,48 @@ fn on_reap_identity_works() { RococoRelay::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; let free_bal_before_reap = - ::Balances::free_balance(RococoRelaySender::get()); - let reserved_balance = ::Balances::reserved_balance( + RococoBalances::free_balance(RococoRelaySender::get()); + let reserved_balance = RococoBalances::reserved_balance( RococoRelaySender::get(), ); //before reap reserved balance should be equal to total deposit assert_eq!(reserved_balance, total_deposit); - assert_ok!(::IdentityMigrator::reap_identity( - rococo_runtime::RuntimeOrigin::root(), + assert_ok!(RococoIdentityMigrator::reap_identity( + RococoOrigin::root(), RococoRelaySender::get(), )); assert_expected_events!( RococoRelay, vec![ - RuntimeEvent::Balances(pallet_balances::Event::Unreserved { who, amount }) => { + RuntimeEvent::Balances(BalancesEvent::Unreserved { who, amount }) => { who: *who == RococoRelaySender::get(), amount: *amount == total_deposit, }, ] ); - assert!(::Identity::identity(&RococoRelaySender::get()) + assert!(PeopleRococoIdentity::identity(&RococoRelaySender::get()) .is_none()); let tuple_subs = - ::Identity::subs_of(&RococoRelaySender::get()); + RococoIdentity::subs_of(&RococoRelaySender::get()); assert_eq!(tuple_subs.1.len(), 0); - let reserved_balance = ::Balances::reserved_balance( + let reserved_balance = RococoBalances::reserved_balance( RococoRelaySender::get(), ); // after reap reserved balance should be 0 assert_eq!(reserved_balance, 0); let free_bal_after_reap = - ::Balances::free_balance(RococoRelaySender::get()); + RococoBalances::free_balance(RococoRelaySender::get()); // free balance should be greater than before reap assert!(free_bal_after_reap > free_bal_before_reap); + assert_eq!(free_bal_after_reap, free_bal_before_reap + total_deposit); }); // 6. assert on Parachain PeopleRococo::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; - let reserved_bal = ::Balances::reserved_balance( + let reserved_bal = PeopleRococoBalances::reserved_balance( PeopleRococoSender::get(), ); let id_deposit = id_deposit_parachain(&identity_parachain); @@ -204,13 +212,13 @@ fn on_reap_identity_works() { assert_expected_events!( PeopleRococo, vec![ - RuntimeEvent::Balances(pallet_balances::Event::Deposit { ..}) => {}, - RuntimeEvent::Balances(pallet_balances::Event::Endowed { ..}) => {}, - RuntimeEvent::Balances(pallet_balances::Event::Reserved { who, amount }) => { + RuntimeEvent::Balances(BalancesEvent::Deposit { .. }) => {}, + RuntimeEvent::Balances(BalancesEvent::Endowed { .. }) => {}, + RuntimeEvent::Balances(BalancesEvent::Reserved { who, amount }) => { who: *who == PeopleRococoSender::get(), amount: *amount == id_deposit, }, - RuntimeEvent::Balances(pallet_balances::Event::Reserved { who, amount }) => { + RuntimeEvent::Balances(BalancesEvent::Reserved { who, amount }) => { who: *who == PeopleRococoSender::get(), amount: *amount == subs_deposit, }, @@ -228,11 +236,7 @@ fn on_reap_identity_works() { // reserved balance should be equal to total deposit calculated on the Parachain assert_eq!(reserved_bal, total_deposit); - - let free_bal = - ::Balances::free_balance(PeopleRococoSender::get()); - - // Atleast a single Existential Deposit should be free - assert!(free_bal >= PEOPLE_ROCOCO_ED); + // A single Existential Deposit should be free + assert!(PeopleRococoBalances::free_balance(PeopleRococoSender::get()) == PEOPLE_ROCOCO_ED); }); } diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs index 095df38eb53d..291a5d6c2bc3 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs @@ -121,16 +121,6 @@ fn relay_limited_teleport_assets(t: RelayToSystemParaTest) -> DispatchResult { ) } -fn relay_teleport_assets(t: RelayToSystemParaTest) -> DispatchResult { - ::XcmPallet::teleport_assets( - t.signed_origin, - bx!(t.args.dest.into()), - bx!(t.args.beneficiary.into()), - bx!(t.args.assets.into()), - t.args.fee_asset_item, - ) -} - fn system_para_limited_teleport_assets(t: SystemParaToRelayTest) -> DispatchResult { ::PolkadotXcm::limited_teleport_assets( t.signed_origin, @@ -142,15 +132,6 @@ fn system_para_limited_teleport_assets(t: SystemParaToRelayTest) -> DispatchResu ) } -fn system_para_teleport_assets(t: SystemParaToRelayTest) -> DispatchResult { - ::PolkadotXcm::teleport_assets( - t.signed_origin, - bx!(t.args.dest.into()), - bx!(t.args.beneficiary.into()), - bx!(t.args.assets.into()), - t.args.fee_asset_item, - ) -} /// Limited Teleport of native asset from Relay Chain to the System Parachain should work #[test] From dd8441fb2565d47f75ed530d63307423ed1f24f7 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Tue, 28 Nov 2023 12:56:49 +0000 Subject: [PATCH 048/102] ".git/.scripts/commands/fmt/fmt.sh" --- .../people/people-rococo/src/genesis.rs | 2 +- .../emulated/common/src/lib.rs | 5 +- .../tests/people/people-rococo/src/lib.rs | 3 -- .../people-rococo/src/tests/reap_identity.rs | 51 +++++++------------ .../people-rococo/src/tests/teleport.rs | 2 - cumulus/xcm/xcm-emulator/src/lib.rs | 1 - 6 files changed, 21 insertions(+), 43 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/genesis.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/genesis.rs index bc1dcbd08d1d..27d5531a0c7d 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/genesis.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/genesis.rs @@ -17,8 +17,8 @@ use sp_core::storage::Storage; // Cumulus -use emulated_integration_tests_common::{build_genesis_storage, collators, SAFE_XCM_VERSION}; use cumulus_primitives_core::ParaId; +use emulated_integration_tests_common::{build_genesis_storage, collators, SAFE_XCM_VERSION}; use parachains_common::Balance; pub const PARA_ID: u32 = 1004; diff --git a/cumulus/parachains/integration-tests/emulated/common/src/lib.rs b/cumulus/parachains/integration-tests/emulated/common/src/lib.rs index dcdd8bb60095..27be474ef0f3 100644 --- a/cumulus/parachains/integration-tests/emulated/common/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/common/src/lib.rs @@ -33,7 +33,9 @@ use sp_runtime::{ // Polakdot use parachains_common::{Balance, BlockNumber}; use polkadot_runtime_parachains::configuration::HostConfiguration; -use xcm::prelude::{MultiLocation, MultiAssets, WeightLimit, AccountId32 as AccountId32Junction, Here}; +use xcm::prelude::{ + AccountId32 as AccountId32Junction, Here, MultiAssets, MultiLocation, WeightLimit, +}; // Cumulus use parachains_common::{AccountId, AssetHubPolkadotAuraId, AuraId}; @@ -85,7 +87,6 @@ pub fn get_host_config() -> HostConfiguration { } } - /// Returns a `TestArgs` instance to be used for the Relay Chain across integration tests pub fn relay_test_args( dest: MultiLocation, diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/lib.rs index 02a584e1a574..57a654ef999a 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/lib.rs @@ -52,7 +52,6 @@ pub use rococo_system_emulated_network::{ RococoRelaySender as RococoSender, }; - pub const ASSET_ID: u32 = 1; pub const ASSET_MIN_BALANCE: u128 = 1000; pub type RelayToSystemParaTest = Test; @@ -61,7 +60,5 @@ pub type SystemParaToRelayTest = Test; pub type SystemParaToParaTest = Test; pub type ParaToSystemParaTest = Test; - - #[cfg(test)] mod tests; diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index 23701fca48a8..8cd89dbf8265 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -14,13 +14,16 @@ // limitations under the License. use crate::*; -use pallet_identity::{legacy::IdentityInfo, Data, Event as IdentityEvent}; use pallet_balances::Event as BalancesEvent; +use pallet_identity::{legacy::IdentityInfo, Data, Event as IdentityEvent}; use people_rococo_runtime::people::{ BasicDeposit as BasicDepositParachain, ByteDeposit as ByteDepositParachain, IdentityInfo as IdentityInfoParachain, SubAccountDeposit as SubAccountDepositParachain, }; -use rococo_runtime::{BasicDeposit, ByteDeposit, MaxAdditionalFields, SubAccountDeposit, RuntimeOrigin as RococoOrigin}; +use rococo_runtime::{ + BasicDeposit, ByteDeposit, MaxAdditionalFields, RuntimeOrigin as RococoOrigin, + SubAccountDeposit, +}; use rococo_system_emulated_network::{ rococo_emulated_chain::RococoRelayPallet, RococoRelay, RococoRelayReceiver, RococoRelaySender, }; @@ -109,9 +112,7 @@ fn on_reap_identity_works() { ] ); - let reserved_bal = RococoBalances::reserved_balance( - RococoRelaySender::get(), - ); + let reserved_bal = RococoBalances::reserved_balance(RococoRelaySender::get()); total_deposit = SubAccountDeposit::get() + id_deposit_relaychain(&identity_relaychain); // The reserved balance should equal the calculated total deposit @@ -120,11 +121,8 @@ fn on_reap_identity_works() { // Set identity and Subs on Parachain with Zero deposit PeopleRococo::execute_with(|| { - let free_bal = - PeopleRococoBalances::free_balance(PeopleRococoSender::get()); - let reserved_bal = PeopleRococoBalances::reserved_balance( - PeopleRococoSender::get(), - ); + let free_bal = PeopleRococoBalances::free_balance(PeopleRococoSender::get()); + let reserved_bal = PeopleRococoBalances::reserved_balance(PeopleRococoSender::get()); //total balance at Genesis should be zero assert_eq!(reserved_bal + free_bal, 0); @@ -144,14 +142,9 @@ fn on_reap_identity_works() { // No events get triggered when calling set_sub_no_deposit // No amount should be reserved as deposit amounts are set to 0. - let reserved_bal = PeopleRococoBalances::reserved_balance( - PeopleRococoSender::get(), - ); + let reserved_bal = PeopleRococoBalances::reserved_balance(PeopleRococoSender::get()); assert_eq!(reserved_bal, 0); - assert!(PeopleRococoIdentity::identity( - &PeopleRococoSender::get() - ) - .is_some()); + assert!(PeopleRococoIdentity::identity(&PeopleRococoSender::get()).is_some()); let (_, sub_accounts) = ::Identity::subs_of(&PeopleRococoSender::get()); assert!(sub_accounts.len() > 0); @@ -160,11 +153,8 @@ fn on_reap_identity_works() { // 5. reap_identity on Relay Chain RococoRelay::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; - let free_bal_before_reap = - RococoBalances::free_balance(RococoRelaySender::get()); - let reserved_balance = RococoBalances::reserved_balance( - RococoRelaySender::get(), - ); + let free_bal_before_reap = RococoBalances::free_balance(RococoRelaySender::get()); + let reserved_balance = RococoBalances::reserved_balance(RococoRelaySender::get()); //before reap reserved balance should be equal to total deposit assert_eq!(reserved_balance, total_deposit); assert_ok!(RococoIdentityMigrator::reap_identity( @@ -180,19 +170,14 @@ fn on_reap_identity_works() { }, ] ); - assert!(PeopleRococoIdentity::identity(&RococoRelaySender::get()) - .is_none()); - let tuple_subs = - RococoIdentity::subs_of(&RococoRelaySender::get()); + assert!(PeopleRococoIdentity::identity(&RococoRelaySender::get()).is_none()); + let tuple_subs = RococoIdentity::subs_of(&RococoRelaySender::get()); assert_eq!(tuple_subs.1.len(), 0); - let reserved_balance = RococoBalances::reserved_balance( - RococoRelaySender::get(), - ); + let reserved_balance = RococoBalances::reserved_balance(RococoRelaySender::get()); // after reap reserved balance should be 0 assert_eq!(reserved_balance, 0); - let free_bal_after_reap = - RococoBalances::free_balance(RococoRelaySender::get()); + let free_bal_after_reap = RococoBalances::free_balance(RococoRelaySender::get()); // free balance should be greater than before reap assert!(free_bal_after_reap > free_bal_before_reap); @@ -202,9 +187,7 @@ fn on_reap_identity_works() { // 6. assert on Parachain PeopleRococo::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; - let reserved_bal = PeopleRococoBalances::reserved_balance( - PeopleRococoSender::get(), - ); + let reserved_bal = PeopleRococoBalances::reserved_balance(PeopleRococoSender::get()); let id_deposit = id_deposit_parachain(&identity_parachain); let subs_deposit = SubAccountDepositParachain::get(); let total_deposit = subs_deposit + id_deposit; diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs index 291a5d6c2bc3..d4830b6a7afd 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs @@ -132,7 +132,6 @@ fn system_para_limited_teleport_assets(t: SystemParaToRelayTest) -> DispatchResu ) } - /// Limited Teleport of native asset from Relay Chain to the System Parachain should work #[test] fn limited_teleport_native_assets_from_relay_to_system_para_works() { @@ -183,7 +182,6 @@ fn limited_teleport_native_assets_back_from_system_para_to_relay_works() { let beneficiary_id = RococoReceiver::get(); let assets = (Parent, amount_to_send).into(); - // set sender to PeopleRococoReceiver because they just received // assets from limited_teleport call above. PeopleRococo has // no balances on Genesis. diff --git a/cumulus/xcm/xcm-emulator/src/lib.rs b/cumulus/xcm/xcm-emulator/src/lib.rs index 5580c51b6e75..f2e4ff397c45 100644 --- a/cumulus/xcm/xcm-emulator/src/lib.rs +++ b/cumulus/xcm/xcm-emulator/src/lib.rs @@ -1498,7 +1498,6 @@ where pub fn set_assertion(&mut self, assertion: fn(Self)) { let chain_name = std::any::type_name::(); self.hops_assertion.insert(chain_name.to_string(), assertion); - } /// Stores a dispatchable in a particular Chain pub fn set_dispatchable(&mut self, dispatchable: fn(Self) -> DispatchResult) { From b313e18ab8f4f5fb7822870dd13cd6ff24356879 Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Tue, 28 Nov 2023 13:00:39 +0000 Subject: [PATCH 049/102] typo --- .../emulated/chains/parachains/people/people-rococo/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/lib.rs index a07ae1438436..457945fd97d6 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/lib.rs @@ -48,4 +48,4 @@ decl_test_parachains! { // PeopleRococo implementation impl_accounts_helpers_for_parachain!(PeopleRococo); -impl_assert_events_helpers_for_parachain!(PeopleRococo, false); +impl_assert_events_helpers_for_parachain!(PeopleRococo); From 8e9b25143e9d820da408d402edc075aed1576671 Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Tue, 28 Nov 2023 13:28:06 +0000 Subject: [PATCH 050/102] clippy --- .../tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs | 1 + .../tests/assets/asset-hub-westend/src/tests/teleport.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs index 1a69a4f3f71d..ae91fda85f6e 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs @@ -15,6 +15,7 @@ use crate::*; use asset_hub_westend_runtime::xcm_config::XcmConfig as AssetHubWestendXcmConfig; +use emulated_integration_tests_common::{para_test_args, relay_test_args}; use penpal_runtime::xcm_config::XcmConfig as PenpalWestendXcmConfig; use westend_runtime::xcm_config::XcmConfig as WestendXcmConfig; diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs index 2c43bb9d8018..2d3c594ebc69 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs @@ -15,6 +15,7 @@ use crate::*; use asset_hub_westend_runtime::xcm_config::XcmConfig as AssetHubWestendXcmConfig; +use emulated_integration_tests_common::{para_test_args, relay_test_args}; use westend_runtime::xcm_config::XcmConfig as WestendXcmConfig; fn relay_origin_assertions(t: RelayToSystemParaTest) { From 5ae4cd8d65e977c012ab4c35bd6758b2a39a7611 Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Tue, 28 Nov 2023 14:23:58 +0000 Subject: [PATCH 051/102] atleast an ED --- .../tests/people/people-rococo/src/tests/reap_identity.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index 8cd89dbf8265..9d027b4b1a61 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -219,7 +219,7 @@ fn on_reap_identity_works() { // reserved balance should be equal to total deposit calculated on the Parachain assert_eq!(reserved_bal, total_deposit); - // A single Existential Deposit should be free - assert!(PeopleRococoBalances::free_balance(PeopleRococoSender::get()) == PEOPLE_ROCOCO_ED); + // Atleast Existential Deposit should be free + assert!(PeopleRococoBalances::free_balance(PeopleRococoSender::get()) >= PEOPLE_ROCOCO_ED); }); } From da2f38e624429d7ff7ad73f8b111dbd30ab88769 Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Tue, 28 Nov 2023 17:48:45 +0000 Subject: [PATCH 052/102] assert equality on exact --- .../people-rococo/src/tests/reap_identity.rs | 44 +++++++++++++++++-- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index 9d027b4b1a61..2696034feb5b 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -48,6 +48,15 @@ fn identity_relay() -> IdentityInfo { } } +fn removed_relay_id_fields(id: IdentityInfo) -> Balance { + let addtional_field= ByteDeposit::get() * TryInto::::try_into(id.additional + .encoded_size()) + .unwrap(); + let riot_field = ByteDeposit::get() * TryInto::::try_into(id.riot.encoded_size()) + .unwrap(); + addtional_field + riot_field +} + fn identity_parachain() -> IdentityInfoParachain { IdentityInfoParachain { display: Data::Raw(b"xcm-test".to_vec().try_into().unwrap()), @@ -63,6 +72,22 @@ fn identity_parachain() -> IdentityInfoParachain { } } +fn added_parachain_id_fields(id: &IdentityInfoParachain) -> Balance { + let matrix_field = ByteDepositParachain::get() * TryInto::::try_into( + id.matrix.encoded_size(), + ) + .unwrap(); + let github_field = ByteDepositParachain::get() * TryInto::::try_into( + id.github.encoded_size(), + ) + .unwrap(); + let discord_field = ByteDepositParachain::get() * TryInto::::try_into( + id.discord.encoded_size(), + ) + .unwrap(); + matrix_field + github_field + discord_field +} + fn id_deposit_parachain(id: &IdentityInfoParachain) -> Balance { let base_deposit = BasicDepositParachain::get(); let byte_deposit = @@ -171,14 +196,17 @@ fn on_reap_identity_works() { ] ); assert!(PeopleRococoIdentity::identity(&RococoRelaySender::get()).is_none()); - let tuple_subs = RococoIdentity::subs_of(&RococoRelaySender::get()); - assert_eq!(tuple_subs.1.len(), 0); + let (_, sub_accounts)= RococoIdentity::subs_of(&RococoRelaySender::get()); + assert_eq!(sub_accounts.len(), 0); let reserved_balance = RococoBalances::reserved_balance(RococoRelaySender::get()); // after reap reserved balance should be 0 assert_eq!(reserved_balance, 0); let free_bal_after_reap = RococoBalances::free_balance(RococoRelaySender::get()); + let removed_fields_dep = removed_relay_id_fields(identity_relaychain.clone()); + println!("removed_fields_dep: {:?}", removed_fields_dep); + // free balance should be greater than before reap assert!(free_bal_after_reap > free_bal_before_reap); assert_eq!(free_bal_after_reap, free_bal_before_reap + total_deposit); @@ -192,6 +220,10 @@ fn on_reap_identity_works() { let subs_deposit = SubAccountDepositParachain::get(); let total_deposit = subs_deposit + id_deposit; + let removed_fields_cost = removed_relay_id_fields(identity_relaychain.clone()); + let added_fields_cost = added_parachain_id_fields(&identity_parachain); + println!("added_fields_deposit: {:?}", added_fields_cost); + assert_expected_events!( PeopleRococo, vec![ @@ -219,7 +251,11 @@ fn on_reap_identity_works() { // reserved balance should be equal to total deposit calculated on the Parachain assert_eq!(reserved_bal, total_deposit); - // Atleast Existential Deposit should be free - assert!(PeopleRococoBalances::free_balance(PeopleRococoSender::get()) >= PEOPLE_ROCOCO_ED); + + // set to * 2 in caclulate_remote_deposit runtime/rococo/src/impls.rs#L55 + let para_existential_deposit = PEOPLE_ROCOCO_ED * 2; + let expected = para_existential_deposit - removed_fields_cost / 100 / 2; + + assert_eq!(expected, PeopleRococoBalances::free_balance(PeopleRococoSender::get())); }); } From 4fc3e01bfeb03014b9bd57404f58e86bf7c12c6f Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Tue, 28 Nov 2023 17:58:18 +0000 Subject: [PATCH 053/102] ".git/.scripts/commands/fmt/fmt.sh" --- .../people-rococo/src/tests/reap_identity.rs | 29 +++++++------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index 2696034feb5b..d8a180d62532 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -49,11 +49,10 @@ fn identity_relay() -> IdentityInfo { } fn removed_relay_id_fields(id: IdentityInfo) -> Balance { - let addtional_field= ByteDeposit::get() * TryInto::::try_into(id.additional - .encoded_size()) - .unwrap(); - let riot_field = ByteDeposit::get() * TryInto::::try_into(id.riot.encoded_size()) - .unwrap(); + let addtional_field = + ByteDeposit::get() * TryInto::::try_into(id.additional.encoded_size()).unwrap(); + let riot_field = + ByteDeposit::get() * TryInto::::try_into(id.riot.encoded_size()).unwrap(); addtional_field + riot_field } @@ -73,18 +72,12 @@ fn identity_parachain() -> IdentityInfoParachain { } fn added_parachain_id_fields(id: &IdentityInfoParachain) -> Balance { - let matrix_field = ByteDepositParachain::get() * TryInto::::try_into( - id.matrix.encoded_size(), - ) - .unwrap(); - let github_field = ByteDepositParachain::get() * TryInto::::try_into( - id.github.encoded_size(), - ) - .unwrap(); - let discord_field = ByteDepositParachain::get() * TryInto::::try_into( - id.discord.encoded_size(), - ) - .unwrap(); + let matrix_field = + ByteDepositParachain::get() * TryInto::::try_into(id.matrix.encoded_size()).unwrap(); + let github_field = + ByteDepositParachain::get() * TryInto::::try_into(id.github.encoded_size()).unwrap(); + let discord_field = + ByteDepositParachain::get() * TryInto::::try_into(id.discord.encoded_size()).unwrap(); matrix_field + github_field + discord_field } @@ -196,7 +189,7 @@ fn on_reap_identity_works() { ] ); assert!(PeopleRococoIdentity::identity(&RococoRelaySender::get()).is_none()); - let (_, sub_accounts)= RococoIdentity::subs_of(&RococoRelaySender::get()); + let (_, sub_accounts) = RococoIdentity::subs_of(&RococoRelaySender::get()); assert_eq!(sub_accounts.len(), 0); let reserved_balance = RococoBalances::reserved_balance(RococoRelaySender::get()); From f575356cc0c7d491a177e4eeda147d036d3d4141 Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Wed, 29 Nov 2023 11:12:26 +0000 Subject: [PATCH 054/102] create identities --- .../people-rococo/src/tests/reap_identity.rs | 100 ++++++++++++------ 1 file changed, 65 insertions(+), 35 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index d8a180d62532..5c2f603fd2d3 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -14,6 +14,7 @@ // limitations under the License. use crate::*; +use frame_support::BoundedVec; use pallet_balances::Event as BalancesEvent; use pallet_identity::{legacy::IdentityInfo, Data, Event as IdentityEvent}; use people_rococo_runtime::people::{ @@ -34,9 +35,24 @@ type RococoIdentityMigrator = ::IdentityMigrat type PeopleRococoIdentity = ::Identity; type PeopleRococoBalances = ::Balances; -fn identity_relay() -> IdentityInfo { - IdentityInfo { - display: Data::Raw(b"xcm-test".to_vec().try_into().unwrap()), +struct Identity { + relay: IdentityInfo, + parachain: IdentityInfoParachain, +} + +fn identities() -> Vec { + let pgp_fingerprint = [ + 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, + 0x88, 0x99, 0xAA, 0xBB, 0xCC, + ]; + let riot = Data::Raw(b"riot-xcm-test".to_vec().try_into().unwrap()); + let additional = BoundedVec::try_from(vec![( + Data::Raw(b"additional".to_vec().try_into().unwrap()), + Data::Raw(b"data".to_vec().try_into().unwrap()), + )]) + .unwrap(); + let mut first_relay = IdentityInfo { + display: Data::Raw(b"xcm-test-one".to_vec().try_into().unwrap()), legal: Data::Raw(b"The Right Ordinal Xcm Test, Esq.".to_vec().try_into().unwrap()), web: Data::Raw(b"https://xcm-test.io".to_vec().try_into().unwrap()), email: Data::Raw(b"xcm-test@gmail.com".to_vec().try_into().unwrap()), @@ -45,19 +61,17 @@ fn identity_relay() -> IdentityInfo { twitter: Data::Raw(b"@xcm-test".to_vec().try_into().unwrap()), riot: Default::default(), additional: Default::default(), - } -} - -fn removed_relay_id_fields(id: IdentityInfo) -> Balance { - let addtional_field = - ByteDeposit::get() * TryInto::::try_into(id.additional.encoded_size()).unwrap(); - let riot_field = - ByteDeposit::get() * TryInto::::try_into(id.riot.encoded_size()).unwrap(); - addtional_field + riot_field -} - -fn identity_parachain() -> IdentityInfoParachain { - IdentityInfoParachain { + }; + let mut second_relay = first_relay.clone(); + let mut third_relay = first_relay.clone(); + let mut fourth_relay = first_relay.clone(); + second_relay.pgp_fingerprint = Some(pgp_fingerprint); + third_relay.pgp_fingerprint = Some(pgp_fingerprint); + third_relay.riot = riot.clone(); + fourth_relay.pgp_fingerprint = Some(pgp_fingerprint); + fourth_relay.riot = riot.clone(); + fourth_relay.additional = additional; + let mut first_parachain = IdentityInfoParachain { display: Data::Raw(b"xcm-test".to_vec().try_into().unwrap()), legal: Data::Raw(b"The Right Ordinal Xcm Test, Esq.".to_vec().try_into().unwrap()), web: Data::Raw(b"https://xcm-test.io".to_vec().try_into().unwrap()), @@ -68,7 +82,31 @@ fn identity_parachain() -> IdentityInfoParachain { twitter: Data::Raw(b"@xcm-test".to_vec().try_into().unwrap()), github: Data::None, discord: Data::None, - } + }; + let mut second_parachain = first_parachain.clone(); + let mut third_parachain = first_parachain.clone(); + let mut fourth_parachain = first_parachain.clone(); + second_parachain.pgp_fingerprint = Some(pgp_fingerprint); + third_parachain.pgp_fingerprint = Some(pgp_fingerprint); + third_parachain.matrix = riot.to_owned(); // riot field on relay is set to matrix in parachain + fourth_parachain.pgp_fingerprint = Some(pgp_fingerprint); + fourth_parachain.matrix = riot.to_owned(); + fourth_parachain.github = riot.to_owned(); + + vec![ + Identity { relay: first_relay, parachain: first_parachain }, + Identity { relay: second_relay, parachain: second_parachain }, + Identity { relay: third_relay, parachain: third_parachain }, + Identity { relay: fourth_relay, parachain: fourth_parachain }, + ] +} + +fn removed_relay_id_fields(id: IdentityInfo) -> Balance { + let addtional_field = + ByteDeposit::get() * TryInto::::try_into(id.additional.encoded_size()).unwrap(); + let riot_field = + ByteDeposit::get() * TryInto::::try_into(id.riot.encoded_size()).unwrap(); + addtional_field + riot_field } fn added_parachain_id_fields(id: &IdentityInfoParachain) -> Balance { @@ -96,8 +134,7 @@ fn id_deposit_relaychain(id: &IdentityInfo) -> Balance { #[test] fn on_reap_identity_works() { - let identity_relaychain = identity_relay(); - let identity_parachain = identity_parachain(); + let identities = identities(); let mut total_deposit = 0_u128; // Set identity and Subs on Relay Chain @@ -105,9 +142,10 @@ fn on_reap_identity_works() { type RuntimeEvent = ::RuntimeEvent; // 1. Set identity on Relay Chain + // For this test case we only use a single instance of IdentityInfo assert_ok!(RococoIdentity::set_identity( RococoOrigin::signed(RococoRelaySender::get()), - Box::new(identity_relaychain.clone()) + Box::new(identities[0].relay.clone()) )); assert_expected_events!( RococoRelay, @@ -131,7 +169,7 @@ fn on_reap_identity_works() { ); let reserved_bal = RococoBalances::reserved_balance(RococoRelaySender::get()); - total_deposit = SubAccountDeposit::get() + id_deposit_relaychain(&identity_relaychain); + total_deposit = SubAccountDeposit::get() + id_deposit_relaychain(&identities[0].relay); // The reserved balance should equal the calculated total deposit assert_eq!(reserved_bal, total_deposit); @@ -148,7 +186,7 @@ fn on_reap_identity_works() { // 3. Set identity on Parachain assert_ok!(PeopleRococoIdentity::set_identity_no_deposit( &PeopleRococoSender::get(), - identity_parachain.clone() + identities[0].parachain.clone(), )); // 4. Set sub-identity on Parachain @@ -197,9 +235,6 @@ fn on_reap_identity_works() { assert_eq!(reserved_balance, 0); let free_bal_after_reap = RococoBalances::free_balance(RococoRelaySender::get()); - let removed_fields_dep = removed_relay_id_fields(identity_relaychain.clone()); - println!("removed_fields_dep: {:?}", removed_fields_dep); - // free balance should be greater than before reap assert!(free_bal_after_reap > free_bal_before_reap); assert_eq!(free_bal_after_reap, free_bal_before_reap + total_deposit); @@ -209,14 +244,10 @@ fn on_reap_identity_works() { PeopleRococo::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; let reserved_bal = PeopleRococoBalances::reserved_balance(PeopleRococoSender::get()); - let id_deposit = id_deposit_parachain(&identity_parachain); + let id_deposit = id_deposit_parachain(&identities[0].parachain); let subs_deposit = SubAccountDepositParachain::get(); let total_deposit = subs_deposit + id_deposit; - let removed_fields_cost = removed_relay_id_fields(identity_relaychain.clone()); - let added_fields_cost = added_parachain_id_fields(&identity_parachain); - println!("added_fields_deposit: {:?}", added_fields_cost); - assert_expected_events!( PeopleRococo, vec![ @@ -245,10 +276,9 @@ fn on_reap_identity_works() { // reserved balance should be equal to total deposit calculated on the Parachain assert_eq!(reserved_bal, total_deposit); - // set to * 2 in caclulate_remote_deposit runtime/rococo/src/impls.rs#L55 - let para_existential_deposit = PEOPLE_ROCOCO_ED * 2; - let expected = para_existential_deposit - removed_fields_cost / 100 / 2; - - assert_eq!(expected, PeopleRococoBalances::free_balance(PeopleRococoSender::get())); + // Should have at least one ED after in free balance after the reap. + assert!(PeopleRococoBalances::free_balance(PeopleRococoSender::get()) >= PEOPLE_ROCOCO_ED); }); } + +fn on_reap_identity_works_for_many_identities() {} From 39021073bf3e11524d43f08a4fdb879c59381de2 Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Wed, 29 Nov 2023 11:38:42 +0000 Subject: [PATCH 055/102] generalise asserts --- .../people-rococo/src/tests/reap_identity.rs | 64 ++++++++++--------- 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index 5c2f603fd2d3..312ac7af7ede 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -35,6 +35,7 @@ type RococoIdentityMigrator = ::IdentityMigrat type PeopleRococoIdentity = ::Identity; type PeopleRococoBalances = ::Balances; +#[derive(Clone, Debug)] struct Identity { relay: IdentityInfo, parachain: IdentityInfoParachain, @@ -51,7 +52,7 @@ fn identities() -> Vec { Data::Raw(b"data".to_vec().try_into().unwrap()), )]) .unwrap(); - let mut first_relay = IdentityInfo { + let first_relay = IdentityInfo { display: Data::Raw(b"xcm-test-one".to_vec().try_into().unwrap()), legal: Data::Raw(b"The Right Ordinal Xcm Test, Esq.".to_vec().try_into().unwrap()), web: Data::Raw(b"https://xcm-test.io".to_vec().try_into().unwrap()), @@ -71,7 +72,7 @@ fn identities() -> Vec { fourth_relay.pgp_fingerprint = Some(pgp_fingerprint); fourth_relay.riot = riot.clone(); fourth_relay.additional = additional; - let mut first_parachain = IdentityInfoParachain { + let first_parachain = IdentityInfoParachain { display: Data::Raw(b"xcm-test".to_vec().try_into().unwrap()), legal: Data::Raw(b"The Right Ordinal Xcm Test, Esq.".to_vec().try_into().unwrap()), web: Data::Raw(b"https://xcm-test.io".to_vec().try_into().unwrap()), @@ -101,24 +102,6 @@ fn identities() -> Vec { ] } -fn removed_relay_id_fields(id: IdentityInfo) -> Balance { - let addtional_field = - ByteDeposit::get() * TryInto::::try_into(id.additional.encoded_size()).unwrap(); - let riot_field = - ByteDeposit::get() * TryInto::::try_into(id.riot.encoded_size()).unwrap(); - addtional_field + riot_field -} - -fn added_parachain_id_fields(id: &IdentityInfoParachain) -> Balance { - let matrix_field = - ByteDepositParachain::get() * TryInto::::try_into(id.matrix.encoded_size()).unwrap(); - let github_field = - ByteDepositParachain::get() * TryInto::::try_into(id.github.encoded_size()).unwrap(); - let discord_field = - ByteDepositParachain::get() * TryInto::::try_into(id.discord.encoded_size()).unwrap(); - matrix_field + github_field + discord_field -} - fn id_deposit_parachain(id: &IdentityInfoParachain) -> Balance { let base_deposit = BasicDepositParachain::get(); let byte_deposit = @@ -132,9 +115,7 @@ fn id_deposit_relaychain(id: &IdentityInfo) -> Balance { base_deposit + byte_deposit } -#[test] -fn on_reap_identity_works() { - let identities = identities(); +fn set_id_relay(id: Identity) -> u128 { let mut total_deposit = 0_u128; // Set identity and Subs on Relay Chain @@ -145,7 +126,7 @@ fn on_reap_identity_works() { // For this test case we only use a single instance of IdentityInfo assert_ok!(RococoIdentity::set_identity( RococoOrigin::signed(RococoRelaySender::get()), - Box::new(identities[0].relay.clone()) + Box::new(id.relay.clone()) )); assert_expected_events!( RococoRelay, @@ -169,12 +150,15 @@ fn on_reap_identity_works() { ); let reserved_bal = RococoBalances::reserved_balance(RococoRelaySender::get()); - total_deposit = SubAccountDeposit::get() + id_deposit_relaychain(&identities[0].relay); + total_deposit = SubAccountDeposit::get() + id_deposit_relaychain(&id.relay); // The reserved balance should equal the calculated total deposit assert_eq!(reserved_bal, total_deposit); }); + total_deposit +} +fn assert_set_id_parachain(id: Identity) { // Set identity and Subs on Parachain with Zero deposit PeopleRococo::execute_with(|| { let free_bal = PeopleRococoBalances::free_balance(PeopleRococoSender::get()); @@ -186,7 +170,7 @@ fn on_reap_identity_works() { // 3. Set identity on Parachain assert_ok!(PeopleRococoIdentity::set_identity_no_deposit( &PeopleRococoSender::get(), - identities[0].parachain.clone(), + id.parachain.clone(), )); // 4. Set sub-identity on Parachain @@ -194,7 +178,6 @@ fn on_reap_identity_works() { &PeopleRococoSender::get(), PeopleRococoReceiver::get(), )); - // No events get triggered when calling set_sub_no_deposit // No amount should be reserved as deposit amounts are set to 0. @@ -205,7 +188,9 @@ fn on_reap_identity_works() { ::Identity::subs_of(&PeopleRococoSender::get()); assert!(sub_accounts.len() > 0); }); +} +fn assert_reap_id_relay(total_deposit: u128) { // 5. reap_identity on Relay Chain RococoRelay::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; @@ -239,12 +224,14 @@ fn on_reap_identity_works() { assert!(free_bal_after_reap > free_bal_before_reap); assert_eq!(free_bal_after_reap, free_bal_before_reap + total_deposit); }); +} +fn assert_reap_parachain(id: Identity) { // 6. assert on Parachain PeopleRococo::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; let reserved_bal = PeopleRococoBalances::reserved_balance(PeopleRococoSender::get()); - let id_deposit = id_deposit_parachain(&identities[0].parachain); + let id_deposit = id_deposit_parachain(&id.parachain); let subs_deposit = SubAccountDepositParachain::get(); let total_deposit = subs_deposit + id_deposit; @@ -281,4 +268,23 @@ fn on_reap_identity_works() { }); } -fn on_reap_identity_works_for_many_identities() {} +#[test] +fn on_reap_identity_works() { + let ids = identities(); + let total_deposit = set_id_relay(ids[0].clone()); + assert_set_id_parachain(ids[0].clone()); + assert_reap_id_relay(total_deposit); + assert_reap_parachain(ids[0].clone()); +} + +#[test] +fn on_reap_identity_works_for_many_identities() { + let ids = identities(); + for id in ids { + println!("Testing identity: {:?}", id.clone()); + let total_deposit = set_id_relay(id.clone()); + assert_set_id_parachain(id.clone()); + assert_reap_id_relay(total_deposit); + assert_reap_parachain(id.clone()); + } +} From bc6a03ed2c619f426b27bfdab7b1a27edaf5c1fd Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Wed, 29 Nov 2023 11:52:18 +0000 Subject: [PATCH 056/102] check many instances --- .../people-rococo/src/tests/reap_identity.rs | 33 ++++++++++++++----- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index 312ac7af7ede..afd5baefd4ef 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -269,7 +269,7 @@ fn assert_reap_parachain(id: Identity) { } #[test] -fn on_reap_identity_works() { +fn on_reap_identity_works_for_first_instance() { let ids = identities(); let total_deposit = set_id_relay(ids[0].clone()); assert_set_id_parachain(ids[0].clone()); @@ -278,13 +278,28 @@ fn on_reap_identity_works() { } #[test] -fn on_reap_identity_works_for_many_identities() { +fn on_reap_identity_works_for_second_instance() { let ids = identities(); - for id in ids { - println!("Testing identity: {:?}", id.clone()); - let total_deposit = set_id_relay(id.clone()); - assert_set_id_parachain(id.clone()); - assert_reap_id_relay(total_deposit); - assert_reap_parachain(id.clone()); - } + let total_deposit = set_id_relay(ids[1].clone()); + assert_set_id_parachain(ids[1].clone()); + assert_reap_id_relay(total_deposit); + assert_reap_parachain(ids[1].clone()); +} + +#[test] +fn on_reap_identity_works_for_third_instance() { + let ids = identities(); + let total_deposit = set_id_relay(ids[2].clone()); + assert_set_id_parachain(ids[2].clone()); + assert_reap_id_relay(total_deposit); + assert_reap_parachain(ids[2].clone()); +} + +#[test] +fn on_reap_identity_works_for_fourth_instance() { + let ids = identities(); + let total_deposit = set_id_relay(ids[3].clone()); + assert_set_id_parachain(ids[3].clone()); + assert_reap_id_relay(total_deposit); + assert_reap_parachain(ids[3].clone()); } From 58f8e7762c2584a69a1e478bd3e5e24ffefd2135 Mon Sep 17 00:00:00 2001 From: Richard Melkonian <35300528+0xmovses@users.noreply.github.com> Date: Wed, 29 Nov 2023 15:34:52 +0000 Subject: [PATCH 057/102] Update cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> --- .../tests/people/people-rococo/src/tests/reap_identity.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index afd5baefd4ef..225da5f613e7 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -186,7 +186,7 @@ fn assert_set_id_parachain(id: Identity) { assert!(PeopleRococoIdentity::identity(&PeopleRococoSender::get()).is_some()); let (_, sub_accounts) = ::Identity::subs_of(&PeopleRococoSender::get()); - assert!(sub_accounts.len() > 0); + assert_eq!(sub_accounts.len(), 1); }); } From 8abca7c14f95e5aba62fd066277c807becb0175b Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Wed, 29 Nov 2023 15:35:18 +0000 Subject: [PATCH 058/102] add comment --- .../tests/people/people-rococo/src/tests/reap_identity.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index 225da5f613e7..083ad1cda29a 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -268,6 +268,8 @@ fn assert_reap_parachain(id: Identity) { }); } +// We don't loop through ids and assert because genesis state is +// required for each test #[test] fn on_reap_identity_works_for_first_instance() { let ids = identities(); From 0e2ddc19c2c68ae7d1edde04f9e13f7b405e6e12 Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Wed, 29 Nov 2023 16:02:13 +0000 Subject: [PATCH 059/102] add petrowski cases --- .../people-rococo/src/tests/reap_identity.rs | 90 ++++++++++++------- 1 file changed, 57 insertions(+), 33 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index 083ad1cda29a..61a9533f214f 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -46,13 +46,32 @@ fn identities() -> Vec { 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, ]; - let riot = Data::Raw(b"riot-xcm-test".to_vec().try_into().unwrap()); - let additional = BoundedVec::try_from(vec![( - Data::Raw(b"additional".to_vec().try_into().unwrap()), - Data::Raw(b"data".to_vec().try_into().unwrap()), - )]) - .unwrap(); + // Minimal Identity let first_relay = IdentityInfo { + display: Data::None, + legal: Data::None, + web: Data::None, + email: Data::None, + pgp_fingerprint: None, + image: Data::None, + twitter: Data::None, + riot: Data::None, + additional: Default::default(), + }; + let first_para = IdentityInfoParachain { + display: Data::None, + legal: Data::None, + web: Data::None, + matrix: Data::None, + email: Data::None, + pgp_fingerprint: None, + image: Data::None, + twitter: Data::None, + github: Data::None, + discord: Data::None, + }; + // Full Identity with no additional + let second_relay = IdentityInfo { display: Data::Raw(b"xcm-test-one".to_vec().try_into().unwrap()), legal: Data::Raw(b"The Right Ordinal Xcm Test, Esq.".to_vec().try_into().unwrap()), web: Data::Raw(b"https://xcm-test.io".to_vec().try_into().unwrap()), @@ -60,45 +79,50 @@ fn identities() -> Vec { pgp_fingerprint: None, image: Data::Raw(b"xcm-test.png".to_vec().try_into().unwrap()), twitter: Data::Raw(b"@xcm-test".to_vec().try_into().unwrap()), - riot: Default::default(), + riot: Data::Raw(b"riot-xcm-test".to_vec().try_into().unwrap()), additional: Default::default(), }; - let mut second_relay = first_relay.clone(); - let mut third_relay = first_relay.clone(); - let mut fourth_relay = first_relay.clone(); - second_relay.pgp_fingerprint = Some(pgp_fingerprint); - third_relay.pgp_fingerprint = Some(pgp_fingerprint); - third_relay.riot = riot.clone(); - fourth_relay.pgp_fingerprint = Some(pgp_fingerprint); - fourth_relay.riot = riot.clone(); - fourth_relay.additional = additional; - let first_parachain = IdentityInfoParachain { - display: Data::Raw(b"xcm-test".to_vec().try_into().unwrap()), + let second_para = IdentityInfoParachain { + display: Data::Raw(b"xcm-test-one".to_vec().try_into().unwrap()), legal: Data::Raw(b"The Right Ordinal Xcm Test, Esq.".to_vec().try_into().unwrap()), web: Data::Raw(b"https://xcm-test.io".to_vec().try_into().unwrap()), - matrix: Data::None, + matrix: Data::Raw(b"riot-xcm-test".to_vec().try_into().unwrap()), email: Data::Raw(b"xcm-test@gmail.com".to_vec().try_into().unwrap()), - pgp_fingerprint: None, + pgp_fingerprint: Some(pgp_fingerprint), image: Data::Raw(b"xcm-test.png".to_vec().try_into().unwrap()), twitter: Data::Raw(b"@xcm-test".to_vec().try_into().unwrap()), github: Data::None, discord: Data::None, }; - let mut second_parachain = first_parachain.clone(); - let mut third_parachain = first_parachain.clone(); - let mut fourth_parachain = first_parachain.clone(); - second_parachain.pgp_fingerprint = Some(pgp_fingerprint); - third_parachain.pgp_fingerprint = Some(pgp_fingerprint); - third_parachain.matrix = riot.to_owned(); // riot field on relay is set to matrix in parachain - fourth_parachain.pgp_fingerprint = Some(pgp_fingerprint); - fourth_parachain.matrix = riot.to_owned(); - fourth_parachain.github = riot.to_owned(); + // Full Identity with nonsensical additional + let mut third_relay = second_relay.clone(); + third_relay.additional = BoundedVec::try_from(vec![( + Data::Raw(b"Foo".to_vec().try_into().unwrap()), + Data::Raw(b"Bar".to_vec().try_into().unwrap()), + )]) + .unwrap(); + // Full Identity with meaninful additional + let mut fourth_relay = second_relay.clone(); + fourth_relay.additional = BoundedVec::try_from(vec![ + ( + Data::Raw(b"github".to_vec().try_into().unwrap()), + Data::Raw(b"niels-usernmae".to_vec().try_into().unwrap()), + ), + ( + Data::Raw(b"discord".to_vec().try_into().unwrap()), + Data::Raw(b"bohr-username".to_vec().try_into().unwrap()), + ), + ]) + .unwrap(); + let mut fourth_para = second_para.clone(); + fourth_para.github = Data::Raw(b"niels-usernmae".to_vec().try_into().unwrap()); + fourth_para.discord = Data::Raw(b"bohr-username".to_vec().try_into().unwrap()); vec![ - Identity { relay: first_relay, parachain: first_parachain }, - Identity { relay: second_relay, parachain: second_parachain }, - Identity { relay: third_relay, parachain: third_parachain }, - Identity { relay: fourth_relay, parachain: fourth_parachain }, + Identity { relay: first_relay, parachain: first_para }, + Identity { relay: second_relay, parachain: second_para.clone() }, + Identity { relay: third_relay, parachain: second_para.clone() }, // same as second_para + Identity { relay: fourth_relay, parachain: fourth_para }, ] } From 512e3a13bf1ed0697adebb891ad57e8cd063348a Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Wed, 29 Nov 2023 17:39:46 +0000 Subject: [PATCH 060/102] updates cleanup --- Cargo.lock | 1 + .../tests/people/people-rococo/Cargo.toml | 1 + .../people-rococo/src/tests/reap_identity.rs | 40 ++++++++----------- 3 files changed, 18 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 843c349db13f..43560e6a807e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11848,6 +11848,7 @@ dependencies = [ "polkadot-primitives", "polkadot-runtime-common", "rococo-runtime", + "rococo-runtime-constants", "rococo-system-emulated-network", "sp-runtime", "staging-xcm", diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/Cargo.toml b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/Cargo.toml index ad97f5184e11..519e205e6e90 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/Cargo.toml @@ -25,6 +25,7 @@ xcm = { package = "staging-xcm", path = "../../../../../../../polkadot/xcm", def pallet-xcm = { path = "../../../../../../../polkadot/xcm/pallet-xcm", default-features = false} xcm-executor = { package = "staging-xcm-executor", path = "../../../../../../../polkadot/xcm/xcm-executor", default-features = false } rococo-runtime = { path = "../../../../../../../polkadot/runtime/rococo" } +rococo-runtime-constants = { path = "../../../../../../../polkadot/runtime/rococo/constants" } polkadot-primitives = { path = "../../../../../../../polkadot/primitives" } polkadot-runtime-common = { path = "../../../../../../../polkadot/runtime/common"} diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index 61a9533f214f..47e5f9ee9db9 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -38,7 +38,7 @@ type PeopleRococoBalances = ::Balances; #[derive(Clone, Debug)] struct Identity { relay: IdentityInfo, - parachain: IdentityInfoParachain, + para: IdentityInfoParachain, } fn identities() -> Vec { @@ -76,7 +76,7 @@ fn identities() -> Vec { legal: Data::Raw(b"The Right Ordinal Xcm Test, Esq.".to_vec().try_into().unwrap()), web: Data::Raw(b"https://xcm-test.io".to_vec().try_into().unwrap()), email: Data::Raw(b"xcm-test@gmail.com".to_vec().try_into().unwrap()), - pgp_fingerprint: None, + pgp_fingerprint: Some(pgp_fingerprint), image: Data::Raw(b"xcm-test.png".to_vec().try_into().unwrap()), twitter: Data::Raw(b"@xcm-test".to_vec().try_into().unwrap()), riot: Data::Raw(b"riot-xcm-test".to_vec().try_into().unwrap()), @@ -97,16 +97,16 @@ fn identities() -> Vec { // Full Identity with nonsensical additional let mut third_relay = second_relay.clone(); third_relay.additional = BoundedVec::try_from(vec![( - Data::Raw(b"Foo".to_vec().try_into().unwrap()), - Data::Raw(b"Bar".to_vec().try_into().unwrap()), + Data::Raw(b"foO".to_vec().try_into().unwrap()), + Data::Raw(b"bAr".to_vec().try_into().unwrap()), )]) .unwrap(); - // Full Identity with meaninful additional + // Full Identity with meaningful additional let mut fourth_relay = second_relay.clone(); fourth_relay.additional = BoundedVec::try_from(vec![ ( Data::Raw(b"github".to_vec().try_into().unwrap()), - Data::Raw(b"niels-usernmae".to_vec().try_into().unwrap()), + Data::Raw(b"niels-username".to_vec().try_into().unwrap()), ), ( Data::Raw(b"discord".to_vec().try_into().unwrap()), @@ -119,10 +119,10 @@ fn identities() -> Vec { fourth_para.discord = Data::Raw(b"bohr-username".to_vec().try_into().unwrap()); vec![ - Identity { relay: first_relay, parachain: first_para }, - Identity { relay: second_relay, parachain: second_para.clone() }, - Identity { relay: third_relay, parachain: second_para.clone() }, // same as second_para - Identity { relay: fourth_relay, parachain: fourth_para }, + Identity { relay: first_relay, para: first_para }, + Identity { relay: second_relay, para: second_para.clone() }, + Identity { relay: third_relay, para: second_para.clone() }, // same as second_para + Identity { relay: fourth_relay, para: fourth_para }, ] } @@ -152,13 +152,6 @@ fn set_id_relay(id: Identity) -> u128 { RococoOrigin::signed(RococoRelaySender::get()), Box::new(id.relay.clone()) )); - assert_expected_events!( - RococoRelay, - vec![ - RuntimeEvent::Identity(IdentityEvent::IdentitySet { .. }) => {}, - RuntimeEvent::Balances(BalancesEvent::Reserved { .. }) => {}, - ] - ); // 2. Set sub-identity on Relay Chain assert_ok!(RococoIdentity::set_subs( @@ -194,7 +187,7 @@ fn assert_set_id_parachain(id: Identity) { // 3. Set identity on Parachain assert_ok!(PeopleRococoIdentity::set_identity_no_deposit( &PeopleRococoSender::get(), - id.parachain.clone(), + id.para.clone(), )); // 4. Set sub-identity on Parachain @@ -249,13 +242,12 @@ fn assert_reap_id_relay(total_deposit: u128) { assert_eq!(free_bal_after_reap, free_bal_before_reap + total_deposit); }); } - fn assert_reap_parachain(id: Identity) { // 6. assert on Parachain PeopleRococo::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; let reserved_bal = PeopleRococoBalances::reserved_balance(PeopleRococoSender::get()); - let id_deposit = id_deposit_parachain(&id.parachain); + let id_deposit = id_deposit_parachain(&id.para); let subs_deposit = SubAccountDepositParachain::get(); let total_deposit = subs_deposit + id_deposit; @@ -295,7 +287,7 @@ fn assert_reap_parachain(id: Identity) { // We don't loop through ids and assert because genesis state is // required for each test #[test] -fn on_reap_identity_works_for_first_instance() { +fn on_reap_identity_works_for_minimal_identity() { let ids = identities(); let total_deposit = set_id_relay(ids[0].clone()); assert_set_id_parachain(ids[0].clone()); @@ -304,7 +296,7 @@ fn on_reap_identity_works_for_first_instance() { } #[test] -fn on_reap_identity_works_for_second_instance() { +fn on_reap_identity_works_for_full_identity_no_additional() { let ids = identities(); let total_deposit = set_id_relay(ids[1].clone()); assert_set_id_parachain(ids[1].clone()); @@ -313,7 +305,7 @@ fn on_reap_identity_works_for_second_instance() { } #[test] -fn on_reap_identity_works_for_third_instance() { +fn on_reap_identity_works_for_full_identity_nonsense_additional() { let ids = identities(); let total_deposit = set_id_relay(ids[2].clone()); assert_set_id_parachain(ids[2].clone()); @@ -322,7 +314,7 @@ fn on_reap_identity_works_for_third_instance() { } #[test] -fn on_reap_identity_works_for_fourth_instance() { +fn on_reap_identity_works_for_full_identity_meaningful_additional() { let ids = identities(); let total_deposit = set_id_relay(ids[3].clone()); assert_set_id_parachain(ids[3].clone()); From 3985fab9a1cfdc88f36b8cfe865500caa7747f8e Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Thu, 30 Nov 2023 10:32:24 +0000 Subject: [PATCH 061/102] reduce code duplication --- .../people-rococo/src/tests/reap_identity.rs | 34 ++++++++----------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index 47e5f9ee9db9..f026601aa77d 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -139,7 +139,7 @@ fn id_deposit_relaychain(id: &IdentityInfo) -> Balance { base_deposit + byte_deposit } -fn set_id_relay(id: Identity) -> u128 { +fn set_id_relay(id: &Identity) -> u128 { let mut total_deposit = 0_u128; // Set identity and Subs on Relay Chain @@ -175,7 +175,7 @@ fn set_id_relay(id: Identity) -> u128 { total_deposit } -fn assert_set_id_parachain(id: Identity) { +fn assert_set_id_parachain(id: &Identity) { // Set identity and Subs on Parachain with Zero deposit PeopleRococo::execute_with(|| { let free_bal = PeopleRococoBalances::free_balance(PeopleRococoSender::get()); @@ -219,6 +219,7 @@ fn assert_reap_id_relay(total_deposit: u128) { RococoOrigin::root(), RococoRelaySender::get(), )); + println!("total_deposit: {}", total_deposit); assert_expected_events!( RococoRelay, vec![ @@ -242,7 +243,7 @@ fn assert_reap_id_relay(total_deposit: u128) { assert_eq!(free_bal_after_reap, free_bal_before_reap + total_deposit); }); } -fn assert_reap_parachain(id: Identity) { +fn assert_reap_parachain(id: &Identity) { // 6. assert on Parachain PeopleRococo::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; @@ -284,40 +285,35 @@ fn assert_reap_parachain(id: Identity) { }); } +fn assert_relay_para_flow(id: &Identity) { + let total_deposit = set_id_relay(id); + assert_set_id_parachain(id); + assert_reap_id_relay(total_deposit); + assert_reap_parachain(id); +} + // We don't loop through ids and assert because genesis state is // required for each test #[test] fn on_reap_identity_works_for_minimal_identity() { let ids = identities(); - let total_deposit = set_id_relay(ids[0].clone()); - assert_set_id_parachain(ids[0].clone()); - assert_reap_id_relay(total_deposit); - assert_reap_parachain(ids[0].clone()); + assert_relay_para_flow(&ids[0]); } #[test] fn on_reap_identity_works_for_full_identity_no_additional() { let ids = identities(); - let total_deposit = set_id_relay(ids[1].clone()); - assert_set_id_parachain(ids[1].clone()); - assert_reap_id_relay(total_deposit); - assert_reap_parachain(ids[1].clone()); + assert_relay_para_flow(&ids[1]); } #[test] fn on_reap_identity_works_for_full_identity_nonsense_additional() { let ids = identities(); - let total_deposit = set_id_relay(ids[2].clone()); - assert_set_id_parachain(ids[2].clone()); - assert_reap_id_relay(total_deposit); - assert_reap_parachain(ids[2].clone()); + assert_relay_para_flow(&ids[2]); } #[test] fn on_reap_identity_works_for_full_identity_meaningful_additional() { let ids = identities(); - let total_deposit = set_id_relay(ids[3].clone()); - assert_set_id_parachain(ids[3].clone()); - assert_reap_id_relay(total_deposit); - assert_reap_parachain(ids[3].clone()); + assert_relay_para_flow(&ids[3]) } From 3d262dd221d3060bc8bc39f056a2a7f1d1a1a4f7 Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Thu, 30 Nov 2023 13:54:32 +0000 Subject: [PATCH 062/102] use calc_remote_deposit --- .../people-rococo/src/tests/reap_identity.rs | 38 ++++++++++++++----- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index f026601aa77d..ef558d44f59c 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -22,8 +22,8 @@ use people_rococo_runtime::people::{ IdentityInfo as IdentityInfoParachain, SubAccountDeposit as SubAccountDepositParachain, }; use rococo_runtime::{ - BasicDeposit, ByteDeposit, MaxAdditionalFields, RuntimeOrigin as RococoOrigin, - SubAccountDeposit, + deposit, BasicDeposit, ByteDeposit, MaxAdditionalFields, RuntimeOrigin as RococoOrigin, + SubAccountDeposit, EXISTENTIAL_DEPOSIT, }; use rococo_system_emulated_network::{ rococo_emulated_chain::RococoRelayPallet, RococoRelay, RococoRelayReceiver, RococoRelaySender, @@ -213,13 +213,17 @@ fn assert_reap_id_relay(total_deposit: u128) { type RuntimeEvent = ::RuntimeEvent; let free_bal_before_reap = RococoBalances::free_balance(RococoRelaySender::get()); let reserved_balance = RococoBalances::reserved_balance(RococoRelaySender::get()); + let mut remote_deposit = Balance::new(); //before reap reserved balance should be equal to total deposit assert_eq!(reserved_balance, total_deposit); - assert_ok!(RococoIdentityMigrator::reap_identity( - RococoOrigin::root(), - RococoRelaySender::get(), - )); - println!("total_deposit: {}", total_deposit); + + if let Some((_reg, bytes, subs)) = + RococoIdentityMigrator::reap_identity(RococoOrigin::root(), RococoRelaySender::get()) + { + remote_deposit = calculate_remote_deposit(bytes, subs); + assert!(remote_deposit > 0); + } + assert_expected_events!( RococoRelay, vec![ @@ -238,9 +242,9 @@ fn assert_reap_id_relay(total_deposit: u128) { assert_eq!(reserved_balance, 0); let free_bal_after_reap = RococoBalances::free_balance(RococoRelaySender::get()); - // free balance should be greater than before reap + // free balance after reap should be greater than before reap assert!(free_bal_after_reap > free_bal_before_reap); - assert_eq!(free_bal_after_reap, free_bal_before_reap + total_deposit); + assert_eq!(free_bal_after_reap, free_bal_before_reap - remote_deposit); }); } fn assert_reap_parachain(id: &Identity) { @@ -285,6 +289,22 @@ fn assert_reap_parachain(id: &Identity) { }); } +fn calculate_remote_deposit(bytes: u32, subs: u32) -> Balance { + let para_basic_deposit = deposit(1, 17) / 100; + let para_byte_deposit = deposit(0, 1) / 100; + let para_sub_account_deposit = deposit(1, 53) / 100; + let para_existential_deposit = EXISTENTIAL_DEPOSIT / 10; + + // pallet deposits + let id_deposit = + para_basic_deposit.saturating_add(para_byte_deposit.saturating_mul(bytes as Balance)); + let subs_deposit = para_sub_account_deposit.saturating_mul(subs as Balance); + + id_deposit + .saturating_add(subs_deposit) + .saturating_add(para_existential_deposit.saturating_mul(2)) +} + fn assert_relay_para_flow(id: &Identity) { let total_deposit = set_id_relay(id); assert_set_id_parachain(id); From 348b9c4324679e31dc7a5d7bb247a6aff73aa7ce Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Thu, 30 Nov 2023 14:18:54 +0000 Subject: [PATCH 063/102] assert and calculate on remote deposit --- .../people-rococo/src/tests/reap_identity.rs | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index ef558d44f59c..7c6038e708cc 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -22,9 +22,10 @@ use people_rococo_runtime::people::{ IdentityInfo as IdentityInfoParachain, SubAccountDeposit as SubAccountDepositParachain, }; use rococo_runtime::{ - deposit, BasicDeposit, ByteDeposit, MaxAdditionalFields, RuntimeOrigin as RococoOrigin, - SubAccountDeposit, EXISTENTIAL_DEPOSIT, + BasicDeposit, ByteDeposit, MaxAdditionalFields, RuntimeOrigin as RococoOrigin, + SubAccountDeposit, }; +use rococo_runtime_constants::currency::*; use rococo_system_emulated_network::{ rococo_emulated_chain::RococoRelayPallet, RococoRelay, RococoRelayReceiver, RococoRelaySender, }; @@ -207,23 +208,21 @@ fn assert_set_id_parachain(id: &Identity) { }); } -fn assert_reap_id_relay(total_deposit: u128) { +fn assert_reap_id_relay(total_deposit: u128, id: &Identity) { // 5. reap_identity on Relay Chain RococoRelay::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; let free_bal_before_reap = RococoBalances::free_balance(RococoRelaySender::get()); let reserved_balance = RococoBalances::reserved_balance(RococoRelaySender::get()); - let mut remote_deposit = Balance::new(); //before reap reserved balance should be equal to total deposit assert_eq!(reserved_balance, total_deposit); - if let Some((_reg, bytes, subs)) = - RococoIdentityMigrator::reap_identity(RococoOrigin::root(), RococoRelaySender::get()) - { - remote_deposit = calculate_remote_deposit(bytes, subs); - assert!(remote_deposit > 0); - } + assert_ok!(RococoIdentityMigrator::reap_identity( + RococoOrigin::root(), + RococoRelaySender::get() + )); + let remote_deposit = calculate_remote_deposit(id.relay.encoded_size() as u32, 1); assert_expected_events!( RococoRelay, vec![ @@ -244,7 +243,7 @@ fn assert_reap_id_relay(total_deposit: u128) { // free balance after reap should be greater than before reap assert!(free_bal_after_reap > free_bal_before_reap); - assert_eq!(free_bal_after_reap, free_bal_before_reap - remote_deposit); + assert_eq!(free_bal_after_reap, free_bal_before_reap + total_deposit - remote_deposit); }); } fn assert_reap_parachain(id: &Identity) { @@ -308,7 +307,7 @@ fn calculate_remote_deposit(bytes: u32, subs: u32) -> Balance { fn assert_relay_para_flow(id: &Identity) { let total_deposit = set_id_relay(id); assert_set_id_parachain(id); - assert_reap_id_relay(total_deposit); + assert_reap_id_relay(total_deposit, id); assert_reap_parachain(id); } From 872e4540cbef64c9c191998a5e2221604f96ded4 Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Thu, 30 Nov 2023 14:20:11 +0000 Subject: [PATCH 064/102] remove redundant comment --- .../tests/people/people-rococo/src/tests/reap_identity.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index 7c6038e708cc..28a5dea53e45 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -148,7 +148,6 @@ fn set_id_relay(id: &Identity) -> u128 { type RuntimeEvent = ::RuntimeEvent; // 1. Set identity on Relay Chain - // For this test case we only use a single instance of IdentityInfo assert_ok!(RococoIdentity::set_identity( RococoOrigin::signed(RococoRelaySender::get()), Box::new(id.relay.clone()) From 363ad04141323d1596a027d5e6ccb6880396dfeb Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Thu, 30 Nov 2023 15:57:01 +0000 Subject: [PATCH 065/102] clean --- .../people/people-rococo/src/tests/teleport.rs | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs index d4830b6a7afd..981142ed92c6 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs @@ -254,16 +254,3 @@ fn limited_teleport_native_assets_from_system_para_to_relay_fails() { // Receiver's balance does not change assert_eq!(receiver_balance_after, receiver_balance_before); } - -// #[test] -// fn teleport_to_other_system_parachains_works() { -// let amount = PEOPLE_ROCOCO_ED * 100; -// let native_asset: MultiAssets = (Parent, amount).into(); -// -// test_parachain_is_trusted_teleporter!( -// PeopleRococo, // Origin -// PeopleRococoXcmConfig, // XCM Configuration -// vec![BridgeHubRococo], // Destinations -// (native_asset, amount) -// ); -// } From c394638822266bddbe2d822dd19b8db6d8290d40 Mon Sep 17 00:00:00 2001 From: Richard Melkonian <35300528+0xmovses@users.noreply.github.com> Date: Fri, 1 Dec 2023 11:56:15 +0000 Subject: [PATCH 066/102] Update cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> --- .../tests/people/people-rococo/src/tests/reap_identity.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index 28a5dea53e45..0da513cebd28 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -116,7 +116,7 @@ fn identities() -> Vec { ]) .unwrap(); let mut fourth_para = second_para.clone(); - fourth_para.github = Data::Raw(b"niels-usernmae".to_vec().try_into().unwrap()); + fourth_para.github = Data::Raw(b"niels-username".to_vec().try_into().unwrap()); fourth_para.discord = Data::Raw(b"bohr-username".to_vec().try_into().unwrap()); vec![ From dbcd0bb2abcebf53af05083861c5c39109a2cc55 Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Fri, 1 Dec 2023 11:56:37 +0000 Subject: [PATCH 067/102] updates --- Cargo.lock | 84 +++++++++---------- .../xcm/xcm-emulator/tests/expected_events.rs | 2 + 2 files changed, 44 insertions(+), 42 deletions(-) create mode 100644 cumulus/xcm/xcm-emulator/tests/expected_events.rs diff --git a/Cargo.lock b/Cargo.lock index 89490cb04303..c0a0ccf7c6ad 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2497,23 +2497,23 @@ dependencies = [ [[package]] name = "clap" -version = "4.4.6" +version = "4.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d04704f56c2cde07f43e8e2c154b43f216dc5c92fc98ada720177362f953b956" +checksum = "41fffed7514f420abec6d183b1d3acfd9099c79c3a10a06ade4f8203f1411272" dependencies = [ "clap_builder", - "clap_derive 4.4.2", + "clap_derive 4.4.7", ] [[package]] name = "clap_builder" -version = "4.4.6" +version = "4.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e231faeaca65ebd1ea3c737966bf858971cd38c3849107aa3ea7de90a804e45" +checksum = "63361bae7eef3771745f02d8d892bec2fee5f6e34af316ba556e7f97a7069ff1" dependencies = [ "anstream", "anstyle", - "clap_lex 0.5.1", + "clap_lex 0.6.0", "strsim", "terminal_size", ] @@ -2524,7 +2524,7 @@ version = "4.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "586a385f7ef2f8b4d86bddaa0c094794e7ccbfe5ffef1f434fe928143fc783a5" dependencies = [ - "clap 4.4.6", + "clap 4.4.10", ] [[package]] @@ -2542,9 +2542,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.4.2" +version = "4.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0862016ff20d69b84ef8247369fabf5c008a7417002411897d40ee1f4532b873" +checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442" dependencies = [ "heck", "proc-macro2", @@ -2563,9 +2563,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.5.1" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd7cc57abe963c6d3b9d8be5b06ba7c8957a930305ca90304f24ef040aa6f961" +checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" [[package]] name = "coarsetime" @@ -3099,7 +3099,7 @@ dependencies = [ "anes", "cast", "ciborium", - "clap 4.4.6", + "clap 4.4.10", "criterion-plot", "futures", "is-terminal", @@ -3274,7 +3274,7 @@ dependencies = [ name = "cumulus-client-cli" version = "0.1.0" dependencies = [ - "clap 4.4.6", + "clap 4.4.10", "parity-scale-codec", "sc-chain-spec", "sc-cli", @@ -3979,7 +3979,7 @@ name = "cumulus-test-service" version = "0.1.0" dependencies = [ "async-trait", - "clap 4.4.6", + "clap 4.4.10", "criterion 0.5.1", "cumulus-client-cli", "cumulus-client-consensus-common", @@ -5291,7 +5291,7 @@ dependencies = [ "Inflector", "array-bytes 6.1.0", "chrono", - "clap 4.4.6", + "clap 4.4.10", "comfy-table", "frame-benchmarking", "frame-support", @@ -5383,7 +5383,7 @@ dependencies = [ name = "frame-election-solution-type-fuzzer" version = "2.0.0-alpha.5" dependencies = [ - "clap 4.4.6", + "clap 4.4.10", "frame-election-provider-solution-type", "frame-election-provider-support", "frame-support", @@ -7961,7 +7961,7 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" name = "minimal-node" version = "4.0.0-dev" dependencies = [ - "clap 4.4.6", + "clap 4.4.10", "frame", "futures", "futures-timer", @@ -8367,7 +8367,7 @@ name = "node-bench" version = "0.9.0-dev" dependencies = [ "array-bytes 6.1.0", - "clap 4.4.6", + "clap 4.4.10", "derive_more", "fs_extra", "futures", @@ -8442,7 +8442,7 @@ dependencies = [ name = "node-runtime-generate-bags" version = "3.0.0" dependencies = [ - "clap 4.4.6", + "clap 4.4.10", "generate-bags", "kitchensink-runtime", ] @@ -8451,7 +8451,7 @@ dependencies = [ name = "node-template" version = "4.0.0-dev" dependencies = [ - "clap 4.4.6", + "clap 4.4.10", "frame-benchmarking", "frame-benchmarking-cli", "frame-system", @@ -8495,7 +8495,7 @@ dependencies = [ name = "node-template-release" version = "3.0.0" dependencies = [ - "clap 4.4.6", + "clap 4.4.10", "flate2", "fs_extra", "glob", @@ -11013,7 +11013,7 @@ dependencies = [ name = "parachain-template-node" version = "0.1.0" dependencies = [ - "clap 4.4.6", + "clap 4.4.10", "color-print", "cumulus-client-cli", "cumulus-client-collator", @@ -11935,7 +11935,7 @@ dependencies = [ name = "polkadot-cli" version = "1.1.0" dependencies = [ - "clap 4.4.6", + "clap 4.4.10", "frame-benchmarking-cli", "futures", "log", @@ -12772,7 +12772,7 @@ dependencies = [ "async-trait", "bridge-hub-rococo-runtime", "bridge-hub-westend-runtime", - "clap 4.4.6", + "clap 4.4.10", "collectives-westend-runtime", "color-print", "contracts-rococo-runtime", @@ -13268,7 +13268,7 @@ version = "1.0.0" dependencies = [ "assert_matches", "async-trait", - "clap 4.4.6", + "clap 4.4.10", "color-eyre", "futures", "futures-timer", @@ -13415,7 +13415,7 @@ dependencies = [ name = "polkadot-voter-bags" version = "1.0.0" dependencies = [ - "clap 4.4.6", + "clap 4.4.10", "generate-bags", "sp-io", "westend-runtime", @@ -14216,7 +14216,7 @@ checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" name = "remote-ext-tests-bags-list" version = "1.0.0" dependencies = [ - "clap 4.4.6", + "clap 4.4.10", "frame-system", "log", "pallet-bags-list-remote-tests", @@ -14989,7 +14989,7 @@ dependencies = [ "array-bytes 6.1.0", "bip39", "chrono", - "clap 4.4.6", + "clap 4.4.10", "fdlimit", "futures", "futures-timer", @@ -16133,7 +16133,7 @@ dependencies = [ name = "sc-storage-monitor" version = "0.1.0" dependencies = [ - "clap 4.4.6", + "clap 4.4.10", "fs4", "log", "sc-client-db", @@ -16589,18 +16589,18 @@ checksum = "f97841a747eef040fcd2e7b3b9a220a7205926e60488e673d9e4926d27772ce5" [[package]] name = "serde" -version = "1.0.188" +version = "1.0.193" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" +checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.188" +version = "1.0.193" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" +checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" dependencies = [ "proc-macro2", "quote", @@ -17677,7 +17677,7 @@ dependencies = [ name = "sp-npos-elections-fuzzer" version = "2.0.0-alpha.5" dependencies = [ - "clap 4.4.6", + "clap 4.4.10", "honggfuzz", "rand 0.8.5", "sp-npos-elections", @@ -18183,7 +18183,7 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" name = "staging-chain-spec-builder" version = "2.0.0" dependencies = [ - "clap 4.4.6", + "clap 4.4.10", "log", "sc-chain-spec", "serde_json", @@ -18196,7 +18196,7 @@ version = "3.0.0-dev" dependencies = [ "array-bytes 6.1.0", "assert_cmd", - "clap 4.4.6", + "clap 4.4.10", "clap_complete", "criterion 0.4.0", "frame-benchmarking", @@ -18301,7 +18301,7 @@ dependencies = [ name = "staging-node-inspect" version = "0.9.0-dev" dependencies = [ - "clap 4.4.6", + "clap 4.4.10", "parity-scale-codec", "sc-cli", "sc-client-api", @@ -18510,7 +18510,7 @@ dependencies = [ name = "subkey" version = "3.0.0" dependencies = [ - "clap 4.4.6", + "clap 4.4.10", "sc-cli", ] @@ -18552,7 +18552,7 @@ dependencies = [ name = "substrate-frame-cli" version = "4.0.0-dev" dependencies = [ - "clap 4.4.6", + "clap 4.4.10", "frame-support", "frame-system", "sc-cli", @@ -19027,7 +19027,7 @@ dependencies = [ name = "test-parachain-adder-collator" version = "1.0.0" dependencies = [ - "clap 4.4.6", + "clap 4.4.10", "futures", "futures-timer", "log", @@ -19075,7 +19075,7 @@ dependencies = [ name = "test-parachain-undying-collator" version = "1.0.0" dependencies = [ - "clap 4.4.6", + "clap 4.4.10", "futures", "futures-timer", "log", @@ -19750,7 +19750,7 @@ version = "0.10.0-dev" dependencies = [ "assert_cmd", "async-trait", - "clap 4.4.6", + "clap 4.4.10", "frame-remote-externalities", "frame-try-runtime", "hex", diff --git a/cumulus/xcm/xcm-emulator/tests/expected_events.rs b/cumulus/xcm/xcm-emulator/tests/expected_events.rs new file mode 100644 index 000000000000..d689a0a3ff73 --- /dev/null +++ b/cumulus/xcm/xcm-emulator/tests/expected_events.rs @@ -0,0 +1,2 @@ +#[test] +fn test_assert_expected_events_should_fail_on_non_equality() {} From 0c51fc43c16d7de1bf8c1286fc961d98331b35d2 Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Fri, 1 Dec 2023 11:58:56 +0000 Subject: [PATCH 068/102] Revert "updates" This reverts commit dbcd0bb2abcebf53af05083861c5c39109a2cc55. --- Cargo.lock | 84 +++++++++---------- .../xcm/xcm-emulator/tests/expected_events.rs | 2 - 2 files changed, 42 insertions(+), 44 deletions(-) delete mode 100644 cumulus/xcm/xcm-emulator/tests/expected_events.rs diff --git a/Cargo.lock b/Cargo.lock index c0a0ccf7c6ad..89490cb04303 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2497,23 +2497,23 @@ dependencies = [ [[package]] name = "clap" -version = "4.4.10" +version = "4.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41fffed7514f420abec6d183b1d3acfd9099c79c3a10a06ade4f8203f1411272" +checksum = "d04704f56c2cde07f43e8e2c154b43f216dc5c92fc98ada720177362f953b956" dependencies = [ "clap_builder", - "clap_derive 4.4.7", + "clap_derive 4.4.2", ] [[package]] name = "clap_builder" -version = "4.4.9" +version = "4.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63361bae7eef3771745f02d8d892bec2fee5f6e34af316ba556e7f97a7069ff1" +checksum = "0e231faeaca65ebd1ea3c737966bf858971cd38c3849107aa3ea7de90a804e45" dependencies = [ "anstream", "anstyle", - "clap_lex 0.6.0", + "clap_lex 0.5.1", "strsim", "terminal_size", ] @@ -2524,7 +2524,7 @@ version = "4.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "586a385f7ef2f8b4d86bddaa0c094794e7ccbfe5ffef1f434fe928143fc783a5" dependencies = [ - "clap 4.4.10", + "clap 4.4.6", ] [[package]] @@ -2542,9 +2542,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.4.7" +version = "4.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442" +checksum = "0862016ff20d69b84ef8247369fabf5c008a7417002411897d40ee1f4532b873" dependencies = [ "heck", "proc-macro2", @@ -2563,9 +2563,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.6.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" +checksum = "cd7cc57abe963c6d3b9d8be5b06ba7c8957a930305ca90304f24ef040aa6f961" [[package]] name = "coarsetime" @@ -3099,7 +3099,7 @@ dependencies = [ "anes", "cast", "ciborium", - "clap 4.4.10", + "clap 4.4.6", "criterion-plot", "futures", "is-terminal", @@ -3274,7 +3274,7 @@ dependencies = [ name = "cumulus-client-cli" version = "0.1.0" dependencies = [ - "clap 4.4.10", + "clap 4.4.6", "parity-scale-codec", "sc-chain-spec", "sc-cli", @@ -3979,7 +3979,7 @@ name = "cumulus-test-service" version = "0.1.0" dependencies = [ "async-trait", - "clap 4.4.10", + "clap 4.4.6", "criterion 0.5.1", "cumulus-client-cli", "cumulus-client-consensus-common", @@ -5291,7 +5291,7 @@ dependencies = [ "Inflector", "array-bytes 6.1.0", "chrono", - "clap 4.4.10", + "clap 4.4.6", "comfy-table", "frame-benchmarking", "frame-support", @@ -5383,7 +5383,7 @@ dependencies = [ name = "frame-election-solution-type-fuzzer" version = "2.0.0-alpha.5" dependencies = [ - "clap 4.4.10", + "clap 4.4.6", "frame-election-provider-solution-type", "frame-election-provider-support", "frame-support", @@ -7961,7 +7961,7 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" name = "minimal-node" version = "4.0.0-dev" dependencies = [ - "clap 4.4.10", + "clap 4.4.6", "frame", "futures", "futures-timer", @@ -8367,7 +8367,7 @@ name = "node-bench" version = "0.9.0-dev" dependencies = [ "array-bytes 6.1.0", - "clap 4.4.10", + "clap 4.4.6", "derive_more", "fs_extra", "futures", @@ -8442,7 +8442,7 @@ dependencies = [ name = "node-runtime-generate-bags" version = "3.0.0" dependencies = [ - "clap 4.4.10", + "clap 4.4.6", "generate-bags", "kitchensink-runtime", ] @@ -8451,7 +8451,7 @@ dependencies = [ name = "node-template" version = "4.0.0-dev" dependencies = [ - "clap 4.4.10", + "clap 4.4.6", "frame-benchmarking", "frame-benchmarking-cli", "frame-system", @@ -8495,7 +8495,7 @@ dependencies = [ name = "node-template-release" version = "3.0.0" dependencies = [ - "clap 4.4.10", + "clap 4.4.6", "flate2", "fs_extra", "glob", @@ -11013,7 +11013,7 @@ dependencies = [ name = "parachain-template-node" version = "0.1.0" dependencies = [ - "clap 4.4.10", + "clap 4.4.6", "color-print", "cumulus-client-cli", "cumulus-client-collator", @@ -11935,7 +11935,7 @@ dependencies = [ name = "polkadot-cli" version = "1.1.0" dependencies = [ - "clap 4.4.10", + "clap 4.4.6", "frame-benchmarking-cli", "futures", "log", @@ -12772,7 +12772,7 @@ dependencies = [ "async-trait", "bridge-hub-rococo-runtime", "bridge-hub-westend-runtime", - "clap 4.4.10", + "clap 4.4.6", "collectives-westend-runtime", "color-print", "contracts-rococo-runtime", @@ -13268,7 +13268,7 @@ version = "1.0.0" dependencies = [ "assert_matches", "async-trait", - "clap 4.4.10", + "clap 4.4.6", "color-eyre", "futures", "futures-timer", @@ -13415,7 +13415,7 @@ dependencies = [ name = "polkadot-voter-bags" version = "1.0.0" dependencies = [ - "clap 4.4.10", + "clap 4.4.6", "generate-bags", "sp-io", "westend-runtime", @@ -14216,7 +14216,7 @@ checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" name = "remote-ext-tests-bags-list" version = "1.0.0" dependencies = [ - "clap 4.4.10", + "clap 4.4.6", "frame-system", "log", "pallet-bags-list-remote-tests", @@ -14989,7 +14989,7 @@ dependencies = [ "array-bytes 6.1.0", "bip39", "chrono", - "clap 4.4.10", + "clap 4.4.6", "fdlimit", "futures", "futures-timer", @@ -16133,7 +16133,7 @@ dependencies = [ name = "sc-storage-monitor" version = "0.1.0" dependencies = [ - "clap 4.4.10", + "clap 4.4.6", "fs4", "log", "sc-client-db", @@ -16589,18 +16589,18 @@ checksum = "f97841a747eef040fcd2e7b3b9a220a7205926e60488e673d9e4926d27772ce5" [[package]] name = "serde" -version = "1.0.193" +version = "1.0.188" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" +checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.193" +version = "1.0.188" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" +checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" dependencies = [ "proc-macro2", "quote", @@ -17677,7 +17677,7 @@ dependencies = [ name = "sp-npos-elections-fuzzer" version = "2.0.0-alpha.5" dependencies = [ - "clap 4.4.10", + "clap 4.4.6", "honggfuzz", "rand 0.8.5", "sp-npos-elections", @@ -18183,7 +18183,7 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" name = "staging-chain-spec-builder" version = "2.0.0" dependencies = [ - "clap 4.4.10", + "clap 4.4.6", "log", "sc-chain-spec", "serde_json", @@ -18196,7 +18196,7 @@ version = "3.0.0-dev" dependencies = [ "array-bytes 6.1.0", "assert_cmd", - "clap 4.4.10", + "clap 4.4.6", "clap_complete", "criterion 0.4.0", "frame-benchmarking", @@ -18301,7 +18301,7 @@ dependencies = [ name = "staging-node-inspect" version = "0.9.0-dev" dependencies = [ - "clap 4.4.10", + "clap 4.4.6", "parity-scale-codec", "sc-cli", "sc-client-api", @@ -18510,7 +18510,7 @@ dependencies = [ name = "subkey" version = "3.0.0" dependencies = [ - "clap 4.4.10", + "clap 4.4.6", "sc-cli", ] @@ -18552,7 +18552,7 @@ dependencies = [ name = "substrate-frame-cli" version = "4.0.0-dev" dependencies = [ - "clap 4.4.10", + "clap 4.4.6", "frame-support", "frame-system", "sc-cli", @@ -19027,7 +19027,7 @@ dependencies = [ name = "test-parachain-adder-collator" version = "1.0.0" dependencies = [ - "clap 4.4.10", + "clap 4.4.6", "futures", "futures-timer", "log", @@ -19075,7 +19075,7 @@ dependencies = [ name = "test-parachain-undying-collator" version = "1.0.0" dependencies = [ - "clap 4.4.10", + "clap 4.4.6", "futures", "futures-timer", "log", @@ -19750,7 +19750,7 @@ version = "0.10.0-dev" dependencies = [ "assert_cmd", "async-trait", - "clap 4.4.10", + "clap 4.4.6", "frame-remote-externalities", "frame-try-runtime", "hex", diff --git a/cumulus/xcm/xcm-emulator/tests/expected_events.rs b/cumulus/xcm/xcm-emulator/tests/expected_events.rs deleted file mode 100644 index d689a0a3ff73..000000000000 --- a/cumulus/xcm/xcm-emulator/tests/expected_events.rs +++ /dev/null @@ -1,2 +0,0 @@ -#[test] -fn test_assert_expected_events_should_fail_on_non_equality() {} From 51a21a718eb92229bce36ad764521fe980c1b3e9 Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Fri, 1 Dec 2023 14:40:50 +0000 Subject: [PATCH 069/102] add Subs cases, refactor, petrowski feedback --- .../people-rococo/src/tests/reap_identity.rs | 294 ++++++++++++++---- 1 file changed, 232 insertions(+), 62 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index 0da513cebd28..5856e8650b3c 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -22,14 +22,15 @@ use people_rococo_runtime::people::{ IdentityInfo as IdentityInfoParachain, SubAccountDeposit as SubAccountDepositParachain, }; use rococo_runtime::{ - BasicDeposit, ByteDeposit, MaxAdditionalFields, RuntimeOrigin as RococoOrigin, + BasicDeposit, ByteDeposit, MaxAdditionalFields, MaxSubAccounts, RuntimeOrigin as RococoOrigin, SubAccountDeposit, }; use rococo_runtime_constants::currency::*; use rococo_system_emulated_network::{ rococo_emulated_chain::RococoRelayPallet, RococoRelay, RococoRelayReceiver, RococoRelaySender, }; - +use std::time::{SystemTime, UNIX_EPOCH}; +type Balance = u128; type RococoIdentity = ::Identity; type RococoBalances = ::Balances; type RococoIdentityMigrator = ::IdentityMigrator; @@ -38,8 +39,26 @@ type PeopleRococoBalances = ::Balances; #[derive(Clone, Debug)] struct Identity { - relay: IdentityInfo, - para: IdentityInfoParachain, + relay: RelayIdentity, + para: ParaIdentity, +} + +#[derive(Clone, Debug)] +struct RelayIdentity { + main: IdentityInfo, + subs: Subs, +} +#[derive(Clone, Debug)] +struct ParaIdentity { + main: IdentityInfoParachain, + subs: Subs, +} + +#[derive(Clone, Debug)] +enum Subs { + Zero, + One, + Many(u32), } fn identities() -> Vec { @@ -74,7 +93,7 @@ fn identities() -> Vec { // Full Identity with no additional let second_relay = IdentityInfo { display: Data::Raw(b"xcm-test-one".to_vec().try_into().unwrap()), - legal: Data::Raw(b"The Right Ordinal Xcm Test, Esq.".to_vec().try_into().unwrap()), + legal: Data::Raw(b"The Xcm Test, Esq.".to_vec().try_into().unwrap()), web: Data::Raw(b"https://xcm-test.io".to_vec().try_into().unwrap()), email: Data::Raw(b"xcm-test@gmail.com".to_vec().try_into().unwrap()), pgp_fingerprint: Some(pgp_fingerprint), @@ -120,10 +139,42 @@ fn identities() -> Vec { fourth_para.discord = Data::Raw(b"bohr-username".to_vec().try_into().unwrap()); vec![ - Identity { relay: first_relay, para: first_para }, - Identity { relay: second_relay, para: second_para.clone() }, - Identity { relay: third_relay, para: second_para.clone() }, // same as second_para - Identity { relay: fourth_relay, para: fourth_para }, + Identity { + relay: RelayIdentity { main: first_relay, subs: Subs::One }, + para: ParaIdentity { main: first_para, subs: Subs::One }, + }, + Identity { + relay: RelayIdentity { main: second_relay, subs: Subs::One }, + para: ParaIdentity { main: second_para.clone(), subs: Subs::One }, + }, + Identity { + relay: RelayIdentity { main: third_relay, subs: Subs::One }, + para: ParaIdentity { main: second_para.clone(), subs: Subs::One }, /* same as + * second_para */ + }, + Identity { + relay: RelayIdentity { main: fourth_relay.clone(), subs: Subs::One }, + para: ParaIdentity { main: fourth_para.clone(), subs: Subs::One }, + }, + Identity { + relay: RelayIdentity { main: fourth_relay.clone(), subs: Subs::Many(2) }, // 2 + // subs + para: ParaIdentity { main: fourth_para.clone(), subs: Subs::Many(2) }, + }, + Identity { + relay: RelayIdentity { + main: fourth_relay.clone(), + subs: Subs::Many(MaxSubAccounts::get()), + }, + para: ParaIdentity { + main: fourth_para.clone(), + subs: Subs::Many(MaxSubAccounts::get()), + }, + }, + Identity { + relay: RelayIdentity { main: fourth_relay.clone(), subs: Subs::Zero }, + para: ParaIdentity { main: fourth_para.clone(), subs: Subs::Zero }, + }, ] } @@ -140,37 +191,93 @@ fn id_deposit_relaychain(id: &IdentityInfo) -> Balance { base_deposit + byte_deposit } -fn set_id_relay(id: &Identity) -> u128 { +fn set_id_relay(id: &Identity) -> Balance { let mut total_deposit = 0_u128; // Set identity and Subs on Relay Chain RococoRelay::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; - // 1. Set identity on Relay Chain assert_ok!(RococoIdentity::set_identity( RococoOrigin::signed(RococoRelaySender::get()), - Box::new(id.relay.clone()) + Box::new(id.relay.main.clone()) )); - // 2. Set sub-identity on Relay Chain - assert_ok!(RococoIdentity::set_subs( - RococoOrigin::signed(RococoRelaySender::get()), - vec![(RococoRelayReceiver::get(), Data::Raw(vec![42; 1].try_into().unwrap()))], - )); - assert_expected_events!( - RococoRelay, - vec![ - RuntimeEvent::Identity(IdentityEvent::IdentitySet { .. }) => {}, - RuntimeEvent::Balances(BalancesEvent::Reserved { .. }) => {}, - ] - ); + match id.relay.subs { + Subs::Zero => {}, + Subs::One => { + assert_ok!(RococoIdentity::set_subs( + RococoOrigin::signed(RococoRelaySender::get()), + vec![( + RococoRelayReceiver::get(), + Data::Raw(vec![1_u8; 1].try_into().unwrap()) + )], + )); + }, + Subs::Many(n) => { + let mut subs = Vec::new(); + for i in 0..n { + subs.push(( + RococoRelayReceiver::get(), + Data::Raw(vec![i as u8; 1].try_into().unwrap()), + )); + } + assert_ok!(RococoIdentity::set_subs( + RococoOrigin::signed(RococoRelaySender::get()), + subs, + )); + }, + } let reserved_bal = RococoBalances::reserved_balance(RococoRelaySender::get()); - total_deposit = SubAccountDeposit::get() + id_deposit_relaychain(&id.relay); - - // The reserved balance should equal the calculated total deposit - assert_eq!(reserved_bal, total_deposit); + let id_deposit = id_deposit_relaychain(&id.relay.main); + + match id.relay.subs { + Subs::Zero => {}, + Subs::One => { + total_deposit = SubAccountDeposit::get() + id_deposit_relaychain(&id.relay.main); + // for Many and One we assert the same + assert_expected_events!( + RococoRelay, + vec![ + RuntimeEvent::Identity(IdentityEvent::IdentitySet { .. }) => {}, + RuntimeEvent::Balances(BalancesEvent::Reserved { who, amount }) => { + who: *who == RococoRelaySender::get(), + amount: *amount == id_deposit, + }, + RuntimeEvent::Balances(BalancesEvent::Reserved { who, amount }) => { + who: *who == RococoRelaySender::get(), + amount: *amount == SubAccountDeposit::get(), + }, + ] + ); + // The reserved balance should equal the calculated total deposit + assert_eq!(reserved_bal, total_deposit); + }, + Subs::Many(n) => { + let mut sub_account_deposit = 0_u128; + for _ in 0..n { + sub_account_deposit += SubAccountDeposit::get(); + } + total_deposit = sub_account_deposit + id_deposit_relaychain(&id.relay.main); + assert_expected_events!( + RococoRelay, + vec![ + RuntimeEvent::Identity(IdentityEvent::IdentitySet { .. }) => {}, + RuntimeEvent::Balances(BalancesEvent::Reserved { who, amount }) => { + who: *who == RococoRelaySender::get(), + amount: *amount == id_deposit, + }, + RuntimeEvent::Balances(BalancesEvent::Reserved { who, amount }) => { + who: *who == RococoRelaySender::get(), + amount: *amount == sub_account_deposit, + }, + ] + ); + // The reserved balance should equal the calculated total deposit + assert_eq!(reserved_bal, total_deposit); + }, + } }); total_deposit } @@ -184,17 +291,16 @@ fn assert_set_id_parachain(id: &Identity) { //total balance at Genesis should be zero assert_eq!(reserved_bal + free_bal, 0); - // 3. Set identity on Parachain assert_ok!(PeopleRococoIdentity::set_identity_no_deposit( &PeopleRococoSender::get(), - id.para.clone(), + id.para.main.clone(), )); - // 4. Set sub-identity on Parachain assert_ok!(PeopleRococoIdentity::set_sub_no_deposit( &PeopleRococoSender::get(), PeopleRococoReceiver::get(), )); + // No events get triggered when calling set_sub_no_deposit // No amount should be reserved as deposit amounts are set to 0. @@ -208,20 +314,27 @@ fn assert_set_id_parachain(id: &Identity) { } fn assert_reap_id_relay(total_deposit: u128, id: &Identity) { - // 5. reap_identity on Relay Chain RococoRelay::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; let free_bal_before_reap = RococoBalances::free_balance(RococoRelaySender::get()); let reserved_balance = RococoBalances::reserved_balance(RococoRelaySender::get()); - //before reap reserved balance should be equal to total deposit - assert_eq!(reserved_balance, total_deposit); + + match id.relay.subs { + Subs::Zero => assert_eq!(reserved_balance, id_deposit_relaychain(&id.relay.main)), + _ => assert_eq!(reserved_balance, total_deposit), + } assert_ok!(RococoIdentityMigrator::reap_identity( RococoOrigin::root(), RococoRelaySender::get() )); - let remote_deposit = calculate_remote_deposit(id.relay.encoded_size() as u32, 1); + let remote_deposit = match id.relay.subs { + Subs::Zero => calculate_remote_deposit(id.relay.main.encoded_size() as u32, 0), + Subs::One => calculate_remote_deposit(id.relay.main.encoded_size() as u32, 1), + Subs::Many(n) => calculate_remote_deposit(id.relay.main.encoded_size() as u32, n), + }; + assert_expected_events!( RococoRelay, vec![ @@ -242,42 +355,81 @@ fn assert_reap_id_relay(total_deposit: u128, id: &Identity) { // free balance after reap should be greater than before reap assert!(free_bal_after_reap > free_bal_before_reap); - assert_eq!(free_bal_after_reap, free_bal_before_reap + total_deposit - remote_deposit); + + match id.relay.subs { + Subs::Zero => { + assert_eq!( + free_bal_after_reap, + free_bal_before_reap + id_deposit_relaychain(&id.relay.main) - remote_deposit + ); + }, + _ => { + assert_eq!( + free_bal_after_reap, + free_bal_before_reap + total_deposit - remote_deposit + ); + }, + } }); } fn assert_reap_parachain(id: &Identity) { - // 6. assert on Parachain PeopleRococo::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; let reserved_bal = PeopleRococoBalances::reserved_balance(PeopleRococoSender::get()); - let id_deposit = id_deposit_parachain(&id.para); + let id_deposit = id_deposit_parachain(&id.para.main); let subs_deposit = SubAccountDepositParachain::get(); let total_deposit = subs_deposit + id_deposit; - assert_expected_events!( - PeopleRococo, - vec![ - RuntimeEvent::Balances(BalancesEvent::Deposit { .. }) => {}, - RuntimeEvent::Balances(BalancesEvent::Endowed { .. }) => {}, - RuntimeEvent::Balances(BalancesEvent::Reserved { who, amount }) => { - who: *who == PeopleRococoSender::get(), - amount: *amount == id_deposit, - }, - RuntimeEvent::Balances(BalancesEvent::Reserved { who, amount }) => { - who: *who == PeopleRococoSender::get(), - amount: *amount == subs_deposit, - }, - RuntimeEvent::IdentityMigrator( - polkadot_runtime_common::identity_migrator::Event::DepositUpdated { - who, identity, subs - }) => { - who: *who == PeopleRococoSender::get(), - identity: *identity == id_deposit, - subs: *subs == subs_deposit, - }, - RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { ..}) => {}, - ] - ); + match id.para.subs { + Subs::Zero => { + assert_expected_events!( + PeopleRococo, + vec![ + RuntimeEvent::Balances(BalancesEvent::Deposit { .. }) => {}, + RuntimeEvent::Balances(BalancesEvent::Endowed { .. }) => {}, + RuntimeEvent::Balances(BalancesEvent::Reserved { who, amount }) => { + who: *who == PeopleRococoSender::get(), + amount: *amount == id_deposit, + }, + RuntimeEvent::Balances(BalancesEvent::Reserved { who, amount }) => { + who: *who == PeopleRococoSender::get(), + amount: *amount == subs_deposit, + }, + RuntimeEvent::IdentityMigrator( + polkadot_runtime_common::identity_migrator::Event::DepositUpdated { + who, identity, subs + }) => { + who: *who == PeopleRococoSender::get(), + identity: *identity == id_deposit, + subs: *subs == subs_deposit, + }, + RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { ..}) => {}, + ] + ); + }, + _ => { + assert_expected_events!( + PeopleRococo, + vec![ + RuntimeEvent::Balances(BalancesEvent::Deposit { .. }) => {}, + RuntimeEvent::Balances(BalancesEvent::Endowed { .. }) => {}, + RuntimeEvent::Balances(BalancesEvent::Reserved { who, amount }) => { + who: *who == PeopleRococoSender::get(), + amount: *amount == id_deposit, + }, + RuntimeEvent::IdentityMigrator( + polkadot_runtime_common::identity_migrator::Event::DepositUpdated { + who, identity, subs + }) => { + who: *who == PeopleRococoSender::get(), + identity: *identity == id_deposit, + subs: *subs == 0, + }, + RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { ..}) => {}, + ] + ); + }, + } // reserved balance should be equal to total deposit calculated on the Parachain assert_eq!(reserved_bal, total_deposit); @@ -335,3 +487,21 @@ fn on_reap_identity_works_for_full_identity_meaningful_additional() { let ids = identities(); assert_relay_para_flow(&ids[3]) } + +#[test] +fn on_reap_indentity_works_for_full_identity_with_two_subs() { + let ids = identities(); + assert_relay_para_flow(&ids[4]) +} + +#[test] +fn on_reap_indentity_works_for_full_identity_with_max_subs() { + let ids = identities(); + assert_relay_para_flow(&ids[5]) +} + +#[test] +fn on_reap_indentity_works_for_full_identity_with_zero_subs() { + let ids = identities(); + assert_relay_para_flow(&ids[6]) +} From c2ca2ab54e2b9d789032739ebd9614d213b36fc9 Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Fri, 1 Dec 2023 15:05:36 +0000 Subject: [PATCH 070/102] cleanup --- .../people-rococo/src/tests/reap_identity.rs | 85 ++++++++----------- substrate/frame/identity/src/lib.rs | 5 +- 2 files changed, 40 insertions(+), 50 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index 5856e8650b3c..f0d4b29bf975 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -381,65 +381,54 @@ fn assert_reap_parachain(id: &Identity) { let total_deposit = subs_deposit + id_deposit; match id.para.subs { - Subs::Zero => { - assert_expected_events!( - PeopleRococo, - vec![ - RuntimeEvent::Balances(BalancesEvent::Deposit { .. }) => {}, - RuntimeEvent::Balances(BalancesEvent::Endowed { .. }) => {}, - RuntimeEvent::Balances(BalancesEvent::Reserved { who, amount }) => { - who: *who == PeopleRococoSender::get(), - amount: *amount == id_deposit, - }, - RuntimeEvent::Balances(BalancesEvent::Reserved { who, amount }) => { - who: *who == PeopleRococoSender::get(), - amount: *amount == subs_deposit, - }, - RuntimeEvent::IdentityMigrator( - polkadot_runtime_common::identity_migrator::Event::DepositUpdated { - who, identity, subs - }) => { - who: *who == PeopleRococoSender::get(), - identity: *identity == id_deposit, - subs: *subs == subs_deposit, - }, - RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { ..}) => {}, - ] - ); - }, - _ => { - assert_expected_events!( - PeopleRococo, - vec![ - RuntimeEvent::Balances(BalancesEvent::Deposit { .. }) => {}, - RuntimeEvent::Balances(BalancesEvent::Endowed { .. }) => {}, - RuntimeEvent::Balances(BalancesEvent::Reserved { who, amount }) => { - who: *who == PeopleRococoSender::get(), - amount: *amount == id_deposit, - }, - RuntimeEvent::IdentityMigrator( - polkadot_runtime_common::identity_migrator::Event::DepositUpdated { - who, identity, subs - }) => { - who: *who == PeopleRococoSender::get(), - identity: *identity == id_deposit, - subs: *subs == 0, - }, - RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { ..}) => {}, - ] - ); + Subs::Many(n) => { + let mut sub_account_deposit = 0_u128; + for _ in 0..n { + sub_account_deposit += SubAccountDepositParachain::get(); + } + assert_reap_events(sub_account_deposit, id_deposit); }, + _ => assert_reap_events(subs_deposit, id_deposit), } // reserved balance should be equal to total deposit calculated on the Parachain assert_eq!(reserved_bal, total_deposit); - // Should have at least one ED after in free balance after the reap. assert!(PeopleRococoBalances::free_balance(PeopleRococoSender::get()) >= PEOPLE_ROCOCO_ED); }); } +fn assert_reap_events(subs_deposit: Balance, id_deposit: Balance) { + type RuntimeEvent = ::RuntimeEvent; + assert_expected_events!( + PeopleRococo, + vec![ + RuntimeEvent::Balances(BalancesEvent::Deposit { .. }) => {}, + RuntimeEvent::Balances(BalancesEvent::Endowed { .. }) => {}, + RuntimeEvent::Balances(BalancesEvent::Reserved { who, amount }) => { + who: *who == PeopleRococoSender::get(), + amount: *amount == id_deposit, + }, + RuntimeEvent::Balances(BalancesEvent::Reserved { who, amount }) => { + who: *who == PeopleRococoSender::get(), + amount: *amount == subs_deposit, + }, + RuntimeEvent::IdentityMigrator( + polkadot_runtime_common::identity_migrator::Event::DepositUpdated { + who, identity, subs + }) => { + who: *who == PeopleRococoSender::get(), + identity: *identity == id_deposit, + subs: *subs == subs_deposit, + }, + RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { ..}) => {}, + ] + ); +} + fn calculate_remote_deposit(bytes: u32, subs: u32) -> Balance { + // Execute these Rococo Relay Currency functions because this is the runtime context that + // this function is called in. let para_basic_deposit = deposit(1, 17) / 100; let para_byte_deposit = deposit(0, 1) / 100; let para_sub_account_deposit = deposit(1, 53) / 100; diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index b220f8dab990..476e2e6d0cb6 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -1005,7 +1005,8 @@ impl Pallet { Ok((new_id_deposit, new_subs_deposit)) } - /// Set an identity with zero deposit. Used for benchmarking and XCM emulator tests, involves + /// Set an identity with zero deposit. Used for benchmarking and XCM emulator tests, + /// that involve /// `rejig_deposit`. #[cfg(any(feature = "runtime-benchmarks", feature = "xcm-emulator"))] pub fn set_identity_no_deposit( @@ -1023,7 +1024,7 @@ impl Pallet { Ok(()) } - /// Set subs with zero deposit. Only used for benchmarking that involves `rejig_deposit`. + /// Set subs with zero deposit. Only used for benchmarking that involve `rejig_deposit`. #[cfg(any(feature = "runtime-benchmarks", feature = "xcm-emulator"))] pub fn set_sub_no_deposit(who: &T::AccountId, sub: T::AccountId) -> DispatchResult { use frame_support::BoundedVec; From 97a59fc8d5574bd3885087383463841e05cefb2e Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Fri, 1 Dec 2023 19:24:04 +0000 Subject: [PATCH 071/102] integrate seadanda feedback and further refactors --- .../people-rococo/src/tests/reap_identity.rs | 312 +++++++++--------- 1 file changed, 149 insertions(+), 163 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index f0d4b29bf975..2c0f4e965f1f 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -29,7 +29,6 @@ use rococo_runtime_constants::currency::*; use rococo_system_emulated_network::{ rococo_emulated_chain::RococoRelayPallet, RococoRelay, RococoRelayReceiver, RococoRelaySender, }; -use std::time::{SystemTime, UNIX_EPOCH}; type Balance = u128; type RococoIdentity = ::Identity; type RococoBalances = ::Balances; @@ -39,19 +38,85 @@ type PeopleRococoBalances = ::Balances; #[derive(Clone, Debug)] struct Identity { - relay: RelayIdentity, - para: ParaIdentity, -} - -#[derive(Clone, Debug)] -struct RelayIdentity { - main: IdentityInfo, + relay: IdentityInfo, + para: IdentityInfoParachain, subs: Subs, } -#[derive(Clone, Debug)] -struct ParaIdentity { - main: IdentityInfoParachain, - subs: Subs, + +impl Identity { + fn new>( + full: bool, + additional: Option>, + subs: Subs, + ) -> Self { + let pgp_fingerprint = [ + 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, + 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, + ]; + if full { + Self { + relay: IdentityInfo { + display: Data::Raw(b"xcm-test-one".to_vec().try_into().unwrap()), + legal: Data::Raw(b"The Xcm Test, Esq.".to_vec().try_into().unwrap()), + web: Data::Raw(b"https://xcm-test.io".to_vec().try_into().unwrap()), + email: Data::Raw(b"xcm-test@gmail.com".to_vec().try_into().unwrap()), + pgp_fingerprint: Some(pgp_fingerprint), + image: Data::Raw(b"xcm-test.png".to_vec().try_into().unwrap()), + twitter: Data::Raw(b"@xcm-test".to_vec().try_into().unwrap()), + riot: Data::Raw(b"riot-xcm-test".to_vec().try_into().unwrap()), + additional: additional.unwrap_or_else(|| { + BoundedVec::try_from(vec![( + Data::Raw(b"foo".to_vec().try_into().unwrap()), + Data::Raw(b"bar".to_vec().try_into().unwrap()), + )]) + .unwrap() + }), + }, + para: IdentityInfoParachain { + display: Data::Raw(b"xcm-test-one".to_vec().try_into().unwrap()), + legal: Data::Raw( + b"The Right Ordinal Xcm Test, Esq.".to_vec().try_into().unwrap(), + ), + web: Data::Raw(b"https://xcm-test.io".to_vec().try_into().unwrap()), + matrix: Data::Raw(b"riot-xcm-test".to_vec().try_into().unwrap()), + email: Data::Raw(b"xcm-test@gmail.com".to_vec().try_into().unwrap()), + pgp_fingerprint: Some(pgp_fingerprint), + image: Data::Raw(b"xcm-test.png".to_vec().try_into().unwrap()), + twitter: Data::Raw(b"@xcm-test".to_vec().try_into().unwrap()), + github: Data::Raw(b"niels-username".to_vec().try_into().unwrap()), + discord: Data::Raw(b"bohr-username".to_vec().try_into().unwrap()), + }, + subs, + } + } else { + Self { + relay: IdentityInfo { + display: Data::None, + legal: Data::None, + web: Data::None, + email: Data::None, + pgp_fingerprint: None, + image: Data::None, + twitter: Data::None, + riot: Data::None, + additional: additional.unwrap_or_default(), + }, + para: IdentityInfoParachain { + display: Data::None, + legal: Data::None, + web: Data::None, + matrix: Data::None, + email: Data::None, + pgp_fingerprint: None, + image: Data::None, + twitter: Data::None, + github: Data::None, + discord: Data::None, + }, + subs, + } + } + } } #[derive(Clone, Debug)] @@ -61,123 +126,6 @@ enum Subs { Many(u32), } -fn identities() -> Vec { - let pgp_fingerprint = [ - 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, - 0x88, 0x99, 0xAA, 0xBB, 0xCC, - ]; - // Minimal Identity - let first_relay = IdentityInfo { - display: Data::None, - legal: Data::None, - web: Data::None, - email: Data::None, - pgp_fingerprint: None, - image: Data::None, - twitter: Data::None, - riot: Data::None, - additional: Default::default(), - }; - let first_para = IdentityInfoParachain { - display: Data::None, - legal: Data::None, - web: Data::None, - matrix: Data::None, - email: Data::None, - pgp_fingerprint: None, - image: Data::None, - twitter: Data::None, - github: Data::None, - discord: Data::None, - }; - // Full Identity with no additional - let second_relay = IdentityInfo { - display: Data::Raw(b"xcm-test-one".to_vec().try_into().unwrap()), - legal: Data::Raw(b"The Xcm Test, Esq.".to_vec().try_into().unwrap()), - web: Data::Raw(b"https://xcm-test.io".to_vec().try_into().unwrap()), - email: Data::Raw(b"xcm-test@gmail.com".to_vec().try_into().unwrap()), - pgp_fingerprint: Some(pgp_fingerprint), - image: Data::Raw(b"xcm-test.png".to_vec().try_into().unwrap()), - twitter: Data::Raw(b"@xcm-test".to_vec().try_into().unwrap()), - riot: Data::Raw(b"riot-xcm-test".to_vec().try_into().unwrap()), - additional: Default::default(), - }; - let second_para = IdentityInfoParachain { - display: Data::Raw(b"xcm-test-one".to_vec().try_into().unwrap()), - legal: Data::Raw(b"The Right Ordinal Xcm Test, Esq.".to_vec().try_into().unwrap()), - web: Data::Raw(b"https://xcm-test.io".to_vec().try_into().unwrap()), - matrix: Data::Raw(b"riot-xcm-test".to_vec().try_into().unwrap()), - email: Data::Raw(b"xcm-test@gmail.com".to_vec().try_into().unwrap()), - pgp_fingerprint: Some(pgp_fingerprint), - image: Data::Raw(b"xcm-test.png".to_vec().try_into().unwrap()), - twitter: Data::Raw(b"@xcm-test".to_vec().try_into().unwrap()), - github: Data::None, - discord: Data::None, - }; - // Full Identity with nonsensical additional - let mut third_relay = second_relay.clone(); - third_relay.additional = BoundedVec::try_from(vec![( - Data::Raw(b"foO".to_vec().try_into().unwrap()), - Data::Raw(b"bAr".to_vec().try_into().unwrap()), - )]) - .unwrap(); - // Full Identity with meaningful additional - let mut fourth_relay = second_relay.clone(); - fourth_relay.additional = BoundedVec::try_from(vec![ - ( - Data::Raw(b"github".to_vec().try_into().unwrap()), - Data::Raw(b"niels-username".to_vec().try_into().unwrap()), - ), - ( - Data::Raw(b"discord".to_vec().try_into().unwrap()), - Data::Raw(b"bohr-username".to_vec().try_into().unwrap()), - ), - ]) - .unwrap(); - let mut fourth_para = second_para.clone(); - fourth_para.github = Data::Raw(b"niels-username".to_vec().try_into().unwrap()); - fourth_para.discord = Data::Raw(b"bohr-username".to_vec().try_into().unwrap()); - - vec![ - Identity { - relay: RelayIdentity { main: first_relay, subs: Subs::One }, - para: ParaIdentity { main: first_para, subs: Subs::One }, - }, - Identity { - relay: RelayIdentity { main: second_relay, subs: Subs::One }, - para: ParaIdentity { main: second_para.clone(), subs: Subs::One }, - }, - Identity { - relay: RelayIdentity { main: third_relay, subs: Subs::One }, - para: ParaIdentity { main: second_para.clone(), subs: Subs::One }, /* same as - * second_para */ - }, - Identity { - relay: RelayIdentity { main: fourth_relay.clone(), subs: Subs::One }, - para: ParaIdentity { main: fourth_para.clone(), subs: Subs::One }, - }, - Identity { - relay: RelayIdentity { main: fourth_relay.clone(), subs: Subs::Many(2) }, // 2 - // subs - para: ParaIdentity { main: fourth_para.clone(), subs: Subs::Many(2) }, - }, - Identity { - relay: RelayIdentity { - main: fourth_relay.clone(), - subs: Subs::Many(MaxSubAccounts::get()), - }, - para: ParaIdentity { - main: fourth_para.clone(), - subs: Subs::Many(MaxSubAccounts::get()), - }, - }, - Identity { - relay: RelayIdentity { main: fourth_relay.clone(), subs: Subs::Zero }, - para: ParaIdentity { main: fourth_para.clone(), subs: Subs::Zero }, - }, - ] -} - fn id_deposit_parachain(id: &IdentityInfoParachain) -> Balance { let base_deposit = BasicDepositParachain::get(); let byte_deposit = @@ -200,10 +148,10 @@ fn set_id_relay(id: &Identity) -> Balance { assert_ok!(RococoIdentity::set_identity( RococoOrigin::signed(RococoRelaySender::get()), - Box::new(id.relay.main.clone()) + Box::new(id.relay.clone()) )); - match id.relay.subs { + match id.subs { Subs::Zero => {}, Subs::One => { assert_ok!(RococoIdentity::set_subs( @@ -230,12 +178,12 @@ fn set_id_relay(id: &Identity) -> Balance { } let reserved_bal = RococoBalances::reserved_balance(RococoRelaySender::get()); - let id_deposit = id_deposit_relaychain(&id.relay.main); + let id_deposit = id_deposit_relaychain(&id.relay); - match id.relay.subs { + match id.subs { Subs::Zero => {}, Subs::One => { - total_deposit = SubAccountDeposit::get() + id_deposit_relaychain(&id.relay.main); + total_deposit = SubAccountDeposit::get() + id_deposit_relaychain(&id.relay); // for Many and One we assert the same assert_expected_events!( RococoRelay, @@ -259,7 +207,7 @@ fn set_id_relay(id: &Identity) -> Balance { for _ in 0..n { sub_account_deposit += SubAccountDeposit::get(); } - total_deposit = sub_account_deposit + id_deposit_relaychain(&id.relay.main); + total_deposit = sub_account_deposit + id_deposit_relaychain(&id.relay); assert_expected_events!( RococoRelay, vec![ @@ -293,7 +241,7 @@ fn assert_set_id_parachain(id: &Identity) { assert_ok!(PeopleRococoIdentity::set_identity_no_deposit( &PeopleRococoSender::get(), - id.para.main.clone(), + id.para.clone(), )); assert_ok!(PeopleRococoIdentity::set_sub_no_deposit( @@ -319,8 +267,8 @@ fn assert_reap_id_relay(total_deposit: u128, id: &Identity) { let free_bal_before_reap = RococoBalances::free_balance(RococoRelaySender::get()); let reserved_balance = RococoBalances::reserved_balance(RococoRelaySender::get()); - match id.relay.subs { - Subs::Zero => assert_eq!(reserved_balance, id_deposit_relaychain(&id.relay.main)), + match id.subs { + Subs::Zero => assert_eq!(reserved_balance, id_deposit_relaychain(&id.relay)), _ => assert_eq!(reserved_balance, total_deposit), } @@ -329,10 +277,10 @@ fn assert_reap_id_relay(total_deposit: u128, id: &Identity) { RococoRelaySender::get() )); - let remote_deposit = match id.relay.subs { - Subs::Zero => calculate_remote_deposit(id.relay.main.encoded_size() as u32, 0), - Subs::One => calculate_remote_deposit(id.relay.main.encoded_size() as u32, 1), - Subs::Many(n) => calculate_remote_deposit(id.relay.main.encoded_size() as u32, n), + let remote_deposit = match id.subs { + Subs::Zero => calculate_remote_deposit(id.relay.encoded_size() as u32, 0), + Subs::One => calculate_remote_deposit(id.relay.encoded_size() as u32, 1), + Subs::Many(n) => calculate_remote_deposit(id.relay.encoded_size() as u32, n), }; assert_expected_events!( @@ -356,11 +304,11 @@ fn assert_reap_id_relay(total_deposit: u128, id: &Identity) { // free balance after reap should be greater than before reap assert!(free_bal_after_reap > free_bal_before_reap); - match id.relay.subs { + match id.subs { Subs::Zero => { assert_eq!( free_bal_after_reap, - free_bal_before_reap + id_deposit_relaychain(&id.relay.main) - remote_deposit + free_bal_before_reap + id_deposit_relaychain(&id.relay) - remote_deposit ); }, _ => { @@ -374,13 +322,12 @@ fn assert_reap_id_relay(total_deposit: u128, id: &Identity) { } fn assert_reap_parachain(id: &Identity) { PeopleRococo::execute_with(|| { - type RuntimeEvent = ::RuntimeEvent; let reserved_bal = PeopleRococoBalances::reserved_balance(PeopleRococoSender::get()); - let id_deposit = id_deposit_parachain(&id.para.main); + let id_deposit = id_deposit_parachain(&id.para); let subs_deposit = SubAccountDepositParachain::get(); let total_deposit = subs_deposit + id_deposit; - match id.para.subs { + match id.subs { Subs::Many(n) => { let mut sub_account_deposit = 0_u128; for _ in 0..n { @@ -451,46 +398,85 @@ fn assert_relay_para_flow(id: &Identity) { assert_reap_parachain(id); } -// We don't loop through ids and assert because genesis state is -// required for each test +fn nonsesical_additional() -> BoundedVec<(Data, Data), MaxAdditionalFields> { + BoundedVec::try_from(vec![ + ( + Data::Raw(b"foo".to_vec().try_into().unwrap()), + Data::Raw(b"bar".to_vec().try_into().unwrap()), + ), + ( + Data::Raw(b"baz".to_vec().try_into().unwrap()), + Data::Raw(b"qux".to_vec().try_into().unwrap()), + ), + ]) + .unwrap() +} + +fn meaningful_additional() -> BoundedVec<(Data, Data), MaxAdditionalFields> { + BoundedVec::try_from(vec![ + ( + Data::Raw(b"github".to_vec().try_into().unwrap()), + Data::Raw(b"niels-username".to_vec().try_into().unwrap()), + ), + ( + Data::Raw(b"discord".to_vec().try_into().unwrap()), + Data::Raw(b"bohr-username".to_vec().try_into().unwrap()), + ), + ]) + .unwrap() +} + #[test] fn on_reap_identity_works_for_minimal_identity() { - let ids = identities(); - assert_relay_para_flow(&ids[0]); + assert_relay_para_flow(&Identity::new::(false, None, Subs::One)); } #[test] fn on_reap_identity_works_for_full_identity_no_additional() { - let ids = identities(); - assert_relay_para_flow(&ids[1]); + assert_relay_para_flow(&Identity::new::(true, None, Subs::One)); } #[test] fn on_reap_identity_works_for_full_identity_nonsense_additional() { - let ids = identities(); - assert_relay_para_flow(&ids[2]); + assert_relay_para_flow(&Identity::new::( + true, + Some(nonsesical_additional()), + Subs::One, + )); } #[test] fn on_reap_identity_works_for_full_identity_meaningful_additional() { - let ids = identities(); - assert_relay_para_flow(&ids[3]) + assert_relay_para_flow(&Identity::new::( + true, + Some(meaningful_additional()), + Subs::One, + )); } #[test] fn on_reap_indentity_works_for_full_identity_with_two_subs() { - let ids = identities(); - assert_relay_para_flow(&ids[4]) + assert_relay_para_flow(&Identity::new::( + true, + Some(meaningful_additional()), + Subs::One, + )) } #[test] fn on_reap_indentity_works_for_full_identity_with_max_subs() { - let ids = identities(); - assert_relay_para_flow(&ids[5]) + assert_relay_para_flow(&Identity::new::( + true, + Some(meaningful_additional()), + Subs::Many(MaxSubAccounts::get()), + )) } #[test] fn on_reap_indentity_works_for_full_identity_with_zero_subs() { - let ids = identities(); - assert_relay_para_flow(&ids[6]) + assert_relay_para_flow(&Identity::new::( + true, + Some(meaningful_additional()), + Subs::Zero, + )); } From 9bcaffb604ee6cc38a85f41cf02ed296963b4ced Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Fri, 1 Dec 2023 19:46:16 +0000 Subject: [PATCH 072/102] improve Identity::new --- .../people-rococo/src/tests/reap_identity.rs | 103 +++++++----------- 1 file changed, 42 insertions(+), 61 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index 2c0f4e965f1f..586800c19d20 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -53,68 +53,49 @@ impl Identity { 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, ]; - if full { - Self { - relay: IdentityInfo { - display: Data::Raw(b"xcm-test-one".to_vec().try_into().unwrap()), - legal: Data::Raw(b"The Xcm Test, Esq.".to_vec().try_into().unwrap()), - web: Data::Raw(b"https://xcm-test.io".to_vec().try_into().unwrap()), - email: Data::Raw(b"xcm-test@gmail.com".to_vec().try_into().unwrap()), - pgp_fingerprint: Some(pgp_fingerprint), - image: Data::Raw(b"xcm-test.png".to_vec().try_into().unwrap()), - twitter: Data::Raw(b"@xcm-test".to_vec().try_into().unwrap()), - riot: Data::Raw(b"riot-xcm-test".to_vec().try_into().unwrap()), - additional: additional.unwrap_or_else(|| { - BoundedVec::try_from(vec![( - Data::Raw(b"foo".to_vec().try_into().unwrap()), - Data::Raw(b"bar".to_vec().try_into().unwrap()), - )]) - .unwrap() - }), - }, - para: IdentityInfoParachain { - display: Data::Raw(b"xcm-test-one".to_vec().try_into().unwrap()), - legal: Data::Raw( - b"The Right Ordinal Xcm Test, Esq.".to_vec().try_into().unwrap(), - ), - web: Data::Raw(b"https://xcm-test.io".to_vec().try_into().unwrap()), - matrix: Data::Raw(b"riot-xcm-test".to_vec().try_into().unwrap()), - email: Data::Raw(b"xcm-test@gmail.com".to_vec().try_into().unwrap()), - pgp_fingerprint: Some(pgp_fingerprint), - image: Data::Raw(b"xcm-test.png".to_vec().try_into().unwrap()), - twitter: Data::Raw(b"@xcm-test".to_vec().try_into().unwrap()), - github: Data::Raw(b"niels-username".to_vec().try_into().unwrap()), - discord: Data::Raw(b"bohr-username".to_vec().try_into().unwrap()), - }, - subs, - } - } else { - Self { - relay: IdentityInfo { - display: Data::None, - legal: Data::None, - web: Data::None, - email: Data::None, - pgp_fingerprint: None, - image: Data::None, - twitter: Data::None, - riot: Data::None, - additional: additional.unwrap_or_default(), - }, - para: IdentityInfoParachain { - display: Data::None, - legal: Data::None, - web: Data::None, - matrix: Data::None, - email: Data::None, - pgp_fingerprint: None, - image: Data::None, - twitter: Data::None, - github: Data::None, - discord: Data::None, - }, - subs, + let make_data = |data: &[u8], full: bool| -> Data { + if full { + Data::Raw(data.to_vec().try_into().unwrap()) + } else { + Data::None } + }; + let (github, discord) = additional + .as_ref() + .and_then(|vec| vec.get(0)) + .map(|(g, d)| (g.clone(), d.clone())) + .unwrap_or((Data::None, Data::None)); + Self { + relay: IdentityInfo { + display: make_data(b"xcm-test", full), + legal: make_data(b"The Xcm Test, Esq.", full), + web: make_data(b"https://xcm-test.io", full), + riot: make_data(b"xcm-riot", full), + email: make_data(b"xcm-test@gmail.com", full), + pgp_fingerprint: Some(pgp_fingerprint), + image: make_data(b"xcm-test.png", full), + twitter: make_data(b"@xcm-test", full), + additional: additional.unwrap_or_else(|| { + BoundedVec::try_from(vec![( + Data::Raw(b"foo".to_vec().try_into().unwrap()), + Data::Raw(b"bar".to_vec().try_into().unwrap()), + )]) + .unwrap() + }), + }, + para: IdentityInfoParachain { + display: make_data(b"xcm-test", full), + legal: make_data(b"The Xcm Test, Esq.", full), + web: make_data(b"https://xcm-test.io", full), + matrix: make_data(b"xcm-matrix@server", full), + email: make_data(b"xcm-test@gmail.com", full), + pgp_fingerprint: Some(pgp_fingerprint), + image: make_data(b"xcm-test.png", full), + twitter: make_data(b"@xcm-test", full), + github, + discord, + }, + subs, } } } From 0877093e9d2dab967f27101fe4a08169799d5de8 Mon Sep 17 00:00:00 2001 From: Richard Melkonian <35300528+0xmovses@users.noreply.github.com> Date: Fri, 1 Dec 2023 19:48:25 +0000 Subject: [PATCH 073/102] Update cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> --- .../tests/people/people-rococo/src/tests/reap_identity.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index 586800c19d20..8d0e36ee2a72 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -184,10 +184,7 @@ fn set_id_relay(id: &Identity) -> Balance { assert_eq!(reserved_bal, total_deposit); }, Subs::Many(n) => { - let mut sub_account_deposit = 0_u128; - for _ in 0..n { - sub_account_deposit += SubAccountDeposit::get(); - } + let sub_account_deposit = n * SubAccountDeposit::get() as u128; total_deposit = sub_account_deposit + id_deposit_relaychain(&id.relay); assert_expected_events!( RococoRelay, From 5c4fa6a91c194a7336abb9a2b2c580e348bdabe4 Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Fri, 1 Dec 2023 20:32:23 +0000 Subject: [PATCH 074/102] integrate petrowski feedback --- .../people-rococo/src/tests/reap_identity.rs | 63 +++++++++++-------- 1 file changed, 36 insertions(+), 27 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index 8d0e36ee2a72..94d7517098f6 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -162,10 +162,9 @@ fn set_id_relay(id: &Identity) -> Balance { let id_deposit = id_deposit_relaychain(&id.relay); match id.subs { - Subs::Zero => {}, - Subs::One => { - total_deposit = SubAccountDeposit::get() + id_deposit_relaychain(&id.relay); - // for Many and One we assert the same + Subs::Many(n) => { + let sub_account_deposit = n as u128 * SubAccountDeposit::get() as u128; + total_deposit = sub_account_deposit + id_deposit_relaychain(&id.relay); assert_expected_events!( RococoRelay, vec![ @@ -176,16 +175,15 @@ fn set_id_relay(id: &Identity) -> Balance { }, RuntimeEvent::Balances(BalancesEvent::Reserved { who, amount }) => { who: *who == RococoRelaySender::get(), - amount: *amount == SubAccountDeposit::get(), + amount: *amount == sub_account_deposit, }, ] ); // The reserved balance should equal the calculated total deposit assert_eq!(reserved_bal, total_deposit); }, - Subs::Many(n) => { - let sub_account_deposit = n * SubAccountDeposit::get() as u128; - total_deposit = sub_account_deposit + id_deposit_relaychain(&id.relay); + _ => { + total_deposit = SubAccountDeposit::get() + id_deposit_relaychain(&id.relay); assert_expected_events!( RococoRelay, vec![ @@ -196,7 +194,7 @@ fn set_id_relay(id: &Identity) -> Balance { }, RuntimeEvent::Balances(BalancesEvent::Reserved { who, amount }) => { who: *who == RococoRelaySender::get(), - amount: *amount == sub_account_deposit, + amount: *amount == SubAccountDeposit::get(), }, ] ); @@ -222,10 +220,22 @@ fn assert_set_id_parachain(id: &Identity) { id.para.clone(), )); - assert_ok!(PeopleRococoIdentity::set_sub_no_deposit( - &PeopleRococoSender::get(), - PeopleRococoReceiver::get(), - )); + match id.subs { + Subs::Zero => {}, + Subs::One => { + assert_ok!(PeopleRococoIdentity::set_sub_no_deposit( + &PeopleRococoSender::get(), + PeopleRococoReceiver::get(), + )); + }, + Subs::Many(n) => + for _ in 0..n { + assert_ok!(PeopleRococoIdentity::set_sub_no_deposit( + &PeopleRococoSender::get(), + PeopleRococoReceiver::get(), + )); + }, + } // No events get triggered when calling set_sub_no_deposit @@ -233,13 +243,18 @@ fn assert_set_id_parachain(id: &Identity) { let reserved_bal = PeopleRococoBalances::reserved_balance(PeopleRococoSender::get()); assert_eq!(reserved_bal, 0); assert!(PeopleRococoIdentity::identity(&PeopleRococoSender::get()).is_some()); + let (_, sub_accounts) = ::Identity::subs_of(&PeopleRococoSender::get()); - assert_eq!(sub_accounts.len(), 1); + match id.subs { + Subs::Zero => assert_eq!(sub_accounts.len(), 0), + Subs::One => assert_eq!(sub_accounts.len(), 1), + Subs::Many(n) => assert_eq!(sub_accounts.len(), n as usize), + } }); } -fn assert_reap_id_relay(total_deposit: u128, id: &Identity) { +fn assert_reap_id_relay(mut total_deposit: u128, id: &Identity) { RococoRelay::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; let free_bal_before_reap = RococoBalances::free_balance(RococoRelaySender::get()); @@ -376,17 +391,11 @@ fn assert_relay_para_flow(id: &Identity) { assert_reap_parachain(id); } -fn nonsesical_additional() -> BoundedVec<(Data, Data), MaxAdditionalFields> { - BoundedVec::try_from(vec![ - ( - Data::Raw(b"foo".to_vec().try_into().unwrap()), - Data::Raw(b"bar".to_vec().try_into().unwrap()), - ), - ( - Data::Raw(b"baz".to_vec().try_into().unwrap()), - Data::Raw(b"qux".to_vec().try_into().unwrap()), - ), - ]) +fn nonsensical_additional() -> BoundedVec<(Data, Data), MaxAdditionalFields> { + BoundedVec::try_from(vec![( + Data::Raw(b"fOo".to_vec().try_into().unwrap()), + Data::Raw(b"baR".to_vec().try_into().unwrap()), + )]) .unwrap() } @@ -418,7 +427,7 @@ fn on_reap_identity_works_for_full_identity_no_additional() { fn on_reap_identity_works_for_full_identity_nonsense_additional() { assert_relay_para_flow(&Identity::new::( true, - Some(nonsesical_additional()), + Some(nonsensical_additional()), Subs::One, )); } From d73f6feb92eba33bb1f31c1068b84a43afc67436 Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Fri, 1 Dec 2023 21:22:00 +0000 Subject: [PATCH 075/102] call n times for with n new accounts --- .../people/people-rococo/src/tests/reap_identity.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index 94d7517098f6..f2597dfd9d2d 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -139,7 +139,7 @@ fn set_id_relay(id: &Identity) -> Balance { RococoOrigin::signed(RococoRelaySender::get()), vec![( RococoRelayReceiver::get(), - Data::Raw(vec![1_u8; 1].try_into().unwrap()) + Data::Raw(vec![1_u8; 1].try_into().unwrap()), )], )); }, @@ -147,7 +147,7 @@ fn set_id_relay(id: &Identity) -> Balance { let mut subs = Vec::new(); for i in 0..n { subs.push(( - RococoRelayReceiver::get(), + AccountId32::new([i as u8 + 1; 32]), Data::Raw(vec![i as u8; 1].try_into().unwrap()), )); } @@ -225,14 +225,14 @@ fn assert_set_id_parachain(id: &Identity) { Subs::One => { assert_ok!(PeopleRococoIdentity::set_sub_no_deposit( &PeopleRococoSender::get(), - PeopleRococoReceiver::get(), + AccountId32::new([1_u8; 32]), )); }, Subs::Many(n) => - for _ in 0..n { + for i in 0..n { assert_ok!(PeopleRococoIdentity::set_sub_no_deposit( &PeopleRococoSender::get(), - PeopleRococoReceiver::get(), + AccountId32::new([i as u8 + 1; 32]), )); }, } @@ -254,7 +254,7 @@ fn assert_set_id_parachain(id: &Identity) { }); } -fn assert_reap_id_relay(mut total_deposit: u128, id: &Identity) { +fn assert_reap_id_relay(total_deposit: u128, id: &Identity) { RococoRelay::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; let free_bal_before_reap = RococoBalances::free_balance(RococoRelaySender::get()); From 83a5e70b6d4a878f0f64577d6d4722e1063547e9 Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Fri, 1 Dec 2023 21:59:04 +0000 Subject: [PATCH 076/102] create set_subs, update assertions --- .../people-rococo/src/tests/reap_identity.rs | 144 ++++++++++++------ substrate/frame/identity/src/lib.rs | 14 +- 2 files changed, 107 insertions(+), 51 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index f2597dfd9d2d..9db5ce1d6e51 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -162,9 +162,22 @@ fn set_id_relay(id: &Identity) -> Balance { let id_deposit = id_deposit_relaychain(&id.relay); match id.subs { - Subs::Many(n) => { - let sub_account_deposit = n as u128 * SubAccountDeposit::get() as u128; - total_deposit = sub_account_deposit + id_deposit_relaychain(&id.relay); + Subs::Zero => { + total_deposit = id_deposit; // No subs + assert_expected_events!( + RococoRelay, + vec![ + RuntimeEvent::Identity(IdentityEvent::IdentitySet { .. }) => {}, + RuntimeEvent::Balances(BalancesEvent::Reserved { who, amount }) => { + who: *who == RococoRelaySender::get(), + amount: *amount == id_deposit, + }, + ] + ); + assert_eq!(reserved_bal, total_deposit); + }, + Subs::One => { + total_deposit = SubAccountDeposit::get() + id_deposit_relaychain(&id.relay); assert_expected_events!( RococoRelay, vec![ @@ -175,15 +188,15 @@ fn set_id_relay(id: &Identity) -> Balance { }, RuntimeEvent::Balances(BalancesEvent::Reserved { who, amount }) => { who: *who == RococoRelaySender::get(), - amount: *amount == sub_account_deposit, + amount: *amount == SubAccountDeposit::get(), }, ] ); - // The reserved balance should equal the calculated total deposit assert_eq!(reserved_bal, total_deposit); }, - _ => { - total_deposit = SubAccountDeposit::get() + id_deposit_relaychain(&id.relay); + Subs::Many(n) => { + let sub_account_deposit = n as u128 * SubAccountDeposit::get() as u128; + total_deposit = sub_account_deposit + id_deposit_relaychain(&id.relay); assert_expected_events!( RococoRelay, vec![ @@ -194,7 +207,7 @@ fn set_id_relay(id: &Identity) -> Balance { }, RuntimeEvent::Balances(BalancesEvent::Reserved { who, amount }) => { who: *who == RococoRelaySender::get(), - amount: *amount == SubAccountDeposit::get(), + amount: *amount == sub_account_deposit, }, ] ); @@ -228,13 +241,16 @@ fn assert_set_id_parachain(id: &Identity) { AccountId32::new([1_u8; 32]), )); }, - Subs::Many(n) => + Subs::Many(n) => { + let mut subs = Vec::new(); for i in 0..n { - assert_ok!(PeopleRococoIdentity::set_sub_no_deposit( - &PeopleRococoSender::get(), - AccountId32::new([i as u8 + 1; 32]), - )); - }, + subs.push(AccountId32::new([i as u8 + 1; 32])); + } + assert_ok!(PeopleRococoIdentity::set_subs_no_deposit( + &PeopleRococoSender::get(), + subs, + )); + }, } // No events get triggered when calling set_sub_no_deposit @@ -244,8 +260,8 @@ fn assert_set_id_parachain(id: &Identity) { assert_eq!(reserved_bal, 0); assert!(PeopleRococoIdentity::identity(&PeopleRococoSender::get()).is_some()); - let (_, sub_accounts) = - ::Identity::subs_of(&PeopleRococoSender::get()); + let (_, sub_accounts) = PeopleRococoIdentity::subs_of(&PeopleRococoSender::get()); + match id.subs { Subs::Zero => assert_eq!(sub_accounts.len(), 0), Subs::One => assert_eq!(sub_accounts.len(), 1), @@ -318,52 +334,80 @@ fn assert_reap_parachain(id: &Identity) { let reserved_bal = PeopleRococoBalances::reserved_balance(PeopleRococoSender::get()); let id_deposit = id_deposit_parachain(&id.para); let subs_deposit = SubAccountDepositParachain::get(); - let total_deposit = subs_deposit + id_deposit; match id.subs { + Subs::Zero => { + assert_reap_events(0, id_deposit, id); + assert_eq!(reserved_bal, id_deposit); + }, + Subs::One => { + assert_reap_events(subs_deposit, id_deposit, id); + assert_eq!(reserved_bal, SubAccountDepositParachain::get() + id_deposit); + }, Subs::Many(n) => { - let mut sub_account_deposit = 0_u128; - for _ in 0..n { - sub_account_deposit += SubAccountDepositParachain::get(); - } - assert_reap_events(sub_account_deposit, id_deposit); + let sub_account_deposit = n as u128 * SubAccountDepositParachain::get() as u128; + assert_reap_events(sub_account_deposit, id_deposit, id); + assert_eq!(reserved_bal, sub_account_deposit + id_deposit); }, - _ => assert_reap_events(subs_deposit, id_deposit), } - // reserved balance should be equal to total deposit calculated on the Parachain - assert_eq!(reserved_bal, total_deposit); // Should have at least one ED after in free balance after the reap. assert!(PeopleRococoBalances::free_balance(PeopleRococoSender::get()) >= PEOPLE_ROCOCO_ED); }); } -fn assert_reap_events(subs_deposit: Balance, id_deposit: Balance) { +fn assert_reap_events(subs_deposit: Balance, id_deposit: Balance, id: &Identity) { type RuntimeEvent = ::RuntimeEvent; - assert_expected_events!( - PeopleRococo, - vec![ - RuntimeEvent::Balances(BalancesEvent::Deposit { .. }) => {}, - RuntimeEvent::Balances(BalancesEvent::Endowed { .. }) => {}, - RuntimeEvent::Balances(BalancesEvent::Reserved { who, amount }) => { - who: *who == PeopleRococoSender::get(), - amount: *amount == id_deposit, - }, - RuntimeEvent::Balances(BalancesEvent::Reserved { who, amount }) => { - who: *who == PeopleRococoSender::get(), - amount: *amount == subs_deposit, - }, - RuntimeEvent::IdentityMigrator( - polkadot_runtime_common::identity_migrator::Event::DepositUpdated { - who, identity, subs - }) => { - who: *who == PeopleRococoSender::get(), - identity: *identity == id_deposit, - subs: *subs == subs_deposit, - }, - RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { ..}) => {}, - ] - ); + match id.subs { + Subs::Zero => { + assert_expected_events!( + PeopleRococo, + vec![ + RuntimeEvent::Balances(BalancesEvent::Deposit { .. }) => {}, + RuntimeEvent::Balances(BalancesEvent::Endowed { .. }) => {}, + RuntimeEvent::Balances(BalancesEvent::Reserved { who, amount }) => { + who: *who == PeopleRococoSender::get(), + amount: *amount == id_deposit, + }, + RuntimeEvent::IdentityMigrator( + polkadot_runtime_common::identity_migrator::Event::DepositUpdated { + who, identity, subs + }) => { + who: *who == PeopleRococoSender::get(), + identity: *identity == id_deposit, + subs: *subs == 0, + }, + RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { ..}) => {}, + ] + ); + }, + _ => { + assert_expected_events!( + PeopleRococo, + vec![ + RuntimeEvent::Balances(BalancesEvent::Deposit { .. }) => {}, + RuntimeEvent::Balances(BalancesEvent::Endowed { .. }) => {}, + RuntimeEvent::Balances(BalancesEvent::Reserved { who, amount }) => { + who: *who == PeopleRococoSender::get(), + amount: *amount == id_deposit, + }, + RuntimeEvent::Balances(BalancesEvent::Reserved { who, amount }) => { + who: *who == PeopleRococoSender::get(), + amount: *amount == subs_deposit, + }, + RuntimeEvent::IdentityMigrator( + polkadot_runtime_common::identity_migrator::Event::DepositUpdated { + who, identity, subs + }) => { + who: *who == PeopleRococoSender::get(), + identity: *identity == id_deposit, + subs: *subs == subs_deposit, + }, + RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { ..}) => {}, + ] + ); + }, + } } fn calculate_remote_deposit(bytes: u32, subs: u32) -> Balance { diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index 476e2e6d0cb6..0192da695614 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -1024,7 +1024,7 @@ impl Pallet { Ok(()) } - /// Set subs with zero deposit. Only used for benchmarking that involve `rejig_deposit`. + /// Set sub with zero deposit. Only used for benchmarking that involve `rejig_deposit`. #[cfg(any(feature = "runtime-benchmarks", feature = "xcm-emulator"))] pub fn set_sub_no_deposit(who: &T::AccountId, sub: T::AccountId) -> DispatchResult { use frame_support::BoundedVec; @@ -1035,4 +1035,16 @@ impl Pallet { >(&who, (Zero::zero(), subs)); Ok(()) } + + /// set subs with zero deposit. Only used for benchmarking that involve `rejig_deposit`. + #[cfg(any(feature = "runtime-benchmarks", feature = "xcm-emulator"))] + pub fn set_subs_no_deposit(who: &T::AccountId, subs: Vec) -> DispatchResult { + use frame_support::BoundedVec; + let subs = BoundedVec::<_, T::MaxSubAccounts>::try_from(subs).unwrap(); + SubsOf::::insert::< + &T::AccountId, + (BalanceOf, BoundedVec), + >(&who, (Zero::zero(), subs)); + Ok(()) + } } From 8d2363513bacbdad1c569fe56d4edeb4c7695254 Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Fri, 1 Dec 2023 22:04:49 +0000 Subject: [PATCH 077/102] update comment --- substrate/frame/identity/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index 0192da695614..c3fe842ba010 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -1036,7 +1036,7 @@ impl Pallet { Ok(()) } - /// set subs with zero deposit. Only used for benchmarking that involve `rejig_deposit`. + /// set subs with zero deposit. Only used for XCM emulator testing. #[cfg(any(feature = "runtime-benchmarks", feature = "xcm-emulator"))] pub fn set_subs_no_deposit(who: &T::AccountId, subs: Vec) -> DispatchResult { use frame_support::BoundedVec; From 5861ab54f44c5d31b7ce203c1fa15cc8150a5a93 Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Fri, 1 Dec 2023 22:14:14 +0000 Subject: [PATCH 078/102] total_deposit from subs variant --- .../people-rococo/src/tests/reap_identity.rs | 24 ++++++------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index 9db5ce1d6e51..1f90f03618bc 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -333,23 +333,13 @@ fn assert_reap_parachain(id: &Identity) { PeopleRococo::execute_with(|| { let reserved_bal = PeopleRococoBalances::reserved_balance(PeopleRococoSender::get()); let id_deposit = id_deposit_parachain(&id.para); - let subs_deposit = SubAccountDepositParachain::get(); - - match id.subs { - Subs::Zero => { - assert_reap_events(0, id_deposit, id); - assert_eq!(reserved_bal, id_deposit); - }, - Subs::One => { - assert_reap_events(subs_deposit, id_deposit, id); - assert_eq!(reserved_bal, SubAccountDepositParachain::get() + id_deposit); - }, - Subs::Many(n) => { - let sub_account_deposit = n as u128 * SubAccountDepositParachain::get() as u128; - assert_reap_events(sub_account_deposit, id_deposit, id); - assert_eq!(reserved_bal, sub_account_deposit + id_deposit); - }, - } + let total_deposit = match id.subs { + Subs::Zero => id_deposit, + Subs::One => id_deposit + SubAccountDepositParachain::get(), + Subs::Many(n) => id_deposit + n as u128 * SubAccountDepositParachain::get(), + }; + assert_reap_events(SubAccountDepositParachain::get(), id_deposit, id); + assert_eq!(reserved_bal, total_deposit); // Should have at least one ED after in free balance after the reap. assert!(PeopleRococoBalances::free_balance(PeopleRococoSender::get()) >= PEOPLE_ROCOCO_ED); From 0a44a21d76e063af973586e0e579b76d8d7a0a90 Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Fri, 1 Dec 2023 22:45:15 +0000 Subject: [PATCH 079/102] small cleanups --- .../tests/people/people-rococo/src/tests/reap_identity.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index 1f90f03618bc..25cf69d62cf4 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -306,11 +306,9 @@ fn assert_reap_id_relay(total_deposit: u128, id: &Identity) { assert_eq!(sub_accounts.len(), 0); let reserved_balance = RococoBalances::reserved_balance(RococoRelaySender::get()); - // after reap reserved balance should be 0 assert_eq!(reserved_balance, 0); - let free_bal_after_reap = RococoBalances::free_balance(RococoRelaySender::get()); - // free balance after reap should be greater than before reap + let free_bal_after_reap = RococoBalances::free_balance(RococoRelaySender::get()); assert!(free_bal_after_reap > free_bal_before_reap); match id.subs { From c5f065f55f54a566ca1609b47fe90ef57c944a9e Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Fri, 1 Dec 2023 22:53:24 +0000 Subject: [PATCH 080/102] remove unneeded match --- .../people-rococo/src/tests/reap_identity.rs | 79 +++++++------------ 1 file changed, 27 insertions(+), 52 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index 25cf69d62cf4..5a2b44f30c95 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -336,7 +336,7 @@ fn assert_reap_parachain(id: &Identity) { Subs::One => id_deposit + SubAccountDepositParachain::get(), Subs::Many(n) => id_deposit + n as u128 * SubAccountDepositParachain::get(), }; - assert_reap_events(SubAccountDepositParachain::get(), id_deposit, id); + assert_reap_events(id_deposit, id); assert_eq!(reserved_bal, total_deposit); // Should have at least one ED after in free balance after the reap. @@ -344,58 +344,33 @@ fn assert_reap_parachain(id: &Identity) { }); } -fn assert_reap_events(subs_deposit: Balance, id_deposit: Balance, id: &Identity) { +fn assert_reap_events(id_deposit: Balance, id: &Identity) { type RuntimeEvent = ::RuntimeEvent; - match id.subs { - Subs::Zero => { - assert_expected_events!( - PeopleRococo, - vec![ - RuntimeEvent::Balances(BalancesEvent::Deposit { .. }) => {}, - RuntimeEvent::Balances(BalancesEvent::Endowed { .. }) => {}, - RuntimeEvent::Balances(BalancesEvent::Reserved { who, amount }) => { - who: *who == PeopleRococoSender::get(), - amount: *amount == id_deposit, - }, - RuntimeEvent::IdentityMigrator( - polkadot_runtime_common::identity_migrator::Event::DepositUpdated { - who, identity, subs - }) => { - who: *who == PeopleRococoSender::get(), - identity: *identity == id_deposit, - subs: *subs == 0, - }, - RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { ..}) => {}, - ] - ); - }, - _ => { - assert_expected_events!( - PeopleRococo, - vec![ - RuntimeEvent::Balances(BalancesEvent::Deposit { .. }) => {}, - RuntimeEvent::Balances(BalancesEvent::Endowed { .. }) => {}, - RuntimeEvent::Balances(BalancesEvent::Reserved { who, amount }) => { - who: *who == PeopleRococoSender::get(), - amount: *amount == id_deposit, - }, - RuntimeEvent::Balances(BalancesEvent::Reserved { who, amount }) => { - who: *who == PeopleRococoSender::get(), - amount: *amount == subs_deposit, - }, - RuntimeEvent::IdentityMigrator( - polkadot_runtime_common::identity_migrator::Event::DepositUpdated { - who, identity, subs - }) => { - who: *who == PeopleRococoSender::get(), - identity: *identity == id_deposit, - subs: *subs == subs_deposit, - }, - RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { ..}) => {}, - ] - ); - }, - } + let subs_deposit: Balance = match id.subs { + Subs::Zero => 0_u128, + Subs::One => SubAccountDepositParachain::get(), + Subs::Many(n) => n as u128 * SubAccountDepositParachain::get(), + }; + assert_expected_events!( + PeopleRococo, + vec![ + RuntimeEvent::Balances(BalancesEvent::Deposit { .. }) => {}, + RuntimeEvent::Balances(BalancesEvent::Endowed { .. }) => {}, + RuntimeEvent::Balances(BalancesEvent::Reserved { who, amount }) => { + who: *who == PeopleRococoSender::get(), + amount: *amount == id_deposit, + }, + RuntimeEvent::IdentityMigrator( + polkadot_runtime_common::identity_migrator::Event::DepositUpdated { + who, identity, subs + }) => { + who: *who == PeopleRococoSender::get(), + identity: *identity == id_deposit, + subs: *subs == subs_deposit, + }, + RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { ..}) => {}, + ] + ); } fn calculate_remote_deposit(bytes: u32, subs: u32) -> Balance { From 37845fe75f8c3f7e013e2dba80c34062dce2713b Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Fri, 1 Dec 2023 23:44:33 +0000 Subject: [PATCH 081/102] add all 12 cases --- .../people-rococo/src/tests/reap_identity.rs | 71 ++++++++++++++----- 1 file changed, 54 insertions(+), 17 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index 5a2b44f30c95..1e166fda7459 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -391,13 +391,6 @@ fn calculate_remote_deposit(bytes: u32, subs: u32) -> Balance { .saturating_add(para_existential_deposit.saturating_mul(2)) } -fn assert_relay_para_flow(id: &Identity) { - let total_deposit = set_id_relay(id); - assert_set_id_parachain(id); - assert_reap_id_relay(total_deposit, id); - assert_reap_parachain(id); -} - fn nonsensical_additional() -> BoundedVec<(Data, Data), MaxAdditionalFields> { BoundedVec::try_from(vec![( Data::Raw(b"fOo".to_vec().try_into().unwrap()), @@ -420,16 +413,51 @@ fn meaningful_additional() -> BoundedVec<(Data, Data), MaxAdditionalFields> { .unwrap() } +fn assert_relay_para_flow(id: &Identity) { + let total_deposit = set_id_relay(id); + assert_set_id_parachain(id); + assert_reap_id_relay(total_deposit, id); + assert_reap_parachain(id); +} + #[test] fn on_reap_identity_works_for_minimal_identity() { assert_relay_para_flow(&Identity::new::(false, None, Subs::One)); } +#[test] +fn on_reap_identity_works_for_minimal_identity_with_zero_subs() { + assert_relay_para_flow(&Identity::new::(false, None, Subs::Zero)); +} + +#[test] +fn on_reap_identity_works_for_minimal_identity_with_max_subs() { + assert_relay_para_flow(&Identity::new::( + false, + None, + Subs::Many(MaxSubAccounts::get()), + )); +} + #[test] fn on_reap_identity_works_for_full_identity_no_additional() { assert_relay_para_flow(&Identity::new::(true, None, Subs::One)); } +#[test] +fn on_reap_identity_works_for_full_identity_no_additional_zero_subs() { + assert_relay_para_flow(&Identity::new::(true, None, Subs::Zero)); +} + +#[test] +fn on_reap_identity_works_for_full_identity_no_additional_max_subs() { + assert_relay_para_flow(&Identity::new::( + true, + None, + Subs::Many(MaxSubAccounts::get()), + )); +} + #[test] fn on_reap_identity_works_for_full_identity_nonsense_additional() { assert_relay_para_flow(&Identity::new::( @@ -440,37 +468,46 @@ fn on_reap_identity_works_for_full_identity_nonsense_additional() { } #[test] -fn on_reap_identity_works_for_full_identity_meaningful_additional() { +fn on_reap_identity_works_for_full_identity_nonsense_additional_zero_subs() { assert_relay_para_flow(&Identity::new::( true, - Some(meaningful_additional()), - Subs::One, + Some(nonsensical_additional()), + Subs::Zero, + )); +} + +#[test] +fn on_reap_identity_works_for_full_identity_nonsense_additional_max_subs() { + assert_relay_para_flow(&Identity::new::( + true, + Some(nonsensical_additional()), + Subs::Many(MaxSubAccounts::get()), )); } #[test] -fn on_reap_indentity_works_for_full_identity_with_two_subs() { +fn on_reap_identity_works_for_full_identity_meaningful_additional() { assert_relay_para_flow(&Identity::new::( true, Some(meaningful_additional()), Subs::One, - )) + )); } #[test] -fn on_reap_indentity_works_for_full_identity_with_max_subs() { +fn on_reap_identity_works_for_full_identity_meaningful_additional_zero_subs() { assert_relay_para_flow(&Identity::new::( true, Some(meaningful_additional()), - Subs::Many(MaxSubAccounts::get()), - )) + Subs::Zero, + )); } #[test] -fn on_reap_indentity_works_for_full_identity_with_zero_subs() { +fn on_reap_identity_works_for_full_identity_meaningful_additional_max_subs() { assert_relay_para_flow(&Identity::new::( true, Some(meaningful_additional()), - Subs::Zero, + Subs::Many(MaxSubAccounts::get()), )); } From dca86189b6f318712f7ef889ff5dd1a9609026ac Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Fri, 1 Dec 2023 23:51:56 +0000 Subject: [PATCH 082/102] use default --- .../tests/people/people-rococo/src/tests/reap_identity.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index 1e166fda7459..e0f12122748c 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -75,13 +75,7 @@ impl Identity { pgp_fingerprint: Some(pgp_fingerprint), image: make_data(b"xcm-test.png", full), twitter: make_data(b"@xcm-test", full), - additional: additional.unwrap_or_else(|| { - BoundedVec::try_from(vec![( - Data::Raw(b"foo".to_vec().try_into().unwrap()), - Data::Raw(b"bar".to_vec().try_into().unwrap()), - )]) - .unwrap() - }), + additional: additional.unwrap_or_else(|| BoundedVec::default()), }, para: IdentityInfoParachain { display: make_data(b"xcm-test", full), From 72829cb7d8d7ebe75f1a1df568098c01893c17af Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Sat, 2 Dec 2023 00:29:45 +0000 Subject: [PATCH 083/102] generalise calc deposit --- .../people-rococo/src/tests/reap_identity.rs | 57 ++++++++++++------- 1 file changed, 35 insertions(+), 22 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index e0f12122748c..f6ce38bcef37 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -101,17 +101,28 @@ enum Subs { Many(u32), } -fn id_deposit_parachain(id: &IdentityInfoParachain) -> Balance { - let base_deposit = BasicDepositParachain::get(); - let byte_deposit = - ByteDepositParachain::get() * TryInto::::try_into(id.encoded_size()).unwrap(); - base_deposit + byte_deposit +enum IdentityOn<'a> { + Relay(&'a IdentityInfo), + Para(&'a IdentityInfoParachain), } -fn id_deposit_relaychain(id: &IdentityInfo) -> Balance { - let base_deposit = BasicDeposit::get(); - let byte_deposit = ByteDeposit::get() * TryInto::::try_into(id.encoded_size()).unwrap(); - base_deposit + byte_deposit +impl IdentityOn<'_> { + fn calculate_deposit(self) -> Balance { + match self { + IdentityOn::Relay(id) => { + let base_deposit = BasicDeposit::get(); + let byte_deposit = + ByteDeposit::get() * TryInto::::try_into(id.encoded_size()).unwrap(); + base_deposit + byte_deposit + }, + IdentityOn::Para(id) => { + let base_deposit = BasicDepositParachain::get(); + let byte_deposit = ByteDepositParachain::get() * + TryInto::::try_into(id.encoded_size()).unwrap(); + base_deposit + byte_deposit + }, + } + } } fn set_id_relay(id: &Identity) -> Balance { @@ -153,7 +164,7 @@ fn set_id_relay(id: &Identity) -> Balance { } let reserved_bal = RococoBalances::reserved_balance(RococoRelaySender::get()); - let id_deposit = id_deposit_relaychain(&id.relay); + let id_deposit = IdentityOn::Relay(&id.relay).calculate_deposit(); match id.subs { Subs::Zero => { @@ -168,10 +179,10 @@ fn set_id_relay(id: &Identity) -> Balance { }, ] ); - assert_eq!(reserved_bal, total_deposit); }, Subs::One => { - total_deposit = SubAccountDeposit::get() + id_deposit_relaychain(&id.relay); + total_deposit = + SubAccountDeposit::get() + IdentityOn::Relay(&id.relay).calculate_deposit(); assert_expected_events!( RococoRelay, vec![ @@ -186,11 +197,11 @@ fn set_id_relay(id: &Identity) -> Balance { }, ] ); - assert_eq!(reserved_bal, total_deposit); }, Subs::Many(n) => { - let sub_account_deposit = n as u128 * SubAccountDeposit::get() as u128; - total_deposit = sub_account_deposit + id_deposit_relaychain(&id.relay); + let sub_account_deposit = n as u128 * SubAccountDeposit::get(); + total_deposit = + sub_account_deposit + IdentityOn::Relay(&id.relay).calculate_deposit(); assert_expected_events!( RococoRelay, vec![ @@ -205,16 +216,16 @@ fn set_id_relay(id: &Identity) -> Balance { }, ] ); - // The reserved balance should equal the calculated total deposit - assert_eq!(reserved_bal, total_deposit); }, } + + assert_eq!(reserved_bal, total_deposit); }); total_deposit } fn assert_set_id_parachain(id: &Identity) { - // Set identity and Subs on Parachain with Zero deposit + // Set identity and Subs on Parachain with zero deposit PeopleRococo::execute_with(|| { let free_bal = PeopleRococoBalances::free_balance(PeopleRococoSender::get()); let reserved_bal = PeopleRococoBalances::reserved_balance(PeopleRococoSender::get()); @@ -271,7 +282,8 @@ fn assert_reap_id_relay(total_deposit: u128, id: &Identity) { let reserved_balance = RococoBalances::reserved_balance(RococoRelaySender::get()); match id.subs { - Subs::Zero => assert_eq!(reserved_balance, id_deposit_relaychain(&id.relay)), + Subs::Zero => + assert_eq!(reserved_balance, IdentityOn::Relay(&id.relay).calculate_deposit()), _ => assert_eq!(reserved_balance, total_deposit), } @@ -309,7 +321,8 @@ fn assert_reap_id_relay(total_deposit: u128, id: &Identity) { Subs::Zero => { assert_eq!( free_bal_after_reap, - free_bal_before_reap + id_deposit_relaychain(&id.relay) - remote_deposit + free_bal_before_reap + IdentityOn::Relay(&id.relay).calculate_deposit() - + remote_deposit ); }, _ => { @@ -324,7 +337,7 @@ fn assert_reap_id_relay(total_deposit: u128, id: &Identity) { fn assert_reap_parachain(id: &Identity) { PeopleRococo::execute_with(|| { let reserved_bal = PeopleRococoBalances::reserved_balance(PeopleRococoSender::get()); - let id_deposit = id_deposit_parachain(&id.para); + let id_deposit = IdentityOn::Para(&id.para).calculate_deposit(); let total_deposit = match id.subs { Subs::Zero => id_deposit, Subs::One => id_deposit + SubAccountDepositParachain::get(), @@ -368,7 +381,7 @@ fn assert_reap_events(id_deposit: Balance, id: &Identity) { } fn calculate_remote_deposit(bytes: u32, subs: u32) -> Balance { - // Execute these Rococo Relay Currency functions because this is the runtime context that + // We execute these Rococo Relay Currency functions because this is the runtime context that // this function is called in. let para_basic_deposit = deposit(1, 17) / 100; let para_byte_deposit = deposit(0, 1) / 100; From e3a9f45a4b2545247e857e9dd1c04638504ec426 Mon Sep 17 00:00:00 2001 From: Richard Melkonian <35300528+0xmovses@users.noreply.github.com> Date: Mon, 4 Dec 2023 09:18:02 +0000 Subject: [PATCH 084/102] Tweaks to emulator People testing (#2595) Co-authored-by: joepetrowski --- Cargo.toml | 16 +- .../emulated/common/src/impls.rs | 5 +- .../tests/people/people-rococo/Cargo.toml | 22 +- .../people-rococo/src/tests/reap_identity.rs | 259 ++++++++++-------- .../people-rococo/src/tests/teleport.rs | 21 +- .../runtime/common/src/identity_migrator.rs | 3 +- substrate/frame/identity/Cargo.toml | 2 +- substrate/frame/identity/src/lib.rs | 33 +-- 8 files changed, 197 insertions(+), 164 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4f0f36fc6cb3..28057dedc1f9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -60,14 +60,6 @@ members = [ "cumulus/parachain-template/pallets/template", "cumulus/parachain-template/runtime", "cumulus/parachains/common", - "cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo", - "cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend", - "cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo", - "cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend", - "cumulus/parachains/integration-tests/emulated/tests/people/people-rococo", - "cumulus/parachains/integration-tests/emulated/common", - "cumulus/parachains/integration-tests/emulated/chains/relays/rococo", - "cumulus/parachains/integration-tests/emulated/chains/relays/westend", "cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo", "cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend", "cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-rococo", @@ -75,15 +67,23 @@ members = [ "cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo", "cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal", "cumulus/parachains/integration-tests/emulated/chains/relays/rococo", + "cumulus/parachains/integration-tests/emulated/chains/relays/rococo", + "cumulus/parachains/integration-tests/emulated/chains/relays/westend", "cumulus/parachains/integration-tests/emulated/chains/relays/westend", "cumulus/parachains/integration-tests/emulated/common", + "cumulus/parachains/integration-tests/emulated/common", "cumulus/parachains/integration-tests/emulated/networks/rococo-system", "cumulus/parachains/integration-tests/emulated/networks/rococo-westend-system", "cumulus/parachains/integration-tests/emulated/networks/westend-system", "cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo", + "cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo", "cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend", + "cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend", + "cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo", "cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo", "cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend", + "cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend", + "cumulus/parachains/integration-tests/emulated/tests/people/people-rococo", "cumulus/parachains/pallets/collective-content", "cumulus/parachains/pallets/parachain-info", "cumulus/parachains/pallets/ping", diff --git a/cumulus/parachains/integration-tests/emulated/common/src/impls.rs b/cumulus/parachains/integration-tests/emulated/common/src/impls.rs index 768784ac0670..08134edb3f2e 100644 --- a/cumulus/parachains/integration-tests/emulated/common/src/impls.rs +++ b/cumulus/parachains/integration-tests/emulated/common/src/impls.rs @@ -240,7 +240,7 @@ macro_rules! impl_assert_events_helpers_for_relay_chain { ); } - /// Asserts a XCM message is sent + /// Asserts an XCM program is sent. pub fn assert_xcm_pallet_sent() { $crate::impls::assert_expected_events!( Self, @@ -250,7 +250,8 @@ macro_rules! impl_assert_events_helpers_for_relay_chain { ); } - /// Asserts a XCM from System Parachain is succesfully received and proccessed + /// Asserts an XCM program from a System Parachain is succesfully received and + /// proccessed within expectations. pub fn assert_ump_queue_processed( expected_success: bool, expected_id: Option<$crate::impls::ParaId>, diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/Cargo.toml b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/Cargo.toml index 519e205e6e90..a90282c4afca 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/Cargo.toml @@ -12,22 +12,22 @@ codec = { package = "parity-scale-codec", version = "3.4.0", default-features = assert_matches = "1.5.0" # Substrate -sp-runtime = { path = "../../../../../../../substrate/primitives/runtime", default-features = false} -frame-support = { path = "../../../../../../../substrate/frame/support", default-features = false} -pallet-balances = { path = "../../../../../../../substrate/frame/balances", default-features = false} -pallet-assets = { path = "../../../../../../../substrate/frame/assets", default-features = false} -pallet-asset-conversion = { path = "../../../../../../../substrate/frame/asset-conversion", default-features = false} +sp-runtime = { path = "../../../../../../../substrate/primitives/runtime", default-features = false } +frame-support = { path = "../../../../../../../substrate/frame/support", default-features = false } +pallet-balances = { path = "../../../../../../../substrate/frame/balances", default-features = false } +pallet-assets = { path = "../../../../../../../substrate/frame/assets", default-features = false } +pallet-asset-conversion = { path = "../../../../../../../substrate/frame/asset-conversion", default-features = false } pallet-message-queue = { path = "../../../../../../../substrate/frame/message-queue", default-features = false } -pallet-identity = { path = "../../../../../../../substrate/frame/identity", default-features = false, features =["xcm-emulator"] } +pallet-identity = { path = "../../../../../../../substrate/frame/identity", default-features = false, features = ["xcm-emulator"] } # Polkadot -xcm = { package = "staging-xcm", path = "../../../../../../../polkadot/xcm", default-features = false} -pallet-xcm = { path = "../../../../../../../polkadot/xcm/pallet-xcm", default-features = false} -xcm-executor = { package = "staging-xcm-executor", path = "../../../../../../../polkadot/xcm/xcm-executor", default-features = false } +xcm = { package = "staging-xcm", path = "../../../../../../../polkadot/xcm", default-features = false } +pallet-xcm = { path = "../../../../../../../polkadot/xcm/pallet-xcm", default-features = false } +xcm-executor = { package = "staging-xcm-executor", path = "../../../../../../../polkadot/xcm/xcm-executor", default-features = false } rococo-runtime = { path = "../../../../../../../polkadot/runtime/rococo" } rococo-runtime-constants = { path = "../../../../../../../polkadot/runtime/rococo/constants" } polkadot-primitives = { path = "../../../../../../../polkadot/primitives" } -polkadot-runtime-common = { path = "../../../../../../../polkadot/runtime/common"} +polkadot-runtime-common = { path = "../../../../../../../polkadot/runtime/common" } # Cumulus asset-test-utils = { path = "../../../../../runtimes/assets/test-utils" } @@ -35,4 +35,4 @@ parachains-common = { path = "../../../../../../parachains/common" } people-rococo-runtime = { path = "../../../../../runtimes/people/people-rococo" } emulated-integration-tests-common = { path = "../../../common", default-features = false } penpal-runtime = { path = "../../../../../runtimes/testing/penpal" } -rococo-system-emulated-network ={ path = "../../../networks/rococo-system" } +rococo-system-emulated-network = { path = "../../../networks/rococo-system" } diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index f6ce38bcef37..956a91d95ea6 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -27,8 +27,9 @@ use rococo_runtime::{ }; use rococo_runtime_constants::currency::*; use rococo_system_emulated_network::{ - rococo_emulated_chain::RococoRelayPallet, RococoRelay, RococoRelayReceiver, RococoRelaySender, + rococo_emulated_chain::RococoRelayPallet, RococoRelay, RococoRelaySender, }; + type Balance = u128; type RococoIdentity = ::Identity; type RococoBalances = ::Balances; @@ -97,7 +98,6 @@ impl Identity { #[derive(Clone, Debug)] enum Subs { Zero, - One, Many(u32), } @@ -112,21 +112,35 @@ impl IdentityOn<'_> { IdentityOn::Relay(id) => { let base_deposit = BasicDeposit::get(); let byte_deposit = - ByteDeposit::get() * TryInto::::try_into(id.encoded_size()).unwrap(); + ByteDeposit::get() * TryInto::::try_into(id.encoded_size()).unwrap(); base_deposit + byte_deposit }, IdentityOn::Para(id) => { let base_deposit = BasicDepositParachain::get(); let byte_deposit = ByteDepositParachain::get() * - TryInto::::try_into(id.encoded_size()).unwrap(); + TryInto::::try_into(id.encoded_size()).unwrap(); base_deposit + byte_deposit }, } } } +// Generate an `AccountId32` from a `u32`. +fn account_from_u32(id: u32) -> AccountId32 { + let mut buffer = [255u8; 32]; + let id_bytes = id.to_le_bytes(); + let id_size = id_bytes.len(); + for ii in 0..buffer.len() / id_size { + let s = ii * id_size; + let e = s + id_size; + buffer[s..e].clone_from_slice(&id_bytes[..]); + } + AccountId32::new(buffer) +} + +// Set up the Relay Chain with an identity. fn set_id_relay(id: &Identity) -> Balance { - let mut total_deposit = 0_u128; + let mut total_deposit: Balance = 0; // Set identity and Subs on Relay Chain RococoRelay::execute_with(|| { @@ -139,21 +153,12 @@ fn set_id_relay(id: &Identity) -> Balance { match id.subs { Subs::Zero => {}, - Subs::One => { - assert_ok!(RococoIdentity::set_subs( - RococoOrigin::signed(RococoRelaySender::get()), - vec![( - RococoRelayReceiver::get(), - Data::Raw(vec![1_u8; 1].try_into().unwrap()), - )], - )); - }, Subs::Many(n) => { - let mut subs = Vec::new(); - for i in 0..n { + let mut subs = Vec::with_capacity(n.try_into().unwrap()); + for ii in 0..n { subs.push(( - AccountId32::new([i as u8 + 1; 32]), - Data::Raw(vec![i as u8; 1].try_into().unwrap()), + account_from_u32(ii), + Data::Raw(b"name".to_vec().try_into().unwrap()), )); } assert_ok!(RococoIdentity::set_subs( @@ -180,26 +185,8 @@ fn set_id_relay(id: &Identity) -> Balance { ] ); }, - Subs::One => { - total_deposit = - SubAccountDeposit::get() + IdentityOn::Relay(&id.relay).calculate_deposit(); - assert_expected_events!( - RococoRelay, - vec![ - RuntimeEvent::Identity(IdentityEvent::IdentitySet { .. }) => {}, - RuntimeEvent::Balances(BalancesEvent::Reserved { who, amount }) => { - who: *who == RococoRelaySender::get(), - amount: *amount == id_deposit, - }, - RuntimeEvent::Balances(BalancesEvent::Reserved { who, amount }) => { - who: *who == RococoRelaySender::get(), - amount: *amount == SubAccountDeposit::get(), - }, - ] - ); - }, Subs::Many(n) => { - let sub_account_deposit = n as u128 * SubAccountDeposit::get(); + let sub_account_deposit = n as Balance * SubAccountDeposit::get(); total_deposit = sub_account_deposit + IdentityOn::Relay(&id.relay).calculate_deposit(); assert_expected_events!( @@ -224,6 +211,7 @@ fn set_id_relay(id: &Identity) -> Balance { total_deposit } +// Set up the parachain with an identity and (maybe) sub accounts, but with zero deposits. fn assert_set_id_parachain(id: &Identity) { // Set identity and Subs on Parachain with zero deposit PeopleRococo::execute_with(|| { @@ -240,16 +228,13 @@ fn assert_set_id_parachain(id: &Identity) { match id.subs { Subs::Zero => {}, - Subs::One => { - assert_ok!(PeopleRococoIdentity::set_sub_no_deposit( - &PeopleRococoSender::get(), - AccountId32::new([1_u8; 32]), - )); - }, Subs::Many(n) => { - let mut subs = Vec::new(); - for i in 0..n { - subs.push(AccountId32::new([i as u8 + 1; 32])); + let mut subs = Vec::with_capacity(n.try_into().unwrap()); + for ii in 0..n { + subs.push(( + account_from_u32(ii), + Data::Raw(b"name".to_vec().try_into().unwrap()), + )); } assert_ok!(PeopleRococoIdentity::set_subs_no_deposit( &PeopleRococoSender::get(), @@ -258,8 +243,6 @@ fn assert_set_id_parachain(id: &Identity) { }, } - // No events get triggered when calling set_sub_no_deposit - // No amount should be reserved as deposit amounts are set to 0. let reserved_bal = PeopleRococoBalances::reserved_balance(PeopleRococoSender::get()); assert_eq!(reserved_bal, 0); @@ -269,23 +252,19 @@ fn assert_set_id_parachain(id: &Identity) { match id.subs { Subs::Zero => assert_eq!(sub_accounts.len(), 0), - Subs::One => assert_eq!(sub_accounts.len(), 1), Subs::Many(n) => assert_eq!(sub_accounts.len(), n as usize), } }); } -fn assert_reap_id_relay(total_deposit: u128, id: &Identity) { +// Reap the identity on the Relay Chain and assert that the correct things happen there. +fn assert_reap_id_relay(total_deposit: Balance, id: &Identity) { RococoRelay::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; let free_bal_before_reap = RococoBalances::free_balance(RococoRelaySender::get()); let reserved_balance = RococoBalances::reserved_balance(RococoRelaySender::get()); - match id.subs { - Subs::Zero => - assert_eq!(reserved_balance, IdentityOn::Relay(&id.relay).calculate_deposit()), - _ => assert_eq!(reserved_balance, total_deposit), - } + assert_eq!(reserved_balance, total_deposit); assert_ok!(RococoIdentityMigrator::reap_identity( RococoOrigin::root(), @@ -294,54 +273,56 @@ fn assert_reap_id_relay(total_deposit: u128, id: &Identity) { let remote_deposit = match id.subs { Subs::Zero => calculate_remote_deposit(id.relay.encoded_size() as u32, 0), - Subs::One => calculate_remote_deposit(id.relay.encoded_size() as u32, 1), Subs::Many(n) => calculate_remote_deposit(id.relay.encoded_size() as u32, n), }; assert_expected_events!( RococoRelay, vec![ + // `reap_identity` sums the identity and subs deposits and unreserves them in one + // call. Therefore, we only expect one `Unreserved` event. RuntimeEvent::Balances(BalancesEvent::Unreserved { who, amount }) => { who: *who == RococoRelaySender::get(), amount: *amount == total_deposit, }, + RuntimeEvent::IdentityMigrator( + polkadot_runtime_common::identity_migrator::Event::IdentityReaped { + who, + }) => { + who: *who == PeopleRococoSender::get(), + }, ] ); + // Identity should be gone. assert!(PeopleRococoIdentity::identity(&RococoRelaySender::get()).is_none()); + + // Subs should be gone. let (_, sub_accounts) = RococoIdentity::subs_of(&RococoRelaySender::get()); assert_eq!(sub_accounts.len(), 0); let reserved_balance = RococoBalances::reserved_balance(RococoRelaySender::get()); assert_eq!(reserved_balance, 0); + // Free balance should be greater (i.e. the teleport should work even if 100% of an + // account's balance is reserved for Identity). let free_bal_after_reap = RococoBalances::free_balance(RococoRelaySender::get()); assert!(free_bal_after_reap > free_bal_before_reap); - match id.subs { - Subs::Zero => { - assert_eq!( - free_bal_after_reap, - free_bal_before_reap + IdentityOn::Relay(&id.relay).calculate_deposit() - - remote_deposit - ); - }, - _ => { - assert_eq!( - free_bal_after_reap, - free_bal_before_reap + total_deposit - remote_deposit - ); - }, - } + // Implicit: total_deposit > remote_deposit. As in, accounts should always have enough + // reserved for the parachain deposit. + assert_eq!(free_bal_after_reap, free_bal_before_reap + total_deposit - remote_deposit); }); } + +// Reaping the identity on the Relay Chain will have sent an XCM program to the parachain. Ensure +// that everything happens as expected. fn assert_reap_parachain(id: &Identity) { PeopleRococo::execute_with(|| { let reserved_bal = PeopleRococoBalances::reserved_balance(PeopleRococoSender::get()); let id_deposit = IdentityOn::Para(&id.para).calculate_deposit(); let total_deposit = match id.subs { Subs::Zero => id_deposit, - Subs::One => id_deposit + SubAccountDepositParachain::get(), - Subs::Many(n) => id_deposit + n as u128 * SubAccountDepositParachain::get(), + Subs::Many(n) => id_deposit + n as Balance * SubAccountDepositParachain::get(), }; assert_reap_events(id_deposit, id); assert_eq!(reserved_bal, total_deposit); @@ -351,38 +332,74 @@ fn assert_reap_parachain(id: &Identity) { }); } +// Assert the events that should happen on the parachain upon reaping an identity on the Relay +// Chain. fn assert_reap_events(id_deposit: Balance, id: &Identity) { type RuntimeEvent = ::RuntimeEvent; - let subs_deposit: Balance = match id.subs { - Subs::Zero => 0_u128, - Subs::One => SubAccountDepositParachain::get(), - Subs::Many(n) => n as u128 * SubAccountDepositParachain::get(), + match id.subs { + Subs::Zero => { + assert_expected_events!( + PeopleRococo, + vec![ + // Deposit and Endowed from teleport + RuntimeEvent::Balances(BalancesEvent::Deposit { .. }) => {}, + RuntimeEvent::Balances(BalancesEvent::Endowed { .. }) => {}, + // Amount reserved for identity info + RuntimeEvent::Balances(BalancesEvent::Reserved { who, amount }) => { + who: *who == PeopleRococoSender::get(), + amount: *amount == id_deposit, + }, + // Confirmation from Migrator with individual identity and subs deposits + RuntimeEvent::IdentityMigrator( + polkadot_runtime_common::identity_migrator::Event::DepositUpdated { + who, identity, subs + }) => { + who: *who == PeopleRococoSender::get(), + identity: *identity == id_deposit, + subs: *subs == 0, + }, + RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { ..}) => {}, + ] + ); + }, + Subs::Many(n) => { + let subs_deposit = n as Balance * SubAccountDepositParachain::get(); + assert_expected_events!( + PeopleRococo, + vec![ + // Deposit and Endowed from teleport + RuntimeEvent::Balances(BalancesEvent::Deposit { .. }) => {}, + RuntimeEvent::Balances(BalancesEvent::Endowed { .. }) => {}, + // Amount reserved for identity info + RuntimeEvent::Balances(BalancesEvent::Reserved { who, amount }) => { + who: *who == PeopleRococoSender::get(), + amount: *amount == id_deposit, + }, + // Amount reserved for subs + RuntimeEvent::Balances(BalancesEvent::Reserved { who, amount }) => { + who: *who == PeopleRococoSender::get(), + amount: *amount == subs_deposit, + }, + // Confirmation from Migrator with individual identity and subs deposits + RuntimeEvent::IdentityMigrator( + polkadot_runtime_common::identity_migrator::Event::DepositUpdated { + who, identity, subs + }) => { + who: *who == PeopleRococoSender::get(), + identity: *identity == id_deposit, + subs: *subs == subs_deposit, + }, + RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { ..}) => {}, + ] + ); + }, }; - assert_expected_events!( - PeopleRococo, - vec![ - RuntimeEvent::Balances(BalancesEvent::Deposit { .. }) => {}, - RuntimeEvent::Balances(BalancesEvent::Endowed { .. }) => {}, - RuntimeEvent::Balances(BalancesEvent::Reserved { who, amount }) => { - who: *who == PeopleRococoSender::get(), - amount: *amount == id_deposit, - }, - RuntimeEvent::IdentityMigrator( - polkadot_runtime_common::identity_migrator::Event::DepositUpdated { - who, identity, subs - }) => { - who: *who == PeopleRococoSender::get(), - identity: *identity == id_deposit, - subs: *subs == subs_deposit, - }, - RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { ..}) => {}, - ] - ); } +// Duplicate of the impl of `ToParachainIdentityReaper` in the Rococo runtime. fn calculate_remote_deposit(bytes: u32, subs: u32) -> Balance { - // We execute these Rococo Relay Currency functions because this is the runtime context that - // this function is called in. + // Note: These `deposit` functions and `EXISTENTIAL_DEPOSIT` correspond to the Relay Chain's. + // Pulled in: use rococo_runtime_constants::currency::*; let para_basic_deposit = deposit(1, 17) / 100; let para_byte_deposit = deposit(0, 1) / 100; let para_sub_account_deposit = deposit(1, 53) / 100; @@ -398,6 +415,8 @@ fn calculate_remote_deposit(bytes: u32, subs: u32) -> Balance { .saturating_add(para_existential_deposit.saturating_mul(2)) } +// Represent some `additional` data that would not be migrated to the parachain. The encoded size, +// and thus the byte deposit, should decrease. fn nonsensical_additional() -> BoundedVec<(Data, Data), MaxAdditionalFields> { BoundedVec::try_from(vec![( Data::Raw(b"fOo".to_vec().try_into().unwrap()), @@ -406,6 +425,7 @@ fn nonsensical_additional() -> BoundedVec<(Data, Data), MaxAdditionalFields> { .unwrap() } +// Represent some `additional` data that will be migrated to the parachain as first-class fields. fn meaningful_additional() -> BoundedVec<(Data, Data), MaxAdditionalFields> { BoundedVec::try_from(vec![ ( @@ -420,6 +440,7 @@ fn meaningful_additional() -> BoundedVec<(Data, Data), MaxAdditionalFields> { .unwrap() } +// Execute a single test case. fn assert_relay_para_flow(id: &Identity) { let total_deposit = set_id_relay(id); assert_set_id_parachain(id); @@ -427,16 +448,18 @@ fn assert_relay_para_flow(id: &Identity) { assert_reap_parachain(id); } -#[test] -fn on_reap_identity_works_for_minimal_identity() { - assert_relay_para_flow(&Identity::new::(false, None, Subs::One)); -} +// Tests with empty `IdentityInfo`. #[test] fn on_reap_identity_works_for_minimal_identity_with_zero_subs() { assert_relay_para_flow(&Identity::new::(false, None, Subs::Zero)); } +#[test] +fn on_reap_identity_works_for_minimal_identity() { + assert_relay_para_flow(&Identity::new::(false, None, Subs::Many(1))); +} + #[test] fn on_reap_identity_works_for_minimal_identity_with_max_subs() { assert_relay_para_flow(&Identity::new::( @@ -446,16 +469,18 @@ fn on_reap_identity_works_for_minimal_identity_with_max_subs() { )); } -#[test] -fn on_reap_identity_works_for_full_identity_no_additional() { - assert_relay_para_flow(&Identity::new::(true, None, Subs::One)); -} +// Tests with full `IdentityInfo`. #[test] fn on_reap_identity_works_for_full_identity_no_additional_zero_subs() { assert_relay_para_flow(&Identity::new::(true, None, Subs::Zero)); } +#[test] +fn on_reap_identity_works_for_full_identity_no_additional() { + assert_relay_para_flow(&Identity::new::(true, None, Subs::Many(1))); +} + #[test] fn on_reap_identity_works_for_full_identity_no_additional_max_subs() { assert_relay_para_flow(&Identity::new::( @@ -465,21 +490,23 @@ fn on_reap_identity_works_for_full_identity_no_additional_max_subs() { )); } +// Tests with full `IdentityInfo` and `additional` fields that will _not_ be migrated. + #[test] -fn on_reap_identity_works_for_full_identity_nonsense_additional() { +fn on_reap_identity_works_for_full_identity_nonsense_additional_zero_subs() { assert_relay_para_flow(&Identity::new::( true, Some(nonsensical_additional()), - Subs::One, + Subs::Zero, )); } #[test] -fn on_reap_identity_works_for_full_identity_nonsense_additional_zero_subs() { +fn on_reap_identity_works_for_full_identity_nonsense_additional() { assert_relay_para_flow(&Identity::new::( true, Some(nonsensical_additional()), - Subs::Zero, + Subs::Many(1), )); } @@ -492,21 +519,23 @@ fn on_reap_identity_works_for_full_identity_nonsense_additional_max_subs() { )); } +// Tests with full `IdentityInfo` and `additional` fields that will be migrated. + #[test] -fn on_reap_identity_works_for_full_identity_meaningful_additional() { +fn on_reap_identity_works_for_full_identity_meaningful_additional_zero_subs() { assert_relay_para_flow(&Identity::new::( true, Some(meaningful_additional()), - Subs::One, + Subs::Zero, )); } #[test] -fn on_reap_identity_works_for_full_identity_meaningful_additional_zero_subs() { +fn on_reap_identity_works_for_full_identity_meaningful_additional() { assert_relay_para_flow(&Identity::new::( true, Some(meaningful_additional()), - Subs::Zero, + Subs::Many(1), )); } diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs index 981142ed92c6..4bb3daf3f995 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs @@ -182,11 +182,11 @@ fn limited_teleport_native_assets_back_from_system_para_to_relay_works() { let beneficiary_id = RococoReceiver::get(); let assets = (Parent, amount_to_send).into(); - // set sender to PeopleRococoReceiver because they just received - // assets from limited_teleport call above. PeopleRococo has - // no balances on Genesis. + // Fund a sender + PeopleRococo::fund_accounts(vec![(PeopleRococoSender::get().into(), ROCOCO_ED * 2_000u128)]); + let test_args = TestContext { - sender: PeopleRococoReceiver::get(), + sender: PeopleRococoSender::get(), receiver: RococoReceiver::get(), args: para_test_args(destination, beneficiary_id, amount_to_send, assets, None, 0), }; @@ -226,6 +226,9 @@ fn limited_teleport_native_assets_from_system_para_to_relay_fails() { let beneficiary_id = RococoReceiver::get().into(); let assets = (Parent, amount_to_send).into(); + // Fund a sender + PeopleRococo::fund_accounts(vec![(PeopleRococoSender::get().into(), ROCOCO_ED * 2_000u128)]); + let test_args = TestContext { sender: PeopleRococoSender::get(), receiver: RococoReceiver::get(), @@ -234,23 +237,25 @@ fn limited_teleport_native_assets_from_system_para_to_relay_fails() { let mut test = SystemParaToRelayTest::new(test_args); + let sender_balance_before = test.sender.balance; let receiver_balance_before = test.receiver.balance; test.set_assertion::(para_origin_assertions); test.set_assertion::(relay_dest_assertions_fail); test.set_dispatchable::(system_para_limited_teleport_assets); + test.assert(); + let sender_balance_after = test.sender.balance; let receiver_balance_after = test.receiver.balance; - let _delivery_fees = PeopleRococo::execute_with(|| { + let delivery_fees = PeopleRococo::execute_with(|| { xcm_helpers::transfer_assets_delivery_fees::< ::XcmSender, >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) }); - // We don't check of sender's balance is reduced because they have no balance - // at genesis. - + // Sender's balance is reduced + assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); // Receiver's balance does not change assert_eq!(receiver_balance_after, receiver_balance_before); } diff --git a/polkadot/runtime/common/src/identity_migrator.rs b/polkadot/runtime/common/src/identity_migrator.rs index cc2c3ce7773c..0dfb03b06ba3 100644 --- a/polkadot/runtime/common/src/identity_migrator.rs +++ b/polkadot/runtime/common/src/identity_migrator.rs @@ -271,7 +271,8 @@ mod benchmarks { let _ = Identity::::set_identity_no_deposit(&target, info.clone()); let sub_account: T::AccountId = account("sub", 0, SEED); - let _ = Identity::::set_sub_no_deposit(&target, sub_account.clone()); + let name = Data::Raw(b"benchsub".to_vec().try_into().unwrap()); + let _ = Identity::::set_subs_no_deposit(&target, vec![(sub_account.clone(), name)]); // expected deposits let expected_id_deposit = ::BasicDeposit::get() diff --git a/substrate/frame/identity/Cargo.toml b/substrate/frame/identity/Cargo.toml index 8e5609a9ffed..5ade5dd1f615 100644 --- a/substrate/frame/identity/Cargo.toml +++ b/substrate/frame/identity/Cargo.toml @@ -28,7 +28,7 @@ pallet-balances = { path = "../balances" } sp-core = { path = "../../primitives/core" } [features] -default = [ "std" ] +default = ["std"] xcm-emulator = [] std = [ diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index c3fe842ba010..ef827d91ede4 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -1005,8 +1005,7 @@ impl Pallet { Ok((new_id_deposit, new_subs_deposit)) } - /// Set an identity with zero deposit. Used for benchmarking and XCM emulator tests, - /// that involve + /// Set an identity with zero deposit. Used for benchmarking and XCM emulator tests that involve /// `rejig_deposit`. #[cfg(any(feature = "runtime-benchmarks", feature = "xcm-emulator"))] pub fn set_identity_no_deposit( @@ -1024,27 +1023,25 @@ impl Pallet { Ok(()) } - /// Set sub with zero deposit. Only used for benchmarking that involve `rejig_deposit`. - #[cfg(any(feature = "runtime-benchmarks", feature = "xcm-emulator"))] - pub fn set_sub_no_deposit(who: &T::AccountId, sub: T::AccountId) -> DispatchResult { - use frame_support::BoundedVec; - let subs = BoundedVec::<_, T::MaxSubAccounts>::try_from(vec![sub]).unwrap(); - SubsOf::::insert::< - &T::AccountId, - (BalanceOf, BoundedVec), - >(&who, (Zero::zero(), subs)); - Ok(()) - } - - /// set subs with zero deposit. Only used for XCM emulator testing. + /// Set subs with zero deposit and default name. Only used for benchmarking that involve + /// `rejig_deposit`. #[cfg(any(feature = "runtime-benchmarks", feature = "xcm-emulator"))] - pub fn set_subs_no_deposit(who: &T::AccountId, subs: Vec) -> DispatchResult { + pub fn set_subs_no_deposit( + who: &T::AccountId, + subs: Vec<(T::AccountId, Data)>, + ) -> DispatchResult { use frame_support::BoundedVec; - let subs = BoundedVec::<_, T::MaxSubAccounts>::try_from(subs).unwrap(); + let mut sub_accounts = BoundedVec::::default(); + for (sub, name) in subs { + >::insert(&sub, (who.clone(), name)); + sub_accounts + .try_push(sub) + .expect("benchmark should not pass more than T::MaxSubAccounts"); + } SubsOf::::insert::< &T::AccountId, (BalanceOf, BoundedVec), - >(&who, (Zero::zero(), subs)); + >(&who, (Zero::zero(), sub_accounts)); Ok(()) } } From 6b015f94b0c30d62ee91c9a8991dc7661f585e2e Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Mon, 4 Dec 2023 14:59:54 +0000 Subject: [PATCH 085/102] integrate aguirre feedback --- .../people-rococo/src/tests/reap_identity.rs | 67 +++++++++++++++---- 1 file changed, 55 insertions(+), 12 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index 956a91d95ea6..9253b1bac087 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -13,6 +13,38 @@ // See the License for the specific language governing permissions and // limitations under the License. +//! # OnReapIdentity Tests +//! +//! This file contains the test cases for migrating Identity data away from the Rococo Relay +//! chain and to the PeopleRococo parachain, with zero cost incurred to the user. This migration +//! is part of the broader Minimal Relay effort: +//! https://github.com/polkadot-fellows/RFCs/blob/main/text/0032-minimal-relay.md +//! +//! ## Overview +//! +//! The tests validate the robustness and correctness of the `OnReapIdentityHandler` +//! ensuring that it behaves as expected in various scenarios. Key aspects tested include: +//! +//! - **Identity Creation**: Verifying that identities can be created with the correct +//! information and handling of deposits. +//! - **Sub-Account Management**: Testing the functionality for managing sub-accounts, including +//! creation and deposit requirements. +//! - **Cross-Chain Functionality**: Ensuring that identities can be managed seamlessly across the +//! Rococo Relay Chain and the PeopleRococo Parachain, including testing cross-chain interactions +//! and migrations. +//! - **Deposit Handling**: Confirming that deposits are correctly handled, reserved, and released +//! in various scenarios, including identity reaping. +//! +//! ### Test Scenarios +//! +//! The tests are categorized into several scenarios, each focusing on different aspects of the +//! Identity Management Module: +//! +//! - Minimal identity information with varying numbers of sub-accounts. +//! - Full identity information with and without additional fields, again with varying numbers of +//! sub-accounts. +//! - Reaping (removal) of identities and the correct release and transfer of associated deposits. + use crate::*; use frame_support::BoundedVec; use pallet_balances::Event as BalancesEvent; @@ -125,15 +157,26 @@ impl IdentityOn<'_> { } } -// Generate an `AccountId32` from a `u32`. +/// Generate an `AccountId32` from a `u32`. +/// This creates a 32-byte array, initially filled with `255`, and then repeatedly fills it +/// with the 4-byte little-endian representation of the `u32` value, until the array is full. +/// +/// **Example**: +/// +/// `account_from_u32(5)` will return an `AccountId32` with the bytes +/// `[0, 5, 0, 0, 0, 0, 0, 0, 0, 5 ... ]` (repeated 8 times) +/// +/// **Note** +/// +/// This is only used for testing and is not intended for production use. fn account_from_u32(id: u32) -> AccountId32 { let mut buffer = [255u8; 32]; let id_bytes = id.to_le_bytes(); let id_size = id_bytes.len(); for ii in 0..buffer.len() / id_size { - let s = ii * id_size; - let e = s + id_size; - buffer[s..e].clone_from_slice(&id_bytes[..]); + let start = ii * id_size; + let end = start + id_size; + buffer[start..end].clone_from_slice(&id_bytes[..]); } AccountId32::new(buffer) } @@ -168,7 +211,7 @@ fn set_id_relay(id: &Identity) -> Balance { }, } - let reserved_bal = RococoBalances::reserved_balance(RococoRelaySender::get()); + let reserved_balance = RococoBalances::reserved_balance(RococoRelaySender::get()); let id_deposit = IdentityOn::Relay(&id.relay).calculate_deposit(); match id.subs { @@ -206,7 +249,7 @@ fn set_id_relay(id: &Identity) -> Balance { }, } - assert_eq!(reserved_bal, total_deposit); + assert_eq!(reserved_balance, total_deposit); }); total_deposit } @@ -216,10 +259,10 @@ fn assert_set_id_parachain(id: &Identity) { // Set identity and Subs on Parachain with zero deposit PeopleRococo::execute_with(|| { let free_bal = PeopleRococoBalances::free_balance(PeopleRococoSender::get()); - let reserved_bal = PeopleRococoBalances::reserved_balance(PeopleRococoSender::get()); + let reserved_balance = PeopleRococoBalances::reserved_balance(PeopleRococoSender::get()); //total balance at Genesis should be zero - assert_eq!(reserved_bal + free_bal, 0); + assert_eq!(reserved_balance + free_bal, 0); assert_ok!(PeopleRococoIdentity::set_identity_no_deposit( &PeopleRococoSender::get(), @@ -244,8 +287,8 @@ fn assert_set_id_parachain(id: &Identity) { } // No amount should be reserved as deposit amounts are set to 0. - let reserved_bal = PeopleRococoBalances::reserved_balance(PeopleRococoSender::get()); - assert_eq!(reserved_bal, 0); + let reserved_balance = PeopleRococoBalances::reserved_balance(PeopleRococoSender::get()); + assert_eq!(reserved_balance, 0); assert!(PeopleRococoIdentity::identity(&PeopleRococoSender::get()).is_some()); let (_, sub_accounts) = PeopleRococoIdentity::subs_of(&PeopleRococoSender::get()); @@ -318,14 +361,14 @@ fn assert_reap_id_relay(total_deposit: Balance, id: &Identity) { // that everything happens as expected. fn assert_reap_parachain(id: &Identity) { PeopleRococo::execute_with(|| { - let reserved_bal = PeopleRococoBalances::reserved_balance(PeopleRococoSender::get()); + let reserved_balance = PeopleRococoBalances::reserved_balance(PeopleRococoSender::get()); let id_deposit = IdentityOn::Para(&id.para).calculate_deposit(); let total_deposit = match id.subs { Subs::Zero => id_deposit, Subs::Many(n) => id_deposit + n as Balance * SubAccountDepositParachain::get(), }; assert_reap_events(id_deposit, id); - assert_eq!(reserved_bal, total_deposit); + assert_eq!(reserved_balance, total_deposit); // Should have at least one ED after in free balance after the reap. assert!(PeopleRococoBalances::free_balance(PeopleRococoSender::get()) >= PEOPLE_ROCOCO_ED); From bc86d0d1881f6687f673632a64acea9514cd5a78 Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Mon, 4 Dec 2023 15:01:00 +0000 Subject: [PATCH 086/102] typo --- .../tests/people/people-rococo/src/tests/reap_identity.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index 9253b1bac087..541e4b46032a 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -164,7 +164,7 @@ impl IdentityOn<'_> { /// **Example**: /// /// `account_from_u32(5)` will return an `AccountId32` with the bytes -/// `[0, 5, 0, 0, 0, 0, 0, 0, 0, 5 ... ]` (repeated 8 times) +/// `[0, 5, 0, 0, 0, 0, 0, 0, 0, 5 ... ]` /// /// **Note** /// From 84fa2b107a44f11cd43342b8d1cedca944910059 Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Mon, 4 Dec 2023 15:07:57 +0000 Subject: [PATCH 087/102] improve doc comment --- .../tests/people/people-rococo/src/tests/reap_identity.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index 541e4b46032a..841f4c72c093 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -16,8 +16,8 @@ //! # OnReapIdentity Tests //! //! This file contains the test cases for migrating Identity data away from the Rococo Relay -//! chain and to the PeopleRococo parachain, with zero cost incurred to the user. This migration -//! is part of the broader Minimal Relay effort: +//! chain and to the PeopleRococo parachain. This migration is part of the broader Minimal Relay +//! effort: //! https://github.com/polkadot-fellows/RFCs/blob/main/text/0032-minimal-relay.md //! //! ## Overview From ee7c5a9a2fc03592fe5927355a5975ea964cfad8 Mon Sep 17 00:00:00 2001 From: Richard Melkonian <35300528+0xmovses@users.noreply.github.com> Date: Mon, 4 Dec 2023 17:12:59 +0000 Subject: [PATCH 088/102] Update cumulus/parachains/integration-tests/emulated/common/src/lib.rs Co-authored-by: Liam Aharon --- cumulus/parachains/integration-tests/emulated/common/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cumulus/parachains/integration-tests/emulated/common/src/lib.rs b/cumulus/parachains/integration-tests/emulated/common/src/lib.rs index 447df8332928..dd89c9b9aa1b 100644 --- a/cumulus/parachains/integration-tests/emulated/common/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/common/src/lib.rs @@ -86,7 +86,7 @@ pub fn get_host_config() -> HostConfiguration { } } -/// Returns a `TestArgs` instance to be used for the Relay Chain across integration tests +/// Returns a [`TestArgs`] instance to be used for the Relay Chain across integration tests pub fn relay_test_args( dest: MultiLocation, beneficiary_id: AccountId32, From 342165f00d59db8974e7e161f875435701438358 Mon Sep 17 00:00:00 2001 From: Richard Melkonian <35300528+0xmovses@users.noreply.github.com> Date: Mon, 4 Dec 2023 17:13:07 +0000 Subject: [PATCH 089/102] Update cumulus/parachains/integration-tests/emulated/common/src/lib.rs Co-authored-by: Liam Aharon --- cumulus/parachains/integration-tests/emulated/common/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cumulus/parachains/integration-tests/emulated/common/src/lib.rs b/cumulus/parachains/integration-tests/emulated/common/src/lib.rs index dd89c9b9aa1b..3a991149e29d 100644 --- a/cumulus/parachains/integration-tests/emulated/common/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/common/src/lib.rs @@ -103,7 +103,7 @@ pub fn relay_test_args( } } -/// Returns a `TestArgs` instance to be used by parachains across integration tests +/// Returns a [`TestArgs`] instance to be used by parachains across integration tests pub fn para_test_args( dest: MultiLocation, beneficiary_id: AccountId32, From cb3f892f75768fadd3cf8fc04e7586e4d553523b Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Mon, 4 Dec 2023 17:29:49 +0000 Subject: [PATCH 090/102] impl relay para methods for TestArgs --- cumulus/xcm/xcm-emulator/src/lib.rs | 41 ++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/cumulus/xcm/xcm-emulator/src/lib.rs b/cumulus/xcm/xcm-emulator/src/lib.rs index f2e4ff397c45..52c8344c1f8a 100644 --- a/cumulus/xcm/xcm-emulator/src/lib.rs +++ b/cumulus/xcm/xcm-emulator/src/lib.rs @@ -59,9 +59,13 @@ pub use polkadot_runtime_parachains::inclusion::{AggregateMessageOrigin, UmpQueu // Polkadot pub use polkadot_parachain_primitives::primitives::RelayChainBlockNumber; -pub use xcm::v3::prelude::{ - Ancestor, MultiAssets, MultiLocation, Parachain as ParachainJunction, Parent, WeightLimit, - XcmHash, X1, +use sp_core::crypto::AccountId32; +pub use xcm::{ + prelude::{AccountId32 as AccountId32Junction, Here}, + v3::prelude::{ + Ancestor, MultiAssets, MultiLocation, Parachain as ParachainJunction, Parent, WeightLimit, + XcmHash, X1, + }, }; pub use xcm_executor::traits::ConvertLocation; @@ -1431,6 +1435,37 @@ pub struct TestArgs { pub weight_limit: WeightLimit, } +impl TestArgs { + pub fn new_relay(dest: MultiLocation, beneficiary_id: AccountId32, amount: Balance) -> Self { + Self { + dest, + beneficiary: AccountId32Junction { network: None, id: beneficiary_id.into() }.into(), + amount, + assets: (Here, amount).into(), + asset_id: None, + fee_asset_item: 0, + weight_limit: WeightLimit::Unlimited, + } + } + + pub fn new_parachain( + dest: MultiLocation, + beneficiary_id: AccountId32, + amount: Balance, + asset_id: Option, + ) -> Self { + Self { + dest, + beneficiary: AccountId32Junction { network: None, id: beneficiary_id.into() }.into(), + amount, + assets, + asset_id, + fee_asset_item, + weight_limit: WeightLimit::Unlimited, + } + } +} + /// Auxiliar struct to help creating a new `Test` instance pub struct TestContext { pub sender: AccountIdOf, From 558217863e10c5dedde3664b2b02684df5b6917b Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Mon, 4 Dec 2023 18:18:27 +0000 Subject: [PATCH 091/102] refactors --- .../emulated/common/src/lib.rs | 37 ------------------- .../src/tests/reserve_transfer.rs | 9 ++--- .../asset-hub-rococo/src/tests/teleport.rs | 15 ++++---- .../src/tests/reserve_transfer.rs | 9 ++--- .../asset-hub-westend/src/tests/teleport.rs | 13 +++---- .../people-rococo/src/tests/reap_identity.rs | 8 +--- .../people-rococo/src/tests/teleport.rs | 7 ++-- cumulus/xcm/xcm-emulator/src/lib.rs | 6 ++- substrate/primitives/core/src/crypto.rs | 22 +++++++++++ 9 files changed, 53 insertions(+), 73 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/common/src/lib.rs b/cumulus/parachains/integration-tests/emulated/common/src/lib.rs index 3a991149e29d..d88599a22fc8 100644 --- a/cumulus/parachains/integration-tests/emulated/common/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/common/src/lib.rs @@ -86,43 +86,6 @@ pub fn get_host_config() -> HostConfiguration { } } -/// Returns a [`TestArgs`] instance to be used for the Relay Chain across integration tests -pub fn relay_test_args( - dest: MultiLocation, - beneficiary_id: AccountId32, - amount: Balance, -) -> TestArgs { - TestArgs { - dest, - beneficiary: AccountId32Junction { network: None, id: beneficiary_id.into() }.into(), - amount, - assets: (Here, amount).into(), - asset_id: None, - fee_asset_item: 0, - weight_limit: WeightLimit::Unlimited, - } -} - -/// Returns a [`TestArgs`] instance to be used by parachains across integration tests -pub fn para_test_args( - dest: MultiLocation, - beneficiary_id: AccountId32, - amount: Balance, - assets: MultiAssets, - asset_id: Option, - fee_asset_item: u32, -) -> TestArgs { - TestArgs { - dest, - beneficiary: AccountId32Junction { network: None, id: beneficiary_id.into() }.into(), - amount, - assets, - asset_id, - fee_asset_item, - weight_limit: WeightLimit::Unlimited, - } -} - /// Helper function used in tests to build the genesis storage using given RuntimeGenesisConfig and /// code Used in `legacy_vs_json_check` submods to verify storage building with JSON patch against /// building with RuntimeGenesisConfig struct. diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs index c0b4c3a52919..6ca34d8b5036 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs @@ -15,7 +15,6 @@ use crate::*; use asset_hub_rococo_runtime::xcm_config::XcmConfig as AssetHubRococoXcmConfig; -use emulated_integration_tests_common::{para_test_args, relay_test_args}; use penpal_runtime::xcm_config::XcmConfig as PenpalRococoXcmConfig; use rococo_runtime::xcm_config::XcmConfig as RococoXcmConfig; @@ -276,7 +275,7 @@ fn reserve_transfer_native_asset_from_relay_to_para() { let test_args = TestContext { sender: RococoSender::get(), receiver: PenpalAReceiver::get(), - args: relay_test_args(destination, beneficiary_id, amount_to_send), + args: TestArgs::new_relay(destination, beneficiary_id, amount_to_send), }; let mut test = RelayToParaTest::new(test_args); @@ -320,7 +319,7 @@ fn reserve_transfer_native_asset_from_system_para_to_para() { let test_args = TestContext { sender: AssetHubRococoSender::get(), receiver: PenpalAReceiver::get(), - args: para_test_args(destination, beneficiary_id, amount_to_send, assets, None, 0), + args: TestArgs::new_para(destination, beneficiary_id, amount_to_send, assets, None, 0), }; let mut test = SystemParaToParaTest::new(test_args); @@ -364,7 +363,7 @@ fn reserve_transfer_native_asset_from_para_to_system_para() { let test_args = TestContext { sender: PenpalASender::get(), receiver: AssetHubRococoReceiver::get(), - args: para_test_args(destination, beneficiary_id, amount_to_send, assets, None, 0), + args: TestArgs::new_para(destination, beneficiary_id, amount_to_send, assets, None, 0), }; let mut test = ParaToSystemParaTest::new(test_args); @@ -444,7 +443,7 @@ fn reserve_transfer_assets_from_system_para_to_para() { let para_test_args = TestContext { sender: AssetHubRococoSender::get(), receiver: PenpalAReceiver::get(), - args: para_test_args( + args: TestArgs::new_para( destination, beneficiary_id, asset_amount_to_send, diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs index 8391e64670e0..82cd1740d364 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs @@ -1,4 +1,4 @@ -// Copyright (C) Parity Technologies (UK) Ltd. +// Copyright (C) Parity Technologies (UK) Lt, // SPDX-License-Identifier: Apache-2.0 // Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,7 +15,6 @@ use crate::*; use asset_hub_rococo_runtime::xcm_config::XcmConfig as AssetHubRococoXcmConfig; -use emulated_integration_tests_common::{para_test_args, relay_test_args}; use rococo_runtime::xcm_config::XcmConfig as RococoXcmConfig; fn relay_origin_assertions(t: RelayToSystemParaTest) { @@ -163,7 +162,7 @@ fn limited_teleport_native_assets_from_relay_to_system_para_works() { let test_args = TestContext { sender: RococoSender::get(), receiver: AssetHubRococoReceiver::get(), - args: relay_test_args(dest, beneficiary_id, amount_to_send), + args: TestArgs::new_relay(dest, beneficiary_id, amount_to_send), }; let mut test = RelayToSystemParaTest::new(test_args); @@ -207,7 +206,7 @@ fn limited_teleport_native_assets_back_from_system_para_to_relay_works() { let test_args = TestContext { sender: AssetHubRococoSender::get(), receiver: RococoReceiver::get(), - args: para_test_args(destination, beneficiary_id, amount_to_send, assets, None, 0), + args: TestArgs::new_para(destination, beneficiary_id, amount_to_send, assets, None, 0), }; let mut test = SystemParaToRelayTest::new(test_args); @@ -248,7 +247,7 @@ fn limited_teleport_native_assets_from_system_para_to_relay_fails() { let test_args = TestContext { sender: AssetHubRococoSender::get(), receiver: RococoReceiver::get(), - args: para_test_args(destination, beneficiary_id, amount_to_send, assets, None, 0), + args: TestArgs::new_para(destination, beneficiary_id, amount_to_send, assets, None, 0), }; let mut test = SystemParaToRelayTest::new(test_args); @@ -286,7 +285,7 @@ fn teleport_native_assets_from_relay_to_system_para_works() { let test_args = TestContext { sender: RococoSender::get(), receiver: AssetHubRococoReceiver::get(), - args: relay_test_args(dest, beneficiary_id, amount_to_send), + args: TestArgs::new_relay(dest, beneficiary_id, amount_to_send), }; let mut test = RelayToSystemParaTest::new(test_args); @@ -330,7 +329,7 @@ fn teleport_native_assets_back_from_system_para_to_relay_works() { let test_args = TestContext { sender: AssetHubRococoSender::get(), receiver: RococoReceiver::get(), - args: para_test_args(destination, beneficiary_id, amount_to_send, assets, None, 0), + args: TestArgs::new_para(destination, beneficiary_id, amount_to_send, assets, None, 0), }; let mut test = SystemParaToRelayTest::new(test_args); @@ -371,7 +370,7 @@ fn teleport_native_assets_from_system_para_to_relay_fails() { let test_args = TestContext { sender: AssetHubRococoSender::get(), receiver: RococoReceiver::get(), - args: para_test_args(destination, beneficiary_id, amount_to_send, assets, None, 0), + args: TestArgs::new_para(destination, beneficiary_id, amount_to_send, assets, None, 0), }; let mut test = SystemParaToRelayTest::new(test_args); diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs index ae91fda85f6e..be99d05244ba 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs @@ -15,7 +15,6 @@ use crate::*; use asset_hub_westend_runtime::xcm_config::XcmConfig as AssetHubWestendXcmConfig; -use emulated_integration_tests_common::{para_test_args, relay_test_args}; use penpal_runtime::xcm_config::XcmConfig as PenpalWestendXcmConfig; use westend_runtime::xcm_config::XcmConfig as WestendXcmConfig; @@ -275,7 +274,7 @@ fn reserve_transfer_native_asset_from_relay_to_para() { let test_args = TestContext { sender: WestendSender::get(), receiver: PenpalBReceiver::get(), - args: relay_test_args(destination, beneficiary_id, amount_to_send), + args: TestArgs::new_relay(destination, beneficiary_id, amount_to_send), }; let mut test = RelayToParaTest::new(test_args); @@ -319,7 +318,7 @@ fn reserve_transfer_native_asset_from_system_para_to_para() { let test_args = TestContext { sender: AssetHubWestendSender::get(), receiver: PenpalBReceiver::get(), - args: para_test_args(destination, beneficiary_id, amount_to_send, assets, None, 0), + args: TestArgs::new_parachain(destination, beneficiary_id, amount_to_send, assets, None, 0), }; let mut test = SystemParaToParaTest::new(test_args); @@ -363,7 +362,7 @@ fn reserve_transfer_native_asset_from_para_to_system_para() { let test_args = TestContext { sender: PenpalBSender::get(), receiver: AssetHubWestendReceiver::get(), - args: para_test_args(destination, beneficiary_id, amount_to_send, assets, None, 0), + args: TestArgs::new_para(destination, beneficiary_id, amount_to_send, assets, None, 0), }; let mut test = ParaToSystemParaTest::new(test_args); @@ -444,7 +443,7 @@ fn reserve_transfer_assets_from_system_para_to_para() { let para_test_args = TestContext { sender: AssetHubWestendSender::get(), receiver: PenpalBReceiver::get(), - args: para_test_args( + args: TestArgs::new_para( destination, beneficiary_id, asset_amount_to_send, diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs index 2d3c594ebc69..fe65fa58208f 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs @@ -15,7 +15,6 @@ use crate::*; use asset_hub_westend_runtime::xcm_config::XcmConfig as AssetHubWestendXcmConfig; -use emulated_integration_tests_common::{para_test_args, relay_test_args}; use westend_runtime::xcm_config::XcmConfig as WestendXcmConfig; fn relay_origin_assertions(t: RelayToSystemParaTest) { @@ -163,7 +162,7 @@ fn limited_teleport_native_assets_from_relay_to_system_para_works() { let test_args = TestContext { sender: WestendSender::get(), receiver: beneficiary.clone(), - args: relay_test_args(dest, beneficiary, amount_to_send), + args: TestArgs::new_relay(dest, beneficiary, amount_to_send), }; let mut test = RelayToSystemParaTest::new(test_args); @@ -207,7 +206,7 @@ fn limited_teleport_native_assets_back_from_system_para_to_relay_works() { let test_args = TestContext { sender: AssetHubWestendSender::get(), receiver: WestendReceiver::get(), - args: para_test_args(destination, beneficiary_id, amount_to_send, assets, None, 0), + args: TestArgs::new_para(destination, beneficiary_id, amount_to_send, assets, None, 0), }; let mut test = SystemParaToRelayTest::new(test_args); @@ -248,7 +247,7 @@ fn limited_teleport_native_assets_from_system_para_to_relay_fails() { let test_args = TestContext { sender: AssetHubWestendSender::get(), receiver: WestendReceiver::get(), - args: para_test_args(destination, beneficiary_id, amount_to_send, assets, None, 0), + args: TestArgs::new_para(destination, beneficiary_id, amount_to_send, assets, None, 0), }; let mut test = SystemParaToRelayTest::new(test_args); @@ -286,7 +285,7 @@ fn teleport_native_assets_from_relay_to_system_para_works() { let test_args = TestContext { sender: WestendSender::get(), receiver: beneficiary.clone(), - args: relay_test_args(dest, beneficiary, amount_to_send), + args: TestArgs::new_relay(dest, beneficiary, amount_to_send), }; let mut test = RelayToSystemParaTest::new(test_args); @@ -330,7 +329,7 @@ fn teleport_native_assets_back_from_system_para_to_relay_works() { let test_args = TestContext { sender: AssetHubWestendSender::get(), receiver: WestendReceiver::get(), - args: para_test_args(destination, beneficiary_id, amount_to_send, assets, None, 0), + args: TestArgs::new_para(destination, beneficiary_id, amount_to_send, assets, None, 0), }; let mut test = SystemParaToRelayTest::new(test_args); @@ -371,7 +370,7 @@ fn teleport_native_assets_from_system_para_to_relay_fails() { let test_args = TestContext { sender: AssetHubWestendSender::get(), receiver: WestendReceiver::get(), - args: para_test_args(destination, beneficiary_id, amount_to_send, assets, None, 0), + args: TestArgs::new_para(destination, beneficiary_id, amount_to_send, assets, None, 0), }; let mut test = SystemParaToRelayTest::new(test_args); diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index 841f4c72c093..192e0ff4bca9 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -165,10 +165,6 @@ impl IdentityOn<'_> { /// /// `account_from_u32(5)` will return an `AccountId32` with the bytes /// `[0, 5, 0, 0, 0, 0, 0, 0, 0, 5 ... ]` -/// -/// **Note** -/// -/// This is only used for testing and is not intended for production use. fn account_from_u32(id: u32) -> AccountId32 { let mut buffer = [255u8; 32]; let id_bytes = id.to_le_bytes(); @@ -198,9 +194,9 @@ fn set_id_relay(id: &Identity) -> Balance { Subs::Zero => {}, Subs::Many(n) => { let mut subs = Vec::with_capacity(n.try_into().unwrap()); - for ii in 0..n { + for i in 0..n { subs.push(( - account_from_u32(ii), + AccountId32::from(i), Data::Raw(b"name".to_vec().try_into().unwrap()), )); } diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs index 4bb3daf3f995..34b9e040717c 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs @@ -14,7 +14,6 @@ // limitations under the License. use crate::*; -use emulated_integration_tests_common::{para_test_args, relay_test_args}; use people_rococo_runtime::xcm_config::XcmConfig as PeopleRococoXcmConfig; use rococo_runtime::xcm_config::XcmConfig as RococoXcmConfig; @@ -142,7 +141,7 @@ fn limited_teleport_native_assets_from_relay_to_system_para_works() { let test_args = TestContext { sender: RococoSender::get(), receiver: PeopleRococoReceiver::get(), - args: relay_test_args(dest, beneficiary_id, amount_to_send), + args: TestArgs::new_relay(dest, beneficiary_id, amount_to_send), }; let mut test = RelayToSystemParaTest::new(test_args); @@ -188,7 +187,7 @@ fn limited_teleport_native_assets_back_from_system_para_to_relay_works() { let test_args = TestContext { sender: PeopleRococoSender::get(), receiver: RococoReceiver::get(), - args: para_test_args(destination, beneficiary_id, amount_to_send, assets, None, 0), + args: TestArgs::new_para(destination, beneficiary_id, amount_to_send, assets, None, 0), }; let mut test = SystemParaToRelayTest::new(test_args); @@ -232,7 +231,7 @@ fn limited_teleport_native_assets_from_system_para_to_relay_fails() { let test_args = TestContext { sender: PeopleRococoSender::get(), receiver: RococoReceiver::get(), - args: para_test_args(destination, beneficiary_id, amount_to_send, assets, None, 0), + args: TestArgs::new_para(destination, beneficiary_id, amount_to_send, assets, None, 0), }; let mut test = SystemParaToRelayTest::new(test_args); diff --git a/cumulus/xcm/xcm-emulator/src/lib.rs b/cumulus/xcm/xcm-emulator/src/lib.rs index 52c8344c1f8a..a2a100e9b811 100644 --- a/cumulus/xcm/xcm-emulator/src/lib.rs +++ b/cumulus/xcm/xcm-emulator/src/lib.rs @@ -1436,6 +1436,7 @@ pub struct TestArgs { } impl TestArgs { + /// Returns a [`TestArgs`] instance to be used for the Relay Chain across integration tests pub fn new_relay(dest: MultiLocation, beneficiary_id: AccountId32, amount: Balance) -> Self { Self { dest, @@ -1448,11 +1449,14 @@ impl TestArgs { } } - pub fn new_parachain( + /// Returns a [`TestArgs`] instance to be used by parachains across integration tests + pub fn new_para( dest: MultiLocation, beneficiary_id: AccountId32, amount: Balance, + assets: MultiAssets, asset_id: Option, + fee_asset_item: u32, ) -> Self { Self { dest, diff --git a/substrate/primitives/core/src/crypto.rs b/substrate/primitives/core/src/crypto.rs index c9719e344d3e..516972eb1add 100644 --- a/substrate/primitives/core/src/crypto.rs +++ b/substrate/primitives/core/src/crypto.rs @@ -554,6 +554,28 @@ impl From<[u8; 32]> for AccountId32 { } } +/// Generate an `AccountId32` from a `u32`. +/// This creates a 32-byte array, initially filled with `255`, and then repeatedly fills it +/// with the 4-byte little-endian representation of the `u32` value, until the array is full. +/// +/// **Example**: +/// +/// `account_from_u32(5)` will return an `AccountId32` with the bytes +/// `[0, 5, 0, 0, 0, 0, 0, 0, 0, 5 ... ]` +impl From for AccountId32 { + fn from(id: u32) -> Self { + let mut buffer = [255u8; 32]; + let id_bytes = id.to_le_bytes(); + let id_size = id_bytes.len(); + for i in 0..buffer.len() / id_size { + let start = i * id_size; + let end = start + id_size; + buffer[start..end].clone_from_slice(&id_bytes[..]); + } + Self::new(buffer) + } +} + impl<'a> TryFrom<&'a [u8]> for AccountId32 { type Error = (); fn try_from(x: &'a [u8]) -> Result { From dca66bfd999dfcd638e1e4ec9a2155f872ede472 Mon Sep 17 00:00:00 2001 From: Richard Melkonian <35300528+0xmovses@users.noreply.github.com> Date: Mon, 4 Dec 2023 18:19:05 +0000 Subject: [PATCH 092/102] Update cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs Co-authored-by: Liam Aharon --- .../tests/people/people-rococo/src/tests/reap_identity.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index 192e0ff4bca9..5645bf8566b9 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -210,7 +210,7 @@ fn set_id_relay(id: &Identity) -> Balance { let reserved_balance = RococoBalances::reserved_balance(RococoRelaySender::get()); let id_deposit = IdentityOn::Relay(&id.relay).calculate_deposit(); - match id.subs { + let total_deposit = match id.subs { Subs::Zero => { total_deposit = id_deposit; // No subs assert_expected_events!( From 860c6476e6c993ba2b39679f7c5d3e898d9f4449 Mon Sep 17 00:00:00 2001 From: Richard Melkonian <35300528+0xmovses@users.noreply.github.com> Date: Mon, 4 Dec 2023 18:20:03 +0000 Subject: [PATCH 093/102] Update cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs Co-authored-by: Liam Aharon --- .../tests/people/people-rococo/src/tests/reap_identity.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index 5645bf8566b9..0ed1df6034ff 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -435,7 +435,7 @@ fn assert_reap_events(id_deposit: Balance, id: &Identity) { }; } -// Duplicate of the impl of `ToParachainIdentityReaper` in the Rococo runtime. +/// Duplicate of the impl of `ToParachainIdentityReaper` in the Rococo runtime. fn calculate_remote_deposit(bytes: u32, subs: u32) -> Balance { // Note: These `deposit` functions and `EXISTENTIAL_DEPOSIT` correspond to the Relay Chain's. // Pulled in: use rococo_runtime_constants::currency::*; From 76f4400c2f08f13b51d7bfaab22f159527de4e37 Mon Sep 17 00:00:00 2001 From: Richard Melkonian <35300528+0xmovses@users.noreply.github.com> Date: Mon, 4 Dec 2023 18:20:54 +0000 Subject: [PATCH 094/102] Update cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs Co-authored-by: Liam Aharon --- .../tests/people/people-rococo/src/tests/reap_identity.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index 0ed1df6034ff..6bb35d5cde9a 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -257,7 +257,7 @@ fn assert_set_id_parachain(id: &Identity) { let free_bal = PeopleRococoBalances::free_balance(PeopleRococoSender::get()); let reserved_balance = PeopleRococoBalances::reserved_balance(PeopleRococoSender::get()); - //total balance at Genesis should be zero + // total balance at Genesis should be zero assert_eq!(reserved_balance + free_bal, 0); assert_ok!(PeopleRococoIdentity::set_identity_no_deposit( From 149cae4945d8f5b7f41db0a29e115676c310b564 Mon Sep 17 00:00:00 2001 From: Richard Melkonian <35300528+0xmovses@users.noreply.github.com> Date: Mon, 4 Dec 2023 18:21:27 +0000 Subject: [PATCH 095/102] Update cumulus/parachains/integration-tests/emulated/common/src/impls.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Dónal Murray --- .../parachains/integration-tests/emulated/common/src/impls.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/common/src/impls.rs b/cumulus/parachains/integration-tests/emulated/common/src/impls.rs index 08134edb3f2e..78dcc4f76800 100644 --- a/cumulus/parachains/integration-tests/emulated/common/src/impls.rs +++ b/cumulus/parachains/integration-tests/emulated/common/src/impls.rs @@ -250,8 +250,8 @@ macro_rules! impl_assert_events_helpers_for_relay_chain { ); } - /// Asserts an XCM program from a System Parachain is succesfully received and - /// proccessed within expectations. + /// Asserts an XCM program from a System Parachain is successfully received and + /// processed within expectations. pub fn assert_ump_queue_processed( expected_success: bool, expected_id: Option<$crate::impls::ParaId>, From bc66fcd925613b7cc418754d11078ebeb11bdffd Mon Sep 17 00:00:00 2001 From: Richard Melkonian <35300528+0xmovses@users.noreply.github.com> Date: Mon, 4 Dec 2023 18:22:03 +0000 Subject: [PATCH 096/102] Update substrate/frame/identity/src/lib.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Dónal Murray --- substrate/frame/identity/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index ef827d91ede4..ddbc7e185be6 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -1023,7 +1023,7 @@ impl Pallet { Ok(()) } - /// Set subs with zero deposit and default name. Only used for benchmarking that involve + /// Set subs with zero deposit and default name. Only used for benchmarks that involve /// `rejig_deposit`. #[cfg(any(feature = "runtime-benchmarks", feature = "xcm-emulator"))] pub fn set_subs_no_deposit( From 4a9cb21dab7f08c53a078e14d67a648fd8fcffc6 Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Mon, 4 Dec 2023 19:33:30 +0000 Subject: [PATCH 097/102] integrate seadanda feedback, remove unused --- .../emulated/common/src/lib.rs | 7 +-- .../asset-hub-rococo/src/tests/teleport.rs | 2 +- .../people-rococo/src/tests/reap_identity.rs | 54 ++++++++----------- substrate/primitives/core/src/crypto.rs | 22 -------- 4 files changed, 25 insertions(+), 60 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/common/src/lib.rs b/cumulus/parachains/integration-tests/emulated/common/src/lib.rs index d88599a22fc8..48ee1a3b7808 100644 --- a/cumulus/parachains/integration-tests/emulated/common/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/common/src/lib.rs @@ -30,18 +30,13 @@ use sp_runtime::{ }; // Polakdot -use parachains_common::{Balance, BlockNumber}; +use parachains_common::BlockNumber; use polkadot_runtime_parachains::configuration::HostConfiguration; -use xcm::prelude::{ - AccountId32 as AccountId32Junction, Here, MultiAssets, MultiLocation, WeightLimit, -}; // Cumulus use parachains_common::{AccountId, AssetHubPolkadotAuraId, AuraId}; use polkadot_primitives::{AssignmentId, ValidatorId}; use polkadot_service::chain_spec::get_authority_keys_from_seed_no_beefy; -use sp_core::crypto::AccountId32; -use xcm_emulator::TestArgs; pub const XCM_V2: u32 = 2; pub const XCM_V3: u32 = 3; diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs index 82cd1740d364..a2fbe665957f 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs @@ -1,4 +1,4 @@ -// Copyright (C) Parity Technologies (UK) Lt, +// Copyright (C) Parity Technologies (UK) Ltd. // SPDX-License-Identifier: Apache-2.0 // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index 6bb35d5cde9a..bfde4faf8023 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -149,8 +149,8 @@ impl IdentityOn<'_> { }, IdentityOn::Para(id) => { let base_deposit = BasicDepositParachain::get(); - let byte_deposit = ByteDepositParachain::get() * - TryInto::::try_into(id.encoded_size()).unwrap(); + let byte_deposit = ByteDepositParachain::get() + * TryInto::::try_into(id.encoded_size()).unwrap(); base_deposit + byte_deposit }, } @@ -169,10 +169,8 @@ fn account_from_u32(id: u32) -> AccountId32 { let mut buffer = [255u8; 32]; let id_bytes = id.to_le_bytes(); let id_size = id_bytes.len(); - for ii in 0..buffer.len() / id_size { - let start = ii * id_size; - let end = start + id_size; - buffer[start..end].clone_from_slice(&id_bytes[..]); + for chunk in buffer.chunks_mut(id_size) { + chunk.clone_from_slice(&id_bytes); } AccountId32::new(buffer) } @@ -190,21 +188,15 @@ fn set_id_relay(id: &Identity) -> Balance { Box::new(id.relay.clone()) )); - match id.subs { - Subs::Zero => {}, - Subs::Many(n) => { - let mut subs = Vec::with_capacity(n.try_into().unwrap()); - for i in 0..n { - subs.push(( - AccountId32::from(i), - Data::Raw(b"name".to_vec().try_into().unwrap()), - )); - } - assert_ok!(RococoIdentity::set_subs( - RococoOrigin::signed(RococoRelaySender::get()), - subs, - )); - }, + if let Subs::Many(n) = id.subs { + let subs: Vec<_> = (0..n) + .map(|i| (account_from_u32(i), Data::Raw(b"name".to_vec().try_into().unwrap()))) + .collect(); + + assert_ok!(RococoIdentity::set_subs( + RococoOrigin::signed(RococoRelaySender::get()), + subs, + )); } let reserved_balance = RococoBalances::reserved_balance(RococoRelaySender::get()); @@ -223,6 +215,7 @@ fn set_id_relay(id: &Identity) -> Balance { }, ] ); + total_deposit }, Subs::Many(n) => { let sub_account_deposit = n as Balance * SubAccountDeposit::get(); @@ -242,8 +235,9 @@ fn set_id_relay(id: &Identity) -> Balance { }, ] ); + total_deposit }, - } + }; assert_eq!(reserved_balance, total_deposit); }); @@ -268,13 +262,11 @@ fn assert_set_id_parachain(id: &Identity) { match id.subs { Subs::Zero => {}, Subs::Many(n) => { - let mut subs = Vec::with_capacity(n.try_into().unwrap()); - for ii in 0..n { - subs.push(( - account_from_u32(ii), - Data::Raw(b"name".to_vec().try_into().unwrap()), - )); - } + let subs: Vec<_> = (0..n) + .map(|ii| { + (account_from_u32(ii), Data::Raw(b"name".to_vec().try_into().unwrap())) + }) + .collect(); assert_ok!(PeopleRococoIdentity::set_subs_no_deposit( &PeopleRococoSender::get(), subs, @@ -397,7 +389,7 @@ fn assert_reap_events(id_deposit: Balance, id: &Identity) { identity: *identity == id_deposit, subs: *subs == 0, }, - RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { ..}) => {}, + RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { .. }) => {}, ] ); }, @@ -428,7 +420,7 @@ fn assert_reap_events(id_deposit: Balance, id: &Identity) { identity: *identity == id_deposit, subs: *subs == subs_deposit, }, - RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { ..}) => {}, + RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { .. }) => {}, ] ); }, diff --git a/substrate/primitives/core/src/crypto.rs b/substrate/primitives/core/src/crypto.rs index 516972eb1add..c9719e344d3e 100644 --- a/substrate/primitives/core/src/crypto.rs +++ b/substrate/primitives/core/src/crypto.rs @@ -554,28 +554,6 @@ impl From<[u8; 32]> for AccountId32 { } } -/// Generate an `AccountId32` from a `u32`. -/// This creates a 32-byte array, initially filled with `255`, and then repeatedly fills it -/// with the 4-byte little-endian representation of the `u32` value, until the array is full. -/// -/// **Example**: -/// -/// `account_from_u32(5)` will return an `AccountId32` with the bytes -/// `[0, 5, 0, 0, 0, 0, 0, 0, 0, 5 ... ]` -impl From for AccountId32 { - fn from(id: u32) -> Self { - let mut buffer = [255u8; 32]; - let id_bytes = id.to_le_bytes(); - let id_size = id_bytes.len(); - for i in 0..buffer.len() / id_size { - let start = i * id_size; - let end = start + id_size; - buffer[start..end].clone_from_slice(&id_bytes[..]); - } - Self::new(buffer) - } -} - impl<'a> TryFrom<&'a [u8]> for AccountId32 { type Error = (); fn try_from(x: &'a [u8]) -> Result { From b2dddf8098a1935b20d0833842366b4307937689 Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Mon, 4 Dec 2023 19:37:22 +0000 Subject: [PATCH 098/102] update feature name --- .../tests/people/people-rococo/Cargo.toml | 2 +- substrate/frame/identity/Cargo.toml | 2 +- substrate/frame/identity/src/lib.rs | 20 ++++++++++--------- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/Cargo.toml b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/Cargo.toml index a90282c4afca..47c72201dff9 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/Cargo.toml @@ -18,7 +18,7 @@ pallet-balances = { path = "../../../../../../../substrate/frame/balances", defa pallet-assets = { path = "../../../../../../../substrate/frame/assets", default-features = false } pallet-asset-conversion = { path = "../../../../../../../substrate/frame/asset-conversion", default-features = false } pallet-message-queue = { path = "../../../../../../../substrate/frame/message-queue", default-features = false } -pallet-identity = { path = "../../../../../../../substrate/frame/identity", default-features = false, features = ["xcm-emulator"] } +pallet-identity = { path = "../../../../../../../substrate/frame/identity", default-features = false, features =["xcm-emulator-testing"] } # Polkadot xcm = { package = "staging-xcm", path = "../../../../../../../polkadot/xcm", default-features = false } diff --git a/substrate/frame/identity/Cargo.toml b/substrate/frame/identity/Cargo.toml index 5ade5dd1f615..644abb67cb03 100644 --- a/substrate/frame/identity/Cargo.toml +++ b/substrate/frame/identity/Cargo.toml @@ -29,7 +29,7 @@ sp-core = { path = "../../primitives/core" } [features] default = ["std"] -xcm-emulator = [] +xcm-emulator-testing = [] std = [ "codec/std", diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index ddbc7e185be6..020f7ea01e82 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -505,14 +505,16 @@ pub mod pallet { let item = (reg_index, Judgement::FeePaid(registrar.fee)); match id.judgements.binary_search_by_key(®_index, |x| x.0) { - Ok(i) => + Ok(i) => { if id.judgements[i].1.is_sticky() { - return Err(Error::::StickyJudgement.into()) + return Err(Error::::StickyJudgement.into()); } else { id.judgements[i] = item - }, - Err(i) => - id.judgements.try_insert(i, item).map_err(|_| Error::::TooManyRegistrars)?, + } + }, + Err(i) => { + id.judgements.try_insert(i, item).map_err(|_| Error::::TooManyRegistrars)? + }, } T::Currency::reserve(&sender, registrar.fee)?; @@ -554,7 +556,7 @@ pub mod pallet { let fee = if let Judgement::FeePaid(fee) = id.judgements.remove(pos).1 { fee } else { - return Err(Error::::JudgementGiven.into()) + return Err(Error::::JudgementGiven.into()); }; let err_amount = T::Currency::unreserve(&sender, fee); @@ -700,7 +702,7 @@ pub mod pallet { let mut id = >::get(&target).ok_or(Error::::InvalidTarget)?; if T::Hashing::hash_of(&id.info) != identity { - return Err(Error::::JudgementForDifferentIdentity.into()) + return Err(Error::::JudgementForDifferentIdentity.into()); } let item = (reg_index, judgement); @@ -1007,7 +1009,7 @@ impl Pallet { /// Set an identity with zero deposit. Used for benchmarking and XCM emulator tests that involve /// `rejig_deposit`. - #[cfg(any(feature = "runtime-benchmarks", feature = "xcm-emulator"))] + #[cfg(any(feature = "runtime-benchmarks", feature = "xcm-emulator-testing"))] pub fn set_identity_no_deposit( who: &T::AccountId, info: T::IdentityInformation, @@ -1025,7 +1027,7 @@ impl Pallet { /// Set subs with zero deposit and default name. Only used for benchmarks that involve /// `rejig_deposit`. - #[cfg(any(feature = "runtime-benchmarks", feature = "xcm-emulator"))] + #[cfg(any(feature = "runtime-benchmarks", feature = "xcm-emulator-testing"))] pub fn set_subs_no_deposit( who: &T::AccountId, subs: Vec<(T::AccountId, Data)>, From bd4183d8e14848fd769255f09e616e4396f44097 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Mon, 4 Dec 2023 19:47:15 +0000 Subject: [PATCH 099/102] ".git/.scripts/commands/fmt/fmt.sh" --- .../emulated/tests/people/people-rococo/Cargo.toml | 2 +- .../people/people-rococo/src/tests/reap_identity.rs | 4 ++-- substrate/frame/identity/src/lib.rs | 10 ++++------ 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/Cargo.toml b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/Cargo.toml index 47c72201dff9..68de9b977fb1 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/Cargo.toml @@ -18,7 +18,7 @@ pallet-balances = { path = "../../../../../../../substrate/frame/balances", defa pallet-assets = { path = "../../../../../../../substrate/frame/assets", default-features = false } pallet-asset-conversion = { path = "../../../../../../../substrate/frame/asset-conversion", default-features = false } pallet-message-queue = { path = "../../../../../../../substrate/frame/message-queue", default-features = false } -pallet-identity = { path = "../../../../../../../substrate/frame/identity", default-features = false, features =["xcm-emulator-testing"] } +pallet-identity = { path = "../../../../../../../substrate/frame/identity", default-features = false, features = ["xcm-emulator-testing"] } # Polkadot xcm = { package = "staging-xcm", path = "../../../../../../../polkadot/xcm", default-features = false } diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index bfde4faf8023..24712fbc1b9b 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -149,8 +149,8 @@ impl IdentityOn<'_> { }, IdentityOn::Para(id) => { let base_deposit = BasicDepositParachain::get(); - let byte_deposit = ByteDepositParachain::get() - * TryInto::::try_into(id.encoded_size()).unwrap(); + let byte_deposit = ByteDepositParachain::get() * + TryInto::::try_into(id.encoded_size()).unwrap(); base_deposit + byte_deposit }, } diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index 020f7ea01e82..de652ca070f5 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -505,16 +505,14 @@ pub mod pallet { let item = (reg_index, Judgement::FeePaid(registrar.fee)); match id.judgements.binary_search_by_key(®_index, |x| x.0) { - Ok(i) => { + Ok(i) => if id.judgements[i].1.is_sticky() { return Err(Error::::StickyJudgement.into()); } else { id.judgements[i] = item - } - }, - Err(i) => { - id.judgements.try_insert(i, item).map_err(|_| Error::::TooManyRegistrars)? - }, + }, + Err(i) => + id.judgements.try_insert(i, item).map_err(|_| Error::::TooManyRegistrars)?, } T::Currency::reserve(&sender, registrar.fee)?; From 8083b9e64f11a5378c774e71b2cbeceb2662098e Mon Sep 17 00:00:00 2001 From: 0xmovses Date: Mon, 4 Dec 2023 21:51:42 +0000 Subject: [PATCH 100/102] wrong method name --- .../assets/asset-hub-westend/src/tests/reserve_transfer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs index be99d05244ba..b929ac70b595 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs @@ -318,7 +318,7 @@ fn reserve_transfer_native_asset_from_system_para_to_para() { let test_args = TestContext { sender: AssetHubWestendSender::get(), receiver: PenpalBReceiver::get(), - args: TestArgs::new_parachain(destination, beneficiary_id, amount_to_send, assets, None, 0), + args: TestArgs::new_para(destination, beneficiary_id, amount_to_send, assets, None, 0), }; let mut test = SystemParaToParaTest::new(test_args); From 3d9d09f818c43e3cad5686b3fe45fcbe17759413 Mon Sep 17 00:00:00 2001 From: joe petrowski <25483142+joepetrowski@users.noreply.github.com> Date: Tue, 5 Dec 2023 08:51:56 +0100 Subject: [PATCH 101/102] Apply suggestions from code review --- .../people-rococo/src/tests/reap_identity.rs | 23 +++++++------------ cumulus/xcm/xcm-emulator/src/lib.rs | 4 ++-- substrate/frame/identity/src/lib.rs | 6 ++--- 3 files changed, 13 insertions(+), 20 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index 24712fbc1b9b..6f109b07f25c 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -25,25 +25,18 @@ //! The tests validate the robustness and correctness of the `OnReapIdentityHandler` //! ensuring that it behaves as expected in various scenarios. Key aspects tested include: //! -//! - **Identity Creation**: Verifying that identities can be created with the correct -//! information and handling of deposits. -//! - **Sub-Account Management**: Testing the functionality for managing sub-accounts, including -//! creation and deposit requirements. -//! - **Cross-Chain Functionality**: Ensuring that identities can be managed seamlessly across the -//! Rococo Relay Chain and the PeopleRococo Parachain, including testing cross-chain interactions -//! and migrations. -//! - **Deposit Handling**: Confirming that deposits are correctly handled, reserved, and released -//! in various scenarios, including identity reaping. +//! - **Deposit Handling**: Confirming that deposits are correctly migrated from the Relay Chain to +//! the People parachain in various scenarios (different `IdentityInfo` fields and different +//! numbers of sub-accounts). //! //! ### Test Scenarios //! -//! The tests are categorized into several scenarios, each focusing on different aspects of the -//! Identity Management Module: +//! The tests are categorized into several scenarios, each resulting in different deposits required +//! on the destination parachain. The tests ensure: //! -//! - Minimal identity information with varying numbers of sub-accounts. -//! - Full identity information with and without additional fields, again with varying numbers of -//! sub-accounts. -//! - Reaping (removal) of identities and the correct release and transfer of associated deposits. +//! - Reserved deposits on the Relay Chain are fully released; +//! - The freed deposit from the Relay Chain is sufficient for the parachain deposit; and +//! - The account will exist on the parachain. use crate::*; use frame_support::BoundedVec; diff --git a/cumulus/xcm/xcm-emulator/src/lib.rs b/cumulus/xcm/xcm-emulator/src/lib.rs index a2a100e9b811..ebbd4c9a0fd4 100644 --- a/cumulus/xcm/xcm-emulator/src/lib.rs +++ b/cumulus/xcm/xcm-emulator/src/lib.rs @@ -1436,7 +1436,7 @@ pub struct TestArgs { } impl TestArgs { - /// Returns a [`TestArgs`] instance to be used for the Relay Chain across integration tests + /// Returns a [`TestArgs`] instance to be used for the Relay Chain across integration tests. pub fn new_relay(dest: MultiLocation, beneficiary_id: AccountId32, amount: Balance) -> Self { Self { dest, @@ -1449,7 +1449,7 @@ impl TestArgs { } } - /// Returns a [`TestArgs`] instance to be used by parachains across integration tests + /// Returns a [`TestArgs`] instance to be used by parachains across integration tests. pub fn new_para( dest: MultiLocation, beneficiary_id: AccountId32, diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index de652ca070f5..518faa92e639 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -507,7 +507,7 @@ pub mod pallet { match id.judgements.binary_search_by_key(®_index, |x| x.0) { Ok(i) => if id.judgements[i].1.is_sticky() { - return Err(Error::::StickyJudgement.into()); + return Err(Error::::StickyJudgement.into()) } else { id.judgements[i] = item }, @@ -554,7 +554,7 @@ pub mod pallet { let fee = if let Judgement::FeePaid(fee) = id.judgements.remove(pos).1 { fee } else { - return Err(Error::::JudgementGiven.into()); + return Err(Error::::JudgementGiven.into()) }; let err_amount = T::Currency::unreserve(&sender, fee); @@ -700,7 +700,7 @@ pub mod pallet { let mut id = >::get(&target).ok_or(Error::::InvalidTarget)?; if T::Hashing::hash_of(&id.info) != identity { - return Err(Error::::JudgementForDifferentIdentity.into()); + return Err(Error::::JudgementForDifferentIdentity.into()) } let item = (reg_index, judgement); From b33d317b32b10573f75aa2c45266c3f5a0454a98 Mon Sep 17 00:00:00 2001 From: joe petrowski <25483142+joepetrowski@users.noreply.github.com> Date: Tue, 5 Dec 2023 10:34:27 +0100 Subject: [PATCH 102/102] Update cumulus/xcm/xcm-emulator/src/lib.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Dónal Murray --- cumulus/xcm/xcm-emulator/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cumulus/xcm/xcm-emulator/src/lib.rs b/cumulus/xcm/xcm-emulator/src/lib.rs index ebbd4c9a0fd4..579949407d41 100644 --- a/cumulus/xcm/xcm-emulator/src/lib.rs +++ b/cumulus/xcm/xcm-emulator/src/lib.rs @@ -1449,7 +1449,7 @@ impl TestArgs { } } - /// Returns a [`TestArgs`] instance to be used by parachains across integration tests. + /// Returns a [`TestArgs`] instance to be used for parachains across integration tests. pub fn new_para( dest: MultiLocation, beneficiary_id: AccountId32,