|
@@ -53,7 +53,7 @@ const MAX_POSTS: u32 = 500;
|
|
|
const MAX_THREADS: u32 = 500;
|
|
|
|
|
|
fn get_byte(num: u32, byte_number: u8) -> u8 {
|
|
|
- ((num & (0xff << (8 * byte_number))) >> 8 * byte_number) as u8
|
|
|
+ ((num & (0xff << (8 * byte_number))) >> (8 * byte_number)) as u8
|
|
|
}
|
|
|
|
|
|
fn assert_last_event<T: Trait>(generic_event: <T as Trait>::Event) {
|
|
@@ -90,12 +90,12 @@ where
|
|
|
let member_id = T::MemberId::from(id.try_into().unwrap());
|
|
|
Membership::<T>::add_staking_account_candidate(
|
|
|
RawOrigin::Signed(account_id.clone()).into(),
|
|
|
- member_id.clone(),
|
|
|
+ member_id,
|
|
|
)
|
|
|
.unwrap();
|
|
|
Membership::<T>::confirm_staking_account(
|
|
|
RawOrigin::Signed(account_id.clone()).into(),
|
|
|
- member_id.clone(),
|
|
|
+ member_id,
|
|
|
account_id.clone(),
|
|
|
)
|
|
|
.unwrap();
|
|
@@ -178,12 +178,8 @@ where
|
|
|
|
|
|
let mut successful_application_ids = BTreeSet::<ApplicationId>::new();
|
|
|
successful_application_ids.insert(application_id);
|
|
|
- ForumGroup::<T>::fill_opening(
|
|
|
- leader_origin.clone().into(),
|
|
|
- opening_id,
|
|
|
- successful_application_ids,
|
|
|
- )
|
|
|
- .unwrap();
|
|
|
+ ForumGroup::<T>::fill_opening(leader_origin.into(), opening_id, successful_application_ids)
|
|
|
+ .unwrap();
|
|
|
|
|
|
let actor_id =
|
|
|
<T as common::membership::MembershipTypes>::ActorId::from(id.try_into().unwrap());
|
|
@@ -294,7 +290,7 @@ fn create_new_thread<T: Trait>(
|
|
|
category_id: T::CategoryId,
|
|
|
title: Vec<u8>,
|
|
|
text: Vec<u8>,
|
|
|
- poll: Option<Poll<T::Moment, T::Hash>>,
|
|
|
+ poll: Option<PollInput<T::Moment>>,
|
|
|
) -> T::ThreadId {
|
|
|
Module::<T>::create_thread(
|
|
|
RawOrigin::Signed(account_id).into(),
|
|
@@ -327,30 +323,26 @@ fn add_thread_post<T: Trait>(
|
|
|
Module::<T>::next_post_id() - T::PostId::one()
|
|
|
}
|
|
|
|
|
|
-pub fn good_poll_alternative_text() -> Vec<u8> {
|
|
|
+fn good_poll_alternative_text() -> Vec<u8> {
|
|
|
b"poll alternative".to_vec()
|
|
|
}
|
|
|
|
|
|
-pub fn good_poll_description() -> Vec<u8> {
|
|
|
+fn good_poll_description() -> Vec<u8> {
|
|
|
b"poll description".to_vec()
|
|
|
}
|
|
|
|
|
|
-pub fn generate_poll<T: Trait>(
|
|
|
+/// Generates poll input
|
|
|
+pub fn generate_poll_input<T: Trait>(
|
|
|
expiration_diff: T::Moment,
|
|
|
alternatives_number: u32,
|
|
|
-) -> Poll<T::Moment, T::Hash> {
|
|
|
- Poll {
|
|
|
- description_hash: T::calculate_hash(good_poll_description().as_slice()),
|
|
|
+) -> PollInput<T::Moment> {
|
|
|
+ PollInput {
|
|
|
+ description: good_poll_description(),
|
|
|
end_time: pallet_timestamp::Module::<T>::now() + expiration_diff,
|
|
|
poll_alternatives: {
|
|
|
let mut alternatives = vec![];
|
|
|
for _ in 0..alternatives_number {
|
|
|
- alternatives.push(PollAlternative {
|
|
|
- alternative_text_hash: T::calculate_hash(
|
|
|
- good_poll_alternative_text().as_slice(),
|
|
|
- ),
|
|
|
- vote_count: 0,
|
|
|
- });
|
|
|
+ alternatives.push(good_poll_alternative_text());
|
|
|
}
|
|
|
alternatives
|
|
|
},
|
|
@@ -382,19 +374,16 @@ pub fn generate_categories_tree<T: Trait>(
|
|
|
text.clone(),
|
|
|
);
|
|
|
|
|
|
- match moderator_id {
|
|
|
- Some(moderator_id) => {
|
|
|
- // Set up category membership of moderator.
|
|
|
- Module::<T>::update_category_membership_of_moderator(
|
|
|
- RawOrigin::Signed(caller_id.clone()).into(),
|
|
|
- moderator_id,
|
|
|
- category_id,
|
|
|
- true,
|
|
|
- )
|
|
|
- .unwrap();
|
|
|
- }
|
|
|
- _ => (),
|
|
|
- };
|
|
|
+ if let Some(moderator_id) = moderator_id {
|
|
|
+ // Set up category membership of moderator.
|
|
|
+ Module::<T>::update_category_membership_of_moderator(
|
|
|
+ RawOrigin::Signed(caller_id.clone()).into(),
|
|
|
+ moderator_id,
|
|
|
+ category_id,
|
|
|
+ true,
|
|
|
+ )
|
|
|
+ .unwrap();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
assert_eq!(
|
|
@@ -434,11 +423,7 @@ benchmarks! {
|
|
|
// Generate categories tree
|
|
|
let (_, parent_category_id) = generate_categories_tree::<T>(caller_id.clone(), i, None);
|
|
|
|
|
|
- let parent_category = if let Some(parent_category_id) = parent_category_id {
|
|
|
- Some(Module::<T>::category_by_id(parent_category_id))
|
|
|
- } else {
|
|
|
- None
|
|
|
- };
|
|
|
+ let parent_category = parent_category_id.map(Module::<T>::category_by_id);
|
|
|
|
|
|
let category_counter = <Module<T>>::category_counter();
|
|
|
|
|
@@ -941,18 +926,18 @@ benchmarks! {
|
|
|
|
|
|
let expiration_diff = 1010u32.into();
|
|
|
|
|
|
- let poll = if z == 1 {
|
|
|
+ let poll_input = if z == 1 {
|
|
|
None
|
|
|
} else {
|
|
|
// min number of poll alternatives is set to 2
|
|
|
- Some(generate_poll::<T>(expiration_diff, z))
|
|
|
+ Some(generate_poll_input::<T>(expiration_diff, z))
|
|
|
};
|
|
|
|
|
|
let next_thread_id = Module::<T>::next_thread_id();
|
|
|
let next_post_id = Module::<T>::next_post_id();
|
|
|
let initial_balance = Balances::<T>::usable_balance(&caller_id);
|
|
|
|
|
|
- }: _ (RawOrigin::Signed(caller_id.clone()), forum_user_id.saturated_into(), category_id, title.clone(), text.clone(), poll.clone())
|
|
|
+ }: _ (RawOrigin::Signed(caller_id.clone()), forum_user_id.saturated_into(), category_id, title.clone(), text.clone(), poll_input.clone())
|
|
|
verify {
|
|
|
|
|
|
assert_eq!(
|
|
@@ -978,7 +963,7 @@ benchmarks! {
|
|
|
category_id,
|
|
|
title_hash: T::calculate_hash(&title),
|
|
|
author_id: forum_user_id.saturated_into(),
|
|
|
- poll: poll.clone(),
|
|
|
+ poll: poll_input.clone().map(<Module<T>>::from_poll_input),
|
|
|
cleanup_pay_off: T::ThreadDeposit::get(),
|
|
|
number_of_posts: 1,
|
|
|
};
|
|
@@ -996,12 +981,13 @@ benchmarks! {
|
|
|
|
|
|
assert_last_event::<T>(
|
|
|
RawEvent::ThreadCreated(
|
|
|
+ category_id,
|
|
|
next_thread_id,
|
|
|
+ next_post_id,
|
|
|
forum_user_id.saturated_into(),
|
|
|
- category_id,
|
|
|
title,
|
|
|
text,
|
|
|
- poll,
|
|
|
+ poll_input,
|
|
|
).into()
|
|
|
);
|
|
|
}
|
|
@@ -1057,13 +1043,13 @@ benchmarks! {
|
|
|
// Create thread
|
|
|
let expiration_diff = 10u32.into();
|
|
|
let poll = Some(
|
|
|
- generate_poll::<T>(expiration_diff, (<<<T as Trait>::MapLimits as StorageLimits>::MaxPollAlternativesNumber>::get() - 1) as u32)
|
|
|
+ generate_poll_input::<T>(expiration_diff, (<<<T as Trait>::MapLimits as StorageLimits>::MaxPollAlternativesNumber>::get() - 1) as u32)
|
|
|
);
|
|
|
let text = vec![1u8].repeat(MAX_BYTES as usize);
|
|
|
|
|
|
let thread_id = create_new_thread::<T>(
|
|
|
caller_id.clone(), forum_user_id.saturated_into(), category_id,
|
|
|
- text.clone(), text.clone(), poll
|
|
|
+ text.clone(), text, poll
|
|
|
);
|
|
|
|
|
|
// Add poll voting.
|
|
@@ -1152,7 +1138,7 @@ benchmarks! {
|
|
|
};
|
|
|
|
|
|
// Create thread
|
|
|
- let thread_id = create_new_thread::<T>(caller_id.clone(), forum_user_id.saturated_into(), category_id, text.clone(), text.clone(), None);
|
|
|
+ let thread_id = create_new_thread::<T>(caller_id.clone(), forum_user_id.saturated_into(), category_id, text.clone(), text, None);
|
|
|
let thread = Module::<T>::thread_by_id(category_id, thread_id);
|
|
|
|
|
|
let mut category = Module::<T>::category_by_id(category_id);
|
|
@@ -1214,7 +1200,7 @@ benchmarks! {
|
|
|
};
|
|
|
|
|
|
// Create thread
|
|
|
- let thread_id = create_new_thread::<T>(caller_id.clone(), forum_user_id.saturated_into(), category_id, text.clone(), text.clone(), None);
|
|
|
+ let thread_id = create_new_thread::<T>(caller_id.clone(), forum_user_id.saturated_into(), category_id, text.clone(), text, None);
|
|
|
let thread = Module::<T>::thread_by_id(category_id, thread_id);
|
|
|
|
|
|
let moderator_id = ModeratorId::<T>::from(forum_user_id.try_into().unwrap());
|
|
@@ -1269,12 +1255,12 @@ benchmarks! {
|
|
|
|
|
|
// Create thread
|
|
|
let expiration_diff = 10u32.into();
|
|
|
- let poll = Some(generate_poll::<T>(expiration_diff, j));
|
|
|
+ let poll_input = Some(generate_poll_input::<T>(expiration_diff, j));
|
|
|
let text = vec![1u8].repeat(MAX_BYTES as usize);
|
|
|
|
|
|
let thread_id = create_new_thread::<T>(
|
|
|
caller_id.clone(), forum_user_id.saturated_into(), category_id,
|
|
|
- text.clone(), text.clone(), poll
|
|
|
+ text.clone(), text, poll_input
|
|
|
);
|
|
|
|
|
|
let mut thread = Module::<T>::thread_by_id(category_id, thread_id);
|
|
@@ -1327,13 +1313,13 @@ benchmarks! {
|
|
|
// Create thread
|
|
|
let expiration_diff = 10u32.into();
|
|
|
let poll = Some(
|
|
|
- generate_poll::<T>(expiration_diff, (<<<T as Trait>::MapLimits as StorageLimits>::MaxPollAlternativesNumber>::get() - 1) as u32)
|
|
|
+ generate_poll_input::<T>(expiration_diff, (<<<T as Trait>::MapLimits as StorageLimits>::MaxPollAlternativesNumber>::get() - 1) as u32)
|
|
|
);
|
|
|
|
|
|
let text = vec![1u8].repeat(MAX_BYTES as usize);
|
|
|
let thread_id = create_new_thread::<T>(
|
|
|
caller_id.clone(), (lead_id as u64).saturated_into(), category_id,
|
|
|
- text.clone(), text.clone(), poll
|
|
|
+ text.clone(), text, poll
|
|
|
);
|
|
|
|
|
|
let mut category = Module::<T>::category_by_id(category_id);
|
|
@@ -1383,13 +1369,13 @@ benchmarks! {
|
|
|
// Create thread
|
|
|
let expiration_diff = 10u32.into();
|
|
|
let poll = Some(
|
|
|
- generate_poll::<T>(expiration_diff, (<<<T as Trait>::MapLimits as StorageLimits>::MaxPollAlternativesNumber>::get() - 1) as u32)
|
|
|
+ generate_poll_input::<T>(expiration_diff, (<<<T as Trait>::MapLimits as StorageLimits>::MaxPollAlternativesNumber>::get() - 1) as u32)
|
|
|
);
|
|
|
|
|
|
let text = vec![1u8].repeat(MAX_BYTES as usize);
|
|
|
let thread_id = create_new_thread::<T>(
|
|
|
caller_id.clone(), (lead_id as u64).saturated_into(), category_id,
|
|
|
- text.clone(), text.clone(), poll
|
|
|
+ text.clone(), text, poll
|
|
|
);
|
|
|
|
|
|
let moderator_id = ModeratorId::<T>::from(lead_id.try_into().unwrap());
|
|
@@ -1466,7 +1452,7 @@ benchmarks! {
|
|
|
let new_post = Post {
|
|
|
text_hash: T::calculate_hash(&text),
|
|
|
author_id: forum_user_id.saturated_into(),
|
|
|
- thread_id: thread_id,
|
|
|
+ thread_id,
|
|
|
last_edited: System::<T>::block_number(),
|
|
|
cleanup_pay_off: T::PostDeposit::get(),
|
|
|
};
|
|
@@ -1501,7 +1487,7 @@ benchmarks! {
|
|
|
// Create thread
|
|
|
let expiration_diff = 10u32.into();
|
|
|
let poll = Some(
|
|
|
- generate_poll::<T>(expiration_diff, (<<<T as Trait>::MapLimits as StorageLimits>::MaxPollAlternativesNumber>::get() - 1) as u32)
|
|
|
+ generate_poll_input::<T>(expiration_diff, (<<<T as Trait>::MapLimits as StorageLimits>::MaxPollAlternativesNumber>::get() - 1) as u32)
|
|
|
);
|
|
|
let text = vec![1u8].repeat(MAX_BYTES as usize);
|
|
|
|
|
@@ -1510,7 +1496,7 @@ benchmarks! {
|
|
|
text.clone(), text.clone(), poll
|
|
|
);
|
|
|
|
|
|
- let post_id = add_thread_post::<T>(caller_id.clone(), forum_user_id.saturated_into(), category_id, thread_id, text.clone());
|
|
|
+ let post_id = add_thread_post::<T>(caller_id.clone(), forum_user_id.saturated_into(), category_id, thread_id, text);
|
|
|
|
|
|
let react = T::PostReactionId::one();
|
|
|
|
|
@@ -1542,7 +1528,7 @@ benchmarks! {
|
|
|
// Create thread
|
|
|
let expiration_diff = 10u32.into();
|
|
|
let poll = Some(
|
|
|
- generate_poll::<T>(expiration_diff, (<<<T as Trait>::MapLimits as StorageLimits>::MaxPollAlternativesNumber>::get() - 1) as u32)
|
|
|
+ generate_poll_input::<T>(expiration_diff, (<<<T as Trait>::MapLimits as StorageLimits>::MaxPollAlternativesNumber>::get() - 1) as u32)
|
|
|
);
|
|
|
let text = vec![1u8].repeat(MAX_BYTES as usize);
|
|
|
|
|
@@ -1551,7 +1537,7 @@ benchmarks! {
|
|
|
text.clone(), text.clone(), poll
|
|
|
);
|
|
|
|
|
|
- let post_id = add_thread_post::<T>(caller_id.clone(), forum_user_id.saturated_into(), category_id, thread_id, text.clone());
|
|
|
+ let post_id = add_thread_post::<T>(caller_id.clone(), forum_user_id.saturated_into(), category_id, thread_id, text);
|
|
|
|
|
|
let mut post = Module::<T>::post_by_id(thread_id, post_id);
|
|
|
|
|
@@ -1596,7 +1582,7 @@ benchmarks! {
|
|
|
// Create thread
|
|
|
let expiration_diff = 10u32.into();
|
|
|
let poll = Some(
|
|
|
- generate_poll::<T>(expiration_diff, (<<<T as Trait>::MapLimits as StorageLimits>::MaxPollAlternativesNumber>::get() - 1) as u32)
|
|
|
+ generate_poll_input::<T>(expiration_diff, (<<<T as Trait>::MapLimits as StorageLimits>::MaxPollAlternativesNumber>::get() - 1) as u32)
|
|
|
);
|
|
|
let text = vec![1u8].repeat(MAX_BYTES as usize);
|
|
|
|
|
@@ -1604,7 +1590,7 @@ benchmarks! {
|
|
|
caller_id.clone(), forum_user_id.saturated_into(), category_id,
|
|
|
text.clone(), text.clone(), poll
|
|
|
);
|
|
|
- let post_id = add_thread_post::<T>(caller_id.clone(), forum_user_id.saturated_into(), category_id, thread_id, text.clone());
|
|
|
+ let post_id = add_thread_post::<T>(caller_id.clone(), forum_user_id.saturated_into(), category_id, thread_id, text);
|
|
|
|
|
|
let mut thread = Module::<T>::thread_by_id(category_id, thread_id);
|
|
|
|
|
@@ -1643,7 +1629,7 @@ benchmarks! {
|
|
|
// Create thread
|
|
|
let expiration_diff = 10u32.into();
|
|
|
let poll = Some(
|
|
|
- generate_poll::<T>(expiration_diff, (<<<T as Trait>::MapLimits as StorageLimits>::MaxPollAlternativesNumber>::get() - 1) as u32)
|
|
|
+ generate_poll_input::<T>(expiration_diff, (<<<T as Trait>::MapLimits as StorageLimits>::MaxPollAlternativesNumber>::get() - 1) as u32)
|
|
|
);
|
|
|
let text = vec![1u8].repeat(MAX_BYTES as usize);
|
|
|
|
|
@@ -1651,7 +1637,7 @@ benchmarks! {
|
|
|
caller_id.clone(), forum_user_id.saturated_into(), category_id,
|
|
|
text.clone(), text.clone(), poll
|
|
|
);
|
|
|
- let post_id = add_thread_post::<T>(caller_id.clone(), forum_user_id.saturated_into(), category_id, thread_id, text.clone());
|
|
|
+ let post_id = add_thread_post::<T>(caller_id.clone(), forum_user_id.saturated_into(), category_id, thread_id, text);
|
|
|
|
|
|
let mut thread = Module::<T>::thread_by_id(category_id, thread_id);
|
|
|
|
|
@@ -1699,7 +1685,7 @@ benchmarks! {
|
|
|
// Create thread
|
|
|
let expiration_diff = 10u32.into();
|
|
|
let poll = Some(
|
|
|
- generate_poll::<T>(expiration_diff, (<<<T as Trait>::MapLimits as StorageLimits>::MaxPollAlternativesNumber>::get() - 1) as u32)
|
|
|
+ generate_poll_input::<T>(expiration_diff, (<<<T as Trait>::MapLimits as StorageLimits>::MaxPollAlternativesNumber>::get() - 1) as u32)
|
|
|
);
|
|
|
let text = vec![1u8].repeat(MAX_BYTES as usize);
|
|
|
|
|
@@ -1726,7 +1712,7 @@ benchmarks! {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- let post_id = add_thread_post::<T>(caller_id.clone(), forum_user_id.saturated_into(), category_id, thread_id, text.clone());
|
|
|
+ let post_id = add_thread_post::<T>(caller_id.clone(), forum_user_id.saturated_into(), category_id, thread_id, text);
|
|
|
|
|
|
let mut thread = Module::<T>::thread_by_id(category_id, thread_id);
|
|
|
|
|
@@ -1777,7 +1763,7 @@ benchmarks! {
|
|
|
// Create threads
|
|
|
let expiration_diff = 1010u32.into();
|
|
|
let poll = Some(
|
|
|
- generate_poll::<T>(expiration_diff, (<<<T as Trait>::MapLimits as StorageLimits>::MaxPollAlternativesNumber>::get() - 1) as u32)
|
|
|
+ generate_poll_input::<T>(expiration_diff, (<<<T as Trait>::MapLimits as StorageLimits>::MaxPollAlternativesNumber>::get() - 1) as u32)
|
|
|
);
|
|
|
let text = vec![1u8].repeat(MAX_BYTES as usize);
|
|
|
|
|
@@ -1820,7 +1806,7 @@ benchmarks! {
|
|
|
// Create threads
|
|
|
let expiration_diff = 1010u32.into();
|
|
|
let poll = Some(
|
|
|
- generate_poll::<T>(expiration_diff, (<<<T as Trait>::MapLimits as StorageLimits>::MaxPollAlternativesNumber>::get() - 1) as u32)
|
|
|
+ generate_poll_input::<T>(expiration_diff, (<<<T as Trait>::MapLimits as StorageLimits>::MaxPollAlternativesNumber>::get() - 1) as u32)
|
|
|
);
|
|
|
let text = vec![1u8].repeat(MAX_BYTES as usize);
|
|
|
|