1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972 |
- use frame_support::dispatch::DispatchResult;
- use frame_support::storage::StorageMap;
- use frame_support::traits::{Currency, OnFinalize, OnInitialize};
- use frame_system::{EventRecord, Phase, RawOrigin};
- use sp_std::collections::btree_map::BTreeMap;
- use sp_std::collections::btree_set::BTreeSet;
- use super::mocks::{
- Balances, CollectiveFlip, Storage, System, Test, TestEvent, DEFAULT_MEMBER_ACCOUNT_ID,
- DEFAULT_STORAGE_PROVIDER_ACCOUNT_ID, STORAGE_WG_LEADER_ACCOUNT_ID,
- };
- use crate::tests::mocks::{
- DEFAULT_DISTRIBUTION_PROVIDER_ACCOUNT_ID, DISTRIBUTION_WG_LEADER_ACCOUNT_ID,
- };
- use crate::{
- BagId, Cid, DataObjectCreationParameters, DataObjectStorage, DistributionBucket,
- DistributionBucketId, DynamicBagDeletionPrize, DynamicBagId, DynamicBagType, RawEvent,
- StaticBagId, StorageBucketOperatorStatus, UploadParameters,
- };
- // 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());
- <CollectiveFlip as OnFinalize<u64>>::on_finalize(System::block_number());
- <Storage 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());
- <CollectiveFlip as OnInitialize<u64>>::on_initialize(System::block_number());
- <Storage as OnInitialize<u64>>::on_initialize(System::block_number());
- }
- }
- pub fn increase_account_balance(account_id: &u64, balance: u64) {
- let _ = Balances::deposit_creating(&account_id, balance);
- }
- pub struct EventFixture;
- impl EventFixture {
- pub fn assert_last_crate_event(
- expected_raw_event: RawEvent<
- u64,
- u64,
- u64,
- UploadParameters<Test>,
- BagId<Test>,
- DynamicBagId<Test>,
- u64,
- u64,
- u64,
- DistributionBucketId<Test>,
- u64,
- >,
- ) {
- let converted_event = TestEvent::storage(expected_raw_event);
- Self::assert_last_global_event(converted_event)
- }
- pub fn contains_crate_event(
- expected_raw_event: RawEvent<
- u64,
- u64,
- u64,
- UploadParameters<Test>,
- BagId<Test>,
- DynamicBagId<Test>,
- u64,
- u64,
- u64,
- DistributionBucketId<Test>,
- u64,
- >,
- ) {
- let converted_event = TestEvent::storage(expected_raw_event);
- Self::contains_global_event(converted_event)
- }
- pub fn assert_last_global_event(expected_event: TestEvent) {
- let expected_event = EventRecord {
- phase: Phase::Initialization,
- event: expected_event,
- topics: vec![],
- };
- assert_eq!(System::events().pop().unwrap(), expected_event);
- }
- fn contains_global_event(expected_event: TestEvent) {
- let expected_event = EventRecord {
- phase: Phase::Initialization,
- event: expected_event,
- topics: vec![],
- };
- assert!(System::events().iter().any(|ev| *ev == expected_event));
- }
- }
- const DEFAULT_ACCOUNT_ID: u64 = 1;
- const DEFAULT_WORKER_ID: u64 = 1;
- pub struct CreateStorageBucketFixture {
- origin: RawOrigin<u64>,
- invite_worker: Option<u64>,
- accepting_new_bags: bool,
- size_limit: u64,
- objects_limit: u64,
- }
- impl CreateStorageBucketFixture {
- pub fn default() -> Self {
- Self {
- origin: RawOrigin::Signed(DEFAULT_ACCOUNT_ID),
- invite_worker: None,
- accepting_new_bags: true,
- size_limit: 0,
- objects_limit: 0,
- }
- }
- pub fn with_origin(self, origin: RawOrigin<u64>) -> Self {
- Self { origin, ..self }
- }
- pub fn with_invite_worker(self, invite_worker: Option<u64>) -> Self {
- Self {
- invite_worker,
- ..self
- }
- }
- pub fn with_accepting_new_bags(self, accepting_new_bags: bool) -> Self {
- Self {
- accepting_new_bags,
- ..self
- }
- }
- pub fn with_size_limit(self, size_limit: u64) -> Self {
- Self { size_limit, ..self }
- }
- pub fn with_objects_limit(self, objects_limit: u64) -> Self {
- Self {
- objects_limit,
- ..self
- }
- }
- pub fn call_and_assert(&self, expected_result: DispatchResult) -> Option<u64> {
- let next_storage_bucket_id = Storage::next_storage_bucket_id();
- let actual_result = Storage::create_storage_bucket(
- self.origin.clone().into(),
- self.invite_worker,
- self.accepting_new_bags,
- self.size_limit,
- self.objects_limit,
- );
- assert_eq!(actual_result, expected_result);
- if actual_result.is_ok() {
- assert_eq!(
- next_storage_bucket_id + 1,
- Storage::next_storage_bucket_id()
- );
- assert!(<crate::StorageBucketById<Test>>::contains_key(
- next_storage_bucket_id
- ));
- Some(next_storage_bucket_id)
- } else {
- assert_eq!(next_storage_bucket_id, Storage::next_storage_bucket_id());
- assert!(!<crate::StorageBucketById<Test>>::contains_key(
- next_storage_bucket_id
- ));
- None
- }
- }
- }
- pub struct AcceptStorageBucketInvitationFixture {
- origin: RawOrigin<u64>,
- worker_id: u64,
- storage_bucket_id: u64,
- transactor_account_id: u64,
- }
- impl AcceptStorageBucketInvitationFixture {
- pub fn default() -> Self {
- Self {
- origin: RawOrigin::Signed(DEFAULT_ACCOUNT_ID),
- worker_id: DEFAULT_WORKER_ID,
- storage_bucket_id: Default::default(),
- transactor_account_id: DEFAULT_ACCOUNT_ID,
- }
- }
- pub fn with_origin(self, origin: RawOrigin<u64>) -> Self {
- Self { origin, ..self }
- }
- pub fn with_worker_id(self, worker_id: u64) -> Self {
- Self { worker_id, ..self }
- }
- pub fn with_transactor_account_id(self, transactor_account_id: u64) -> Self {
- Self {
- transactor_account_id,
- ..self
- }
- }
- pub fn with_storage_bucket_id(self, storage_bucket_id: u64) -> Self {
- Self {
- storage_bucket_id,
- ..self
- }
- }
- pub fn call_and_assert(&self, expected_result: DispatchResult) {
- let old_bucket = Storage::storage_bucket_by_id(self.storage_bucket_id);
- let actual_result = Storage::accept_storage_bucket_invitation(
- self.origin.clone().into(),
- self.worker_id,
- self.storage_bucket_id,
- self.transactor_account_id,
- );
- assert_eq!(actual_result, expected_result);
- let new_bucket = Storage::storage_bucket_by_id(self.storage_bucket_id);
- if actual_result.is_ok() {
- assert_eq!(
- new_bucket.operator_status,
- StorageBucketOperatorStatus::StorageWorker(
- self.worker_id,
- self.transactor_account_id
- )
- );
- } else {
- assert_eq!(old_bucket, new_bucket);
- }
- }
- }
- pub struct UpdateStorageBucketForBagsFixture {
- origin: RawOrigin<u64>,
- bag_id: BagId<Test>,
- add_bucket_ids: BTreeSet<u64>,
- remove_bucket_ids: BTreeSet<u64>,
- }
- impl UpdateStorageBucketForBagsFixture {
- pub fn default() -> Self {
- Self {
- origin: RawOrigin::Signed(DEFAULT_ACCOUNT_ID),
- bag_id: Default::default(),
- add_bucket_ids: Default::default(),
- remove_bucket_ids: Default::default(),
- }
- }
- pub fn with_origin(self, origin: RawOrigin<u64>) -> Self {
- Self { origin, ..self }
- }
- pub fn with_add_bucket_ids(self, add_bucket_ids: BTreeSet<u64>) -> Self {
- Self {
- add_bucket_ids,
- ..self
- }
- }
- pub fn with_remove_bucket_ids(self, remove_bucket_ids: BTreeSet<u64>) -> Self {
- Self {
- remove_bucket_ids,
- ..self
- }
- }
- pub fn with_bag_id(self, bag_id: BagId<Test>) -> Self {
- Self { bag_id, ..self }
- }
- pub fn call_and_assert(&self, expected_result: DispatchResult) {
- let actual_result = Storage::update_storage_buckets_for_bag(
- self.origin.clone().into(),
- self.bag_id.clone(),
- self.add_bucket_ids.clone(),
- self.remove_bucket_ids.clone(),
- );
- assert_eq!(actual_result, expected_result);
- }
- }
- pub struct UploadFixture {
- params: UploadParameters<Test>,
- }
- impl UploadFixture {
- pub fn default() -> Self {
- Self {
- params: Default::default(),
- }
- }
- pub fn with_params(self, params: UploadParameters<Test>) -> Self {
- Self { params, ..self }
- }
- pub fn call_and_assert(&self, expected_result: DispatchResult) {
- let old_next_data_object_id = Storage::next_data_object_id();
- let actual_result = Storage::upload_data_objects(self.params.clone());
- assert_eq!(actual_result, expected_result);
- if actual_result.is_ok() {
- // check next data object ID
- assert_eq!(
- Storage::next_data_object_id(),
- old_next_data_object_id + self.params.object_creation_list.len() as u64
- );
- } else {
- assert_eq!(Storage::next_data_object_id(), old_next_data_object_id);
- }
- }
- }
- pub fn create_data_object_candidates(
- starting_index: u8,
- number: u8,
- ) -> Vec<DataObjectCreationParameters> {
- let range = starting_index..(starting_index + number);
- range
- .into_iter()
- .map(|idx| DataObjectCreationParameters {
- size: 10 * idx as u64,
- ipfs_content_id: vec![idx],
- })
- .collect()
- }
- pub fn create_single_data_object() -> Vec<DataObjectCreationParameters> {
- create_data_object_candidates(1, 1)
- }
- pub struct SetStorageOperatorMetadataFixture {
- origin: RawOrigin<u64>,
- worker_id: u64,
- storage_bucket_id: u64,
- metadata: Vec<u8>,
- }
- impl SetStorageOperatorMetadataFixture {
- pub fn default() -> Self {
- Self {
- origin: RawOrigin::Signed(DEFAULT_MEMBER_ACCOUNT_ID),
- worker_id: DEFAULT_WORKER_ID,
- storage_bucket_id: Default::default(),
- metadata: Vec::new(),
- }
- }
- pub fn with_origin(self, origin: RawOrigin<u64>) -> Self {
- Self { origin, ..self }
- }
- pub fn with_worker_id(self, worker_id: u64) -> Self {
- Self { worker_id, ..self }
- }
- pub fn with_storage_bucket_id(self, storage_bucket_id: u64) -> Self {
- Self {
- storage_bucket_id,
- ..self
- }
- }
- pub fn with_metadata(self, metadata: Vec<u8>) -> Self {
- Self { metadata, ..self }
- }
- pub fn call_and_assert(&self, expected_result: DispatchResult) {
- let actual_result = Storage::set_storage_operator_metadata(
- self.origin.clone().into(),
- self.worker_id,
- self.storage_bucket_id,
- self.metadata.clone(),
- );
- assert_eq!(actual_result, expected_result);
- }
- }
- pub struct AcceptPendingDataObjectsFixture {
- origin: RawOrigin<u64>,
- worker_id: u64,
- storage_bucket_id: u64,
- bag_id: BagId<Test>,
- data_object_ids: BTreeSet<u64>,
- }
- impl AcceptPendingDataObjectsFixture {
- pub fn default() -> Self {
- Self {
- origin: RawOrigin::Signed(DEFAULT_STORAGE_PROVIDER_ACCOUNT_ID),
- worker_id: DEFAULT_WORKER_ID,
- storage_bucket_id: Default::default(),
- data_object_ids: Default::default(),
- bag_id: Default::default(),
- }
- }
- pub fn with_origin(self, origin: RawOrigin<u64>) -> Self {
- Self { origin, ..self }
- }
- pub fn with_worker_id(self, worker_id: u64) -> Self {
- Self { worker_id, ..self }
- }
- pub fn with_bag_id(self, bag_id: BagId<Test>) -> Self {
- Self { bag_id, ..self }
- }
- pub fn with_data_object_ids(self, data_object_ids: BTreeSet<u64>) -> Self {
- Self {
- data_object_ids,
- ..self
- }
- }
- pub fn with_storage_bucket_id(self, storage_bucket_id: u64) -> Self {
- Self {
- storage_bucket_id,
- ..self
- }
- }
- pub fn call_and_assert(&self, expected_result: DispatchResult) {
- let actual_result = Storage::accept_pending_data_objects(
- self.origin.clone().into(),
- self.worker_id,
- self.storage_bucket_id,
- self.bag_id.clone(),
- self.data_object_ids.clone(),
- );
- assert_eq!(actual_result, expected_result);
- }
- }
- pub struct CancelStorageBucketInvitationFixture {
- origin: RawOrigin<u64>,
- storage_bucket_id: u64,
- }
- impl CancelStorageBucketInvitationFixture {
- pub fn default() -> Self {
- Self {
- origin: RawOrigin::Signed(STORAGE_WG_LEADER_ACCOUNT_ID),
- storage_bucket_id: Default::default(),
- }
- }
- pub fn with_origin(self, origin: RawOrigin<u64>) -> Self {
- Self { origin, ..self }
- }
- pub fn with_storage_bucket_id(self, storage_bucket_id: u64) -> Self {
- Self {
- storage_bucket_id,
- ..self
- }
- }
- pub fn call_and_assert(&self, expected_result: DispatchResult) {
- let old_bucket = Storage::storage_bucket_by_id(self.storage_bucket_id);
- let actual_result = Storage::cancel_storage_bucket_operator_invite(
- self.origin.clone().into(),
- self.storage_bucket_id,
- );
- assert_eq!(actual_result, expected_result);
- let new_bucket = Storage::storage_bucket_by_id(self.storage_bucket_id);
- if actual_result.is_ok() {
- assert_eq!(
- new_bucket.operator_status,
- StorageBucketOperatorStatus::Missing
- );
- } else {
- assert_eq!(old_bucket, new_bucket);
- }
- }
- }
- pub struct InviteStorageBucketOperatorFixture {
- origin: RawOrigin<u64>,
- operator_worker_id: u64,
- storage_bucket_id: u64,
- }
- impl InviteStorageBucketOperatorFixture {
- pub fn default() -> Self {
- Self {
- origin: RawOrigin::Signed(DEFAULT_ACCOUNT_ID),
- operator_worker_id: DEFAULT_WORKER_ID,
- storage_bucket_id: Default::default(),
- }
- }
- pub fn with_origin(self, origin: RawOrigin<u64>) -> Self {
- Self { origin, ..self }
- }
- pub fn with_operator_worker_id(self, operator_worker_id: u64) -> Self {
- Self {
- operator_worker_id,
- ..self
- }
- }
- pub fn with_storage_bucket_id(self, storage_bucket_id: u64) -> Self {
- Self {
- storage_bucket_id,
- ..self
- }
- }
- pub fn call_and_assert(&self, expected_result: DispatchResult) {
- let old_bucket = Storage::storage_bucket_by_id(self.storage_bucket_id);
- let actual_result = Storage::invite_storage_bucket_operator(
- self.origin.clone().into(),
- self.storage_bucket_id,
- self.operator_worker_id,
- );
- assert_eq!(actual_result, expected_result);
- let new_bucket = Storage::storage_bucket_by_id(self.storage_bucket_id);
- if actual_result.is_ok() {
- assert_eq!(
- new_bucket.operator_status,
- StorageBucketOperatorStatus::InvitedStorageWorker(self.operator_worker_id)
- );
- } else {
- assert_eq!(old_bucket, new_bucket);
- }
- }
- }
- pub struct UpdateUploadingBlockedStatusFixture {
- origin: RawOrigin<u64>,
- new_status: bool,
- }
- impl UpdateUploadingBlockedStatusFixture {
- pub fn default() -> Self {
- Self {
- origin: RawOrigin::Signed(STORAGE_WG_LEADER_ACCOUNT_ID),
- new_status: false,
- }
- }
- pub fn with_origin(self, origin: RawOrigin<u64>) -> Self {
- Self { origin, ..self }
- }
- pub fn with_new_status(self, new_status: bool) -> Self {
- Self { new_status, ..self }
- }
- pub fn call_and_assert(&self, expected_result: DispatchResult) {
- let old_status = Storage::uploading_blocked();
- let actual_result =
- Storage::update_uploading_blocked_status(self.origin.clone().into(), self.new_status);
- assert_eq!(actual_result, expected_result);
- if actual_result.is_ok() {
- assert_eq!(Storage::uploading_blocked(), self.new_status);
- } else {
- assert_eq!(old_status, Storage::uploading_blocked());
- }
- }
- }
- pub struct MoveDataObjectsFixture {
- src_bag_id: BagId<Test>,
- dest_bag_id: BagId<Test>,
- data_object_ids: BTreeSet<u64>,
- }
- impl MoveDataObjectsFixture {
- pub fn default() -> Self {
- Self {
- src_bag_id: BagId::<Test>::Static(StaticBagId::Council),
- dest_bag_id: BagId::<Test>::Static(StaticBagId::Council),
- data_object_ids: BTreeSet::new(),
- }
- }
- pub fn with_src_bag_id(self, src_bag_id: BagId<Test>) -> Self {
- Self { src_bag_id, ..self }
- }
- pub fn with_dest_bag_id(self, dest_bag_id: BagId<Test>) -> Self {
- Self {
- dest_bag_id,
- ..self
- }
- }
- pub fn with_data_object_ids(self, data_object_ids: BTreeSet<u64>) -> Self {
- Self {
- data_object_ids,
- ..self
- }
- }
- pub fn call_and_assert(&self, expected_result: DispatchResult) {
- let actual_result = Storage::move_data_objects(
- self.src_bag_id.clone(),
- self.dest_bag_id.clone(),
- self.data_object_ids.clone(),
- );
- assert_eq!(actual_result, expected_result);
- }
- }
- pub struct DeleteDataObjectsFixture {
- deletion_prize_account_id: u64,
- bag_id: BagId<Test>,
- data_object_ids: BTreeSet<u64>,
- }
- impl DeleteDataObjectsFixture {
- pub fn default() -> Self {
- Self {
- bag_id: Default::default(),
- data_object_ids: Default::default(),
- deletion_prize_account_id: DEFAULT_ACCOUNT_ID,
- }
- }
- pub fn with_bag_id(self, bag_id: BagId<Test>) -> Self {
- Self { bag_id, ..self }
- }
- pub fn with_data_object_ids(self, data_object_ids: BTreeSet<u64>) -> Self {
- Self {
- data_object_ids,
- ..self
- }
- }
- pub fn with_deletion_account_id(self, deletion_prize_account_id: u64) -> Self {
- Self {
- deletion_prize_account_id,
- ..self
- }
- }
- pub fn call_and_assert(&self, expected_result: DispatchResult) {
- let actual_result = Storage::delete_data_objects(
- self.deletion_prize_account_id,
- self.bag_id.clone(),
- self.data_object_ids.clone(),
- );
- assert_eq!(actual_result, expected_result);
- }
- }
- pub struct UpdateStorageBucketStatusFixture {
- origin: RawOrigin<u64>,
- storage_bucket_id: u64,
- new_status: bool,
- }
- impl UpdateStorageBucketStatusFixture {
- pub fn default() -> Self {
- Self {
- origin: RawOrigin::Signed(DEFAULT_MEMBER_ACCOUNT_ID),
- storage_bucket_id: Default::default(),
- new_status: false,
- }
- }
- pub fn with_origin(self, origin: RawOrigin<u64>) -> Self {
- Self { origin, ..self }
- }
- pub fn with_storage_bucket_id(self, storage_bucket_id: u64) -> Self {
- Self {
- storage_bucket_id,
- ..self
- }
- }
- pub fn with_new_status(self, new_status: bool) -> Self {
- Self { new_status, ..self }
- }
- pub fn call_and_assert(&self, expected_result: DispatchResult) {
- let actual_result = Storage::update_storage_bucket_status(
- self.origin.clone().into(),
- self.storage_bucket_id,
- self.new_status,
- );
- assert_eq!(actual_result, expected_result);
- if actual_result.is_ok() {
- let bucket = Storage::storage_bucket_by_id(self.storage_bucket_id);
- assert_eq!(bucket.accepting_new_bags, self.new_status);
- }
- }
- }
- pub struct UpdateBlacklistFixture {
- origin: RawOrigin<u64>,
- remove_hashes: BTreeSet<Cid>,
- add_hashes: BTreeSet<Cid>,
- }
- impl UpdateBlacklistFixture {
- pub fn default() -> Self {
- Self {
- origin: RawOrigin::Signed(STORAGE_WG_LEADER_ACCOUNT_ID),
- remove_hashes: BTreeSet::new(),
- add_hashes: BTreeSet::new(),
- }
- }
- pub fn with_origin(self, origin: RawOrigin<u64>) -> Self {
- Self { origin, ..self }
- }
- pub fn with_add_hashes(self, add_hashes: BTreeSet<Cid>) -> Self {
- Self { add_hashes, ..self }
- }
- pub fn with_remove_hashes(self, remove_hashes: BTreeSet<Cid>) -> Self {
- Self {
- remove_hashes,
- ..self
- }
- }
- pub fn call_and_assert(&self, expected_result: DispatchResult) {
- let actual_result = Storage::update_blacklist(
- self.origin.clone().into(),
- self.remove_hashes.clone(),
- self.add_hashes.clone(),
- );
- assert_eq!(actual_result, expected_result);
- }
- }
- pub struct DeleteDynamicBagFixture {
- bag_id: DynamicBagId<Test>,
- deletion_account_id: u64,
- }
- impl DeleteDynamicBagFixture {
- pub fn default() -> Self {
- Self {
- bag_id: Default::default(),
- deletion_account_id: DEFAULT_ACCOUNT_ID,
- }
- }
- pub fn with_deletion_account_id(self, deletion_account_id: u64) -> Self {
- Self {
- deletion_account_id,
- ..self
- }
- }
- pub fn with_bag_id(self, bag_id: DynamicBagId<Test>) -> Self {
- Self { bag_id, ..self }
- }
- pub fn call_and_assert(&self, expected_result: DispatchResult) {
- let actual_result =
- Storage::delete_dynamic_bag(self.deletion_account_id, self.bag_id.clone());
- assert_eq!(actual_result, expected_result);
- }
- }
- pub struct DeleteStorageBucketFixture {
- origin: RawOrigin<u64>,
- storage_bucket_id: u64,
- }
- impl DeleteStorageBucketFixture {
- pub fn default() -> Self {
- Self {
- origin: RawOrigin::Signed(DEFAULT_ACCOUNT_ID),
- storage_bucket_id: Default::default(),
- }
- }
- pub fn with_origin(self, origin: RawOrigin<u64>) -> Self {
- Self { origin, ..self }
- }
- pub fn with_storage_bucket_id(self, storage_bucket_id: u64) -> Self {
- Self {
- storage_bucket_id,
- ..self
- }
- }
- pub fn call_and_assert(&self, expected_result: DispatchResult) {
- let actual_result =
- Storage::delete_storage_bucket(self.origin.clone().into(), self.storage_bucket_id);
- assert_eq!(actual_result, expected_result);
- if actual_result.is_ok() {
- assert!(!<crate::StorageBucketById<Test>>::contains_key(
- self.storage_bucket_id
- ));
- }
- }
- }
- pub struct RemoveStorageBucketOperatorFixture {
- origin: RawOrigin<u64>,
- storage_bucket_id: u64,
- }
- impl RemoveStorageBucketOperatorFixture {
- pub fn default() -> Self {
- Self {
- origin: RawOrigin::Signed(STORAGE_WG_LEADER_ACCOUNT_ID),
- storage_bucket_id: Default::default(),
- }
- }
- pub fn with_origin(self, origin: RawOrigin<u64>) -> Self {
- Self { origin, ..self }
- }
- pub fn with_storage_bucket_id(self, storage_bucket_id: u64) -> Self {
- Self {
- storage_bucket_id,
- ..self
- }
- }
- pub fn call_and_assert(&self, expected_result: DispatchResult) {
- let old_bucket = Storage::storage_bucket_by_id(self.storage_bucket_id);
- let actual_result = Storage::remove_storage_bucket_operator(
- self.origin.clone().into(),
- self.storage_bucket_id,
- );
- assert_eq!(actual_result, expected_result);
- let new_bucket = Storage::storage_bucket_by_id(self.storage_bucket_id);
- if actual_result.is_ok() {
- assert_eq!(
- new_bucket.operator_status,
- StorageBucketOperatorStatus::Missing
- );
- } else {
- assert_eq!(old_bucket, new_bucket);
- }
- }
- }
- pub struct UpdateDataObjectPerMegabyteFeeFixture {
- origin: RawOrigin<u64>,
- new_fee: u64,
- }
- impl UpdateDataObjectPerMegabyteFeeFixture {
- pub fn default() -> Self {
- Self {
- origin: RawOrigin::Signed(STORAGE_WG_LEADER_ACCOUNT_ID),
- new_fee: 0,
- }
- }
- pub fn with_origin(self, origin: RawOrigin<u64>) -> Self {
- Self { origin, ..self }
- }
- pub fn with_new_fee(self, new_fee: u64) -> Self {
- Self { new_fee, ..self }
- }
- pub fn call_and_assert(&self, expected_result: DispatchResult) {
- let old_fee = Storage::data_object_per_mega_byte_fee();
- let actual_result = Storage::update_data_size_fee(self.origin.clone().into(), self.new_fee);
- assert_eq!(actual_result, expected_result);
- if actual_result.is_ok() {
- assert_eq!(Storage::data_object_per_mega_byte_fee(), self.new_fee);
- } else {
- assert_eq!(old_fee, Storage::data_object_per_mega_byte_fee());
- }
- }
- }
- pub struct UpdateStorageBucketsPerBagLimitFixture {
- origin: RawOrigin<u64>,
- new_limit: u64,
- }
- impl UpdateStorageBucketsPerBagLimitFixture {
- pub fn default() -> Self {
- Self {
- origin: RawOrigin::Signed(STORAGE_WG_LEADER_ACCOUNT_ID),
- new_limit: 0,
- }
- }
- pub fn with_origin(self, origin: RawOrigin<u64>) -> Self {
- Self { origin, ..self }
- }
- pub fn with_new_limit(self, new_limit: u64) -> Self {
- Self { new_limit, ..self }
- }
- pub fn call_and_assert(&self, expected_result: DispatchResult) {
- let old_fee = Storage::storage_buckets_per_bag_limit();
- let actual_result = Storage::update_storage_buckets_per_bag_limit(
- self.origin.clone().into(),
- self.new_limit,
- );
- assert_eq!(actual_result, expected_result);
- if actual_result.is_ok() {
- assert_eq!(Storage::storage_buckets_per_bag_limit(), self.new_limit);
- } else {
- assert_eq!(old_fee, Storage::storage_buckets_per_bag_limit());
- }
- }
- }
- pub struct SetStorageBucketVoucherLimitsFixture {
- origin: RawOrigin<u64>,
- storage_bucket_id: u64,
- new_objects_size_limit: u64,
- new_objects_number_limit: u64,
- }
- impl SetStorageBucketVoucherLimitsFixture {
- pub fn default() -> Self {
- Self {
- origin: RawOrigin::Signed(DEFAULT_MEMBER_ACCOUNT_ID),
- storage_bucket_id: Default::default(),
- new_objects_size_limit: 0,
- new_objects_number_limit: 0,
- }
- }
- pub fn with_origin(self, origin: RawOrigin<u64>) -> Self {
- Self { origin, ..self }
- }
- pub fn with_storage_bucket_id(self, storage_bucket_id: u64) -> Self {
- Self {
- storage_bucket_id,
- ..self
- }
- }
- pub fn with_new_objects_size_limit(self, new_objects_size_limit: u64) -> Self {
- Self {
- new_objects_size_limit,
- ..self
- }
- }
- pub fn with_new_objects_number_limit(self, new_objects_number_limit: u64) -> Self {
- Self {
- new_objects_number_limit,
- ..self
- }
- }
- pub fn call_and_assert(&self, expected_result: DispatchResult) {
- let old_voucher = Storage::storage_bucket_by_id(self.storage_bucket_id).voucher;
- let actual_result = Storage::set_storage_bucket_voucher_limits(
- self.origin.clone().into(),
- self.storage_bucket_id,
- self.new_objects_size_limit.clone(),
- self.new_objects_number_limit.clone(),
- );
- assert_eq!(actual_result, expected_result);
- let new_voucher = Storage::storage_bucket_by_id(self.storage_bucket_id).voucher;
- if actual_result.is_ok() {
- assert_eq!(self.new_objects_size_limit, new_voucher.size_limit);
- assert_eq!(self.new_objects_number_limit, new_voucher.objects_limit);
- } else {
- assert_eq!(old_voucher.size_limit, new_voucher.size_limit);
- assert_eq!(old_voucher.objects_limit, new_voucher.objects_limit);
- }
- }
- }
- pub struct UpdateStorageBucketsVoucherMaxLimitsFixture {
- origin: RawOrigin<u64>,
- new_objects_size_limit: u64,
- new_objects_number_limit: u64,
- }
- impl UpdateStorageBucketsVoucherMaxLimitsFixture {
- pub fn default() -> Self {
- Self {
- origin: RawOrigin::Signed(STORAGE_WG_LEADER_ACCOUNT_ID),
- new_objects_size_limit: 0,
- new_objects_number_limit: 0,
- }
- }
- pub fn with_origin(self, origin: RawOrigin<u64>) -> Self {
- Self { origin, ..self }
- }
- pub fn with_new_objects_size_limit(self, new_objects_size_limit: u64) -> Self {
- Self {
- new_objects_size_limit,
- ..self
- }
- }
- pub fn with_new_objects_number_limit(self, new_objects_number_limit: u64) -> Self {
- Self {
- new_objects_number_limit,
- ..self
- }
- }
- pub fn call_and_assert(&self, expected_result: DispatchResult) {
- let old_size_limit = Storage::voucher_max_objects_size_limit();
- let old_number_limit = Storage::voucher_max_objects_number_limit();
- let actual_result = Storage::update_storage_buckets_voucher_max_limits(
- self.origin.clone().into(),
- self.new_objects_size_limit.clone(),
- self.new_objects_number_limit.clone(),
- );
- assert_eq!(actual_result, expected_result);
- if actual_result.is_ok() {
- assert_eq!(
- self.new_objects_size_limit,
- Storage::voucher_max_objects_size_limit()
- );
- assert_eq!(
- self.new_objects_number_limit,
- Storage::voucher_max_objects_number_limit()
- );
- } else {
- assert_eq!(old_size_limit, Storage::voucher_max_objects_size_limit());
- assert_eq!(
- old_number_limit,
- Storage::voucher_max_objects_number_limit()
- );
- }
- }
- }
- pub struct CreateDynamicBagFixture {
- bag_id: DynamicBagId<Test>,
- deletion_prize: Option<DynamicBagDeletionPrize<Test>>,
- }
- impl CreateDynamicBagFixture {
- pub fn default() -> Self {
- Self {
- bag_id: Default::default(),
- deletion_prize: Default::default(),
- }
- }
- pub fn with_bag_id(self, bag_id: DynamicBagId<Test>) -> Self {
- Self { bag_id, ..self }
- }
- pub fn with_deletion_prize(self, deletion_prize: DynamicBagDeletionPrize<Test>) -> Self {
- Self {
- deletion_prize: Some(deletion_prize),
- ..self
- }
- }
- pub fn call_and_assert(&self, expected_result: DispatchResult) {
- let actual_result =
- Storage::create_dynamic_bag(self.bag_id.clone(), self.deletion_prize.clone());
- assert_eq!(actual_result, expected_result);
- if actual_result.is_ok() {
- let bag_id: BagId<Test> = self.bag_id.clone().into();
- assert!(<crate::Bags<Test>>::contains_key(&bag_id));
- }
- }
- }
- pub struct UpdateNumberOfStorageBucketsInDynamicBagCreationPolicyFixture {
- origin: RawOrigin<u64>,
- new_storage_buckets_number: u64,
- dynamic_bag_type: DynamicBagType,
- }
- impl UpdateNumberOfStorageBucketsInDynamicBagCreationPolicyFixture {
- pub fn default() -> Self {
- Self {
- origin: RawOrigin::Signed(STORAGE_WG_LEADER_ACCOUNT_ID),
- new_storage_buckets_number: 0,
- dynamic_bag_type: Default::default(),
- }
- }
- pub fn with_origin(self, origin: RawOrigin<u64>) -> Self {
- Self { origin, ..self }
- }
- pub fn with_new_storage_buckets_number(self, new_storage_buckets_number: u64) -> Self {
- Self {
- new_storage_buckets_number,
- ..self
- }
- }
- pub fn with_dynamic_bag_type(self, dynamic_bag_type: DynamicBagType) -> Self {
- Self {
- dynamic_bag_type,
- ..self
- }
- }
- pub fn call_and_assert(&self, expected_result: DispatchResult) {
- let old_policy = Storage::get_dynamic_bag_creation_policy(self.dynamic_bag_type);
- let actual_result =
- Storage::update_number_of_storage_buckets_in_dynamic_bag_creation_policy(
- self.origin.clone().into(),
- self.dynamic_bag_type,
- self.new_storage_buckets_number,
- );
- assert_eq!(actual_result, expected_result);
- let new_policy = Storage::get_dynamic_bag_creation_policy(self.dynamic_bag_type);
- if actual_result.is_ok() {
- assert_eq!(
- new_policy.number_of_storage_buckets,
- self.new_storage_buckets_number
- );
- } else {
- assert_eq!(old_policy, new_policy);
- }
- }
- }
- pub struct CreateDistributionBucketFamilyFixture {
- origin: RawOrigin<u64>,
- }
- impl CreateDistributionBucketFamilyFixture {
- pub fn default() -> Self {
- Self {
- origin: RawOrigin::Signed(DEFAULT_ACCOUNT_ID),
- }
- }
- pub fn with_origin(self, origin: RawOrigin<u64>) -> Self {
- Self { origin, ..self }
- }
- pub fn call_and_assert(&self, expected_result: DispatchResult) -> Option<u64> {
- let next_family_id = Storage::next_distribution_bucket_family_id();
- let family_number = Storage::distribution_bucket_family_number();
- let actual_result = Storage::create_distribution_bucket_family(self.origin.clone().into());
- assert_eq!(actual_result, expected_result);
- if actual_result.is_ok() {
- assert_eq!(
- next_family_id + 1,
- Storage::next_distribution_bucket_family_id()
- );
- assert_eq!(
- family_number + 1,
- Storage::distribution_bucket_family_number()
- );
- assert!(<crate::DistributionBucketFamilyById<Test>>::contains_key(
- next_family_id
- ));
- Some(next_family_id)
- } else {
- assert_eq!(
- next_family_id,
- Storage::next_distribution_bucket_family_id()
- );
- assert_eq!(family_number, Storage::distribution_bucket_family_number());
- assert!(!<crate::DistributionBucketFamilyById<Test>>::contains_key(
- next_family_id
- ));
- None
- }
- }
- }
- pub struct DeleteDistributionBucketFamilyFixture {
- origin: RawOrigin<u64>,
- family_id: u64,
- }
- impl DeleteDistributionBucketFamilyFixture {
- pub fn default() -> Self {
- Self {
- origin: RawOrigin::Signed(DEFAULT_ACCOUNT_ID),
- family_id: Default::default(),
- }
- }
- pub fn with_family_id(self, family_id: u64) -> Self {
- Self { family_id, ..self }
- }
- pub fn with_origin(self, origin: RawOrigin<u64>) -> Self {
- Self { origin, ..self }
- }
- pub fn call_and_assert(&self, expected_result: DispatchResult) {
- let family_number = Storage::distribution_bucket_family_number();
- let actual_result =
- Storage::delete_distribution_bucket_family(self.origin.clone().into(), self.family_id);
- assert_eq!(actual_result, expected_result);
- if actual_result.is_ok() {
- assert_eq!(
- family_number - 1,
- Storage::distribution_bucket_family_number()
- );
- assert!(!<crate::DistributionBucketFamilyById<Test>>::contains_key(
- self.family_id
- ));
- } else {
- assert_eq!(family_number, Storage::distribution_bucket_family_number());
- }
- }
- }
- pub struct CreateDistributionBucketFixture {
- origin: RawOrigin<u64>,
- family_id: u64,
- accept_new_bags: bool,
- }
- impl CreateDistributionBucketFixture {
- pub fn default() -> Self {
- Self {
- origin: RawOrigin::Signed(DEFAULT_ACCOUNT_ID),
- family_id: Default::default(),
- accept_new_bags: false,
- }
- }
- pub fn with_family_id(self, family_id: u64) -> Self {
- Self { family_id, ..self }
- }
- pub fn with_origin(self, origin: RawOrigin<u64>) -> Self {
- Self { origin, ..self }
- }
- pub fn with_accept_new_bags(self, accept_new_bags: bool) -> Self {
- Self {
- accept_new_bags,
- ..self
- }
- }
- pub fn call_and_assert(&self, expected_result: DispatchResult) -> Option<u64> {
- let next_bucket_index = Storage::distribution_bucket_family_by_id(self.family_id)
- .next_distribution_bucket_index;
- let actual_result = Storage::create_distribution_bucket(
- self.origin.clone().into(),
- self.family_id,
- self.accept_new_bags,
- );
- assert_eq!(actual_result, expected_result);
- if actual_result.is_ok() {
- assert_eq!(
- next_bucket_index + 1,
- Storage::distribution_bucket_family_by_id(self.family_id)
- .next_distribution_bucket_index
- );
- let bucket: DistributionBucket<Test> =
- Storage::distribution_bucket_by_family_id_by_index(
- self.family_id,
- next_bucket_index,
- );
- assert_eq!(bucket.accepting_new_bags, self.accept_new_bags);
- Some(next_bucket_index)
- } else {
- assert_eq!(
- next_bucket_index,
- Storage::distribution_bucket_family_by_id(self.family_id)
- .next_distribution_bucket_index
- );
- None
- }
- }
- }
- pub struct UpdateDistributionBucketStatusFixture {
- origin: RawOrigin<u64>,
- family_id: u64,
- distribution_bucket_index: u64,
- new_status: bool,
- }
- impl UpdateDistributionBucketStatusFixture {
- pub fn default() -> Self {
- Self {
- origin: RawOrigin::Signed(DEFAULT_MEMBER_ACCOUNT_ID),
- family_id: Default::default(),
- distribution_bucket_index: Default::default(),
- new_status: false,
- }
- }
- pub fn with_bucket_index(self, bucket_index: u64) -> Self {
- Self {
- distribution_bucket_index: bucket_index,
- ..self
- }
- }
- pub fn with_family_id(self, family_id: u64) -> Self {
- Self { family_id, ..self }
- }
- pub fn with_origin(self, origin: RawOrigin<u64>) -> Self {
- Self { origin, ..self }
- }
- pub fn with_new_status(self, new_status: bool) -> Self {
- Self { new_status, ..self }
- }
- pub fn call_and_assert(&self, expected_result: DispatchResult) {
- let actual_result = Storage::update_distribution_bucket_status(
- self.origin.clone().into(),
- Storage::create_distribution_bucket_id(self.family_id, self.distribution_bucket_index),
- self.new_status,
- );
- assert_eq!(actual_result, expected_result);
- }
- }
- pub struct DeleteDistributionBucketFixture {
- origin: RawOrigin<u64>,
- family_id: u64,
- distribution_bucket_index: u64,
- }
- impl DeleteDistributionBucketFixture {
- pub fn default() -> Self {
- Self {
- origin: RawOrigin::Signed(DEFAULT_MEMBER_ACCOUNT_ID),
- family_id: Default::default(),
- distribution_bucket_index: Default::default(),
- }
- }
- pub fn with_bucket_index(self, bucket_index: u64) -> Self {
- Self {
- distribution_bucket_index: bucket_index,
- ..self
- }
- }
- pub fn with_family_id(self, family_id: u64) -> Self {
- Self { family_id, ..self }
- }
- pub fn with_origin(self, origin: RawOrigin<u64>) -> Self {
- Self { origin, ..self }
- }
- pub fn call_and_assert(&self, expected_result: DispatchResult) {
- let actual_result = Storage::delete_distribution_bucket(
- self.origin.clone().into(),
- Storage::create_distribution_bucket_id(self.family_id, self.distribution_bucket_index),
- );
- assert_eq!(actual_result, expected_result);
- }
- }
- pub struct UpdateDistributionBucketForBagsFixture {
- origin: RawOrigin<u64>,
- bag_id: BagId<Test>,
- family_id: u64,
- add_bucket_indices: BTreeSet<u64>,
- remove_bucket_indices: BTreeSet<u64>,
- }
- impl UpdateDistributionBucketForBagsFixture {
- pub fn default() -> Self {
- Self {
- origin: RawOrigin::Signed(DEFAULT_ACCOUNT_ID),
- bag_id: Default::default(),
- family_id: Default::default(),
- add_bucket_indices: Default::default(),
- remove_bucket_indices: Default::default(),
- }
- }
- pub fn with_origin(self, origin: RawOrigin<u64>) -> Self {
- Self { origin, ..self }
- }
- pub fn with_add_bucket_indices(self, add_bucket_indices: BTreeSet<u64>) -> Self {
- Self {
- add_bucket_indices,
- ..self
- }
- }
- pub fn with_remove_bucket_indices(self, remove_bucket_indices: BTreeSet<u64>) -> Self {
- Self {
- remove_bucket_indices,
- ..self
- }
- }
- pub fn with_bag_id(self, bag_id: BagId<Test>) -> Self {
- Self { bag_id, ..self }
- }
- pub fn with_family_id(self, family_id: u64) -> Self {
- Self { family_id, ..self }
- }
- pub fn call_and_assert(&self, expected_result: DispatchResult) {
- let actual_result = Storage::update_distribution_buckets_for_bag(
- self.origin.clone().into(),
- self.bag_id.clone(),
- self.family_id,
- self.add_bucket_indices.clone(),
- self.remove_bucket_indices.clone(),
- );
- assert_eq!(actual_result, expected_result);
- }
- }
- pub struct UpdateDistributionBucketsPerBagLimitFixture {
- origin: RawOrigin<u64>,
- new_limit: u64,
- }
- impl UpdateDistributionBucketsPerBagLimitFixture {
- pub fn default() -> Self {
- Self {
- origin: RawOrigin::Signed(DISTRIBUTION_WG_LEADER_ACCOUNT_ID),
- new_limit: 0,
- }
- }
- pub fn with_origin(self, origin: RawOrigin<u64>) -> Self {
- Self { origin, ..self }
- }
- pub fn with_new_limit(self, new_limit: u64) -> Self {
- Self { new_limit, ..self }
- }
- pub fn call_and_assert(&self, expected_result: DispatchResult) {
- let old_limit = Storage::distribution_buckets_per_bag_limit();
- let actual_result = Storage::update_distribution_buckets_per_bag_limit(
- self.origin.clone().into(),
- self.new_limit,
- );
- assert_eq!(actual_result, expected_result);
- if actual_result.is_ok() {
- assert_eq!(
- Storage::distribution_buckets_per_bag_limit(),
- self.new_limit
- );
- } else {
- assert_eq!(old_limit, Storage::distribution_buckets_per_bag_limit());
- }
- }
- }
- pub struct UpdateDistributionBucketModeFixture {
- origin: RawOrigin<u64>,
- family_id: u64,
- distribution_bucket_index: u64,
- distributing: bool,
- }
- impl UpdateDistributionBucketModeFixture {
- pub fn default() -> Self {
- Self {
- origin: RawOrigin::Signed(DEFAULT_MEMBER_ACCOUNT_ID),
- family_id: Default::default(),
- distribution_bucket_index: Default::default(),
- distributing: true,
- }
- }
- pub fn with_bucket_index(self, bucket_index: u64) -> Self {
- Self {
- distribution_bucket_index: bucket_index,
- ..self
- }
- }
- pub fn with_family_id(self, family_id: u64) -> Self {
- Self { family_id, ..self }
- }
- pub fn with_origin(self, origin: RawOrigin<u64>) -> Self {
- Self { origin, ..self }
- }
- pub fn with_distributing(self, distributing: bool) -> Self {
- Self {
- distributing,
- ..self
- }
- }
- pub fn call_and_assert(&self, expected_result: DispatchResult) {
- let actual_result = Storage::update_distribution_bucket_mode(
- self.origin.clone().into(),
- Storage::create_distribution_bucket_id(self.family_id, self.distribution_bucket_index),
- self.distributing,
- );
- assert_eq!(actual_result, expected_result);
- }
- }
- pub struct UpdateFamiliesInDynamicBagCreationPolicyFixture {
- origin: RawOrigin<u64>,
- dynamic_bag_type: DynamicBagType,
- families: BTreeMap<u64, u32>,
- }
- impl UpdateFamiliesInDynamicBagCreationPolicyFixture {
- pub fn default() -> Self {
- Self {
- origin: RawOrigin::Signed(STORAGE_WG_LEADER_ACCOUNT_ID),
- dynamic_bag_type: Default::default(),
- families: Default::default(),
- }
- }
- pub fn with_origin(self, origin: RawOrigin<u64>) -> Self {
- Self { origin, ..self }
- }
- pub fn with_families(self, families: BTreeMap<u64, u32>) -> Self {
- Self { families, ..self }
- }
- pub fn with_dynamic_bag_type(self, dynamic_bag_type: DynamicBagType) -> Self {
- Self {
- dynamic_bag_type,
- ..self
- }
- }
- pub fn call_and_assert(&self, expected_result: DispatchResult) {
- let old_policy = Storage::get_dynamic_bag_creation_policy(self.dynamic_bag_type);
- let actual_result = Storage::update_families_in_dynamic_bag_creation_policy(
- self.origin.clone().into(),
- self.dynamic_bag_type,
- self.families.clone(),
- );
- assert_eq!(actual_result, expected_result);
- let new_policy = Storage::get_dynamic_bag_creation_policy(self.dynamic_bag_type);
- assert_eq!(
- old_policy.number_of_storage_buckets,
- new_policy.number_of_storage_buckets
- );
- if actual_result.is_ok() {
- assert_eq!(new_policy.families, self.families);
- } else {
- assert_eq!(old_policy, new_policy);
- }
- }
- }
- pub struct InviteDistributionBucketOperatorFixture {
- origin: RawOrigin<u64>,
- operator_worker_id: u64,
- family_id: u64,
- bucket_index: u64,
- }
- impl InviteDistributionBucketOperatorFixture {
- pub fn default() -> Self {
- Self {
- origin: RawOrigin::Signed(DEFAULT_ACCOUNT_ID),
- operator_worker_id: DEFAULT_WORKER_ID,
- bucket_index: Default::default(),
- family_id: Default::default(),
- }
- }
- pub fn with_origin(self, origin: RawOrigin<u64>) -> Self {
- Self { origin, ..self }
- }
- pub fn with_operator_worker_id(self, operator_worker_id: u64) -> Self {
- Self {
- operator_worker_id,
- ..self
- }
- }
- pub fn with_bucket_index(self, bucket_index: u64) -> Self {
- Self {
- bucket_index,
- ..self
- }
- }
- pub fn with_family_id(self, family_id: u64) -> Self {
- Self { family_id, ..self }
- }
- pub fn call_and_assert(&self, expected_result: DispatchResult) {
- let actual_result = Storage::invite_distribution_bucket_operator(
- self.origin.clone().into(),
- Storage::create_distribution_bucket_id(self.family_id, self.bucket_index),
- self.operator_worker_id,
- );
- assert_eq!(actual_result, expected_result);
- if actual_result.is_ok() {
- let new_bucket: DistributionBucket<Test> =
- Storage::distribution_bucket_by_family_id_by_index(
- self.family_id,
- self.bucket_index,
- );
- assert!(new_bucket
- .pending_invitations
- .contains(&self.operator_worker_id),);
- }
- }
- }
- pub struct CancelDistributionBucketInvitationFixture {
- origin: RawOrigin<u64>,
- bucket_index: u64,
- family_id: u64,
- operator_worker_id: u64,
- }
- impl CancelDistributionBucketInvitationFixture {
- pub fn default() -> Self {
- Self {
- origin: RawOrigin::Signed(DEFAULT_DISTRIBUTION_PROVIDER_ACCOUNT_ID),
- bucket_index: Default::default(),
- family_id: Default::default(),
- operator_worker_id: Default::default(),
- }
- }
- pub fn with_origin(self, origin: RawOrigin<u64>) -> Self {
- Self { origin, ..self }
- }
- pub fn with_bucket_index(self, bucket_index: u64) -> Self {
- Self {
- bucket_index,
- ..self
- }
- }
- pub fn with_family_id(self, family_id: u64) -> Self {
- Self { family_id, ..self }
- }
- pub fn with_operator_worker_id(self, operator_worker_id: u64) -> Self {
- Self {
- operator_worker_id,
- ..self
- }
- }
- pub fn call_and_assert(&self, expected_result: DispatchResult) {
- let actual_result = Storage::cancel_distribution_bucket_operator_invite(
- self.origin.clone().into(),
- Storage::create_distribution_bucket_id(self.family_id, self.bucket_index),
- self.operator_worker_id,
- );
- assert_eq!(actual_result, expected_result);
- if actual_result.is_ok() {
- let new_bucket: DistributionBucket<Test> =
- Storage::distribution_bucket_by_family_id_by_index(
- self.family_id,
- self.bucket_index,
- );
- assert!(!new_bucket
- .pending_invitations
- .contains(&self.operator_worker_id));
- }
- }
- }
- pub struct AcceptDistributionBucketInvitationFixture {
- origin: RawOrigin<u64>,
- bucket_index: u64,
- family_id: u64,
- worker_id: u64,
- }
- impl AcceptDistributionBucketInvitationFixture {
- pub fn default() -> Self {
- Self {
- origin: RawOrigin::Signed(DEFAULT_DISTRIBUTION_PROVIDER_ACCOUNT_ID),
- bucket_index: Default::default(),
- family_id: Default::default(),
- worker_id: Default::default(),
- }
- }
- pub fn with_origin(self, origin: RawOrigin<u64>) -> Self {
- Self { origin, ..self }
- }
- pub fn with_bucket_index(self, bucket_index: u64) -> Self {
- Self {
- bucket_index,
- ..self
- }
- }
- pub fn with_family_id(self, family_id: u64) -> Self {
- Self { family_id, ..self }
- }
- pub fn with_worker_id(self, worker_id: u64) -> Self {
- Self { worker_id, ..self }
- }
- pub fn call_and_assert(&self, expected_result: DispatchResult) {
- let actual_result = Storage::accept_distribution_bucket_invitation(
- self.origin.clone().into(),
- self.worker_id,
- Storage::create_distribution_bucket_id(self.family_id, self.bucket_index),
- );
- assert_eq!(actual_result, expected_result);
- if actual_result.is_ok() {
- let new_bucket: DistributionBucket<Test> =
- Storage::distribution_bucket_by_family_id_by_index(
- self.family_id,
- self.bucket_index,
- );
- assert!(!new_bucket.pending_invitations.contains(&self.worker_id));
- assert!(new_bucket.operators.contains(&self.worker_id));
- }
- }
- }
- pub struct SetDistributionBucketMetadataFixture {
- origin: RawOrigin<u64>,
- bucket_index: u64,
- family_id: u64,
- worker_id: u64,
- metadata: Vec<u8>,
- }
- impl SetDistributionBucketMetadataFixture {
- pub fn default() -> Self {
- Self {
- origin: RawOrigin::Signed(DEFAULT_DISTRIBUTION_PROVIDER_ACCOUNT_ID),
- bucket_index: Default::default(),
- family_id: Default::default(),
- worker_id: Default::default(),
- metadata: Default::default(),
- }
- }
- pub fn with_metadata(self, metadata: Vec<u8>) -> Self {
- Self { metadata, ..self }
- }
- pub fn with_origin(self, origin: RawOrigin<u64>) -> Self {
- Self { origin, ..self }
- }
- pub fn with_bucket_index(self, bucket_index: u64) -> Self {
- Self {
- bucket_index,
- ..self
- }
- }
- pub fn with_family_id(self, family_id: u64) -> Self {
- Self { family_id, ..self }
- }
- pub fn with_worker_id(self, worker_id: u64) -> Self {
- Self { worker_id, ..self }
- }
- pub fn call_and_assert(&self, expected_result: DispatchResult) {
- let actual_result = Storage::set_distribution_operator_metadata(
- self.origin.clone().into(),
- self.worker_id,
- Storage::create_distribution_bucket_id(self.family_id, self.bucket_index),
- self.metadata.clone(),
- );
- assert_eq!(actual_result, expected_result);
- }
- }
- pub struct RemoveDistributionBucketOperatorFixture {
- origin: RawOrigin<u64>,
- bucket_index: u64,
- family_id: u64,
- operator_worker_id: u64,
- }
- impl RemoveDistributionBucketOperatorFixture {
- pub fn default() -> Self {
- Self {
- origin: RawOrigin::Signed(DISTRIBUTION_WG_LEADER_ACCOUNT_ID),
- bucket_index: Default::default(),
- family_id: Default::default(),
- operator_worker_id: Default::default(),
- }
- }
- pub fn with_origin(self, origin: RawOrigin<u64>) -> Self {
- Self { origin, ..self }
- }
- pub fn with_bucket_index(self, bucket_index: u64) -> Self {
- Self {
- bucket_index,
- ..self
- }
- }
- pub fn with_family_id(self, family_id: u64) -> Self {
- Self { family_id, ..self }
- }
- pub fn with_operator_worker_id(self, operator_worker_id: u64) -> Self {
- Self {
- operator_worker_id,
- ..self
- }
- }
- pub fn call_and_assert(&self, expected_result: DispatchResult) {
- let actual_result = Storage::remove_distribution_bucket_operator(
- self.origin.clone().into(),
- Storage::create_distribution_bucket_id(self.family_id, self.bucket_index),
- self.operator_worker_id,
- );
- assert_eq!(actual_result, expected_result);
- if actual_result.is_ok() {
- let new_bucket: DistributionBucket<Test> =
- Storage::distribution_bucket_by_family_id_by_index(
- self.family_id,
- self.bucket_index,
- );
- assert!(!new_bucket.operators.contains(&self.operator_worker_id));
- }
- }
- }
- pub struct SetDistributionBucketFamilyMetadataFixture {
- origin: RawOrigin<u64>,
- family_id: u64,
- metadata: Vec<u8>,
- }
- impl SetDistributionBucketFamilyMetadataFixture {
- pub fn default() -> Self {
- Self {
- origin: RawOrigin::Signed(DEFAULT_DISTRIBUTION_PROVIDER_ACCOUNT_ID),
- family_id: Default::default(),
- metadata: Default::default(),
- }
- }
- pub fn with_metadata(self, metadata: Vec<u8>) -> Self {
- Self { metadata, ..self }
- }
- pub fn with_origin(self, origin: RawOrigin<u64>) -> Self {
- Self { origin, ..self }
- }
- pub fn with_family_id(self, family_id: u64) -> Self {
- Self { family_id, ..self }
- }
- pub fn call_and_assert(&self, expected_result: DispatchResult) {
- let actual_result = Storage::set_distribution_bucket_family_metadata(
- self.origin.clone().into(),
- self.family_id,
- self.metadata.clone(),
- );
- assert_eq!(actual_result, expected_result);
- }
- }
|