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

[WIP] Frame v2 upgrade part4 #1774

Open
wants to merge 4 commits into
base: frame_v2_upgrade_part3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions pallets/corporate-actions/src/ballot/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use super::*;
use crate::benchmarking::{set_ca_targets, setup_ca};
use crate::CAConfig;
use core::iter;
use frame_benchmarking::benchmarks;
use pallet_identity::benchmarking::User;
Expand All @@ -40,22 +41,24 @@ fn meta(n_motions: u32, n_choices: u32) -> BallotMeta {
}
}

fn attach<T: Config>(n_motions: u32, n_choices: u32) -> (User<T>, CAId) {
fn attach<T: CAConfig>(n_motions: u32, n_choices: u32) -> (User<T>, CAId) {
let meta = meta(n_motions, n_choices);
let (owner, ca_id) = setup_ca::<T>(CAKind::IssuerNotice);
<Pallet<T>>::attach_ballot(owner.origin().into(), ca_id, RANGE, meta, true).unwrap();
(owner, ca_id)
}

benchmarks! {
where_clause { where T: CAConfig }

attach_ballot {
let c in 0..MAX_CHOICES;

let meta = meta(1, c);
let (owner, ca_id) = setup_ca::<T>(CAKind::IssuerNotice);
}: _(owner.origin(), ca_id, RANGE, meta, true)
verify {
assert_eq!(TimeRanges::get(ca_id), Some(RANGE), "ballot not created");
assert_eq!(TimeRanges::<T>::get(ca_id), Some(RANGE), "ballot not created");
}

vote {
Expand All @@ -82,14 +85,14 @@ benchmarks! {
let results = votes.iter().map(|v| v.power).collect::<Vec<_>>();
}: _(owner.origin(), ca_id, votes)
verify {
assert_eq!(Results::get(ca_id), results, "voting results are wrong")
assert_eq!(Results::<T>::get(ca_id), results, "voting results are wrong")
}

change_end {
let (owner, ca_id) = attach::<T>(0, 0);
}: _(owner.origin(), ca_id, 5000)
verify {
assert_eq!(TimeRanges::get(ca_id).unwrap().end, 5000, "range not changed");
assert_eq!(TimeRanges::<T>::get(ca_id).unwrap().end, 5000, "range not changed");
}

change_meta {
Expand All @@ -100,20 +103,20 @@ benchmarks! {
let meta2 = meta.clone();
}: _(owner.origin(), ca_id, meta)
verify {
assert_eq!(Metas::get(ca_id).unwrap(), meta2, "meta not changed");
assert_eq!(Metas::<T>::get(ca_id).unwrap(), meta2, "meta not changed");
}

change_rcv {
let (owner, ca_id) = attach::<T>(0, 0);
}: _(owner.origin(), ca_id, false)
verify {
assert!(!RCV::get(ca_id), "RCV not changed");
assert!(!RCV::<T>::get(ca_id), "RCV not changed");
}

remove_ballot {
let (owner, ca_id) = attach::<T>(0, 0);
}: _(owner.origin(), ca_id)
verify {
assert_eq!(TimeRanges::get(ca_id), None, "ballot not removed");
assert_eq!(TimeRanges::<T>::get(ca_id), None, "ballot not removed");
}
}
Loading