|
@@ -41,36 +41,19 @@ fn ensure_replies_equality(
|
|
|
reply: Option<Reply<Runtime, DefaultInstance>>,
|
|
|
reply_owner_id: <Runtime as frame_system::Trait>::AccountId,
|
|
|
parent: ParentId<Runtime, DefaultInstance>,
|
|
|
- editing: bool,
|
|
|
) {
|
|
|
// Ensure stored reply is equal to expected one
|
|
|
assert!(matches!(
|
|
|
reply,
|
|
|
- Some(reply) if reply == get_reply(ReplyType::Valid, reply_owner_id, parent, editing)
|
|
|
+ Some(reply) if reply == get_reply(reply_owner_id, parent)
|
|
|
));
|
|
|
}
|
|
|
|
|
|
-fn ensure_posts_equality(
|
|
|
- post: Option<Post<Runtime, DefaultInstance>>,
|
|
|
- editing: bool,
|
|
|
- locked: bool,
|
|
|
-) {
|
|
|
+fn ensure_posts_equality(post: Option<Post<Runtime, DefaultInstance>>, locked: bool) {
|
|
|
// Ensure stored post is equal to expected one
|
|
|
assert!(matches!(
|
|
|
post,
|
|
|
- Some(post) if post == get_post(PostType::Valid, editing, locked)
|
|
|
- ));
|
|
|
-}
|
|
|
-
|
|
|
-fn ensure_reaction_status(
|
|
|
- reactions: Option<[bool; REACTIONS_MAX_NUMBER as usize]>,
|
|
|
- index: ReactionsNumber,
|
|
|
- status: bool,
|
|
|
-) {
|
|
|
- // Ensure reaction status at given index is equal to expected one
|
|
|
- assert!(matches!(
|
|
|
- reactions,
|
|
|
- Some(reactions) if reactions[index as usize] == status
|
|
|
+ Some(post) if post == get_post(locked)
|
|
|
));
|
|
|
}
|
|
|
|
|
@@ -82,14 +65,14 @@ fn post_creation_success() {
|
|
|
let number_of_events_before_call = System::events().len();
|
|
|
|
|
|
// Create post
|
|
|
- assert_ok!(create_post(FIRST_OWNER_ORIGIN, PostType::Valid));
|
|
|
+ assert_ok!(create_post(FIRST_OWNER_ORIGIN));
|
|
|
|
|
|
// Check related state after extrinsic performed
|
|
|
|
|
|
// Posts storage updated succesfully
|
|
|
let post = post_by_id(FIRST_ID);
|
|
|
|
|
|
- ensure_posts_equality(post, false, false);
|
|
|
+ ensure_posts_equality(post, false);
|
|
|
|
|
|
// Post counter, related to given blog updated succesfully
|
|
|
assert_eq!(post_count(), 1);
|
|
@@ -106,7 +89,7 @@ fn post_creation_blog_ownership_error() {
|
|
|
// Events number before tested call
|
|
|
let number_of_events_before_call = System::events().len();
|
|
|
|
|
|
- let create_result = create_post(SECOND_OWNER_ORIGIN, PostType::Valid);
|
|
|
+ let create_result = create_post(SECOND_OWNER_ORIGIN);
|
|
|
|
|
|
// Check if related runtime storage left unchanged
|
|
|
// assert!(post_storage_unchanged(FIRST_ID, FIRST_ID));
|
|
@@ -120,46 +103,6 @@ fn post_creation_blog_ownership_error() {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-#[test]
|
|
|
-fn post_creation_title_too_long() {
|
|
|
- ExtBuilder::default().build().execute_with(|| {
|
|
|
- // Events number before tested call
|
|
|
- let number_of_events_before_call = System::events().len();
|
|
|
-
|
|
|
- let create_result = create_post(FIRST_OWNER_ORIGIN, PostType::PostTitleInvalid);
|
|
|
-
|
|
|
- // Check if related runtime storage left unchanged
|
|
|
- //assert!(post_storage_unchanged(FIRST_ID, FIRST_ID));
|
|
|
-
|
|
|
- // Failure checked
|
|
|
- assert_failure(
|
|
|
- create_result,
|
|
|
- Error::PostTitleTooLong,
|
|
|
- number_of_events_before_call,
|
|
|
- );
|
|
|
- })
|
|
|
-}
|
|
|
-
|
|
|
-#[test]
|
|
|
-fn post_creation_body_too_long() {
|
|
|
- ExtBuilder::default().build().execute_with(|| {
|
|
|
- // Events number before tested call
|
|
|
- let number_of_events_before_call = System::events().len();
|
|
|
-
|
|
|
- let create_result = create_post(FIRST_OWNER_ORIGIN, PostType::PostBodyInvalid);
|
|
|
-
|
|
|
- // Check if related runtime storage left unchanged
|
|
|
- //assert!(post_storage_unchanged(FIRST_ID, FIRST_ID));
|
|
|
-
|
|
|
- // Failure checked
|
|
|
- assert_failure(
|
|
|
- create_result,
|
|
|
- Error::PostBodyTooLong,
|
|
|
- number_of_events_before_call,
|
|
|
- );
|
|
|
- })
|
|
|
-}
|
|
|
-
|
|
|
#[test]
|
|
|
fn post_creation_limit_reached() {
|
|
|
ExtBuilder::default().build().execute_with(|| {
|
|
@@ -167,7 +110,7 @@ fn post_creation_limit_reached() {
|
|
|
// Events number before tested call
|
|
|
let number_of_events_before_call = System::events().len();
|
|
|
|
|
|
- if let Err(create_post_err) = create_post(FIRST_OWNER_ORIGIN, PostType::Valid) {
|
|
|
+ if let Err(create_post_err) = create_post(FIRST_OWNER_ORIGIN) {
|
|
|
// Post counter & post max number contraint equality checked
|
|
|
assert_eq!(post_count(), PostsMaxNumber::get());
|
|
|
|
|
@@ -186,7 +129,7 @@ fn post_creation_limit_reached() {
|
|
|
#[test]
|
|
|
fn post_locking_success() {
|
|
|
ExtBuilder::default().build().execute_with(|| {
|
|
|
- create_post(FIRST_OWNER_ORIGIN, PostType::Valid).unwrap();
|
|
|
+ create_post(FIRST_OWNER_ORIGIN).unwrap();
|
|
|
|
|
|
let post = post_by_id(FIRST_ID).unwrap();
|
|
|
|
|
@@ -231,7 +174,7 @@ fn post_locking_post_not_found() {
|
|
|
#[test]
|
|
|
fn post_locking_ownership_error() {
|
|
|
ExtBuilder::default().build().execute_with(|| {
|
|
|
- create_post(FIRST_OWNER_ORIGIN, PostType::Valid).unwrap();
|
|
|
+ create_post(FIRST_OWNER_ORIGIN).unwrap();
|
|
|
|
|
|
// Events number before tested call
|
|
|
let number_of_events_before_call = System::events().len();
|
|
@@ -257,7 +200,7 @@ fn post_locking_ownership_error() {
|
|
|
#[test]
|
|
|
fn post_unlocking_success() {
|
|
|
ExtBuilder::default().build().execute_with(|| {
|
|
|
- create_post(FIRST_OWNER_ORIGIN, PostType::Valid).unwrap();
|
|
|
+ create_post(FIRST_OWNER_ORIGIN).unwrap();
|
|
|
|
|
|
// Lock post firstly
|
|
|
lock_post(FIRST_OWNER_ORIGIN, FIRST_ID).unwrap();
|
|
@@ -287,7 +230,7 @@ fn post_unlocking_success() {
|
|
|
#[test]
|
|
|
fn post_unlocking_owner_not_found() {
|
|
|
ExtBuilder::default().build().execute_with(|| {
|
|
|
- create_post(FIRST_OWNER_ORIGIN, PostType::Valid).unwrap();
|
|
|
+ create_post(FIRST_OWNER_ORIGIN).unwrap();
|
|
|
|
|
|
// Lock post firstly
|
|
|
lock_post(FIRST_OWNER_ORIGIN, FIRST_ID).unwrap();
|
|
@@ -333,7 +276,7 @@ fn post_unlocking_post_not_found() {
|
|
|
#[test]
|
|
|
fn post_unlocking_ownership_error() {
|
|
|
ExtBuilder::default().build().execute_with(|| {
|
|
|
- create_post(FIRST_OWNER_ORIGIN, PostType::Valid).unwrap();
|
|
|
+ create_post(FIRST_OWNER_ORIGIN).unwrap();
|
|
|
|
|
|
// Lock post firstly
|
|
|
lock_post(FIRST_OWNER_ORIGIN, FIRST_ID).unwrap();
|
|
@@ -362,17 +305,17 @@ fn post_unlocking_ownership_error() {
|
|
|
fn post_editing_success() {
|
|
|
ExtBuilder::default().build().execute_with(|| {
|
|
|
// Create blog for future posts
|
|
|
- create_post(FIRST_OWNER_ORIGIN, PostType::Valid).unwrap();
|
|
|
+ create_post(FIRST_OWNER_ORIGIN).unwrap();
|
|
|
|
|
|
// Events number before tested call
|
|
|
let number_of_events_before_call = System::events().len();
|
|
|
|
|
|
- assert_ok!(edit_post(FIRST_OWNER_ORIGIN, FIRST_ID, PostType::Valid));
|
|
|
+ assert_ok!(edit_post(FIRST_OWNER_ORIGIN, FIRST_ID));
|
|
|
|
|
|
// Post after editing checked
|
|
|
let post_after_editing = post_by_id(FIRST_ID);
|
|
|
|
|
|
- ensure_posts_equality(post_after_editing, true, false);
|
|
|
+ ensure_posts_equality(post_after_editing, false);
|
|
|
|
|
|
let post_edited_event = TestEvent::crate_DefaultInstance(RawEvent::PostEdited(FIRST_ID));
|
|
|
|
|
@@ -384,18 +327,18 @@ fn post_editing_success() {
|
|
|
#[test]
|
|
|
fn post_editing_ownership_error() {
|
|
|
ExtBuilder::default().build().execute_with(|| {
|
|
|
- create_post(FIRST_OWNER_ORIGIN, PostType::Valid).unwrap();
|
|
|
+ create_post(FIRST_OWNER_ORIGIN).unwrap();
|
|
|
|
|
|
// Events number before tested call
|
|
|
let number_of_events_before_call = System::events().len();
|
|
|
|
|
|
- let edit_result = edit_post(SECOND_OWNER_ORIGIN, FIRST_ID, PostType::Valid);
|
|
|
+ let edit_result = edit_post(SECOND_OWNER_ORIGIN, FIRST_ID);
|
|
|
|
|
|
// Remain unedited
|
|
|
let post = post_by_id(FIRST_ID);
|
|
|
|
|
|
// Compare with default unedited post
|
|
|
- ensure_posts_equality(post, false, false);
|
|
|
+ ensure_posts_equality(post, false);
|
|
|
|
|
|
// Failure checked
|
|
|
assert_failure(
|
|
@@ -413,7 +356,7 @@ fn post_editing_post_not_found() {
|
|
|
let number_of_events_before_call = System::events().len();
|
|
|
|
|
|
// Try to unlock not existing post
|
|
|
- let edit_result = edit_post(FIRST_OWNER_ORIGIN, FIRST_ID, PostType::Valid);
|
|
|
+ let edit_result = edit_post(FIRST_OWNER_ORIGIN, FIRST_ID);
|
|
|
|
|
|
// Failure checked
|
|
|
assert_failure(
|
|
@@ -427,7 +370,7 @@ fn post_editing_post_not_found() {
|
|
|
#[test]
|
|
|
fn post_editing_post_locked_error() {
|
|
|
ExtBuilder::default().build().execute_with(|| {
|
|
|
- create_post(FIRST_OWNER_ORIGIN, PostType::Valid).unwrap();
|
|
|
+ create_post(FIRST_OWNER_ORIGIN).unwrap();
|
|
|
|
|
|
// Lock post to make all related data immutable
|
|
|
lock_post(FIRST_OWNER_ORIGIN, FIRST_ID).unwrap();
|
|
@@ -435,13 +378,13 @@ fn post_editing_post_locked_error() {
|
|
|
// Events number before tested call
|
|
|
let number_of_events_before_call = System::events().len();
|
|
|
|
|
|
- let edit_result = edit_post(FIRST_OWNER_ORIGIN, FIRST_ID, PostType::Valid);
|
|
|
+ let edit_result = edit_post(FIRST_OWNER_ORIGIN, FIRST_ID);
|
|
|
|
|
|
// Remain unedited
|
|
|
let post = post_by_id(FIRST_ID);
|
|
|
|
|
|
// Compare with default unedited locked post
|
|
|
- ensure_posts_equality(post, false, true);
|
|
|
+ ensure_posts_equality(post, true);
|
|
|
|
|
|
// Failure checked
|
|
|
assert_failure(
|
|
@@ -452,74 +395,19 @@ fn post_editing_post_locked_error() {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-#[test]
|
|
|
-fn post_editing_title_invalid_error() {
|
|
|
- ExtBuilder::default().build().execute_with(|| {
|
|
|
- create_post(FIRST_OWNER_ORIGIN, PostType::Valid).unwrap();
|
|
|
-
|
|
|
- // Events number before tested call
|
|
|
- let number_of_events_before_call = System::events().len();
|
|
|
-
|
|
|
- let edit_result = edit_post(FIRST_OWNER_ORIGIN, FIRST_ID, PostType::PostTitleInvalid);
|
|
|
-
|
|
|
- // Remain unedited
|
|
|
- let post = post_by_id(FIRST_ID);
|
|
|
-
|
|
|
- // Compare with default unedited post
|
|
|
- ensure_posts_equality(post, false, false);
|
|
|
-
|
|
|
- // Failure checked
|
|
|
- assert_failure(
|
|
|
- edit_result,
|
|
|
- Error::PostTitleTooLong,
|
|
|
- number_of_events_before_call,
|
|
|
- );
|
|
|
- })
|
|
|
-}
|
|
|
-
|
|
|
-#[test]
|
|
|
-fn post_editing_body_invalid_error() {
|
|
|
- ExtBuilder::default().build().execute_with(|| {
|
|
|
- create_post(FIRST_OWNER_ORIGIN, PostType::Valid).unwrap();
|
|
|
-
|
|
|
- // Events number before tested call
|
|
|
- let number_of_events_before_call = System::events().len();
|
|
|
-
|
|
|
- let edit_result = edit_post(FIRST_OWNER_ORIGIN, FIRST_ID, PostType::PostBodyInvalid);
|
|
|
-
|
|
|
- // Remain unedited
|
|
|
- let post = post_by_id(FIRST_ID);
|
|
|
-
|
|
|
- // Compare with default unedited post
|
|
|
- ensure_posts_equality(post, false, false);
|
|
|
-
|
|
|
- // Failure checked
|
|
|
- assert_failure(
|
|
|
- edit_result,
|
|
|
- Error::PostBodyTooLong,
|
|
|
- number_of_events_before_call,
|
|
|
- );
|
|
|
- })
|
|
|
-}
|
|
|
-
|
|
|
// Replies
|
|
|
#[test]
|
|
|
fn reply_creation_success() {
|
|
|
ExtBuilder::default().build().execute_with(|| {
|
|
|
// Create post for future replies
|
|
|
- create_post(FIRST_OWNER_ORIGIN, PostType::Valid).unwrap();
|
|
|
+ create_post(FIRST_OWNER_ORIGIN).unwrap();
|
|
|
|
|
|
let reply_owner_id = ensure_signed(Origin::signed(SECOND_OWNER_ORIGIN)).unwrap();
|
|
|
|
|
|
// Events number before tested call
|
|
|
let number_of_events_before_call = System::events().len();
|
|
|
|
|
|
- assert_ok!(create_reply(
|
|
|
- SECOND_OWNER_ORIGIN,
|
|
|
- FIRST_ID,
|
|
|
- None,
|
|
|
- ReplyType::Valid
|
|
|
- ));
|
|
|
+ assert_ok!(create_reply(SECOND_OWNER_ORIGIN, FIRST_ID, None));
|
|
|
|
|
|
// Check reply related state after extrinsic performed
|
|
|
|
|
@@ -528,7 +416,7 @@ fn reply_creation_success() {
|
|
|
// Replies related storage updated succesfully
|
|
|
let reply = reply_by_id(FIRST_ID, FIRST_ID);
|
|
|
|
|
|
- ensure_replies_equality(reply, reply_owner_id, ParentId::Post(FIRST_ID), false);
|
|
|
+ ensure_replies_equality(reply, reply_owner_id, ParentId::Post(FIRST_ID));
|
|
|
|
|
|
// Overall post replies count
|
|
|
assert_eq!(post.replies_count(), 1);
|
|
@@ -547,26 +435,16 @@ fn reply_creation_success() {
|
|
|
fn direct_reply_creation_success() {
|
|
|
ExtBuilder::default().build().execute_with(|| {
|
|
|
// Create post for future replies
|
|
|
- create_post(FIRST_OWNER_ORIGIN, PostType::Valid).unwrap();
|
|
|
+ create_post(FIRST_OWNER_ORIGIN).unwrap();
|
|
|
let direct_reply_owner_id = ensure_signed(Origin::signed(SECOND_OWNER_ORIGIN)).unwrap();
|
|
|
|
|
|
- assert_ok!(create_reply(
|
|
|
- FIRST_OWNER_ORIGIN,
|
|
|
- FIRST_ID,
|
|
|
- None,
|
|
|
- ReplyType::Valid
|
|
|
- ));
|
|
|
+ assert_ok!(create_reply(FIRST_OWNER_ORIGIN, FIRST_ID, None));
|
|
|
|
|
|
// Events number before tested call
|
|
|
let number_of_events_before_call = System::events().len();
|
|
|
|
|
|
// Create reply for direct replying
|
|
|
- assert_ok!(create_reply(
|
|
|
- SECOND_OWNER_ORIGIN,
|
|
|
- FIRST_ID,
|
|
|
- Some(FIRST_ID),
|
|
|
- ReplyType::Valid
|
|
|
- ));
|
|
|
+ assert_ok!(create_reply(SECOND_OWNER_ORIGIN, FIRST_ID, Some(FIRST_ID)));
|
|
|
|
|
|
// Check reply related state after extrinsic performed
|
|
|
|
|
@@ -592,7 +470,7 @@ fn direct_reply_creation_success() {
|
|
|
#[test]
|
|
|
fn reply_creation_post_locked_error() {
|
|
|
ExtBuilder::default().build().execute_with(|| {
|
|
|
- create_post(FIRST_OWNER_ORIGIN, PostType::Valid).unwrap();
|
|
|
+ create_post(FIRST_OWNER_ORIGIN).unwrap();
|
|
|
|
|
|
// Lock post to make all related data immutable
|
|
|
lock_post(FIRST_OWNER_ORIGIN, FIRST_ID).unwrap();
|
|
@@ -600,8 +478,7 @@ fn reply_creation_post_locked_error() {
|
|
|
// Events number before tested call
|
|
|
let number_of_events_before_call = System::events().len();
|
|
|
|
|
|
- let reply_creation_result =
|
|
|
- create_reply(SECOND_OWNER_ORIGIN, FIRST_ID, None, ReplyType::Valid);
|
|
|
+ let reply_creation_result = create_reply(SECOND_OWNER_ORIGIN, FIRST_ID, None);
|
|
|
|
|
|
// Check if related replies storage left unchanged
|
|
|
assert!(replies_storage_unchanged(FIRST_ID, FIRST_ID));
|
|
@@ -615,37 +492,13 @@ fn reply_creation_post_locked_error() {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-#[test]
|
|
|
-fn reply_creation_text_too_long_error() {
|
|
|
- ExtBuilder::default().build().execute_with(|| {
|
|
|
- create_post(FIRST_OWNER_ORIGIN, PostType::Valid).unwrap();
|
|
|
-
|
|
|
- // Events number before tested call
|
|
|
- let number_of_events_before_call = System::events().len();
|
|
|
-
|
|
|
- let reply_creation_result =
|
|
|
- create_reply(SECOND_OWNER_ORIGIN, FIRST_ID, None, ReplyType::Invalid);
|
|
|
-
|
|
|
- // Check if related replies storage left unchanged
|
|
|
- assert!(replies_storage_unchanged(FIRST_ID, FIRST_ID));
|
|
|
-
|
|
|
- // Failure checked
|
|
|
- assert_failure(
|
|
|
- reply_creation_result,
|
|
|
- Error::ReplyTextTooLong,
|
|
|
- number_of_events_before_call,
|
|
|
- );
|
|
|
- })
|
|
|
-}
|
|
|
-
|
|
|
#[test]
|
|
|
fn reply_creation_post_not_found() {
|
|
|
ExtBuilder::default().build().execute_with(|| {
|
|
|
// Events number before tested call
|
|
|
let number_of_events_before_call = System::events().len();
|
|
|
|
|
|
- let reply_creation_result =
|
|
|
- create_reply(SECOND_OWNER_ORIGIN, FIRST_ID, None, ReplyType::Valid);
|
|
|
+ let reply_creation_result = create_reply(SECOND_OWNER_ORIGIN, FIRST_ID, None);
|
|
|
|
|
|
// Check if related replies storage left unchanged
|
|
|
assert!(replies_storage_unchanged(FIRST_ID, FIRST_ID));
|
|
@@ -663,13 +516,11 @@ fn reply_creation_post_not_found() {
|
|
|
fn reply_creation_limit_reached() {
|
|
|
ExtBuilder::default().build().execute_with(|| {
|
|
|
// Create post for future replies
|
|
|
- create_post(FIRST_OWNER_ORIGIN, PostType::Valid).unwrap();
|
|
|
+ create_post(FIRST_OWNER_ORIGIN).unwrap();
|
|
|
loop {
|
|
|
// Events number before tested call
|
|
|
let number_of_events_before_call = System::events().len();
|
|
|
- if let Err(create_reply_err) =
|
|
|
- create_reply(FIRST_OWNER_ORIGIN, FIRST_ID, None, ReplyType::Valid)
|
|
|
- {
|
|
|
+ if let Err(create_reply_err) = create_reply(FIRST_OWNER_ORIGIN, FIRST_ID, None) {
|
|
|
let post = post_by_id(FIRST_ID).unwrap();
|
|
|
|
|
|
// Root post replies counter & reply root max number contraint equality checked
|
|
@@ -691,18 +542,13 @@ fn reply_creation_limit_reached() {
|
|
|
fn direct_reply_creation_reply_not_found() {
|
|
|
ExtBuilder::default().build().execute_with(|| {
|
|
|
// Create post for future replies
|
|
|
- create_post(FIRST_OWNER_ORIGIN, PostType::Valid).unwrap();
|
|
|
+ create_post(FIRST_OWNER_ORIGIN).unwrap();
|
|
|
|
|
|
// Events number before tested call
|
|
|
let number_of_events_before_call = System::events().len();
|
|
|
|
|
|
// Attempt to create direct reply for nonexistent reply
|
|
|
- let reply_creation_result = create_reply(
|
|
|
- SECOND_OWNER_ORIGIN,
|
|
|
- FIRST_ID,
|
|
|
- Some(FIRST_ID),
|
|
|
- ReplyType::Valid,
|
|
|
- );
|
|
|
+ let reply_creation_result = create_reply(SECOND_OWNER_ORIGIN, FIRST_ID, Some(FIRST_ID));
|
|
|
|
|
|
// Check if related runtime storage left unchanged
|
|
|
assert!(replies_storage_unchanged(FIRST_ID, SECOND_ID));
|
|
@@ -720,21 +566,21 @@ fn direct_reply_creation_reply_not_found() {
|
|
|
fn reply_editing_success() {
|
|
|
ExtBuilder::default().build().execute_with(|| {
|
|
|
// Create post for future replies
|
|
|
- create_post(FIRST_OWNER_ORIGIN, PostType::Valid).unwrap();
|
|
|
+ create_post(FIRST_OWNER_ORIGIN).unwrap();
|
|
|
|
|
|
let reply_owner_id = ensure_signed(Origin::signed(SECOND_OWNER_ORIGIN)).unwrap();
|
|
|
|
|
|
- create_reply(SECOND_OWNER_ORIGIN, FIRST_ID, None, ReplyType::Valid).unwrap();
|
|
|
+ create_reply(SECOND_OWNER_ORIGIN, FIRST_ID, None).unwrap();
|
|
|
|
|
|
// Events number before tested call
|
|
|
let number_of_events_before_call = System::events().len();
|
|
|
|
|
|
- edit_reply(SECOND_OWNER_ORIGIN, FIRST_ID, FIRST_ID, ReplyType::Valid).unwrap();
|
|
|
+ edit_reply(SECOND_OWNER_ORIGIN, FIRST_ID, FIRST_ID).unwrap();
|
|
|
|
|
|
// Reply after editing checked
|
|
|
let reply = reply_by_id(FIRST_ID, FIRST_ID);
|
|
|
|
|
|
- ensure_replies_equality(reply, reply_owner_id, ParentId::Post(FIRST_ID), true);
|
|
|
+ ensure_replies_equality(reply, reply_owner_id, ParentId::Post(FIRST_ID));
|
|
|
|
|
|
// Event checked
|
|
|
let reply_edited_event = get_test_event(RawEvent::ReplyEdited(FIRST_ID, FIRST_ID));
|
|
@@ -746,11 +592,11 @@ fn reply_editing_success() {
|
|
|
fn reply_editing_post_locked_error() {
|
|
|
ExtBuilder::default().build().execute_with(|| {
|
|
|
// Create post for future replies
|
|
|
- create_post(FIRST_OWNER_ORIGIN, PostType::Valid).unwrap();
|
|
|
+ create_post(FIRST_OWNER_ORIGIN).unwrap();
|
|
|
|
|
|
let reply_owner_id = ensure_signed(Origin::signed(SECOND_OWNER_ORIGIN)).unwrap();
|
|
|
|
|
|
- create_reply(SECOND_OWNER_ORIGIN, FIRST_ID, None, ReplyType::Valid).unwrap();
|
|
|
+ create_reply(SECOND_OWNER_ORIGIN, FIRST_ID, None).unwrap();
|
|
|
|
|
|
// Lock blog to make all related data immutable
|
|
|
lock_post(FIRST_OWNER_ORIGIN, FIRST_ID).unwrap();
|
|
@@ -758,14 +604,13 @@ fn reply_editing_post_locked_error() {
|
|
|
// Events number before tested call
|
|
|
let number_of_events_before_call = System::events().len();
|
|
|
|
|
|
- let reply_editing_result =
|
|
|
- edit_reply(SECOND_OWNER_ORIGIN, FIRST_ID, FIRST_ID, ReplyType::Valid);
|
|
|
+ let reply_editing_result = edit_reply(SECOND_OWNER_ORIGIN, FIRST_ID, FIRST_ID);
|
|
|
|
|
|
// Reply after editing checked
|
|
|
let reply = reply_by_id(FIRST_ID, FIRST_ID);
|
|
|
|
|
|
// Compare with default unedited reply
|
|
|
- ensure_replies_equality(reply, reply_owner_id, ParentId::Post(FIRST_ID), true);
|
|
|
+ ensure_replies_equality(reply, reply_owner_id, ParentId::Post(FIRST_ID));
|
|
|
|
|
|
// Failure checked
|
|
|
assert_failure(
|
|
@@ -780,13 +625,12 @@ fn reply_editing_post_locked_error() {
|
|
|
fn reply_editing_not_found() {
|
|
|
ExtBuilder::default().build().execute_with(|| {
|
|
|
// Create post for future replies
|
|
|
- create_post(FIRST_OWNER_ORIGIN, PostType::Valid).unwrap();
|
|
|
+ create_post(FIRST_OWNER_ORIGIN).unwrap();
|
|
|
|
|
|
// Events number before tested call
|
|
|
let number_of_events_before_call = System::events().len();
|
|
|
|
|
|
- let reply_editing_result =
|
|
|
- edit_reply(SECOND_OWNER_ORIGIN, FIRST_ID, FIRST_ID, ReplyType::Valid);
|
|
|
+ let reply_editing_result = edit_reply(SECOND_OWNER_ORIGIN, FIRST_ID, FIRST_ID);
|
|
|
|
|
|
// Failure checked
|
|
|
assert_failure(
|
|
@@ -797,58 +641,26 @@ fn reply_editing_not_found() {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-#[test]
|
|
|
-fn reply_editing_text_too_long_error() {
|
|
|
- ExtBuilder::default().build().execute_with(|| {
|
|
|
- // Create post for future replies
|
|
|
- create_post(FIRST_OWNER_ORIGIN, PostType::Valid).unwrap();
|
|
|
-
|
|
|
- let reply_owner_id = ensure_signed(Origin::signed(SECOND_OWNER_ORIGIN)).unwrap();
|
|
|
-
|
|
|
- create_reply(SECOND_OWNER_ORIGIN, FIRST_ID, None, ReplyType::Valid).unwrap();
|
|
|
-
|
|
|
- // Events number before tested call
|
|
|
- let number_of_events_before_call = System::events().len();
|
|
|
-
|
|
|
- let reply_editing_result =
|
|
|
- edit_reply(SECOND_OWNER_ORIGIN, FIRST_ID, FIRST_ID, ReplyType::Invalid);
|
|
|
-
|
|
|
- // Reply after editing checked
|
|
|
- let reply = reply_by_id(FIRST_ID, FIRST_ID);
|
|
|
-
|
|
|
- // Compare with default unedited reply
|
|
|
- ensure_replies_equality(reply, reply_owner_id, ParentId::Post(FIRST_ID), true);
|
|
|
-
|
|
|
- // Failure checked
|
|
|
- assert_failure(
|
|
|
- reply_editing_result,
|
|
|
- Error::ReplyTextTooLong,
|
|
|
- number_of_events_before_call,
|
|
|
- );
|
|
|
- })
|
|
|
-}
|
|
|
-
|
|
|
#[test]
|
|
|
fn reply_editing_ownership_error() {
|
|
|
ExtBuilder::default().build().execute_with(|| {
|
|
|
// Create post for future replies
|
|
|
- create_post(FIRST_OWNER_ORIGIN, PostType::Valid).unwrap();
|
|
|
+ create_post(FIRST_OWNER_ORIGIN).unwrap();
|
|
|
|
|
|
let reply_owner_id = ensure_signed(Origin::signed(SECOND_OWNER_ORIGIN)).unwrap();
|
|
|
|
|
|
- create_reply(SECOND_OWNER_ORIGIN, FIRST_ID, None, ReplyType::Valid).unwrap();
|
|
|
+ create_reply(SECOND_OWNER_ORIGIN, FIRST_ID, None).unwrap();
|
|
|
|
|
|
// Events number before tested call
|
|
|
let number_of_events_before_call = System::events().len();
|
|
|
|
|
|
- let reply_editing_result =
|
|
|
- edit_reply(FIRST_OWNER_ORIGIN, FIRST_ID, FIRST_ID, ReplyType::Valid);
|
|
|
+ let reply_editing_result = edit_reply(FIRST_OWNER_ORIGIN, FIRST_ID, FIRST_ID);
|
|
|
|
|
|
// Reply after editing checked
|
|
|
let reply = reply_by_id(FIRST_ID, FIRST_ID);
|
|
|
|
|
|
// Compare with default unedited reply
|
|
|
- ensure_replies_equality(reply, reply_owner_id, ParentId::Post(FIRST_ID), true);
|
|
|
+ ensure_replies_equality(reply, reply_owner_id, ParentId::Post(FIRST_ID));
|
|
|
|
|
|
// Failure checked
|
|
|
assert_failure(
|
|
@@ -865,7 +677,7 @@ fn reaction_success() {
|
|
|
|
|
|
ExtBuilder::default().build().execute_with(|| {
|
|
|
// Create post for future replies
|
|
|
- create_post(FIRST_OWNER_ORIGIN, PostType::Valid).unwrap();
|
|
|
+ create_post(FIRST_OWNER_ORIGIN).unwrap();
|
|
|
|
|
|
let reaction_owner_id = ensure_signed(Origin::signed(SECOND_OWNER_ORIGIN)).unwrap();
|
|
|
|
|
@@ -875,26 +687,19 @@ fn reaction_success() {
|
|
|
// React to a post
|
|
|
assert_ok!(react(SECOND_OWNER_ORIGIN, REACTION_INDEX, FIRST_ID, None,));
|
|
|
|
|
|
- // Reactions state after react to post extrinsic performed
|
|
|
- ensure_reaction_status(
|
|
|
- get_reactions(FIRST_ID, None, reaction_owner_id),
|
|
|
- REACTION_INDEX,
|
|
|
- true,
|
|
|
- );
|
|
|
-
|
|
|
// Event checked
|
|
|
let post_reactions_updated_event = get_test_event(RawEvent::PostReactionsUpdated(
|
|
|
reaction_owner_id,
|
|
|
FIRST_ID,
|
|
|
REACTION_INDEX,
|
|
|
- true,
|
|
|
));
|
|
|
+
|
|
|
assert_event_success(
|
|
|
post_reactions_updated_event,
|
|
|
number_of_events_before_call + 1,
|
|
|
);
|
|
|
|
|
|
- create_reply(FIRST_OWNER_ORIGIN, FIRST_ID, None, ReplyType::Valid).unwrap();
|
|
|
+ create_reply(FIRST_OWNER_ORIGIN, FIRST_ID, None).unwrap();
|
|
|
|
|
|
// Events number before tested call
|
|
|
let number_of_events_before_call = System::events().len();
|
|
@@ -909,20 +714,12 @@ fn reaction_success() {
|
|
|
));
|
|
|
}
|
|
|
|
|
|
- // Reactions state after react to reply extrinsic performed
|
|
|
- ensure_reaction_status(
|
|
|
- get_reactions(FIRST_ID, Some(FIRST_ID), reaction_owner_id),
|
|
|
- REACTION_INDEX,
|
|
|
- false,
|
|
|
- );
|
|
|
-
|
|
|
// Event checked
|
|
|
let reply_reactions_updated_event = get_test_event(RawEvent::ReplyReactionsUpdated(
|
|
|
reaction_owner_id,
|
|
|
FIRST_ID,
|
|
|
FIRST_ID,
|
|
|
REACTION_INDEX,
|
|
|
- false,
|
|
|
));
|
|
|
assert_event_success(
|
|
|
reply_reactions_updated_event,
|
|
@@ -936,7 +733,7 @@ fn reaction_invalid_index() {
|
|
|
const REACTIONS_MAX_NUMBER: ReactionsNumber = 5;
|
|
|
|
|
|
ExtBuilder::default().build().execute_with(|| {
|
|
|
- create_post(FIRST_OWNER_ORIGIN, PostType::Valid).unwrap();
|
|
|
+ create_post(FIRST_OWNER_ORIGIN).unwrap();
|
|
|
|
|
|
// Events number before tested call
|
|
|
let number_of_events_before_call = System::events().len();
|
|
@@ -945,11 +742,6 @@ fn reaction_invalid_index() {
|
|
|
// Should fail, as last index in configured reactions array is less by one than array length
|
|
|
let react_result = react(SECOND_OWNER_ORIGIN, REACTIONS_MAX_NUMBER, FIRST_ID, None);
|
|
|
|
|
|
- let reaction_owner_id = ensure_signed(Origin::signed(SECOND_OWNER_ORIGIN)).unwrap();
|
|
|
-
|
|
|
- // Ensure reactions related state left unchanged
|
|
|
- assert!(get_reactions(FIRST_ID, None, reaction_owner_id).is_none());
|
|
|
-
|
|
|
// Failure checked
|
|
|
assert_failure(
|
|
|
react_result,
|
|
@@ -970,11 +762,6 @@ fn reaction_post_not_found() {
|
|
|
// React to a post
|
|
|
let react_result = react(SECOND_OWNER_ORIGIN, REACTION_INDEX, FIRST_ID, None);
|
|
|
|
|
|
- let reaction_owner_id = ensure_signed(Origin::signed(SECOND_OWNER_ORIGIN)).unwrap();
|
|
|
-
|
|
|
- // Ensure reactions related state left unchanged
|
|
|
- assert!(get_reactions(FIRST_ID, None, reaction_owner_id).is_none());
|
|
|
-
|
|
|
// Failure checked
|
|
|
assert_failure(
|
|
|
react_result,
|
|
@@ -989,7 +776,7 @@ fn reaction_reply_not_found() {
|
|
|
const REACTION_INDEX: ReactionsNumber = 4;
|
|
|
|
|
|
ExtBuilder::default().build().execute_with(|| {
|
|
|
- create_post(FIRST_OWNER_ORIGIN, PostType::Valid).unwrap();
|
|
|
+ create_post(FIRST_OWNER_ORIGIN).unwrap();
|
|
|
|
|
|
// Events number before tested call
|
|
|
let number_of_events_before_call = System::events().len();
|
|
@@ -1002,11 +789,6 @@ fn reaction_reply_not_found() {
|
|
|
Some(FIRST_ID),
|
|
|
);
|
|
|
|
|
|
- let reaction_owner_id = ensure_signed(Origin::signed(SECOND_OWNER_ORIGIN)).unwrap();
|
|
|
-
|
|
|
- // Ensure reactions related state left unchanged
|
|
|
- assert!(get_reactions(FIRST_ID, Some(FIRST_ID), reaction_owner_id).is_none());
|
|
|
-
|
|
|
// Failure checked
|
|
|
assert_failure(
|
|
|
react_result,
|
|
@@ -1021,7 +803,7 @@ fn reaction_post_locked_error() {
|
|
|
const REACTION_INDEX: ReactionsNumber = 4;
|
|
|
|
|
|
ExtBuilder::default().build().execute_with(|| {
|
|
|
- create_post(FIRST_OWNER_ORIGIN, PostType::Valid).unwrap();
|
|
|
+ create_post(FIRST_OWNER_ORIGIN).unwrap();
|
|
|
|
|
|
// Lock block to forbid mutations
|
|
|
lock_post(FIRST_OWNER_ORIGIN, FIRST_ID).unwrap();
|
|
@@ -1032,11 +814,6 @@ fn reaction_post_locked_error() {
|
|
|
// React to a post
|
|
|
let react_result = react(SECOND_OWNER_ORIGIN, REACTION_INDEX, FIRST_ID, None);
|
|
|
|
|
|
- let reaction_owner_id = ensure_signed(Origin::signed(SECOND_OWNER_ORIGIN)).unwrap();
|
|
|
-
|
|
|
- // Ensure reactions related state left unchanged
|
|
|
- assert!(get_reactions(FIRST_ID, None, reaction_owner_id).is_none());
|
|
|
-
|
|
|
// Failure checked
|
|
|
assert_failure(
|
|
|
react_result,
|