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

XcmExecutorUtils pallet #5

Merged
merged 15 commits into from
Jan 29, 2024
17 changes: 17 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ members = [
"client/orchestrator-chain-interface",
"container-chain-pallets/*",
"container-chain-primitives/*",
"pallets/*",
"primitives/*",
"test-sproof-builder"
]
Expand Down
48 changes: 48 additions & 0 deletions pallets/xcm-executor-utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
[package]
name = "pallet-xcm-executor-utils"
authors = { workspace = true }
description = "XCM Executor configuration utility pallet"
edition = "2021"
license = "GPL-3.0-only"
version = "0.1.0"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
serde = { workspace = true, features = ["derive"] }

frame-benchmarking = { workspace = true, optional = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
parity-scale-codec = { workspace = true, features = [
"derive",
"max-encoded-len",
] }
scale-info = { workspace = true }
sp-core = { workspace = true }
sp-io = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }
staging-xcm = { workspace = true }

[features]
default = ["std"]
std = [
"frame-benchmarking/std",
"frame-support/std",
"frame-system/std",
"parity-scale-codec/std",
"scale-info/std",
"serde/std",
"sp-runtime/std",
"sp-std/std",
"staging-xcm/std",
]
runtime-benchmarks = [
"frame-benchmarking",
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
121 changes: 121 additions & 0 deletions pallets/xcm-executor-utils/src/benchmarks.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// 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(feature = "runtime-benchmarks")]

//! Benchmarking
use {
crate::{Call, Config, DefaultTrustPolicy, MultiLocation, Pallet, TrustPolicy},
frame_benchmarking::{impl_benchmark_test_suite, v2::*},
frame_system::RawOrigin,
sp_std::vec,
staging_xcm::v3::Junctions::Here,
};

#[benchmarks]
mod benchmarks {
use super::*;

#[benchmark]
fn set_reserve_policy() -> Result<(), BenchmarkError> {
#[extrinsic_call]
_(
RawOrigin::Root,
MultiLocation {
parents: 1,
interior: Here,
},
TrustPolicy::DefaultTrustPolicy(DefaultTrustPolicy::Never),
);

// assert!(
Ok(())
}

#[benchmark]
fn remove_reserve_policy() -> Result<(), BenchmarkError> {
let _ = Pallet::<T>::set_reserve_policy(
RawOrigin::Root.into(),
MultiLocation {
parents: 1,
interior: Here,
},
TrustPolicy::DefaultTrustPolicy(DefaultTrustPolicy::Never),
);

#[extrinsic_call]
_(
RawOrigin::Root,
MultiLocation {
parents: 1,
interior: Here,
},
);
assert!(Pallet::<T>::reserve_policy(MultiLocation {
parents: 1,
interior: Here,
})
.is_none());

Ok(())
}

#[benchmark]
fn set_teleport_policy() -> Result<(), BenchmarkError> {
#[extrinsic_call]
_(
RawOrigin::Root,
MultiLocation {
parents: 1,
interior: Here,
},
TrustPolicy::DefaultTrustPolicy(DefaultTrustPolicy::Never),
);

// assert!(
Ok(())
}

#[benchmark]
fn remove_teleport_policy() -> Result<(), BenchmarkError> {
let _ = Pallet::<T>::set_teleport_policy(
RawOrigin::Root.into(),
MultiLocation {
parents: 1,
interior: Here,
},
TrustPolicy::DefaultTrustPolicy(DefaultTrustPolicy::Never),
);

#[extrinsic_call]
_(
RawOrigin::Root,
MultiLocation {
parents: 1,
interior: Here,
},
);
assert!(Pallet::<T>::teleport_policy(MultiLocation {
parents: 1,
interior: Here,
})
.is_none());

Ok(())
}

impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Test);
}
Loading
Loading