This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 380
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add statemine emulator tests (#2630)
* fix typo * statemine tests * fix statemine tests * cargo fmt, update readme
- Loading branch information
Showing
11 changed files
with
293 additions
and
14 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
parachains/integration-tests/emulated/assets/statemine/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
[package] | ||
name = "statemine-it" | ||
version = "1.0.0" | ||
authors = ["Parity Technologies <admin@parity.io>"] | ||
edition = "2021" | ||
description = "Statemine parachain runtime integration tests with xcm-emulator" | ||
|
||
[dependencies] | ||
codec = { package = "parity-scale-codec", version = "3.4.0", default-features = false } | ||
|
||
# Substrate | ||
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master" } | ||
frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master" } | ||
frame-system = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master" } | ||
sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master" } | ||
sp-weights = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master" } | ||
pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master" } | ||
pallet-assets = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master" } | ||
|
||
# Polkadot | ||
polkadot-core-primitives = { default-features = false, git = "https://github.com/paritytech/polkadot", branch = "master" } | ||
polkadot-parachain = { default-features = false, git = "https://github.com/paritytech/polkadot", branch = "master" } | ||
polkadot-runtime-parachains = { git = "https://github.com/paritytech/polkadot", branch = "master" } | ||
polkadot-runtime = { git = "https://github.com/paritytech/polkadot", branch = "master" } | ||
xcm = { default-features = false, git = "https://github.com/paritytech/polkadot", branch = "master" } | ||
xcm-executor = { default-features = false, git = "https://github.com/paritytech/polkadot", branch = "master" } | ||
pallet-xcm = { default-features = false, git = "https://github.com/paritytech/polkadot", branch = "master" } | ||
|
||
# Cumulus | ||
parachains-common = { path = "../../../../common" } | ||
penpal-runtime = { path = "../../../../runtimes/testing/penpal" } | ||
statemine-runtime = { path = "../../../../runtimes/assets/statemine" } | ||
|
||
# Local | ||
xcm-emulator = { default-features = false, path = "../../../../../xcm/xcm-emulator" } | ||
integration-tests-common = { default-features = false, path = "../../common" } |
30 changes: 30 additions & 0 deletions
30
parachains/integration-tests/emulated/assets/statemine/src/lib.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
pub use codec::Encode; | ||
pub use frame_support::{ | ||
assert_ok, instances::Instance1, pallet_prelude::Weight, traits::fungibles::Inspect, | ||
}; | ||
pub use integration_tests_common::{ | ||
constants::{ | ||
accounts::{ALICE, BOB}, | ||
kusama::ED as KUSAMA_ED, | ||
PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3, | ||
}, | ||
AccountId, BHKusama, BHKusamaPallet, BHKusamaReceiver, BHKusamaSender, BHPolkadot, | ||
BHPolkadotPallet, BHPolkadotReceiver, BHPolkadotSender, Collectives, CollectivesPallet, | ||
CollectivesReceiver, CollectivesSender, Kusama, KusamaMockNet, KusamaPallet, KusamaReceiver, | ||
KusamaSender, PenpalKusama, PenpalKusamaReceiver, PenpalKusamaSender, PenpalPolkadot, | ||
PenpalPolkadotReceiver, PenpalPolkadotSender, Polkadot, PolkadotMockNet, PolkadotPallet, | ||
PolkadotReceiver, PolkadotSender, Statemine, StateminePallet, StatemineReceiver, | ||
StatemineSender, | ||
}; | ||
pub use polkadot_core_primitives::InboundDownwardMessage; | ||
pub use xcm::{ | ||
prelude::*, | ||
v3::{Error, NetworkId::Kusama as KusamaId}, | ||
}; | ||
pub use xcm_emulator::{ | ||
assert_expected_events, bx, cumulus_pallet_dmp_queue, helpers::weight_within_threshold, | ||
Parachain as Para, RelayChain as Relay, TestExt, | ||
}; | ||
|
||
#[cfg(test)] | ||
mod tests; |
3 changes: 3 additions & 0 deletions
3
parachains/integration-tests/emulated/assets/statemine/src/tests/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
mod reserve_transfer; | ||
mod teleport; | ||
mod transact; |
63 changes: 63 additions & 0 deletions
63
parachains/integration-tests/emulated/assets/statemine/src/tests/reserve_transfer.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
use crate::*; | ||
|
||
#[test] | ||
fn reserve_transfer_native_asset_from_relay_to_assets() { | ||
// Init tests variables | ||
let amount = KUSAMA_ED * 1000; | ||
let relay_sender_balance_before = Kusama::account_data_of(KusamaSender::get()).free; | ||
let para_receiver_balance_before = Statemine::account_data_of(StatemineReceiver::get()).free; | ||
|
||
let origin = <Kusama as Relay>::RuntimeOrigin::signed(KusamaSender::get()); | ||
let assets_para_destination: VersionedMultiLocation = | ||
Kusama::child_location_of(Statemine::para_id()).into(); | ||
let beneficiary: VersionedMultiLocation = | ||
AccountId32 { network: None, id: StatemineReceiver::get().into() }.into(); | ||
let native_assets: VersionedMultiAssets = (Here, amount).into(); | ||
let fee_asset_item = 0; | ||
let weight_limit = WeightLimit::Unlimited; | ||
|
||
// Send XCM message from Relay Chain | ||
Kusama::execute_with(|| { | ||
assert_ok!(<Kusama as KusamaPallet>::XcmPallet::limited_reserve_transfer_assets( | ||
origin, | ||
bx!(assets_para_destination), | ||
bx!(beneficiary), | ||
bx!(native_assets), | ||
fee_asset_item, | ||
weight_limit, | ||
)); | ||
|
||
type RuntimeEvent = <Kusama as Relay>::RuntimeEvent; | ||
|
||
assert_expected_events!( | ||
Kusama, | ||
vec![ | ||
RuntimeEvent::XcmPallet(pallet_xcm::Event::Attempted(Outcome::Complete(weight))) => { | ||
weight: weight_within_threshold((REF_TIME_THRESHOLD, PROOF_SIZE_THRESHOLD), Weight::from_parts(754_244_000, 0), *weight), | ||
}, | ||
] | ||
); | ||
}); | ||
|
||
// Receive XCM message in Assets Parachain | ||
Statemine::execute_with(|| { | ||
type RuntimeEvent = <Statemine as Para>::RuntimeEvent; | ||
|
||
assert_expected_events!( | ||
Statemine, | ||
vec![ | ||
RuntimeEvent::DmpQueue(cumulus_pallet_dmp_queue::Event::ExecutedDownward { | ||
outcome: Outcome::Incomplete(_, Error::UntrustedReserveLocation), | ||
.. | ||
}) => {}, | ||
] | ||
); | ||
}); | ||
|
||
// Check if balances are updated accordingly in Relay Chain and Assets Parachain | ||
let relay_sender_balance_after = Kusama::account_data_of(KusamaSender::get()).free; | ||
let para_sender_balance_after = Statemine::account_data_of(StatemineReceiver::get()).free; | ||
|
||
assert_eq!(relay_sender_balance_before - amount, relay_sender_balance_after); | ||
assert_eq!(para_sender_balance_after, para_receiver_balance_before); | ||
} |
60 changes: 60 additions & 0 deletions
60
parachains/integration-tests/emulated/assets/statemine/src/tests/teleport.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use crate::*; | ||
|
||
#[test] | ||
fn teleport_native_assets_from_relay_to_assets_para() { | ||
// Init tests variables | ||
let amount = KUSAMA_ED * 1000; | ||
let relay_sender_balance_before = Kusama::account_data_of(KusamaSender::get()).free; | ||
let para_receiver_balance_before = Statemine::account_data_of(StatemineReceiver::get()).free; | ||
|
||
let origin = <Kusama as Relay>::RuntimeOrigin::signed(KusamaSender::get()); | ||
let assets_para_destination: VersionedMultiLocation = | ||
Kusama::child_location_of(Statemine::para_id()).into(); | ||
let beneficiary: VersionedMultiLocation = | ||
AccountId32 { network: None, id: StatemineReceiver::get().into() }.into(); | ||
let native_assets: VersionedMultiAssets = (Here, amount).into(); | ||
let fee_asset_item = 0; | ||
let weight_limit = WeightLimit::Unlimited; | ||
|
||
// Send XCM message from Relay Chain | ||
Kusama::execute_with(|| { | ||
assert_ok!(<Kusama as KusamaPallet>::XcmPallet::limited_teleport_assets( | ||
origin, | ||
bx!(assets_para_destination), | ||
bx!(beneficiary), | ||
bx!(native_assets), | ||
fee_asset_item, | ||
weight_limit, | ||
)); | ||
|
||
type RuntimeEvent = <Kusama as Relay>::RuntimeEvent; | ||
|
||
assert_expected_events!( | ||
Kusama, | ||
vec![ | ||
RuntimeEvent::XcmPallet(pallet_xcm::Event::Attempted(Outcome::Complete { .. })) => {}, | ||
] | ||
); | ||
}); | ||
|
||
// Receive XCM message in Assets Parachain | ||
Statemine::execute_with(|| { | ||
type RuntimeEvent = <Statemine as Para>::RuntimeEvent; | ||
|
||
assert_expected_events!( | ||
Statemine, | ||
vec![ | ||
RuntimeEvent::Balances(pallet_balances::Event::Deposit { who, .. }) => { | ||
who: *who == StatemineReceiver::get().into(), | ||
}, | ||
] | ||
); | ||
}); | ||
|
||
// Check if balances are updated accordingly in Relay Chain and Assets Parachain | ||
let relay_sender_balance_after = Kusama::account_data_of(KusamaSender::get()).free; | ||
let para_sender_balance_after = Statemine::account_data_of(StatemineReceiver::get()).free; | ||
|
||
assert_eq!(relay_sender_balance_before - amount, relay_sender_balance_after); | ||
assert!(para_sender_balance_after > para_receiver_balance_before); | ||
} |
58 changes: 58 additions & 0 deletions
58
parachains/integration-tests/emulated/assets/statemine/src/tests/transact.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use crate::*; | ||
|
||
#[test] | ||
fn transact_sudo_from_relay_to_assets_para() { | ||
// Init tests variables | ||
// Call to be executed in Assets Parachain | ||
const ASSET_ID: u32 = 1; | ||
|
||
let call = <Statemine as Para>::RuntimeCall::Assets(pallet_assets::Call::< | ||
<Statemine as Para>::Runtime, | ||
Instance1, | ||
>::force_create { | ||
id: ASSET_ID.into(), | ||
is_sufficient: true, | ||
min_balance: 1000, | ||
owner: StatemineSender::get().into(), | ||
}) | ||
.encode() | ||
.into(); | ||
|
||
// XcmPallet send arguments | ||
let sudo_origin = <Kusama as Relay>::RuntimeOrigin::root(); | ||
let assets_para_destination: VersionedMultiLocation = | ||
Kusama::child_location_of(Statemine::para_id()).into(); | ||
|
||
let weight_limit = WeightLimit::Unlimited; | ||
let require_weight_at_most = Weight::from_parts(1000000000, 200000); | ||
let origin_kind = OriginKind::Superuser; | ||
let check_origin = None; | ||
|
||
let xcm = VersionedXcm::from(Xcm(vec![ | ||
UnpaidExecution { weight_limit, check_origin }, | ||
Transact { require_weight_at_most, origin_kind, call }, | ||
])); | ||
|
||
// Send XCM message from Relay Chain | ||
Kusama::execute_with(|| { | ||
assert_ok!(<Kusama as KusamaPallet>::XcmPallet::send( | ||
sudo_origin, | ||
bx!(assets_para_destination), | ||
bx!(xcm), | ||
)); | ||
|
||
type RuntimeEvent = <Kusama as Relay>::RuntimeEvent; | ||
|
||
assert_expected_events!( | ||
Kusama, | ||
vec![ | ||
RuntimeEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {}, | ||
] | ||
); | ||
}); | ||
|
||
// Receive XCM message in Assets Parachain | ||
Statemine::execute_with(|| { | ||
assert!(<Statemine as StateminePallet>::Assets::asset_exists(ASSET_ID)); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.