remove_curator_from_group.rs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. use super::*;
  2. #[test]
  3. fn remove_curator_from_group_success() {
  4. with_test_externalities(|| {
  5. // Add curator group
  6. assert_ok!(add_curator_group(LEAD_ORIGIN));
  7. // Add first curator to group
  8. assert_ok!(add_curator_to_group(
  9. LEAD_ORIGIN,
  10. FIRST_CURATOR_GROUP_ID,
  11. FIRST_CURATOR_ID
  12. ));
  13. // Add second curator to group
  14. assert_ok!(add_curator_to_group(
  15. LEAD_ORIGIN,
  16. FIRST_CURATOR_GROUP_ID,
  17. SECOND_CURATOR_ID
  18. ));
  19. // Runtime tested state before call
  20. // Events number before tested call
  21. let number_of_events_before_call = System::events().len();
  22. // Remove first curator from group
  23. assert_ok!(remove_curator_from_group(
  24. LEAD_ORIGIN,
  25. FIRST_CURATOR_GROUP_ID,
  26. FIRST_CURATOR_ID
  27. ));
  28. // Runtime tested state after call
  29. // Ensure group contains only second curator
  30. let mut curator_group = CuratorGroup::default();
  31. curator_group.get_curators_mut().insert(SECOND_CURATOR_ID);
  32. assert_eq!(curator_group_by_id(FIRST_CURATOR_GROUP_ID), curator_group);
  33. let curator_group_curator_removed_event = get_test_event(RawEvent::CuratorRemoved(
  34. FIRST_CURATOR_GROUP_ID,
  35. FIRST_CURATOR_ID,
  36. ));
  37. // Event checked
  38. assert_event(
  39. curator_group_curator_removed_event,
  40. number_of_events_before_call + 1,
  41. );
  42. })
  43. }
  44. #[test]
  45. fn remove_curator_from_group_lead_auth_failed() {
  46. with_test_externalities(|| {
  47. // Add curator group
  48. assert_ok!(add_curator_group(LEAD_ORIGIN));
  49. // Add curator to group
  50. assert_ok!(add_curator_to_group(
  51. LEAD_ORIGIN,
  52. FIRST_CURATOR_GROUP_ID,
  53. FIRST_CURATOR_ID
  54. ));
  55. // Runtime tested state before call
  56. // Events number before tested call
  57. let number_of_events_before_call = System::events().len();
  58. // Make an attempt to remove curator from group using non lead origin
  59. let remove_curator_from_group_result = remove_curator_from_group(
  60. FIRST_MEMBER_ORIGIN,
  61. FIRST_CURATOR_GROUP_ID,
  62. FIRST_CURATOR_ID,
  63. );
  64. // Failure checked
  65. assert_failure(
  66. remove_curator_from_group_result,
  67. Error::<Runtime>::LeadAuthFailed,
  68. number_of_events_before_call,
  69. );
  70. })
  71. }
  72. #[test]
  73. fn remove_curator_from_group_curator_is_not_a_member() {
  74. with_test_externalities(|| {
  75. // Add curator group
  76. assert_ok!(add_curator_group(LEAD_ORIGIN));
  77. // Runtime tested state before call
  78. // Events number before tested call
  79. let number_of_events_before_call = System::events().len();
  80. // Make an attempt to remove curator that does not added to the provided curator group
  81. let remove_curator_from_group_result =
  82. remove_curator_from_group(LEAD_ORIGIN, FIRST_CURATOR_GROUP_ID, UNKNOWN_CURATOR_ID);
  83. // Failure checked
  84. assert_failure(
  85. remove_curator_from_group_result,
  86. Error::<Runtime>::CuratorIsNotAMemberOfGivenCuratorGroup,
  87. number_of_events_before_call,
  88. );
  89. })
  90. }
  91. #[test]
  92. fn remove_curator_from_non_existent_group() {
  93. with_test_externalities(|| {
  94. // Runtime tested state before call
  95. // Events number before tested call
  96. let number_of_events_before_call = System::events().len();
  97. // Make an attempt to remove curator from group using non lead origin
  98. let remove_curator_from_group_result =
  99. remove_curator_from_group(LEAD_ORIGIN, UNKNOWN_CURATOR_GROUP_ID, FIRST_CURATOR_ID);
  100. // Failure checked
  101. assert_failure(
  102. remove_curator_from_group_result,
  103. Error::<Runtime>::CuratorGroupDoesNotExist,
  104. number_of_events_before_call,
  105. );
  106. })
  107. }