|
@@ -95,7 +95,10 @@ fn generate_post<T: Trait<I>, I: Instance>() -> PostId {
|
|
|
|
|
|
assert_eq!(Blog::<T, I>::post_count(), 1);
|
|
|
|
|
|
- assert!(Blog::<T, I>::post_by_id(post_id) == Post::<T, I>::new(&vec![0u8], &vec![0u8]));
|
|
|
+ assert_eq!(
|
|
|
+ Blog::<T, I>::post_by_id(post_id),
|
|
|
+ Post::<T, I>::new(&vec![0u8], &vec![0u8])
|
|
|
+ );
|
|
|
|
|
|
post_id
|
|
|
}
|
|
@@ -115,9 +118,9 @@ fn generate_reply<T: Trait<I>, I: Instance>(
|
|
|
)
|
|
|
.unwrap();
|
|
|
|
|
|
- assert!(
|
|
|
- Blog::<T, I>::reply_by_id(post_id, T::ReplyId::zero())
|
|
|
- == Reply::<T, I>::new(vec![0u8], participant_id, ParentId::Post(post_id))
|
|
|
+ assert_eq!(
|
|
|
+ Blog::<T, I>::reply_by_id(post_id, T::ReplyId::zero()),
|
|
|
+ Reply::<T, I>::new(vec![0u8], participant_id, ParentId::Post(post_id))
|
|
|
);
|
|
|
|
|
|
T::ReplyId::zero()
|
|
@@ -134,13 +137,14 @@ benchmarks_instance! {
|
|
|
assert_eq!(Blog::<T, I>::post_count(), 0);
|
|
|
let title = vec![0u8; t.try_into().unwrap()];
|
|
|
let body = vec![0u8; b.try_into().unwrap()];
|
|
|
+ let post_id = Blog::<T, I>::post_count();
|
|
|
|
|
|
}:_(RawOrigin::Root, title.clone(), body.clone())
|
|
|
verify {
|
|
|
- assert_eq!(Blog::<T, I>::post_count(), 1);
|
|
|
+ assert_eq!(Blog::<T, I>::post_count(), post_id + 1);
|
|
|
|
|
|
- assert!(
|
|
|
- Blog::<T, I>::post_by_id(0) ==
|
|
|
+ assert_eq!(
|
|
|
+ Blog::<T, I>::post_by_id(post_id),
|
|
|
Post::<T, I>::new(&title, &body)
|
|
|
);
|
|
|
|
|
@@ -176,15 +180,10 @@ benchmarks_instance! {
|
|
|
let post_id = generate_post::<T, I>();
|
|
|
let title = Some(vec![1u8; t.try_into().unwrap()]);
|
|
|
let body = Some(vec![1u8; b.try_into().unwrap()]);
|
|
|
- }: _(
|
|
|
- RawOrigin::Root,
|
|
|
- post_id,
|
|
|
- title.clone(),
|
|
|
- body.clone()
|
|
|
- )
|
|
|
+ }: _(RawOrigin::Root, post_id, title.clone(), body.clone())
|
|
|
verify {
|
|
|
- assert!(
|
|
|
- Blog::<T, I>::post_by_id(post_id) ==
|
|
|
+ assert_eq!(
|
|
|
+ Blog::<T, I>::post_by_id(post_id),
|
|
|
Post::<T, I>::new(&vec![1u8; t.try_into().unwrap()], &vec![1u8; b.try_into().unwrap()])
|
|
|
);
|
|
|
assert_last_event::<T, I>(RawEvent::PostEdited(post_id, title, body).into());
|
|
@@ -197,19 +196,13 @@ benchmarks_instance! {
|
|
|
let (account_id, participant_id) = member_funded_account::<T, I>("caller", 0);
|
|
|
let origin = RawOrigin::Signed(account_id);
|
|
|
let text = vec![0u8; t.try_into().unwrap()];
|
|
|
- }: create_reply(
|
|
|
- origin.clone(),
|
|
|
- participant_id,
|
|
|
- post_id,
|
|
|
- None,
|
|
|
- text.clone()
|
|
|
- )
|
|
|
+ }: create_reply(origin.clone(), participant_id, post_id, None, text.clone())
|
|
|
verify {
|
|
|
let mut expected_post = Post::<T, I>::new(&vec![0u8], &vec![0u8]);
|
|
|
expected_post.increment_replies_counter();
|
|
|
- assert!(Blog::<T, I>::post_by_id(post_id) == expected_post);
|
|
|
- assert!(
|
|
|
- Blog::<T, I>::reply_by_id(post_id, T::ReplyId::zero()) ==
|
|
|
+ assert_eq!(Blog::<T, I>::post_by_id(post_id), expected_post);
|
|
|
+ assert_eq!(
|
|
|
+ Blog::<T, I>::reply_by_id(post_id, T::ReplyId::zero()),
|
|
|
Reply::<T, I>::new(
|
|
|
text.clone(),
|
|
|
participant_id,
|
|
@@ -217,7 +210,14 @@ benchmarks_instance! {
|
|
|
)
|
|
|
);
|
|
|
|
|
|
- assert_last_event::<T, I>(RawEvent::ReplyCreated(participant_id, post_id, Zero::zero(), text).into());
|
|
|
+ assert_last_event::<T, I>(
|
|
|
+ RawEvent::ReplyCreated(
|
|
|
+ participant_id,
|
|
|
+ post_id,
|
|
|
+ Zero::zero(),
|
|
|
+ text
|
|
|
+ ).into()
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
create_reply_to_reply {
|
|
@@ -229,20 +229,14 @@ benchmarks_instance! {
|
|
|
let origin = RawOrigin::Signed(account_id);
|
|
|
let mut expected_post = Post::<T, I>::new(&vec![0u8], &vec![0u8]);
|
|
|
expected_post.increment_replies_counter();
|
|
|
- assert!(Blog::<T, I>::post_by_id(post_id) == expected_post);
|
|
|
+ assert_eq!(Blog::<T, I>::post_by_id(post_id), expected_post);
|
|
|
let text = vec![0u8; t.try_into().unwrap()];
|
|
|
- }: create_reply(
|
|
|
- origin.clone(),
|
|
|
- participant_id,
|
|
|
- post_id,
|
|
|
- Some(reply_id),
|
|
|
- text.clone()
|
|
|
- )
|
|
|
+ }: create_reply(origin.clone(), participant_id, post_id, Some(reply_id), text.clone())
|
|
|
verify {
|
|
|
expected_post.increment_replies_counter();
|
|
|
- assert!(Blog::<T, I>::post_by_id(post_id) == expected_post);
|
|
|
- assert!(
|
|
|
- Blog::<T, I>::reply_by_id(post_id, T::ReplyId::one()) ==
|
|
|
+ assert_eq!(Blog::<T, I>::post_by_id(post_id), expected_post);
|
|
|
+ assert_eq!(
|
|
|
+ Blog::<T, I>::reply_by_id(post_id, T::ReplyId::one()),
|
|
|
Reply::<T, I>::new(
|
|
|
text.clone(),
|
|
|
participant_id,
|
|
@@ -251,7 +245,13 @@ benchmarks_instance! {
|
|
|
);
|
|
|
|
|
|
assert_last_event::<T, I>(
|
|
|
- RawEvent::DirectReplyCreated(participant_id, post_id, reply_id, One::one(), text).into()
|
|
|
+ RawEvent::DirectReplyCreated(
|
|
|
+ participant_id,
|
|
|
+ post_id,
|
|
|
+ reply_id,
|
|
|
+ One::one(),
|
|
|
+ text
|
|
|
+ ).into()
|
|
|
);
|
|
|
}
|
|
|
|
|
@@ -263,20 +263,14 @@ benchmarks_instance! {
|
|
|
let reply_id = generate_reply::<T, I>(account_id.clone(), participant_id, post_id.clone());
|
|
|
let origin = RawOrigin::Signed(account_id);
|
|
|
let updated_text = vec![1u8; t.try_into().unwrap()];
|
|
|
- }: _(
|
|
|
- origin.clone(),
|
|
|
- participant_id,
|
|
|
- post_id,
|
|
|
- reply_id,
|
|
|
- updated_text.clone()
|
|
|
- )
|
|
|
+ }: _(origin.clone(), participant_id, post_id, reply_id, updated_text.clone())
|
|
|
verify {
|
|
|
assert_eq!(
|
|
|
Blog::<T, I>::reply_by_id(post_id, reply_id).text_hash,
|
|
|
T::Hashing::hash(&updated_text)
|
|
|
);
|
|
|
- assert!(
|
|
|
- Blog::<T, I>::reply_by_id(post_id, reply_id) ==
|
|
|
+ assert_eq!(
|
|
|
+ Blog::<T, I>::reply_by_id(post_id, reply_id),
|
|
|
Reply::<T, I>::new(
|
|
|
updated_text.clone(),
|
|
|
participant_id,
|
|
@@ -296,13 +290,7 @@ benchmarks_instance! {
|
|
|
let post_id = generate_post::<T, I>();
|
|
|
let (account_id, participant_id) = member_funded_account::<T, I>("caller", 0);
|
|
|
let origin = RawOrigin::Signed(account_id);
|
|
|
- }: react(
|
|
|
- origin.clone(),
|
|
|
- participant_id,
|
|
|
- 0,
|
|
|
- post_id,
|
|
|
- None
|
|
|
- )
|
|
|
+ }: react(origin.clone(), participant_id, 0, post_id, None)
|
|
|
verify {
|
|
|
assert_last_event::<T, I>(
|
|
|
RawEvent::PostReactionsUpdated(participant_id, post_id, 0).into()
|
|
@@ -314,13 +302,7 @@ benchmarks_instance! {
|
|
|
let (account_id, participant_id) = member_funded_account::<T, I>("caller", 0);
|
|
|
let reply_id = generate_reply::<T, I>(account_id.clone(), participant_id, post_id.clone());
|
|
|
let origin = RawOrigin::Signed(account_id);
|
|
|
- }: react(
|
|
|
- origin.clone(),
|
|
|
- participant_id,
|
|
|
- 0,
|
|
|
- post_id,
|
|
|
- Some(reply_id)
|
|
|
- )
|
|
|
+ }: react(origin.clone(), participant_id, 0, post_id, Some(reply_id))
|
|
|
verify {
|
|
|
assert_last_event::<T, I>(
|
|
|
RawEvent::ReplyReactionsUpdated(participant_id, post_id, reply_id, 0).into()
|
|
@@ -389,4 +371,11 @@ mod tests {
|
|
|
assert_ok!(test_benchmark_react_to_post::<Runtime>());
|
|
|
})
|
|
|
}
|
|
|
+
|
|
|
+ #[test]
|
|
|
+ fn test_react_to_reply() {
|
|
|
+ ExtBuilder::default().build().execute_with(|| {
|
|
|
+ assert_ok!(test_benchmark_react_to_reply::<Runtime>());
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|