[xcm-emulator] Improve hygiene and clean up (#1301)

* improve hygiene & clean up

* improve hygiene & clean up - xcm-emulator

* improve hygiene & clean up - common

* improve hygiene & clean up - tests

* improve hygiene & clean up - tests 2

* last hygiene bits

* ".git/.scripts/commands/fmt/fmt.sh"

---------

Co-authored-by: command-bot <>
This commit is contained in:
Ignacio Palacios
2023-09-01 12:44:06 +02:00
committed by GitHub
parent 12443589e3
commit 241601b1c1
18 changed files with 388 additions and 513 deletions
Generated
+5 -43
View File
@@ -697,9 +697,6 @@ version = "1.0.0"
dependencies = [ dependencies = [
"assert_matches", "assert_matches",
"asset-hub-kusama-runtime", "asset-hub-kusama-runtime",
"cumulus-pallet-dmp-queue",
"cumulus-pallet-parachain-system",
"cumulus-pallet-xcmp-queue",
"frame-support", "frame-support",
"frame-system", "frame-system",
"integration-tests-common", "integration-tests-common",
@@ -713,11 +710,8 @@ dependencies = [
"polkadot-parachain-primitives", "polkadot-parachain-primitives",
"polkadot-runtime", "polkadot-runtime",
"polkadot-runtime-parachains", "polkadot-runtime-parachains",
"sp-core",
"sp-runtime", "sp-runtime",
"sp-weights",
"staging-xcm", "staging-xcm",
"staging-xcm-executor",
"xcm-emulator", "xcm-emulator",
] ]
@@ -798,12 +792,11 @@ dependencies = [
name = "asset-hub-polkadot-integration-tests" name = "asset-hub-polkadot-integration-tests"
version = "1.0.0" version = "1.0.0"
dependencies = [ dependencies = [
"cumulus-pallet-dmp-queue", "asset-hub-kusama-runtime",
"cumulus-pallet-parachain-system",
"cumulus-pallet-xcmp-queue",
"frame-support", "frame-support",
"frame-system", "frame-system",
"integration-tests-common", "integration-tests-common",
"pallet-asset-conversion",
"pallet-assets", "pallet-assets",
"pallet-balances", "pallet-balances",
"pallet-xcm", "pallet-xcm",
@@ -813,11 +806,8 @@ dependencies = [
"polkadot-parachain-primitives", "polkadot-parachain-primitives",
"polkadot-runtime", "polkadot-runtime",
"polkadot-runtime-parachains", "polkadot-runtime-parachains",
"sp-core",
"sp-runtime", "sp-runtime",
"sp-weights",
"staging-xcm", "staging-xcm",
"staging-xcm-executor",
"xcm-emulator", "xcm-emulator",
] ]
@@ -896,9 +886,6 @@ version = "1.0.0"
dependencies = [ dependencies = [
"assert_matches", "assert_matches",
"asset-hub-westend-runtime", "asset-hub-westend-runtime",
"cumulus-pallet-dmp-queue",
"cumulus-pallet-parachain-system",
"cumulus-pallet-xcmp-queue",
"frame-support", "frame-support",
"frame-system", "frame-system",
"integration-tests-common", "integration-tests-common",
@@ -912,11 +899,8 @@ dependencies = [
"polkadot-parachain-primitives", "polkadot-parachain-primitives",
"polkadot-runtime", "polkadot-runtime",
"polkadot-runtime-parachains", "polkadot-runtime-parachains",
"sp-core",
"sp-runtime", "sp-runtime",
"sp-weights",
"staging-xcm", "staging-xcm",
"staging-xcm-executor",
"xcm-emulator", "xcm-emulator",
] ]
@@ -1957,13 +1941,10 @@ name = "bridge-hub-rococo-integration-tests"
version = "1.0.0" version = "1.0.0"
dependencies = [ dependencies = [
"bp-messages", "bp-messages",
"cumulus-pallet-parachain-system", "cumulus-pallet-dmp-queue",
"cumulus-pallet-xcmp-queue", "cumulus-pallet-xcmp-queue",
"frame-support", "frame-support",
"frame-system",
"integration-tests-common", "integration-tests-common",
"pallet-assets",
"pallet-balances",
"pallet-bridge-messages", "pallet-bridge-messages",
"pallet-xcm", "pallet-xcm",
"parachains-common", "parachains-common",
@@ -1972,11 +1953,7 @@ dependencies = [
"polkadot-parachain-primitives", "polkadot-parachain-primitives",
"polkadot-runtime", "polkadot-runtime",
"polkadot-runtime-parachains", "polkadot-runtime-parachains",
"sp-core",
"sp-runtime",
"sp-weights",
"staging-xcm", "staging-xcm",
"staging-xcm-executor",
"xcm-emulator", "xcm-emulator",
] ]
@@ -2581,15 +2558,12 @@ dependencies = [
name = "collectives-polkadot-integration-tests" name = "collectives-polkadot-integration-tests"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"asset-hub-polkadot-runtime",
"collectives-polkadot-runtime", "collectives-polkadot-runtime",
"cumulus-pallet-parachain-system", "cumulus-pallet-parachain-system",
"cumulus-pallet-xcmp-queue", "cumulus-pallet-xcmp-queue",
"frame-support", "frame-support",
"frame-system",
"integration-tests-common", "integration-tests-common",
"pallet-assets", "pallet-assets",
"pallet-balances",
"pallet-core-fellowship", "pallet-core-fellowship",
"pallet-salary", "pallet-salary",
"pallet-xcm", "pallet-xcm",
@@ -2601,9 +2575,7 @@ dependencies = [
"polkadot-runtime-parachains", "polkadot-runtime-parachains",
"sp-core", "sp-core",
"sp-runtime", "sp-runtime",
"sp-weights",
"staging-xcm", "staging-xcm",
"staging-xcm-executor",
"xcm-emulator", "xcm-emulator",
] ]
@@ -6434,7 +6406,6 @@ dependencies = [
"asset-hub-polkadot-runtime", "asset-hub-polkadot-runtime",
"asset-hub-westend-runtime", "asset-hub-westend-runtime",
"bp-messages", "bp-messages",
"bp-runtime",
"bridge-hub-kusama-runtime", "bridge-hub-kusama-runtime",
"bridge-hub-polkadot-runtime", "bridge-hub-polkadot-runtime",
"bridge-hub-rococo-runtime", "bridge-hub-rococo-runtime",
@@ -6445,17 +6416,13 @@ dependencies = [
"cumulus-pallet-xcmp-queue", "cumulus-pallet-xcmp-queue",
"cumulus-primitives-core", "cumulus-primitives-core",
"frame-support", "frame-support",
"frame-system",
"kusama-runtime-constants", "kusama-runtime-constants",
"lazy_static",
"pallet-assets", "pallet-assets",
"pallet-balances",
"pallet-bridge-messages", "pallet-bridge-messages",
"pallet-im-online", "pallet-im-online",
"pallet-message-queue", "pallet-message-queue",
"pallet-staking", "pallet-staking",
"pallet-xcm", "pallet-xcm",
"parachain-info",
"parachains-common", "parachains-common",
"parity-scale-codec", "parity-scale-codec",
"paste", "paste",
@@ -6475,11 +6442,8 @@ dependencies = [
"sp-consensus-beefy", "sp-consensus-beefy",
"sp-core", "sp-core",
"sp-runtime", "sp-runtime",
"sp-tracing",
"sp-weights",
"staging-kusama-runtime", "staging-kusama-runtime",
"staging-xcm", "staging-xcm",
"staging-xcm-executor",
"westend-runtime", "westend-runtime",
"westend-runtime-constants", "westend-runtime-constants",
"xcm-emulator", "xcm-emulator",
@@ -20858,9 +20822,7 @@ dependencies = [
name = "xcm-emulator" name = "xcm-emulator"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"cumulus-pallet-dmp-queue",
"cumulus-pallet-parachain-system", "cumulus-pallet-parachain-system",
"cumulus-pallet-xcmp-queue",
"cumulus-primitives-core", "cumulus-primitives-core",
"cumulus-primitives-parachain-inherent", "cumulus-primitives-parachain-inherent",
"cumulus-test-relay-sproof-builder", "cumulus-test-relay-sproof-builder",
@@ -20871,10 +20833,10 @@ dependencies = [
"log", "log",
"pallet-balances", "pallet-balances",
"pallet-message-queue", "pallet-message-queue",
"parachain-info",
"parachains-common", "parachains-common",
"parity-scale-codec", "parity-scale-codec",
"paste", "paste",
"polkadot-parachain-primitives",
"polkadot-primitives", "polkadot-primitives",
"polkadot-runtime-parachains", "polkadot-runtime-parachains",
"sp-arithmetic", "sp-arithmetic",
@@ -20882,7 +20844,7 @@ dependencies = [
"sp-io", "sp-io",
"sp-runtime", "sp-runtime",
"sp-std", "sp-std",
"sp-trie", "sp-tracing",
"staging-xcm", "staging-xcm",
"staging-xcm-executor", "staging-xcm-executor",
] ]
@@ -14,8 +14,6 @@ assert_matches = "1.5.0"
sp-runtime = { path = "../../../../../../substrate/primitives/runtime", default-features = false} sp-runtime = { path = "../../../../../../substrate/primitives/runtime", default-features = false}
frame-support = { path = "../../../../../../substrate/frame/support", default-features = false} frame-support = { path = "../../../../../../substrate/frame/support", default-features = false}
frame-system = { path = "../../../../../../substrate/frame/system", default-features = false} frame-system = { path = "../../../../../../substrate/frame/system", default-features = false}
sp-core = { path = "../../../../../../substrate/primitives/core", default-features = false}
sp-weights = { path = "../../../../../../substrate/primitives/weights", default-features = false}
pallet-balances = { path = "../../../../../../substrate/frame/balances", default-features = false} pallet-balances = { path = "../../../../../../substrate/frame/balances", default-features = false}
pallet-assets = { path = "../../../../../../substrate/frame/assets", default-features = false} pallet-assets = { path = "../../../../../../substrate/frame/assets", default-features = false}
pallet-asset-conversion = { path = "../../../../../../substrate/frame/asset-conversion", default-features = false} pallet-asset-conversion = { path = "../../../../../../substrate/frame/asset-conversion", default-features = false}
@@ -26,15 +24,11 @@ polkadot-parachain-primitives = { path = "../../../../../../polkadot/parachain",
polkadot-runtime-parachains = { path = "../../../../../../polkadot/runtime/parachains" } polkadot-runtime-parachains = { path = "../../../../../../polkadot/runtime/parachains" }
polkadot-runtime = { path = "../../../../../../polkadot/runtime/polkadot" } polkadot-runtime = { path = "../../../../../../polkadot/runtime/polkadot" }
xcm = { package = "staging-xcm", path = "../../../../../../polkadot/xcm", default-features = false} xcm = { package = "staging-xcm", path = "../../../../../../polkadot/xcm", default-features = false}
xcm-executor = { package = "staging-xcm-executor", path = "../../../../../../polkadot/xcm/xcm-executor", default-features = false}
pallet-xcm = { path = "../../../../../../polkadot/xcm/pallet-xcm", default-features = false} pallet-xcm = { path = "../../../../../../polkadot/xcm/pallet-xcm", default-features = false}
# Cumulus # Cumulus
parachains-common = { path = "../../../../common" } parachains-common = { path = "../../../../common" }
asset-hub-kusama-runtime = { path = "../../../../runtimes/assets/asset-hub-kusama" } asset-hub-kusama-runtime = { path = "../../../../runtimes/assets/asset-hub-kusama" }
cumulus-pallet-dmp-queue = { path = "../../../../../pallets/dmp-queue" }
cumulus-pallet-xcmp-queue = { path = "../../../../../pallets/xcmp-queue", default-features = false}
cumulus-pallet-parachain-system = { path = "../../../../../pallets/parachain-system" }
# Local # Local
xcm-emulator = { path = "../../../../../xcm/xcm-emulator", default-features = false} xcm-emulator = { path = "../../../../../xcm/xcm-emulator", default-features = false}
@@ -17,42 +17,28 @@
pub use codec::Encode; pub use codec::Encode;
pub use frame_support::{ pub use frame_support::{
assert_err, assert_ok, assert_err, assert_ok,
instances::Instance1,
pallet_prelude::Weight, pallet_prelude::Weight,
sp_runtime::{AccountId32, DispatchError, DispatchResult, MultiAddress}, sp_runtime::{AccountId32, DispatchError, DispatchResult},
traits::{fungibles::Inspect, OriginTrait}, traits::fungibles::Inspect,
}; };
pub use integration_tests_common::{ pub use integration_tests_common::{
constants::{ constants::{
accounts::{ALICE, BOB}, asset_hub_kusama::ED as ASSET_HUB_KUSAMA_ED, kusama::ED as KUSAMA_ED, PROOF_SIZE_THRESHOLD,
asset_hub_kusama::ED as ASSET_HUB_KUSAMA_ED, REF_TIME_THRESHOLD, XCM_V3,
kusama::ED as KUSAMA_ED,
PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3,
}, },
lazy_static::lazy_static, xcm_helpers::{xcm_transact_paid_execution, xcm_transact_unpaid_execution},
xcm_transact_paid_execution, xcm_transact_unpaid_execution, AccountId, AssetHubKusama, AssetHubKusama, AssetHubKusamaPallet, AssetHubKusamaReceiver, AssetHubKusamaSender, Kusama,
AssetHubKusamaPallet, AssetHubKusamaReceiver, AssetHubKusamaSender, BridgeHubKusama, KusamaPallet, KusamaReceiver, KusamaSender, PenpalKusamaA, PenpalKusamaAPallet,
BridgeHubKusamaPallet, BridgeHubKusamaReceiver, BridgeHubKusamaSender, BridgeHubPolkadot, PenpalKusamaAReceiver, PenpalKusamaASender,
BridgeHubPolkadotPallet, BridgeHubPolkadotReceiver, BridgeHubPolkadotSender, Collectives,
CollectivesPallet, CollectivesReceiver, CollectivesSender, Kusama, KusamaMockNet, KusamaPallet,
KusamaReceiver, KusamaSender, PenpalKusamaA, PenpalKusamaAPallet, PenpalKusamaAReceiver,
PenpalKusamaASender, PenpalKusamaB, PenpalKusamaBPallet, PenpalKusamaBReceiver,
PenpalKusamaBSender, PenpalPolkadotA, PenpalPolkadotAReceiver, PenpalPolkadotASender, Polkadot,
PolkadotMockNet, PolkadotPallet, PolkadotReceiver, PolkadotSender,
}; };
pub use parachains_common::Balance; pub use parachains_common::{AccountId, Balance};
pub use polkadot_core_primitives::InboundDownwardMessage;
pub use polkadot_parachain_primitives::primitives::{HrmpChannelId, Id};
pub use polkadot_runtime_parachains::inclusion::{AggregateMessageOrigin, UmpQueueId};
pub use xcm::{ pub use xcm::{
prelude::*, prelude::{AccountId32 as AccountId32Junction, *},
v3::{Error, NetworkId::Kusama as KusamaId}, v3::{Error, NetworkId::Kusama as KusamaId},
DoubleEncoded,
}; };
pub use xcm_emulator::{ pub use xcm_emulator::{
assert_expected_events, bx, cumulus_pallet_dmp_queue, helpers::weight_within_threshold, assert_expected_events, bx, helpers::weight_within_threshold, Chain, Parachain as Para,
AccountId32Junction, Chain, ParaId, Parachain as Para, RelayChain as Relay, Test, TestArgs, RelayChain as Relay, Test, TestArgs, TestContext, TestExt,
TestContext, TestExt, TestExternalities,
}; };
pub const ASSET_ID: u32 = 1; pub const ASSET_ID: u32 = 1;
@@ -13,10 +13,9 @@ codec = { package = "parity-scale-codec", version = "3.4.0", default-features =
sp-runtime = { path = "../../../../../../substrate/primitives/runtime", default-features = false} sp-runtime = { path = "../../../../../../substrate/primitives/runtime", default-features = false}
frame-support = { path = "../../../../../../substrate/frame/support", default-features = false} frame-support = { path = "../../../../../../substrate/frame/support", default-features = false}
frame-system = { path = "../../../../../../substrate/frame/system", default-features = false} frame-system = { path = "../../../../../../substrate/frame/system", default-features = false}
sp-core = { path = "../../../../../../substrate/primitives/core", default-features = false}
sp-weights = { path = "../../../../../../substrate/primitives/weights", default-features = false}
pallet-balances = { path = "../../../../../../substrate/frame/balances", default-features = false} pallet-balances = { path = "../../../../../../substrate/frame/balances", default-features = false}
pallet-assets = { path = "../../../../../../substrate/frame/assets", default-features = false} pallet-assets = { path = "../../../../../../substrate/frame/assets", default-features = false}
pallet-asset-conversion = { path = "../../../../../../substrate/frame/asset-conversion", default-features = false}
# Polkadot # Polkadot
polkadot-core-primitives = { path = "../../../../../../polkadot/core-primitives", default-features = false} polkadot-core-primitives = { path = "../../../../../../polkadot/core-primitives", default-features = false}
@@ -24,14 +23,11 @@ polkadot-parachain-primitives = { path = "../../../../../../polkadot/parachain",
polkadot-runtime-parachains = { path = "../../../../../../polkadot/runtime/parachains" } polkadot-runtime-parachains = { path = "../../../../../../polkadot/runtime/parachains" }
polkadot-runtime = { path = "../../../../../../polkadot/runtime/polkadot" } polkadot-runtime = { path = "../../../../../../polkadot/runtime/polkadot" }
xcm = { package = "staging-xcm", path = "../../../../../../polkadot/xcm", default-features = false} xcm = { package = "staging-xcm", path = "../../../../../../polkadot/xcm", default-features = false}
xcm-executor = { package = "staging-xcm-executor", path = "../../../../../../polkadot/xcm/xcm-executor", default-features = false}
pallet-xcm = { path = "../../../../../../polkadot/xcm/pallet-xcm", default-features = false} pallet-xcm = { path = "../../../../../../polkadot/xcm/pallet-xcm", default-features = false}
# Cumulus # Cumulus
parachains-common = { path = "../../../../common" } parachains-common = { path = "../../../../common" }
cumulus-pallet-dmp-queue = { path = "../../../../../pallets/dmp-queue" } asset-hub-kusama-runtime = { path = "../../../../runtimes/assets/asset-hub-kusama" }
cumulus-pallet-xcmp-queue = { path = "../../../../../pallets/xcmp-queue", default-features = false}
cumulus-pallet-parachain-system = { path = "../../../../../pallets/parachain-system" }
# Local # Local
xcm-emulator = { path = "../../../../../xcm/xcm-emulator", default-features = false} xcm-emulator = { path = "../../../../../xcm/xcm-emulator", default-features = false}
@@ -17,40 +17,28 @@
pub use codec::Encode; pub use codec::Encode;
pub use frame_support::{ pub use frame_support::{
assert_err, assert_ok, assert_err, assert_ok,
instances::Instance1,
pallet_prelude::Weight, pallet_prelude::Weight,
sp_runtime::{AccountId32, DispatchError, DispatchResult, MultiAddress}, sp_runtime::{AccountId32, DispatchError, DispatchResult},
traits::{fungibles::Inspect, OriginTrait}, traits::fungibles::Inspect,
}; };
pub use integration_tests_common::{ pub use integration_tests_common::{
constants::{ constants::{
accounts::{ALICE, BOB}, asset_hub_polkadot::ED as ASSET_HUB_POLKADOT_ED, polkadot::ED as POLKADOT_ED,
asset_hub_polkadot::ED as ASSET_HUB_POLKADOT_ED,
polkadot::ED as POLKADOT_ED,
PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3, PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3,
}, },
lazy_static::lazy_static, xcm_helpers::{xcm_transact_paid_execution, xcm_transact_unpaid_execution},
xcm_transact_paid_execution, xcm_transact_unpaid_execution, AssetHubPolkadot, AssetHubPolkadot, AssetHubPolkadotPallet, AssetHubPolkadotReceiver, AssetHubPolkadotSender,
AssetHubPolkadotPallet, AssetHubPolkadotReceiver, AssetHubPolkadotSender, BridgeHubPolkadot, PenpalPolkadotA, PenpalPolkadotAReceiver, Polkadot, PolkadotPallet, PolkadotReceiver,
BridgeHubPolkadotPallet, BridgeHubPolkadotReceiver, BridgeHubPolkadotSender, Collectives, PolkadotSender,
CollectivesPallet, CollectivesReceiver, CollectivesSender, PenpalPolkadotA,
PenpalPolkadotAPallet, PenpalPolkadotAReceiver, PenpalPolkadotASender, PenpalPolkadotB,
PenpalPolkadotBPallet, PenpalPolkadotBReceiver, PenpalPolkadotBSender, Polkadot,
PolkadotMockNet, PolkadotPallet, PolkadotReceiver, PolkadotSender,
}; };
pub use parachains_common::{AccountId, Balance}; pub use parachains_common::{AccountId, Balance};
pub use polkadot_core_primitives::InboundDownwardMessage;
pub use polkadot_parachain_primitives::primitives::{HrmpChannelId, Id};
pub use polkadot_runtime_parachains::inclusion::{AggregateMessageOrigin, UmpQueueId};
pub use xcm::{ pub use xcm::{
prelude::*, prelude::{AccountId32 as AccountId32Junction, *},
v3::{Error, NetworkId::Polkadot as PolkadotId}, v3::{Error, NetworkId::Polkadot as PolkadotId},
DoubleEncoded,
}; };
pub use xcm_emulator::{ pub use xcm_emulator::{
assert_expected_events, bx, cumulus_pallet_dmp_queue, helpers::weight_within_threshold, assert_expected_events, bx, helpers::weight_within_threshold, Chain, Parachain as Para,
AccountId32Junction, Chain, ParaId, Parachain as Para, RelayChain as Relay, Test, TestArgs, RelayChain as Relay, Test, TestArgs, TestContext, TestExt,
TestContext, TestExt, TestExternalities,
}; };
pub const ASSET_ID: u32 = 1; pub const ASSET_ID: u32 = 1;
@@ -14,8 +14,6 @@ assert_matches = "1.5.0"
sp-runtime = { path = "../../../../../../substrate/primitives/runtime", default-features = false} sp-runtime = { path = "../../../../../../substrate/primitives/runtime", default-features = false}
frame-support = { path = "../../../../../../substrate/frame/support", default-features = false} frame-support = { path = "../../../../../../substrate/frame/support", default-features = false}
frame-system = { path = "../../../../../../substrate/frame/system", default-features = false} frame-system = { path = "../../../../../../substrate/frame/system", default-features = false}
sp-core = { path = "../../../../../../substrate/primitives/core", default-features = false}
sp-weights = { path = "../../../../../../substrate/primitives/weights", default-features = false}
pallet-balances = { path = "../../../../../../substrate/frame/balances", default-features = false} pallet-balances = { path = "../../../../../../substrate/frame/balances", default-features = false}
pallet-assets = { path = "../../../../../../substrate/frame/assets", default-features = false} pallet-assets = { path = "../../../../../../substrate/frame/assets", default-features = false}
pallet-asset-conversion = { path = "../../../../../../substrate/frame/asset-conversion", default-features = false} pallet-asset-conversion = { path = "../../../../../../substrate/frame/asset-conversion", default-features = false}
@@ -26,15 +24,11 @@ polkadot-parachain-primitives = { path = "../../../../../../polkadot/parachain",
polkadot-runtime-parachains = { path = "../../../../../../polkadot/runtime/parachains" } polkadot-runtime-parachains = { path = "../../../../../../polkadot/runtime/parachains" }
polkadot-runtime = { path = "../../../../../../polkadot/runtime/polkadot" } polkadot-runtime = { path = "../../../../../../polkadot/runtime/polkadot" }
xcm = { package = "staging-xcm", path = "../../../../../../polkadot/xcm", default-features = false} xcm = { package = "staging-xcm", path = "../../../../../../polkadot/xcm", default-features = false}
xcm-executor = { package = "staging-xcm-executor", path = "../../../../../../polkadot/xcm/xcm-executor", default-features = false}
pallet-xcm = { path = "../../../../../../polkadot/xcm/pallet-xcm", default-features = false} pallet-xcm = { path = "../../../../../../polkadot/xcm/pallet-xcm", default-features = false}
# Cumulus # Cumulus
parachains-common = { path = "../../../../common" } parachains-common = { path = "../../../../common" }
asset-hub-westend-runtime = { path = "../../../../runtimes/assets/asset-hub-westend" } asset-hub-westend-runtime = { path = "../../../../runtimes/assets/asset-hub-westend" }
cumulus-pallet-dmp-queue = { path = "../../../../../pallets/dmp-queue" }
cumulus-pallet-xcmp-queue = { path = "../../../../../pallets/xcmp-queue", default-features = false}
cumulus-pallet-parachain-system = { path = "../../../../../pallets/parachain-system" }
# Local # Local
xcm-emulator = { path = "../../../../../xcm/xcm-emulator", default-features = false} xcm-emulator = { path = "../../../../../xcm/xcm-emulator", default-features = false}
@@ -17,39 +17,30 @@
pub use codec::Encode; pub use codec::Encode;
pub use frame_support::{ pub use frame_support::{
assert_err, assert_ok, assert_err, assert_ok,
instances::{Instance1, Instance2}, instances::Instance2,
pallet_prelude::Weight, pallet_prelude::Weight,
sp_runtime::{AccountId32, DispatchError, DispatchResult, ModuleError, MultiAddress}, sp_runtime::{AccountId32, DispatchError, DispatchResult, ModuleError},
traits::{fungibles::Inspect, OriginTrait}, traits::fungibles::Inspect,
BoundedVec, BoundedVec,
}; };
pub use integration_tests_common::{ pub use integration_tests_common::{
constants::{ constants::{
accounts::{ALICE, BOB}, asset_hub_westend::ED as ASSET_HUB_WESTEND_ED, westend::ED as WESTEND_ED,
asset_hub_westend::ED as ASSET_HUB_WESTEND_ED,
westend::ED as WESTEND_ED,
PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3, PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3,
}, },
lazy_static::lazy_static, xcm_helpers::{xcm_transact_paid_execution, xcm_transact_unpaid_execution},
xcm_transact_paid_execution, xcm_transact_unpaid_execution, AssetHubWestend, AssetHubWestend, AssetHubWestendPallet, AssetHubWestendReceiver, AssetHubWestendSender,
AssetHubWestendPallet, AssetHubWestendReceiver, AssetHubWestendSender, Collectives, PenpalWestendA, PenpalWestendAPallet, PenpalWestendAReceiver, PenpalWestendASender, Westend,
CollectivesPallet, CollectivesReceiver, CollectivesSender, PenpalWestendA,
PenpalWestendAPallet, PenpalWestendAReceiver, PenpalWestendASender, Westend, WestendMockNet,
WestendPallet, WestendReceiver, WestendSender, WestendPallet, WestendReceiver, WestendSender,
}; };
pub use parachains_common::{AccountId, Balance}; pub use parachains_common::{AccountId, Balance};
pub use polkadot_core_primitives::InboundDownwardMessage;
pub use polkadot_parachain_primitives::primitives::{HrmpChannelId, Id};
pub use polkadot_runtime_parachains::inclusion::{AggregateMessageOrigin, UmpQueueId};
pub use xcm::{ pub use xcm::{
prelude::*, prelude::{AccountId32 as AccountId32Junction, *},
v3::{Error, NetworkId::Westend as WestendId}, v3::{Error, NetworkId::Westend as WestendId},
DoubleEncoded,
}; };
pub use xcm_emulator::{ pub use xcm_emulator::{
assert_expected_events, bx, cumulus_pallet_dmp_queue, helpers::weight_within_threshold, assert_expected_events, bx, helpers::weight_within_threshold, Chain, Parachain as Para,
AccountId32Junction, Chain, ParaId, Parachain as Para, RelayChain as Relay, Test, TestArgs, RelayChain as Relay, Test, TestArgs, TestContext, TestExt,
TestContext, TestExt, TestExternalities,
}; };
pub const ASSET_ID: u32 = 1; pub const ASSET_ID: u32 = 1;
@@ -10,13 +10,7 @@ publish = false
codec = { package = "parity-scale-codec", version = "3.4.0", default-features = false } codec = { package = "parity-scale-codec", version = "3.4.0", default-features = false }
# Substrate # Substrate
sp-runtime = { path = "../../../../../../substrate/primitives/runtime", default-features = false}
frame-support = { path = "../../../../../../substrate/frame/support", default-features = false} frame-support = { path = "../../../../../../substrate/frame/support", default-features = false}
frame-system = { path = "../../../../../../substrate/frame/system", default-features = false}
sp-core = { path = "../../../../../../substrate/primitives/core", default-features = false}
sp-weights = { path = "../../../../../../substrate/primitives/weights", default-features = false}
pallet-balances = { path = "../../../../../../substrate/frame/balances", default-features = false}
pallet-assets = { path = "../../../../../../substrate/frame/assets", default-features = false}
# Polkadot # Polkadot
polkadot-core-primitives = { path = "../../../../../../polkadot/core-primitives", default-features = false} polkadot-core-primitives = { path = "../../../../../../polkadot/core-primitives", default-features = false}
@@ -24,13 +18,12 @@ polkadot-parachain-primitives = { path = "../../../../../../polkadot/parachain",
polkadot-runtime-parachains = { path = "../../../../../../polkadot/runtime/parachains" } polkadot-runtime-parachains = { path = "../../../../../../polkadot/runtime/parachains" }
polkadot-runtime = { path = "../../../../../../polkadot/runtime/polkadot" } polkadot-runtime = { path = "../../../../../../polkadot/runtime/polkadot" }
xcm = { package = "staging-xcm", path = "../../../../../../polkadot/xcm", default-features = false} xcm = { package = "staging-xcm", path = "../../../../../../polkadot/xcm", default-features = false}
xcm-executor = { package = "staging-xcm-executor", path = "../../../../../../polkadot/xcm/xcm-executor", default-features = false}
pallet-xcm = { path = "../../../../../../polkadot/xcm/pallet-xcm", default-features = false} pallet-xcm = { path = "../../../../../../polkadot/xcm/pallet-xcm", default-features = false}
# Cumulus # Cumulus
parachains-common = { path = "../../../../common" } parachains-common = { path = "../../../../common" }
cumulus-pallet-xcmp-queue = { path = "../../../../../pallets/xcmp-queue", default-features = false} cumulus-pallet-xcmp-queue = { path = "../../../../../pallets/xcmp-queue", default-features = false}
cumulus-pallet-parachain-system = { path = "../../../../../pallets/parachain-system" } cumulus-pallet-dmp-queue = { path = "../../../../../pallets/dmp-queue", default-features = false}
pallet-bridge-messages = { path = "../../../../../bridges/modules/messages", default-features = false} pallet-bridge-messages = { path = "../../../../../bridges/modules/messages", default-features = false}
bp-messages = { path = "../../../../../bridges/primitives/messages", default-features = false} bp-messages = { path = "../../../../../bridges/primitives/messages", default-features = false}
@@ -15,48 +15,27 @@
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>. // along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
pub use bp_messages::LaneId; pub use bp_messages::LaneId;
pub use codec::Encode; pub use frame_support::assert_ok;
pub use frame_support::{
assert_err, assert_ok,
instances::Instance1,
pallet_prelude::Weight,
sp_runtime::{AccountId32, DispatchError, DispatchResult, MultiAddress},
traits::{fungibles::Inspect, OriginTrait},
};
pub use integration_tests_common::{ pub use integration_tests_common::{
constants::{ constants::{
accounts::{ALICE, BOB}, asset_hub_kusama::ED as ASSET_HUB_ROCOCO_ED, kusama::ED as ROCOCO_ED, PROOF_SIZE_THRESHOLD,
asset_hub_kusama::ED as ASSET_HUB_ROCOCO_ED, REF_TIME_THRESHOLD, XCM_V3,
kusama::ED as ROCOCO_ED,
PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3,
}, },
lazy_static::lazy_static, xcm_helpers::{xcm_transact_paid_execution, xcm_transact_unpaid_execution},
xcm_transact_paid_execution, xcm_transact_unpaid_execution, AssetHubRococo, AssetHubRococo, AssetHubRococoReceiver, AssetHubWococo, BridgeHubRococo, BridgeHubWococo,
AssetHubRococoPallet, AssetHubRococoReceiver, AssetHubRococoSender, AssetHubWococo, PenpalRococoA, Rococo, RococoPallet,
AssetHubWococoPallet, AssetHubWococoReceiver, AssetHubWococoSender, BridgeHubRococo,
BridgeHubRococoPallet, BridgeHubRococoReceiver, BridgeHubRococoSender, BridgeHubWococo,
BridgeHubWococoPallet, BridgeHubWococoReceiver, BridgeHubWococoSender, Collectives,
CollectivesPallet, CollectivesReceiver, CollectivesSender, PenpalRococoA, PenpalRococoAPallet,
PenpalRococoAReceiver, PenpalRococoASender, Rococo, RococoMockNet, RococoPallet,
RococoReceiver, RococoSender, Wococo, WococoMockNet, WococoPallet, WococoReceiver,
WococoSender,
}; };
pub use parachains_common::{AccountId, Balance}; pub use parachains_common::{AccountId, Balance};
pub use polkadot_core_primitives::InboundDownwardMessage;
pub use polkadot_parachain_primitives::primitives::{HrmpChannelId, Id};
pub use polkadot_runtime_parachains::inclusion::{AggregateMessageOrigin, UmpQueueId};
pub use xcm::{ pub use xcm::{
prelude::*, prelude::{AccountId32 as AccountId32Junction, *},
v3::{ v3::{
Error, Error,
NetworkId::{Rococo as RococoId, Wococo as WococoId}, NetworkId::{Rococo as RococoId, Wococo as WococoId},
}, },
DoubleEncoded,
}; };
pub use xcm_emulator::{ pub use xcm_emulator::{
assert_expected_events, bx, cumulus_pallet_dmp_queue, helpers::weight_within_threshold, assert_expected_events, bx, helpers::weight_within_threshold, Chain, Parachain as Para,
AccountId32Junction, Chain, ParaId, Parachain as Para, RelayChain as Relay, Test, TestArgs, RelayChain as Relay, Test, TestArgs, TestContext, TestExt,
TestContext, TestExt, TestExternalities,
}; };
pub const ASSET_ID: u32 = 1; pub const ASSET_ID: u32 = 1;
@@ -12,10 +12,7 @@ codec = { package = "parity-scale-codec", version = "3.4.0", default-features =
# Substrate # Substrate
sp-runtime = { path = "../../../../../../substrate/primitives/runtime", default-features = false} sp-runtime = { path = "../../../../../../substrate/primitives/runtime", default-features = false}
frame-support = { path = "../../../../../../substrate/frame/support", default-features = false} frame-support = { path = "../../../../../../substrate/frame/support", default-features = false}
frame-system = { path = "../../../../../../substrate/frame/system", default-features = false}
sp-core = { path = "../../../../../../substrate/primitives/core", default-features = false} sp-core = { path = "../../../../../../substrate/primitives/core", default-features = false}
sp-weights = { path = "../../../../../../substrate/primitives/weights", default-features = false}
pallet-balances = { path = "../../../../../../substrate/frame/balances", default-features = false}
pallet-assets = { path = "../../../../../../substrate/frame/assets", default-features = false} pallet-assets = { path = "../../../../../../substrate/frame/assets", default-features = false}
pallet-core-fellowship = { path = "../../../../../../substrate/frame/core-fellowship", default-features = false} pallet-core-fellowship = { path = "../../../../../../substrate/frame/core-fellowship", default-features = false}
pallet-salary = { path = "../../../../../../substrate/frame/salary", default-features = false} pallet-salary = { path = "../../../../../../substrate/frame/salary", default-features = false}
@@ -26,7 +23,6 @@ polkadot-parachain-primitives = { path = "../../../../../../polkadot/parachain",
polkadot-runtime-parachains = { path = "../../../../../../polkadot/runtime/parachains" } polkadot-runtime-parachains = { path = "../../../../../../polkadot/runtime/parachains" }
polkadot-runtime = { path = "../../../../../../polkadot/runtime/polkadot" } polkadot-runtime = { path = "../../../../../../polkadot/runtime/polkadot" }
xcm = { package = "staging-xcm", path = "../../../../../../polkadot/xcm", default-features = false} xcm = { package = "staging-xcm", path = "../../../../../../polkadot/xcm", default-features = false}
xcm-executor = { package = "staging-xcm-executor", path = "../../../../../../polkadot/xcm/xcm-executor", default-features = false}
pallet-xcm = { path = "../../../../../../polkadot/xcm/pallet-xcm", default-features = false} pallet-xcm = { path = "../../../../../../polkadot/xcm/pallet-xcm", default-features = false}
# Cumulus # Cumulus
@@ -34,7 +30,6 @@ parachains-common = { path = "../../../../common" }
cumulus-pallet-xcmp-queue = { path = "../../../../../pallets/xcmp-queue", default-features = false} cumulus-pallet-xcmp-queue = { path = "../../../../../pallets/xcmp-queue", default-features = false}
cumulus-pallet-parachain-system = { path = "../../../../../pallets/parachain-system" } cumulus-pallet-parachain-system = { path = "../../../../../pallets/parachain-system" }
collectives-polkadot-runtime = { path = "../../../../runtimes/collectives/collectives-polkadot" } collectives-polkadot-runtime = { path = "../../../../runtimes/collectives/collectives-polkadot" }
asset-hub-polkadot-runtime = { path = "../../../../runtimes/assets/asset-hub-polkadot" }
# Local # Local
xcm-emulator = { path = "../../../../../xcm/xcm-emulator", default-features = false} xcm-emulator = { path = "../../../../../xcm/xcm-emulator", default-features = false}
@@ -15,42 +15,24 @@
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>. // along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
pub use codec::Encode; pub use codec::Encode;
pub use frame_support::{ pub use frame_support::{assert_ok, sp_runtime::AccountId32};
assert_err, assert_ok,
instances::Instance1,
pallet_prelude::Weight,
sp_runtime::{AccountId32, DispatchError, DispatchResult, MultiAddress},
traits::{fungibles::Inspect, OriginTrait},
};
pub use integration_tests_common::{ pub use integration_tests_common::{
constants::{ constants::{
accounts::{ALICE, BOB}, accounts::ALICE, asset_hub_polkadot::ED as ASSET_HUB_POLKADOT_ED,
asset_hub_polkadot::ED as ASSET_HUB_POLKADOT_ED, polkadot::ED as POLKADOT_ED, PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3,
polkadot::ED as POLKADOT_ED,
PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3,
}, },
lazy_static::lazy_static, xcm_helpers::{xcm_transact_paid_execution, xcm_transact_unpaid_execution},
xcm_transact_paid_execution, xcm_transact_unpaid_execution, AssetHubPolkadot, AssetHubPolkadot, AssetHubPolkadotPallet, AssetHubPolkadotReceiver, Collectives,
AssetHubPolkadotPallet, AssetHubPolkadotReceiver, AssetHubPolkadotSender, BridgeHubPolkadot, PenpalPolkadotA, Polkadot,
BridgeHubPolkadotPallet, BridgeHubPolkadotReceiver, BridgeHubPolkadotSender, Collectives,
CollectivesPallet, CollectivesReceiver, CollectivesSender, PenpalPolkadotA,
PenpalPolkadotAPallet, PenpalPolkadotAReceiver, PenpalPolkadotASender, PenpalPolkadotB,
PenpalPolkadotBPallet, PenpalPolkadotBReceiver, PenpalPolkadotBSender, Polkadot,
PolkadotMockNet, PolkadotPallet, PolkadotReceiver, PolkadotSender,
}; };
pub use parachains_common::{AccountId, Balance}; pub use parachains_common::{AccountId, Balance};
pub use polkadot_core_primitives::InboundDownwardMessage;
pub use polkadot_parachain_primitives::primitives::{HrmpChannelId, Id};
pub use polkadot_runtime_parachains::inclusion::{AggregateMessageOrigin, UmpQueueId};
pub use xcm::{ pub use xcm::{
prelude::*, prelude::{AccountId32 as AccountId32Junction, *},
v3::{Error, NetworkId::Polkadot as PolkadotId}, v3::{Error, NetworkId::Polkadot as PolkadotId},
DoubleEncoded,
}; };
pub use xcm_emulator::{ pub use xcm_emulator::{
assert_expected_events, bx, cumulus_pallet_dmp_queue, helpers::weight_within_threshold, assert_expected_events, bx, helpers::weight_within_threshold, Chain, ParaId, Parachain as Para,
AccountId32Junction, Chain, ParaId, Parachain as Para, RelayChain as Relay, Test, TestArgs, RelayChain as Relay, Test, TestArgs, TestContext, TestExt, TestExternalities,
TestContext, TestExt, TestExternalities,
}; };
pub const ASSET_ID: u32 = 1; pub const ASSET_ID: u32 = 1;
@@ -8,7 +8,6 @@ publish = false
[dependencies] [dependencies]
codec = { package = "parity-scale-codec", version = "3.4.0", default-features = false } codec = { package = "parity-scale-codec", version = "3.4.0", default-features = false }
lazy_static = "1.4.0"
paste = "1.0.14" paste = "1.0.14"
# Substrate # Substrate
@@ -16,12 +15,8 @@ grandpa = { package = "sc-consensus-grandpa", path = "../../../../../substrate/c
sp-authority-discovery = { path = "../../../../../substrate/primitives/authority-discovery", default-features = false} sp-authority-discovery = { path = "../../../../../substrate/primitives/authority-discovery", default-features = false}
sp-runtime = { path = "../../../../../substrate/primitives/runtime", default-features = false} sp-runtime = { path = "../../../../../substrate/primitives/runtime", default-features = false}
frame-support = { path = "../../../../../substrate/frame/support", default-features = false} frame-support = { path = "../../../../../substrate/frame/support", default-features = false}
frame-system = { path = "../../../../../substrate/frame/system", default-features = false}
sp-core = { path = "../../../../../substrate/primitives/core", default-features = false} sp-core = { path = "../../../../../substrate/primitives/core", default-features = false}
sp-weights = { path = "../../../../../substrate/primitives/weights", default-features = false}
sp-consensus-babe = { path = "../../../../../substrate/primitives/consensus/babe", default-features = false} sp-consensus-babe = { path = "../../../../../substrate/primitives/consensus/babe", default-features = false}
sp-tracing = { path = "../../../../../substrate/primitives/tracing" }
pallet-balances = { path = "../../../../../substrate/frame/balances", default-features = false}
pallet-assets = { path = "../../../../../substrate/frame/assets", default-features = false} pallet-assets = { path = "../../../../../substrate/frame/assets", default-features = false}
pallet-staking = { path = "../../../../../substrate/frame/staking", default-features = false} pallet-staking = { path = "../../../../../substrate/frame/staking", default-features = false}
pallet-message-queue = { path = "../../../../../substrate/frame/message-queue", default-features = false} pallet-message-queue = { path = "../../../../../substrate/frame/message-queue", default-features = false}
@@ -43,12 +38,10 @@ rococo-runtime-constants = { path = "../../../../../polkadot/runtime/rococo/cons
westend-runtime = { path = "../../../../../polkadot/runtime/westend" } westend-runtime = { path = "../../../../../polkadot/runtime/westend" }
westend-runtime-constants = { path = "../../../../../polkadot/runtime/westend/constants" } westend-runtime-constants = { path = "../../../../../polkadot/runtime/westend/constants" }
xcm = { package = "staging-xcm", path = "../../../../../polkadot/xcm", default-features = false} xcm = { package = "staging-xcm", path = "../../../../../polkadot/xcm", default-features = false}
xcm-executor = { package = "staging-xcm-executor", path = "../../../../../polkadot/xcm/xcm-executor", default-features = false}
pallet-xcm = { path = "../../../../../polkadot/xcm/pallet-xcm", default-features = false} pallet-xcm = { path = "../../../../../polkadot/xcm/pallet-xcm", default-features = false}
# Cumulus # Cumulus
parachains-common = { path = "../../../common" } parachains-common = { path = "../../../common" }
parachain-info = { path = "../../../pallets/parachain-info" }
cumulus-primitives-core = { path = "../../../../primitives/core" } cumulus-primitives-core = { path = "../../../../primitives/core" }
penpal-runtime = { path = "../../../runtimes/testing/penpal" } penpal-runtime = { path = "../../../runtimes/testing/penpal" }
asset-hub-polkadot-runtime = { path = "../../../runtimes/assets/asset-hub-polkadot" } asset-hub-polkadot-runtime = { path = "../../../runtimes/assets/asset-hub-polkadot" }
@@ -63,7 +56,6 @@ cumulus-pallet-dmp-queue = { path = "../../../../pallets/dmp-queue" }
cumulus-pallet-xcmp-queue = { path = "../../../../pallets/xcmp-queue", default-features = false} cumulus-pallet-xcmp-queue = { path = "../../../../pallets/xcmp-queue", default-features = false}
cumulus-pallet-parachain-system = { path = "../../../../pallets/parachain-system" } cumulus-pallet-parachain-system = { path = "../../../../pallets/parachain-system" }
bp-messages = { path = "../../../../bridges/primitives/messages" } bp-messages = { path = "../../../../bridges/primitives/messages" }
bp-runtime = { path = "../../../../bridges/primitives/runtime" }
pallet-bridge-messages = { path = "../../../../bridges/modules/messages" } pallet-bridge-messages = { path = "../../../../bridges/modules/messages" }
bridge-runtime-common = { path = "../../../../bridges/bin/runtime-common" } bridge-runtime-common = { path = "../../../../bridges/bin/runtime-common" }
@@ -80,10 +72,8 @@ runtime-benchmarks = [
"cumulus-pallet-parachain-system/runtime-benchmarks", "cumulus-pallet-parachain-system/runtime-benchmarks",
"cumulus-pallet-xcmp-queue/runtime-benchmarks", "cumulus-pallet-xcmp-queue/runtime-benchmarks",
"frame-support/runtime-benchmarks", "frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"kusama-runtime/runtime-benchmarks", "kusama-runtime/runtime-benchmarks",
"pallet-assets/runtime-benchmarks", "pallet-assets/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-bridge-messages/runtime-benchmarks", "pallet-bridge-messages/runtime-benchmarks",
"pallet-im-online/runtime-benchmarks", "pallet-im-online/runtime-benchmarks",
"pallet-message-queue/runtime-benchmarks", "pallet-message-queue/runtime-benchmarks",
@@ -98,5 +88,4 @@ runtime-benchmarks = [
"rococo-runtime/runtime-benchmarks", "rococo-runtime/runtime-benchmarks",
"sp-runtime/runtime-benchmarks", "sp-runtime/runtime-benchmarks",
"westend-runtime/runtime-benchmarks", "westend-runtime/runtime-benchmarks",
"xcm-executor/runtime-benchmarks",
] ]
@@ -14,9 +14,19 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>. // along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
// Substrate
use beefy_primitives::ecdsa_crypto::AuthorityId as BeefyId; use beefy_primitives::ecdsa_crypto::AuthorityId as BeefyId;
use grandpa::AuthorityId as GrandpaId; use grandpa::AuthorityId as GrandpaId;
use pallet_im_online::sr25519::AuthorityId as ImOnlineId; use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId;
use sp_consensus_babe::AuthorityId as BabeId;
use sp_core::{sr25519, storage::Storage, Pair, Public};
use sp_runtime::{
traits::{IdentifyAccount, Verify},
BuildStorage, MultiSignature, Perbill,
};
// Cumulus
use parachains_common::{AccountId, AssetHubPolkadotAuraId, AuraId, Balance, BlockNumber}; use parachains_common::{AccountId, AssetHubPolkadotAuraId, AuraId, Balance, BlockNumber};
use polkadot_parachain_primitives::primitives::{HeadData, ValidationCode}; use polkadot_parachain_primitives::primitives::{HeadData, ValidationCode};
use polkadot_primitives::{AssignmentId, ValidatorId}; use polkadot_primitives::{AssignmentId, ValidatorId};
@@ -25,13 +35,6 @@ use polkadot_runtime_parachains::{
paras::{ParaGenesisArgs, ParaKind}, paras::{ParaGenesisArgs, ParaKind},
}; };
use polkadot_service::chain_spec::get_authority_keys_from_seed_no_beefy; use polkadot_service::chain_spec::get_authority_keys_from_seed_no_beefy;
use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId;
use sp_consensus_babe::AuthorityId as BabeId;
use sp_core::{sr25519, storage::Storage, Pair, Public};
use sp_runtime::{
traits::{IdentifyAccount, Verify},
BuildStorage, MultiSignature, Perbill,
};
use xcm; use xcm;
pub const XCM_V2: u32 = 3; pub const XCM_V2: u32 = 3;
@@ -14,18 +14,51 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>. // along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
use super::{BridgeHubRococo, BridgeHubWococo}; pub use codec::{Decode, Encode};
// pub use paste; pub use paste;
pub use crate::{
constants::{PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD},
xcm_helpers::xcm_transact_unpaid_execution,
BridgeHubRococo, BridgeHubWococo,
};
// Substrate
pub use frame_support::{assert_ok, traits::fungibles::Inspect};
pub use pallet_assets;
pub use pallet_message_queue;
use sp_core::Get;
// Cumulus
use bp_messages::{ use bp_messages::{
target_chain::{DispatchMessage, DispatchMessageData, MessageDispatch}, target_chain::{DispatchMessage, DispatchMessageData, MessageDispatch},
LaneId, MessageKey, OutboundLaneData, LaneId, MessageKey, OutboundLaneData,
}; };
use bridge_runtime_common::messages_xcm_extension::XcmBlobMessageDispatchResult; use bridge_runtime_common::messages_xcm_extension::XcmBlobMessageDispatchResult;
use codec::Decode; pub use cumulus_pallet_dmp_queue;
pub use cumulus_primitives_core::{DmpMessageHandler, XcmpMessageHandler}; pub use cumulus_pallet_parachain_system;
pub use cumulus_pallet_xcmp_queue;
pub use cumulus_primitives_core::{
relay_chain::HrmpChannelId, DmpMessageHandler, ParaId, XcmpMessageHandler,
};
use pallet_bridge_messages::{Config, Instance1, Instance2, OutboundLanes, Pallet}; use pallet_bridge_messages::{Config, Instance1, Instance2, OutboundLanes, Pallet};
use sp_core::Get; pub use parachains_common::{AccountId, Balance};
use xcm_emulator::{BridgeMessage, BridgeMessageDispatchError, BridgeMessageHandler, Chain}; pub use xcm_emulator::{
assert_expected_events, bx, helpers::weight_within_threshold, BridgeMessage,
BridgeMessageDispatchError, BridgeMessageHandler, Chain, Parachain, RelayChain, TestExt,
};
// Polkadot
pub use pallet_xcm;
pub use polkadot_runtime_parachains::{
dmp, hrmp,
inclusion::{AggregateMessageOrigin, UmpQueueId},
};
pub use xcm::{
prelude::{OriginKind, Outcome, VersionedXcm, Weight},
v3::Error,
DoubleEncoded,
};
pub struct BridgeHubMessageHandler<S, T, I> { pub struct BridgeHubMessageHandler<S, T, I> {
_marker: std::marker::PhantomData<(S, T, I)>, _marker: std::marker::PhantomData<(S, T, I)>,
@@ -145,14 +178,14 @@ where
#[macro_export] #[macro_export]
macro_rules! impl_accounts_helpers_for_relay_chain { macro_rules! impl_accounts_helpers_for_relay_chain {
( $chain:ident ) => { ( $chain:ident ) => {
$crate::paste::paste! { $crate::impls::paste::paste! {
impl $chain { impl $chain {
/// Fund a set of accounts with a balance /// Fund a set of accounts with a balance
pub fn fund_accounts(accounts: Vec<(AccountId, Balance)>) { pub fn fund_accounts(accounts: Vec<($crate::impls::AccountId, $crate::impls::Balance)>) {
Self::execute_with(|| { <Self as $crate::impls::TestExt>::execute_with(|| {
for account in accounts { for account in accounts {
assert_ok!(<Self as [<$chain Pallet>]>::Balances::force_set_balance( $crate::impls::assert_ok!(<Self as [<$chain Pallet>]>::Balances::force_set_balance(
<Self as Chain>::RuntimeOrigin::root(), <Self as $crate::impls::Chain>::RuntimeOrigin::root(),
account.0.into(), account.0.into(),
account.1, account.1,
)); ));
@@ -160,8 +193,8 @@ macro_rules! impl_accounts_helpers_for_relay_chain {
}); });
} }
/// Fund a sovereign account based on its Parachain Id /// Fund a sovereign account based on its Parachain Id
pub fn fund_para_sovereign(amount: Balance, para_id: ParaId) -> sp_runtime::AccountId32 { pub fn fund_para_sovereign(amount: $crate::impls::Balance, para_id: $crate::impls::ParaId) -> sp_runtime::AccountId32 {
let sovereign_account = Self::sovereign_account_id_of_child_para(para_id); let sovereign_account = <Self as $crate::impls::RelayChain>::sovereign_account_id_of_child_para(para_id);
Self::fund_accounts(vec![(sovereign_account.clone(), amount)]); Self::fund_accounts(vec![(sovereign_account.clone(), amount)]);
sovereign_account sovereign_account
} }
@@ -173,20 +206,20 @@ macro_rules! impl_accounts_helpers_for_relay_chain {
#[macro_export] #[macro_export]
macro_rules! impl_assert_events_helpers_for_relay_chain { macro_rules! impl_assert_events_helpers_for_relay_chain {
( $chain:ident ) => { ( $chain:ident ) => {
$crate::paste::paste! { $crate::impls::paste::paste! {
type [<$chain RuntimeEvent>] = <$chain as Chain>::RuntimeEvent; type [<$chain RuntimeEvent>] = <$chain as $crate::impls::Chain>::RuntimeEvent;
impl $chain { impl $chain {
/// Asserts a dispatchable is completely executed and XCM sent /// Asserts a dispatchable is completely executed and XCM sent
pub fn assert_xcm_pallet_attempted_complete(expected_weight: Option<Weight>) { pub fn assert_xcm_pallet_attempted_complete(expected_weight: Option<$crate::impls::Weight>) {
assert_expected_events!( $crate::impls::assert_expected_events!(
Self, Self,
vec![ vec![
[<$chain RuntimeEvent>]::XcmPallet( [<$chain RuntimeEvent>]::XcmPallet(
pallet_xcm::Event::Attempted { outcome: Outcome::Complete(weight) } $crate::impls::pallet_xcm::Event::Attempted { outcome: $crate::impls::Outcome::Complete(weight) }
) => { ) => {
weight: weight_within_threshold( weight: $crate::impls::weight_within_threshold(
(REF_TIME_THRESHOLD, PROOF_SIZE_THRESHOLD), ($crate::impls::REF_TIME_THRESHOLD, $crate::impls::PROOF_SIZE_THRESHOLD),
expected_weight.unwrap_or(*weight), expected_weight.unwrap_or(*weight),
*weight *weight
), ),
@@ -197,18 +230,18 @@ macro_rules! impl_assert_events_helpers_for_relay_chain {
/// Asserts a dispatchable is incompletely executed and XCM sent /// Asserts a dispatchable is incompletely executed and XCM sent
pub fn assert_xcm_pallet_attempted_incomplete( pub fn assert_xcm_pallet_attempted_incomplete(
expected_weight: Option<Weight>, expected_weight: Option<$crate::impls::Weight>,
expected_error: Option<Error>, expected_error: Option<$crate::impls::Error>,
) { ) {
assert_expected_events!( $crate::impls::assert_expected_events!(
Self, Self,
vec![ vec![
// Dispatchable is properly executed and XCM message sent // Dispatchable is properly executed and XCM message sent
[<$chain RuntimeEvent>]::XcmPallet( [<$chain RuntimeEvent>]::XcmPallet(
pallet_xcm::Event::Attempted { outcome: Outcome::Incomplete(weight, error) } $crate::impls::pallet_xcm::Event::Attempted { outcome: $crate::impls::Outcome::Incomplete(weight, error) }
) => { ) => {
weight: weight_within_threshold( weight: $crate::impls::weight_within_threshold(
(REF_TIME_THRESHOLD, PROOF_SIZE_THRESHOLD), ($crate::impls::REF_TIME_THRESHOLD, $crate::impls::PROOF_SIZE_THRESHOLD),
expected_weight.unwrap_or(*weight), expected_weight.unwrap_or(*weight),
*weight *weight
), ),
@@ -220,10 +253,10 @@ macro_rules! impl_assert_events_helpers_for_relay_chain {
/// Asserts a XCM message is sent /// Asserts a XCM message is sent
pub fn assert_xcm_pallet_sent() { pub fn assert_xcm_pallet_sent() {
assert_expected_events!( $crate::impls::assert_expected_events!(
Self, Self,
vec![ vec![
[<$chain RuntimeEvent>]::XcmPallet(pallet_xcm::Event::Sent { .. }) => {}, [<$chain RuntimeEvent>]::XcmPallet($crate::impls::pallet_xcm::Event::Sent { .. }) => {},
] ]
); );
} }
@@ -231,22 +264,22 @@ macro_rules! impl_assert_events_helpers_for_relay_chain {
/// Asserts a XCM from System Parachain is succesfully received and proccessed /// Asserts a XCM from System Parachain is succesfully received and proccessed
pub fn assert_ump_queue_processed( pub fn assert_ump_queue_processed(
expected_success: bool, expected_success: bool,
expected_id: Option<ParaId>, expected_id: Option<$crate::impls::ParaId>,
expected_weight: Option<Weight>, expected_weight: Option<$crate::impls::Weight>,
) { ) {
assert_expected_events!( $crate::impls::assert_expected_events!(
Self, Self,
vec![ vec![
// XCM is succesfully received and proccessed // XCM is succesfully received and proccessed
[<$chain RuntimeEvent>]::MessageQueue(pallet_message_queue::Event::Processed { [<$chain RuntimeEvent>]::MessageQueue($crate::impls::pallet_message_queue::Event::Processed {
origin: AggregateMessageOrigin::Ump(UmpQueueId::Para(id)), origin: $crate::impls::AggregateMessageOrigin::Ump($crate::impls::UmpQueueId::Para(id)),
weight_used, weight_used,
success, success,
.. ..
}) => { }) => {
id: *id == expected_id.unwrap_or(*id), id: *id == expected_id.unwrap_or(*id),
weight_used: weight_within_threshold( weight_used: $crate::impls::weight_within_threshold(
(REF_TIME_THRESHOLD, PROOF_SIZE_THRESHOLD), ($crate::impls::REF_TIME_THRESHOLD, $crate::impls::PROOF_SIZE_THRESHOLD),
expected_weight.unwrap_or(*weight_used), expected_weight.unwrap_or(*weight_used),
*weight_used *weight_used
), ),
@@ -263,16 +296,18 @@ macro_rules! impl_assert_events_helpers_for_relay_chain {
#[macro_export] #[macro_export]
macro_rules! impl_hrmp_channels_helpers_for_relay_chain { macro_rules! impl_hrmp_channels_helpers_for_relay_chain {
( $chain:ident ) => { ( $chain:ident ) => {
$crate::paste::paste! { $crate::impls::paste::paste! {
impl $chain { impl $chain {
/// Init open channel request with another Parachain /// Init open channel request with another Parachain
pub fn init_open_channel_call( pub fn init_open_channel_call(
recipient_para_id: ParaId, recipient_para_id: $crate::impls::ParaId,
max_capacity: u32, max_capacity: u32,
max_message_size: u32, max_message_size: u32,
) -> DoubleEncoded<()> { ) -> $crate::impls::DoubleEncoded<()> {
<Self as Chain>::RuntimeCall::Hrmp(polkadot_runtime_parachains::hrmp::Call::< use $crate::impls::Encode;
<Self as Chain>::Runtime,
<Self as $crate::impls::Chain>::RuntimeCall::Hrmp($crate::impls::hrmp::Call::<
<Self as $crate::impls::Chain>::Runtime,
>::hrmp_init_open_channel { >::hrmp_init_open_channel {
recipient: recipient_para_id, recipient: recipient_para_id,
proposed_max_capacity: max_capacity, proposed_max_capacity: max_capacity,
@@ -282,9 +317,11 @@ macro_rules! impl_hrmp_channels_helpers_for_relay_chain {
.into() .into()
} }
/// Recipient Parachain accept the open request from another Parachain /// Recipient Parachain accept the open request from another Parachain
pub fn accept_open_channel_call(sender_para_id: ParaId) -> DoubleEncoded<()> { pub fn accept_open_channel_call(sender_para_id: $crate::impls::ParaId) -> $crate::impls::DoubleEncoded<()> {
<Self as Chain>::RuntimeCall::Hrmp(polkadot_runtime_parachains::hrmp::Call::< use $crate::impls::Encode;
<Self as Chain>::Runtime,
<Self as $crate::impls::Chain>::RuntimeCall::Hrmp($crate::impls::hrmp::Call::<
<Self as $crate::impls::Chain>::Runtime,
>::hrmp_accept_open_channel { >::hrmp_accept_open_channel {
sender: sender_para_id, sender: sender_para_id,
}) })
@@ -293,19 +330,21 @@ macro_rules! impl_hrmp_channels_helpers_for_relay_chain {
} }
/// A root origin force to open a channel between two Parachains /// A root origin force to open a channel between two Parachains
pub fn force_process_hrmp_open(sender: ParaId, recipient: ParaId) { pub fn force_process_hrmp_open(sender: $crate::impls::ParaId, recipient: $crate::impls::ParaId) {
Self::execute_with(|| { use $crate::impls::Chain;
<Self as $crate::impls::TestExt>::execute_with(|| {
let relay_root_origin = <Self as Chain>::RuntimeOrigin::root(); let relay_root_origin = <Self as Chain>::RuntimeOrigin::root();
// Force process HRMP open channel requests without waiting for the next session // Force process HRMP open channel requests without waiting for the next session
assert_ok!(<Self as [<$chain Pallet>]>::Hrmp::force_process_hrmp_open( $crate::impls::assert_ok!(<Self as [<$chain Pallet>]>::Hrmp::force_process_hrmp_open(
relay_root_origin, relay_root_origin,
0 0
)); ));
let channel_id = HrmpChannelId { sender, recipient }; let channel_id = $crate::impls::HrmpChannelId { sender, recipient };
let hrmp_channel_exist = polkadot_runtime_parachains::hrmp::HrmpChannels::< let hrmp_channel_exist = $crate::impls::hrmp::HrmpChannels::<
<Self as Chain>::Runtime, <Self as Chain>::Runtime,
>::contains_key(&channel_id); >::contains_key(&channel_id);
@@ -321,14 +360,14 @@ macro_rules! impl_hrmp_channels_helpers_for_relay_chain {
#[macro_export] #[macro_export]
macro_rules! impl_accounts_helpers_for_parachain { macro_rules! impl_accounts_helpers_for_parachain {
( $chain:ident ) => { ( $chain:ident ) => {
$crate::paste::paste! { $crate::impls::paste::paste! {
impl $chain { impl $chain {
/// Fund a set of accounts with a balance /// Fund a set of accounts with a balance
pub fn fund_accounts(accounts: Vec<(AccountId, Balance)>) { pub fn fund_accounts(accounts: Vec<($crate::impls::AccountId, $crate::impls::Balance)>) {
Self::execute_with(|| { <Self as $crate::impls::TestExt>::execute_with(|| {
for account in accounts { for account in accounts {
assert_ok!(<Self as [<$chain Pallet>]>::Balances::force_set_balance( $crate::impls::assert_ok!(<Self as [<$chain Pallet>]>::Balances::force_set_balance(
<Self as Chain>::RuntimeOrigin::root(), <Self as $crate::impls::Chain>::RuntimeOrigin::root(),
account.0.into(), account.0.into(),
account.1, account.1,
)); ));
@@ -343,20 +382,20 @@ macro_rules! impl_accounts_helpers_for_parachain {
#[macro_export] #[macro_export]
macro_rules! impl_assert_events_helpers_for_parachain { macro_rules! impl_assert_events_helpers_for_parachain {
( $chain:ident ) => { ( $chain:ident ) => {
$crate::paste::paste! { $crate::impls::paste::paste! {
type [<$chain RuntimeEvent>] = <$chain as Chain>::RuntimeEvent; type [<$chain RuntimeEvent>] = <$chain as $crate::impls::Chain>::RuntimeEvent;
impl $chain { impl $chain {
/// Asserts a dispatchable is completely executed and XCM sent /// Asserts a dispatchable is completely executed and XCM sent
pub fn assert_xcm_pallet_attempted_complete(expected_weight: Option<Weight>) { pub fn assert_xcm_pallet_attempted_complete(expected_weight: Option<$crate::impls::Weight>) {
assert_expected_events!( $crate::impls::assert_expected_events!(
Self, Self,
vec![ vec![
[<$chain RuntimeEvent>]::PolkadotXcm( [<$chain RuntimeEvent>]::PolkadotXcm(
pallet_xcm::Event::Attempted { outcome: Outcome::Complete(weight) } $crate::impls::pallet_xcm::Event::Attempted { outcome: $crate::impls::Outcome::Complete(weight) }
) => { ) => {
weight: weight_within_threshold( weight: $crate::impls::weight_within_threshold(
(REF_TIME_THRESHOLD, PROOF_SIZE_THRESHOLD), ($crate::impls::REF_TIME_THRESHOLD, $crate::impls::PROOF_SIZE_THRESHOLD),
expected_weight.unwrap_or(*weight), expected_weight.unwrap_or(*weight),
*weight *weight
), ),
@@ -367,18 +406,18 @@ macro_rules! impl_assert_events_helpers_for_parachain {
/// Asserts a dispatchable is incompletely executed and XCM sent /// Asserts a dispatchable is incompletely executed and XCM sent
pub fn assert_xcm_pallet_attempted_incomplete( pub fn assert_xcm_pallet_attempted_incomplete(
expected_weight: Option<Weight>, expected_weight: Option<$crate::impls::Weight>,
expected_error: Option<Error>, expected_error: Option<$crate::impls::Error>,
) { ) {
assert_expected_events!( $crate::impls::assert_expected_events!(
Self, Self,
vec![ vec![
// Dispatchable is properly executed and XCM message sent // Dispatchable is properly executed and XCM message sent
[<$chain RuntimeEvent>]::PolkadotXcm( [<$chain RuntimeEvent>]::PolkadotXcm(
pallet_xcm::Event::Attempted { outcome: Outcome::Incomplete(weight, error) } $crate::impls::pallet_xcm::Event::Attempted { outcome: $crate::impls::Outcome::Incomplete(weight, error) }
) => { ) => {
weight: weight_within_threshold( weight: $crate::impls::weight_within_threshold(
(REF_TIME_THRESHOLD, PROOF_SIZE_THRESHOLD), ($crate::impls::REF_TIME_THRESHOLD, $crate::impls::PROOF_SIZE_THRESHOLD),
expected_weight.unwrap_or(*weight), expected_weight.unwrap_or(*weight),
*weight *weight
), ),
@@ -389,13 +428,13 @@ macro_rules! impl_assert_events_helpers_for_parachain {
} }
/// Asserts a dispatchable throws and error when trying to be sent /// Asserts a dispatchable throws and error when trying to be sent
pub fn assert_xcm_pallet_attempted_error(expected_error: Option<Error>) { pub fn assert_xcm_pallet_attempted_error(expected_error: Option<$crate::impls::Error>) {
assert_expected_events!( $crate::impls::assert_expected_events!(
Self, Self,
vec![ vec![
// Execution fails in the origin with `Barrier` // Execution fails in the origin with `Barrier`
[<$chain RuntimeEvent>]::PolkadotXcm( [<$chain RuntimeEvent>]::PolkadotXcm(
pallet_xcm::Event::Attempted { outcome: Outcome::Error(error) } $crate::impls::pallet_xcm::Event::Attempted { outcome: $crate::impls::Outcome::Error(error) }
) => { ) => {
error: *error == expected_error.unwrap_or(*error), error: *error == expected_error.unwrap_or(*error),
}, },
@@ -405,36 +444,36 @@ macro_rules! impl_assert_events_helpers_for_parachain {
/// Asserts a XCM message is sent /// Asserts a XCM message is sent
pub fn assert_xcm_pallet_sent() { pub fn assert_xcm_pallet_sent() {
assert_expected_events!( $crate::impls::assert_expected_events!(
Self, Self,
vec![ vec![
[<$chain RuntimeEvent>]::PolkadotXcm(pallet_xcm::Event::Sent { .. }) => {}, [<$chain RuntimeEvent>]::PolkadotXcm($crate::impls::pallet_xcm::Event::Sent { .. }) => {},
] ]
); );
} }
/// Asserts a XCM message is sent to Relay Chain /// Asserts a XCM message is sent to Relay Chain
pub fn assert_parachain_system_ump_sent() { pub fn assert_parachain_system_ump_sent() {
assert_expected_events!( $crate::impls::assert_expected_events!(
Self, Self,
vec![ vec![
[<$chain RuntimeEvent>]::ParachainSystem( [<$chain RuntimeEvent>]::ParachainSystem(
cumulus_pallet_parachain_system::Event::UpwardMessageSent { .. } $crate::impls::cumulus_pallet_parachain_system::Event::UpwardMessageSent { .. }
) => {}, ) => {},
] ]
); );
} }
/// Asserts a XCM from Relay Chain is completely executed /// Asserts a XCM from Relay Chain is completely executed
pub fn assert_dmp_queue_complete(expected_weight: Option<Weight>) { pub fn assert_dmp_queue_complete(expected_weight: Option<$crate::impls::Weight>) {
assert_expected_events!( $crate::impls::assert_expected_events!(
Self, Self,
vec![ vec![
[<$chain RuntimeEvent>]::DmpQueue(cumulus_pallet_dmp_queue::Event::ExecutedDownward { [<$chain RuntimeEvent>]::DmpQueue($crate::impls::cumulus_pallet_dmp_queue::Event::ExecutedDownward {
outcome: Outcome::Complete(weight), .. outcome: $crate::impls::Outcome::Complete(weight), ..
}) => { }) => {
weight: weight_within_threshold( weight: $crate::impls::weight_within_threshold(
(REF_TIME_THRESHOLD, PROOF_SIZE_THRESHOLD), ($crate::impls::REF_TIME_THRESHOLD, $crate::impls::PROOF_SIZE_THRESHOLD),
expected_weight.unwrap_or(*weight), expected_weight.unwrap_or(*weight),
*weight *weight
), ),
@@ -445,17 +484,17 @@ macro_rules! impl_assert_events_helpers_for_parachain {
/// Asserts a XCM from Relay Chain is incompletely executed /// Asserts a XCM from Relay Chain is incompletely executed
pub fn assert_dmp_queue_incomplete( pub fn assert_dmp_queue_incomplete(
expected_weight: Option<Weight>, expected_weight: Option<$crate::impls::Weight>,
expected_error: Option<Error>, expected_error: Option<$crate::impls::Error>,
) { ) {
assert_expected_events!( $crate::impls::assert_expected_events!(
Self, Self,
vec![ vec![
[<$chain RuntimeEvent>]::DmpQueue(cumulus_pallet_dmp_queue::Event::ExecutedDownward { [<$chain RuntimeEvent>]::DmpQueue($crate::impls::cumulus_pallet_dmp_queue::Event::ExecutedDownward {
outcome: Outcome::Incomplete(weight, error), .. outcome: $crate::impls::Outcome::Incomplete(weight, error), ..
}) => { }) => {
weight: weight_within_threshold( weight: $crate::impls::weight_within_threshold(
(REF_TIME_THRESHOLD, PROOF_SIZE_THRESHOLD), ($crate::impls::REF_TIME_THRESHOLD, $crate::impls::PROOF_SIZE_THRESHOLD),
expected_weight.unwrap_or(*weight), expected_weight.unwrap_or(*weight),
*weight *weight
), ),
@@ -466,15 +505,15 @@ macro_rules! impl_assert_events_helpers_for_parachain {
} }
/// Asserts a XCM from another Parachain is completely executed /// Asserts a XCM from another Parachain is completely executed
pub fn assert_xcmp_queue_success(expected_weight: Option<Weight>) { pub fn assert_xcmp_queue_success(expected_weight: Option<$crate::impls::Weight>) {
assert_expected_events!( $crate::impls::assert_expected_events!(
Self, Self,
vec![ vec![
[<$chain RuntimeEvent>]::XcmpQueue( [<$chain RuntimeEvent>]::XcmpQueue(
cumulus_pallet_xcmp_queue::Event::Success { weight, .. } $crate::impls::cumulus_pallet_xcmp_queue::Event::Success { weight, .. }
) => { ) => {
weight: weight_within_threshold( weight: $crate::impls::weight_within_threshold(
(REF_TIME_THRESHOLD, PROOF_SIZE_THRESHOLD), ($crate::impls::REF_TIME_THRESHOLD, $crate::impls::PROOF_SIZE_THRESHOLD),
expected_weight.unwrap_or(*weight), expected_weight.unwrap_or(*weight),
*weight *weight
), ),
@@ -490,18 +529,20 @@ macro_rules! impl_assert_events_helpers_for_parachain {
#[macro_export] #[macro_export]
macro_rules! impl_assets_helpers_for_parachain { macro_rules! impl_assets_helpers_for_parachain {
( $chain:ident, $relay_chain:ident ) => { ( $chain:ident, $relay_chain:ident ) => {
$crate::paste::paste! { $crate::impls::paste::paste! {
impl $chain { impl $chain {
/// Returns the encoded call for `force_create` from the assets pallet /// Returns the encoded call for `force_create` from the assets pallet
pub fn force_create_asset_call( pub fn force_create_asset_call(
asset_id: u32, asset_id: u32,
owner: AccountId, owner: $crate::impls::AccountId,
is_sufficient: bool, is_sufficient: bool,
min_balance: Balance, min_balance: $crate::impls::Balance,
) -> DoubleEncoded<()> { ) -> $crate::impls::DoubleEncoded<()> {
<Self as Chain>::RuntimeCall::Assets(pallet_assets::Call::< use $crate::impls::{Chain, Encode};
<Self as Chain>::RuntimeCall::Assets($crate::impls::pallet_assets::Call::<
<Self as Chain>::Runtime, <Self as Chain>::Runtime,
Instance1, $crate::impls::pallet_assets::Instance1,
>::force_create { >::force_create {
id: asset_id.into(), id: asset_id.into(),
owner: owner.into(), owner: owner.into(),
@@ -514,37 +555,37 @@ macro_rules! impl_assets_helpers_for_parachain {
/// Returns a `VersionedXcm` for `force_create` from the assets pallet /// Returns a `VersionedXcm` for `force_create` from the assets pallet
pub fn force_create_asset_xcm( pub fn force_create_asset_xcm(
origin_kind: OriginKind, origin_kind: $crate::impls::OriginKind,
asset_id: u32, asset_id: u32,
owner: AccountId, owner: $crate::impls::AccountId,
is_sufficient: bool, is_sufficient: bool,
min_balance: Balance, min_balance: $crate::impls::Balance,
) -> VersionedXcm<()> { ) -> $crate::impls::VersionedXcm<()> {
let call = Self::force_create_asset_call(asset_id, owner, is_sufficient, min_balance); let call = Self::force_create_asset_call(asset_id, owner, is_sufficient, min_balance);
xcm_transact_unpaid_execution(call, origin_kind) $crate::impls::xcm_transact_unpaid_execution(call, origin_kind)
} }
/// Mint assets making use of the assets pallet /// Mint assets making use of the assets pallet
pub fn mint_asset( pub fn mint_asset(
signed_origin: <Self as Chain>::RuntimeOrigin, signed_origin: <Self as $crate::impls::Chain>::RuntimeOrigin,
id: u32, id: u32,
beneficiary: AccountId, beneficiary: $crate::impls::AccountId,
amount_to_mint: u128, amount_to_mint: u128,
) { ) {
Self::execute_with(|| { <Self as $crate::impls::TestExt>::execute_with(|| {
assert_ok!(<Self as [<$chain Pallet>]>::Assets::mint( $crate::impls::assert_ok!(<Self as [<$chain Pallet>]>::Assets::mint(
signed_origin, signed_origin,
id.into(), id.into(),
beneficiary.clone().into(), beneficiary.clone().into(),
amount_to_mint amount_to_mint
)); ));
type RuntimeEvent = <$chain as Chain>::RuntimeEvent; type RuntimeEvent = <$chain as $crate::impls::Chain>::RuntimeEvent;
assert_expected_events!( $crate::impls::assert_expected_events!(
Self, Self,
vec![ vec![
RuntimeEvent::Assets(pallet_assets::Event::Issued { asset_id, owner, amount }) => { RuntimeEvent::Assets($crate::impls::pallet_assets::Event::Issued { asset_id, owner, amount }) => {
asset_id: *asset_id == id, asset_id: *asset_id == id,
owner: *owner == beneficiary.clone().into(), owner: *owner == beneficiary.clone().into(),
amount: *amount == amount_to_mint, amount: *amount == amount_to_mint,
@@ -559,14 +600,15 @@ macro_rules! impl_assets_helpers_for_parachain {
id: u32, id: u32,
min_balance: u128, min_balance: u128,
is_sufficient: bool, is_sufficient: bool,
asset_owner: AccountId, asset_owner: $crate::impls::AccountId,
amount_to_mint: u128, amount_to_mint: u128,
) { ) {
use $crate::impls::{bx, Chain, RelayChain, Parachain, Inspect, TestExt};
// Init values for Relay Chain // Init values for Relay Chain
let root_origin = <$relay_chain as Chain>::RuntimeOrigin::root(); let root_origin = <$relay_chain as Chain>::RuntimeOrigin::root();
let destination = <$relay_chain>::child_location_of(<$chain>::para_id()); let destination = <$relay_chain>::child_location_of(<$chain>::para_id());
let xcm = Self::force_create_asset_xcm( let xcm = Self::force_create_asset_xcm(
OriginKind::Superuser, $crate::impls::OriginKind::Superuser,
id, id,
asset_owner.clone(), asset_owner.clone(),
is_sufficient, is_sufficient,
@@ -574,7 +616,7 @@ macro_rules! impl_assets_helpers_for_parachain {
); );
<$relay_chain>::execute_with(|| { <$relay_chain>::execute_with(|| {
assert_ok!(<$relay_chain as [<$relay_chain Pallet>]>::XcmPallet::send( $crate::impls::assert_ok!(<$relay_chain as [<$relay_chain Pallet>]>::XcmPallet::send(
root_origin, root_origin,
bx!(destination.into()), bx!(destination.into()),
bx!(xcm), bx!(xcm),
@@ -584,15 +626,15 @@ macro_rules! impl_assets_helpers_for_parachain {
}); });
Self::execute_with(|| { Self::execute_with(|| {
Self::assert_dmp_queue_complete(Some(Weight::from_parts(1_019_445_000, 200_000))); Self::assert_dmp_queue_complete(Some($crate::impls::Weight::from_parts(1_019_445_000, 200_000)));
type RuntimeEvent = <$chain as Chain>::RuntimeEvent; type RuntimeEvent = <$chain as $crate::impls::Chain>::RuntimeEvent;
assert_expected_events!( $crate::impls::assert_expected_events!(
Self, Self,
vec![ vec![
// Asset has been created // Asset has been created
RuntimeEvent::Assets(pallet_assets::Event::ForceCreated { asset_id, owner }) => { RuntimeEvent::Assets($crate::impls::pallet_assets::Event::ForceCreated { asset_id, owner }) => {
asset_id: *asset_id == id, asset_id: *asset_id == id,
owner: *owner == asset_owner.clone(), owner: *owner == asset_owner.clone(),
}, },
@@ -14,46 +14,24 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>. // along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
pub use lazy_static;
pub mod constants; pub mod constants;
pub mod impls; pub mod impls;
pub mod xcm_helpers;
pub use codec::Encode; use constants::{
pub use constants::{
accounts::{ALICE, BOB}, accounts::{ALICE, BOB},
asset_hub_kusama, asset_hub_polkadot, asset_hub_westend, bridge_hub_kusama, asset_hub_kusama, asset_hub_polkadot, asset_hub_westend, bridge_hub_kusama,
bridge_hub_polkadot, bridge_hub_rococo, collectives, kusama, penpal, polkadot, rococo, westend, bridge_hub_polkadot, bridge_hub_rococo, collectives, kusama, penpal, polkadot, rococo, westend,
PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD,
};
use frame_support::{
assert_ok,
instances::Instance1,
parameter_types,
traits::{fungibles::Inspect, Hooks},
};
pub use impls::{RococoWococoMessageHandler, WococoRococoMessageHandler};
pub use parachains_common::{AccountId, Balance};
pub use paste;
use polkadot_parachain_primitives::primitives::HrmpChannelId;
use polkadot_primitives::runtime_api::runtime_decl_for_parachain_host::ParachainHostV6;
pub use polkadot_runtime_parachains::inclusion::{AggregateMessageOrigin, UmpQueueId};
pub use sp_core::{sr25519, storage::Storage, Get};
use sp_tracing;
use xcm_emulator::{
assert_expected_events, bx, decl_test_bridges, decl_test_networks, decl_test_parachains,
decl_test_relay_chains, decl_test_sender_receiver_accounts_parameter_types,
helpers::weight_within_threshold, BridgeMessageHandler, Chain, DefaultMessageProcessor, ParaId,
Parachain, RelayChain, TestExt,
}; };
use impls::{RococoWococoMessageHandler, WococoRococoMessageHandler};
pub use xcm::{ // Substrate
prelude::{ use frame_support::traits::OnInitialize;
AccountId32, All, BuyExecution, DepositAsset, MultiAsset, MultiAssets, MultiLocation,
OriginKind, Outcome, RefundSurplus, Transact, UnpaidExecution, VersionedXcm, Weight, // Cumulus
WeightLimit, WithdrawAsset, Xcm, X1, use xcm_emulator::{
}, decl_test_bridges, decl_test_networks, decl_test_parachains, decl_test_relay_chains,
v3::Error, decl_test_sender_receiver_accounts_parameter_types, DefaultMessageProcessor,
DoubleEncoded,
}; };
decl_test_relay_chains! { decl_test_relay_chains! {
@@ -87,7 +65,7 @@ decl_test_relay_chains! {
Hrmp: kusama_runtime::Hrmp, Hrmp: kusama_runtime::Hrmp,
} }
}, },
#[api_version(5)] #[api_version(6)]
pub struct Westend { pub struct Westend {
genesis = westend::genesis(), genesis = westend::genesis(),
on_init = (), on_init = (),
@@ -582,44 +560,3 @@ decl_test_sender_receiver_accounts_parameter_types! {
PenpalWestendA { sender: ALICE, receiver: BOB }, PenpalWestendA { sender: ALICE, receiver: BOB },
PenpalRococoA { sender: ALICE, receiver: BOB } PenpalRococoA { sender: ALICE, receiver: BOB }
} }
/// Helper method to build a XCM with a `Transact` instruction and paying for its execution
pub fn xcm_transact_paid_execution(
call: DoubleEncoded<()>,
origin_kind: OriginKind,
native_asset: MultiAsset,
beneficiary: AccountId,
) -> VersionedXcm<()> {
let weight_limit = WeightLimit::Unlimited;
let require_weight_at_most = Weight::from_parts(1000000000, 200000);
let native_assets: MultiAssets = native_asset.clone().into();
VersionedXcm::from(Xcm(vec![
WithdrawAsset(native_assets),
BuyExecution { fees: native_asset, weight_limit },
Transact { require_weight_at_most, origin_kind, call },
RefundSurplus,
DepositAsset {
assets: All.into(),
beneficiary: MultiLocation {
parents: 0,
interior: X1(AccountId32 { network: None, id: beneficiary.into() }),
},
},
]))
}
/// Helper method to build a XCM with a `Transact` instruction without paying for its execution
pub fn xcm_transact_unpaid_execution(
call: DoubleEncoded<()>,
origin_kind: OriginKind,
) -> VersionedXcm<()> {
let weight_limit = WeightLimit::Unlimited;
let require_weight_at_most = Weight::from_parts(1000000000, 200000);
let check_origin = None;
VersionedXcm::from(Xcm(vec![
UnpaidExecution { weight_limit, check_origin },
Transact { require_weight_at_most, origin_kind, call },
]))
}
@@ -0,0 +1,66 @@
// Copyright Parity Technologies (UK) Ltd.
// This file is part of Cumulus.
// Cumulus is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Cumulus is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
use parachains_common::AccountId;
use xcm::{
prelude::{
AccountId32, All, BuyExecution, DepositAsset, MultiAsset, MultiAssets, MultiLocation,
OriginKind, RefundSurplus, Transact, UnpaidExecution, VersionedXcm, Weight, WeightLimit,
WithdrawAsset, Xcm, X1,
},
DoubleEncoded,
};
/// Helper method to build a XCM with a `Transact` instruction and paying for its execution
pub fn xcm_transact_paid_execution(
call: DoubleEncoded<()>,
origin_kind: OriginKind,
native_asset: MultiAsset,
beneficiary: AccountId,
) -> VersionedXcm<()> {
let weight_limit = WeightLimit::Unlimited;
let require_weight_at_most = Weight::from_parts(1000000000, 200000);
let native_assets: MultiAssets = native_asset.clone().into();
VersionedXcm::from(Xcm(vec![
WithdrawAsset(native_assets),
BuyExecution { fees: native_asset, weight_limit },
Transact { require_weight_at_most, origin_kind, call },
RefundSurplus,
DepositAsset {
assets: All.into(),
beneficiary: MultiLocation {
parents: 0,
interior: X1(AccountId32 { network: None, id: beneficiary.into() }),
},
},
]))
}
/// Helper method to build a XCM with a `Transact` instruction without paying for its execution
pub fn xcm_transact_unpaid_execution(
call: DoubleEncoded<()>,
origin_kind: OriginKind,
) -> VersionedXcm<()> {
let weight_limit = WeightLimit::Unlimited;
let require_weight_at_most = Weight::from_parts(1000000000, 200000);
let check_origin = None;
VersionedXcm::from(Xcm(vec![
UnpaidExecution { weight_limit, check_origin },
Transact { require_weight_at_most, origin_kind, call },
]))
}
+2 -4
View File
@@ -21,16 +21,13 @@ sp-core = { path = "../../../substrate/primitives/core" }
sp-std = { path = "../../../substrate/primitives/std" } sp-std = { path = "../../../substrate/primitives/std" }
sp-runtime = { path = "../../../substrate/primitives/runtime" } sp-runtime = { path = "../../../substrate/primitives/runtime" }
sp-arithmetic = { path = "../../../substrate/primitives/arithmetic" } sp-arithmetic = { path = "../../../substrate/primitives/arithmetic" }
sp-trie = { path = "../../../substrate/primitives/trie" } sp-tracing = { path = "../../../substrate/primitives/tracing" }
pallet-balances = { path = "../../../substrate/frame/balances" } pallet-balances = { path = "../../../substrate/frame/balances" }
pallet-message-queue = { path = "../../../substrate/frame/message-queue" } pallet-message-queue = { path = "../../../substrate/frame/message-queue" }
# Cumulus # Cumulus
cumulus-primitives-core = { path = "../../primitives/core" } cumulus-primitives-core = { path = "../../primitives/core" }
cumulus-pallet-xcmp-queue = { path = "../../pallets/xcmp-queue" }
cumulus-pallet-dmp-queue = { path = "../../pallets/dmp-queue" }
cumulus-pallet-parachain-system = { path = "../../pallets/parachain-system" } cumulus-pallet-parachain-system = { path = "../../pallets/parachain-system" }
parachain-info = { path = "../../parachains/pallets/parachain-info" }
cumulus-primitives-parachain-inherent = { path = "../../primitives/parachain-inherent" } cumulus-primitives-parachain-inherent = { path = "../../primitives/parachain-inherent" }
cumulus-test-relay-sproof-builder = { path = "../../test/relay-sproof-builder" } cumulus-test-relay-sproof-builder = { path = "../../test/relay-sproof-builder" }
parachains-common = { path = "../../parachains/common" } parachains-common = { path = "../../parachains/common" }
@@ -39,4 +36,5 @@ parachains-common = { path = "../../parachains/common" }
xcm = { package = "staging-xcm", path = "../../../polkadot/xcm" } xcm = { package = "staging-xcm", path = "../../../polkadot/xcm" }
xcm-executor = { package = "staging-xcm-executor", path = "../../../polkadot/xcm/xcm-executor" } xcm-executor = { package = "staging-xcm-executor", path = "../../../polkadot/xcm/xcm-executor" }
polkadot-primitives = { path = "../../../polkadot/primitives" } polkadot-primitives = { path = "../../../polkadot/primitives" }
polkadot-parachain-primitives = { path = "../../../polkadot/parachain" }
polkadot-runtime-parachains = { path = "../../../polkadot/runtime/parachains" } polkadot-runtime-parachains = { path = "../../../polkadot/runtime/parachains" }
+82 -102
View File
@@ -19,61 +19,45 @@ pub use lazy_static::lazy_static;
pub use log; pub use log;
pub use paste; pub use paste;
pub use std::{ pub use std::{
any::type_name, any::type_name, collections::HashMap, error::Error, fmt, marker::PhantomData, ops::Deref,
collections::HashMap, sync::Mutex,
error::Error,
fmt,
marker::PhantomData,
ops::Deref,
sync::{Condvar, Mutex},
thread::LocalKey,
}; };
// Substrate // Substrate
pub use frame_support::{ pub use frame_support::{
assert_ok, assert_ok,
sp_runtime::{AccountId32, DispatchResult}, sp_runtime::{traits::Header as HeaderT, AccountId32, DispatchResult},
traits::{ traits::{
tokens::currency::Currency, EnqueueMessage, Get, Hooks, OriginTrait, ProcessMessage, EnqueueMessage, Get, Hooks, OriginTrait, ProcessMessage, ProcessMessageError, ServiceQueues,
ProcessMessageError, ServiceQueues,
}, },
weights::{Weight, WeightMeter}, weights::{Weight, WeightMeter},
StorageHasher,
}; };
pub use frame_system::{AccountInfo, Config as SystemConfig, Pallet as SystemPallet}; pub use frame_system::{Config as SystemConfig, Pallet as SystemPallet};
pub use pallet_balances::AccountData; pub use pallet_balances::AccountData;
pub use sp_arithmetic::traits::Bounded; pub use sp_arithmetic::traits::Bounded;
pub use sp_core::{sr25519, storage::Storage, Pair, H256}; pub use sp_core::{blake2_256, parameter_types, sr25519, storage::Storage, Pair};
pub use sp_io::TestExternalities; pub use sp_io::TestExternalities;
pub use sp_std::{cell::RefCell, collections::vec_deque::VecDeque, fmt::Debug}; pub use sp_std::{cell::RefCell, collections::vec_deque::VecDeque, fmt::Debug};
pub use sp_trie::StorageProof; pub use sp_tracing;
// Cumulus // Cumulus
pub use cumulus_pallet_dmp_queue; pub use cumulus_pallet_parachain_system::Pallet as ParachainSystemPallet;
pub use cumulus_pallet_parachain_system::{self, Pallet as ParachainSystemPallet};
pub use cumulus_pallet_xcmp_queue::{Config as XcmpQueueConfig, Pallet as XcmpQueuePallet};
pub use cumulus_primitives_core::{ pub use cumulus_primitives_core::{
self, relay_chain::{BlockNumber as RelayBlockNumber, HeadData, HrmpChannelId},
relay_chain::{BlockNumber as RelayBlockNumber, HeadData}, AbridgedHrmpChannel, DmpMessageHandler, ParaId, PersistedValidationData, XcmpMessageHandler,
DmpMessageHandler, ParaId, PersistedValidationData, XcmpMessageHandler,
}; };
pub use cumulus_primitives_parachain_inherent::ParachainInherentData; pub use cumulus_primitives_parachain_inherent::ParachainInherentData;
pub use cumulus_test_relay_sproof_builder::RelayStateSproofBuilder; pub use cumulus_test_relay_sproof_builder::RelayStateSproofBuilder;
pub use pallet_message_queue::{ pub use pallet_message_queue::{Config as MessageQueueConfig, Pallet as MessageQueuePallet};
Config as MessageQueueConfig, Event as MessageQueueEvent, Pallet as MessageQueuePallet,
};
pub use parachain_info;
pub use parachains_common::{AccountId, Balance, BlockNumber}; pub use parachains_common::{AccountId, Balance, BlockNumber};
pub use polkadot_primitives; pub use polkadot_primitives;
pub use polkadot_runtime_parachains::{ pub use polkadot_runtime_parachains::inclusion::{AggregateMessageOrigin, UmpQueueId};
dmp,
inclusion::{AggregateMessageOrigin, UmpQueueId},
};
// Polkadot // Polkadot
pub use xcm::{ pub use polkadot_parachain_primitives::primitives::RelayChainBlockNumber;
v3::prelude::{AccountId32 as AccountId32Junction, Parachain as ParachainJunction, *}, pub use xcm::v3::prelude::{
VersionedMultiAssets, VersionedMultiLocation, Ancestor, MultiAssets, MultiLocation, Parachain as ParachainJunction, Parent, WeightLimit,
XcmHash, X1,
}; };
pub use xcm_executor::traits::ConvertLocation; pub use xcm_executor::traits::ConvertLocation;
@@ -362,23 +346,24 @@ macro_rules! decl_test_relay_chains {
} }
), ),
+ +
$(,)?
) => { ) => {
$( $(
#[derive(Clone)] #[derive(Clone)]
pub struct $name; pub struct $name;
impl Chain for $name { impl $crate::Chain for $name {
type Runtime = $runtime::Runtime; type Runtime = $runtime::Runtime;
type RuntimeCall = $runtime::RuntimeCall; type RuntimeCall = $runtime::RuntimeCall;
type RuntimeOrigin = $runtime::RuntimeOrigin; type RuntimeOrigin = $runtime::RuntimeOrigin;
type RuntimeEvent = $runtime::RuntimeEvent; type RuntimeEvent = $runtime::RuntimeEvent;
type System = $crate::SystemPallet::<Self::Runtime>; type System = $crate::SystemPallet::<Self::Runtime>;
fn account_data_of(account: AccountId) -> $crate::AccountData<Balance> { fn account_data_of(account: $crate::AccountId) -> $crate::AccountData<$crate::Balance> {
Self::ext_wrapper(|| $crate::SystemPallet::<Self::Runtime>::account(account).data.into()) <Self as $crate::TestExt>::ext_wrapper(|| $crate::SystemPallet::<Self::Runtime>::account(account).data.into())
} }
fn events() -> Vec<<Self as Chain>::RuntimeEvent> { fn events() -> Vec<<Self as $crate::Chain>::RuntimeEvent> {
Self::System::events() Self::System::events()
.iter() .iter()
.map(|record| record.event.clone()) .map(|record| record.event.clone())
@@ -386,7 +371,7 @@ macro_rules! decl_test_relay_chains {
} }
} }
impl RelayChain for $name { impl $crate::RelayChain for $name {
type SovereignAccountOf = $sovereign_acc_of; type SovereignAccountOf = $sovereign_acc_of;
type MessageProcessor = $mp; type MessageProcessor = $mp;
} }
@@ -430,7 +415,7 @@ macro_rules! __impl_test_ext_for_relay_chain {
(@impl $name:ident, $genesis:expr, $on_init:expr, $api_version:ident, $local_ext:ident, $global_ext:ident) => { (@impl $name:ident, $genesis:expr, $on_init:expr, $api_version:ident, $local_ext:ident, $global_ext:ident) => {
thread_local! { thread_local! {
pub static $local_ext: $crate::RefCell<$crate::TestExternalities> pub static $local_ext: $crate::RefCell<$crate::TestExternalities>
= $crate::RefCell::new(<$name>::build_new_ext($genesis)); = $crate::RefCell::new(<$name as $crate::TestExt>::build_new_ext($genesis));
} }
$crate::lazy_static! { $crate::lazy_static! {
@@ -438,11 +423,11 @@ macro_rules! __impl_test_ext_for_relay_chain {
= $crate::Mutex::new($crate::RefCell::new($crate::HashMap::new())); = $crate::Mutex::new($crate::RefCell::new($crate::HashMap::new()));
} }
impl TestExt for $name { impl $crate::TestExt for $name {
fn build_new_ext(storage: $crate::Storage) -> $crate::TestExternalities { fn build_new_ext(storage: $crate::Storage) -> $crate::TestExternalities {
use $crate::{NetworkComponent, Network, Chain}; use $crate::{sp_tracing, NetworkComponent, Network, Chain, TestExternalities};
let mut ext = $crate::TestExternalities::new(storage); let mut ext = TestExternalities::new(storage);
ext.execute_with(|| { ext.execute_with(|| {
#[allow(clippy::no_effect)] #[allow(clippy::no_effect)]
@@ -512,7 +497,7 @@ macro_rules! __impl_test_ext_for_relay_chain {
} }
fn execute_with<R>(execute: impl FnOnce() -> R) -> R { fn execute_with<R>(execute: impl FnOnce() -> R) -> R {
use $crate::{NetworkComponent, Network}; use $crate::{Chain, NetworkComponent, Network};
// Make sure the Network is initialized // Make sure the Network is initialized
<$name as NetworkComponent>::Network::init(); <$name as NetworkComponent>::Network::init();
@@ -527,7 +512,7 @@ macro_rules! __impl_test_ext_for_relay_chain {
//TODO: mark sent count & filter out sent msg //TODO: mark sent count & filter out sent msg
for para_id in<$name as NetworkComponent>::Network::para_ids() { for para_id in<$name as NetworkComponent>::Network::para_ids() {
// downward messages // downward messages
let downward_messages = <Self as Chain>::Runtime::dmq_contents(para_id.into()) let downward_messages = <Self as $crate::Chain>::Runtime::dmq_contents(para_id.into())
.into_iter() .into_iter()
.map(|inbound| (inbound.sent_at, inbound.msg)); .map(|inbound| (inbound.sent_at, inbound.msg));
if downward_messages.len() == 0 { if downward_messages.len() == 0 {
@@ -586,23 +571,24 @@ macro_rules! decl_test_parachains {
} }
), ),
+ +
$(,)?
) => { ) => {
$( $(
#[derive(Clone)] #[derive(Clone)]
pub struct $name; pub struct $name;
impl Chain for $name { impl $crate::Chain for $name {
type Runtime = $runtime::Runtime; type Runtime = $runtime::Runtime;
type RuntimeCall = $runtime::RuntimeCall; type RuntimeCall = $runtime::RuntimeCall;
type RuntimeOrigin = $runtime::RuntimeOrigin; type RuntimeOrigin = $runtime::RuntimeOrigin;
type RuntimeEvent = $runtime::RuntimeEvent; type RuntimeEvent = $runtime::RuntimeEvent;
type System = $crate::SystemPallet::<Self::Runtime>; type System = $crate::SystemPallet::<Self::Runtime>;
fn account_data_of(account: AccountId) -> $crate::AccountData<Balance> { fn account_data_of(account: $crate::AccountId) -> $crate::AccountData<$crate::Balance> {
Self::ext_wrapper(|| $crate::SystemPallet::<Self::Runtime>::account(account).data.into()) <Self as $crate::TestExt>::ext_wrapper(|| $crate::SystemPallet::<Self::Runtime>::account(account).data.into())
} }
fn events() -> Vec<<Self as Chain>::RuntimeEvent> { fn events() -> Vec<<Self as $crate::Chain>::RuntimeEvent> {
Self::System::events() Self::System::events()
.iter() .iter()
.map(|record| record.event.clone()) .map(|record| record.event.clone())
@@ -610,25 +596,25 @@ macro_rules! decl_test_parachains {
} }
} }
impl Parachain for $name { impl $crate::Parachain for $name {
type XcmpMessageHandler = $xcmp_message_handler; type XcmpMessageHandler = $xcmp_message_handler;
type DmpMessageHandler = $dmp_message_handler; type DmpMessageHandler = $dmp_message_handler;
type LocationToAccountId = $location_to_account; type LocationToAccountId = $location_to_account;
type ParachainSystem = $crate::ParachainSystemPallet<<Self as Chain>::Runtime>; type ParachainSystem = $crate::ParachainSystemPallet<<Self as $crate::Chain>::Runtime>;
type ParachainInfo = $parachain_info; type ParachainInfo = $parachain_info;
fn init() { fn init() {
use $crate::{Network, NetworkComponent, Hooks}; use $crate::{Chain, HeadData, Network, NetworkComponent, Hooks, Encode, Parachain, TestExt};
let para_id = Self::para_id(); let para_id = Self::para_id();
<Self as TestExt>::ext_wrapper(|| { Self::ext_wrapper(|| {
let block_number = <Self as Chain>::System::block_number(); let block_number = <Self as Chain>::System::block_number();
let mut relay_block_number = <Self as NetworkComponent>::Network::relay_block_number(); let mut relay_block_number = <Self as NetworkComponent>::Network::relay_block_number();
// Get parent head data // Get parent head data
let header = <Self as Chain>::System::finalize(); let header = <Self as Chain>::System::finalize();
let parent_head_data = $crate::HeadData(header.encode()); let parent_head_data = HeadData(header.encode());
$crate::LAST_HEAD.with(|b| b.borrow_mut() $crate::LAST_HEAD.with(|b| b.borrow_mut()
.get_mut(<Self as NetworkComponent>::Network::name()) .get_mut(<Self as NetworkComponent>::Network::name())
@@ -638,7 +624,7 @@ macro_rules! decl_test_parachains {
let next_block_number = block_number + 1; let next_block_number = block_number + 1;
<Self as Chain>::System::initialize(&next_block_number, &header.hash(), &Default::default()); <Self as Chain>::System::initialize(&next_block_number, &header.hash(), &Default::default());
<Self as Parachain>::ParachainSystem::on_initialize(next_block_number); <<Self as Parachain>::ParachainSystem as Hooks<$crate::BlockNumber>>::on_initialize(next_block_number);
}); });
} }
} }
@@ -675,7 +661,7 @@ macro_rules! __impl_test_ext_for_parachain {
(@impl $name:ident, $genesis:expr, $on_init:expr, $local_ext:ident, $global_ext:ident) => { (@impl $name:ident, $genesis:expr, $on_init:expr, $local_ext:ident, $global_ext:ident) => {
thread_local! { thread_local! {
pub static $local_ext: $crate::RefCell<$crate::TestExternalities> pub static $local_ext: $crate::RefCell<$crate::TestExternalities>
= $crate::RefCell::new(<$name>::build_new_ext($genesis)); = $crate::RefCell::new(<$name as $crate::TestExt>::build_new_ext($genesis));
} }
$crate::lazy_static! { $crate::lazy_static! {
@@ -683,20 +669,18 @@ macro_rules! __impl_test_ext_for_parachain {
= $crate::Mutex::new($crate::RefCell::new($crate::HashMap::new())); = $crate::Mutex::new($crate::RefCell::new($crate::HashMap::new()));
} }
impl TestExt for $name { impl $crate::TestExt for $name {
fn build_new_ext(storage: $crate::Storage) -> $crate::TestExternalities { fn build_new_ext(storage: $crate::Storage) -> $crate::TestExternalities {
use $crate::{NetworkComponent, Network, Chain};
let mut ext = $crate::TestExternalities::new(storage); let mut ext = $crate::TestExternalities::new(storage);
ext.execute_with(|| { ext.execute_with(|| {
#[allow(clippy::no_effect)] #[allow(clippy::no_effect)]
$on_init; $on_init;
sp_tracing::try_init_simple(); $crate::sp_tracing::try_init_simple();
let mut block_number = <Self as Chain>::System::block_number(); let mut block_number = <Self as $crate::Chain>::System::block_number();
block_number = std::cmp::max(1, block_number); block_number = std::cmp::max(1, block_number);
<Self as Chain>::System::set_block_number(block_number); <Self as $crate::Chain>::System::set_block_number(block_number);
}); });
ext ext
} }
@@ -757,10 +741,7 @@ macro_rules! __impl_test_ext_for_parachain {
} }
fn execute_with<R>(execute: impl FnOnce() -> R) -> R { fn execute_with<R>(execute: impl FnOnce() -> R) -> R {
use $crate::{Get, Hooks, NetworkComponent, Network, Bridge}; use $crate::{Chain, Get, Hooks, NetworkComponent, Network, Parachain, Encode};
use sp_core::Encode;
use sp_runtime::traits::BlakeTwo256;
use polkadot_primitives::HashT;
// Make sure the Network is initialized // Make sure the Network is initialized
<$name as NetworkComponent>::Network::init(); <$name as NetworkComponent>::Network::init();
@@ -801,10 +782,8 @@ macro_rules! __impl_test_ext_for_parachain {
// Finalize block and send messages if needed // Finalize block and send messages if needed
$local_ext.with(|v| { $local_ext.with(|v| {
v.borrow_mut().execute_with(|| { v.borrow_mut().execute_with(|| {
use sp_runtime::traits::Header as HeaderT;
let block_number = <Self as Chain>::System::block_number(); let block_number = <Self as Chain>::System::block_number();
let mock_header = HeaderT::new( let mock_header = $crate::HeaderT::new(
0, 0,
Default::default(), Default::default(),
Default::default(), Default::default(),
@@ -839,9 +818,9 @@ macro_rules! __impl_test_ext_for_parachain {
} }
// get bridge messages // get bridge messages
type NetworkBridge = <<$name as NetworkComponent>::Network as Network>::Bridge; type NetworkBridge = <<$name as NetworkComponent>::Network as $crate::Network>::Bridge;
let bridge_messages = <NetworkBridge as Bridge>::Handler::get_source_outbound_messages(); let bridge_messages = <<NetworkBridge as $crate::Bridge>::Handler as $crate::BridgeMessageHandler>::get_source_outbound_messages();
// send bridged messages // send bridged messages
for msg in bridge_messages { for msg in bridge_messages {
@@ -849,17 +828,17 @@ macro_rules! __impl_test_ext_for_parachain {
} }
// log events // log events
Self::events().iter().for_each(|event| { <Self as $crate::Chain>::events().iter().for_each(|event| {
$crate::log::debug!(target: concat!("events::", stringify!($name)), "{:?}", event); $crate::log::debug!(target: concat!("events::", stringify!($name)), "{:?}", event);
}); });
// clean events // clean events
<Self as Chain>::System::reset_events(); <Self as $crate::Chain>::System::reset_events();
// reinitialize before next call. // reinitialize before next call.
let next_block_number = block_number + 1; let next_block_number = block_number + 1;
<Self as Chain>::System::initialize(&next_block_number, &created_header.hash(), &Default::default()); <Self as $crate::Chain>::System::initialize(&next_block_number, &created_header.hash(), &Default::default());
<Self as Parachain>::ParachainSystem::on_initialize(next_block_number); <<Self as $crate::Parachain>::ParachainSystem as Hooks<$crate::BlockNumber>>::on_initialize(next_block_number);
}) })
}); });
@@ -894,6 +873,7 @@ macro_rules! decl_test_networks {
} }
), ),
+ +
$(,)?
) => { ) => {
$( $(
pub struct $name; pub struct $name;
@@ -907,7 +887,7 @@ macro_rules! decl_test_networks {
} }
fn reset() { fn reset() {
use $crate::{TestExt, VecDeque}; use $crate::{TestExt};
$crate::INITIALIZED.with(|b| b.borrow_mut().remove(Self::name())); $crate::INITIALIZED.with(|b| b.borrow_mut().remove(Self::name()));
$crate::DOWNWARD_MESSAGES.with(|b| b.borrow_mut().remove(Self::name())); $crate::DOWNWARD_MESSAGES.with(|b| b.borrow_mut().remove(Self::name()));
@@ -933,25 +913,25 @@ macro_rules! decl_test_networks {
$crate::PARA_IDS.with(|b| b.borrow_mut().insert(Self::name().to_string(), Self::para_ids())); $crate::PARA_IDS.with(|b| b.borrow_mut().insert(Self::name().to_string(), Self::para_ids()));
$crate::LAST_HEAD.with(|b| b.borrow_mut().insert(Self::name().to_string(), $crate::HashMap::new())); $crate::LAST_HEAD.with(|b| b.borrow_mut().insert(Self::name().to_string(), $crate::HashMap::new()));
$( <$parachain>::init(); )* $( <$parachain as $crate::Parachain>::init(); )*
} }
} }
fn para_ids() -> Vec<u32> { fn para_ids() -> Vec<u32> {
vec![$( vec![$(
<$parachain>::para_id().into(), <$parachain as $crate::Parachain>::para_id().into(),
)*] )*]
} }
fn relay_block_number() -> u32 { fn relay_block_number() -> u32 {
Self::Relay::ext_wrapper(|| { <Self::Relay as $crate::TestExt>::ext_wrapper(|| {
<Self::Relay as Chain>::System::block_number() <Self::Relay as $crate::Chain>::System::block_number()
}) })
} }
fn set_relay_block_number(number: u32) { fn set_relay_block_number(number: u32) {
Self::Relay::ext_wrapper(|| { <Self::Relay as $crate::TestExt>::ext_wrapper(|| {
<Self::Relay as Chain>::System::set_block_number(number); <Self::Relay as $crate::Chain>::System::set_block_number(number);
}) })
} }
@@ -972,8 +952,7 @@ macro_rules! decl_test_networks {
} }
fn process_downward_messages() { fn process_downward_messages() {
use $crate::{DmpMessageHandler, Bounded}; use $crate::{DmpMessageHandler, Bounded, Parachain, RelayChainBlockNumber, TestExt};
use polkadot_parachain_primitives::primitives::RelayChainBlockNumber;
while let Some((to_para_id, messages)) while let Some((to_para_id, messages))
= $crate::DOWNWARD_MESSAGES.with(|b| b.borrow_mut().get_mut(Self::name()).unwrap().pop_front()) { = $crate::DOWNWARD_MESSAGES.with(|b| b.borrow_mut().get_mut(Self::name()).unwrap().pop_front()) {
@@ -1005,7 +984,7 @@ macro_rules! decl_test_networks {
} }
fn process_horizontal_messages() { fn process_horizontal_messages() {
use $crate::{XcmpMessageHandler, Bounded}; use $crate::{XcmpMessageHandler, Bounded, Parachain, TestExt};
while let Some((to_para_id, messages)) while let Some((to_para_id, messages))
= $crate::HORIZONTAL_MESSAGES.with(|b| b.borrow_mut().get_mut(Self::name()).unwrap().pop_front()) { = $crate::HORIZONTAL_MESSAGES.with(|b| b.borrow_mut().get_mut(Self::name()).unwrap().pop_front()) {
@@ -1024,16 +1003,16 @@ macro_rules! decl_test_networks {
} }
fn process_upward_messages() { fn process_upward_messages() {
use $crate::{Bounded, ProcessMessage, WeightMeter}; use $crate::{Encode, ProcessMessage, TestExt};
use sp_core::Encode;
while let Some((from_para_id, msg)) = $crate::UPWARD_MESSAGES.with(|b| b.borrow_mut().get_mut(Self::name()).unwrap().pop_front()) { while let Some((from_para_id, msg)) = $crate::UPWARD_MESSAGES.with(|b| b.borrow_mut().get_mut(Self::name()).unwrap().pop_front()) {
let mut weight_meter = WeightMeter::new(); let mut weight_meter = $crate::WeightMeter::new();
<$relay_chain>::ext_wrapper(|| { <$relay_chain>::ext_wrapper(|| {
let _ = <$relay_chain as RelayChain>::MessageProcessor::process_message( let _ = <$relay_chain as $crate::RelayChain>::MessageProcessor::process_message(
&msg[..], &msg[..],
from_para_id.into(), from_para_id.into(),
&mut weight_meter, &mut weight_meter,
&mut msg.using_encoded(sp_core::blake2_256), &mut msg.using_encoded($crate::blake2_256),
); );
}); });
$crate::log::debug!(target: concat!("ump::", stringify!($name)) , "Upward message processed {:?} from para_id {:?}", &msg, &from_para_id); $crate::log::debug!(target: concat!("ump::", stringify!($name)) , "Upward message processed {:?} from para_id {:?}", &msg, &from_para_id);
@@ -1041,19 +1020,19 @@ macro_rules! decl_test_networks {
} }
fn process_bridged_messages() { fn process_bridged_messages() {
use $crate::Bridge; use $crate::{Bridge, BridgeMessageHandler, TestExt};
// Make sure both, including the target `Network` are initialized // Make sure both, including the target `Network` are initialized
<Self::Bridge as Bridge>::init(); <Self::Bridge as Bridge>::init();
while let Some(msg) = $crate::BRIDGED_MESSAGES.with(|b| b.borrow_mut().get_mut(Self::name()).unwrap().pop_front()) { while let Some(msg) = $crate::BRIDGED_MESSAGES.with(|b| b.borrow_mut().get_mut(Self::name()).unwrap().pop_front()) {
let dispatch_result = <<Self::Bridge as $crate::Bridge>::Target as TestExt>::ext_wrapper(|| { let dispatch_result = <<Self::Bridge as Bridge>::Target as TestExt>::ext_wrapper(|| {
<<Self::Bridge as Bridge>::Handler as BridgeMessageHandler>::dispatch_target_inbound_message(msg.clone()) <<Self::Bridge as Bridge>::Handler as BridgeMessageHandler>::dispatch_target_inbound_message(msg.clone())
}); });
match dispatch_result { match dispatch_result {
Err(e) => panic!("Error {:?} processing bridged message: {:?}", e, msg.clone()), Err(e) => panic!("Error {:?} processing bridged message: {:?}", e, msg.clone()),
Ok(()) => { Ok(()) => {
<<Self::Bridge as $crate::Bridge>::Source as TestExt>::ext_wrapper(|| { <<Self::Bridge as Bridge>::Source as TestExt>::ext_wrapper(|| {
<<Self::Bridge as Bridge>::Handler as BridgeMessageHandler>::notify_source_message_delivery(msg.id); <<Self::Bridge as Bridge>::Handler as BridgeMessageHandler>::notify_source_message_delivery(msg.id);
}); });
$crate::log::debug!(target: concat!("bridge::", stringify!($name)) , "Bridged message processed {:?}", msg.clone()); $crate::log::debug!(target: concat!("bridge::", stringify!($name)) , "Bridged message processed {:?}", msg.clone());
@@ -1067,8 +1046,6 @@ macro_rules! decl_test_networks {
relay_parent_number: u32, relay_parent_number: u32,
parent_head_data: $crate::HeadData, parent_head_data: $crate::HeadData,
) -> $crate::ParachainInherentData { ) -> $crate::ParachainInherentData {
use $crate::cumulus_primitives_core::{relay_chain::{HeadData, HrmpChannelId}, AbridgedHrmpChannel};
let mut sproof = $crate::RelayStateSproofBuilder::default(); let mut sproof = $crate::RelayStateSproofBuilder::default();
sproof.para_id = para_id.into(); sproof.para_id = para_id.into();
@@ -1084,11 +1061,11 @@ macro_rules! decl_test_networks {
sproof sproof
.hrmp_channels .hrmp_channels
.entry(HrmpChannelId { .entry($crate::HrmpChannelId {
sender: sproof.para_id, sender: sproof.para_id,
recipient: recipient_para_id, recipient: recipient_para_id,
}) })
.or_insert_with(|| AbridgedHrmpChannel { .or_insert_with(|| $crate::AbridgedHrmpChannel {
max_capacity: 1024, max_capacity: 1024,
max_total_size: 1024 * 1024, max_total_size: 1024 * 1024,
max_message_size: 1024 * 1024, max_message_size: 1024 * 1024,
@@ -1138,6 +1115,7 @@ macro_rules! decl_test_bridges {
} }
), ),
+ +
$(,)?
) => { ) => {
$( $(
#[derive(Debug)] #[derive(Debug)]
@@ -1165,8 +1143,8 @@ macro_rules! __impl_check_assertion {
impl<Origin, Destination, Hops, Args> impl<Origin, Destination, Hops, Args>
$crate::CheckAssertion<Origin, Destination, Hops, Args> for $chain $crate::CheckAssertion<Origin, Destination, Hops, Args> for $chain
where where
Origin: Chain + Clone, Origin: $crate::Chain + Clone,
Destination: Chain + Clone, Destination: $crate::Chain + Clone,
Origin::RuntimeOrigin: $crate::OriginTrait<AccountId = $crate::AccountId32> + Clone, Origin::RuntimeOrigin: $crate::OriginTrait<AccountId = $crate::AccountId32> + Clone,
Destination::RuntimeOrigin: Destination::RuntimeOrigin:
$crate::OriginTrait<AccountId = $crate::AccountId32> + Clone, $crate::OriginTrait<AccountId = $crate::AccountId32> + Clone,
@@ -1174,6 +1152,8 @@ macro_rules! __impl_check_assertion {
Args: Clone, Args: Clone,
{ {
fn check_assertion(test: $crate::Test<Origin, Destination, Hops, Args>) { fn check_assertion(test: $crate::Test<Origin, Destination, Hops, Args>) {
use $crate::TestExt;
let chain_name = std::any::type_name::<$chain>(); let chain_name = std::any::type_name::<$chain>();
<$chain>::execute_with(|| { <$chain>::execute_with(|| {
@@ -1193,7 +1173,7 @@ macro_rules! __impl_check_assertion {
macro_rules! assert_expected_events { macro_rules! assert_expected_events {
( $chain:ident, vec![$( $event_pat:pat => { $($attr:ident : $condition:expr, )* }, )*] ) => { ( $chain:ident, vec![$( $event_pat:pat => { $($attr:ident : $condition:expr, )* }, )*] ) => {
let mut message: Vec<String> = Vec::new(); let mut message: Vec<String> = Vec::new();
let mut events = <$chain>::events(); let mut events = <$chain as $crate::Chain>::events();
$( $(
let mut event_received = false; let mut event_received = false;
@@ -1256,7 +1236,7 @@ macro_rules! assert_expected_events {
if !message.is_empty() { if !message.is_empty() {
// Log events as they will not be logged after the panic // Log events as they will not be logged after the panic
<$chain>::events().iter().for_each(|event| { <$chain as $crate::Chain>::events().iter().for_each(|event| {
$crate::log::debug!(target: concat!("events::", stringify!($chain)), "{:?}", event); $crate::log::debug!(target: concat!("events::", stringify!($chain)), "{:?}", event);
}); });
panic!("{}", message.concat()) panic!("{}", message.concat())
@@ -1275,10 +1255,10 @@ macro_rules! bx {
macro_rules! decl_test_sender_receiver_accounts_parameter_types { macro_rules! decl_test_sender_receiver_accounts_parameter_types {
( $( $chain:ident { sender: $sender:expr, receiver: $receiver:expr }),+ ) => { ( $( $chain:ident { sender: $sender:expr, receiver: $receiver:expr }),+ ) => {
$crate::paste::paste! { $crate::paste::paste! {
parameter_types! { $crate::parameter_types! {
$( $(
pub [<$chain Sender>]: $crate::AccountId = <$chain>::account_id_of($sender); pub [<$chain Sender>]: $crate::AccountId = <$chain as $crate::Chain>::account_id_of($sender);
pub [<$chain Receiver>]: $crate::AccountId = <$chain>::account_id_of($receiver); pub [<$chain Receiver>]: $crate::AccountId = <$chain as $crate::Chain>::account_id_of($receiver);
)+ )+
} }
} }