Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test/fix: polkadot xcm #644

Merged
merged 2 commits into from Jun 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
355 changes: 185 additions & 170 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions parachain/runtime/interlay/src/lib.rs
Expand Up @@ -23,6 +23,7 @@ use frame_system::{
limits::{BlockLength, BlockWeights},
EnsureRoot, RawOrigin,
};
pub use orml_asset_registry::AssetMetadata;
use orml_asset_registry::SequentialId;
use orml_traits::parameter_type_with_key;
use pallet_transaction_payment::{Multiplier, TargetedFeeAdjustment};
Expand Down
26 changes: 26 additions & 0 deletions parachain/runtime/interlay/src/xcm_config.rs
Expand Up @@ -21,6 +21,7 @@ use xcm_builder::{
RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative,
SignedToAccountId32, SovereignSignedViaLocation, TakeRevenue, TakeWeightCredit,
};
pub use xcm_executor;
use xcm_executor::{Config, XcmExecutor};

parameter_types! {
Expand Down Expand Up @@ -105,6 +106,22 @@ parameter_types! {
// (I)BTC:DOT = 1:2266 & Satoshi:Planck = 1:100
dot_per_second() / 226_600
);
pub IntrPerSecond: (AssetId, u128) = ( // can be removed once we no longer need to support polkadot < 0.9.16
MultiLocation::new(
1,
X2(Parachain(ParachainInfo::get().into()), GeneralKey(Token(INTR).encode())),
).into(),
// KINT:KSM = 4:3
(dot_per_second() * 4) / 3
);
pub IbtcPerSecond: (AssetId, u128) = (
MultiLocation::new(
1,
X2(Parachain(ParachainInfo::get().into()), GeneralKey(Token(IBTC).encode())),
).into(),
// (I)BTC:DOT = 1:2266 & Satoshi:Planck = 1:100
dot_per_second() / 226_600
);
}

pub struct ToAuthor;
Expand All @@ -119,6 +136,10 @@ impl TakeRevenue for ToAuthor {
if let Some(author) = pallet_authorship::Pallet::<Runtime>::author() {
// Note: will need rethinking once we have existential deposits. Ignore the result.
let _ = Tokens::deposit(currency_id, &author, amount);
} else {
// should only happen in tests. In the tests it helps us ensure that the fee are
// dealt with.
let _ = Tokens::deposit(currency_id, &TreasuryAccount::get(), amount);
}
}
}
Expand All @@ -129,6 +150,11 @@ pub type Trader = (
FixedRateOfFungible<DotPerSecond, ToAuthor>,
FixedRateOfFungible<CanonicalizedIntrPerSecond, ToAuthor>,
FixedRateOfFungible<CanonicalizedIbtcPerSecond, ToAuthor>,
// The xcm-executor ensures no non-canonicalized versions will be used in transfers to our chain
// when execute_xcm_in_credit is used. However, there are still cases where it can appear, e.g.
// when reclaiming trapped tokens.
FixedRateOfFungible<IntrPerSecond, ToAuthor>,
FixedRateOfFungible<IbtcPerSecond, ToAuthor>,
AssetRegistryTrader<FixedRateAssetRegistryTrader<MyFixedConversionRateProvider>, ToAuthor>,
);

