Browse Source

Merge branch 'quote-patch' of github.com:mnaamani/substrate-runtime-joystream into quote-patch

Mokhtar Naamani 5 years ago
parent
commit
ec9dc53e41

+ 0 - 2
src/content_working_group/genesis.rs

@@ -34,7 +34,6 @@ pub struct GenesisConfigBuilder<T: Trait> {
     channel_creation_enabled: bool,
     channel_handle_constraint: InputValidationLengthConstraint,
     channel_description_constraint: InputValidationLengthConstraint,
-    opening_human_readble_text: InputValidationLengthConstraint,
     curator_application_human_readable_text: InputValidationLengthConstraint,
     curator_exit_rationale_text: InputValidationLengthConstraint,
     channel_title_constraint: InputValidationLengthConstraint,
@@ -124,7 +123,6 @@ impl<T: Trait> Default for GenesisConfigBuilder<T> {
             channel_creation_enabled: true,
             channel_handle_constraint: default_constraint.clone(),
             channel_description_constraint: default_constraint.clone(),
-            opening_human_readble_text: default_constraint.clone(),
             curator_application_human_readable_text: default_constraint.clone(),
             curator_exit_rationale_text: default_constraint.clone(),
             channel_title_constraint: default_constraint.clone(),

+ 19 - 8
src/content_working_group/lib.rs

@@ -15,7 +15,7 @@ use rstd::collections::btree_set::BTreeSet;
 use rstd::convert::From;
 use rstd::prelude::*;
 use sr_primitives::traits::{One, Zero}; // Member, SimpleArithmetic, MaybeSerialize
-use srml_support::traits::{Currency, ExistenceRequirement, Get, WithdrawReasons};
+use srml_support::traits::{Currency, ExistenceRequirement, WithdrawReasons};
 use srml_support::{
     decl_event,
     decl_module,
@@ -1210,8 +1210,12 @@ decl_module! {
             // Ensure channel owner has signed
             let channel = Self::ensure_channel_owner_signed(origin, &channel_id)?;
 
-            // Ensure prospective new owner can actually become a channel owner
-            let (new_owner_as_channel_owner, _next_channel_id) = Self::ensure_can_register_channel_owner_role_on_member(&new_owner, Some(channel_id))?;
+            // Ensure prospective new owner can actually become a channel owner (with a new channel id)
+            // We do not pass the existing channel id because it is already owned and the call would
+            // return with Err, since the membership system doesn't allow the same ActorInRole to be assigned
+            // to more than one member, and we don't use the returned actor_in_role because its not
+            // for the channel being transferred.
+            Self::ensure_can_register_channel_owner_role_on_member(&new_owner, None)?;
 
             //
             // == MUTATION SAFE ==
@@ -1227,16 +1231,23 @@ decl_module! {
             // Overwrite entry in ChannelById
             ChannelById::<T>::insert(channel_id, new_channel);
 
+            let role = role_types::ActorInRole::new(
+                role_types::Role::ChannelOwner,
+                channel_id
+            );
+
             // Remove
-            let unregistered_role = <members::Module<T>>::unregister_role(role_types::ActorInRole::new(role_types::Role::ChannelOwner, channel_id)).is_ok();
+            let unregistered_role = <members::Module<T>>::unregister_role(
+                role
+            ).is_ok();
 
             assert!(unregistered_role);
 
-            // Dial out to membership module and inform about new role as channe owner.
+            // Dial out to membership module and inform about new role as channel owner.
             let registered_role = <members::Module<T>>::register_role_on_member(
                 new_owner,
-                &new_owner_as_channel_owner)
-                .is_ok();
+                &role
+            ).is_ok();
 
             assert!(registered_role);
 
@@ -2118,7 +2129,7 @@ impl<T: Trait> Module<T> {
     ) -> Result<
         (
             members::ActorInRole<ActorIdInMembersModule<T>>,
-            CuratorId<T>,
+            ChannelId<T>,
         ),
         &'static str,
     > {

+ 53 - 2
src/content_working_group/tests.rs

@@ -171,7 +171,57 @@ fn create_channel_description_too_short() {
 }
 
 #[test]
-fn transfer_channel_ownership_success() {}
+fn transfer_channel_ownership_success() {
+    TestExternalitiesBuilder::<Test>::default()
+        .build()
+        .execute_with(|| {
+            // Add channel creator as member
+            let channel_creator_member_root_and_controller_account_1 = 1111;
+            let channel_creator_member_root_and_controller_account_2 = 2222;
+
+            let channel_creator_member_id_1 = add_member(
+                channel_creator_member_root_and_controller_account_1,
+                to_vec(CHANNEL_CREATOR_HANDLE),
+            );
+
+            let channel_creator_member_id_2 = add_member(
+                channel_creator_member_root_and_controller_account_2,
+                to_vec(CHANNEL_CREATOR_HANDLE2),
+            );
+
+            let create_channel_fixture =
+                CreateChannelFixture::make_valid_unpulished_video_channel_for(
+                    channel_creator_member_id_1,
+                    None,
+                );
+
+            let channel_id = create_channel_fixture.call_and_assert_success();
+
+            let original_channel = ChannelById::<Test>::get(channel_id);
+
+            let new_role_account = 3333;
+
+            let transfer_result = ContentWorkingGroup::transfer_channel_ownership(
+                Origin::signed(create_channel_fixture.channel_creator_role_account),
+                channel_id,
+                channel_creator_member_id_2,
+                new_role_account,
+            );
+
+            assert_ok!(transfer_result);
+
+            let updated_channel = ChannelById::<Test>::get(channel_id);
+
+            assert_eq!(
+                updated_channel,
+                Channel {
+                    owner: channel_creator_member_id_2,
+                    role_account: new_role_account,
+                    ..original_channel
+                }
+            );
+        });
+}
 
 #[test]
 fn update_channel_as_owner_success() {}
@@ -1354,7 +1404,8 @@ static LEAD_ROOT_AND_CONTROLLER_ACCOUNT: <Test as system::Trait>::AccountId = 12
 static LEAD_ROLE_ACCOUNT: <Test as system::Trait>::AccountId = 1289;
 static LEAD_MEMBER_HANDLE: &str = "IamTheLead";
 static CHANNEL_CREATOR_ROOT_AND_CONTROLLER_ACCOUNT: <Test as system::Trait>::AccountId = 11;
-static CHANNEL_CREATOR_HANDLE: &str = "Coolcreator";
+static CHANNEL_CREATOR_HANDLE: &str = "Coolcreator1";
+static CHANNEL_CREATOR_HANDLE2: &str = "Coolcreator2";
 
 fn make_generic_add_member_params() -> AddMemberAndApplyOnOpeningParams {
     AddMemberAndApplyOnOpeningParams::new(

+ 1 - 1
src/governance/election.rs

@@ -84,7 +84,7 @@ pub struct TransferableStake<Balance> {
 }
 
 // can we use a type alias to overcome name clashes of public types with other modules?
-pub type ElectionStake<T: Trait> = Stake<BalanceOf<T>>;
+pub type ElectionStake<T> = Stake<BalanceOf<T>>;
 
 decl_storage! {
     trait Store for Module<T: Trait> as CouncilElection {

+ 2 - 0
src/membership/members.rs

@@ -709,6 +709,8 @@ impl<T: Trait> Module<T> {
 
         assert!(profile.roles.unregister_role(&actor_in_role));
 
+        <MembershipIdByActorInRole<T>>::remove(actor_in_role);
+
         <MemberProfile<T>>::insert(member_id, profile);
 
         Self::deposit_event(RawEvent::MemberUnregisteredRole(member_id, actor_in_role));