-
Notifications
You must be signed in to change notification settings - Fork 646
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
The Ambassador Program #1308
Merged
Merged
The Ambassador Program #1308
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
ce8514f
the ambassador program
muharem cfc9ffb
Merge remote-tracking branch 'origin/master' into muharem-ambassador-…
muharem 28b7fdf
license headers
muharem be08918
propagate feature
muharem ab7af40
format cargo toml files
muharem 53b61d1
fix
muharem 4b371bc
Merge remote-tracking branch 'origin/master' into muharem-ambassador-…
muharem 1ee6f1b
fixes after master merge and integration test for amabssador pay
muharem e073fd3
Apply suggestions from code review
muharem 96a91dd
remove auto clean_announcements
muharem 5d0744b
use counted map
muharem 72ffda2
max announcements
muharem 746cf0f
remove weight from complexity
muharem 2a011a8
Update cumulus/parachains/integration-tests/emulated/collectives/coll…
joepetrowski 43fceb5
Update cumulus/parachains/integration-tests/emulated/collectives/coll…
muharem File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...hains/integration-tests/emulated/collectives/collectives-polkadot/src/tests/ambassador.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright (C) Parity Technologies (UK) Ltd. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
//! Integration tests concerning the Ambassador Program. | ||
|
||
use crate::*; | ||
use collectives_polkadot_runtime::ambassador::AmbassadorSalaryPaymaster; | ||
use frame_support::traits::{fungible::Mutate, tokens::Pay}; | ||
use sp_core::crypto::Ss58Codec; | ||
use xcm_emulator::TestExt; | ||
|
||
#[test] | ||
fn pay_salary() { | ||
let pay_from: AccountId = | ||
<AccountId as Ss58Codec>::from_string("5DS1Gaf6R9eFAV8QyeZP9P89kTkJMurxv3y3J3TTMu8p8VCX") | ||
.unwrap(); | ||
let pay_to = Polkadot::account_id_of(ALICE); | ||
let pay_amount = 90000000000; | ||
|
||
AssetHubPolkadot::execute_with(|| { | ||
type AssetHubBalances = <AssetHubPolkadot as AssetHubPolkadotPallet>::Balances; | ||
|
||
assert_ok!(<AssetHubBalances as Mutate<_>>::mint_into(&pay_from, pay_amount * 2)); | ||
}); | ||
|
||
Collectives::execute_with(|| { | ||
type RuntimeEvent = <Collectives as Chain>::RuntimeEvent; | ||
|
||
assert_ok!(AmbassadorSalaryPaymaster::pay(&pay_to, (), pay_amount)); | ||
assert_expected_events!( | ||
Collectives, | ||
vec![ | ||
RuntimeEvent::XcmpQueue(cumulus_pallet_xcmp_queue::Event::XcmpMessageSent { .. }) => {}, | ||
] | ||
); | ||
}); | ||
|
||
AssetHubPolkadot::execute_with(|| { | ||
type RuntimeEvent = <AssetHubPolkadot as Chain>::RuntimeEvent; | ||
|
||
assert_expected_events!( | ||
AssetHubPolkadot, | ||
vec![ | ||
RuntimeEvent::Balances(pallet_balances::Event::Transfer { from, to, amount }) => { | ||
from: from == &pay_from, | ||
to: to == &pay_to, | ||
amount: amount == &pay_amount, | ||
}, | ||
RuntimeEvent::XcmpQueue(cumulus_pallet_xcmp_queue::Event::Success { .. }) => {}, | ||
] | ||
); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
[package] | ||
name = "pallet-collective-content" | ||
version = "0.1.0" | ||
authors = ["Parity Technologies <admin@parity.io>"] | ||
edition = "2021" | ||
description = "Managed content" | ||
|
||
[dependencies] | ||
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive", "max-encoded-len"] } | ||
scale-info = { version = "2.3.0", default-features = false, features = ["derive"] } | ||
|
||
frame-benchmarking = { path = "../../../../substrate/frame/benchmarking", optional = true, default-features = false } | ||
frame-support = { path = "../../../../substrate/frame/support", default-features = false } | ||
frame-system = { path = "../../../../substrate/frame/system", default-features = false } | ||
|
||
sp-core = { path = "../../../../substrate/primitives/core", default-features = false } | ||
sp-runtime = { path = "../../../../substrate/primitives/runtime", default-features = false } | ||
sp-std = { path = "../../../../substrate/primitives/std", default-features = false } | ||
|
||
[dev-dependencies] | ||
sp-io = { path = "../../../../substrate/primitives/io", default-features = false } | ||
|
||
[features] | ||
default = [ "std" ] | ||
runtime-benchmarks = [ | ||
"frame-benchmarking/runtime-benchmarks", | ||
"frame-support/runtime-benchmarks", | ||
"frame-system/runtime-benchmarks", | ||
"sp-runtime/runtime-benchmarks", | ||
] | ||
|
||
try-runtime = [ | ||
"frame-support/try-runtime", | ||
"frame-system/try-runtime", | ||
"sp-runtime/try-runtime", | ||
] | ||
|
||
std = [ | ||
"codec/std", | ||
"frame-benchmarking/std", | ||
"frame-support/std", | ||
"frame-system/std", | ||
"scale-info/std", | ||
"sp-core/std", | ||
"sp-io/std", | ||
"sp-runtime/std", | ||
"sp-std/std", | ||
] |
88 changes: 88 additions & 0 deletions
88
cumulus/parachains/pallets/collective-content/src/benchmarking.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// Copyright (C) 2023 Parity Technologies (UK) Ltd. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
//! The pallet benchmarks. | ||
|
||
use super::{Pallet as CollectiveContent, *}; | ||
use frame_benchmarking::{impl_benchmark_test_suite, v2::*}; | ||
use frame_support::traits::EnsureOrigin; | ||
|
||
fn assert_last_event<T: Config<I>, I: 'static>(generic_event: <T as Config<I>>::RuntimeEvent) { | ||
frame_system::Pallet::<T>::assert_last_event(generic_event.into()); | ||
} | ||
|
||
/// returns CID hash of 68 bytes of given `i`. | ||
fn create_cid(i: u8) -> OpaqueCid { | ||
let cid: OpaqueCid = [i; 68].to_vec().try_into().unwrap(); | ||
cid | ||
} | ||
|
||
#[instance_benchmarks] | ||
mod benchmarks { | ||
use super::*; | ||
|
||
#[benchmark] | ||
fn set_charter() -> Result<(), BenchmarkError> { | ||
let cid: OpaqueCid = create_cid(1); | ||
let origin = | ||
T::CharterOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; | ||
|
||
#[extrinsic_call] | ||
_(origin as T::RuntimeOrigin, cid.clone()); | ||
|
||
assert_eq!(Charter::<T, I>::get(), Some(cid.clone())); | ||
assert_last_event::<T, I>(Event::NewCharterSet { cid }.into()); | ||
Ok(()) | ||
} | ||
|
||
#[benchmark] | ||
fn announce() -> Result<(), BenchmarkError> { | ||
let expire_at = DispatchTime::<_>::At(10u32.into()); | ||
let now = frame_system::Pallet::<T>::block_number(); | ||
let cid: OpaqueCid = create_cid(1); | ||
let origin = T::AnnouncementOrigin::try_successful_origin() | ||
.map_err(|_| BenchmarkError::Weightless)?; | ||
|
||
#[extrinsic_call] | ||
_(origin as T::RuntimeOrigin, cid.clone(), Some(expire_at.clone())); | ||
|
||
assert_eq!(<Announcements<T, I>>::count(), 1); | ||
assert_last_event::<T, I>( | ||
Event::AnnouncementAnnounced { cid, expire_at: expire_at.evaluate(now) }.into(), | ||
); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[benchmark] | ||
fn remove_announcement() -> Result<(), BenchmarkError> { | ||
let cid: OpaqueCid = create_cid(1); | ||
let origin = T::AnnouncementOrigin::try_successful_origin() | ||
.map_err(|_| BenchmarkError::Weightless)?; | ||
CollectiveContent::<T, I>::announce(origin.clone(), cid.clone(), None) | ||
.expect("could not publish an announcement"); | ||
assert_eq!(<Announcements<T, I>>::count(), 1); | ||
|
||
#[extrinsic_call] | ||
_(origin as T::RuntimeOrigin, cid.clone()); | ||
|
||
assert_eq!(<Announcements<T, I>>::count(), 0); | ||
assert_last_event::<T, I>(Event::AnnouncementRemoved { cid }.into()); | ||
|
||
Ok(()) | ||
} | ||
|
||
impl_benchmark_test_suite!(CollectiveContent, super::mock::new_bench_ext(), super::mock::Test); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is experimental and may undergo numerous changes based on the needs of collectives. this is why it was decided not to integrate it into the frame for now.