Expand Down
6 changes: 6 additions & 0 deletions parachain/runtime/runtime-tests/Cargo.toml
Expand Up @@ -53,6 +53,7 @@ pallet-society = { git = "https://github.com/paritytech/substrate", branch = "po
pallet-authorship = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24", default-features = false }
pallet-aura = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24", default-features = false }
sp-consensus-aura = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24", default-features = false }
pallet-session = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24", default-features = false }

# Cumulus dependencies
cumulus-pallet-aura-ext = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.24", default-features = false }
Expand All @@ -72,6 +73,7 @@ polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch =
polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.24", default-features = false }
polkadot-runtime-parachains = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.24", default-features = false }
kusama-runtime = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.24", default-features = false }
polkadot-runtime = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.24", default-features = false }
xcm = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.24", default-features = false }
xcm-builder = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.24", default-features = false }
xcm-executor = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.24", default-features = false }
Expand All @@ -98,6 +100,7 @@ annuity = { path = "../../../crates/annuity", default-features = false }
supply = { path = "../../../crates/supply", default-features = false }

kintsugi-runtime-parachain = { path = "../kintsugi", default-features = false }
interlay-runtime-parachain = { path = "../interlay", default-features = false }
testnet-kintsugi-runtime-parachain = { path = "../testnet-kintsugi", default-features = false }
testnet-interlay-runtime-parachain = { path = "../testnet-interlay", default-features = false }

Expand Down Expand Up @@ -172,6 +175,7 @@ std = [

"pallet-authorship/std",
"pallet-aura/std",
"pallet-session/std",
"sp-consensus-aura/std",

"cumulus-pallet-aura-ext/std",
Expand All @@ -189,12 +193,14 @@ std = [
"polkadot-primitives/std",
"polkadot-runtime-parachains/std",
"kusama-runtime/std",
"polkadot-runtime/std",
"xcm/std",
"xcm-builder/std",
"xcm-executor/std",
"pallet-xcm/std",

"kintsugi-runtime-parachain/std",
"interlay-runtime-parachain/std",
"testnet-kintsugi-runtime-parachain/std",
"testnet-interlay-runtime-parachain/std",

Expand Down
1 change: 0 additions & 1 deletion parachain/runtime/runtime-tests/src/lib.rs
@@ -1,4 +1,3 @@
#![cfg(test)]

mod relaychain;
mod setup;
@@ -1,9 +1,14 @@
use crate::{relaychain::kusama_test_net::*, setup::*};
use crate::relaychain::kusama_test_net::*;
use codec::Encode;
use frame_support::{assert_ok, weights::WeightToFee};
use orml_traits::MultiCurrency;
use primitives::CurrencyId::Token;
use primitives::{
CurrencyId::{ForeignAsset, Token},
CustomMetadata,
};
use xcm::latest::prelude::*;
use xcm_builder::ParentIsPreset;
use xcm_emulator::TestExt;
use xcm_emulator::{TestExt, XcmExecutor};
use xcm_executor::traits::Convert;

mod hrmp {
Expand Down
91 changes: 89 additions & 2 deletions parachain/runtime/runtime-tests/src/relaychain/kusama_test_net.rs
@@ -1,10 +1,17 @@
use crate::setup::*;
use frame_support::traits::GenesisBuild;
pub use kintsugi_runtime_parachain::{xcm_config::*, *};
use polkadot_primitives::v2::{BlockNumber, MAX_CODE_SIZE, MAX_POV_SIZE};
use polkadot_runtime_parachains::configuration::HostConfiguration;
use primitives::CurrencyId::Token;
pub use primitives::{
CurrencyId::Token,
TokenSymbol::{KINT, KSM},
};
use sp_runtime::traits::AccountIdConversion;
use xcm_emulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain};

pub const KINTSUGI_PARA_ID: u32 = 2092;
pub const SIBLING_PARA_ID: u32 = 2001;

decl_test_relay_chain! {
pub struct KusamaNet {
Runtime = kusama_runtime::Runtime,
Expand Down Expand Up @@ -144,3 +151,83 @@ pub fn para_ext(parachain_id: u32) -> sp_io::TestExternalities {
.parachain_id(parachain_id)
.build()
}

#[allow(dead_code)]
pub const DEFAULT: [u8; 32] = [0u8; 32];
#[allow(dead_code)]
pub const ALICE: [u8; 32] = [4u8; 32];
#[allow(dead_code)]
pub const BOB: [u8; 32] = [5u8; 32];

pub struct ExtBuilder {
balances: Vec<(AccountId, CurrencyId, Balance)>,
parachain_id: u32,
}

impl Default for ExtBuilder {
fn default() -> Self {
Self {
balances: vec![],
parachain_id: 2000,
}
}
}

impl ExtBuilder {
pub fn balances(mut self, balances: Vec<(AccountId, CurrencyId, Balance)>) -> Self {
self.balances = balances;
self
}

#[allow(dead_code)]
pub fn parachain_id(mut self, parachain_id: u32) -> Self {
self.parachain_id = parachain_id;
self
}

pub fn build(self) -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::default()
.build_storage::<Runtime>()
.unwrap();

let native_currency_id = GetNativeCurrencyId::get();

orml_tokens::GenesisConfig::<Runtime> {
balances: self
.balances
.into_iter()
.filter(|(_, currency_id, _)| *currency_id != native_currency_id)
.collect::<Vec<_>>(),
}
.assimilate_storage(&mut t)
.unwrap();

<parachain_info::GenesisConfig as GenesisBuild<Runtime>>::assimilate_storage(
&parachain_info::GenesisConfig {
parachain_id: self.parachain_id.into(),
},
&mut t,
)
.unwrap();

<pallet_xcm::GenesisConfig as GenesisBuild<Runtime>>::assimilate_storage(
&pallet_xcm::GenesisConfig {
safe_xcm_version: Some(2),
},
&mut t,
)
.unwrap();

let mut ext = sp_io::TestExternalities::new(t);
ext.execute_with(|| System::set_block_number(1));
ext
}
}

pub(crate) fn kintsugi_sovereign_account_on_kusama() -> AccountId {
polkadot_parachain::primitives::Id::from(KINTSUGI_PARA_ID).into_account_truncating()
}

pub(crate) fn sibling_sovereign_account_on_kusama() -> AccountId {
polkadot_parachain::primitives::Id::from(SIBLING_PARA_ID).into_account_truncating()
}
2 changes: 2 additions & 0 deletions parachain/runtime/runtime-tests/src/relaychain/mod.rs
@@ -1,2 +1,4 @@
mod kusama_cross_chain_transfer;
pub mod kusama_test_net;
mod polkadot_cross_chain_transfer;
pub mod polkadot_test_net;