feat: initialize Kurdistan SDK - independent fork of Polkadot SDK
This commit is contained in:
@@ -0,0 +1,161 @@
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// This file is part of Pezkuwi.
|
||||
|
||||
// Pezkuwi 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.
|
||||
|
||||
// Pezkuwi 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 Pezkuwi. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Test the methods generated by the Builder derive macro.
|
||||
//! Tests directly on the actual Xcm struct and Instruction enum.
|
||||
|
||||
use frame_support::BoundedVec;
|
||||
use xcm::latest::prelude::*;
|
||||
|
||||
#[test]
|
||||
fn builder_pattern_works() {
|
||||
let asset: Asset = (Here, 100u128).into();
|
||||
let beneficiary: Location = [0u8; 32].into();
|
||||
let message: Xcm<()> = Xcm::builder()
|
||||
.receive_teleported_asset(asset.clone())
|
||||
.buy_execution(asset.clone(), Unlimited)
|
||||
.deposit_asset(asset.clone(), beneficiary.clone())
|
||||
.build();
|
||||
assert_eq!(
|
||||
message,
|
||||
Xcm(vec![
|
||||
ReceiveTeleportedAsset(asset.clone().into()),
|
||||
BuyExecution { fees: asset.clone(), weight_limit: Unlimited },
|
||||
DepositAsset { assets: asset.into(), beneficiary },
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn default_builder_requires_buy_execution() {
|
||||
let asset: Asset = (Here, 100u128).into();
|
||||
let beneficiary: Location = AccountId32 { id: [0u8; 32], network: None }.into();
|
||||
// This is invalid, since it doesn't pay for fees.
|
||||
// This is enforced by the runtime, because the build() method doesn't exist
|
||||
// on the resulting type.
|
||||
// let message: Xcm<()> = Xcm::builder()
|
||||
// .withdraw_asset(asset.clone().into())
|
||||
// .deposit_asset(asset.into(), beneficiary)
|
||||
// .build();
|
||||
|
||||
// To be able to do that, we need to use the explicitly unpaid variant
|
||||
let message: Xcm<()> = Xcm::builder_unpaid()
|
||||
.unpaid_execution(Unlimited, None)
|
||||
.withdraw_asset(asset.clone())
|
||||
.deposit_asset(asset.clone(), beneficiary.clone())
|
||||
.build(); // This works
|
||||
assert_eq!(
|
||||
message,
|
||||
Xcm(vec![
|
||||
UnpaidExecution { weight_limit: Unlimited, check_origin: None },
|
||||
WithdrawAsset(asset.clone().into()),
|
||||
DepositAsset { assets: asset.clone().into(), beneficiary: beneficiary.clone() },
|
||||
])
|
||||
);
|
||||
|
||||
// The other option doesn't have any limits whatsoever, so it should
|
||||
// only be used when you really know what you're doing.
|
||||
let message: Xcm<()> = Xcm::builder_unsafe()
|
||||
.withdraw_asset(asset.clone())
|
||||
.deposit_asset(asset.clone(), beneficiary.clone())
|
||||
.build();
|
||||
assert_eq!(
|
||||
message,
|
||||
Xcm(vec![
|
||||
WithdrawAsset(asset.clone().into()),
|
||||
DepositAsset { assets: asset.clone().into(), beneficiary },
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn default_builder_allows_clear_origin_before_buy_execution() {
|
||||
let asset: Asset = (Here, 100u128).into();
|
||||
let beneficiary: Location = [0u8; 32].into();
|
||||
let message: Xcm<()> = Xcm::builder()
|
||||
.receive_teleported_asset(asset.clone())
|
||||
.clear_origin()
|
||||
.buy_execution(asset.clone(), Unlimited)
|
||||
.deposit_asset(asset.clone(), beneficiary.clone())
|
||||
.build();
|
||||
assert_eq!(
|
||||
message,
|
||||
Xcm(vec![
|
||||
ReceiveTeleportedAsset(asset.clone().into()),
|
||||
ClearOrigin,
|
||||
BuyExecution { fees: asset.clone(), weight_limit: Unlimited },
|
||||
DepositAsset { assets: asset.into(), beneficiary },
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bounded_vecs_use_vecs_and_truncate_them() {
|
||||
let claimer = Location::parent();
|
||||
// We can use a vec instead of a bounded vec for specifying hints.
|
||||
let xcm: Xcm<()> = Xcm::builder_unsafe()
|
||||
.set_hints(vec![AssetClaimer { location: claimer.clone() }])
|
||||
.build();
|
||||
assert_eq!(
|
||||
xcm,
|
||||
Xcm(vec![SetHints {
|
||||
hints: BoundedVec::<Hint, HintNumVariants>::truncate_from(vec![AssetClaimer {
|
||||
location: Location::parent()
|
||||
},]),
|
||||
},])
|
||||
);
|
||||
|
||||
// If we include more than the limit they'll get truncated.
|
||||
let xcm: Xcm<()> = Xcm::builder_unsafe()
|
||||
.set_hints(vec![
|
||||
AssetClaimer { location: claimer.clone() },
|
||||
AssetClaimer { location: Location::here() },
|
||||
])
|
||||
.build();
|
||||
assert_eq!(
|
||||
xcm,
|
||||
Xcm(vec![SetHints {
|
||||
hints: BoundedVec::<Hint, HintNumVariants>::truncate_from(vec![AssetClaimer {
|
||||
location: Location::parent()
|
||||
},]),
|
||||
},])
|
||||
);
|
||||
|
||||
let xcm: Xcm<()> = Xcm::builder()
|
||||
.withdraw_asset((Here, 100u128))
|
||||
.set_hints(vec![AssetClaimer { location: claimer }])
|
||||
.clear_origin()
|
||||
.pay_fees((Here, 10u128))
|
||||
.deposit_asset(All, [0u8; 32])
|
||||
.build();
|
||||
assert_eq!(
|
||||
xcm,
|
||||
Xcm(vec![
|
||||
WithdrawAsset(Asset { id: AssetId(Location::here()), fun: Fungible(100) }.into()),
|
||||
SetHints {
|
||||
hints: BoundedVec::<Hint, HintNumVariants>::truncate_from(vec![AssetClaimer {
|
||||
location: Location::parent()
|
||||
}])
|
||||
},
|
||||
ClearOrigin,
|
||||
PayFees { asset: Asset { id: AssetId(Location::here()), fun: Fungible(10) } },
|
||||
DepositAsset {
|
||||
assets: All.into(),
|
||||
beneficiary: AccountId32 { id: [0u8; 32], network: None }.into()
|
||||
},
|
||||
])
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// This file is part of Pezkuwi.
|
||||
|
||||
// Pezkuwi 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.
|
||||
|
||||
// Pezkuwi 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 Pezkuwi. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use xcm::v3::prelude::*;
|
||||
|
||||
#[test]
|
||||
fn slice_syntax_in_v3_works() {
|
||||
let old_junctions = Junctions::X2(Teyrchain(1), PalletInstance(1));
|
||||
let new_junctions = Junctions::from([Teyrchain(1), PalletInstance(1)]);
|
||||
assert_eq!(old_junctions, new_junctions);
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// This file is part of Pezkuwi.
|
||||
|
||||
// Pezkuwi 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.
|
||||
|
||||
// Pezkuwi 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 Pezkuwi. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Test the struct generated by the `NumVariants` derive macro.
|
||||
|
||||
use frame_support::traits::Get;
|
||||
use xcm_procedural::NumVariants;
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(NumVariants)]
|
||||
enum SomeEnum {
|
||||
Variant1,
|
||||
Variant2,
|
||||
Variant3,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn num_variants_works() {
|
||||
assert_eq!(SomeEnumNumVariants::get(), 3);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// This file is part of Pezkuwi.
|
||||
|
||||
// Pezkuwi 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.
|
||||
|
||||
// Pezkuwi 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 Pezkuwi. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! UI tests for XCM procedural macros
|
||||
|
||||
#[test]
|
||||
fn ui() {
|
||||
// Only run the ui tests when `RUN_UI_TESTS` is set.
|
||||
if std::env::var("RUN_UI_TESTS").is_err() {
|
||||
return;
|
||||
}
|
||||
|
||||
// As trybuild is using `cargo check`, we don't need the real WASM binaries.
|
||||
std::env::set_var("SKIP_WASM_BUILD", "1");
|
||||
|
||||
let t = trybuild::TestCases::new();
|
||||
t.compile_fail("tests/ui/**/*.rs");
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// This file is part of Pezkuwi.
|
||||
|
||||
// Pezkuwi 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.
|
||||
|
||||
// Pezkuwi 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 Pezkuwi. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Test error when using a badly formatted attribute.
|
||||
|
||||
use xcm_procedural::Builder;
|
||||
|
||||
struct Xcm<Call>(pub Vec<Instruction<Call>>);
|
||||
|
||||
#[derive(Builder)]
|
||||
enum Instruction<Call> {
|
||||
#[builder(funds_holding = 2)]
|
||||
WithdrawAsset(u128),
|
||||
BuyExecution { fees: u128 },
|
||||
UnpaidExecution { weight_limit: (u32, u32) },
|
||||
Transact { call: Call },
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: Expected `builder(loads_holding)` or `builder(pays_fees)`
|
||||
--> tests/ui/builder_pattern/badly_formatted_attribute.rs:25:5
|
||||
|
|
||||
25 | #[builder(funds_holding = 2)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@@ -0,0 +1,29 @@
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// This file is part of Pezkuwi.
|
||||
|
||||
// Pezkuwi 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.
|
||||
|
||||
// Pezkuwi 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 Pezkuwi. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Test error when there's no `UnpaidExecution` instruction.
|
||||
|
||||
use xcm_procedural::Builder;
|
||||
|
||||
struct Xcm<Call>(pub Vec<Instruction<Call>>);
|
||||
|
||||
#[derive(Builder)]
|
||||
enum Instruction<Call> {
|
||||
BuyExecution { fees: u128 },
|
||||
Transact { call: Call },
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,6 @@
|
||||
error: No UnpaidExecution instruction
|
||||
--> tests/ui/builder_pattern/no_unpaid_execution.rs:25:5
|
||||
|
|
||||
25 | / BuyExecution { fees: u128 },
|
||||
26 | | Transact { call: Call },
|
||||
| |____________________________^
|
||||
@@ -0,0 +1,5 @@
|
||||
error: Expected `builder(loads_holding)` or `builder(pays_fees)`
|
||||
--> tests/ui/builder_pattern/unexpected_attribute.rs:25:5
|
||||
|
|
||||
25 | #[builder(funds_holding)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@@ -0,0 +1,25 @@
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// This file is part of Pezkuwi.
|
||||
|
||||
// Pezkuwi 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.
|
||||
|
||||
// Pezkuwi 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 Pezkuwi. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Test error when attaching the derive builder macro to something
|
||||
//! other than the XCM `Instruction` enum.
|
||||
|
||||
use xcm_procedural::Builder;
|
||||
|
||||
#[derive(Builder)]
|
||||
struct SomeStruct;
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: Expected the `Instruction` enum
|
||||
--> tests/ui/builder_pattern/wrong_target.rs:23:1
|
||||
|
|
||||
23 | struct SomeStruct;
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
Reference in New Issue
Block a user