|
@@ -1,811 +1,1491 @@
|
|
|
#![cfg(test)]
|
|
|
|
|
|
use super::curators;
|
|
|
+use super::fixtures::*;
|
|
|
use super::mock::*;
|
|
|
use crate::*;
|
|
|
-use frame_support::traits::Currency;
|
|
|
use frame_support::{assert_err, assert_ok};
|
|
|
|
|
|
#[test]
|
|
|
-fn successful_channel_deletion() {
|
|
|
+fn channel_censoring() {
|
|
|
with_default_mock_builder(|| {
|
|
|
// Run to block one to see emitted events
|
|
|
run_to_block(1);
|
|
|
|
|
|
- create_initial_storage_buckets();
|
|
|
-
|
|
|
- // create an account with enought balance
|
|
|
- let _ = balances::Module::<Test>::deposit_creating(
|
|
|
- &FIRST_MEMBER_ORIGIN,
|
|
|
- <Test as balances::Trait>::Balance::from(INITIAL_BALANCE),
|
|
|
- );
|
|
|
-
|
|
|
- // 3 assets added at creation
|
|
|
- let assets = StorageAssetsRecord {
|
|
|
- object_creation_list: vec![
|
|
|
- DataObjectCreationParameters {
|
|
|
- size: 3,
|
|
|
- ipfs_content_id: b"first".to_vec(),
|
|
|
- },
|
|
|
- DataObjectCreationParameters {
|
|
|
- size: 3,
|
|
|
- ipfs_content_id: b"second".to_vec(),
|
|
|
- },
|
|
|
- DataObjectCreationParameters {
|
|
|
- size: 3,
|
|
|
- ipfs_content_id: b"third".to_vec(),
|
|
|
- },
|
|
|
- ],
|
|
|
- expected_data_size_fee: storage::DataObjectPerMegabyteFee::<Test>::get(),
|
|
|
- };
|
|
|
- let channel_id = NextChannelId::<Test>::get();
|
|
|
-
|
|
|
- // create channel
|
|
|
- create_channel_mock(
|
|
|
- FIRST_MEMBER_ORIGIN,
|
|
|
- ContentActor::Member(FIRST_MEMBER_ID),
|
|
|
+ let channel_id = Content::next_channel_id();
|
|
|
+ assert_ok!(Content::create_channel(
|
|
|
+ Origin::signed(DEFAULT_MEMBER_ACCOUNT_ID),
|
|
|
+ ContentActor::Member(DEFAULT_MEMBER_ID),
|
|
|
ChannelCreationParametersRecord {
|
|
|
- assets: Some(assets),
|
|
|
+ assets: None,
|
|
|
meta: None,
|
|
|
reward_account: None,
|
|
|
collaborators: BTreeSet::new(),
|
|
|
- },
|
|
|
- Ok(()),
|
|
|
- );
|
|
|
+ }
|
|
|
+ ));
|
|
|
|
|
|
- // attempt to delete channel with non zero assets should result in error: objects
|
|
|
- // are misspecified
|
|
|
- delete_channel_mock(
|
|
|
- FIRST_MEMBER_ORIGIN,
|
|
|
- ContentActor::Member(FIRST_MEMBER_ID),
|
|
|
+ let group_id = curators::add_curator_to_new_group(DEFAULT_CURATOR_ID);
|
|
|
+
|
|
|
+ // Curator can censor channels
|
|
|
+ let is_censored = true;
|
|
|
+ assert_ok!(Content::update_channel_censorship_status(
|
|
|
+ Origin::signed(DEFAULT_CURATOR_ACCOUNT_ID),
|
|
|
+ ContentActor::Curator(group_id, DEFAULT_CURATOR_ID),
|
|
|
channel_id,
|
|
|
- 2u64,
|
|
|
- Err(Error::<Test>::InvalidBagSizeSpecified.into()),
|
|
|
+ is_censored,
|
|
|
+ vec![]
|
|
|
+ ));
|
|
|
+
|
|
|
+ assert_eq!(
|
|
|
+ System::events().last().unwrap().event,
|
|
|
+ MetaEvent::content(RawEvent::ChannelCensorshipStatusUpdated(
|
|
|
+ ContentActor::Curator(group_id, DEFAULT_CURATOR_ID),
|
|
|
+ channel_id,
|
|
|
+ is_censored,
|
|
|
+ vec![]
|
|
|
+ ))
|
|
|
);
|
|
|
|
|
|
- // successful deletion because we empty the bag first
|
|
|
- delete_channel_mock(
|
|
|
- FIRST_MEMBER_ORIGIN,
|
|
|
- ContentActor::Member(FIRST_MEMBER_ID),
|
|
|
+ let channel = Content::channel_by_id(channel_id);
|
|
|
+
|
|
|
+ assert!(channel.is_censored);
|
|
|
+
|
|
|
+ // Curator can un-censor channels
|
|
|
+ let is_censored = false;
|
|
|
+ assert_ok!(Content::update_channel_censorship_status(
|
|
|
+ Origin::signed(DEFAULT_CURATOR_ACCOUNT_ID),
|
|
|
+ ContentActor::Curator(group_id, DEFAULT_CURATOR_ID),
|
|
|
channel_id,
|
|
|
- 3u64, // now assets are 0
|
|
|
- Ok(()),
|
|
|
+ is_censored,
|
|
|
+ vec![]
|
|
|
+ ));
|
|
|
+
|
|
|
+ assert_eq!(
|
|
|
+ System::events().last().unwrap().event,
|
|
|
+ MetaEvent::content(RawEvent::ChannelCensorshipStatusUpdated(
|
|
|
+ ContentActor::Curator(group_id, DEFAULT_CURATOR_ID),
|
|
|
+ channel_id,
|
|
|
+ is_censored,
|
|
|
+ vec![]
|
|
|
+ ))
|
|
|
);
|
|
|
|
|
|
- // create a channel with no assets:
|
|
|
- let empty_channel_id = Content::next_channel_id();
|
|
|
- create_channel_mock(
|
|
|
- FIRST_MEMBER_ORIGIN,
|
|
|
- ContentActor::Member(FIRST_MEMBER_ID),
|
|
|
+ let channel = Content::channel_by_id(channel_id);
|
|
|
+
|
|
|
+ assert!(!channel.is_censored);
|
|
|
+
|
|
|
+ // Member cannot censor channels
|
|
|
+ let is_censored = true;
|
|
|
+ assert_err!(
|
|
|
+ Content::update_channel_censorship_status(
|
|
|
+ Origin::signed(DEFAULT_MEMBER_ACCOUNT_ID),
|
|
|
+ ContentActor::Member(DEFAULT_MEMBER_ID),
|
|
|
+ channel_id,
|
|
|
+ is_censored,
|
|
|
+ vec![]
|
|
|
+ ),
|
|
|
+ Error::<Test>::ActorNotAuthorized
|
|
|
+ );
|
|
|
+
|
|
|
+ let curator_channel_id = Content::next_channel_id();
|
|
|
+
|
|
|
+ // create curator channel
|
|
|
+ assert_ok!(Content::create_channel(
|
|
|
+ Origin::signed(DEFAULT_CURATOR_ACCOUNT_ID),
|
|
|
+ ContentActor::Curator(group_id, DEFAULT_CURATOR_ID),
|
|
|
ChannelCreationParametersRecord {
|
|
|
assets: None,
|
|
|
meta: None,
|
|
|
reward_account: None,
|
|
|
collaborators: BTreeSet::new(),
|
|
|
- },
|
|
|
- Ok(()),
|
|
|
+ }
|
|
|
+ ));
|
|
|
+
|
|
|
+ // Curator cannot censor curator group channels
|
|
|
+ assert_err!(
|
|
|
+ Content::update_channel_censorship_status(
|
|
|
+ Origin::signed(DEFAULT_CURATOR_ACCOUNT_ID),
|
|
|
+ ContentActor::Curator(group_id, DEFAULT_CURATOR_ID),
|
|
|
+ curator_channel_id,
|
|
|
+ is_censored,
|
|
|
+ vec![]
|
|
|
+ ),
|
|
|
+ Error::<Test>::CannotCensoreCuratorGroupOwnedChannels
|
|
|
);
|
|
|
|
|
|
- delete_channel_mock(
|
|
|
- FIRST_MEMBER_ORIGIN,
|
|
|
- ContentActor::Member(FIRST_MEMBER_ID),
|
|
|
- empty_channel_id,
|
|
|
- 0u64,
|
|
|
- Ok(()),
|
|
|
+ // Lead can still censor curator group channels
|
|
|
+ assert_ok!(Content::update_channel_censorship_status(
|
|
|
+ Origin::signed(LEAD_ACCOUNT_ID),
|
|
|
+ ContentActor::Lead,
|
|
|
+ curator_channel_id,
|
|
|
+ is_censored,
|
|
|
+ vec![]
|
|
|
+ ));
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+// channel creation tests
|
|
|
+#[test]
|
|
|
+fn successful_channel_creation_with_member_context() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+ CreateChannelFixture::default()
|
|
|
+ .with_sender(DEFAULT_MEMBER_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Member(DEFAULT_MEMBER_ID))
|
|
|
+ .call_and_assert(Ok(()));
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn successful_channel_creation_with_curator_context() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+ let default_curator_group_id = curators::add_curator_to_new_group(DEFAULT_CURATOR_ID);
|
|
|
+ CreateChannelFixture::default()
|
|
|
+ .with_sender(DEFAULT_CURATOR_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Curator(
|
|
|
+ default_curator_group_id,
|
|
|
+ DEFAULT_CURATOR_ID,
|
|
|
+ ))
|
|
|
+ .call_and_assert(Ok(()));
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn unsuccessful_channel_creation_with_lead_context() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+ CreateChannelFixture::default()
|
|
|
+ .with_sender(LEAD_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Lead)
|
|
|
+ .call_and_assert(Err(Error::<Test>::ActorCannotOwnChannel.into()));
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn unsuccessful_channel_creation_with_collaborator_context() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+ CreateChannelFixture::default()
|
|
|
+ .with_sender(COLLABORATOR_MEMBER_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Collaborator(COLLABORATOR_MEMBER_ID))
|
|
|
+ .call_and_assert(Err(Error::<Test>::ActorCannotOwnChannel.into()));
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn unsuccessful_channel_creation_with_uncorresponding_member_id_and_origin() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+ CreateChannelFixture::default()
|
|
|
+ .with_sender(DEFAULT_MEMBER_ACCOUNT_ID + 100)
|
|
|
+ .with_actor(ContentActor::Member(DEFAULT_MEMBER_ID))
|
|
|
+ .call_and_assert(Err(Error::<Test>::MemberAuthFailed.into()));
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn unsuccessful_channel_creation_with_uncorresponding_curator_id_and_origin() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+ let default_curator_group_id = curators::add_curator_to_new_group(DEFAULT_CURATOR_ID);
|
|
|
+ CreateChannelFixture::default()
|
|
|
+ .with_sender(DEFAULT_CURATOR_ACCOUNT_ID + 100)
|
|
|
+ .with_actor(ContentActor::Curator(
|
|
|
+ default_curator_group_id,
|
|
|
+ DEFAULT_CURATOR_ID,
|
|
|
+ ))
|
|
|
+ .call_and_assert(Err(Error::<Test>::CuratorAuthFailed.into()));
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn successful_channel_creation_with_storage_upload_and_member_context() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ CreateChannelFixture::default()
|
|
|
+ .with_sender(DEFAULT_MEMBER_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Member(DEFAULT_MEMBER_ID))
|
|
|
+ .with_assets(StorageAssets::<Test> {
|
|
|
+ expected_data_size_fee: Storage::<Test>::data_object_per_mega_byte_fee(),
|
|
|
+ object_creation_list: create_data_objects_helper(),
|
|
|
+ })
|
|
|
+ .call_and_assert(Ok(()));
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn successful_channel_creation_with_storage_upload_and_curator_context() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_CURATOR_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ let default_curator_group_id = curators::add_curator_to_new_group(DEFAULT_CURATOR_ID);
|
|
|
+ CreateChannelFixture::default()
|
|
|
+ .with_sender(DEFAULT_CURATOR_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Curator(
|
|
|
+ default_curator_group_id,
|
|
|
+ DEFAULT_CURATOR_ID,
|
|
|
+ ))
|
|
|
+ .with_assets(StorageAssets::<Test> {
|
|
|
+ expected_data_size_fee: Storage::<Test>::data_object_per_mega_byte_fee(),
|
|
|
+ object_creation_list: create_data_objects_helper(),
|
|
|
+ })
|
|
|
+ .call_and_assert(Ok(()));
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn unsuccessful_channel_creation_with_invalid_expected_data_size_fee() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_CURATOR_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ let default_curator_group_id = curators::add_curator_to_new_group(DEFAULT_CURATOR_ID);
|
|
|
+ CreateChannelFixture::default()
|
|
|
+ .with_sender(DEFAULT_CURATOR_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Curator(
|
|
|
+ default_curator_group_id,
|
|
|
+ DEFAULT_CURATOR_ID,
|
|
|
+ ))
|
|
|
+ .with_assets(StorageAssets::<Test> {
|
|
|
+ // setting a purposely high fee to trigger error
|
|
|
+ expected_data_size_fee: BalanceOf::<Test>::from(1_000_000u64),
|
|
|
+ object_creation_list: create_data_objects_helper(),
|
|
|
+ })
|
|
|
+ .call_and_assert(Err(storage::Error::<Test>::DataSizeFeeChanged.into()));
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn unsuccessful_channel_creation_with_insufficient_balance() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ CreateChannelFixture::default()
|
|
|
+ .with_sender(DEFAULT_MEMBER_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Member(DEFAULT_MEMBER_ID))
|
|
|
+ .with_assets(StorageAssets::<Test> {
|
|
|
+ expected_data_size_fee: Storage::<Test>::data_object_per_mega_byte_fee(),
|
|
|
+ object_creation_list: create_data_objects_helper(),
|
|
|
+ })
|
|
|
+ .call_and_assert(Err(storage::Error::<Test>::InsufficientBalance.into()));
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn unsuccessful_channel_creation_with_no_bucket_available() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+
|
|
|
+ CreateChannelFixture::default()
|
|
|
+ .with_sender(DEFAULT_MEMBER_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Member(DEFAULT_MEMBER_ID))
|
|
|
+ .with_assets(StorageAssets::<Test> {
|
|
|
+ expected_data_size_fee: Storage::<Test>::data_object_per_mega_byte_fee(),
|
|
|
+ object_creation_list: vec![DataObjectCreationParameters {
|
|
|
+ size: STORAGE_BUCKET_OBJECTS_SIZE_LIMIT + 1,
|
|
|
+ ipfs_content_id: vec![1u8],
|
|
|
+ }],
|
|
|
+ })
|
|
|
+ .call_and_assert(Err(
|
|
|
+ storage::Error::<Test>::StorageBucketIdCollectionsAreEmpty.into(),
|
|
|
+ ));
|
|
|
+
|
|
|
+ CreateChannelFixture::default()
|
|
|
+ .with_sender(DEFAULT_MEMBER_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Member(DEFAULT_MEMBER_ID))
|
|
|
+ .with_assets(StorageAssets::<Test> {
|
|
|
+ expected_data_size_fee: Storage::<Test>::data_object_per_mega_byte_fee(),
|
|
|
+ object_creation_list: (0..(STORAGE_BUCKET_OBJECTS_NUMBER_LIMIT + 1))
|
|
|
+ .map(|_| DataObjectCreationParameters {
|
|
|
+ size: 1,
|
|
|
+ ipfs_content_id: vec![1u8],
|
|
|
+ })
|
|
|
+ .collect(),
|
|
|
+ })
|
|
|
+ .call_and_assert(Err(
|
|
|
+ storage::Error::<Test>::StorageBucketIdCollectionsAreEmpty.into(),
|
|
|
+ ));
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn unsuccessful_channel_creation_with_data_limits_exceeded() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ CreateChannelFixture::default()
|
|
|
+ .with_sender(DEFAULT_MEMBER_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Member(DEFAULT_MEMBER_ID))
|
|
|
+ .with_assets(StorageAssets::<Test> {
|
|
|
+ expected_data_size_fee: Storage::<Test>::data_object_per_mega_byte_fee(),
|
|
|
+ object_creation_list: vec![DataObjectCreationParameters {
|
|
|
+ size: VOUCHER_OBJECTS_SIZE_LIMIT + 1,
|
|
|
+ ipfs_content_id: vec![1u8],
|
|
|
+ }],
|
|
|
+ })
|
|
|
+ .call_and_assert(Err(storage::Error::<Test>::MaxDataObjectSizeExceeded.into()));
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn successful_channel_creation_with_collaborators_set() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+
|
|
|
+ CreateChannelFixture::default()
|
|
|
+ .with_sender(DEFAULT_MEMBER_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Member(DEFAULT_MEMBER_ID))
|
|
|
+ .with_collaborators(vec![COLLABORATOR_MEMBER_ID].into_iter().collect())
|
|
|
+ .call_and_assert(Ok(()));
|
|
|
+
|
|
|
+ let default_curator_group_id = curators::add_curator_to_new_group(DEFAULT_CURATOR_ID);
|
|
|
+ CreateChannelFixture::default()
|
|
|
+ .with_sender(DEFAULT_CURATOR_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Curator(
|
|
|
+ default_curator_group_id,
|
|
|
+ DEFAULT_CURATOR_ID,
|
|
|
+ ))
|
|
|
+ .with_collaborators(vec![COLLABORATOR_MEMBER_ID].into_iter().collect())
|
|
|
+ .call_and_assert(Ok(()));
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn unsuccessful_channel_creation_with_invalid_collaborators_set() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+ CreateChannelFixture::default()
|
|
|
+ .with_sender(DEFAULT_MEMBER_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Member(DEFAULT_MEMBER_ID))
|
|
|
+ .with_collaborators(vec![COLLABORATOR_MEMBER_ID + 100].into_iter().collect())
|
|
|
+ .call_and_assert(Err(Error::<Test>::CollaboratorIsNotValidMember.into()));
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn successful_channel_creation_with_reward_account() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+
|
|
|
+ CreateChannelFixture::default()
|
|
|
+ .with_sender(DEFAULT_MEMBER_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Member(DEFAULT_MEMBER_ID))
|
|
|
+ .with_reward_account(DEFAULT_MEMBER_ACCOUNT_ID)
|
|
|
+ .call_and_assert(Ok(()));
|
|
|
+
|
|
|
+ let default_curator_group_id = curators::add_curator_to_new_group(DEFAULT_CURATOR_ID);
|
|
|
+ CreateChannelFixture::default()
|
|
|
+ .with_sender(DEFAULT_CURATOR_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Curator(
|
|
|
+ default_curator_group_id,
|
|
|
+ DEFAULT_CURATOR_ID,
|
|
|
+ ))
|
|
|
+ .with_reward_account(DEFAULT_CURATOR_ACCOUNT_ID)
|
|
|
+ .call_and_assert(Ok(()));
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+// channel update tests
|
|
|
+#[test]
|
|
|
+fn unsuccessful_channel_update_with_uncorresponding_member_id_and_origin() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_member_owned_channel();
|
|
|
+
|
|
|
+ UpdateChannelFixture::default()
|
|
|
+ .with_sender(DEFAULT_MEMBER_ACCOUNT_ID + 100)
|
|
|
+ .with_actor(ContentActor::Member(DEFAULT_MEMBER_ID))
|
|
|
+ .call_and_assert(Err(Error::<Test>::MemberAuthFailed.into()));
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn unsuccessful_channel_update_with_uncorresponding_curator_id_and_origin() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_CURATOR_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_curator_owned_channel();
|
|
|
+
|
|
|
+ let default_curator_group_id = curators::add_curator_to_new_group(DEFAULT_CURATOR_ID);
|
|
|
+ UpdateChannelFixture::default()
|
|
|
+ .with_sender(DEFAULT_CURATOR_ACCOUNT_ID + 100)
|
|
|
+ .with_actor(ContentActor::Curator(
|
|
|
+ default_curator_group_id,
|
|
|
+ DEFAULT_CURATOR_ID,
|
|
|
+ ))
|
|
|
+ .call_and_assert(Err(Error::<Test>::CuratorAuthFailed.into()));
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn unsuccessful_channel_update_with_uncorresponding_collaborator_id_and_origin() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_member_owned_channel();
|
|
|
+
|
|
|
+ UpdateChannelFixture::default()
|
|
|
+ .with_sender(COLLABORATOR_MEMBER_ACCOUNT_ID + 100)
|
|
|
+ .with_actor(ContentActor::Collaborator(COLLABORATOR_MEMBER_ID))
|
|
|
+ .call_and_assert(Err(Error::<Test>::MemberAuthFailed.into()));
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn unsuccessful_channel_update_with_invalid_channel_id() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_member_owned_channel();
|
|
|
+
|
|
|
+ UpdateChannelFixture::default()
|
|
|
+ .with_sender(DEFAULT_MEMBER_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Member(DEFAULT_MEMBER_ID))
|
|
|
+ .with_channel_id(ChannelId::zero())
|
|
|
+ .call_and_assert(Err(Error::<Test>::ChannelDoesNotExist.into()));
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn successful_channel_update_with_assets_uploaded_by_collaborator() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ increase_account_balance_helper(COLLABORATOR_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_member_owned_channel();
|
|
|
+
|
|
|
+ UpdateChannelFixture::default()
|
|
|
+ .with_sender(COLLABORATOR_MEMBER_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Collaborator(COLLABORATOR_MEMBER_ID))
|
|
|
+ .with_assets_to_upload(StorageAssets::<Test> {
|
|
|
+ expected_data_size_fee: Storage::<Test>::data_object_per_mega_byte_fee(),
|
|
|
+ object_creation_list: create_data_objects_helper(),
|
|
|
+ })
|
|
|
+ .call_and_assert(Ok(()));
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn successful_channel_update_with_assets_removed_by_collaborator() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_member_owned_channel();
|
|
|
+
|
|
|
+ UpdateChannelFixture::default()
|
|
|
+ .with_sender(COLLABORATOR_MEMBER_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Collaborator(COLLABORATOR_MEMBER_ID))
|
|
|
+ // data objects ids start at index 1
|
|
|
+ .with_assets_to_remove((1..(DATA_OBJECTS_NUMBER as u64 - 1)).collect())
|
|
|
+ .call_and_assert(Ok(()));
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn successful_channel_update_with_assets_uploaded_by_member() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_member_owned_channel();
|
|
|
+
|
|
|
+ UpdateChannelFixture::default()
|
|
|
+ .with_sender(DEFAULT_MEMBER_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Member(DEFAULT_MEMBER_ID))
|
|
|
+ .with_assets_to_upload(StorageAssets::<Test> {
|
|
|
+ expected_data_size_fee: Storage::<Test>::data_object_per_mega_byte_fee(),
|
|
|
+ object_creation_list: create_data_objects_helper(),
|
|
|
+ })
|
|
|
+ .call_and_assert(Ok(()));
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn successful_channel_update_with_assets_removed_by_member() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_member_owned_channel();
|
|
|
+
|
|
|
+ UpdateChannelFixture::default()
|
|
|
+ .with_sender(DEFAULT_MEMBER_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Member(DEFAULT_MEMBER_ID))
|
|
|
+ // data objects ids start at index 1
|
|
|
+ .with_assets_to_remove((1..(DATA_OBJECTS_NUMBER as u64 - 1)).collect())
|
|
|
+ .call_and_assert(Ok(()));
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn successful_channel_update_with_assets_uploaded_by_curator() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_CURATOR_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_curator_owned_channel();
|
|
|
+
|
|
|
+ let default_curator_group_id = NextCuratorGroupId::<Test>::get() - 1;
|
|
|
+ UpdateChannelFixture::default()
|
|
|
+ .with_sender(DEFAULT_CURATOR_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Curator(
|
|
|
+ default_curator_group_id,
|
|
|
+ DEFAULT_CURATOR_ID,
|
|
|
+ ))
|
|
|
+ .with_assets_to_upload(StorageAssets::<Test> {
|
|
|
+ expected_data_size_fee: Storage::<Test>::data_object_per_mega_byte_fee(),
|
|
|
+ object_creation_list: create_data_objects_helper(),
|
|
|
+ })
|
|
|
+ .call_and_assert(Ok(()));
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn successful_channel_update_with_assets_removed_by_curator() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_CURATOR_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_curator_owned_channel();
|
|
|
+
|
|
|
+ let default_curator_group_id = NextCuratorGroupId::<Test>::get() - 1;
|
|
|
+ UpdateChannelFixture::default()
|
|
|
+ .with_sender(DEFAULT_CURATOR_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Curator(
|
|
|
+ default_curator_group_id,
|
|
|
+ DEFAULT_CURATOR_ID,
|
|
|
+ ))
|
|
|
+ // data objects ids start at index 1
|
|
|
+ .with_assets_to_remove((1..(DATA_OBJECTS_NUMBER as u64 - 1)).collect())
|
|
|
+ .call_and_assert(Ok(()));
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn successful_curator_channel_update_with_assets_uploaded_by_lead() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_CURATOR_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ increase_account_balance_helper(LEAD_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_curator_owned_channel();
|
|
|
+
|
|
|
+ UpdateChannelFixture::default()
|
|
|
+ .with_sender(LEAD_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Lead)
|
|
|
+ .with_assets_to_upload(StorageAssets::<Test> {
|
|
|
+ expected_data_size_fee: Storage::<Test>::data_object_per_mega_byte_fee(),
|
|
|
+ object_creation_list: create_data_objects_helper(),
|
|
|
+ })
|
|
|
+ .call_and_assert(Ok(()));
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn unsuccessful_curator_channel_update_with_assets_uploaded_by_invalid_lead_origin() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_CURATOR_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ increase_account_balance_helper(LEAD_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_curator_owned_channel();
|
|
|
+
|
|
|
+ UpdateChannelFixture::default()
|
|
|
+ .with_sender(LEAD_ACCOUNT_ID + 100)
|
|
|
+ .with_actor(ContentActor::Lead)
|
|
|
+ .with_assets_to_upload(StorageAssets::<Test> {
|
|
|
+ expected_data_size_fee: Storage::<Test>::data_object_per_mega_byte_fee(),
|
|
|
+ object_creation_list: create_data_objects_helper(),
|
|
|
+ })
|
|
|
+ .call_and_assert(Err(Error::<Test>::LeadAuthFailed.into()));
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn successful_channel_update_with_assets_removed_by_lead() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_CURATOR_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_curator_owned_channel();
|
|
|
+
|
|
|
+ UpdateChannelFixture::default()
|
|
|
+ .with_sender(LEAD_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Lead)
|
|
|
+ // data objects ids start at index 1
|
|
|
+ .with_assets_to_remove((1..(DATA_OBJECTS_NUMBER as u64 - 1)).collect())
|
|
|
+ .call_and_assert(Ok(()));
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn unsuccessful_channel_update_with_assets_removed_by_invalid_lead_origin() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_CURATOR_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_curator_owned_channel();
|
|
|
+
|
|
|
+ UpdateChannelFixture::default()
|
|
|
+ .with_sender(LEAD_ACCOUNT_ID + 100)
|
|
|
+ .with_actor(ContentActor::Lead)
|
|
|
+ // data objects ids start at index 1
|
|
|
+ .with_assets_to_remove((1..(DATA_OBJECTS_NUMBER as u64 - 1)).collect())
|
|
|
+ .call_and_assert(Err(Error::<Test>::LeadAuthFailed.into()));
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn unsuccessful_channel_update_with_assets_uploaded_by_unauthorized_collaborator() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ increase_account_balance_helper(
|
|
|
+ UNAUTHORIZED_COLLABORATOR_MEMBER_ACCOUNT_ID,
|
|
|
+ INITIAL_BALANCE,
|
|
|
);
|
|
|
+ create_default_member_owned_channel();
|
|
|
+
|
|
|
+ UpdateChannelFixture::default()
|
|
|
+ .with_sender(UNAUTHORIZED_COLLABORATOR_MEMBER_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Collaborator(
|
|
|
+ UNAUTHORIZED_COLLABORATOR_MEMBER_ID,
|
|
|
+ ))
|
|
|
+ .with_assets_to_upload(StorageAssets::<Test> {
|
|
|
+ expected_data_size_fee: Storage::<Test>::data_object_per_mega_byte_fee(),
|
|
|
+ object_creation_list: create_data_objects_helper(),
|
|
|
+ })
|
|
|
+ .call_and_assert(Err(Error::<Test>::ActorNotAuthorized.into()));
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn unsuccessful_channel_update_with_assets_removed_by_unauthorized_collaborator() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_member_owned_channel();
|
|
|
+
|
|
|
+ UpdateChannelFixture::default()
|
|
|
+ .with_sender(UNAUTHORIZED_COLLABORATOR_MEMBER_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Collaborator(
|
|
|
+ UNAUTHORIZED_COLLABORATOR_MEMBER_ID,
|
|
|
+ ))
|
|
|
+ // data objects ids start at index 1
|
|
|
+ .with_assets_to_remove((1..(DATA_OBJECTS_NUMBER as u64 - 1)).collect())
|
|
|
+ .call_and_assert(Err(Error::<Test>::ActorNotAuthorized.into()));
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn unsuccessful_channel_update_with_assets_uploaded_by_unauthorized_member() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ increase_account_balance_helper(UNAUTHORIZED_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_member_owned_channel();
|
|
|
+
|
|
|
+ UpdateChannelFixture::default()
|
|
|
+ .with_sender(UNAUTHORIZED_MEMBER_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Member(UNAUTHORIZED_MEMBER_ID))
|
|
|
+ .with_assets_to_upload(StorageAssets::<Test> {
|
|
|
+ expected_data_size_fee: Storage::<Test>::data_object_per_mega_byte_fee(),
|
|
|
+ object_creation_list: create_data_objects_helper(),
|
|
|
+ })
|
|
|
+ .call_and_assert(Err(Error::<Test>::ActorNotAuthorized.into()));
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn unsuccessful_channel_update_with_assets_removed_by_unathorized_member() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_member_owned_channel();
|
|
|
+
|
|
|
+ UpdateChannelFixture::default()
|
|
|
+ .with_sender(UNAUTHORIZED_MEMBER_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Member(UNAUTHORIZED_MEMBER_ID))
|
|
|
+ // data objects ids start at index 1
|
|
|
+ .with_assets_to_remove((1..(DATA_OBJECTS_NUMBER as u64 - 1)).collect())
|
|
|
+ .call_and_assert(Err(Error::<Test>::ActorNotAuthorized.into()));
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn unsuccessful_channel_update_with_assets_uploaded_by_unauthorized_curator() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_CURATOR_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ increase_account_balance_helper(UNAUTHORIZED_CURATOR_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_curator_owned_channel();
|
|
|
+
|
|
|
+ let unauthorized_curator_group_id =
|
|
|
+ curators::add_curator_to_new_group(UNAUTHORIZED_CURATOR_ID);
|
|
|
+ UpdateChannelFixture::default()
|
|
|
+ .with_sender(UNAUTHORIZED_CURATOR_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Curator(
|
|
|
+ unauthorized_curator_group_id,
|
|
|
+ UNAUTHORIZED_CURATOR_ID,
|
|
|
+ ))
|
|
|
+ .with_assets_to_upload(StorageAssets::<Test> {
|
|
|
+ expected_data_size_fee: Storage::<Test>::data_object_per_mega_byte_fee(),
|
|
|
+ object_creation_list: create_data_objects_helper(),
|
|
|
+ })
|
|
|
+ .call_and_assert(Err(Error::<Test>::ActorNotAuthorized.into()));
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn unsuccessful_channel_update_with_assets_removed_by_unauthorized_curator() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_CURATOR_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_curator_owned_channel();
|
|
|
+
|
|
|
+ let unauthorized_curator_group_id =
|
|
|
+ curators::add_curator_to_new_group(UNAUTHORIZED_CURATOR_ID);
|
|
|
+ UpdateChannelFixture::default()
|
|
|
+ .with_sender(UNAUTHORIZED_CURATOR_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Curator(
|
|
|
+ unauthorized_curator_group_id,
|
|
|
+ UNAUTHORIZED_CURATOR_ID,
|
|
|
+ ))
|
|
|
+ // data objects ids start at index 1
|
|
|
+ .with_assets_to_remove((1..(DATA_OBJECTS_NUMBER as u64 - 1)).collect())
|
|
|
+ .call_and_assert(Err(Error::<Test>::ActorNotAuthorized.into()));
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn unsuccessful_member_channel_update_with_assets_uploaded_by_lead() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ increase_account_balance_helper(LEAD_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_member_owned_channel();
|
|
|
+
|
|
|
+ UpdateChannelFixture::default()
|
|
|
+ .with_sender(LEAD_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Lead)
|
|
|
+ .with_assets_to_upload(StorageAssets::<Test> {
|
|
|
+ expected_data_size_fee: Storage::<Test>::data_object_per_mega_byte_fee(),
|
|
|
+ object_creation_list: create_data_objects_helper(),
|
|
|
+ })
|
|
|
+ .call_and_assert(Err(Error::<Test>::ActorNotAuthorized.into()));
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn unsuccessful_member_channel_update_with_assets_removed_by_lead() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_member_owned_channel();
|
|
|
+
|
|
|
+ UpdateChannelFixture::default()
|
|
|
+ .with_sender(LEAD_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Lead)
|
|
|
+ // data objects ids start at index 1
|
|
|
+ .with_assets_to_remove((1..(DATA_OBJECTS_NUMBER as u64 - 1)).collect())
|
|
|
+ .call_and_assert(Err(Error::<Test>::ActorNotAuthorized.into()));
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn successful_channel_update_with_collaborators_set_updated_by_member() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_member_owned_channel();
|
|
|
+
|
|
|
+ UpdateChannelFixture::default()
|
|
|
+ .with_sender(DEFAULT_MEMBER_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Member(DEFAULT_MEMBER_ID))
|
|
|
+ .with_collaborators(BTreeSet::new())
|
|
|
+ .call_and_assert(Ok(()));
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn unsuccessful_channel_update_with_collaborators_set_updated_by_unauthorized_member() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_member_owned_channel();
|
|
|
+
|
|
|
+ UpdateChannelFixture::default()
|
|
|
+ .with_sender(UNAUTHORIZED_MEMBER_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Member(UNAUTHORIZED_MEMBER_ID))
|
|
|
+ .with_collaborators(BTreeSet::new())
|
|
|
+ .call_and_assert(Err(Error::<Test>::ActorNotAuthorized.into()));
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn successful_channel_update_with_collaborators_set_updated_by_curator() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_CURATOR_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_curator_owned_channel();
|
|
|
+
|
|
|
+ let default_curator_group_id = NextCuratorGroupId::<Test>::get() - 1;
|
|
|
+ UpdateChannelFixture::default()
|
|
|
+ .with_sender(DEFAULT_CURATOR_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Curator(
|
|
|
+ default_curator_group_id,
|
|
|
+ DEFAULT_CURATOR_ID,
|
|
|
+ ))
|
|
|
+ .with_collaborators(BTreeSet::new())
|
|
|
+ .call_and_assert(Ok(()));
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn unsuccessful_channel_update_with_collaborators_set_updated_by_unauthorized_curator() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_CURATOR_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_curator_owned_channel();
|
|
|
+
|
|
|
+ let unauthorized_curator_group_id =
|
|
|
+ curators::add_curator_to_new_group(UNAUTHORIZED_CURATOR_ID);
|
|
|
+ UpdateChannelFixture::default()
|
|
|
+ .with_sender(UNAUTHORIZED_CURATOR_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Curator(
|
|
|
+ unauthorized_curator_group_id,
|
|
|
+ UNAUTHORIZED_CURATOR_ID,
|
|
|
+ ))
|
|
|
+ .with_collaborators(BTreeSet::new())
|
|
|
+ .call_and_assert(Err(Error::<Test>::ActorNotAuthorized.into()));
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn unsuccessful_channel_update_with_collaborators_set_updated_by_collaborator() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_member_owned_channel();
|
|
|
+
|
|
|
+ UpdateChannelFixture::default()
|
|
|
+ .with_sender(COLLABORATOR_MEMBER_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Collaborator(COLLABORATOR_MEMBER_ID))
|
|
|
+ .with_collaborators(BTreeSet::new())
|
|
|
+ .call_and_assert(Err(Error::<Test>::ActorNotAuthorized.into()));
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn unsuccessful_member_channel_update_with_collaborators_set_updated_by_lead() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_member_owned_channel();
|
|
|
+
|
|
|
+ UpdateChannelFixture::default()
|
|
|
+ .with_sender(LEAD_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Lead)
|
|
|
+ .with_collaborators(BTreeSet::new())
|
|
|
+ .call_and_assert(Err(Error::<Test>::ActorNotAuthorized.into()));
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn successful_curator_channel_update_with_collaborators_set_updated_by_lead() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_CURATOR_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_curator_owned_channel();
|
|
|
+
|
|
|
+ UpdateChannelFixture::default()
|
|
|
+ .with_sender(LEAD_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Lead)
|
|
|
+ .with_collaborators(BTreeSet::new())
|
|
|
+ .call_and_assert(Ok(()));
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn unsuccessful_curator_channel_update_with_collaborators_set_updated_by_invalid_lead_origin() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_CURATOR_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_curator_owned_channel();
|
|
|
+
|
|
|
+ UpdateChannelFixture::default()
|
|
|
+ .with_sender(LEAD_ACCOUNT_ID + 100)
|
|
|
+ .with_actor(ContentActor::Lead)
|
|
|
+ .with_collaborators(BTreeSet::new())
|
|
|
+ .call_and_assert(Err(Error::<Test>::LeadAuthFailed.into()));
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn successful_channel_update_with_reward_account_updated_by_member() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_member_owned_channel();
|
|
|
+
|
|
|
+ UpdateChannelFixture::default()
|
|
|
+ .with_sender(DEFAULT_MEMBER_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Member(DEFAULT_MEMBER_ID))
|
|
|
+ .with_reward_account(Some(None))
|
|
|
+ .call_and_assert(Ok(()));
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn unsuccessful_channel_update_with_reward_account_updated_by_unauthorized_member() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_member_owned_channel();
|
|
|
+
|
|
|
+ UpdateChannelFixture::default()
|
|
|
+ .with_sender(UNAUTHORIZED_MEMBER_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Member(UNAUTHORIZED_MEMBER_ID))
|
|
|
+ .with_reward_account(Some(None))
|
|
|
+ .call_and_assert(Err(Error::<Test>::ActorNotAuthorized.into()));
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn successful_channel_update_with_reward_account_updated_by_curator() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_CURATOR_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_curator_owned_channel();
|
|
|
+
|
|
|
+ let default_curator_group_id = NextCuratorGroupId::<Test>::get() - 1;
|
|
|
+ UpdateChannelFixture::default()
|
|
|
+ .with_sender(DEFAULT_CURATOR_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Curator(
|
|
|
+ default_curator_group_id,
|
|
|
+ DEFAULT_CURATOR_ID,
|
|
|
+ ))
|
|
|
+ .with_reward_account(Some(None))
|
|
|
+ .call_and_assert(Ok(()));
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn unsuccessful_channel_update_with_reward_account_updated_by_unauthorized_curator() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_CURATOR_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_curator_owned_channel();
|
|
|
+
|
|
|
+ let unauthorized_curator_group_id =
|
|
|
+ curators::add_curator_to_new_group(UNAUTHORIZED_CURATOR_ID);
|
|
|
+ UpdateChannelFixture::default()
|
|
|
+ .with_sender(UNAUTHORIZED_CURATOR_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Curator(
|
|
|
+ unauthorized_curator_group_id,
|
|
|
+ UNAUTHORIZED_CURATOR_ID,
|
|
|
+ ))
|
|
|
+ .with_reward_account(Some(None))
|
|
|
+ .call_and_assert(Err(Error::<Test>::ActorNotAuthorized.into()));
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn unsuccessful_channel_update_with_reward_account_updated_by_collaborator() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_member_owned_channel();
|
|
|
+
|
|
|
+ UpdateChannelFixture::default()
|
|
|
+ .with_sender(COLLABORATOR_MEMBER_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Collaborator(COLLABORATOR_MEMBER_ID))
|
|
|
+ .with_reward_account(Some(None))
|
|
|
+ .call_and_assert(Err(Error::<Test>::ActorNotAuthorized.into()));
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn unsuccessful_member_channel_update_with_reward_account_updated_by_lead() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_member_owned_channel();
|
|
|
+
|
|
|
+ UpdateChannelFixture::default()
|
|
|
+ .with_sender(LEAD_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Lead)
|
|
|
+ .with_reward_account(Some(None))
|
|
|
+ .call_and_assert(Err(Error::<Test>::ActorNotAuthorized.into()));
|
|
|
})
|
|
|
}
|
|
|
|
|
|
#[test]
|
|
|
-fn successful_channel_assets_deletion() {
|
|
|
+fn successful_curator_channel_update_with_reward_account_updated_by_lead() {
|
|
|
with_default_mock_builder(|| {
|
|
|
- // Run to block one to see emitted events
|
|
|
run_to_block(1);
|
|
|
|
|
|
- create_initial_storage_buckets();
|
|
|
- // create an account with enought balance
|
|
|
- let _ = balances::Module::<Test>::deposit_creating(
|
|
|
- &FIRST_MEMBER_ORIGIN,
|
|
|
- <Test as balances::Trait>::Balance::from(INITIAL_BALANCE),
|
|
|
- );
|
|
|
-
|
|
|
- // 3 assets
|
|
|
- let assets = StorageAssetsRecord {
|
|
|
- object_creation_list: vec![
|
|
|
- DataObjectCreationParameters {
|
|
|
- size: 3,
|
|
|
- ipfs_content_id: b"first".to_vec(),
|
|
|
- },
|
|
|
- DataObjectCreationParameters {
|
|
|
- size: 3,
|
|
|
- ipfs_content_id: b"second".to_vec(),
|
|
|
- },
|
|
|
- DataObjectCreationParameters {
|
|
|
- size: 3,
|
|
|
- ipfs_content_id: b"third".to_vec(),
|
|
|
- },
|
|
|
- ],
|
|
|
- expected_data_size_fee: storage::DataObjectPerMegabyteFee::<Test>::get(),
|
|
|
- };
|
|
|
-
|
|
|
- let channel_id = NextChannelId::<Test>::get();
|
|
|
- // create channel
|
|
|
- create_channel_mock(
|
|
|
- FIRST_MEMBER_ORIGIN,
|
|
|
- ContentActor::Member(FIRST_MEMBER_ID),
|
|
|
- ChannelCreationParametersRecord {
|
|
|
- assets: Some(assets),
|
|
|
- meta: None,
|
|
|
- reward_account: None,
|
|
|
- collaborators: BTreeSet::new(),
|
|
|
- },
|
|
|
- Ok(()),
|
|
|
- );
|
|
|
-
|
|
|
- // delete assets
|
|
|
- let assets_to_remove = [0u64, 1u64].iter().map(|&x| x).collect::<BTreeSet<_>>();
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_CURATOR_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_curator_owned_channel();
|
|
|
|
|
|
- // delete channel assets
|
|
|
- assert_ok!(Content::update_channel(
|
|
|
- Origin::signed(FIRST_MEMBER_ORIGIN),
|
|
|
- ContentActor::Member(FIRST_MEMBER_ID),
|
|
|
- channel_id,
|
|
|
- ChannelUpdateParametersRecord {
|
|
|
- assets_to_upload: None,
|
|
|
- new_meta: None,
|
|
|
- reward_account: None,
|
|
|
- assets_to_remove: assets_to_remove,
|
|
|
- collaborators: None,
|
|
|
- },
|
|
|
- ));
|
|
|
+ UpdateChannelFixture::default()
|
|
|
+ .with_sender(LEAD_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Lead)
|
|
|
+ .with_reward_account(Some(None))
|
|
|
+ .call_and_assert(Ok(()));
|
|
|
})
|
|
|
}
|
|
|
|
|
|
#[test]
|
|
|
-fn succesful_channel_update() {
|
|
|
+fn unsuccessful_curator_channel_update_with_reward_account_updated_by_invalid_lead_origin() {
|
|
|
with_default_mock_builder(|| {
|
|
|
- // Run to block one to see emitted events
|
|
|
run_to_block(1);
|
|
|
|
|
|
- create_initial_storage_buckets();
|
|
|
-
|
|
|
- // create an account with enought balance
|
|
|
- let _ = balances::Module::<Test>::deposit_creating(
|
|
|
- &FIRST_MEMBER_ORIGIN,
|
|
|
- <Test as balances::Trait>::Balance::from(INITIAL_BALANCE),
|
|
|
- );
|
|
|
-
|
|
|
- // 2 + 1 assets to be uploaded
|
|
|
- let first_obj_id = Storage::<Test>::next_data_object_id();
|
|
|
- let first_batch = StorageAssetsRecord {
|
|
|
- object_creation_list: vec![
|
|
|
- DataObjectCreationParameters {
|
|
|
- size: 3,
|
|
|
- ipfs_content_id: b"first".to_vec(),
|
|
|
- },
|
|
|
- DataObjectCreationParameters {
|
|
|
- size: 3,
|
|
|
- ipfs_content_id: b"second".to_vec(),
|
|
|
- },
|
|
|
- ],
|
|
|
- expected_data_size_fee: storage::DataObjectPerMegabyteFee::<Test>::get(),
|
|
|
- };
|
|
|
- let first_batch_ids =
|
|
|
- (first_obj_id..Storage::<Test>::next_data_object_id()).collect::<BTreeSet<_>>();
|
|
|
-
|
|
|
- let second_batch = StorageAssetsRecord {
|
|
|
- object_creation_list: vec![
|
|
|
- DataObjectCreationParameters {
|
|
|
- size: 3,
|
|
|
- ipfs_content_id: b"first".to_vec(),
|
|
|
- },
|
|
|
- DataObjectCreationParameters {
|
|
|
- size: 3,
|
|
|
- ipfs_content_id: b"second".to_vec(),
|
|
|
- },
|
|
|
- ],
|
|
|
- expected_data_size_fee: storage::DataObjectPerMegabyteFee::<Test>::get(),
|
|
|
- };
|
|
|
-
|
|
|
- let channel_id = NextChannelId::<Test>::get();
|
|
|
-
|
|
|
- // create channel with first batch of assets
|
|
|
- create_channel_mock(
|
|
|
- FIRST_MEMBER_ORIGIN,
|
|
|
- ContentActor::Member(FIRST_MEMBER_ID),
|
|
|
- ChannelCreationParametersRecord {
|
|
|
- assets: Some(first_batch),
|
|
|
- meta: None,
|
|
|
- reward_account: None,
|
|
|
- collaborators: BTreeSet::new(),
|
|
|
- },
|
|
|
- Ok(()),
|
|
|
- );
|
|
|
-
|
|
|
- // update channel by adding the second batch of assets
|
|
|
- update_channel_mock(
|
|
|
- FIRST_MEMBER_ORIGIN,
|
|
|
- ContentActor::Member(FIRST_MEMBER_ID),
|
|
|
- channel_id,
|
|
|
- ChannelUpdateParametersRecord {
|
|
|
- assets_to_upload: Some(second_batch),
|
|
|
- new_meta: None,
|
|
|
- reward_account: None,
|
|
|
- assets_to_remove: BTreeSet::new(),
|
|
|
- collaborators: None,
|
|
|
- },
|
|
|
- Ok(()),
|
|
|
- );
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_CURATOR_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_curator_owned_channel();
|
|
|
|
|
|
- // update channel by removing the first batch of assets
|
|
|
- update_channel_mock(
|
|
|
- FIRST_MEMBER_ORIGIN,
|
|
|
- ContentActor::Member(FIRST_MEMBER_ID),
|
|
|
- channel_id,
|
|
|
- ChannelUpdateParametersRecord {
|
|
|
- assets_to_upload: None,
|
|
|
- new_meta: None,
|
|
|
- reward_account: None,
|
|
|
- assets_to_remove: first_batch_ids,
|
|
|
- collaborators: None,
|
|
|
- },
|
|
|
- Ok(()),
|
|
|
- );
|
|
|
+ UpdateChannelFixture::default()
|
|
|
+ .with_sender(LEAD_ACCOUNT_ID + 100)
|
|
|
+ .with_actor(ContentActor::Lead)
|
|
|
+ .with_reward_account(Some(None))
|
|
|
+ .call_and_assert(Err(Error::<Test>::LeadAuthFailed.into()));
|
|
|
})
|
|
|
}
|
|
|
|
|
|
#[test]
|
|
|
-fn succesful_channel_creation() {
|
|
|
+fn unsuccessful_channel_update_with_data_limits_exceeded() {
|
|
|
with_default_mock_builder(|| {
|
|
|
- // Run to block one to see emitted events
|
|
|
run_to_block(1);
|
|
|
|
|
|
- create_initial_storage_buckets();
|
|
|
-
|
|
|
- // create an account with enought balance
|
|
|
- let _ = balances::Module::<Test>::deposit_creating(
|
|
|
- &FIRST_MEMBER_ORIGIN,
|
|
|
- <Test as balances::Trait>::Balance::from(INITIAL_BALANCE),
|
|
|
- );
|
|
|
-
|
|
|
- // 3 assets to be uploaded
|
|
|
- let assets = StorageAssetsRecord {
|
|
|
- object_creation_list: vec![
|
|
|
- DataObjectCreationParameters {
|
|
|
- size: 3,
|
|
|
- ipfs_content_id: b"first".to_vec(),
|
|
|
- },
|
|
|
- DataObjectCreationParameters {
|
|
|
- size: 3,
|
|
|
- ipfs_content_id: b"second".to_vec(),
|
|
|
- },
|
|
|
- DataObjectCreationParameters {
|
|
|
- size: 3,
|
|
|
- ipfs_content_id: b"third".to_vec(),
|
|
|
- },
|
|
|
- ],
|
|
|
- expected_data_size_fee: storage::DataObjectPerMegabyteFee::<Test>::get(),
|
|
|
- };
|
|
|
-
|
|
|
- // create channel
|
|
|
- create_channel_mock(
|
|
|
- FIRST_MEMBER_ORIGIN,
|
|
|
- ContentActor::Member(FIRST_MEMBER_ID),
|
|
|
- ChannelCreationParametersRecord {
|
|
|
- assets: Some(assets),
|
|
|
- meta: None,
|
|
|
- reward_account: None,
|
|
|
- collaborators: BTreeSet::new(),
|
|
|
- },
|
|
|
- Ok(()),
|
|
|
- );
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_member_owned_channel();
|
|
|
+
|
|
|
+ UpdateChannelFixture::default()
|
|
|
+ .with_sender(DEFAULT_MEMBER_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Member(DEFAULT_MEMBER_ID))
|
|
|
+ .with_assets_to_upload(StorageAssets::<Test> {
|
|
|
+ expected_data_size_fee: Storage::<Test>::data_object_per_mega_byte_fee(),
|
|
|
+ object_creation_list: vec![DataObjectCreationParameters {
|
|
|
+ size: VOUCHER_OBJECTS_SIZE_LIMIT + 1,
|
|
|
+ ipfs_content_id: vec![1u8],
|
|
|
+ }],
|
|
|
+ })
|
|
|
+ .call_and_assert(Err(storage::Error::<Test>::MaxDataObjectSizeExceeded.into()));
|
|
|
})
|
|
|
}
|
|
|
|
|
|
#[test]
|
|
|
-fn lead_cannot_create_channel() {
|
|
|
+fn unsuccessful_channel_update_with_invalid_objects_id_to_remove() {
|
|
|
with_default_mock_builder(|| {
|
|
|
- create_initial_storage_buckets();
|
|
|
- assert_err!(
|
|
|
- Content::create_channel(
|
|
|
- Origin::signed(LEAD_ORIGIN),
|
|
|
- ContentActor::Lead,
|
|
|
- ChannelCreationParametersRecord {
|
|
|
- assets: None,
|
|
|
- meta: None,
|
|
|
- reward_account: None,
|
|
|
- collaborators: BTreeSet::new(),
|
|
|
- }
|
|
|
- ),
|
|
|
- Error::<Test>::ActorCannotOwnChannel
|
|
|
- );
|
|
|
+ run_to_block(1);
|
|
|
+
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_member_owned_channel();
|
|
|
+
|
|
|
+ UpdateChannelFixture::default()
|
|
|
+ .with_sender(DEFAULT_MEMBER_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Member(DEFAULT_MEMBER_ID))
|
|
|
+ .with_assets_to_remove(
|
|
|
+ ((DATA_OBJECTS_NUMBER as u64 + 1)..(2 * DATA_OBJECTS_NUMBER as u64)).collect(),
|
|
|
+ )
|
|
|
+ .call_and_assert(Err(storage::Error::<Test>::DataObjectDoesntExist.into()));
|
|
|
})
|
|
|
}
|
|
|
|
|
|
#[test]
|
|
|
-fn curator_owned_channels() {
|
|
|
+fn unsuccessful_channel_update_with_invalid_collaborators_set() {
|
|
|
with_default_mock_builder(|| {
|
|
|
- // Run to block one to see emitted events
|
|
|
run_to_block(1);
|
|
|
|
|
|
- // Curator group doesn't exist yet
|
|
|
- assert_err!(
|
|
|
- Content::create_channel(
|
|
|
- Origin::signed(FIRST_CURATOR_ORIGIN),
|
|
|
- ContentActor::Curator(FIRST_CURATOR_GROUP_ID, FIRST_CURATOR_ID),
|
|
|
- ChannelCreationParametersRecord {
|
|
|
- assets: None,
|
|
|
- meta: None,
|
|
|
- reward_account: None,
|
|
|
- collaborators: BTreeSet::new(),
|
|
|
- }
|
|
|
- ),
|
|
|
- Error::<Test>::CuratorGroupIsNotActive
|
|
|
- );
|
|
|
-
|
|
|
- let group_id = curators::add_curator_to_new_group(FIRST_CURATOR_ID);
|
|
|
- assert_eq!(FIRST_CURATOR_GROUP_ID, group_id);
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_member_owned_channel();
|
|
|
|
|
|
- // Curator from wrong group
|
|
|
- assert_err!(
|
|
|
- Content::create_channel(
|
|
|
- Origin::signed(SECOND_CURATOR_ORIGIN),
|
|
|
- ContentActor::Curator(FIRST_CURATOR_GROUP_ID, SECOND_CURATOR_ID),
|
|
|
- ChannelCreationParametersRecord {
|
|
|
- assets: None,
|
|
|
- meta: None,
|
|
|
- reward_account: None,
|
|
|
- collaborators: BTreeSet::new(),
|
|
|
- }
|
|
|
- ),
|
|
|
- Error::<Test>::CuratorIsNotAMemberOfGivenCuratorGroup
|
|
|
- );
|
|
|
+ UpdateChannelFixture::default()
|
|
|
+ .with_sender(DEFAULT_MEMBER_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Member(DEFAULT_MEMBER_ID))
|
|
|
+ .with_collaborators(vec![COLLABORATOR_MEMBER_ID + 100].into_iter().collect())
|
|
|
+ .call_and_assert(Err(Error::<Test>::CollaboratorIsNotValidMember.into()));
|
|
|
+ })
|
|
|
+}
|
|
|
|
|
|
- // Curator in correct active group, but wrong origin
|
|
|
- assert_err!(
|
|
|
- Content::create_channel(
|
|
|
- Origin::signed(SECOND_CURATOR_ORIGIN),
|
|
|
- ContentActor::Curator(FIRST_CURATOR_GROUP_ID, FIRST_CURATOR_ID),
|
|
|
- ChannelCreationParametersRecord {
|
|
|
- assets: None,
|
|
|
- meta: None,
|
|
|
- reward_account: None,
|
|
|
- collaborators: BTreeSet::new(),
|
|
|
- }
|
|
|
- ),
|
|
|
- Error::<Test>::CuratorAuthFailed
|
|
|
- );
|
|
|
+#[test]
|
|
|
+fn unsuccessful_channel_update_with_invalid_expected_data_size_fee() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
|
|
|
- let channel_id = Content::next_channel_id();
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_member_owned_channel();
|
|
|
+
|
|
|
+ UpdateChannelFixture::default()
|
|
|
+ .with_sender(DEFAULT_MEMBER_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Member(DEFAULT_MEMBER_ID))
|
|
|
+ .with_assets_to_upload(StorageAssets::<Test> {
|
|
|
+ // setting a purposely high fee to trigger error
|
|
|
+ expected_data_size_fee: BalanceOf::<Test>::from(1_000_000u64),
|
|
|
+ object_creation_list: create_data_objects_helper(),
|
|
|
+ })
|
|
|
+ .call_and_assert(Err(storage::Error::<Test>::DataSizeFeeChanged.into()));
|
|
|
+ })
|
|
|
+}
|
|
|
|
|
|
- // Curator in correct active group, with correct origin
|
|
|
- assert_ok!(Content::create_channel(
|
|
|
- Origin::signed(FIRST_CURATOR_ORIGIN),
|
|
|
- ContentActor::Curator(FIRST_CURATOR_GROUP_ID, FIRST_CURATOR_ID),
|
|
|
- ChannelCreationParametersRecord {
|
|
|
- assets: None,
|
|
|
- meta: None,
|
|
|
- reward_account: None,
|
|
|
- collaborators: BTreeSet::new(),
|
|
|
- }
|
|
|
- ));
|
|
|
+#[test]
|
|
|
+fn unsuccessful_channel_update_with_insufficient_balance() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
|
|
|
- assert_eq!(
|
|
|
- System::events().last().unwrap().event,
|
|
|
- MetaEvent::content(RawEvent::ChannelCreated(
|
|
|
- ContentActor::Curator(FIRST_CURATOR_GROUP_ID, FIRST_CURATOR_ID),
|
|
|
- channel_id,
|
|
|
- ChannelRecord {
|
|
|
- owner: ChannelOwner::CuratorGroup(FIRST_CURATOR_GROUP_ID),
|
|
|
- is_censored: false,
|
|
|
- reward_account: None,
|
|
|
- num_videos: 0,
|
|
|
- collaborators: BTreeSet::new(),
|
|
|
- },
|
|
|
- ChannelCreationParametersRecord {
|
|
|
- assets: None,
|
|
|
- meta: None,
|
|
|
- reward_account: None,
|
|
|
- collaborators: BTreeSet::new(),
|
|
|
- }
|
|
|
- ))
|
|
|
- );
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_member_owned_channel();
|
|
|
+ slash_account_balance_helper(DEFAULT_MEMBER_ACCOUNT_ID);
|
|
|
+
|
|
|
+ UpdateChannelFixture::default()
|
|
|
+ .with_sender(DEFAULT_MEMBER_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Member(DEFAULT_MEMBER_ID))
|
|
|
+ .with_assets_to_upload(StorageAssets::<Test> {
|
|
|
+ expected_data_size_fee: Storage::<Test>::data_object_per_mega_byte_fee(),
|
|
|
+ object_creation_list: create_data_objects_helper(),
|
|
|
+ })
|
|
|
+ .call_and_assert(Err(storage::Error::<Test>::InsufficientBalance.into()));
|
|
|
+ })
|
|
|
+}
|
|
|
|
|
|
- // Curator can update channel
|
|
|
- assert_ok!(Content::update_channel(
|
|
|
- Origin::signed(FIRST_CURATOR_ORIGIN),
|
|
|
- ContentActor::Curator(FIRST_CURATOR_GROUP_ID, FIRST_CURATOR_ID),
|
|
|
- channel_id,
|
|
|
- ChannelUpdateParametersRecord {
|
|
|
- assets_to_upload: None,
|
|
|
- new_meta: None,
|
|
|
- reward_account: None,
|
|
|
- assets_to_remove: BTreeSet::new(),
|
|
|
- collaborators: None,
|
|
|
- }
|
|
|
- ));
|
|
|
+#[test]
|
|
|
+fn unsuccessful_channel_update_with_no_bucket_with_sufficient_object_size_limit() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
|
|
|
- // Lead can update curator owned channels
|
|
|
- assert_ok!(Content::update_channel(
|
|
|
- Origin::signed(LEAD_ORIGIN),
|
|
|
- ContentActor::Lead,
|
|
|
- channel_id,
|
|
|
- ChannelUpdateParametersRecord {
|
|
|
- assets_to_upload: None,
|
|
|
- new_meta: None,
|
|
|
- reward_account: None,
|
|
|
- assets_to_remove: BTreeSet::new(),
|
|
|
- collaborators: None,
|
|
|
- }
|
|
|
- ));
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_member_owned_channel();
|
|
|
+
|
|
|
+ UpdateChannelFixture::default()
|
|
|
+ .with_sender(DEFAULT_MEMBER_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Member(DEFAULT_MEMBER_ID))
|
|
|
+ .with_assets_to_upload(StorageAssets::<Test> {
|
|
|
+ expected_data_size_fee: Storage::<Test>::data_object_per_mega_byte_fee(),
|
|
|
+ object_creation_list: vec![DataObjectCreationParameters {
|
|
|
+ size: STORAGE_BUCKET_OBJECTS_SIZE_LIMIT + 1,
|
|
|
+ ipfs_content_id: vec![1u8],
|
|
|
+ }],
|
|
|
+ })
|
|
|
+ .call_and_assert(Err(
|
|
|
+ storage::Error::<Test>::StorageBucketObjectSizeLimitReached.into(),
|
|
|
+ ));
|
|
|
})
|
|
|
}
|
|
|
|
|
|
#[test]
|
|
|
-fn invalid_member_cannot_create_channel() {
|
|
|
+fn unsuccessful_channel_update_with_no_bucket_with_sufficient_object_number_limit() {
|
|
|
with_default_mock_builder(|| {
|
|
|
- // Run to block one to see emitted events
|
|
|
run_to_block(1);
|
|
|
|
|
|
- create_initial_storage_buckets();
|
|
|
- // Not a member
|
|
|
- create_channel_mock(
|
|
|
- FIRST_MEMBER_ORIGIN,
|
|
|
- ContentActor::Member(UNKNOWN_MEMBER_ID),
|
|
|
- ChannelCreationParametersRecord {
|
|
|
- assets: None,
|
|
|
- meta: None,
|
|
|
- reward_account: None,
|
|
|
- collaborators: BTreeSet::new(),
|
|
|
- },
|
|
|
- Err(Error::<Test>::MemberAuthFailed.into()),
|
|
|
- );
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_member_owned_channel();
|
|
|
+
|
|
|
+ UpdateChannelFixture::default()
|
|
|
+ .with_sender(DEFAULT_MEMBER_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Member(DEFAULT_MEMBER_ID))
|
|
|
+ .with_assets_to_upload(StorageAssets::<Test> {
|
|
|
+ expected_data_size_fee: Storage::<Test>::data_object_per_mega_byte_fee(),
|
|
|
+ object_creation_list: (0..(STORAGE_BUCKET_OBJECTS_NUMBER_LIMIT + 1))
|
|
|
+ .map(|_| DataObjectCreationParameters {
|
|
|
+ size: 1,
|
|
|
+ ipfs_content_id: vec![1u8],
|
|
|
+ })
|
|
|
+ .collect(),
|
|
|
+ })
|
|
|
+ .call_and_assert(Err(
|
|
|
+ storage::Error::<Test>::StorageBucketObjectNumberLimitReached.into(),
|
|
|
+ ));
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+// channel deletion tests
|
|
|
#[test]
|
|
|
-fn invalid_member_cannot_update_channel() {
|
|
|
+fn successful_curator_channel_deletion_by_lead() {
|
|
|
with_default_mock_builder(|| {
|
|
|
- // Run to block one to see emitted events
|
|
|
run_to_block(1);
|
|
|
|
|
|
- create_initial_storage_buckets();
|
|
|
- create_channel_mock(
|
|
|
- FIRST_MEMBER_ORIGIN,
|
|
|
- ContentActor::Member(FIRST_MEMBER_ID),
|
|
|
- ChannelCreationParametersRecord {
|
|
|
- assets: None,
|
|
|
- meta: None,
|
|
|
- reward_account: None,
|
|
|
- collaborators: BTreeSet::new(),
|
|
|
- },
|
|
|
- Ok(()),
|
|
|
- );
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_CURATOR_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_curator_owned_channel();
|
|
|
|
|
|
- update_channel_mock(
|
|
|
- FIRST_MEMBER_ORIGIN,
|
|
|
- ContentActor::Member(UNKNOWN_MEMBER_ID),
|
|
|
- <Test as storage::Trait>::ChannelId::one(),
|
|
|
- ChannelUpdateParametersRecord {
|
|
|
- assets_to_upload: None,
|
|
|
- new_meta: None,
|
|
|
- reward_account: None,
|
|
|
- collaborators: None,
|
|
|
- assets_to_remove: BTreeSet::new(),
|
|
|
- },
|
|
|
- Err(Error::<Test>::MemberAuthFailed.into()),
|
|
|
- );
|
|
|
+ DeleteChannelFixture::default()
|
|
|
+ .with_sender(LEAD_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Lead)
|
|
|
+ .call_and_assert(Ok(()));
|
|
|
})
|
|
|
}
|
|
|
|
|
|
#[test]
|
|
|
-fn invalid_member_cannot_delete_channel() {
|
|
|
+fn unsuccessful_curator_channel_deletion_by_invalid_lead_origin() {
|
|
|
with_default_mock_builder(|| {
|
|
|
- // Run to block one to see emitted events
|
|
|
run_to_block(1);
|
|
|
|
|
|
- create_initial_storage_buckets();
|
|
|
-
|
|
|
- create_channel_mock(
|
|
|
- FIRST_MEMBER_ORIGIN,
|
|
|
- ContentActor::Member(FIRST_MEMBER_ID),
|
|
|
- ChannelCreationParametersRecord {
|
|
|
- assets: None,
|
|
|
- meta: None,
|
|
|
- reward_account: None,
|
|
|
- collaborators: BTreeSet::new(),
|
|
|
- },
|
|
|
- Ok(()),
|
|
|
- );
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_CURATOR_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_curator_owned_channel();
|
|
|
|
|
|
- delete_channel_mock(
|
|
|
- FIRST_MEMBER_ORIGIN,
|
|
|
- ContentActor::Member(UNKNOWN_MEMBER_ID),
|
|
|
- <Test as storage::Trait>::ChannelId::one(),
|
|
|
- 0u64,
|
|
|
- Err(Error::<Test>::MemberAuthFailed.into()),
|
|
|
- );
|
|
|
+ DeleteChannelFixture::default()
|
|
|
+ .with_sender(LEAD_ACCOUNT_ID + 100)
|
|
|
+ .with_actor(ContentActor::Lead)
|
|
|
+ .call_and_assert(Err(Error::<Test>::LeadAuthFailed.into()));
|
|
|
})
|
|
|
}
|
|
|
|
|
|
#[test]
|
|
|
-fn non_authorized_collaborators_cannot_update_channel() {
|
|
|
+fn unsuccessful_member_channel_deletion_by_lead() {
|
|
|
with_default_mock_builder(|| {
|
|
|
- // Run to block one to see emitted events
|
|
|
run_to_block(1);
|
|
|
|
|
|
- helper_init_accounts(vec![FIRST_MEMBER_ORIGIN, COLLABORATOR_MEMBER_ORIGIN]);
|
|
|
-
|
|
|
- create_initial_storage_buckets();
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_member_owned_channel();
|
|
|
|
|
|
- // create channel
|
|
|
- create_channel_mock(
|
|
|
- FIRST_MEMBER_ORIGIN,
|
|
|
- ContentActor::Member(FIRST_MEMBER_ID),
|
|
|
- ChannelCreationParametersRecord {
|
|
|
- assets: Some(helper_generate_storage_assets(vec![2, 3])),
|
|
|
- meta: None,
|
|
|
- reward_account: None,
|
|
|
- collaborators: BTreeSet::new(),
|
|
|
- },
|
|
|
- Ok(()),
|
|
|
- );
|
|
|
+ DeleteChannelFixture::default()
|
|
|
+ .with_sender(LEAD_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Lead)
|
|
|
+ .call_and_assert(Err(Error::<Test>::ActorNotAuthorized.into()));
|
|
|
+ })
|
|
|
+}
|
|
|
|
|
|
- // attempt for an non auth. collaborator to update channel assets
|
|
|
- update_channel_mock(
|
|
|
- COLLABORATOR_MEMBER_ORIGIN,
|
|
|
- ContentActor::Collaborator(COLLABORATOR_MEMBER_ID),
|
|
|
- <Test as storage::Trait>::ChannelId::one(),
|
|
|
- ChannelUpdateParametersRecord {
|
|
|
- assets_to_upload: Some(helper_generate_storage_assets(vec![5])),
|
|
|
- new_meta: None,
|
|
|
- reward_account: None,
|
|
|
- assets_to_remove: vec![DataObjectId::<Test>::one()]
|
|
|
- .into_iter()
|
|
|
- .collect::<BTreeSet<_>>(),
|
|
|
- collaborators: None,
|
|
|
- },
|
|
|
- Err(Error::<Test>::ActorNotAuthorized.into()),
|
|
|
- );
|
|
|
+#[test]
|
|
|
+fn unsuccessful_channel_deletion_by_collaborator() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
|
|
|
- // add collaborators
|
|
|
- update_channel_mock(
|
|
|
- FIRST_MEMBER_ORIGIN,
|
|
|
- ContentActor::Member(FIRST_MEMBER_ID),
|
|
|
- <Test as storage::Trait>::ChannelId::one(),
|
|
|
- ChannelUpdateParametersRecord {
|
|
|
- assets_to_upload: None,
|
|
|
- new_meta: None,
|
|
|
- reward_account: None,
|
|
|
- assets_to_remove: BTreeSet::new(),
|
|
|
- collaborators: Some(
|
|
|
- vec![COLLABORATOR_MEMBER_ID]
|
|
|
- .into_iter()
|
|
|
- .collect::<BTreeSet<_>>(),
|
|
|
- ),
|
|
|
- },
|
|
|
- Ok(()),
|
|
|
- );
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_member_owned_channel();
|
|
|
|
|
|
- // attempt for a valid collaborator to update channel fields outside
|
|
|
- // of his scope
|
|
|
- update_channel_mock(
|
|
|
- COLLABORATOR_MEMBER_ORIGIN,
|
|
|
- ContentActor::Collaborator(COLLABORATOR_MEMBER_ID),
|
|
|
- <Test as storage::Trait>::ChannelId::one(),
|
|
|
- ChannelUpdateParametersRecord {
|
|
|
- assets_to_upload: None,
|
|
|
- new_meta: None,
|
|
|
- reward_account: Some(Some(COLLABORATOR_MEMBER_ORIGIN)),
|
|
|
- assets_to_remove: BTreeSet::new(),
|
|
|
- collaborators: None,
|
|
|
- },
|
|
|
- Err(Error::<Test>::ActorNotAuthorized.into()),
|
|
|
- );
|
|
|
+ DeleteChannelFixture::default()
|
|
|
+ .with_sender(COLLABORATOR_MEMBER_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Collaborator(COLLABORATOR_MEMBER_ID))
|
|
|
+ .call_and_assert(Err(Error::<Test>::ActorNotAuthorized.into()));
|
|
|
})
|
|
|
}
|
|
|
|
|
|
#[test]
|
|
|
-fn authorized_collaborators_can_update_channel() {
|
|
|
+fn successful_channel_deletion_by_member() {
|
|
|
with_default_mock_builder(|| {
|
|
|
- // Run to block one to see emitted events
|
|
|
run_to_block(1);
|
|
|
|
|
|
- helper_init_accounts(vec![FIRST_MEMBER_ORIGIN, COLLABORATOR_MEMBER_ORIGIN]);
|
|
|
-
|
|
|
- create_initial_storage_buckets();
|
|
|
- // create channel
|
|
|
- create_channel_mock(
|
|
|
- FIRST_MEMBER_ORIGIN,
|
|
|
- ContentActor::Member(FIRST_MEMBER_ID),
|
|
|
- ChannelCreationParametersRecord {
|
|
|
- assets: Some(helper_generate_storage_assets(vec![2, 3])),
|
|
|
- meta: None,
|
|
|
- reward_account: None,
|
|
|
- collaborators: vec![COLLABORATOR_MEMBER_ID]
|
|
|
- .into_iter()
|
|
|
- .collect::<BTreeSet<_>>(),
|
|
|
- },
|
|
|
- Ok(()),
|
|
|
- );
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_member_owned_channel();
|
|
|
|
|
|
- // attempt for an auth. collaborator to update channel assets
|
|
|
- update_channel_mock(
|
|
|
- COLLABORATOR_MEMBER_ORIGIN,
|
|
|
- ContentActor::Collaborator(COLLABORATOR_MEMBER_ID),
|
|
|
- <Test as storage::Trait>::ChannelId::one(),
|
|
|
- ChannelUpdateParametersRecord {
|
|
|
- assets_to_upload: Some(helper_generate_storage_assets(vec![5])),
|
|
|
- new_meta: None,
|
|
|
- reward_account: None,
|
|
|
- assets_to_remove: vec![DataObjectId::<Test>::one()]
|
|
|
- .into_iter()
|
|
|
- .collect::<BTreeSet<_>>(),
|
|
|
- collaborators: None,
|
|
|
- },
|
|
|
- Ok(()),
|
|
|
- );
|
|
|
+ DeleteChannelFixture::default()
|
|
|
+ .with_sender(DEFAULT_MEMBER_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Member(DEFAULT_MEMBER_ID))
|
|
|
+ .call_and_assert(Ok(()));
|
|
|
})
|
|
|
}
|
|
|
|
|
|
#[test]
|
|
|
-fn channel_censoring() {
|
|
|
+fn successful_channel_deletion_by_curator() {
|
|
|
with_default_mock_builder(|| {
|
|
|
- // Run to block one to see emitted events
|
|
|
run_to_block(1);
|
|
|
|
|
|
- let channel_id = Content::next_channel_id();
|
|
|
- assert_ok!(Content::create_channel(
|
|
|
- Origin::signed(FIRST_MEMBER_ORIGIN),
|
|
|
- ContentActor::Member(FIRST_MEMBER_ID),
|
|
|
- ChannelCreationParametersRecord {
|
|
|
- assets: None,
|
|
|
- meta: None,
|
|
|
- reward_account: None,
|
|
|
- collaborators: BTreeSet::new(),
|
|
|
- }
|
|
|
- ));
|
|
|
-
|
|
|
- let group_id = curators::add_curator_to_new_group(FIRST_CURATOR_ID);
|
|
|
-
|
|
|
- // Curator can censor channels
|
|
|
- let is_censored = true;
|
|
|
- assert_ok!(Content::update_channel_censorship_status(
|
|
|
- Origin::signed(FIRST_CURATOR_ORIGIN),
|
|
|
- ContentActor::Curator(group_id, FIRST_CURATOR_ID),
|
|
|
- channel_id,
|
|
|
- is_censored,
|
|
|
- vec![]
|
|
|
- ));
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_CURATOR_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_curator_owned_channel();
|
|
|
|
|
|
- assert_eq!(
|
|
|
- System::events().last().unwrap().event,
|
|
|
- MetaEvent::content(RawEvent::ChannelCensorshipStatusUpdated(
|
|
|
- ContentActor::Curator(group_id, FIRST_CURATOR_ID),
|
|
|
- channel_id,
|
|
|
- is_censored,
|
|
|
- vec![]
|
|
|
+ let default_curator_group_id = Content::next_curator_group_id() - 1;
|
|
|
+ DeleteChannelFixture::default()
|
|
|
+ .with_sender(DEFAULT_CURATOR_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Curator(
|
|
|
+ default_curator_group_id,
|
|
|
+ DEFAULT_CURATOR_ID,
|
|
|
))
|
|
|
- );
|
|
|
+ .call_and_assert(Ok(()));
|
|
|
+ })
|
|
|
+}
|
|
|
|
|
|
- let channel = Content::channel_by_id(channel_id);
|
|
|
+#[test]
|
|
|
+fn unsuccessful_channel_deletion_by_unauthorized_member() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
|
|
|
- assert!(channel.is_censored);
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_member_owned_channel();
|
|
|
|
|
|
- // Curator can un-censor channels
|
|
|
- let is_censored = false;
|
|
|
- assert_ok!(Content::update_channel_censorship_status(
|
|
|
- Origin::signed(FIRST_CURATOR_ORIGIN),
|
|
|
- ContentActor::Curator(group_id, FIRST_CURATOR_ID),
|
|
|
- channel_id,
|
|
|
- is_censored,
|
|
|
- vec![]
|
|
|
- ));
|
|
|
+ DeleteChannelFixture::default()
|
|
|
+ .with_sender(UNAUTHORIZED_MEMBER_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Member(UNAUTHORIZED_MEMBER_ID))
|
|
|
+ .call_and_assert(Err(Error::<Test>::ActorNotAuthorized.into()));
|
|
|
+ })
|
|
|
+}
|
|
|
|
|
|
- assert_eq!(
|
|
|
- System::events().last().unwrap().event,
|
|
|
- MetaEvent::content(RawEvent::ChannelCensorshipStatusUpdated(
|
|
|
- ContentActor::Curator(group_id, FIRST_CURATOR_ID),
|
|
|
- channel_id,
|
|
|
- is_censored,
|
|
|
- vec![]
|
|
|
- ))
|
|
|
- );
|
|
|
+#[test]
|
|
|
+fn unsuccessful_channel_deletion_by_unauthorized_curator() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
|
|
|
- let channel = Content::channel_by_id(channel_id);
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_CURATOR_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_curator_owned_channel();
|
|
|
+
|
|
|
+ let unauthorized_curator_group_id =
|
|
|
+ curators::add_curator_to_new_group(UNAUTHORIZED_CURATOR_ID);
|
|
|
+ DeleteChannelFixture::default()
|
|
|
+ .with_sender(UNAUTHORIZED_CURATOR_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Curator(
|
|
|
+ unauthorized_curator_group_id,
|
|
|
+ UNAUTHORIZED_CURATOR_ID,
|
|
|
+ ))
|
|
|
+ .call_and_assert(Err(Error::<Test>::ActorNotAuthorized.into()));
|
|
|
+ })
|
|
|
+}
|
|
|
|
|
|
- assert!(!channel.is_censored);
|
|
|
+#[test]
|
|
|
+fn unsuccessful_channel_deletion_by_uncorresponding_member_id_and_origin() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
|
|
|
- // Member cannot censor channels
|
|
|
- let is_censored = true;
|
|
|
- assert_err!(
|
|
|
- Content::update_channel_censorship_status(
|
|
|
- Origin::signed(FIRST_MEMBER_ORIGIN),
|
|
|
- ContentActor::Member(FIRST_MEMBER_ID),
|
|
|
- channel_id,
|
|
|
- is_censored,
|
|
|
- vec![]
|
|
|
- ),
|
|
|
- Error::<Test>::ActorNotAuthorized
|
|
|
- );
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_member_owned_channel();
|
|
|
|
|
|
- let curator_channel_id = Content::next_channel_id();
|
|
|
+ DeleteChannelFixture::default()
|
|
|
+ .with_sender(UNAUTHORIZED_MEMBER_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Member(DEFAULT_MEMBER_ID))
|
|
|
+ .call_and_assert(Err(Error::<Test>::MemberAuthFailed.into()));
|
|
|
+ })
|
|
|
+}
|
|
|
|
|
|
- // create curator channel
|
|
|
- assert_ok!(Content::create_channel(
|
|
|
- Origin::signed(FIRST_CURATOR_ORIGIN),
|
|
|
- ContentActor::Curator(group_id, FIRST_CURATOR_ID),
|
|
|
- ChannelCreationParametersRecord {
|
|
|
- assets: None,
|
|
|
- meta: None,
|
|
|
- reward_account: None,
|
|
|
- collaborators: BTreeSet::new(),
|
|
|
- }
|
|
|
- ));
|
|
|
+#[test]
|
|
|
+fn unsuccessful_channel_deletion_by_uncorresponding_curator_id_and_origin() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
|
|
|
- // Curator cannot censor curator group channels
|
|
|
- assert_err!(
|
|
|
- Content::update_channel_censorship_status(
|
|
|
- Origin::signed(FIRST_CURATOR_ORIGIN),
|
|
|
- ContentActor::Curator(group_id, FIRST_CURATOR_ID),
|
|
|
- curator_channel_id,
|
|
|
- is_censored,
|
|
|
- vec![]
|
|
|
- ),
|
|
|
- Error::<Test>::CannotCensoreCuratorGroupOwnedChannels
|
|
|
- );
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_CURATOR_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_curator_owned_channel();
|
|
|
|
|
|
- // Lead can still censor curator group channels
|
|
|
- assert_ok!(Content::update_channel_censorship_status(
|
|
|
- Origin::signed(LEAD_ORIGIN),
|
|
|
- ContentActor::Lead,
|
|
|
- curator_channel_id,
|
|
|
- is_censored,
|
|
|
- vec![]
|
|
|
- ));
|
|
|
+ let default_curator_group_id = Content::next_curator_group_id() - 1;
|
|
|
+ DeleteChannelFixture::default()
|
|
|
+ .with_sender(UNAUTHORIZED_CURATOR_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Curator(
|
|
|
+ default_curator_group_id,
|
|
|
+ DEFAULT_CURATOR_ID,
|
|
|
+ ))
|
|
|
+ .call_and_assert(Err(Error::<Test>::CuratorAuthFailed.into()));
|
|
|
})
|
|
|
}
|
|
|
|
|
|
#[test]
|
|
|
-fn channel_creation_doesnt_leave_bags_dangling() {
|
|
|
+fn unsuccessful_channel_deletion_with_invalid_channel_id() {
|
|
|
with_default_mock_builder(|| {
|
|
|
- // in order to emit events
|
|
|
run_to_block(1);
|
|
|
|
|
|
- create_initial_storage_buckets();
|
|
|
- // number of assets big enought to make upload_data_objects throw
|
|
|
- let asset_num = 100_000usize;
|
|
|
- let mut object_creation_list =
|
|
|
- Vec::<DataObjectCreationParameters>::with_capacity(asset_num);
|
|
|
- for _i in 0..asset_num {
|
|
|
- object_creation_list.push(DataObjectCreationParameters {
|
|
|
- size: 1_000_000, // size big enought to make upload_data_objects throw
|
|
|
- ipfs_content_id: b"test".to_vec(),
|
|
|
- });
|
|
|
- }
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_member_owned_channel();
|
|
|
|
|
|
- let assets = StorageAssetsRecord {
|
|
|
- object_creation_list: object_creation_list,
|
|
|
- expected_data_size_fee: storage::DataObjectPerMegabyteFee::<Test>::get(),
|
|
|
- };
|
|
|
+ DeleteChannelFixture::default()
|
|
|
+ .with_sender(DEFAULT_MEMBER_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Member(DEFAULT_MEMBER_ID))
|
|
|
+ .with_channel_id(Zero::zero())
|
|
|
+ .call_and_assert(Err(Error::<Test>::ChannelDoesNotExist.into()));
|
|
|
+ })
|
|
|
+}
|
|
|
|
|
|
- let channel_id = NextChannelId::<Test>::get();
|
|
|
- // create channel
|
|
|
- create_channel_mock(
|
|
|
- FIRST_MEMBER_ORIGIN,
|
|
|
- ContentActor::Member(FIRST_MEMBER_ID),
|
|
|
- ChannelCreationParametersRecord {
|
|
|
- assets: Some(assets),
|
|
|
- meta: Some(vec![]),
|
|
|
- reward_account: None,
|
|
|
- collaborators: BTreeSet::new(),
|
|
|
- },
|
|
|
- Err(storage::Error::<Test>::MaxDataObjectSizeExceeded.into()),
|
|
|
- );
|
|
|
+#[test]
|
|
|
+fn unsuccessful_channel_deletion_with_invalid_bag_size() {
|
|
|
+ with_default_mock_builder(|| {
|
|
|
+ run_to_block(1);
|
|
|
+
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_member_owned_channel();
|
|
|
+
|
|
|
+ assert!(DATA_OBJECTS_NUMBER > 0);
|
|
|
|
|
|
- // ensure that no bag are left dangling
|
|
|
- let dyn_bag = DynamicBagIdType::<MemberId, ChannelId>::Channel(channel_id);
|
|
|
- let bag_id = storage::BagIdType::from(dyn_bag.clone());
|
|
|
- assert!(<Test as Trait>::DataObjectStorage::ensure_bag_exists(&bag_id).is_err());
|
|
|
+ DeleteChannelFixture::default()
|
|
|
+ .with_sender(DEFAULT_MEMBER_ACCOUNT_ID)
|
|
|
+ .with_actor(ContentActor::Member(DEFAULT_MEMBER_ID))
|
|
|
+ // default member owned channel has DATA_OBJECTS_NUMBER > 0 assets
|
|
|
+ .with_num_objects_to_delete(0u64)
|
|
|
+ .call_and_assert(Err(Error::<Test>::InvalidBagSizeSpecified.into()));
|
|
|
})
|
|
|
}
|