Skip to content

Commit 83a01e9

Browse files
gavofyorkshawntabrizikianenigma
authored
Generalised proxies (#6156)
* Initial work * It should work * Fix node * Fix tests * Initial test * Tests * Expunge proxy functionality from democracy and elections * Allow different proxy types * Repotted * Build * Build * Making a start on weights * Undo breaking change * Line widths. * Fix * fix tests * finish benchmarks? * Storage name! * Utility -> Proxy * proxy weight * add proxy weight * remove weights * Update transfer constraint * Again, fix constraints * Fix negation * Update frame/proxy/Cargo.toml Co-authored-by: Kian Paimani <[email protected]> * Remove unneeded event. * Grumbles * Apply suggestions from code review Co-authored-by: Kian Paimani <[email protected]> Co-authored-by: Shawn Tabrizi <[email protected]> Co-authored-by: Kian Paimani <[email protected]>
0 parents  commit 83a01e9

File tree

4 files changed

+622
-0
lines changed

4 files changed

+622
-0
lines changed

Cargo.toml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
[package]
2+
name = "pallet-proxy"
3+
version = "2.0.0-rc2"
4+
authors = ["Parity Technologies <[email protected]>"]
5+
edition = "2018"
6+
license = "Apache-2.0"
7+
homepage = "https://substrate.dev"
8+
repository = "https://github.com/paritytech/substrate/"
9+
description = "FRAME proxying pallet"
10+
11+
[package.metadata.docs.rs]
12+
targets = ["x86_64-unknown-linux-gnu"]
13+
14+
[dependencies]
15+
serde = { version = "1.0.101", optional = true }
16+
codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false }
17+
frame-support = { version = "2.0.0-rc2", default-features = false, path = "../support" }
18+
frame-system = { version = "2.0.0-rc2", default-features = false, path = "../system" }
19+
sp-core = { version = "2.0.0-rc2", default-features = false, path = "../../primitives/core" }
20+
sp-runtime = { version = "2.0.0-rc2", default-features = false, path = "../../primitives/runtime" }
21+
sp-std = { version = "2.0.0-rc2", default-features = false, path = "../../primitives/std" }
22+
23+
frame-benchmarking = { version = "2.0.0-rc2", default-features = false, path = "../benchmarking", optional = true }
24+
25+
[dev-dependencies]
26+
sp-core = { version = "2.0.0-rc2", path = "../../primitives/core" }
27+
pallet-balances = { version = "2.0.0-rc2", path = "../balances" }
28+
sp-io = { version = "2.0.0-rc2", path = "../../primitives/io" }
29+
30+
[features]
31+
default = ["std"]
32+
std = [
33+
"serde",
34+
"codec/std",
35+
"sp-runtime/std",
36+
"frame-support/std",
37+
"frame-system/std",
38+
"sp-std/std"
39+
]
40+
runtime-benchmarks = [
41+
"frame-benchmarking",
42+
"frame-support/runtime-benchmarks",
43+
]

src/benchmarking.rs

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// This file is part of Substrate.
2+
3+
// Copyright (C) 2019-2020 Parity Technologies (UK) Ltd.
4+
// SPDX-License-Identifier: Apache-2.0
5+
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
18+
// Benchmarks for Proxy Pallet
19+
20+
#![cfg(feature = "runtime-benchmarks")]
21+
22+
use super::*;
23+
use frame_system::RawOrigin;
24+
use frame_benchmarking::{benchmarks, account};
25+
use sp_runtime::traits::Bounded;
26+
use crate::Module as Proxy;
27+
28+
const SEED: u32 = 0;
29+
30+
fn add_proxies<T: Trait>(n: u32) -> Result<(), &'static str> {
31+
let caller: T::AccountId = account("caller", 0, SEED);
32+
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
33+
for i in 0..n {
34+
Proxy::<T>::add_proxy(
35+
RawOrigin::Signed(caller.clone()).into(),
36+
account("target", i, SEED),
37+
T::ProxyType::default()
38+
)?;
39+
}
40+
Ok(())
41+
}
42+
43+
benchmarks! {
44+
_ {
45+
let p in 1 .. (T::MaxProxies::get() - 1).into() => add_proxies::<T>(p)?;
46+
}
47+
48+
proxy {
49+
let p in ...;
50+
// In this case the caller is the "target" proxy
51+
let caller: T::AccountId = account("target", p - 1, SEED);
52+
// ... and "real" is the traditional caller. This is not a typo.
53+
let real: T::AccountId = account("caller", 0, SEED);
54+
let call: <T as Trait>::Call = frame_system::Call::<T>::remark(vec![]).into();
55+
}: _(RawOrigin::Signed(caller), real, Some(T::ProxyType::default()), Box::new(call))
56+
57+
add_proxy {
58+
let p in ...;
59+
let caller: T::AccountId = account("caller", 0, SEED);
60+
}: _(RawOrigin::Signed(caller), account("target", T::MaxProxies::get().into(), SEED), T::ProxyType::default())
61+
62+
remove_proxy {
63+
let p in ...;
64+
let caller: T::AccountId = account("caller", 0, SEED);
65+
}: _(RawOrigin::Signed(caller), account("target", 0, SEED), T::ProxyType::default())
66+
67+
remove_proxies {
68+
let p in ...;
69+
let caller: T::AccountId = account("caller", 0, SEED);
70+
}: _(RawOrigin::Signed(caller))
71+
}
72+
73+
#[cfg(test)]
74+
mod tests {
75+
use super::*;
76+
use crate::tests::{new_test_ext, Test};
77+
use frame_support::assert_ok;
78+
79+
#[test]
80+
fn test_benchmarks() {
81+
new_test_ext().execute_with(|| {
82+
assert_ok!(test_benchmark_proxy::<Test>());
83+
assert_ok!(test_benchmark_add_proxy::<Test>());
84+
assert_ok!(test_benchmark_remove_proxy::<Test>());
85+
assert_ok!(test_benchmark_remove_proxies::<Test>());
86+
});
87+
}
88+
}

0 commit comments

Comments
 (0)