Browse Source

runtime: Remove obsolete `storage` and `service-discovery` pallets.

Shamil Gadelshin 3 years ago
parent
commit
4539cce798

+ 0 - 49
Cargo.lock

@@ -2425,13 +2425,11 @@ dependencies = [
  "pallet-proposals-engine",
  "pallet-randomness-collective-flip",
  "pallet-recurring-reward",
- "pallet-service-discovery",
  "pallet-session",
  "pallet-session-benchmarking",
  "pallet-stake",
  "pallet-staking",
  "pallet-staking-reward-curve",
- "pallet-storage",
  "pallet-storage-v2",
  "pallet-sudo",
  "pallet-timestamp",
@@ -4143,29 +4141,6 @@ dependencies = [
  "sp-runtime",
 ]
 
-[[package]]
-name = "pallet-service-discovery"
-version = "3.1.1"
-dependencies = [
- "frame-support",
- "frame-system",
- "pallet-balances",
- "pallet-common",
- "pallet-hiring",
- "pallet-membership",
- "pallet-recurring-reward",
- "pallet-stake",
- "pallet-timestamp",
- "pallet-token-mint",
- "pallet-working-group",
- "parity-scale-codec",
- "serde",
- "sp-core",
- "sp-io",
- "sp-runtime",
- "sp-std",
-]
-
 [[package]]
 name = "pallet-session"
 version = "2.0.1"
@@ -4251,30 +4226,6 @@ dependencies = [
  "syn",
 ]
 
-[[package]]
-name = "pallet-storage"
-version = "3.1.1"
-dependencies = [
- "frame-support",
- "frame-system",
- "pallet-balances",
- "pallet-common",
- "pallet-hiring",
- "pallet-membership",
- "pallet-recurring-reward",
- "pallet-stake",
- "pallet-timestamp",
- "pallet-token-mint",
- "pallet-working-group",
- "parity-scale-codec",
- "serde",
- "sp-arithmetic",
- "sp-core",
- "sp-io",
- "sp-runtime",
- "sp-std",
-]
-
 [[package]]
 name = "pallet-storage-v2"
 version = "1.0.0"

+ 0 - 2
Cargo.toml

@@ -12,9 +12,7 @@ members = [
 	"runtime-modules/membership",
 	"runtime-modules/memo",
 	"runtime-modules/recurring-reward",
-	"runtime-modules/service-discovery",
 	"runtime-modules/stake",
-	"runtime-modules/storage",
 	"runtime-modules/token-minting",
 	"runtime-modules/versioned-store",
 	"runtime-modules/versioned-store-permissions",

+ 1 - 68
node/src/chain_spec/content_config.rs

@@ -2,12 +2,10 @@ use codec::Decode;
 use node_runtime::common::constraints::InputValidationLengthConstraint;
 use node_runtime::{
     content_wg::{Channel, ChannelId, Principal, PrincipalId},
-    data_directory::DataObject,
     primitives::{AccountId, BlockNumber, Credential},
     versioned_store::{Class, ClassId, Entity, EntityId},
     versioned_store_permissions::ClassPermissions,
-    ContentId, ContentWorkingGroupConfig, DataDirectoryConfig, Runtime, VersionedStoreConfig,
-    VersionedStorePermissionsConfig,
+    ContentWorkingGroupConfig, Runtime, VersionedStoreConfig, VersionedStorePermissionsConfig,
 };
 use serde::Deserialize;
 use std::{fs, path::Path};
@@ -28,20 +26,12 @@ struct EntityAndMaintainer {
     maintainer: Option<Credential>,
 }
 
-#[derive(Decode)]
-struct DataObjectAndContentId {
-    content_id: ContentId,
-    data_object: DataObject<Runtime>,
-}
-
 #[derive(Decode)]
 struct ContentData {
     /// classes and their associted permissions
     classes: Vec<ClassAndPermissions>,
     /// entities and their associated maintainer
     entities: Vec<EntityAndMaintainer>,
-    /// DataObject(s) and ContentId
-    data_objects: Vec<DataObjectAndContentId>,
     /// Media Channels
     channels: Vec<ChannelAndId>,
 }
@@ -92,28 +82,6 @@ impl EncodedEntityAndMaintainer {
     }
 }
 
-#[derive(Deserialize)]
-struct EncodedDataObjectAndContentId {
-    /// hex encoded ContentId
-    content_id: String,
-    /// hex encoded DataObject<Runtime>
-    data_object: String,
-}
-
-impl EncodedDataObjectAndContentId {
-    fn decode(&self) -> DataObjectAndContentId {
-        // hex string must not include '0x' prefix!
-        let encoded_content_id = hex::decode(&self.content_id[2..].as_bytes())
-            .expect("failed to parse content_id hex string");
-        let encoded_data_object = hex::decode(&self.data_object[2..].as_bytes())
-            .expect("failed to parse data_object hex string");
-        DataObjectAndContentId {
-            content_id: Decode::decode(&mut encoded_content_id.as_slice()).unwrap(),
-            data_object: Decode::decode(&mut encoded_data_object.as_slice()).unwrap(),
-        }
-    }
-}
-
 #[derive(Decode)]
 struct ChannelAndId {
     id: ChannelId<Runtime>,
@@ -146,8 +114,6 @@ struct EncodedContentData {
     classes: Vec<EncodedClassAndPermissions>,
     /// entities and their associated maintainer
     entities: Vec<EncodedEntityAndMaintainer>,
-    /// DataObject(s) and ContentId
-    data_objects: Vec<EncodedDataObjectAndContentId>,
     /// Media Channels
     channels: Vec<EncodedChannelAndId>,
 }
@@ -170,11 +136,6 @@ impl EncodedContentData {
                 .iter()
                 .map(|entities_and_maintainer| entities_and_maintainer.decode())
                 .collect(),
-            data_objects: self
-                .data_objects
-                .iter()
-                .map(|data_objects| data_objects.decode())
-                .collect(),
             channels: self
                 .channels
                 .iter()
@@ -277,34 +238,6 @@ pub fn versioned_store_permissions_config_from_json(
     }
 }
 
-/// Generates a basic empty `DataDirectoryConfig` genesis config
-pub fn empty_data_directory_config() -> DataDirectoryConfig {
-    DataDirectoryConfig {
-        data_object_by_content_id: vec![],
-        known_content_ids: vec![],
-    }
-}
-
-/// Generates a `DataDirectoryConfig` genesis config
-/// pre-populated with data objects and known content ids parsed from
-/// a json file serialized as a `ContentData` struct
-pub fn data_directory_config_from_json(data_file: &Path) -> DataDirectoryConfig {
-    let content = parse_content_data(data_file).decode();
-
-    DataDirectoryConfig {
-        data_object_by_content_id: content
-            .data_objects
-            .iter()
-            .map(|object| (object.content_id, object.data_object.clone()))
-            .collect(),
-        known_content_ids: content
-            .data_objects
-            .into_iter()
-            .map(|object| object.content_id)
-            .collect(),
-    }
-}
-
 /// Generates a basic `ContentWorkingGroupConfig` genesis config without any active curators
 /// curator lead or channels.
 pub fn empty_content_working_group_config() -> ContentWorkingGroupConfig {

+ 3 - 16
node/src/chain_spec/mod.rs

@@ -33,10 +33,9 @@ use sp_runtime::Perbill;
 use node_runtime::{
     membership, wasm_binary_unwrap, AuthorityDiscoveryConfig, BabeConfig, Balance, BalancesConfig,
     ContentDirectoryConfig, ContentDirectoryWorkingGroupConfig, ContentWorkingGroupConfig,
-    CouncilConfig, CouncilElectionConfig, DataDirectoryConfig, DataObjectStorageRegistryConfig,
-    DataObjectTypeRegistryConfig, ElectionParameters, ForumConfig, GrandpaConfig, ImOnlineConfig,
-    MembersConfig, Moment, ProposalsCodexConfig, SessionConfig, SessionKeys, Signature,
-    StakerStatus, StakingConfig, StorageWorkingGroupConfig, SudoConfig, SystemConfig,
+    CouncilConfig, CouncilElectionConfig, ElectionParameters, ForumConfig, GrandpaConfig,
+    ImOnlineConfig, MembersConfig, Moment, ProposalsCodexConfig, SessionConfig, SessionKeys,
+    Signature, StakerStatus, StakingConfig, StorageWorkingGroupConfig, SudoConfig, SystemConfig,
     VersionedStoreConfig, VersionedStorePermissionsConfig, DAYS,
 };
 
@@ -140,7 +139,6 @@ impl Alternative {
                         forum_config::empty(get_account_id_from_seed::<sr25519::Public>("Alice")),
                         content_config::empty_versioned_store_config(),
                         content_config::empty_versioned_store_permissions_config(),
-                        content_config::empty_data_directory_config(),
                         content_config::empty_content_working_group_config(),
                         vec![],
                     )
@@ -181,7 +179,6 @@ impl Alternative {
                         forum_config::empty(get_account_id_from_seed::<sr25519::Public>("Alice")),
                         content_config::empty_versioned_store_config(),
                         content_config::empty_versioned_store_permissions_config(),
-                        content_config::empty_data_directory_config(),
                         content_config::empty_content_working_group_config(),
                         vec![],
                     )
@@ -227,7 +224,6 @@ pub fn testnet_genesis(
     forum_config: ForumConfig,
     versioned_store_config: VersionedStoreConfig,
     versioned_store_permissions_config: VersionedStorePermissionsConfig,
-    data_directory_config: DataDirectoryConfig,
     content_working_group_config: ContentWorkingGroupConfig,
     initial_balances: Vec<(AccountId, Balance)>,
 ) -> GenesisConfig {
@@ -309,13 +305,6 @@ pub fn testnet_genesis(
             members,
         }),
         forum: Some(forum_config),
-        data_directory: Some(data_directory_config),
-        data_object_type_registry: Some(DataObjectTypeRegistryConfig {
-            first_data_object_type_id: 1,
-        }),
-        data_object_storage_registry: Some(DataObjectStorageRegistryConfig {
-            first_relationship_id: 1,
-        }),
         working_group_Instance2: Some(StorageWorkingGroupConfig {
             phantom: Default::default(),
             working_group_mint_capacity: 0,
@@ -410,7 +399,6 @@ pub(crate) mod tests {
             forum_config::empty(get_account_id_from_seed::<sr25519::Public>("Alice")),
             content_config::empty_versioned_store_config(),
             content_config::empty_versioned_store_permissions_config(),
-            content_config::empty_data_directory_config(),
             content_config::empty_content_working_group_config(),
             vec![],
         )
@@ -447,7 +435,6 @@ pub(crate) mod tests {
             forum_config::empty(get_account_id_from_seed::<sr25519::Public>("Alice")),
             content_config::empty_versioned_store_config(),
             content_config::empty_versioned_store_permissions_config(),
-            content_config::empty_data_directory_config(),
             content_config::empty_content_working_group_config(),
             vec![],
         )

+ 0 - 38
runtime-modules/service-discovery/Cargo.toml

@@ -1,38 +0,0 @@
-[package]
-name = 'pallet-service-discovery'
-version = '3.1.1'
-authors = ['Joystream contributors']
-edition = '2018'
-
-[dependencies]
-serde = { version = "1.0.101", optional = true, features = ["derive"] }
-codec = { package = 'parity-scale-codec', version = '1.3.4', default-features = false, features = ['derive'] }
-sp-std = { package = 'sp-std', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '2cd20966cc09b059817c3ebe12fc130cdd850d62'}
-frame-support = { package = 'frame-support', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '2cd20966cc09b059817c3ebe12fc130cdd850d62'}
-frame-system = { package = 'frame-system', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '2cd20966cc09b059817c3ebe12fc130cdd850d62'}
-sp-runtime = { package = 'sp-runtime', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '2cd20966cc09b059817c3ebe12fc130cdd850d62'}
-working-group = { package = 'pallet-working-group', default-features = false, path = '../working-group'}
-
-[dev-dependencies]
-sp-io = { package = 'sp-io', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '2cd20966cc09b059817c3ebe12fc130cdd850d62'}
-sp-core = { package = 'sp-core', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '2cd20966cc09b059817c3ebe12fc130cdd850d62'}
-pallet-timestamp = { package = 'pallet-timestamp', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '2cd20966cc09b059817c3ebe12fc130cdd850d62'}
-balances = { package = 'pallet-balances', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '2cd20966cc09b059817c3ebe12fc130cdd850d62'}
-membership = { package = 'pallet-membership', default-features = false, path = '../membership'}
-stake = { package = 'pallet-stake', default-features = false, path = '../stake'}
-hiring = { package = 'pallet-hiring', default-features = false, path = '../hiring'}
-minting = { package = 'pallet-token-mint', default-features = false, path = '../token-minting'}
-recurringrewards = { package = 'pallet-recurring-reward', default-features = false, path = '../recurring-reward'}
-common = { package = 'pallet-common', default-features = false, path = '../common'}
-
-[features]
-default = ['std']
-std = [
-	'serde',
-	'codec/std',
-	'sp-std/std',
-	'frame-support/std',
-	'frame-system/std',
-	'sp-runtime/std',
-	'working-group/std',
-]

+ 0 - 191
runtime-modules/service-discovery/src/lib.rs

@@ -1,191 +0,0 @@
-//! # Service discovery module
-//! Service discovery module for the Joystream platform supports the storage providers.
-//! It registers their 'pings' in the frame_system with the expiration time, and stores the bootstrap
-//! nodes for the Colossus.
-//!
-//! ## Comments
-//!
-//! Service discovery module uses working group module to authorize actions. It is generally used by
-//! the Colossus service.
-//!
-//! ## Supported extrinsics
-//!
-//! - [set_ipns_id](./struct.Module.html#method.set_ipns_id) - Creates the ServiceProviderRecord to save an IPNS identity for the storage provider.
-//! - [unset_ipns_id](./struct.Module.html#method.unset_ipns_id) - Deletes the ServiceProviderRecord with the IPNS identity for the storage provider.
-//! - [set_default_lifetime](./struct.Module.html#method.set_default_lifetime) - Sets default lifetime for storage providers accounts info.
-//! - [set_bootstrap_endpoints](./struct.Module.html#method.set_bootstrap_endpoints) - Sets bootstrap endpoints for the Colossus.
-//!
-
-// Ensure we're `no_std` when compiling for Wasm.
-#![cfg_attr(not(feature = "std"), no_std)]
-
-mod mock;
-mod tests;
-
-use codec::{Decode, Encode};
-#[cfg(feature = "std")]
-use serde::{Deserialize, Serialize};
-
-use frame_support::{decl_event, decl_module, decl_storage, ensure};
-use frame_system::ensure_root;
-use sp_std::vec::Vec;
-/*
-  Although there is support for ed25519 keys as the IPNS identity key and we could potentially
-  reuse the same key for the role account and ipns (and make this discovery module obselete)
-  it is probably better to separate concerns.
-  Why not to use a fixed size 32byte -> SHA256 hash of public key: because we would have to force
-  specific key type on ipfs side.
-  pub struct IPNSIdentity(pub [u8; 32]); // we loose the key type!
-  pub type IPNSIdentity(pub u8, pub [u8; 32]); // we could add the keytype?
-  can we use rust library in wasm runtime?
-  https://github.com/multiformats/rust-multihash
-  https://github.com/multiformats/multicodec/
-  https://github.com/multiformats/multihash/
-*/
-// Will be removed in the next releases.
-#[allow(clippy::upper_case_acronyms)]
-/// base58 encoded IPNS identity multihash codec
-pub type IPNSIdentity = Vec<u8>;
-
-/// HTTP Url string to a discovery service endpoint
-pub type Url = Vec<u8>;
-
-// The storage working group instance alias.
-pub(crate) type StorageWorkingGroupInstance = working_group::Instance2;
-
-// Alias for storage working group.
-pub(crate) type StorageWorkingGroup<T> = working_group::Module<T, StorageWorkingGroupInstance>;
-
-/// Storage provider is a worker from the  working_group module.
-pub type StorageProviderId<T> = working_group::WorkerId<T>;
-
-pub(crate) const MINIMUM_LIFETIME: u32 = 600; // 1hr assuming 6s block times
-pub(crate) const DEFAULT_LIFETIME: u32 = MINIMUM_LIFETIME * 24; // 24hr
-
-/// Defines the expiration date for the storage provider.
-#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))]
-#[derive(Encode, Decode, Default, Clone, PartialEq, Eq)]
-pub struct ServiceProviderRecord<BlockNumber> {
-    /// IPNS Identity.
-    pub identity: IPNSIdentity,
-    /// Block at which information expires.
-    pub expires_at: BlockNumber,
-}
-
-/// The _Service discovery_ main _Trait_.
-pub trait Trait: frame_system::Trait + working_group::Trait<StorageWorkingGroupInstance> {
-    /// _Service discovery_ event type.
-    type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
-}
-
-decl_storage! {
-    trait Store for Module<T: Trait> as Discovery {
-        /// Bootstrap endpoints maintained by root
-        pub BootstrapEndpoints get(fn bootstrap_endpoints): Vec<Url>;
-
-        /// Mapping of service providers' storage provider id to their ServiceProviderRecord
-        pub AccountInfoByStorageProviderId get(fn account_info_by_storage_provider_id):
-            map hasher(blake2_128_concat) StorageProviderId<T> => ServiceProviderRecord<T::BlockNumber>;
-
-        /// Lifetime of an ServiceProviderRecord record in AccountInfoByAccountId map
-        pub DefaultLifetime get(fn default_lifetime) config():
-            T::BlockNumber = T::BlockNumber::from(DEFAULT_LIFETIME);
-    }
-}
-
-decl_event! {
-    /// _Service discovery_ events
-    pub enum Event<T> where
-        StorageProviderId = StorageProviderId<T>
-       {
-        /// Emits on updating of the account info.
-        /// Params:
-        /// - Id of the storage provider.
-        /// - Id of the IPNS.
-        AccountInfoUpdated(StorageProviderId, IPNSIdentity),
-
-        /// Emits on removing of the account info.
-        /// Params:
-        /// - Id of the storage provider.
-        AccountInfoRemoved(StorageProviderId),
-    }
-}
-
-decl_module! {
-    /// _Service discovery_ substrate module.
-    pub struct Module<T: Trait> for enum Call where origin: T::Origin {
-        /// Default deposit_event() handler
-        fn deposit_event() = default;
-
-        /// Creates the ServiceProviderRecord to save an IPNS identity for the storage provider.
-        /// Requires signed storage provider credentials.
-        #[weight = 10_000_000] // TODO: adjust weight
-        pub fn set_ipns_id(
-            origin,
-            storage_provider_id: StorageProviderId<T>,
-            id: Vec<u8>,
-        ) {
-            <StorageWorkingGroup<T>>::ensure_worker_signed(origin, &storage_provider_id)?;
-
-            // TODO: ensure id is a valid base58 encoded IPNS identity
-
-            //
-            // == MUTATION SAFE ==
-            //
-
-            <AccountInfoByStorageProviderId<T>>::insert(storage_provider_id, ServiceProviderRecord {
-                identity: id.clone(),
-                expires_at: <frame_system::Module<T>>::block_number() + Self::default_lifetime(),
-            });
-
-            Self::deposit_event(RawEvent::AccountInfoUpdated(storage_provider_id, id));
-        }
-
-        /// Deletes the ServiceProviderRecord with the IPNS identity for the storage provider.
-        /// Requires signed storage provider credentials.
-        #[weight = 10_000_000] // TODO: adjust weight
-        pub fn unset_ipns_id(origin, storage_provider_id: StorageProviderId<T>) {
-            <StorageWorkingGroup<T>>::ensure_worker_signed(origin, &storage_provider_id)?;
-
-            // == MUTATION SAFE ==
-
-            if <AccountInfoByStorageProviderId<T>>::contains_key(storage_provider_id) {
-                <AccountInfoByStorageProviderId<T>>::remove(storage_provider_id);
-                Self::deposit_event(RawEvent::AccountInfoRemoved(storage_provider_id));
-            }
-        }
-
-        // Privileged methods
-
-        /// Sets default lifetime for storage providers accounts info. Requires root privileges.
-        #[weight = 10_000_000] // TODO: adjust weight
-        pub fn set_default_lifetime(origin, lifetime: T::BlockNumber) {
-            ensure_root(origin)?;
-            ensure!(lifetime >= T::BlockNumber::from(MINIMUM_LIFETIME),
-                "discovery: default lifetime must be gte minimum lifetime");
-
-            // == MUTATION SAFE ==
-
-            <DefaultLifetime<T>>::put(lifetime);
-        }
-
-        /// Sets bootstrap endpoints for the Colossus. Requires root privileges.
-        #[weight = 10_000_000] // TODO: adjust weight
-        pub fn set_bootstrap_endpoints(origin, endpoints: Vec<Url>) {
-            ensure_root(origin)?;
-
-            // == MUTATION SAFE ==
-
-            BootstrapEndpoints::put(endpoints);
-        }
-    }
-}
-
-impl<T: Trait> Module<T> {
-    /// Verifies that account info for the storage provider is still valid.
-    pub fn is_account_info_expired(storage_provider_id: &StorageProviderId<T>) -> bool {
-        !<AccountInfoByStorageProviderId<T>>::contains_key(storage_provider_id)
-            || <frame_system::Module<T>>::block_number()
-                > <AccountInfoByStorageProviderId<T>>::get(storage_provider_id).expires_at
-    }
-}

+ 0 - 182
runtime-modules/service-discovery/src/mock.rs

@@ -1,182 +0,0 @@
-#![cfg(test)]
-
-pub use crate::*;
-
-use frame_support::{impl_outer_event, impl_outer_origin, parameter_types};
-use sp_core::H256;
-use sp_runtime::{
-    testing::Header,
-    traits::{BlakeTwo256, IdentityLookup},
-    Perbill,
-};
-
-// The storage working group instance alias.
-pub type StorageWorkingGroupInstance = working_group::Instance2;
-
-mod working_group_mod {
-    pub use super::StorageWorkingGroupInstance;
-    pub use working_group::Event;
-    pub use working_group::Trait;
-}
-
-mod membership_mod {
-    pub use membership::Event;
-}
-
-mod discovery {
-    pub use crate::Event;
-}
-
-impl_outer_origin! {
-    pub enum Origin for Test {}
-}
-
-impl_outer_event! {
-    pub enum MetaEvent for Test {
-        discovery<T>,
-        balances<T>,
-        membership_mod<T>,
-        working_group_mod StorageWorkingGroupInstance <T>,
-        frame_system<T>,
-    }
-}
-
-// Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
-#[derive(Clone, PartialEq, Eq, Debug)]
-pub struct Test;
-parameter_types! {
-    pub const BlockHashCount: u64 = 250;
-    pub const MaximumBlockWeight: u32 = 1024;
-    pub const MaximumBlockLength: u32 = 2 * 1024;
-    pub const AvailableBlockRatio: Perbill = Perbill::one();
-    pub const MinimumPeriod: u64 = 5;
-    pub const StakePoolId: [u8; 8] = *b"joystake";
-    pub const ExistentialDeposit: u32 = 0;
-}
-
-impl frame_system::Trait for Test {
-    type BaseCallFilter = ();
-    type Origin = Origin;
-    type Call = ();
-    type Index = u64;
-    type BlockNumber = u64;
-    type Hash = H256;
-    type Hashing = BlakeTwo256;
-    type AccountId = u64;
-    type Lookup = IdentityLookup<Self::AccountId>;
-    type Header = Header;
-    type Event = MetaEvent;
-    type BlockHashCount = BlockHashCount;
-    type MaximumBlockWeight = MaximumBlockWeight;
-    type DbWeight = ();
-    type BlockExecutionWeight = ();
-    type ExtrinsicBaseWeight = ();
-    type MaximumExtrinsicWeight = ();
-    type MaximumBlockLength = MaximumBlockLength;
-    type AvailableBlockRatio = AvailableBlockRatio;
-    type Version = ();
-    type AccountData = balances::AccountData<u64>;
-    type OnNewAccount = ();
-    type OnKilledAccount = ();
-    type SystemWeightInfo = ();
-    type PalletInfo = ();
-}
-
-impl Trait for Test {
-    type Event = MetaEvent;
-}
-
-impl hiring::Trait for Test {
-    type OpeningId = u64;
-    type ApplicationId = u64;
-    type ApplicationDeactivatedHandler = ();
-    type StakeHandlerProvider = hiring::Module<Self>;
-}
-
-impl minting::Trait for Test {
-    type Currency = Balances;
-    type MintId = u64;
-}
-
-impl stake::Trait for Test {
-    type Currency = Balances;
-    type StakePoolId = StakePoolId;
-    type StakingEventsHandler = ();
-    type StakeId = u64;
-    type SlashId = u64;
-}
-
-impl membership::Trait for Test {
-    type Event = MetaEvent;
-    type MemberId = u64;
-    type PaidTermId = u64;
-    type SubscriptionId = u64;
-    type ActorId = u64;
-}
-
-impl common::currency::GovernanceCurrency for Test {
-    type Currency = Balances;
-}
-
-impl balances::Trait for Test {
-    type Balance = u64;
-    type DustRemoval = ();
-    type Event = MetaEvent;
-    type ExistentialDeposit = ExistentialDeposit;
-    type AccountStore = System;
-    type WeightInfo = ();
-    type MaxLocks = ();
-}
-
-impl recurringrewards::Trait for Test {
-    type PayoutStatusHandler = ();
-    type RecipientId = u64;
-    type RewardRelationshipId = u64;
-}
-
-parameter_types! {
-    pub const MaxWorkerNumberLimit: u32 = 3;
-}
-
-impl working_group::Trait<StorageWorkingGroupInstance> for Test {
-    type Event = MetaEvent;
-    type MaxWorkerNumberLimit = MaxWorkerNumberLimit;
-}
-
-impl pallet_timestamp::Trait for Test {
-    type Moment = u64;
-    type OnTimestampSet = ();
-    type MinimumPeriod = MinimumPeriod;
-    type WeightInfo = ();
-}
-
-pub fn initial_test_ext() -> sp_io::TestExternalities {
-    let t = frame_system::GenesisConfig::default()
-        .build_storage::<Test>()
-        .unwrap();
-
-    t.into()
-}
-
-pub type Balances = balances::Module<Test>;
-pub type System = frame_system::Module<Test>;
-pub type Discovery = Module<Test>;
-
-pub(crate) fn hire_storage_provider() -> (u64, u64) {
-    let storage_provider_id = 1;
-    let role_account_id = 1;
-
-    let storage_provider = working_group::Worker {
-        member_id: 1,
-        role_account_id,
-        reward_relationship: None,
-        role_stake_profile: None,
-    };
-
-    <working_group::WorkerById<Test, StorageWorkingGroupInstance>>::insert(
-        storage_provider_id,
-        storage_provider,
-    );
-
-    (role_account_id, storage_provider_id)
-}

+ 0 - 178
runtime-modules/service-discovery/src/tests.rs

@@ -1,178 +0,0 @@
-#![cfg(test)]
-
-use super::mock::*;
-
-use frame_system::{EventRecord, Phase, RawOrigin};
-
-#[test]
-fn set_ipns_id() {
-    initial_test_ext().execute_with(|| {
-        let current_block_number = 1000;
-        System::set_block_number(current_block_number);
-
-        let (storage_provider_account_id, storage_provider_id) = hire_storage_provider();
-
-        let identity = "alice".as_bytes().to_vec();
-        let ttl = <Test as frame_system::Trait>::BlockNumber::from(DEFAULT_LIFETIME);
-        assert!(Discovery::set_ipns_id(
-            Origin::signed(storage_provider_account_id),
-            storage_provider_id,
-            identity.clone(),
-        )
-        .is_ok());
-
-        assert!(<AccountInfoByStorageProviderId<Test>>::contains_key(
-            &storage_provider_id
-        ));
-        let account_info = Discovery::account_info_by_storage_provider_id(&storage_provider_id);
-        assert_eq!(
-            account_info,
-            ServiceProviderRecord {
-                identity: identity.clone(),
-                expires_at: current_block_number + ttl
-            }
-        );
-
-        assert_eq!(
-            *System::events().last().unwrap(),
-            EventRecord {
-                phase: Phase::Initialization,
-                event: MetaEvent::discovery(RawEvent::AccountInfoUpdated(
-                    storage_provider_id,
-                    identity.clone()
-                )),
-                topics: vec![]
-            }
-        );
-
-        // Invalid storage provider data
-        let invalid_storage_provider_id = 2;
-        let invalid_storage_provider_account_id = 2;
-        assert!(Discovery::set_ipns_id(
-            Origin::signed(invalid_storage_provider_id),
-            invalid_storage_provider_account_id,
-            identity.clone(),
-        )
-        .is_err());
-        assert!(!<AccountInfoByStorageProviderId<Test>>::contains_key(
-            &invalid_storage_provider_id
-        ));
-    });
-}
-
-#[test]
-fn unset_ipns_id() {
-    initial_test_ext().execute_with(|| {
-        let current_block_number = 1000;
-        System::set_block_number(current_block_number);
-
-        let (storage_provider_account_id, storage_provider_id) = hire_storage_provider();
-
-        <AccountInfoByStorageProviderId<Test>>::insert(
-            &storage_provider_id,
-            ServiceProviderRecord {
-                expires_at: 1000,
-                identity: "alice".as_bytes().to_vec(),
-            },
-        );
-
-        assert!(<AccountInfoByStorageProviderId<Test>>::contains_key(
-            &storage_provider_account_id
-        ));
-
-        assert!(Discovery::unset_ipns_id(
-            Origin::signed(storage_provider_account_id),
-            storage_provider_id
-        )
-        .is_ok());
-        assert!(!<AccountInfoByStorageProviderId<Test>>::contains_key(
-            &storage_provider_account_id
-        ));
-
-        assert_eq!(
-            *System::events().last().unwrap(),
-            EventRecord {
-                phase: Phase::Initialization,
-                event: MetaEvent::discovery(RawEvent::AccountInfoRemoved(storage_provider_id)),
-                topics: vec![]
-            }
-        );
-
-        // Invalid storage provider data
-        let invalid_storage_provider_id = 2;
-        let invalid_storage_provider_account_id = 2;
-        assert!(Discovery::unset_ipns_id(
-            Origin::signed(invalid_storage_provider_id),
-            invalid_storage_provider_account_id,
-        )
-        .is_err());
-        assert!(!<AccountInfoByStorageProviderId<Test>>::contains_key(
-            &invalid_storage_provider_id
-        ));
-    });
-}
-
-#[test]
-fn is_account_info_expired() {
-    initial_test_ext().execute_with(|| {
-        let storage_provider_id = 1;
-        let expires_at = 1000;
-        let id = "alice".as_bytes().to_vec();
-        <AccountInfoByStorageProviderId<Test>>::insert(
-            &storage_provider_id,
-            ServiceProviderRecord {
-                expires_at,
-                identity: id.clone(),
-            },
-        );
-
-        System::set_block_number(expires_at - 10);
-        assert!(!Discovery::is_account_info_expired(&storage_provider_id));
-
-        System::set_block_number(expires_at + 10);
-        assert!(Discovery::is_account_info_expired(&storage_provider_id));
-    });
-}
-
-#[test]
-fn set_default_lifetime() {
-    initial_test_ext().execute_with(|| {
-        let lifetime = <Test as frame_system::Trait>::BlockNumber::from(MINIMUM_LIFETIME + 2000);
-        // privileged method should fail if not from root origin
-        assert!(
-            Discovery::set_default_lifetime(Origin::signed(1), lifetime).is_err(),
-            ""
-        );
-        assert!(
-            Discovery::set_default_lifetime(RawOrigin::Root.into(), lifetime).is_ok(),
-            ""
-        );
-        assert_eq!(Discovery::default_lifetime(), lifetime, "");
-
-        // cannot set default lifetime to less than minimum
-        let less_than_min_lifetime =
-            <Test as frame_system::Trait>::BlockNumber::from(MINIMUM_LIFETIME - 1);
-        assert!(
-            Discovery::set_default_lifetime(RawOrigin::Root.into(), less_than_min_lifetime)
-                .is_err(),
-            ""
-        );
-    });
-}
-
-#[test]
-fn set_bootstrap_endpoints() {
-    initial_test_ext().execute_with(|| {
-        let endpoints = vec!["endpoint1".as_bytes().to_vec()];
-        // privileged method should fail if not from root origin
-        assert!(
-            Discovery::set_bootstrap_endpoints(Origin::signed(1), endpoints.clone()).is_err(),
-            ""
-        );
-        assert!(
-            Discovery::set_bootstrap_endpoints(RawOrigin::Root.into(), endpoints.clone()).is_ok(),
-            ""
-        );
-        assert_eq!(Discovery::bootstrap_endpoints(), endpoints, "");
-    });
-}

+ 0 - 43
runtime-modules/storage/Cargo.toml

@@ -1,43 +0,0 @@
-[package]
-name = 'pallet-storage'
-version = '3.1.1'
-authors = ['Joystream contributors']
-edition = '2018'
-
-[dependencies]
-serde = { version = "1.0.101", optional = true, features = ["derive"] }
-codec = { package = 'parity-scale-codec', version = '1.3.4', default-features = false, features = ['derive'] }
-sp-std = { package = 'sp-std', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '2cd20966cc09b059817c3ebe12fc130cdd850d62'}
-frame-support = { package = 'frame-support', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '2cd20966cc09b059817c3ebe12fc130cdd850d62'}
-frame-system = { package = 'frame-system', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '2cd20966cc09b059817c3ebe12fc130cdd850d62'}
-sp-arithmetic = { package = 'sp-arithmetic', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '2cd20966cc09b059817c3ebe12fc130cdd850d62'}
-sp-runtime = { package = 'sp-runtime', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '2cd20966cc09b059817c3ebe12fc130cdd850d62'}
-membership = { package = 'pallet-membership', default-features = false, path = '../membership'}
-pallet-timestamp = { package = 'pallet-timestamp', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '2cd20966cc09b059817c3ebe12fc130cdd850d62'}
-working-group = { package = 'pallet-working-group', default-features = false, path = '../working-group'}
-common = { package = 'pallet-common', default-features = false, path = '../common'}
-
-[dev-dependencies]
-sp-io = { package = 'sp-io', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '2cd20966cc09b059817c3ebe12fc130cdd850d62'}
-sp-core = { package = 'sp-core', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '2cd20966cc09b059817c3ebe12fc130cdd850d62'}
-balances = { package = 'pallet-balances', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '2cd20966cc09b059817c3ebe12fc130cdd850d62'}
-stake = { package = 'pallet-stake', default-features = false, path = '../stake'}
-hiring = { package = 'pallet-hiring', default-features = false, path = '../hiring'}
-minting = { package = 'pallet-token-mint', default-features = false, path = '../token-minting'}
-recurringrewards = { package = 'pallet-recurring-reward', default-features = false, path = '../recurring-reward'}
-
-[features]
-default = ['std']
-std = [
-	'serde',
-	'codec/std',
-	'sp-std/std',
-	'frame-support/std',
-	'frame-system/std',
-	'sp-arithmetic/std',
-	'sp-runtime/std',
-	'membership/std',
-	'pallet-timestamp/std',
-	'working-group/std',
-	'common/std',
-]

+ 0 - 370
runtime-modules/storage/src/data_directory.rs

@@ -1,370 +0,0 @@
-//! # Data directory module
-//! Data directory module for the Joystream platform manages IPFS content id, storage providers,
-//! owners of the content. It allows to add and accept or reject the content in the frame_system.
-//!
-//! ## Comments
-//!
-//! Data object type registry module uses  working group module to authorize actions.
-//!
-//! ## Supported extrinsics
-//!
-//! ### Public extrinsic
-//! - [add_content](./struct.Module.html#method.add_content) - Adds the content to the frame_system.
-//!
-//! ### Private extrinsics
-//! - accept_content - Storage provider accepts a content.
-//! - reject_content - Storage provider rejects a content.
-//! - remove_known_content_id - Removes the content id from the list of known content ids. Requires root privileges.
-//! - set_known_content_id - Sets the content id from the list of known content ids. Requires root privileges.
-//!
-
-// Do not delete! Cannot be uncommented by default, because of Parity decl_module! issue.
-//#![warn(missing_docs)]
-
-use codec::{Decode, Encode};
-use frame_support::dispatch::DispatchResult;
-use frame_support::traits::Get;
-use frame_support::{decl_error, decl_event, decl_module, decl_storage, ensure, Parameter};
-use frame_system::ensure_root;
-use sp_runtime::traits::{MaybeSerialize, Member};
-use sp_std::collections::btree_map::BTreeMap;
-use sp_std::vec::Vec;
-
-#[cfg(feature = "std")]
-use serde::{Deserialize, Serialize};
-
-use common::origin::ActorOriginValidator;
-pub(crate) use common::BlockAndTime;
-
-use crate::data_object_type_registry;
-use crate::data_object_type_registry::IsActiveDataObjectType;
-use crate::{MemberId, StorageProviderId, StorageWorkingGroup, StorageWorkingGroupInstance};
-
-/// The _Data directory_ main _Trait_.
-pub trait Trait:
-    pallet_timestamp::Trait
-    + frame_system::Trait
-    + data_object_type_registry::Trait
-    + membership::Trait
-    + working_group::Trait<StorageWorkingGroupInstance>
-{
-    /// _Data directory_ event type.
-    type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
-
-    /// Content id.
-    type ContentId: Parameter + Member + MaybeSerialize + Copy + Ord + Default;
-
-    /// Provides random storage provider id.
-    type StorageProviderHelper: StorageProviderHelper<Self>;
-
-    ///Active data object type validator.
-    type IsActiveDataObjectType: data_object_type_registry::IsActiveDataObjectType<Self>;
-
-    /// Validates member id and origin combination.
-    type MemberOriginValidator: ActorOriginValidator<Self::Origin, MemberId<Self>, Self::AccountId>;
-
-    type MaxObjectsPerInjection: Get<u32>;
-}
-
-decl_error! {
-    /// _Data object storage registry_ module predefined errors.
-    pub enum Error for Module<T: Trait>{
-        /// Content with this ID not found.
-        CidNotFound,
-
-        /// Only the liaison for the content may modify its status.
-        LiaisonRequired,
-
-        /// Cannot create content for inactive or missing data object type.
-        DataObjectTypeMustBeActive,
-
-        /// "Data object already added under this content id".
-        DataObjectAlreadyAdded,
-
-        /// Require root origin in extrinsics.
-        RequireRootOrigin,
-
-        /// DataObject Injection Failed. Too Many DataObjects.
-        DataObjectsInjectionExceededLimit
-    }
-}
-
-/// The decision of the storage provider when it acts as liaison.
-#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
-#[derive(Clone, Encode, Decode, PartialEq, Debug)]
-pub enum LiaisonJudgement {
-    /// Content awaits for a judgment.
-    Pending,
-
-    /// Content accepted.
-    Accepted,
-
-    /// Content rejected.
-    Rejected,
-}
-
-impl Default for LiaisonJudgement {
-    fn default() -> Self {
-        LiaisonJudgement::Pending
-    }
-}
-
-/// Alias for DataObjectInternal
-pub type DataObject<T> = DataObjectInternal<
-    MemberId<T>,
-    <T as frame_system::Trait>::BlockNumber,
-    <T as pallet_timestamp::Trait>::Moment,
-    <T as data_object_type_registry::Trait>::DataObjectTypeId,
-    StorageProviderId<T>,
->;
-
-/// Manages content ids, type and storage provider decision about it.
-#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
-#[derive(Clone, Encode, Decode, PartialEq, Debug)]
-pub struct DataObjectInternal<MemberId, BlockNumber, Moment, DataObjectTypeId, StorageProviderId> {
-    /// Content owner.
-    pub owner: MemberId,
-
-    /// Content added at.
-    pub added_at: BlockAndTime<BlockNumber, Moment>,
-
-    /// Content type id.
-    pub type_id: DataObjectTypeId,
-
-    /// Content size in bytes.
-    pub size: u64,
-
-    /// Storage provider id of the liaison.
-    pub liaison: StorageProviderId,
-
-    /// Storage provider as liaison judgment.
-    pub liaison_judgement: LiaisonJudgement,
-
-    /// IPFS content id.
-    pub ipfs_content_id: Vec<u8>,
-}
-
-/// A map collection of unique DataObjects keyed by the ContentId
-pub type DataObjectsMap<T> = BTreeMap<<T as Trait>::ContentId, DataObject<T>>;
-
-decl_storage! {
-    trait Store for Module<T: Trait> as DataDirectory {
-        /// List of ids known to the frame_system.
-        pub KnownContentIds get(fn known_content_ids) config(): Vec<T::ContentId> = Vec::new();
-
-        /// Maps data objects by their content id.
-        pub DataObjectByContentId get(fn data_object_by_content_id) config():
-            map hasher(blake2_128_concat) T::ContentId => Option<DataObject<T>>;
-    }
-}
-
-decl_event! {
-    /// _Data directory_ events
-    pub enum Event<T> where
-        <T as Trait>::ContentId,
-        MemberId = MemberId<T>,
-        StorageProviderId = StorageProviderId<T>
-    {
-        /// Emits on adding of the content.
-        /// Params:
-        /// - Id of the relationship.
-        /// - Id of the member.
-        ContentAdded(ContentId, MemberId),
-
-        /// Emits when the storage provider accepts a content.
-        /// Params:
-        /// - Id of the relationship.
-        /// - Id of the storage provider.
-        ContentAccepted(ContentId, StorageProviderId),
-
-        /// Emits when the storage provider rejects a content.
-        /// Params:
-        /// - Id of the relationship.
-        /// - Id of the storage provider.
-        ContentRejected(ContentId, StorageProviderId),
-    }
-}
-
-decl_module! {
-    /// _Data directory_ substrate module.
-    pub struct Module<T: Trait> for enum Call where origin: T::Origin {
-        /// Default deposit_event() handler
-        fn deposit_event() = default;
-
-        /// Predefined errors.
-        type Error = Error<T>;
-
-        /// Maximum objects allowed per inject_data_objects() transaction
-        const MaxObjectsPerInjection: u32 = T::MaxObjectsPerInjection::get();
-
-        /// Adds the content to the frame_system. Member id should match its origin. The created DataObject
-        /// awaits liaison to accept or reject it.
-        #[weight = 10_000_000] // TODO: adjust weight
-        pub fn add_content(
-            origin,
-            member_id: MemberId<T>,
-            content_id: T::ContentId,
-            type_id: <T as data_object_type_registry::Trait>::DataObjectTypeId,
-            size: u64,
-            ipfs_content_id: Vec<u8>
-        ) {
-            T::MemberOriginValidator::ensure_actor_origin(
-                origin,
-                member_id,
-            )?;
-
-            ensure!(T::IsActiveDataObjectType::is_active_data_object_type(&type_id),
-                Error::<T>::DataObjectTypeMustBeActive);
-
-            ensure!(!<DataObjectByContentId<T>>::contains_key(content_id),
-                Error::<T>::DataObjectAlreadyAdded);
-
-            let liaison = T::StorageProviderHelper::get_random_storage_provider()?;
-
-            // Let's create the entry then
-            let data: DataObject<T> = DataObjectInternal {
-                type_id,
-                size,
-                added_at: common::current_block_time::<T>(),
-                owner: member_id,
-                liaison,
-                liaison_judgement: LiaisonJudgement::Pending,
-                ipfs_content_id,
-            };
-
-            //
-            // == MUTATION SAFE ==
-            //
-
-            <DataObjectByContentId<T>>::insert(&content_id, data);
-            Self::deposit_event(RawEvent::ContentAdded(content_id, member_id));
-        }
-
-        /// Storage provider accepts a content. Requires signed storage provider account and its id.
-        /// The LiaisonJudgement can be updated, but only by the liaison.
-        #[weight = 10_000_000] // TODO: adjust weight
-        pub(crate) fn accept_content(
-            origin,
-            storage_provider_id: StorageProviderId<T>,
-            content_id: T::ContentId
-        ) {
-            <StorageWorkingGroup<T>>::ensure_worker_signed(origin, &storage_provider_id)?;
-
-            // == MUTATION SAFE ==
-
-            Self::update_content_judgement(&storage_provider_id, content_id, LiaisonJudgement::Accepted)?;
-
-            <KnownContentIds<T>>::mutate(|ids| ids.push(content_id));
-
-            Self::deposit_event(RawEvent::ContentAccepted(content_id, storage_provider_id));
-        }
-
-        /// Storage provider rejects a content. Requires signed storage provider account and its id.
-        /// The LiaisonJudgement can be updated, but only by the liaison.
-        #[weight = 10_000_000] // TODO: adjust weight
-        pub(crate) fn reject_content(
-            origin,
-            storage_provider_id: StorageProviderId<T>,
-            content_id: T::ContentId
-        ) {
-            <StorageWorkingGroup<T>>::ensure_worker_signed(origin, &storage_provider_id)?;
-
-            // == MUTATION SAFE ==
-
-            Self::update_content_judgement(&storage_provider_id, content_id, LiaisonJudgement::Rejected)?;
-            Self::deposit_event(RawEvent::ContentRejected(content_id, storage_provider_id));
-        }
-
-        // Sudo methods
-
-        /// Removes the content id from the list of known content ids. Requires root privileges.
-        #[weight = 10_000_000] // TODO: adjust weight
-        fn remove_known_content_id(origin, content_id: T::ContentId) {
-            ensure_root(origin)?;
-
-            // == MUTATION SAFE ==
-
-            let upd_content_ids: Vec<T::ContentId> = Self::known_content_ids()
-                .into_iter()
-                .filter(|&id| id != content_id)
-                .collect();
-            <KnownContentIds<T>>::put(upd_content_ids);
-        }
-
-        /// Injects a set of data objects and their corresponding content id into the directory.
-        /// The operation is "silent" - no events will be emitted as objects are added.
-        /// The number of objects that can be added per call is limited to prevent the dispatch
-        /// from causing the block production to fail if it takes too much time to process.
-        /// Existing data objects will be overwritten.
-        #[weight = 10_000_000] // TODO: adjust weight
-        pub(crate) fn inject_data_objects(origin, objects: DataObjectsMap<T>) {
-            ensure_root(origin)?;
-
-            // Must provide something to inject
-            ensure!(objects.len() <= T::MaxObjectsPerInjection::get() as usize, Error::<T>::DataObjectsInjectionExceededLimit);
-
-            for (id, object) in objects.into_iter() {
-                // append to known content ids
-                // duplicates will be removed at the end
-                <KnownContentIds<T>>::mutate(|ids| ids.push(id));
-                <DataObjectByContentId<T>>::insert(id, object);
-            }
-
-            // remove duplicate ids
-            <KnownContentIds<T>>::mutate(|ids| {
-                ids.sort();
-                ids.dedup();
-            });
-        }
-    }
-}
-
-impl<T: Trait> Module<T> {
-    fn update_content_judgement(
-        storage_provider_id: &StorageProviderId<T>,
-        content_id: T::ContentId,
-        judgement: LiaisonJudgement,
-    ) -> DispatchResult {
-        let mut data =
-            Self::data_object_by_content_id(&content_id).ok_or(Error::<T>::CidNotFound)?;
-
-        // Make sure the liaison matches
-        ensure!(
-            data.liaison == *storage_provider_id,
-            Error::<T>::LiaisonRequired
-        );
-
-        data.liaison_judgement = judgement;
-        <DataObjectByContentId<T>>::insert(content_id, data);
-
-        Ok(())
-    }
-}
-
-/// Provides random storage provider id. We use it when assign the content to the storage provider.
-pub trait StorageProviderHelper<T: Trait> {
-    /// Provides random storage provider id.
-    fn get_random_storage_provider() -> Result<StorageProviderId<T>, &'static str>;
-}
-
-/// Content access helper.
-pub trait ContentIdExists<T: Trait> {
-    /// Verifies the content existence.
-    fn has_content(id: &T::ContentId) -> bool;
-
-    /// Returns the data object for the provided content id.
-    fn get_data_object(id: &T::ContentId) -> Result<DataObject<T>, &'static str>;
-}
-
-impl<T: Trait> ContentIdExists<T> for Module<T> {
-    fn has_content(content_id: &T::ContentId) -> bool {
-        Self::data_object_by_content_id(*content_id).is_some()
-    }
-
-    fn get_data_object(content_id: &T::ContentId) -> Result<DataObject<T>, &'static str> {
-        match Self::data_object_by_content_id(*content_id) {
-            Some(data) => Ok(data),
-            None => Err(Error::<T>::LiaisonRequired.into()),
-        }
-    }
-}

+ 0 - 234
runtime-modules/storage/src/data_object_storage_registry.rs

@@ -1,234 +0,0 @@
-//! # Data object storage registry module
-//! Data object storage registry module for the Joystream platform allows to set relationships
-//! between the content and the storage providers. All extrinsics require storage working group registration.
-//!
-//! ## Comments
-//!
-//! Data object storage registry module uses  working group module to authorize actions.
-//! Only registered storage providers can call extrinsics.
-//!
-//! ## Supported extrinsics
-//!
-//! - [add_relationship](./struct.Module.html#method.add_relationship) - Add storage provider-to-content relationship.
-//! - [set_relationship_ready](./struct.Module.html#method.set_relationship_ready)- Activates storage provider-to-content relationship.
-//! - [unset_relationship_ready](./struct.Module.html#method.unset_relationship_ready) - Deactivates storage provider-to-content relationship.
-//!
-
-// Clippy linter requirement.
-// Disable it because of the substrate lib design. Example:
-// pub NextRelationshipId get(next_relationship_id) build(|config: &GenesisConfig<T>|
-#![allow(clippy::redundant_closure_call)]
-
-// Do not delete! Cannot be uncommented by default, because of Parity decl_module! issue.
-//#![warn(missing_docs)]
-
-use codec::{Codec, Decode, Encode};
-use frame_support::dispatch::DispatchResult;
-use frame_support::{decl_error, decl_event, decl_module, decl_storage, ensure, Parameter};
-use sp_arithmetic::traits::BaseArithmetic;
-use sp_runtime::traits::{MaybeSerialize, Member};
-use sp_std::vec::Vec;
-
-use crate::data_directory::{self, ContentIdExists};
-use crate::{StorageProviderId, StorageWorkingGroup, StorageWorkingGroupInstance};
-
-const DEFAULT_FIRST_RELATIONSHIP_ID: u8 = 1;
-
-/// The _Data object storage registry_ main _Trait_.
-pub trait Trait:
-    pallet_timestamp::Trait
-    + frame_system::Trait
-    + data_directory::Trait
-    + working_group::Trait<StorageWorkingGroupInstance>
-{
-    /// _Data object storage registry_ event type.
-    type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
-
-    /// Type for data object storage relationship id
-    type DataObjectStorageRelationshipId: Parameter
-        + Member
-        + BaseArithmetic
-        + Codec
-        + Default
-        + Copy
-        + MaybeSerialize
-        + PartialEq;
-
-    /// Ensures that a content exists
-    type ContentIdExists: data_directory::ContentIdExists<Self>;
-}
-
-decl_error! {
-    /// _Data object storage registry_ module predefined errors
-    pub enum Error for Module<T: Trait>{
-        /// Content with this ID not found.
-        CidNotFound,
-
-        /// No data object storage relationship found for this ID.
-        DataObjectStorageRelationshipNotFound,
-
-        /// Only the storage provider in a DOSR can decide whether they're ready.
-        OnlyStorageProviderMayClaimReady,
-
-        /// Require root origin in extrinsics
-        RequireRootOrigin,
-    }
-}
-
-/// Defines a relationship between the content and the storage provider
-#[derive(Clone, Encode, Decode, PartialEq, Debug)]
-pub struct DataObjectStorageRelationship<T: Trait> {
-    /// Content id.
-    pub content_id: <T as data_directory::Trait>::ContentId,
-
-    /// Storge provider id.
-    pub storage_provider_id: StorageProviderId<T>,
-
-    /// Active state (True=Active)
-    pub ready: bool,
-}
-
-decl_storage! {
-    trait Store for Module<T: Trait> as DataObjectStorageRegistry {
-
-        /// Defines first relationship id.
-        pub FirstRelationshipId get(fn first_relationship_id) config(first_relationship_id):
-            T::DataObjectStorageRelationshipId = T::DataObjectStorageRelationshipId::from(DEFAULT_FIRST_RELATIONSHIP_ID);
-
-        /// Defines next relationship id.
-        pub NextRelationshipId get(fn next_relationship_id) build(|config: &GenesisConfig<T>| config.first_relationship_id): T::DataObjectStorageRelationshipId = T::DataObjectStorageRelationshipId::from(DEFAULT_FIRST_RELATIONSHIP_ID);
-
-        /// Mapping of Data object types
-        pub Relationships get(fn relationships): map hasher(blake2_128_concat)
-            T::DataObjectStorageRelationshipId => Option<DataObjectStorageRelationship<T>>;
-
-        /// Keeps a list of storage relationships per content id.
-        pub RelationshipsByContentId get(fn relationships_by_content_id): map hasher(blake2_128_concat)
-            T::ContentId => Vec<T::DataObjectStorageRelationshipId>;
-    }
-}
-
-decl_event! {
-    /// _Data object storage registry_ events
-    pub enum Event<T> where
-        <T as data_directory::Trait>::ContentId,
-        <T as Trait>::DataObjectStorageRelationshipId,
-        StorageProviderId = StorageProviderId<T>
-    {
-        /// Emits on adding of the data object storage relationship.
-        /// Params:
-        /// - Id of the relationship.
-        /// - Id of the content.
-        /// - Id of the storage provider.
-        DataObjectStorageRelationshipAdded(DataObjectStorageRelationshipId, ContentId, StorageProviderId),
-
-        /// Emits on adding of the data object storage relationship.
-        /// Params:
-        /// - Id of the relationship.
-        /// - Current state of the relationship (True=Active).
-        DataObjectStorageRelationshipReadyUpdated(DataObjectStorageRelationshipId, bool),
-    }
-}
-
-decl_module! {
-    /// _Data object storage registry_ substrate module.
-    pub struct Module<T: Trait> for enum Call where origin: T::Origin {
-        /// Default deposit_event() handler.
-        fn deposit_event() = default;
-
-        /// Predefined errors.
-        type Error = Error<T>;
-
-        /// Add storage provider-to-content relationship. The storage provider should be registered
-        /// in the storage working group.
-        #[weight = 10_000_000] // TODO: adjust weight
-        pub fn add_relationship(origin, storage_provider_id: StorageProviderId<T>, cid: T::ContentId) {
-            // Origin should match storage provider.
-            <StorageWorkingGroup<T>>::ensure_worker_signed(origin, &storage_provider_id)?;
-
-            // Content ID must exist
-            ensure!(T::ContentIdExists::has_content(&cid), Error::<T>::CidNotFound);
-
-            // Create new ID, data.
-            let new_id = Self::next_relationship_id();
-            let dosr: DataObjectStorageRelationship<T> = DataObjectStorageRelationship {
-                content_id: cid,
-                storage_provider_id,
-                ready: false,
-            };
-
-            //
-            // == MUTATION SAFE ==
-            //
-
-            <Relationships<T>>::insert(new_id, dosr);
-            <NextRelationshipId<T>>::mutate(|n| {
-                *n += T::DataObjectStorageRelationshipId::from(1);
-            });
-
-            // Also add the DOSR to the list of DOSRs for the CID. Uniqueness is guaranteed
-            // by the map, so we can just append the new_id to the list.
-            let mut dosr_list = Self::relationships_by_content_id(cid);
-            dosr_list.push(new_id);
-            <RelationshipsByContentId<T>>::insert(cid, dosr_list);
-
-            // Emit event
-            Self::deposit_event(
-                RawEvent::DataObjectStorageRelationshipAdded(new_id, cid, storage_provider_id)
-            );
-        }
-
-        /// Activates storage provider-to-content relationship. The storage provider should be registered
-        /// in the storage working group. A storage provider may flip their own ready state, but nobody else.
-        #[weight = 10_000_000] // TODO: adjust weight
-        pub fn set_relationship_ready(
-            origin,
-            storage_provider_id: StorageProviderId<T>,
-            id: T::DataObjectStorageRelationshipId
-        ) {
-            Self::toggle_dosr_ready(origin, storage_provider_id, id, true)?;
-        }
-
-        /// Deactivates storage provider-to-content relationship. The storage provider should be registered
-        /// in the storage working group. A storage provider may flip their own ready state, but nobody else.
-        #[weight = 10_000_000] // TODO: adjust weight
-        pub fn unset_relationship_ready(
-            origin,
-            storage_provider_id: StorageProviderId<T>,
-            id: T::DataObjectStorageRelationshipId
-        ) {
-            Self::toggle_dosr_ready(origin, storage_provider_id, id, false)?;
-        }
-    }
-}
-
-impl<T: Trait> Module<T> {
-    fn toggle_dosr_ready(
-        origin: T::Origin,
-        storage_provider_id: StorageProviderId<T>,
-        id: T::DataObjectStorageRelationshipId,
-        ready: bool,
-    ) -> DispatchResult {
-        <StorageWorkingGroup<T>>::ensure_worker_signed(origin, &storage_provider_id)?;
-
-        // For that, we need to fetch the identified DOSR
-        let mut dosr =
-            Self::relationships(id).ok_or(Error::<T>::DataObjectStorageRelationshipNotFound)?;
-
-        ensure!(
-            dosr.storage_provider_id == storage_provider_id,
-            Error::<T>::OnlyStorageProviderMayClaimReady
-        );
-
-        // Flip to ready
-        dosr.ready = ready;
-
-        // Update DOSR and fire event.
-        <Relationships<T>>::insert(id, dosr);
-        Self::deposit_event(RawEvent::DataObjectStorageRelationshipReadyUpdated(
-            id, ready,
-        ));
-
-        Ok(())
-    }
-}

+ 0 - 235
runtime-modules/storage/src/data_object_type_registry.rs

@@ -1,235 +0,0 @@
-//! # Data object type registry module
-//! Data object type registry module for the Joystream platform allows to set constraints for the data objects. All extrinsics require leader.
-//!
-//! ## Comments
-//!
-//! Data object type registry module uses  working group module to authorize actions. Only leader can
-//! call extrinsics.
-//!
-//! ## Supported extrinsics
-//!
-//! - [register_data_object_type](./struct.Module.html#method.register_data_object_type) - Registers the new data object type.
-//! - [update_data_object_type](./struct.Module.html#method.update_data_object_type)- Updates existing data object type.
-//! - [activate_data_object_type](./struct.Module.html#method.activate_data_object_type) -  Activates existing data object type.
-//! - [deactivate_data_object_type](./struct.Module.html#method.deactivate_data_object_type) -  Deactivates existing data object type.
-//!
-
-// Clippy linter requirement.
-// Disable it because of the substrate lib design. Example:
-//   NextDataObjectTypeId get(next_data_object_type_id) build(|config: &GenesisConfig<T>|
-#![allow(clippy::redundant_closure_call)]
-
-// Do not delete! Cannot be uncommented by default, because of Parity decl_module! issue.
-//#![warn(missing_docs)]
-
-use codec::{Codec, Decode, Encode};
-use frame_support::dispatch::DispatchError;
-use frame_support::weights::Weight;
-use frame_support::{decl_error, decl_event, decl_module, decl_storage, Parameter};
-use sp_arithmetic::traits::BaseArithmetic;
-use sp_runtime::traits::{MaybeSerialize, Member};
-use sp_std::vec::Vec;
-
-use crate::{StorageWorkingGroup, StorageWorkingGroupInstance};
-
-const DEFAULT_TYPE_DESCRIPTION: &str = "Default data object type for audio and video content.";
-const DEFAULT_FIRST_DATA_OBJECT_TYPE_ID: u8 = 1;
-
-/// The _Data object type registry_ main _Trait_.
-pub trait Trait: frame_system::Trait + working_group::Trait<StorageWorkingGroupInstance> {
-    /// _Data object type registry_ event type.
-    type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
-
-    /// _Data object type id_ type
-    type DataObjectTypeId: Parameter
-        + Member
-        + BaseArithmetic
-        + Codec
-        + Default
-        + Copy
-        + MaybeSerialize
-        + PartialEq;
-}
-
-decl_error! {
-    /// _Data object type registry_ module predefined errors
-    pub enum Error for Module<T: Trait> {
-        /// Data Object Type with the given ID not found.
-        DataObjectTypeNotFound,
-
-        /// Require root origin in extrinsics
-        RequireRootOrigin,
-    }
-}
-
-/// Contains description and constrains for the data object.
-#[derive(Clone, Encode, Decode, PartialEq, Debug)]
-pub struct DataObjectType {
-    /// Data object description.
-    pub description: Vec<u8>,
-
-    /// Active/Disabled flag.
-    pub active: bool,
-}
-
-impl Default for DataObjectType {
-    fn default() -> Self {
-        DataObjectType {
-            description: DEFAULT_TYPE_DESCRIPTION.as_bytes().to_vec(),
-            active: true,
-        }
-    }
-}
-
-decl_storage! {
-    trait Store for Module<T: Trait> as DataObjectTypeRegistry {
-        /// Data object type ids should start at this value.
-        pub FirstDataObjectTypeId get(fn first_data_object_type_id) config(first_data_object_type_id):
-            T::DataObjectTypeId = T::DataObjectTypeId::from(DEFAULT_FIRST_DATA_OBJECT_TYPE_ID);
-
-        /// Provides id counter for the data object types.
-        pub NextDataObjectTypeId get(fn next_data_object_type_id) build(|config: &GenesisConfig<T>|
-            config.first_data_object_type_id): T::DataObjectTypeId = T::DataObjectTypeId::from(DEFAULT_FIRST_DATA_OBJECT_TYPE_ID);
-
-        /// Mapping of Data object types.
-        pub DataObjectTypes get(fn data_object_types): map hasher(blake2_128_concat)
-            T::DataObjectTypeId => Option<DataObjectType>;
-    }
-}
-
-decl_event! {
-    /// _Data object type registry_ events
-    pub enum Event<T> where
-        <T as Trait>::DataObjectTypeId {
-        /// Emits on the data object type registration.
-        /// Params:
-        /// - Id of the new data object type.
-        DataObjectTypeRegistered(DataObjectTypeId),
-
-        /// Emits on the data object type update.
-        /// Params:
-        /// - Id of the updated data object type.
-        DataObjectTypeUpdated(DataObjectTypeId),
-    }
-}
-
-decl_module! {
-    /// _Data object type registry_ substrate module.
-    pub struct Module<T: Trait> for enum Call where origin: T::Origin {
-        /// Default deposit_event() handler
-        fn deposit_event() = default;
-
-        /// Predefined errors
-        type Error = Error<T>;
-
-        fn on_initialize() -> Weight{
-            // Create a default data object type if it was not created yet.
-            if !<DataObjectTypes<T>>::contains_key(Self::first_data_object_type_id()) {
-                let do_type: DataObjectType = DataObjectType::default();
-                let new_type_id = Self::next_data_object_type_id();
-
-                <DataObjectTypes<T>>::insert(new_type_id, do_type);
-                <NextDataObjectTypeId<T>>::mutate(|n| { *n += T::DataObjectTypeId::from(1); });
-            }
-
-            10_000_000 //TODO: adjust weight
-        }
-
-        /// Registers the new data object type. Requires leader privileges.
-        #[weight = 10_000_000] // TODO: adjust weight
-        pub fn register_data_object_type(origin, data_object_type: DataObjectType) {
-            <StorageWorkingGroup<T>>::ensure_origin_is_active_leader(origin)?;
-
-            let new_do_type_id = Self::next_data_object_type_id();
-            let do_type: DataObjectType = DataObjectType {
-                description: data_object_type.description.clone(),
-                active: data_object_type.active,
-            };
-
-            //
-            // == MUTATION SAFE ==
-            //
-
-            <DataObjectTypes<T>>::insert(new_do_type_id, do_type);
-            <NextDataObjectTypeId<T>>::mutate(|n| { *n += T::DataObjectTypeId::from(1); });
-
-            Self::deposit_event(RawEvent::DataObjectTypeRegistered(new_do_type_id));
-        }
-
-        /// Updates existing data object type. Requires leader privileges.
-        #[weight = 10_000_000] // TODO: adjust weight
-        pub fn update_data_object_type(origin, id: T::DataObjectTypeId, data_object_type: DataObjectType) {
-            <StorageWorkingGroup<T>>::ensure_origin_is_active_leader(origin)?;
-
-            let mut do_type = Self::ensure_data_object_type(id)?;
-
-            do_type.description = data_object_type.description.clone();
-            do_type.active = data_object_type.active;
-
-            //
-            // == MUTATION SAFE ==
-            //
-
-            <DataObjectTypes<T>>::insert(id, do_type);
-
-            Self::deposit_event(RawEvent::DataObjectTypeUpdated(id));
-        }
-
-        /// Activates existing data object type. Requires leader privileges.
-        #[weight = 10_000_000] // TODO: adjust weight
-        pub fn activate_data_object_type(origin, id: T::DataObjectTypeId) {
-            <StorageWorkingGroup<T>>::ensure_origin_is_active_leader(origin)?;
-
-            let mut do_type = Self::ensure_data_object_type(id)?;
-
-            do_type.active = true;
-
-            //
-            // == MUTATION SAFE ==
-            //
-
-            <DataObjectTypes<T>>::insert(id, do_type);
-
-            Self::deposit_event(RawEvent::DataObjectTypeUpdated(id));
-        }
-
-        /// Deactivates existing data object type. Requires leader privileges.
-        #[weight = 10_000_000] // TODO: adjust weight
-        pub fn deactivate_data_object_type(origin, id: T::DataObjectTypeId) {
-            <StorageWorkingGroup<T>>::ensure_origin_is_active_leader(origin)?;
-
-            let mut do_type = Self::ensure_data_object_type(id)?;
-
-            do_type.active = false;
-
-            //
-            // == MUTATION SAFE ==
-            //
-
-            <DataObjectTypes<T>>::insert(id, do_type);
-
-            Self::deposit_event(RawEvent::DataObjectTypeUpdated(id));
-        }
-    }
-}
-
-impl<T: Trait> Module<T> {
-    fn ensure_data_object_type(id: T::DataObjectTypeId) -> Result<DataObjectType, DispatchError> {
-        Self::data_object_types(&id).ok_or_else(|| Error::<T>::DataObjectTypeNotFound.into())
-    }
-}
-
-/// Active data object type validator trait.
-pub trait IsActiveDataObjectType<T: Trait> {
-    /// Ensures that data object type with given id is active.
-    fn is_active_data_object_type(id: &T::DataObjectTypeId) -> bool;
-}
-
-impl<T: Trait> IsActiveDataObjectType<T> for Module<T> {
-    fn is_active_data_object_type(id: &T::DataObjectTypeId) -> bool {
-        match Self::ensure_data_object_type(*id) {
-            Ok(do_type) => do_type.active,
-            Err(_err) => false,
-        }
-    }
-}

+ 0 - 20
runtime-modules/storage/src/lib.rs

@@ -1,20 +0,0 @@
-// Ensure we're `no_std` when compiling for Wasm.
-#![cfg_attr(not(feature = "std"), no_std)]
-
-pub mod data_directory;
-pub mod data_object_storage_registry;
-pub mod data_object_type_registry;
-
-mod tests;
-
-// The storage working group instance alias.
-pub type StorageWorkingGroupInstance = working_group::Instance2;
-
-// Alias for storage working group
-pub(crate) type StorageWorkingGroup<T> = working_group::Module<T, StorageWorkingGroupInstance>;
-
-// Alias for the member id.
-pub(crate) type MemberId<T> = <T as membership::Trait>::MemberId;
-
-/// Storage provider is a worker from the working group module.
-pub type StorageProviderId<T> = working_group::WorkerId<T>;

+ 0 - 325
runtime-modules/storage/src/tests/data_directory.rs

@@ -1,325 +0,0 @@
-#![cfg(test)]
-
-use frame_support::dispatch::DispatchError;
-use frame_system::RawOrigin;
-use sp_std::collections::btree_map::BTreeMap;
-
-use super::mock::*;
-
-#[test]
-fn succeed_adding_content() {
-    with_default_mock_builder(|| {
-        let sender = 1u64;
-        let member_id = 1u64;
-        // Register a content with 1234 bytes of type 1, which should be recognized.
-        let res = TestDataDirectory::add_content(
-            Origin::signed(sender),
-            member_id,
-            1,
-            1234,
-            0,
-            vec![1, 3, 3, 7],
-        );
-        assert!(res.is_ok());
-    });
-}
-
-#[test]
-fn add_content_fails_with_invalid_origin() {
-    with_default_mock_builder(|| {
-        let member_id = 1u64;
-        // Register a content with 1234 bytes of type 1, which should be recognized.
-        let res = TestDataDirectory::add_content(
-            RawOrigin::Root.into(),
-            member_id,
-            1,
-            1234,
-            0,
-            vec![1, 3, 3, 7],
-        );
-        assert_eq!(res, Err(DispatchError::Other("Bad origin")));
-    });
-}
-
-#[test]
-fn accept_and_reject_content_fail_with_invalid_storage_provider() {
-    with_default_mock_builder(|| {
-        /*
-           Events are not emitted on block 0.
-           So any dispatchable calls made during genesis block formation will have no events emitted.
-           https://substrate.dev/recipes/2-appetizers/4-events.html
-        */
-        run_to_block(1);
-
-        let sender = 1u64;
-        let member_id = 1u64;
-
-        let res = TestDataDirectory::add_content(
-            Origin::signed(sender),
-            member_id,
-            1,
-            1234,
-            0,
-            vec![1, 2, 3, 4],
-        );
-        assert!(res.is_ok());
-
-        let (content_id, _) = match System::events().last().unwrap().event {
-            MetaEvent::data_directory(data_directory::RawEvent::ContentAdded(
-                content_id,
-                creator,
-            )) => (content_id, creator),
-            _ => (0u64, 0xdeadbeefu64), // invalid value, unlikely to match
-        };
-
-        //  invalid data
-        let (storage_provider_account_id, storage_provider_id) = (1, 5);
-
-        let res = TestDataDirectory::accept_content(
-            Origin::signed(storage_provider_account_id),
-            storage_provider_id,
-            content_id,
-        );
-        assert_eq!(res, Err(working_group::Error::<Test, crate::StorageWorkingGroupInstance>::WorkerDoesNotExist.into()));
-
-        let res = TestDataDirectory::reject_content(
-            Origin::signed(storage_provider_account_id),
-            storage_provider_id,
-            content_id,
-        );
-        assert_eq!(res, Err(working_group::Error::<Test, crate::StorageWorkingGroupInstance>::WorkerDoesNotExist.into()));
-    });
-}
-
-#[test]
-fn accept_content_as_liaison() {
-    with_default_mock_builder(|| {
-        /*
-           Events are not emitted on block 0.
-           So any dispatchable calls made during genesis block formation will have no events emitted.
-           https://substrate.dev/recipes/2-appetizers/4-events.html
-        */
-        run_to_block(1);
-
-        let sender = 1u64;
-        let member_id = 1u64;
-
-        let res = TestDataDirectory::add_content(
-            Origin::signed(sender),
-            member_id,
-            1,
-            1234,
-            0,
-            vec![1, 2, 3, 4],
-        );
-        assert!(res.is_ok());
-
-        // An appropriate event should have been fired.
-        let (content_id, creator) = match System::events().last().unwrap().event {
-            MetaEvent::data_directory(data_directory::RawEvent::ContentAdded(
-                content_id,
-                creator,
-            )) => (content_id, creator),
-            _ => (0u64, 0xdeadbeefu64), // invalid value, unlikely to match
-        };
-        assert_ne!(creator, 0xdeadbeefu64);
-        assert_eq!(creator, sender);
-
-        let (storage_provider_account_id, storage_provider_id) = hire_storage_provider();
-
-        // Accepting content should not work with some random origin
-        let res =
-            TestDataDirectory::accept_content(Origin::signed(55), storage_provider_id, content_id);
-        assert!(res.is_err());
-
-        // However, with the liaison as origin it should.
-        let res = TestDataDirectory::accept_content(
-            Origin::signed(storage_provider_account_id),
-            storage_provider_id,
-            content_id,
-        );
-        assert_eq!(res, Ok(()));
-    });
-}
-
-#[test]
-fn reject_content_as_liaison() {
-    with_default_mock_builder(|| {
-        /*
-           Events are not emitted on block 0.
-           So any dispatchable calls made during genesis block formation will have no events emitted.
-           https://substrate.dev/recipes/2-appetizers/4-events.html
-        */
-        run_to_block(1);
-
-        let sender = 1u64;
-        let member_id = 1u64;
-
-        let res = TestDataDirectory::add_content(
-            Origin::signed(sender),
-            member_id,
-            1,
-            1234,
-            0,
-            vec![1, 2, 3, 4],
-        );
-        assert!(res.is_ok());
-
-        // An appropriate event should have been fired.
-        let (content_id, creator) = match System::events().last().unwrap().event {
-            MetaEvent::data_directory(data_directory::RawEvent::ContentAdded(
-                content_id,
-                creator,
-            )) => (content_id, creator),
-            _ => (0u64, 0xdeadbeefu64), // invalid value, unlikely to match
-        };
-        assert_ne!(creator, 0xdeadbeefu64);
-        assert_eq!(creator, sender);
-
-        let (storage_provider_account_id, storage_provider_id) = hire_storage_provider();
-
-        // Rejecting content should not work with some random origin
-        let res =
-            TestDataDirectory::reject_content(Origin::signed(55), storage_provider_id, content_id);
-        assert!(res.is_err());
-
-        // However, with the liaison as origin it should.
-        let res = TestDataDirectory::reject_content(
-            Origin::signed(storage_provider_account_id),
-            storage_provider_id,
-            content_id,
-        );
-        assert_eq!(res, Ok(()));
-    });
-}
-
-#[test]
-fn data_object_injection_works() {
-    with_default_mock_builder(|| {
-        // No objects in directory before injection
-        assert_eq!(
-            TestDataDirectory::known_content_ids(),
-            Vec::<<Test as data_directory::Trait>::ContentId>::new()
-        );
-
-        // new objects to inject into the directory
-        let mut objects = BTreeMap::new();
-
-        let object = data_directory::DataObjectInternal {
-            type_id: 1,
-            size: 1234,
-            added_at: data_directory::BlockAndTime {
-                block: 10,
-                time: 1024,
-            },
-            owner: 1,
-            liaison: TEST_MOCK_LIAISON_STORAGE_PROVIDER_ID,
-            liaison_judgement: data_directory::LiaisonJudgement::Pending,
-            ipfs_content_id: vec![],
-        };
-
-        let content_id_1 = 1;
-        objects.insert(content_id_1, object.clone());
-
-        let content_id_2 = 2;
-        objects.insert(content_id_2, object.clone());
-
-        let res = TestDataDirectory::inject_data_objects(RawOrigin::Root.into(), objects);
-        assert!(res.is_ok());
-
-        assert_eq!(
-            TestDataDirectory::known_content_ids(),
-            vec![content_id_1, content_id_2]
-        );
-
-        assert_eq!(
-            TestDataDirectory::data_object_by_content_id(content_id_1),
-            Some(object.clone())
-        );
-
-        assert_eq!(
-            TestDataDirectory::data_object_by_content_id(content_id_2),
-            Some(object)
-        );
-    });
-}
-
-#[test]
-fn data_object_injection_overwrites_and_removes_duplicate_ids() {
-    with_default_mock_builder(|| {
-        let sender = 1u64;
-        let member_id = 1u64;
-        let content_id_1 = 1;
-        let content_id_2 = 2;
-
-        // Start with some existing objects in directory which will be
-        // overwritten
-        let res = TestDataDirectory::add_content(
-            Origin::signed(sender),
-            member_id,
-            content_id_1,
-            1,
-            10,
-            vec![8, 8, 8, 8],
-        );
-        assert!(res.is_ok());
-        let res = TestDataDirectory::add_content(
-            Origin::signed(sender),
-            member_id,
-            content_id_2,
-            2,
-            20,
-            vec![9, 9, 9, 9],
-        );
-        assert!(res.is_ok());
-
-        let mut objects = BTreeMap::new();
-
-        let object1 = data_directory::DataObjectInternal {
-            type_id: 1,
-            size: 6666,
-            added_at: data_directory::BlockAndTime {
-                block: 10,
-                time: 1000,
-            },
-            owner: 5,
-            liaison: TEST_MOCK_LIAISON_STORAGE_PROVIDER_ID,
-            liaison_judgement: data_directory::LiaisonJudgement::Pending,
-            ipfs_content_id: vec![5, 6, 7],
-        };
-
-        let object2 = data_directory::DataObjectInternal {
-            type_id: 1,
-            size: 7777,
-            added_at: data_directory::BlockAndTime {
-                block: 20,
-                time: 2000,
-            },
-            owner: 6,
-            liaison: TEST_MOCK_LIAISON_STORAGE_PROVIDER_ID,
-            liaison_judgement: data_directory::LiaisonJudgement::Pending,
-            ipfs_content_id: vec![5, 6, 7],
-        };
-
-        objects.insert(content_id_1, object1.clone());
-        objects.insert(content_id_2, object2.clone());
-
-        let res = TestDataDirectory::inject_data_objects(RawOrigin::Root.into(), objects);
-        assert!(res.is_ok());
-
-        assert_eq!(
-            TestDataDirectory::known_content_ids(),
-            vec![content_id_1, content_id_2]
-        );
-
-        assert_eq!(
-            TestDataDirectory::data_object_by_content_id(content_id_1),
-            Some(object1.clone())
-        );
-
-        assert_eq!(
-            TestDataDirectory::data_object_by_content_id(content_id_2),
-            Some(object2)
-        );
-    });
-}

+ 0 - 164
runtime-modules/storage/src/tests/data_object_storage_registry.rs

@@ -1,164 +0,0 @@
-#![cfg(test)]
-
-use super::mock::*;
-
-#[test]
-fn initial_state() {
-    with_default_mock_builder(|| {
-        assert_eq!(
-            TestDataObjectStorageRegistry::first_relationship_id(),
-            TEST_FIRST_RELATIONSHIP_ID
-        );
-    });
-}
-
-#[test]
-fn add_relationship_fails_with_invalid_authorization() {
-    with_default_mock_builder(|| {
-        let (account_id, storage_provider_id) = (2, 2);
-        // The content needs to exist - in our mock, that's with the content ID TEST_MOCK_EXISTING_CID
-        let res = TestDataObjectStorageRegistry::add_relationship(
-            Origin::signed(account_id),
-            storage_provider_id,
-            TEST_MOCK_EXISTING_CID,
-        );
-        assert_eq!(res, Err(working_group::Error::<Test, crate::StorageWorkingGroupInstance>::WorkerDoesNotExist.into()));
-    });
-}
-
-#[test]
-fn set_relationship_ready_fails_with_invalid_authorization() {
-    with_default_mock_builder(|| {
-        let (account_id, storage_provider_id) = hire_storage_provider();
-        // The content needs to exist - in our mock, that's with the content ID TEST_MOCK_EXISTING_CID
-        let res = TestDataObjectStorageRegistry::add_relationship(
-            Origin::signed(account_id),
-            storage_provider_id,
-            TEST_MOCK_EXISTING_CID,
-        );
-        assert!(res.is_ok());
-
-        let (invalid_account_id, invalid_storage_provider_id) = (2, 2);
-        let res = TestDataObjectStorageRegistry::set_relationship_ready(
-            Origin::signed(invalid_account_id),
-            invalid_storage_provider_id,
-            TEST_MOCK_EXISTING_CID,
-        );
-        assert_eq!(res, Err(working_group::Error::<Test, crate::StorageWorkingGroupInstance>::WorkerDoesNotExist.into()));
-    });
-}
-
-#[test]
-fn unset_relationship_ready_fails_with_invalid_authorization() {
-    with_default_mock_builder(|| {
-        let (account_id, storage_provider_id) = hire_storage_provider();
-        // The content needs to exist - in our mock, that's with the content ID TEST_MOCK_EXISTING_CID
-        let res = TestDataObjectStorageRegistry::add_relationship(
-            Origin::signed(account_id),
-            storage_provider_id,
-            TEST_MOCK_EXISTING_CID,
-        );
-        assert!(res.is_ok());
-
-        let (invalid_account_id, invalid_storage_provider_id) = (2, 2);
-        let res = TestDataObjectStorageRegistry::unset_relationship_ready(
-            Origin::signed(invalid_account_id),
-            invalid_storage_provider_id,
-            TEST_MOCK_EXISTING_CID,
-        );
-        assert_eq!(res, Err(working_group::Error::<Test, crate::StorageWorkingGroupInstance>::WorkerDoesNotExist.into()));
-    });
-}
-
-#[test]
-fn test_add_relationship() {
-    with_default_mock_builder(|| {
-        let (account_id, storage_provider_id) = hire_storage_provider();
-        // The content needs to exist - in our mock, that's with the content ID TEST_MOCK_EXISTING_CID
-        let res = TestDataObjectStorageRegistry::add_relationship(
-            Origin::signed(account_id),
-            storage_provider_id,
-            TEST_MOCK_EXISTING_CID,
-        );
-        assert_eq!(res, Ok(()));
-    });
-}
-
-#[test]
-fn test_fail_adding_relationship_with_bad_content() {
-    with_default_mock_builder(|| {
-        let (account_id, storage_provider_id) = hire_storage_provider();
-        let res = TestDataObjectStorageRegistry::add_relationship(
-            Origin::signed(account_id),
-            storage_provider_id,
-            24,
-        );
-        assert!(res.is_err());
-    });
-}
-
-#[test]
-fn test_toggle_ready() {
-    with_default_mock_builder(|| {
-        /*
-           Events are not emitted on block 0.
-           So any dispatchable calls made during genesis block formation will have no events emitted.
-           https://substrate.dev/recipes/2-appetizers/4-events.html
-        */
-        run_to_block(1);
-
-        let (account_id, storage_provider_id) = hire_storage_provider();
-        // Create a DOSR
-        let res = TestDataObjectStorageRegistry::add_relationship(
-            Origin::signed(account_id),
-            storage_provider_id,
-            TEST_MOCK_EXISTING_CID,
-        );
-        assert!(res.is_ok());
-
-        // Grab DOSR ID from event
-        let dosr_id = match System::events().last().unwrap().event {
-            MetaEvent::data_object_storage_registry(
-                data_object_storage_registry::RawEvent::DataObjectStorageRelationshipAdded(
-                    dosr_id,
-                    _content_id,
-                    _account_id,
-                ),
-            ) => dosr_id,
-            _ => 0xdeadbeefu64, // invalid value, unlikely to match
-        };
-        assert_ne!(dosr_id, 0xdeadbeefu64);
-
-        // Toggling from a different account should fail
-        let res = TestDataObjectStorageRegistry::set_relationship_ready(
-            Origin::signed(2),
-            storage_provider_id,
-            dosr_id,
-        );
-        assert!(res.is_err());
-
-        // Toggling with the wrong ID should fail.
-        let res = TestDataObjectStorageRegistry::set_relationship_ready(
-            Origin::signed(account_id),
-            storage_provider_id,
-            dosr_id + 1,
-        );
-        assert!(res.is_err());
-
-        // Toggling with the correct ID and origin should succeed
-        let res = TestDataObjectStorageRegistry::set_relationship_ready(
-            Origin::signed(account_id),
-            storage_provider_id,
-            dosr_id,
-        );
-        assert!(res.is_ok());
-        assert_eq!(
-            System::events().last().unwrap().event,
-            MetaEvent::data_object_storage_registry(
-                data_object_storage_registry::RawEvent::DataObjectStorageRelationshipReadyUpdated(
-                    dosr_id, true,
-                )
-            )
-        );
-    });
-}

+ 0 - 353
runtime-modules/storage/src/tests/data_object_type_registry.rs

@@ -1,353 +0,0 @@
-#![cfg(test)]
-
-use frame_support::{StorageMap, StorageValue};
-use frame_system::{EventRecord, Phase, RawOrigin};
-
-use super::mock::*;
-
-const DEFAULT_LEADER_ACCOUNT_ID: u64 = 1;
-const DEFAULT_LEADER_MEMBER_ID: u64 = 1;
-const DEFAULT_LEADER_WORKER_ID: u32 = 1;
-
-struct SetLeadFixture;
-impl SetLeadFixture {
-    fn set_default_lead() {
-        let worker = working_group::Worker {
-            member_id: DEFAULT_LEADER_MEMBER_ID,
-            role_account_id: DEFAULT_LEADER_ACCOUNT_ID,
-            reward_relationship: None,
-            role_stake_profile: None,
-        };
-
-        // Create the worker.
-        <working_group::WorkerById<Test, StorageWorkingGroupInstance>>::insert(
-            DEFAULT_LEADER_WORKER_ID,
-            worker,
-        );
-
-        // Update current lead.
-        <working_group::CurrentLead<Test, StorageWorkingGroupInstance>>::put(
-            DEFAULT_LEADER_WORKER_ID,
-        );
-    }
-}
-
-fn get_last_data_object_type_id() -> u64 {
-    let dot_id = match System::events().last().unwrap().event {
-        MetaEvent::data_object_type_registry(
-            data_object_type_registry::RawEvent::DataObjectTypeRegistered(dot_id),
-        ) => dot_id,
-        _ => 0xdeadbeefu64, // unlikely value
-    };
-    assert_ne!(dot_id, 0xdeadbeefu64);
-
-    dot_id
-}
-
-#[test]
-fn initial_state() {
-    with_default_mock_builder(|| {
-        assert_eq!(
-            TestDataObjectTypeRegistry::first_data_object_type_id(),
-            TEST_FIRST_DATA_OBJECT_TYPE_ID
-        );
-    });
-}
-
-#[test]
-fn succeed_register() {
-    with_default_mock_builder(|| {
-        SetLeadFixture::set_default_lead();
-
-        let data: TestDataObjectType = TestDataObjectType {
-            description: "foo".as_bytes().to_vec(),
-            active: false,
-        };
-        let res = TestDataObjectTypeRegistry::register_data_object_type(
-            RawOrigin::Signed(DEFAULT_LEADER_ACCOUNT_ID).into(),
-            data,
-        );
-        assert!(res.is_ok());
-    });
-}
-
-#[test]
-fn activate_data_object_type_fails_with_invalid_lead() {
-    with_default_mock_builder(|| {
-        /*
-           Events are not emitted on block 0.
-           So any dispatchable calls made during genesis block formation will have no events emitted.
-           https://substrate.dev/recipes/2-appetizers/4-events.html
-        */
-        run_to_block(1);
-
-        SetLeadFixture::set_default_lead();
-
-        // First register a type
-        let data: TestDataObjectType = TestDataObjectType {
-            description: "foo".as_bytes().to_vec(),
-            active: false,
-        };
-        let id_res = TestDataObjectTypeRegistry::register_data_object_type(
-            RawOrigin::Signed(DEFAULT_LEADER_ACCOUNT_ID).into(),
-            data,
-        );
-        assert!(id_res.is_ok());
-
-        let dot_id = get_last_data_object_type_id();
-
-        let invalid_leader_account_id = 2;
-        let res = TestDataObjectTypeRegistry::activate_data_object_type(
-            RawOrigin::Signed(invalid_leader_account_id).into(),
-            dot_id,
-        );
-        assert_eq!(
-            res,
-            Err(
-                working_group::Error::<Test, crate::StorageWorkingGroupInstance>::IsNotLeadAccount
-                    .into()
-            )
-        );
-    });
-}
-
-#[test]
-fn deactivate_data_object_type_fails_with_invalid_lead() {
-    with_default_mock_builder(|| {
-        /*
-           Events are not emitted on block 0.
-           So any dispatchable calls made during genesis block formation will have no events emitted.
-           https://substrate.dev/recipes/2-appetizers/4-events.html
-        */
-        run_to_block(1);
-
-        SetLeadFixture::set_default_lead();
-
-        // First register a type
-        let data: TestDataObjectType = TestDataObjectType {
-            description: "foo".as_bytes().to_vec(),
-            active: true,
-        };
-        let id_res = TestDataObjectTypeRegistry::register_data_object_type(
-            RawOrigin::Signed(DEFAULT_LEADER_ACCOUNT_ID).into(),
-            data,
-        );
-        assert!(id_res.is_ok());
-
-        let dot_id = get_last_data_object_type_id();
-
-        let invalid_leader_account_id = 2;
-        let res = TestDataObjectTypeRegistry::deactivate_data_object_type(
-            RawOrigin::Signed(invalid_leader_account_id).into(),
-            dot_id,
-        );
-        assert_eq!(
-            res,
-            Err(
-                working_group::Error::<Test, crate::StorageWorkingGroupInstance>::IsNotLeadAccount
-                    .into()
-            )
-        );
-    });
-}
-
-#[test]
-fn update_data_object_type_fails_with_invalid_lead() {
-    with_default_mock_builder(|| {
-        /*
-           Events are not emitted on block 0.
-           So any dispatchable calls made during genesis block formation will have no events emitted.
-           https://substrate.dev/recipes/2-appetizers/4-events.html
-        */
-        run_to_block(1);
-
-        SetLeadFixture::set_default_lead();
-
-        // First register a type
-        let data: TestDataObjectType = TestDataObjectType {
-            description: "foo".as_bytes().to_vec(),
-            active: false,
-        };
-        let id_res = TestDataObjectTypeRegistry::register_data_object_type(
-            RawOrigin::Signed(DEFAULT_LEADER_ACCOUNT_ID).into(),
-            data,
-        );
-        assert!(id_res.is_ok());
-
-        let dot_id = get_last_data_object_type_id();
-        let updated1: TestDataObjectType = TestDataObjectType {
-            description: "bar".as_bytes().to_vec(),
-            active: false,
-        };
-
-        let invalid_leader_account_id = 2;
-        let res = TestDataObjectTypeRegistry::update_data_object_type(
-            RawOrigin::Signed(invalid_leader_account_id).into(),
-            dot_id,
-            updated1,
-        );
-        assert_eq!(
-            res,
-            Err(
-                working_group::Error::<Test, crate::StorageWorkingGroupInstance>::IsNotLeadAccount
-                    .into()
-            )
-        );
-    });
-}
-
-#[test]
-fn update_existing() {
-    with_default_mock_builder(|| {
-        /*
-           Events are not emitted on block 0.
-           So any dispatchable calls made during genesis block formation will have no events emitted.
-           https://substrate.dev/recipes/2-appetizers/4-events.html
-        */
-        run_to_block(1);
-
-        SetLeadFixture::set_default_lead();
-
-        // First register a type
-        let data: TestDataObjectType = TestDataObjectType {
-            description: "foo".as_bytes().to_vec(),
-            active: false,
-        };
-        let id_res = TestDataObjectTypeRegistry::register_data_object_type(
-            RawOrigin::Signed(DEFAULT_LEADER_ACCOUNT_ID).into(),
-            data,
-        );
-        assert!(id_res.is_ok());
-
-        let dot_id = get_last_data_object_type_id();
-
-        // Now update it with new data - we need the ID to be the same as in
-        // returned by the previous call. First, though, try and fail with a bad ID
-        let updated1: TestDataObjectType = TestDataObjectType {
-            description: "bar".as_bytes().to_vec(),
-            active: false,
-        };
-        let res = TestDataObjectTypeRegistry::update_data_object_type(
-            RawOrigin::Signed(DEFAULT_LEADER_ACCOUNT_ID).into(),
-            dot_id + 1,
-            updated1,
-        );
-        assert!(res.is_err());
-
-        // Finally with an existing ID, it should work.
-        let updated3: TestDataObjectType = TestDataObjectType {
-            description: "bar".as_bytes().to_vec(),
-            active: false,
-        };
-        let res = TestDataObjectTypeRegistry::update_data_object_type(
-            RawOrigin::Signed(DEFAULT_LEADER_ACCOUNT_ID).into(),
-            dot_id,
-            updated3,
-        );
-        assert!(res.is_ok());
-        assert_eq!(
-            *System::events().last().unwrap(),
-            EventRecord {
-                phase: Phase::Initialization,
-                event: MetaEvent::data_object_type_registry(
-                    data_object_type_registry::RawEvent::DataObjectTypeUpdated(dot_id)
-                ),
-                topics: vec![],
-            }
-        );
-    });
-}
-
-#[test]
-fn register_data_object_type_failed_with_no_lead() {
-    with_default_mock_builder(|| {
-        // First register a type
-        let data: TestDataObjectType = TestDataObjectType {
-            description: "foo".as_bytes().to_vec(),
-            active: false,
-        };
-        let id_res = TestDataObjectTypeRegistry::register_data_object_type(
-            RawOrigin::Signed(DEFAULT_LEADER_ACCOUNT_ID).into(),
-            data,
-        );
-        assert!(!id_res.is_ok());
-    });
-}
-
-#[test]
-fn activate_existing() {
-    with_default_mock_builder(|| {
-        /*
-           Events are not emitted on block 0.
-           So any dispatchable calls made during genesis block formation will have no events emitted.
-           https://substrate.dev/recipes/2-appetizers/4-events.html
-        */
-        run_to_block(1);
-
-        let expected_data_object_type_id = TEST_FIRST_DATA_OBJECT_TYPE_ID + 1; // on_initialize() increments the default value.
-
-        SetLeadFixture::set_default_lead();
-
-        // First register a type
-        let data: TestDataObjectType = TestDataObjectType {
-            description: "foo".as_bytes().to_vec(),
-            active: false,
-        };
-        let id_res = TestDataObjectTypeRegistry::register_data_object_type(
-            RawOrigin::Signed(DEFAULT_LEADER_ACCOUNT_ID).into(),
-            data,
-        );
-        assert!(id_res.is_ok());
-        assert_eq!(
-            *System::events().last().unwrap(),
-            EventRecord {
-                phase: Phase::Initialization,
-                event: MetaEvent::data_object_type_registry(
-                    data_object_type_registry::RawEvent::DataObjectTypeRegistered(
-                        expected_data_object_type_id
-                    )
-                ),
-                topics: vec![],
-            }
-        );
-
-        // Retrieve, and ensure it's not active.
-        let data = TestDataObjectTypeRegistry::data_object_types(expected_data_object_type_id);
-        assert!(data.is_some());
-        assert!(!data.unwrap().active);
-
-        // Now activate the data object type
-        let res = TestDataObjectTypeRegistry::activate_data_object_type(
-            RawOrigin::Signed(DEFAULT_LEADER_ACCOUNT_ID).into(),
-            expected_data_object_type_id,
-        );
-        assert!(res.is_ok());
-        assert_eq!(
-            *System::events().last().unwrap(),
-            EventRecord {
-                phase: Phase::Initialization,
-                event: MetaEvent::data_object_type_registry(
-                    data_object_type_registry::RawEvent::DataObjectTypeUpdated(
-                        expected_data_object_type_id
-                    )
-                ),
-                topics: vec![],
-            }
-        );
-
-        // Ensure that the item is actually activated.
-        let data = TestDataObjectTypeRegistry::data_object_types(expected_data_object_type_id);
-        assert!(data.is_some());
-        assert!(data.unwrap().active);
-
-        // Deactivate again.
-        let res = TestDataObjectTypeRegistry::deactivate_data_object_type(
-            RawOrigin::Signed(DEFAULT_LEADER_ACCOUNT_ID).into(),
-            expected_data_object_type_id,
-        );
-        assert!(res.is_ok());
-        let data = TestDataObjectTypeRegistry::data_object_types(expected_data_object_type_id);
-        assert!(data.is_some());
-        assert!(!data.unwrap().active);
-    });
-}

+ 0 - 353
runtime-modules/storage/src/tests/mock.rs

@@ -1,353 +0,0 @@
-#![cfg(test)]
-
-use frame_support::storage::StorageMap;
-use frame_support::traits::{OnFinalize, OnInitialize};
-use frame_support::{impl_outer_event, impl_outer_origin, parameter_types};
-use sp_core::H256;
-use sp_runtime::{
-    testing::Header,
-    traits::{BlakeTwo256, IdentityLookup},
-    Perbill,
-};
-
-use crate::data_directory::ContentIdExists;
-use crate::data_object_type_registry::IsActiveDataObjectType;
-pub use crate::StorageWorkingGroupInstance;
-pub use crate::{data_directory, data_object_storage_registry, data_object_type_registry};
-use common::currency::GovernanceCurrency;
-use membership;
-
-mod working_group_mod {
-    pub use super::StorageWorkingGroupInstance;
-    pub use working_group::Event;
-}
-
-mod members {
-    pub use membership::Event;
-}
-
-impl_outer_origin! {
-    pub enum Origin for Test {}
-}
-
-impl_outer_event! {
-    pub enum MetaEvent for Test {
-        data_object_type_registry<T>,
-        data_directory<T>,
-        data_object_storage_registry<T>,
-        balances<T>,
-        members<T>,
-        working_group_mod StorageWorkingGroupInstance <T>,
-        frame_system<T>,
-    }
-}
-
-pub const TEST_FIRST_DATA_OBJECT_TYPE_ID: u64 = 1000;
-pub const TEST_FIRST_CONTENT_ID: u64 = 2000;
-pub const TEST_FIRST_RELATIONSHIP_ID: u64 = 3000;
-pub const TEST_FIRST_METADATA_ID: u64 = 4000;
-
-pub const TEST_MOCK_LIAISON_STORAGE_PROVIDER_ID: u32 = 1;
-pub const TEST_MOCK_EXISTING_CID: u64 = 42;
-
-pub struct AnyDataObjectTypeIsActive {}
-impl<T: data_object_type_registry::Trait> IsActiveDataObjectType<T> for AnyDataObjectTypeIsActive {
-    fn is_active_data_object_type(_which: &T::DataObjectTypeId) -> bool {
-        true
-    }
-}
-
-pub struct MockContent {}
-impl ContentIdExists<Test> for MockContent {
-    fn has_content(which: &<Test as data_directory::Trait>::ContentId) -> bool {
-        *which == TEST_MOCK_EXISTING_CID
-    }
-
-    fn get_data_object(
-        which: &<Test as data_directory::Trait>::ContentId,
-    ) -> Result<data_directory::DataObject<Test>, &'static str> {
-        match *which {
-            TEST_MOCK_EXISTING_CID => Ok(data_directory::DataObjectInternal {
-                type_id: 1,
-                size: 1234,
-                added_at: data_directory::BlockAndTime {
-                    block: 10,
-                    time: 1024,
-                },
-                owner: 1,
-                liaison: TEST_MOCK_LIAISON_STORAGE_PROVIDER_ID,
-                liaison_judgement: data_directory::LiaisonJudgement::Pending,
-                ipfs_content_id: vec![],
-            }),
-            _ => Err("nope, missing"),
-        }
-    }
-}
-
-// Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
-#[derive(Clone, PartialEq, Eq, Debug)]
-pub struct Test;
-parameter_types! {
-    pub const BlockHashCount: u64 = 250;
-    pub const MaximumBlockWeight: u32 = 1024;
-    pub const MaximumBlockLength: u32 = 2 * 1024;
-    pub const AvailableBlockRatio: Perbill = Perbill::one();
-    pub const MinimumPeriod: u64 = 5;
-    pub const MaxObjectsPerInjection: u32 = 5;
-}
-
-impl frame_system::Trait for Test {
-    type BaseCallFilter = ();
-    type Origin = Origin;
-    type Call = ();
-    type Index = u64;
-    type BlockNumber = u64;
-    type Hash = H256;
-    type Hashing = BlakeTwo256;
-    type AccountId = u64;
-    type Lookup = IdentityLookup<Self::AccountId>;
-    type Header = Header;
-    type Event = MetaEvent;
-    type BlockHashCount = BlockHashCount;
-    type MaximumBlockWeight = MaximumBlockWeight;
-    type DbWeight = ();
-    type BlockExecutionWeight = ();
-    type ExtrinsicBaseWeight = ();
-    type MaximumExtrinsicWeight = ();
-    type MaximumBlockLength = MaximumBlockLength;
-    type AvailableBlockRatio = AvailableBlockRatio;
-    type Version = ();
-    type AccountData = balances::AccountData<u64>;
-    type OnNewAccount = ();
-    type OnKilledAccount = ();
-    type SystemWeightInfo = ();
-    type PalletInfo = ();
-}
-
-impl pallet_timestamp::Trait for Test {
-    type Moment = u64;
-    type OnTimestampSet = ();
-    type MinimumPeriod = MinimumPeriod;
-    type WeightInfo = ();
-}
-
-parameter_types! {
-    pub const ExistentialDeposit: u32 = 0;
-    pub const StakePoolId: [u8; 8] = *b"joystake";
-}
-
-impl balances::Trait for Test {
-    type Balance = u64;
-    type DustRemoval = ();
-    type Event = MetaEvent;
-    type ExistentialDeposit = ExistentialDeposit;
-    type AccountStore = System;
-    type WeightInfo = ();
-    type MaxLocks = ();
-}
-
-impl GovernanceCurrency for Test {
-    type Currency = balances::Module<Self>;
-}
-
-parameter_types! {
-    pub const MaxWorkerNumberLimit: u32 = 3;
-}
-
-impl working_group::Trait<StorageWorkingGroupInstance> for Test {
-    type Event = MetaEvent;
-    type MaxWorkerNumberLimit = MaxWorkerNumberLimit;
-}
-
-impl data_object_type_registry::Trait for Test {
-    type Event = MetaEvent;
-    type DataObjectTypeId = u64;
-}
-
-impl data_directory::Trait for Test {
-    type Event = MetaEvent;
-    type ContentId = u64;
-    type StorageProviderHelper = ();
-    type IsActiveDataObjectType = AnyDataObjectTypeIsActive;
-    type MemberOriginValidator = ();
-    type MaxObjectsPerInjection = MaxObjectsPerInjection;
-}
-
-impl crate::data_directory::StorageProviderHelper<Test> for () {
-    fn get_random_storage_provider() -> Result<u32, &'static str> {
-        Ok(1)
-    }
-}
-
-impl common::origin::ActorOriginValidator<Origin, u64, u64> for () {
-    fn ensure_actor_origin(origin: Origin, _account_id: u64) -> Result<u64, &'static str> {
-        let signed_account_id = frame_system::ensure_signed(origin)?;
-
-        Ok(signed_account_id)
-    }
-}
-
-impl data_object_storage_registry::Trait for Test {
-    type Event = MetaEvent;
-    type DataObjectStorageRelationshipId = u64;
-    type ContentIdExists = MockContent;
-}
-
-impl membership::Trait for Test {
-    type Event = MetaEvent;
-    type MemberId = u64;
-    type SubscriptionId = u32;
-    type PaidTermId = u32;
-    type ActorId = u32;
-}
-
-impl stake::Trait for Test {
-    type Currency = Balances;
-    type StakePoolId = StakePoolId;
-    type StakingEventsHandler = ();
-    type StakeId = u64;
-    type SlashId = u64;
-}
-
-impl minting::Trait for Test {
-    type Currency = Balances;
-    type MintId = u64;
-}
-
-impl recurringrewards::Trait for Test {
-    type PayoutStatusHandler = ();
-    type RecipientId = u64;
-    type RewardRelationshipId = u64;
-}
-
-impl hiring::Trait for Test {
-    type OpeningId = u64;
-    type ApplicationId = u64;
-    type ApplicationDeactivatedHandler = ();
-    type StakeHandlerProvider = hiring::Module<Self>;
-}
-
-#[allow(dead_code)]
-pub struct ExtBuilder {
-    first_data_object_type_id: u64,
-    first_content_id: u64,
-    first_relationship_id: u64,
-    first_metadata_id: u64,
-}
-
-impl Default for ExtBuilder {
-    fn default() -> Self {
-        Self {
-            first_data_object_type_id: 1,
-            first_content_id: 2,
-            first_relationship_id: 3,
-            first_metadata_id: 4,
-        }
-    }
-}
-
-impl ExtBuilder {
-    pub fn first_data_object_type_id(mut self, first_data_object_type_id: u64) -> Self {
-        self.first_data_object_type_id = first_data_object_type_id;
-        self
-    }
-    pub fn first_content_id(mut self, first_content_id: u64) -> Self {
-        self.first_content_id = first_content_id;
-        self
-    }
-    pub fn first_relationship_id(mut self, first_relationship_id: u64) -> Self {
-        self.first_relationship_id = first_relationship_id;
-        self
-    }
-    pub fn first_metadata_id(mut self, first_metadata_id: u64) -> Self {
-        self.first_metadata_id = first_metadata_id;
-        self
-    }
-    pub fn build(self) -> sp_io::TestExternalities {
-        let mut t = frame_system::GenesisConfig::default()
-            .build_storage::<Test>()
-            .unwrap();
-
-        data_object_type_registry::GenesisConfig::<Test> {
-            first_data_object_type_id: self.first_data_object_type_id,
-        }
-        .assimilate_storage(&mut t)
-        .unwrap();
-
-        data_object_storage_registry::GenesisConfig::<Test> {
-            first_relationship_id: self.first_relationship_id,
-        }
-        .assimilate_storage(&mut t)
-        .unwrap();
-
-        membership::GenesisConfig::<Test> {
-            default_paid_membership_fee: 0,
-            members: vec![membership::genesis::Member {
-                member_id: 0,
-                root_account: 1,
-                controller_account: 1,
-                handle: "alice".into(),
-                avatar_uri: "".into(),
-                about: "".into(),
-                registered_at_time: 0,
-            }],
-        }
-        .assimilate_storage(&mut t)
-        .unwrap();
-
-        t.into()
-    }
-}
-
-pub type TestDataObjectType = data_object_type_registry::DataObjectType;
-
-pub type Balances = balances::Module<Test>;
-pub type System = frame_system::Module<Test>;
-pub type TestDataObjectTypeRegistry = data_object_type_registry::Module<Test>;
-pub type TestDataDirectory = data_directory::Module<Test>;
-pub type TestDataObjectStorageRegistry = data_object_storage_registry::Module<Test>;
-
-pub fn with_default_mock_builder<R, F: FnOnce() -> R>(f: F) -> R {
-    ExtBuilder::default()
-        .first_data_object_type_id(TEST_FIRST_DATA_OBJECT_TYPE_ID)
-        .first_content_id(TEST_FIRST_CONTENT_ID)
-        .first_relationship_id(TEST_FIRST_RELATIONSHIP_ID)
-        .first_metadata_id(TEST_FIRST_METADATA_ID)
-        .build()
-        .execute_with(|| f())
-}
-
-pub(crate) fn hire_storage_provider() -> (u64, u32) {
-    let storage_provider_id = 1;
-    let role_account_id = 1;
-
-    let storage_provider = working_group::Worker {
-        member_id: 1,
-        role_account_id,
-        reward_relationship: None,
-        role_stake_profile: None,
-    };
-
-    <working_group::WorkerById<Test, StorageWorkingGroupInstance>>::insert(
-        storage_provider_id,
-        storage_provider,
-    );
-
-    (role_account_id, storage_provider_id)
-}
-
-// Recommendation from Parity on testing on_finalize
-// https://substrate.dev/docs/en/next/development/module/tests
-pub fn run_to_block(n: u64) {
-    while System::block_number() < n {
-        <System as OnFinalize<u64>>::on_finalize(System::block_number());
-        <TestDataObjectTypeRegistry as OnFinalize<u64>>::on_finalize(System::block_number());
-        <TestDataDirectory as OnFinalize<u64>>::on_finalize(System::block_number());
-        <TestDataObjectStorageRegistry as OnFinalize<u64>>::on_finalize(System::block_number());
-        System::set_block_number(System::block_number() + 1);
-        <System as OnInitialize<u64>>::on_initialize(System::block_number());
-        <TestDataObjectTypeRegistry as OnInitialize<u64>>::on_initialize(System::block_number());
-        <TestDataDirectory as OnInitialize<u64>>::on_initialize(System::block_number());
-        <TestDataObjectStorageRegistry as OnInitialize<u64>>::on_initialize(System::block_number());
-    }
-}

+ 0 - 6
runtime-modules/storage/src/tests/mod.rs

@@ -1,6 +0,0 @@
-#![cfg(test)]
-
-mod data_directory;
-mod data_object_storage_registry;
-mod data_object_type_registry;
-mod mock;

+ 0 - 4
runtime/Cargo.toml

@@ -74,8 +74,6 @@ working-group = { package = 'pallet-working-group', default-features = false, pa
 content-working-group = { package = 'pallet-content-working-group', default-features = false, path = '../runtime-modules/content-working-group'}
 versioned-store = { package = 'pallet-versioned-store', default-features = false, path = '../runtime-modules/versioned-store'}
 versioned-store-permissions = { package = 'pallet-versioned-store-permissions', default-features = false, path = '../runtime-modules/versioned-store-permissions'}
-storage = { package = 'pallet-storage', default-features = false, path = '../runtime-modules/storage'}
-service-discovery = { package = 'pallet-service-discovery', default-features = false, path = '../runtime-modules/service-discovery'}
 proposals-engine = { package = 'pallet-proposals-engine', default-features = false, path = '../runtime-modules/proposals/engine'}
 proposals-discussion = { package = 'pallet-proposals-discussion', default-features = false, path = '../runtime-modules/proposals/discussion'}
 proposals-codex = { package = 'pallet-proposals-codex', default-features = false, path = '../runtime-modules/proposals/codex'}
@@ -152,8 +150,6 @@ std = [
     'content-working-group/std',
     'versioned-store/std',
     'versioned-store-permissions/std',
-    'storage/std',
-    'service-discovery/std',
     'proposals-engine/std',
     'proposals-discussion/std',
     'proposals-codex/std',

+ 0 - 1
runtime/src/integration/mod.rs

@@ -2,7 +2,6 @@ pub mod content_directory;
 pub mod content_working_group;
 pub mod forum;
 pub mod proposals;
-pub mod storage;
 pub mod transactions;
 pub mod versioned_store_permissions;
 pub mod working_group;

+ 0 - 36
runtime/src/integration/storage.rs

@@ -1,36 +0,0 @@
-use frame_support::traits::Randomness;
-use sp_std::vec::Vec;
-
-use crate::{ActorId, Runtime};
-
-/// Provides random storage provider id. We use it when assign the content to the storage provider.
-pub struct StorageProviderHelper;
-
-impl storage::data_directory::StorageProviderHelper<Runtime> for StorageProviderHelper {
-    fn get_random_storage_provider() -> Result<ActorId, &'static str> {
-        let ids = crate::StorageWorkingGroup::get_all_worker_ids();
-
-        let live_ids: Vec<ActorId> = ids
-            .into_iter()
-            .filter(|id| !<service_discovery::Module<Runtime>>::is_account_info_expired(id))
-            .collect();
-
-        if live_ids.is_empty() {
-            Err("No valid storage provider found.")
-        } else {
-            let index = Self::random_index(live_ids.len());
-            Ok(live_ids[index])
-        }
-    }
-}
-
-impl StorageProviderHelper {
-    fn random_index(upper_bound: usize) -> usize {
-        let seed = crate::RandomnessCollectiveFlip::random_seed();
-        let mut rand: u64 = 0;
-        for offset in 0..8 {
-            rand += (seed.as_ref()[offset] as u64) << offset;
-        }
-        (rand as usize) % upper_bound
-    }
-}

+ 2 - 35
runtime/src/lib.rs

@@ -63,7 +63,6 @@ pub use runtime_api::*;
 use integration::proposals::{CouncilManager, ExtrinsicProposalEncoder, MembershipOriginValidator};
 
 use governance::{council, election};
-use storage::data_object_storage_registry;
 use storage_v2::DynamicBagCreationPolicy;
 
 // Node dependencies
@@ -80,7 +79,7 @@ pub use membership;
 pub use pallet_balances::Call as BalancesCall;
 pub use pallet_staking::StakerStatus;
 pub use proposals_codex::ProposalsConfigParameters;
-pub use storage::{data_directory, data_object_type_registry};
+pub use storage_v2::DataObject;
 pub use versioned_store;
 pub use versioned_store_permissions;
 pub use working_group;
@@ -546,30 +545,6 @@ impl memo::Trait for Runtime {
     type Event = Event;
 }
 
-parameter_types! {
-    pub const MaxObjectsPerInjection: u32 = 100;
-}
-
-impl storage::data_object_type_registry::Trait for Runtime {
-    type Event = Event;
-    type DataObjectTypeId = u64;
-}
-
-impl storage::data_directory::Trait for Runtime {
-    type Event = Event;
-    type ContentId = ContentId;
-    type StorageProviderHelper = integration::storage::StorageProviderHelper;
-    type IsActiveDataObjectType = DataObjectTypeRegistry;
-    type MemberOriginValidator = MembershipOriginValidator<Self>;
-    type MaxObjectsPerInjection = MaxObjectsPerInjection;
-}
-
-impl storage::data_object_storage_registry::Trait for Runtime {
-    type Event = Event;
-    type DataObjectStorageRelationshipId = u64;
-    type ContentIdExists = DataDirectory;
-}
-
 impl membership::Trait for Runtime {
     type Event = Event;
     type MemberId = MemberId;
@@ -605,10 +580,6 @@ impl working_group::Trait<ContentDirectoryWorkingGroupInstance> for Runtime {
     type MaxWorkerNumberLimit = MaxWorkerNumberLimit;
 }
 
-impl service_discovery::Trait for Runtime {
-    type Event = Event;
-}
-
 parameter_types! {
     pub const ProposalCancellationFee: u64 = 10000;
     pub const ProposalRejectionFee: u64 = 5000;
@@ -779,11 +750,6 @@ construct_runtime!(
         Hiring: hiring::{Module, Call, Storage},
         ContentWorkingGroup: content_wg::{Module, Call, Storage, Event<T>, Config<T>},
         ContentDirectory: content_directory::{Module, Call, Storage, Event<T>, Config<T>},
-        // --- Storage
-        DataObjectTypeRegistry: data_object_type_registry::{Module, Call, Storage, Event<T>, Config<T>},
-        DataDirectory: data_directory::{Module, Call, Storage, Event<T>, Config<T>},
-        DataObjectStorageRegistry: data_object_storage_registry::{Module, Call, Storage, Event<T>, Config<T>},
-        Discovery: service_discovery::{Module, Call, Storage, Event<T>},
         // --- Proposals
         ProposalsEngine: proposals_engine::{Module, Call, Storage, Event<T>},
         ProposalsDiscussion: proposals_discussion::{Module, Call, Storage, Event<T>},
@@ -792,6 +758,7 @@ construct_runtime!(
         // reserved for the future use: ForumWorkingGroup: working_group::<Instance1>::{Module, Call, Storage, Event<T>},
         StorageWorkingGroup: working_group::<Instance2>::{Module, Call, Storage, Config<T>, Event<T>},
         ContentDirectoryWorkingGroup: working_group::<Instance3>::{Module, Call, Storage, Config<T>, Event<T>},
+        //
         StorageV2: storage_v2::{Module, Call, Storage, Event<T>},
     }
 );

+ 0 - 1
runtime/src/tests/mod.rs

@@ -4,7 +4,6 @@
 #[macro_use]
 
 mod proposals_integration;
-mod storage_integration;
 use sp_runtime::BuildStorage;
 
 pub(crate) fn initial_test_ext() -> sp_io::TestExternalities {

+ 0 - 45
runtime/src/tests/storage_integration.rs

@@ -1,45 +0,0 @@
-use super::initial_test_ext;
-use crate::integration::storage::StorageProviderHelper;
-use crate::Runtime;
-
-use frame_support::StorageMap;
-use working_group::{Instance2, Worker};
-
-#[test]
-fn storage_provider_helper_succeeds() {
-    initial_test_ext().execute_with(|| {
-		// Bug in random module requires move the initial block number.
-		<frame_system::Module<Runtime>>::set_block_number(1);
-
-		// Error - no workers.
-		let random_provider_result = <StorageProviderHelper
-			as storage::data_directory::StorageProviderHelper<Runtime>>::get_random_storage_provider();
-		assert!(random_provider_result.is_err());
-
-		let worker_id1 = 1;
-		let worker_id2 = 7;
-		let worker_id3 = 19;
-
-		<working_group::WorkerById<Runtime, Instance2>>::insert(worker_id1, Worker::default());
-		<working_group::WorkerById<Runtime, Instance2>>::insert(worker_id2, Worker::default());
-		<working_group::WorkerById<Runtime, Instance2>>::insert(worker_id3, Worker::default());
-
-		// Still error - not registered in the service discovery.
-		let random_provider_result = <StorageProviderHelper as storage::data_directory::StorageProviderHelper<Runtime>>::get_random_storage_provider();
-		assert!(random_provider_result.is_err());
-
-		let account_info = service_discovery::ServiceProviderRecord{
-			identity: Vec::new(),
-			expires_at: 1000
-		};
-
-		<service_discovery::AccountInfoByStorageProviderId<Runtime>>::insert(worker_id1,account_info.clone());
-		<service_discovery::AccountInfoByStorageProviderId<Runtime>>::insert(worker_id2,account_info.clone());
-		<service_discovery::AccountInfoByStorageProviderId<Runtime>>::insert(worker_id3,account_info);
-
-		// Should work now.
-		let worker_ids = vec![worker_id1, worker_id2, worker_id3];
-		let random_provider_id = <StorageProviderHelper as storage::data_directory::StorageProviderHelper<Runtime>>::get_random_storage_provider().unwrap();
-		assert!(worker_ids.contains(&random_provider_id));
-	});
-}

+ 16 - 23
utils/chain-spec-builder/src/main.rs

@@ -242,28 +242,22 @@ fn genesis_constructor(
         .map(|path| forum_config::from_json(sudo_account.clone(), path.as_path()))
         .unwrap_or_else(|| forum_config::empty(sudo_account.clone()));
 
-    let (
-        versioned_store_cfg,
-        versioned_store_permissions_cfg,
-        data_directory_config,
-        content_working_group_config,
-    ) = if let Some(path) = initial_content_path {
-        let path = path.as_path();
-
-        (
-            content_config::versioned_store_config_from_json(path),
-            content_config::versioned_store_permissions_config_from_json(path),
-            content_config::data_directory_config_from_json(path),
-            content_config::content_working_group_config_from_json(path),
-        )
-    } else {
-        (
-            content_config::empty_versioned_store_config(),
-            content_config::empty_versioned_store_permissions_config(),
-            content_config::empty_data_directory_config(),
-            content_config::empty_content_working_group_config(),
-        )
-    };
+    let (versioned_store_cfg, versioned_store_permissions_cfg, content_working_group_config) =
+        if let Some(path) = initial_content_path {
+            let path = path.as_path();
+
+            (
+                content_config::versioned_store_config_from_json(path),
+                content_config::versioned_store_permissions_config_from_json(path),
+                content_config::content_working_group_config_from_json(path),
+            )
+        } else {
+            (
+                content_config::empty_versioned_store_config(),
+                content_config::empty_versioned_store_permissions_config(),
+                content_config::empty_content_working_group_config(),
+            )
+        };
 
     let initial_account_balances = initial_balances_path
         .as_ref()
@@ -285,7 +279,6 @@ fn genesis_constructor(
         forum_cfg,
         versioned_store_cfg,
         versioned_store_permissions_cfg,
-        data_directory_config,
         content_working_group_config,
         initial_account_balances,
     )