Skip to content

Commit

Permalink
Merge branch 'master' into aleks-fix-data-preservers-benchmarking
Browse files Browse the repository at this point in the history
  • Loading branch information
chexware authored Dec 21, 2024
2 parents 623b7db + 9c52d4d commit 55c37fd
Show file tree
Hide file tree
Showing 43 changed files with 2,503 additions and 647 deletions.
668 changes: 344 additions & 324 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ tp-author-noting-inherent = { path = "primitives/author-noting-inherent", defaul
tp-bridge = { path = "primitives/bridge", default-features = false }
tp-maths = { path = "primitives/maths", default-features = false }
tp-traits = { path = "primitives/traits", default-features = false }
tp-xcm-commons = { path = "primitives/xcm-commons", default-features = false }
tp-xcm-core-buyer = { path = "primitives/xcm-core-buyer", default-features = false }

# Dancekit (wasm)
Expand Down
26 changes: 26 additions & 0 deletions primitives/xcm-commons/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[package]
name = "tp-xcm-commons"
edition = "2021"
version = "0.1.0"
[package.authors]
workspace = true
[package.repository]
workspace = true

[lints]
workspace = true

[dependencies]
frame-support = { workspace = true }
log = { workspace = true }
staging-xcm = { workspace = true }

[features]
default = [
"std",
]
std = [
"frame-support/std",
"log/std",
"staging-xcm/std",
]
59 changes: 59 additions & 0 deletions primitives/xcm-commons/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright (C) Moondance Labs Ltd.
// This file is part of Tanssi.

// Tanssi 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.

// Tanssi 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 Tanssi. If not, see <http://www.gnu.org/licenses/>

#![cfg_attr(not(feature = "std"), no_std)]

use staging_xcm::latest::prelude::*;
trait Parse {
/// Returns the "chain" location part. It could be parent, sibling
/// parachain, or child parachain.
fn chain_part(&self) -> Option<Location>;
}

impl Parse for Location {
fn chain_part(&self) -> Option<Location> {
match (self.parents, self.first_interior()) {
// sibling parachain
(1, Some(Parachain(id))) => Some(Location::new(1, [Parachain(*id)])),
// parent
(1, _) => Some(Location::parent()),
// children parachain
(0, Some(Parachain(id))) => Some(Location::new(0, [Parachain(*id)])),
_ => None,
}
}
}

pub struct NativeAssetReserve;
impl frame_support::traits::ContainsPair<Asset, Location> for NativeAssetReserve {
fn contains(asset: &Asset, origin: &Location) -> bool {
log::trace!(target: "xcm::contains", "NativeAssetReserve asset: {:?}, origin: {:?}", asset, origin);
let reserve = if asset.id.0.parents == 0
&& !matches!(asset.id.0.first_interior(), Some(Parachain(_)))
{
Some(Location::here())
} else {
asset.id.0.chain_part()
};

if let Some(ref reserve) = reserve {
if reserve == origin {
return true;
}
}
false
}
}
2 changes: 2 additions & 0 deletions runtime/dancebox/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pallet-xcm-core-buyer = { workspace = true }
pallet-xcm-core-buyer-runtime-api = { workspace = true }
tanssi-relay-encoder = { workspace = true }
tanssi-runtime-common = { workspace = true }
tp-xcm-commons = { workspace = true }
tp-xcm-core-buyer = { workspace = true }

# Moonkit
Expand Down Expand Up @@ -271,6 +272,7 @@ std = [
"test-relay-sproof-builder/std",
"tp-author-noting-inherent/std",
"tp-traits/std",
"tp-xcm-commons/std",
"tp-xcm-core-buyer/std",
"westend-runtime-constants/std",
"westend-runtime/std",
Expand Down
13 changes: 5 additions & 8 deletions runtime/dancebox/src/tests/common/xcm/core_buyer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,15 @@
// along with Tanssi. If not, see <http://www.gnu.org/licenses/>

use {
crate::{
assert_expected_events,
tests::common::xcm::{
core_buyer_common::*,
mocknets::{DanceboxRococoPara as Dancebox, RococoRelay as Rococo, RococoRelayPallet},
*,
},
crate::tests::common::xcm::{
core_buyer_common::*,
mocknets::{DanceboxRococoPara as Dancebox, RococoRelay as Rococo, RococoRelayPallet},
*,
},
polkadot_runtime_parachains::on_demand as parachains_assigner_on_demand,
staging_xcm::latest::{MaybeErrorCode, Response},
tp_traits::ParaId,
xcm_emulator::Chain,
xcm_emulator::{assert_expected_events, Chain},
};

const PARATHREAD_ID: u32 = 3333;
Expand Down
3 changes: 1 addition & 2 deletions runtime/dancebox/src/tests/common/xcm/core_buyer_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

use {
crate::{
assert_expected_events,
tests::common::{
empty_genesis_data, run_to_session, set_dummy_boot_node, start_block,
xcm::{
Expand All @@ -42,7 +41,7 @@ use {
staging_xcm::v3::QueryId,
staging_xcm_executor::traits::ConvertLocation,
tp_traits::{ParaId, SlotFrequency},
xcm_emulator::{Chain, RelayChain},
xcm_emulator::{assert_expected_events, Chain, RelayChain},
};

pub const PARATHREAD_ID: u32 = 3333;
Expand Down
19 changes: 8 additions & 11 deletions runtime/dancebox/src/tests/common/xcm/delivery_fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,22 @@
// along with Tanssi. If not, see <http://www.gnu.org/licenses/>

use {
crate::{
assert_expected_events,
tests::common::xcm::{
mocknets::{
DanceboxPara as Dancebox, DanceboxParaPallet, DanceboxSender,
EthereumSender as FrontierTemplateSender, FrontierTemplatePara as FrontierTemplate,
FrontierTemplateParaPallet, SimpleTemplatePara as SimpleTemplate,
SimpleTemplateParaPallet, SimpleTemplateSender,
},
*,
crate::tests::common::xcm::{
mocknets::{
DanceboxPara as Dancebox, DanceboxParaPallet, DanceboxSender,
EthereumSender as FrontierTemplateSender, FrontierTemplatePara as FrontierTemplate,
FrontierTemplateParaPallet, SimpleTemplatePara as SimpleTemplate,
SimpleTemplateParaPallet, SimpleTemplateSender,
},
*,
},
frame_support::{assert_ok, traits::EnsureOrigin},
paste::paste,
staging_xcm::{
latest::prelude::{Junctions::X1, *},
VersionedLocation, VersionedXcm,
},
xcm_emulator::Chain,
xcm_emulator::{assert_expected_events, Chain},
};

#[test]
Expand Down
103 changes: 0 additions & 103 deletions runtime/dancebox/src/tests/common/xcm/expected_event_checker.rs

This file was deleted.

13 changes: 5 additions & 8 deletions runtime/dancebox/src/tests/common/xcm/force_core_buyer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,15 @@
// along with Tanssi. If not, see <http://www.gnu.org/licenses/>

use {
crate::{
assert_expected_events,
tests::common::xcm::{
core_buyer_common::*,
mocknets::{DanceboxRococoPara as Dancebox, RococoRelay as Rococo, RococoRelayPallet},
*,
},
crate::tests::common::xcm::{
core_buyer_common::*,
mocknets::{DanceboxRococoPara as Dancebox, RococoRelay as Rococo, RococoRelayPallet},
*,
},
polkadot_runtime_parachains::on_demand as parachains_assigner_on_demand,
staging_xcm::latest::{MaybeErrorCode, Response},
tp_traits::ParaId,
xcm_emulator::Chain,
xcm_emulator::{assert_expected_events, Chain},
};

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

use {
crate::{
assert_expected_events,
tests::common::xcm::{
mocknets::{
DanceboxEmptyReceiver, DanceboxPara as Dancebox, DanceboxParaPallet,
Expand All @@ -38,7 +37,7 @@ use {
VersionedLocation, VersionedXcm,
},
staging_xcm_executor::traits::ConvertLocation,
xcm_emulator::Chain,
xcm_emulator::{assert_expected_events, Chain},
};

#[test]
Expand Down
18 changes: 7 additions & 11 deletions runtime/dancebox/src/tests/common/xcm/foreign_sovereigns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,13 @@
// along with Tanssi. If not, see <http://www.gnu.org/licenses/>

use {
crate::{
assert_expected_events,
tests::common::xcm::{
mocknets::{
DanceboxPara as Dancebox, DanceboxParaPallet, EthereumEmptyReceiver,
EthereumSender, FrontierTemplatePara as FrontierTemplate,
FrontierTemplateParaPallet, WestendEmptyReceiver, WestendRelay as Westend,
WestendRelayPallet, WestendSender,
},
*,
crate::tests::common::xcm::{
mocknets::{
DanceboxPara as Dancebox, DanceboxParaPallet, EthereumEmptyReceiver, EthereumSender,
FrontierTemplatePara as FrontierTemplate, FrontierTemplateParaPallet,
WestendEmptyReceiver, WestendRelay as Westend, WestendRelayPallet, WestendSender,
},
*,
},
container_chain_template_frontier_runtime::currency::UNIT as FRONTIER_DEV,
frame_support::{
Expand All @@ -38,7 +34,7 @@ use {
},
staging_xcm_executor::traits::ConvertLocation,
westend_runtime_constants::currency::UNITS as WND,
xcm_emulator::Chain,
xcm_emulator::{assert_expected_events, Chain},
};

#[test]
Expand Down
3 changes: 0 additions & 3 deletions runtime/dancebox/src/tests/common/xcm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ mod token_derivative_reception_relay_simple_container;
mod transact;
mod trap;

#[macro_use]
mod expected_event_checker;

pub use {
paste,
xcm_emulator::{bx, Parachain as Para, RelayChain as Relay, TestExt},
Expand Down
Loading

0 comments on commit 55c37fd

Please sign in to comment.