123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998 |
- mod fixtures;
- mod hiring_workflow;
- mod mock;
- use crate::types::{OpeningPolicyCommitment, OpeningType, RewardPolicy};
- use crate::{Error, RawEvent, Worker};
- use common::constraints::InputValidationLengthConstraint;
- use mock::{
- build_test_externalities, Test, TestWorkingGroup, TestWorkingGroupInstance,
- WORKING_GROUP_CONSTRAINT_DIFF, WORKING_GROUP_CONSTRAINT_MIN, WORKING_GROUP_MINT_CAPACITY,
- };
- use srml_support::{StorageLinkedMap, StorageValue};
- use std::collections::BTreeMap;
- use system::RawOrigin;
- use crate::tests::hiring_workflow::HiringWorkflow;
- use fixtures::*;
- #[test]
- fn hire_lead_succeeds() {
- build_test_externalities().execute_with(|| {
- // Ensure that lead is default
- assert_eq!(TestWorkingGroup::current_lead(), None);
- HireLeadFixture::default().hire_lead();
- assert!(TestWorkingGroup::current_lead().is_some());
- });
- }
- #[test]
- fn hire_lead_fails_with_existing_lead() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- let hiring_workflow = HiringWorkflow::default()
- .disable_setup_environment()
- .with_opening_type(OpeningType::Leader)
- .add_application(b"leader_handle".to_vec())
- .expect(Err(Error::CannotHireLeaderWhenLeaderExists));
- hiring_workflow.execute();
- });
- }
- #[test]
- fn hire_lead_fails_multiple_applications() {
- build_test_externalities().execute_with(|| {
- let hiring_workflow = HiringWorkflow::default()
- .with_opening_type(OpeningType::Leader)
- .add_application_with_origin(b"leader_handle".to_vec(), RawOrigin::Signed(1), 1)
- .add_application_with_origin(b"leader_handle2".to_vec(), RawOrigin::Signed(2), 2)
- .expect(Err(Error::CannotHireMultipleLeaders));
- hiring_workflow.execute();
- });
- }
- #[test]
- fn add_opening_fails_with_incorrect_unstaking_periods() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- let add_opening_fixture =
- AddWorkerOpeningFixture::default().with_policy_commitment(OpeningPolicyCommitment {
- fill_opening_failed_applicant_role_stake_unstaking_period: Some(0),
- ..OpeningPolicyCommitment::default()
- });
- add_opening_fixture.call_and_assert(Err(
- Error::FillOpeningFailedApplicantRoleStakeUnstakingPeriodIsZero,
- ));
- let add_opening_fixture =
- AddWorkerOpeningFixture::default().with_policy_commitment(OpeningPolicyCommitment {
- fill_opening_failed_applicant_application_stake_unstaking_period: Some(0),
- ..OpeningPolicyCommitment::default()
- });
- add_opening_fixture.call_and_assert(Err(
- Error::FillOpeningFailedApplicantApplicationStakeUnstakingPeriodIsZero,
- ));
- let add_opening_fixture =
- AddWorkerOpeningFixture::default().with_policy_commitment(OpeningPolicyCommitment {
- fill_opening_successful_applicant_application_stake_unstaking_period: Some(0),
- ..OpeningPolicyCommitment::default()
- });
- add_opening_fixture.call_and_assert(Err(
- Error::FillOpeningSuccessfulApplicantApplicationStakeUnstakingPeriodIsZero,
- ));
- });
- }
- #[test]
- fn add_opening_succeeds() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- let add_opening_fixture = AddWorkerOpeningFixture::default();
- let opening_id = add_opening_fixture.call_and_assert(Ok(()));
- EventFixture::assert_last_crate_event(RawEvent::OpeningAdded(opening_id));
- });
- }
- #[test]
- fn add_leader_opening_succeeds_fails_with_incorrect_origin_for_opening_type() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- let add_opening_fixture =
- AddWorkerOpeningFixture::default().with_opening_type(OpeningType::Leader);
- add_opening_fixture.call_and_assert(Err(Error::RequireRootOrigin));
- });
- }
- #[test]
- fn add_leader_opening_succeeds() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- let add_opening_fixture = AddWorkerOpeningFixture::default()
- .with_opening_type(OpeningType::Leader)
- .with_origin(RawOrigin::Root);
- add_opening_fixture.call_and_assert(Ok(()));
- });
- }
- #[test]
- fn add_opening_fails_with_lead_is_not_set() {
- build_test_externalities().execute_with(|| {
- let add_opening_fixture = AddWorkerOpeningFixture::default();
- add_opening_fixture.call_and_assert(Err(Error::CurrentLeadNotSet));
- });
- }
- #[test]
- fn add_opening_fails_with_invalid_human_readable_text() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- <crate::OpeningHumanReadableText<TestWorkingGroupInstance>>::put(
- InputValidationLengthConstraint {
- min: 1,
- max_min_diff: 5,
- },
- );
- let add_opening_fixture = AddWorkerOpeningFixture::default().with_text(Vec::new());
- add_opening_fixture.call_and_assert(Err(Error::Other("OpeningTextTooShort")));
- let add_opening_fixture =
- AddWorkerOpeningFixture::default().with_text(b"Long text".to_vec());
- add_opening_fixture.call_and_assert(Err(Error::Other("OpeningTextTooLong")));
- });
- }
- #[test]
- fn add_opening_fails_with_hiring_error() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- let add_opening_fixture = AddWorkerOpeningFixture::default()
- .with_activate_at(hiring::ActivateOpeningAt::ExactBlock(0));
- add_opening_fixture.call_and_assert(Err(Error::AddWorkerOpeningActivatesInThePast));
- });
- }
- #[test]
- fn accept_applications_succeeds() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- let add_opening_fixture = AddWorkerOpeningFixture::default()
- .with_activate_at(hiring::ActivateOpeningAt::ExactBlock(5));
- let opening_id = add_opening_fixture.call_and_assert(Ok(()));
- let accept_applications_fixture =
- AcceptWorkerApplicationsFixture::default_for_opening_id(opening_id);
- accept_applications_fixture.call_and_assert(Ok(()));
- EventFixture::assert_last_crate_event(RawEvent::AcceptedApplications(opening_id));
- });
- }
- #[test]
- fn accept_applications_fails_for_invalid_opening_type() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- let add_opening_fixture = AddWorkerOpeningFixture::default()
- .with_origin(RawOrigin::Root)
- .with_opening_type(OpeningType::Leader)
- .with_activate_at(hiring::ActivateOpeningAt::ExactBlock(5));
- let opening_id = add_opening_fixture.call_and_assert(Ok(()));
- let accept_applications_fixture =
- AcceptWorkerApplicationsFixture::default_for_opening_id(opening_id);
- accept_applications_fixture.call_and_assert(Err(Error::RequireRootOrigin));
- });
- }
- #[test]
- fn accept_applications_fails_with_hiring_error() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- let add_opening_fixture = AddWorkerOpeningFixture::default();
- let opening_id = add_opening_fixture.call_and_assert(Ok(()));
- let accept_applications_fixture =
- AcceptWorkerApplicationsFixture::default_for_opening_id(opening_id);
- accept_applications_fixture.call_and_assert(Err(
- Error::AcceptWorkerApplicationsOpeningIsNotWaitingToBegin,
- ));
- });
- }
- #[test]
- fn accept_applications_fails_with_not_lead() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- let add_opening_fixture = AddWorkerOpeningFixture::default();
- let opening_id = add_opening_fixture.call_and_assert(Ok(()));
- SetLeadFixture::set_lead_with_ids(2, 2, 2);
- let accept_applications_fixture =
- AcceptWorkerApplicationsFixture::default_for_opening_id(opening_id);
- accept_applications_fixture.call_and_assert(Err(Error::IsNotLeadAccount));
- });
- }
- #[test]
- fn accept_applications_fails_with_no_opening() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- let opening_id = 55; // random opening id
- let accept_applications_fixture =
- AcceptWorkerApplicationsFixture::default_for_opening_id(opening_id);
- accept_applications_fixture.call_and_assert(Err(Error::OpeningDoesNotExist));
- });
- }
- #[test]
- fn apply_on_opening_succeeds() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- let add_opening_fixture = AddWorkerOpeningFixture::default();
- let opening_id = add_opening_fixture.call_and_assert(Ok(()));
- let apply_on_opening_fixture =
- ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
- let application_id = apply_on_opening_fixture.call_and_assert(Ok(()));
- EventFixture::assert_last_crate_event(RawEvent::AppliedOnOpening(
- opening_id,
- application_id,
- ));
- });
- }
- #[test]
- fn apply_on_opening_fails_with_no_opening() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- let opening_id = 123; // random opening id
- let apply_on_opening_fixture =
- ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
- apply_on_opening_fixture.call_and_assert(Err(Error::OpeningDoesNotExist));
- });
- }
- #[test]
- fn apply_on_opening_fails_with_not_set_members() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- let add_opening_fixture = AddWorkerOpeningFixture::default();
- let opening_id = add_opening_fixture.call_and_assert(Ok(()));
- let apply_on_opening_fixture =
- ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id)
- .with_origin(RawOrigin::Signed(55), 55);
- apply_on_opening_fixture.call_and_assert(Err(Error::OriginIsNeitherMemberControllerOrRoot));
- });
- }
- #[test]
- fn apply_on_opening_fails_with_hiring_error() {
- build_test_externalities().execute_with(|| {
- increase_total_balance_issuance_using_account_id(1, 500000);
- HireLeadFixture::default().hire_lead();
- let add_opening_fixture = AddWorkerOpeningFixture::default();
- let opening_id = add_opening_fixture.call_and_assert(Ok(()));
- let apply_on_opening_fixture =
- ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id)
- .with_application_stake(100);
- apply_on_opening_fixture
- .call_and_assert(Err(Error::AddWorkerOpeningStakeProvidedWhenRedundant));
- });
- }
- #[test]
- fn apply_on_opening_fails_with_invalid_application_stake() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- let stake = 100;
- let add_opening_fixture =
- AddWorkerOpeningFixture::default().with_policy_commitment(OpeningPolicyCommitment {
- application_staking_policy: Some(hiring::StakingPolicy {
- amount: stake,
- ..hiring::StakingPolicy::default()
- }),
- ..OpeningPolicyCommitment::default()
- });
- let opening_id = add_opening_fixture.call_and_assert(Ok(()));
- let apply_on_opening_fixture =
- ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id)
- .with_origin(RawOrigin::Signed(2), 2)
- .with_application_stake(stake);
- apply_on_opening_fixture.call_and_assert(Err(Error::InsufficientBalanceToApply));
- });
- }
- #[test]
- fn add_opening_fails_with_invalid_zero_application_stake() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- let zero_stake = 0;
- let add_opening_fixture =
- AddWorkerOpeningFixture::default().with_policy_commitment(OpeningPolicyCommitment {
- application_staking_policy: Some(hiring::StakingPolicy {
- amount: zero_stake,
- amount_mode: hiring::StakingAmountLimitMode::AtLeast,
- ..hiring::StakingPolicy::default()
- }),
- ..OpeningPolicyCommitment::default()
- });
- add_opening_fixture
- .call_and_assert(Err(Error::AddWorkerOpeningApplicationStakeCannotBeZero));
- });
- }
- #[test]
- fn apply_on_opening_fails_with_invalid_role_stake() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- let stake = 100;
- let add_opening_fixture =
- AddWorkerOpeningFixture::default().with_policy_commitment(OpeningPolicyCommitment {
- role_staking_policy: Some(hiring::StakingPolicy {
- amount: stake,
- ..hiring::StakingPolicy::default()
- }),
- ..OpeningPolicyCommitment::default()
- });
- let opening_id = add_opening_fixture.call_and_assert(Ok(()));
- let apply_on_opening_fixture =
- ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id)
- .with_role_stake(Some(stake))
- .with_origin(RawOrigin::Signed(2), 2);
- apply_on_opening_fixture.call_and_assert(Err(Error::InsufficientBalanceToApply));
- });
- }
- #[test]
- fn apply_on_opening_fails_with_invalid_text() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- let add_opening_fixture = AddWorkerOpeningFixture::default();
- let opening_id = add_opening_fixture.call_and_assert(Ok(()));
- <crate::WorkerApplicationHumanReadableText<TestWorkingGroupInstance>>::put(
- InputValidationLengthConstraint {
- min: 1,
- max_min_diff: 5,
- },
- );
- let apply_on_opening_fixture =
- ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id).with_text(Vec::new());
- apply_on_opening_fixture
- .call_and_assert(Err(Error::Other("WorkerApplicationTextTooShort")));
- let apply_on_opening_fixture =
- ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id)
- .with_text(b"Long text".to_vec());
- apply_on_opening_fixture.call_and_assert(Err(Error::Other("WorkerApplicationTextTooLong")));
- });
- }
- #[test]
- fn apply_on_opening_fails_with_already_active_application() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- let add_opening_fixture = AddWorkerOpeningFixture::default();
- let opening_id = add_opening_fixture.call_and_assert(Ok(()));
- let apply_on_opening_fixture =
- ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
- apply_on_opening_fixture.call_and_assert(Ok(()));
- apply_on_opening_fixture.call_and_assert(Err(Error::MemberHasActiveApplicationOnOpening));
- });
- }
- #[test]
- fn withdraw_worker_application_succeeds() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- let add_opening_fixture = AddWorkerOpeningFixture::default();
- let opening_id = add_opening_fixture.call_and_assert(Ok(()));
- let apply_on_opening_fixture =
- ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
- let application_id = apply_on_opening_fixture.call_and_assert(Ok(()));
- let withdraw_application_fixture =
- WithdrawApplicationFixture::default_for_application_id(application_id);
- withdraw_application_fixture.call_and_assert(Ok(()));
- EventFixture::assert_last_crate_event(RawEvent::ApplicationWithdrawn(application_id));
- });
- }
- #[test]
- fn withdraw_worker_application_fails_invalid_application_id() {
- build_test_externalities().execute_with(|| {
- let invalid_application_id = 6;
- let withdraw_application_fixture =
- WithdrawApplicationFixture::default_for_application_id(invalid_application_id);
- withdraw_application_fixture.call_and_assert(Err(Error::WorkerApplicationDoesNotExist));
- });
- }
- #[test]
- fn withdraw_worker_application_fails_invalid_origin() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- let add_opening_fixture = AddWorkerOpeningFixture::default();
- let opening_id = add_opening_fixture.call_and_assert(Ok(()));
- let apply_on_opening_fixture =
- ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
- let application_id = apply_on_opening_fixture.call_and_assert(Ok(()));
- let withdraw_application_fixture =
- WithdrawApplicationFixture::default_for_application_id(application_id)
- .with_origin(RawOrigin::None);
- withdraw_application_fixture.call_and_assert(Err(Error::RequireSignedOrigin));
- });
- }
- #[test]
- fn withdraw_worker_application_fails_with_invalid_application_author() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- let add_opening_fixture = AddWorkerOpeningFixture::default();
- let opening_id = add_opening_fixture.call_and_assert(Ok(()));
- let apply_on_opening_fixture =
- ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
- let application_id = apply_on_opening_fixture.call_and_assert(Ok(()));
- let invalid_author_account_id = 55;
- let withdraw_application_fixture =
- WithdrawApplicationFixture::default_for_application_id(application_id)
- .with_signer(invalid_author_account_id);
- withdraw_application_fixture.call_and_assert(Err(Error::OriginIsNotApplicant));
- });
- }
- #[test]
- fn withdraw_worker_application_fails_with_hiring_error() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- let add_opening_fixture = AddWorkerOpeningFixture::default();
- let opening_id = add_opening_fixture.call_and_assert(Ok(()));
- let apply_on_opening_fixture =
- ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
- let application_id = apply_on_opening_fixture.call_and_assert(Ok(()));
- let withdraw_application_fixture =
- WithdrawApplicationFixture::default_for_application_id(application_id);
- withdraw_application_fixture.call_and_assert(Ok(()));
- withdraw_application_fixture
- .call_and_assert(Err(Error::WithdrawWorkerApplicationApplicationNotActive));
- });
- }
- #[test]
- fn terminate_worker_application_succeeds() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- let add_opening_fixture = AddWorkerOpeningFixture::default();
- let opening_id = add_opening_fixture.call_and_assert(Ok(()));
- let apply_on_opening_fixture =
- ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
- let application_id = apply_on_opening_fixture.call_and_assert(Ok(()));
- let terminate_application_fixture =
- TerminateApplicationFixture::default_for_application_id(application_id);
- terminate_application_fixture.call_and_assert(Ok(()));
- EventFixture::assert_last_crate_event(RawEvent::ApplicationTerminated(application_id));
- });
- }
- #[test]
- fn terminate_worker_application_fails_with_invalid_application_author() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- let add_opening_fixture = AddWorkerOpeningFixture::default();
- let opening_id = add_opening_fixture.call_and_assert(Ok(()));
- let apply_on_opening_fixture =
- ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
- let application_id = apply_on_opening_fixture.call_and_assert(Ok(()));
- let invalid_author_account_id = 55;
- let terminate_application_fixture =
- TerminateApplicationFixture::default_for_application_id(application_id)
- .with_signer(invalid_author_account_id);
- terminate_application_fixture.call_and_assert(Err(Error::IsNotLeadAccount));
- });
- }
- #[test]
- fn terminate_worker_application_fails_invalid_origin() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- let add_opening_fixture = AddWorkerOpeningFixture::default();
- let opening_id = add_opening_fixture.call_and_assert(Ok(()));
- let apply_on_opening_fixture =
- ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
- let application_id = apply_on_opening_fixture.call_and_assert(Ok(()));
- let terminate_application_fixture =
- TerminateApplicationFixture::default_for_application_id(application_id)
- .with_origin(RawOrigin::None);
- terminate_application_fixture.call_and_assert(Err(Error::RequireSignedOrigin));
- });
- }
- #[test]
- fn terminate_worker_application_fails_invalid_application_id() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- let invalid_application_id = 6;
- let terminate_application_fixture =
- TerminateApplicationFixture::default_for_application_id(invalid_application_id);
- terminate_application_fixture.call_and_assert(Err(Error::WorkerApplicationDoesNotExist));
- });
- }
- #[test]
- fn terminate_worker_application_fails_with_hiring_error() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- let add_opening_fixture = AddWorkerOpeningFixture::default();
- let opening_id = add_opening_fixture.call_and_assert(Ok(()));
- let apply_on_opening_fixture =
- ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
- let application_id = apply_on_opening_fixture.call_and_assert(Ok(()));
- let terminate_application_fixture =
- TerminateApplicationFixture::default_for_application_id(application_id);
- terminate_application_fixture.call_and_assert(Ok(()));
- terminate_application_fixture
- .call_and_assert(Err(Error::WithdrawWorkerApplicationApplicationNotActive));
- });
- }
- #[test]
- fn begin_review_worker_applications_succeeds() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- let add_opening_fixture = AddWorkerOpeningFixture::default();
- let opening_id = add_opening_fixture.call_and_assert(Ok(()));
- let begin_review_worker_applications_fixture =
- BeginReviewWorkerApplicationsFixture::default_for_opening_id(opening_id);
- begin_review_worker_applications_fixture.call_and_assert(Ok(()));
- EventFixture::assert_last_crate_event(RawEvent::BeganApplicationReview(opening_id));
- });
- }
- #[test]
- fn begin_review_worker_applications_fails_with_invalid_origin_for_opening_type() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- let add_opening_fixture = AddWorkerOpeningFixture::default()
- .with_origin(RawOrigin::Root)
- .with_opening_type(OpeningType::Leader);
- let opening_id = add_opening_fixture.call_and_assert(Ok(()));
- let begin_review_worker_applications_fixture =
- BeginReviewWorkerApplicationsFixture::default_for_opening_id(opening_id);
- begin_review_worker_applications_fixture.call_and_assert(Err(Error::RequireRootOrigin));
- });
- }
- #[test]
- fn begin_review_worker_applications_fails_with_not_a_lead() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- let add_opening_fixture = AddWorkerOpeningFixture::default();
- let opening_id = add_opening_fixture.call_and_assert(Ok(()));
- SetLeadFixture::set_lead_with_ids(2, 2, 2);
- let begin_review_worker_applications_fixture =
- BeginReviewWorkerApplicationsFixture::default_for_opening_id(opening_id);
- begin_review_worker_applications_fixture.call_and_assert(Err(Error::IsNotLeadAccount));
- });
- }
- #[test]
- fn begin_review_worker_applications_fails_with_invalid_opening() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- let invalid_opening_id = 6;
- let begin_review_worker_applications_fixture =
- BeginReviewWorkerApplicationsFixture::default_for_opening_id(invalid_opening_id);
- begin_review_worker_applications_fixture.call_and_assert(Err(Error::OpeningDoesNotExist));
- });
- }
- #[test]
- fn begin_review_worker_applications_with_hiring_error() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- let add_opening_fixture = AddWorkerOpeningFixture::default();
- let opening_id = add_opening_fixture.call_and_assert(Ok(()));
- let begin_review_worker_applications_fixture =
- BeginReviewWorkerApplicationsFixture::default_for_opening_id(opening_id);
- begin_review_worker_applications_fixture.call_and_assert(Ok(()));
- begin_review_worker_applications_fixture.call_and_assert(Err(
- Error::BeginWorkerApplicantReviewOpeningOpeningIsNotWaitingToBegin,
- ));
- });
- }
- #[test]
- fn begin_review_worker_applications_fails_with_invalid_origin() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- let add_opening_fixture = AddWorkerOpeningFixture::default();
- let opening_id = add_opening_fixture.call_and_assert(Ok(()));
- let begin_review_worker_applications_fixture =
- BeginReviewWorkerApplicationsFixture::default_for_opening_id(opening_id)
- .with_origin(RawOrigin::None);
- begin_review_worker_applications_fixture.call_and_assert(Err(Error::RequireSignedOrigin));
- });
- }
- #[test]
- fn fill_opening_succeeds() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- increase_total_balance_issuance_using_account_id(1, 10000);
- let add_opening_fixture =
- AddWorkerOpeningFixture::default().with_policy_commitment(OpeningPolicyCommitment {
- role_staking_policy: Some(hiring::StakingPolicy {
- amount: 10,
- amount_mode: hiring::StakingAmountLimitMode::AtLeast,
- crowded_out_unstaking_period_length: None,
- review_period_expired_unstaking_period_length: None,
- }),
- ..OpeningPolicyCommitment::default()
- });
- let opening_id = add_opening_fixture.call_and_assert(Ok(()));
- let apply_on_opening_fixture =
- ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id)
- .with_role_stake(Some(10));
- let application_id = apply_on_opening_fixture.call_and_assert(Ok(()));
- let begin_review_worker_applications_fixture =
- BeginReviewWorkerApplicationsFixture::default_for_opening_id(opening_id);
- begin_review_worker_applications_fixture.call_and_assert(Ok(()));
- let mint_id = create_mint();
- set_mint_id(mint_id);
- let fill_opening_fixture =
- FillWorkerOpeningFixture::default_for_ids(opening_id, vec![application_id])
- .with_reward_policy(RewardPolicy {
- amount_per_payout: 1000,
- next_payment_at_block: 20,
- payout_interval: None,
- });
- let worker_id = fill_opening_fixture.call_and_assert(Ok(()));
- let mut worker_application_dictionary = BTreeMap::new();
- worker_application_dictionary.insert(application_id, worker_id);
- EventFixture::assert_last_crate_event(RawEvent::OpeningFilled(
- opening_id,
- worker_application_dictionary,
- ));
- });
- }
- #[test]
- fn fill_opening_fails_with_invalid_origin_for_opening_type() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- increase_total_balance_issuance_using_account_id(1, 10000);
- let add_opening_fixture = AddWorkerOpeningFixture::default()
- .with_policy_commitment(OpeningPolicyCommitment {
- role_staking_policy: Some(hiring::StakingPolicy {
- amount: 10,
- amount_mode: hiring::StakingAmountLimitMode::AtLeast,
- crowded_out_unstaking_period_length: None,
- review_period_expired_unstaking_period_length: None,
- }),
- ..OpeningPolicyCommitment::default()
- })
- .with_opening_type(OpeningType::Leader)
- .with_origin(RawOrigin::Root);
- let opening_id = add_opening_fixture.call_and_assert(Ok(()));
- let apply_on_opening_fixture =
- ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id)
- .with_role_stake(Some(10));
- let application_id = apply_on_opening_fixture.call_and_assert(Ok(()));
- let begin_review_worker_applications_fixture =
- BeginReviewWorkerApplicationsFixture::default_for_opening_id(opening_id)
- .with_origin(RawOrigin::Root);
- begin_review_worker_applications_fixture.call_and_assert(Ok(()));
- set_mint_id(create_mint());
- let fill_opening_fixture =
- FillWorkerOpeningFixture::default_for_ids(opening_id, vec![application_id])
- .with_reward_policy(RewardPolicy {
- amount_per_payout: 1000,
- next_payment_at_block: 20,
- payout_interval: None,
- });
- fill_opening_fixture.call_and_assert(Err(Error::RequireRootOrigin));
- });
- }
- #[test]
- fn fill_opening_fails_with_invalid_origin() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- let add_opening_fixture = AddWorkerOpeningFixture::default();
- let opening_id = add_opening_fixture.call_and_assert(Ok(()));
- let fill_opening_fixture =
- FillWorkerOpeningFixture::default_for_ids(opening_id, Vec::new())
- .with_origin(RawOrigin::None);
- fill_opening_fixture.call_and_assert(Err(Error::RequireSignedOrigin));
- });
- }
- #[test]
- fn fill_opening_fails_with_not_a_lead() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- let add_opening_fixture = AddWorkerOpeningFixture::default();
- let opening_id = add_opening_fixture.call_and_assert(Ok(()));
- SetLeadFixture::set_lead_with_ids(2, 2, 2);
- let fill_opening_fixture =
- FillWorkerOpeningFixture::default_for_ids(opening_id, Vec::new());
- fill_opening_fixture.call_and_assert(Err(Error::IsNotLeadAccount));
- });
- }
- #[test]
- fn fill_opening_fails_with_invalid_opening() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- let invalid_opening_id = 6;
- let fill_opening_fixture =
- FillWorkerOpeningFixture::default_for_ids(invalid_opening_id, Vec::new());
- fill_opening_fixture.call_and_assert(Err(Error::OpeningDoesNotExist));
- });
- }
- #[test]
- fn fill_opening_fails_with_invalid_application_list() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- let add_opening_fixture = AddWorkerOpeningFixture::default();
- let opening_id = add_opening_fixture.call_and_assert(Ok(()));
- let apply_on_opening_fixture =
- ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
- let application_id = apply_on_opening_fixture.call_and_assert(Ok(()));
- let begin_review_worker_applications_fixture =
- BeginReviewWorkerApplicationsFixture::default_for_opening_id(opening_id);
- begin_review_worker_applications_fixture.call_and_assert(Ok(()));
- let invalid_application_id = 66;
- let fill_opening_fixture = FillWorkerOpeningFixture::default_for_ids(
- opening_id,
- vec![application_id, invalid_application_id],
- );
- fill_opening_fixture.call_and_assert(Err(Error::SuccessfulWorkerApplicationDoesNotExist));
- });
- }
- #[test]
- fn fill_opening_fails_with_invalid_application_with_hiring_error() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- let add_opening_fixture = AddWorkerOpeningFixture::default();
- let opening_id = add_opening_fixture.call_and_assert(Ok(()));
- let fill_opening_fixture =
- FillWorkerOpeningFixture::default_for_ids(opening_id, Vec::new());
- fill_opening_fixture
- .call_and_assert(Err(Error::FullWorkerOpeningOpeningNotInReviewPeriodStage));
- });
- }
- #[test]
- fn fill_opening_fails_with_invalid_reward_policy() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- let add_opening_fixture = AddWorkerOpeningFixture::default();
- let opening_id = add_opening_fixture.call_and_assert(Ok(()));
- let apply_on_opening_fixture =
- ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
- let application_id = apply_on_opening_fixture.call_and_assert(Ok(()));
- let begin_review_worker_applications_fixture =
- BeginReviewWorkerApplicationsFixture::default_for_opening_id(opening_id);
- begin_review_worker_applications_fixture.call_and_assert(Ok(()));
- let fill_opening_fixture =
- FillWorkerOpeningFixture::default_for_ids(opening_id, vec![application_id])
- .with_reward_policy(RewardPolicy {
- amount_per_payout: 10000,
- // Invalid next payment at block zero
- next_payment_at_block: 0,
- payout_interval: None,
- });
- fill_opening_fixture
- });
- }
- #[test]
- fn update_worker_role_account_succeeds() {
- build_test_externalities().execute_with(|| {
- let new_account_id = 10;
- let worker_id = fill_default_worker_position();
- let update_worker_account_fixture =
- UpdateWorkerRoleAccountFixture::default_with_ids(worker_id, new_account_id);
- update_worker_account_fixture.call_and_assert(Ok(()));
- EventFixture::assert_last_crate_event(RawEvent::WorkerRoleAccountUpdated(
- worker_id,
- new_account_id,
- ));
- });
- }
- #[test]
- fn update_worker_role_account_by_leader_succeeds() {
- build_test_externalities().execute_with(|| {
- let new_account_id = 10;
- let worker_id = HireLeadFixture::default().hire_lead();
- let old_lead = TestWorkingGroup::worker_by_id(worker_id);
- let update_worker_account_fixture =
- UpdateWorkerRoleAccountFixture::default_with_ids(worker_id, new_account_id);
- update_worker_account_fixture.call_and_assert(Ok(()));
- let new_lead = TestWorkingGroup::worker_by_id(worker_id);
- assert_eq!(
- new_lead,
- Worker {
- role_account_id: new_account_id,
- ..old_lead
- }
- );
- });
- }
- #[test]
- fn update_worker_role_account_fails_with_invalid_origin() {
- build_test_externalities().execute_with(|| {
- let worker_id = fill_default_worker_position();
- let update_worker_account_fixture =
- UpdateWorkerRoleAccountFixture::default_with_ids(worker_id, 1)
- .with_origin(RawOrigin::None);
- update_worker_account_fixture.call_and_assert(Err(Error::MembershipUnsignedOrigin));
- });
- }
- #[test]
- fn update_worker_reward_account_succeeds() {
- build_test_externalities().execute_with(|| {
- let worker_id = fill_default_worker_position();
- let new_role_account = 22;
- let update_worker_account_fixture =
- UpdateWorkerRewardAccountFixture::default_with_ids(worker_id, new_role_account);
- update_worker_account_fixture.call_and_assert(Ok(()));
- EventFixture::assert_last_crate_event(RawEvent::WorkerRewardAccountUpdated(
- worker_id,
- new_role_account,
- ));
- });
- }
- #[test]
- fn update_worker_reward_account_succeeds_for_leader() {
- build_test_externalities().execute_with(|| {
- let worker_id = HireLeadFixture::default()
- .with_reward_policy(RewardPolicy {
- amount_per_payout: 1000,
- next_payment_at_block: 20,
- payout_interval: None,
- })
- .hire_lead();
- let new_reward_account = 22;
- let update_worker_account_fixture =
- UpdateWorkerRewardAccountFixture::default_with_ids(worker_id, new_reward_account);
- update_worker_account_fixture.call_and_assert(Ok(()));
- });
- }
- #[test]
- fn update_worker_reward_account_fails_with_invalid_origin() {
- build_test_externalities().execute_with(|| {
- let update_worker_account_fixture =
- UpdateWorkerRewardAccountFixture::default_with_ids(1, 1).with_origin(RawOrigin::None);
- update_worker_account_fixture.call_and_assert(Err(Error::RequireSignedOrigin));
- });
- }
- #[test]
- fn update_worker_reward_account_fails_with_invalid_origin_signed_account() {
- build_test_externalities().execute_with(|| {
- let worker_id = fill_default_worker_position();
- let worker = get_worker_by_id(worker_id);
- let invalid_role_account = 23333;
- let update_worker_account_fixture =
- UpdateWorkerRewardAccountFixture::default_with_ids(worker_id, worker.role_account_id)
- .with_origin(RawOrigin::Signed(invalid_role_account));
- update_worker_account_fixture.call_and_assert(Err(Error::SignerIsNotWorkerRoleAccount));
- });
- }
- #[test]
- fn update_worker_reward_account_fails_with_invalid_worker_id() {
- build_test_externalities().execute_with(|| {
- let invalid_worker_id = 1;
- fill_default_worker_position();
- let new_reward_account = 2;
- let update_worker_account_fixture = UpdateWorkerRewardAccountFixture::default_with_ids(
- invalid_worker_id,
- new_reward_account,
- );
- update_worker_account_fixture.call_and_assert(Err(Error::WorkerDoesNotExist));
- });
- }
- #[test]
- fn update_worker_reward_account_fails_with_no_recurring_reward() {
- build_test_externalities().execute_with(|| {
- let worker_id = fill_worker_position_with_no_reward();
- let new_reward_account = 343;
- let update_worker_account_fixture =
- UpdateWorkerRewardAccountFixture::default_with_ids(worker_id, new_reward_account);
- update_worker_account_fixture.call_and_assert(Err(Error::WorkerHasNoReward));
- });
- }
- #[test]
- fn update_worker_reward_amount_succeeds() {
- build_test_externalities().execute_with(|| {
- let worker_id = fill_default_worker_position();
- let update_worker_amount_fixture =
- UpdateWorkerRewardAmountFixture::default_for_worker_id(worker_id);
- update_worker_amount_fixture.call_and_assert(Ok(()));
- EventFixture::assert_last_crate_event(RawEvent::WorkerRewardAmountUpdated(worker_id));
- });
- }
- #[test]
- fn update_worker_reward_amount_succeeds_for_leader() {
- build_test_externalities().execute_with(|| {
- let worker_id = HireLeadFixture::default()
- .with_reward_policy(RewardPolicy {
- amount_per_payout: 1000,
- next_payment_at_block: 20,
- payout_interval: None,
- })
- .hire_lead();
- let update_worker_amount_fixture =
- UpdateWorkerRewardAmountFixture::default_for_worker_id(worker_id)
- .with_origin(RawOrigin::Root);
- update_worker_amount_fixture.call_and_assert(Ok(()));
- });
- }
- #[test]
- fn update_worker_reward_amount_fails_with_invalid_origin() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- let worker_id = 22; // random worker id
- let update_worker_amount_fixture =
- UpdateWorkerRewardAmountFixture::default_for_worker_id(worker_id)
- .with_origin(RawOrigin::None);
- update_worker_amount_fixture.call_and_assert(Err(Error::RequireSignedOrigin));
- });
- }
- #[test]
- fn update_worker_reward_amount_fails_with_invalid_origin_for_leader() {
- build_test_externalities().execute_with(|| {
- let worker_id = HireLeadFixture::default().hire_lead();
- let update_worker_amount_fixture =
- UpdateWorkerRewardAmountFixture::default_for_worker_id(worker_id)
- .with_origin(RawOrigin::None);
- update_worker_amount_fixture.call_and_assert(Err(Error::RequireRootOrigin));
- });
- }
- #[test]
- fn update_worker_reward_amount_fails_with_invalid_origin_signed_account() {
- build_test_externalities().execute_with(|| {
- let worker_id = fill_default_worker_position();
- let update_worker_amount_fixture =
- UpdateWorkerRewardAmountFixture::default_for_worker_id(worker_id)
- .with_origin(RawOrigin::Signed(2));
- update_worker_amount_fixture.call_and_assert(Err(Error::IsNotLeadAccount));
- });
- }
- #[test]
- fn update_worker_reward_amount_fails_with_invalid_worker_id() {
- build_test_externalities().execute_with(|| {
- let invalid_worker_id = 12;
- fill_default_worker_position();
- let update_worker_amount_fixture =
- UpdateWorkerRewardAmountFixture::default_for_worker_id(invalid_worker_id);
- update_worker_amount_fixture.call_and_assert(Err(Error::WorkerDoesNotExist));
- });
- }
- #[test]
- fn update_worker_reward_amount_fails_with_no_recurring_reward() {
- build_test_externalities().execute_with(|| {
- let worker_id = fill_worker_position_with_no_reward();
- let update_worker_amount_fixture =
- UpdateWorkerRewardAmountFixture::default_for_worker_id(worker_id);
- update_worker_amount_fixture.call_and_assert(Err(Error::WorkerHasNoReward));
- });
- }
- fn fill_default_worker_position() -> u64 {
- fill_worker_position(
- Some(RewardPolicy {
- amount_per_payout: 1000,
- next_payment_at_block: 20,
- payout_interval: None,
- }),
- None,
- true,
- OpeningType::Worker,
- None,
- )
- }
- fn fill_worker_position_with_no_reward() -> u64 {
- fill_worker_position(None, None, true, OpeningType::Worker, None)
- }
- fn fill_worker_position_with_stake(stake: u64) -> u64 {
- fill_worker_position(
- Some(RewardPolicy {
- amount_per_payout: 1000,
- next_payment_at_block: 20,
- payout_interval: None,
- }),
- Some(stake),
- true,
- OpeningType::Worker,
- None,
- )
- }
- fn fill_worker_position(
- reward_policy: Option<RewardPolicy<u64, u64>>,
- role_stake: Option<u64>,
- setup_environment: bool,
- opening_type: OpeningType,
- worker_handle: Option<Vec<u8>>,
- ) -> u64 {
- let mut hiring_workflow = HiringWorkflow::default()
- .with_role_stake(role_stake)
- .with_setup_environment(setup_environment)
- .with_opening_type(opening_type)
- .with_reward_policy(reward_policy);
- hiring_workflow = if let Some(worker_handle) = worker_handle {
- hiring_workflow.add_application(worker_handle)
- } else {
- hiring_workflow.add_default_application()
- };
- hiring_workflow.execute().unwrap()
- }
- #[test]
- fn leave_worker_role_succeeds() {
- build_test_externalities().execute_with(|| {
- let worker_id = fill_default_worker_position();
- let leave_worker_role_fixture = LeaveWorkerRoleFixture::default_for_worker_id(worker_id);
- leave_worker_role_fixture.call_and_assert(Ok(()));
- EventFixture::assert_last_crate_event(RawEvent::WorkerExited(
- worker_id,
- b"rationale_text".to_vec(),
- ));
- });
- }
- #[test]
- fn leave_worker_role_by_leader_succeeds() {
- build_test_externalities().execute_with(|| {
- // Ensure that lead is default
- assert_eq!(TestWorkingGroup::current_lead(), None);
- let worker_id = HireLeadFixture::default().hire_lead();
- assert!(TestWorkingGroup::current_lead().is_some());
- let leave_worker_role_fixture = LeaveWorkerRoleFixture::default_for_worker_id(worker_id);
- leave_worker_role_fixture.call_and_assert(Ok(()));
- assert_eq!(TestWorkingGroup::current_lead(), None);
- });
- }
- #[test]
- fn leave_worker_role_fails_with_invalid_origin() {
- build_test_externalities().execute_with(|| {
- let leave_worker_role_fixture =
- LeaveWorkerRoleFixture::default_for_worker_id(1).with_origin(RawOrigin::None);
- leave_worker_role_fixture.call_and_assert(Err(Error::RequireSignedOrigin));
- });
- }
- #[test]
- fn leave_worker_role_fails_with_invalid_origin_signed_account() {
- build_test_externalities().execute_with(|| {
- let worker_id = fill_default_worker_position();
- let leave_worker_role_fixture = LeaveWorkerRoleFixture::default_for_worker_id(worker_id)
- .with_origin(RawOrigin::Signed(2));
- leave_worker_role_fixture.call_and_assert(Err(Error::SignerIsNotWorkerRoleAccount));
- });
- }
- #[test]
- fn leave_worker_role_fails_with_invalid_worker_id() {
- build_test_externalities().execute_with(|| {
- let invalid_worker_id = 1;
- fill_default_worker_position();
- let leave_worker_role_fixture =
- LeaveWorkerRoleFixture::default_for_worker_id(invalid_worker_id);
- leave_worker_role_fixture.call_and_assert(Err(Error::WorkerDoesNotExist));
- });
- }
- #[test]
- fn leave_worker_role_fails_with_invalid_recurring_reward_relationships() {
- build_test_externalities().execute_with(|| {
- let worker_id = fill_default_worker_position();
- let mut worker = TestWorkingGroup::worker_by_id(worker_id);
- worker.reward_relationship = Some(2);
- <crate::WorkerById<Test, TestWorkingGroupInstance>>::insert(worker_id, worker);
- let leave_worker_role_fixture = LeaveWorkerRoleFixture::default_for_worker_id(worker_id);
- leave_worker_role_fixture.call_and_assert(Err(Error::RelationshipMustExist));
- });
- }
- #[test]
- fn leave_worker_role_succeeds_with_stakes() {
- build_test_externalities().execute_with(|| {
- let worker_id = fill_worker_position_with_stake(100);
- let leave_worker_role_fixture = LeaveWorkerRoleFixture::default_for_worker_id(worker_id);
- leave_worker_role_fixture.call_and_assert(Ok(()));
- EventFixture::assert_last_crate_event(RawEvent::WorkerExited(
- worker_id,
- b"rationale_text".to_vec(),
- ));
- });
- }
- #[test]
- fn terminate_worker_role_succeeds_with_stakes() {
- build_test_externalities().execute_with(|| {
- let total_balance = 10000;
- let stake_balance = 100;
- let worker_account_id = 2;
- let worker_member_id = 2;
- increase_total_balance_issuance_using_account_id(worker_account_id, total_balance);
- HireLeadFixture::default().hire_lead();
- let worker_id = HiringWorkflow::default()
- .disable_setup_environment()
- .with_role_stake(Some(stake_balance))
- .add_application_with_origin(
- b"worker_handle".to_vec(),
- RawOrigin::Signed(worker_account_id),
- worker_member_id,
- )
- .execute()
- .unwrap();
- // Balance was staked.
- assert_eq!(
- get_balance(worker_account_id),
- total_balance - stake_balance
- );
- let stake_id = 0;
- let old_stake = <stake::Module<Test>>::stakes(stake_id);
- assert_eq!(get_stake_balance(old_stake), stake_balance);
- let terminate_worker_role_fixture =
- TerminateWorkerRoleFixture::default_for_worker_id(worker_id);
- terminate_worker_role_fixture.call_and_assert(Ok(()));
- EventFixture::assert_last_crate_event(RawEvent::TerminatedWorker(
- worker_id,
- b"rationale_text".to_vec(),
- ));
- // Balance was restored.
- assert_eq!(get_balance(worker_account_id), total_balance);
- let new_stake = <stake::Module<Test>>::stakes(stake_id);
- assert!(matches!(
- new_stake.staking_status,
- stake::StakingStatus::NotStaked
- ));
- });
- }
- #[test]
- fn terminate_worker_role_succeeds_with_slashing() {
- build_test_externalities().execute_with(|| {
- let total_balance = 10000;
- let stake_balance = 100;
- let worker_account_id = 2;
- let worker_member_id = 2;
- increase_total_balance_issuance_using_account_id(worker_account_id, total_balance);
- assert_eq!(get_balance(worker_account_id), total_balance);
- HireLeadFixture::default().hire_lead();
- let worker_id = HiringWorkflow::default()
- .disable_setup_environment()
- .with_role_stake(Some(stake_balance))
- .add_application_with_origin(
- b"worker_handle".to_vec(),
- RawOrigin::Signed(worker_account_id),
- worker_member_id,
- )
- .execute()
- .unwrap();
- // Balance was staked.
- assert_eq!(
- get_balance(worker_account_id),
- total_balance - stake_balance
- );
- let stake_id = 0;
- let old_stake = <stake::Module<Test>>::stakes(stake_id);
- assert_eq!(get_stake_balance(old_stake), stake_balance);
- // Terminate with slashing.
- let terminate_worker_role_fixture =
- TerminateWorkerRoleFixture::default_for_worker_id(worker_id).with_slashing();
- terminate_worker_role_fixture.call_and_assert(Ok(()));
- // Balance was slashed.
- assert_eq!(
- get_balance(worker_account_id),
- total_balance - stake_balance
- );
- let new_stake = <stake::Module<Test>>::stakes(stake_id);
- assert!(matches!(
- new_stake.staking_status,
- stake::StakingStatus::NotStaked
- ));
- });
- }
- #[test]
- fn terminate_worker_role_succeeds() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- let worker_id = HiringWorkflow::default()
- .disable_setup_environment()
- .add_application_with_origin(b"worker_handle".to_vec(), RawOrigin::Signed(2), 2)
- .execute()
- .unwrap();
- let terminate_worker_role_fixture =
- TerminateWorkerRoleFixture::default_for_worker_id(worker_id);
- terminate_worker_role_fixture.call_and_assert(Ok(()));
- EventFixture::assert_last_crate_event(RawEvent::TerminatedWorker(
- worker_id,
- b"rationale_text".to_vec(),
- ));
- });
- }
- #[test]
- fn fire_leader_succeeds() {
- build_test_externalities().execute_with(|| {
- let worker_id = HireLeadFixture::default().hire_lead();
- let terminate_worker_role_fixture =
- TerminateWorkerRoleFixture::default_for_worker_id(worker_id)
- .with_origin(RawOrigin::Root);
- terminate_worker_role_fixture.call_and_assert(Ok(()));
- EventFixture::assert_last_crate_event(RawEvent::TerminatedLeader(
- worker_id,
- b"rationale_text".to_vec(),
- ));
- assert_eq!(TestWorkingGroup::current_lead(), None);
- });
- }
- #[test]
- fn terminate_worker_role_fails_with_invalid_text() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- let worker_id = HiringWorkflow::default()
- .disable_setup_environment()
- .add_application_with_origin(b"worker_handle".to_vec(), RawOrigin::Signed(2), 2)
- .execute()
- .unwrap();
- let terminate_worker_role_fixture =
- TerminateWorkerRoleFixture::default_for_worker_id(worker_id).with_text(Vec::new());
- terminate_worker_role_fixture
- .call_and_assert(Err(Error::Other("WorkerExitRationaleTextTooShort")));
- let terminate_worker_role_fixture =
- TerminateWorkerRoleFixture::default_for_worker_id(worker_id)
- .with_text(b"MSG_WORKER_EXIT_RATIONALE_TEXT_TOO_LONG".to_vec());
- terminate_worker_role_fixture
- .call_and_assert(Err(Error::Other("WorkerExitRationaleTextTooLong")));
- });
- }
- #[test]
- fn terminate_worker_role_fails_with_unset_lead() {
- build_test_externalities().execute_with(|| {
- let worker_id = fill_default_worker_position();
- SetLeadFixture::unset_lead();
- let terminate_worker_role_fixture =
- TerminateWorkerRoleFixture::default_for_worker_id(worker_id);
- terminate_worker_role_fixture.call_and_assert(Err(Error::CurrentLeadNotSet));
- });
- }
- #[test]
- fn terminate_worker_role_fails_with_invalid_origin() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- let worker_id = HiringWorkflow::default()
- .disable_setup_environment()
- .add_application_with_origin(b"worker_handle".to_vec(), RawOrigin::Signed(2), 2)
- .execute()
- .unwrap();
- let terminate_worker_role_fixture =
- TerminateWorkerRoleFixture::default_for_worker_id(worker_id)
- .with_origin(RawOrigin::None);
- terminate_worker_role_fixture.call_and_assert(Err(Error::RequireSignedOrigin));
- });
- }
- #[test]
- fn fire_leader_fails_with_invalid_origin() {
- build_test_externalities().execute_with(|| {
- let worker_id = HireLeadFixture::default().hire_lead();
- let terminate_worker_role_fixture =
- TerminateWorkerRoleFixture::default_for_worker_id(worker_id)
- .with_origin(RawOrigin::None);
- terminate_worker_role_fixture.call_and_assert(Err(Error::RequireRootOrigin));
- });
- }
- #[test]
- fn increase_worker_stake_succeeds() {
- build_test_externalities().execute_with(|| {
- let worker_id = fill_worker_position_with_stake(100);
- let increase_stake_fixture = IncreaseWorkerStakeFixture::default_for_worker_id(worker_id);
- increase_stake_fixture.call_and_assert(Ok(()));
- EventFixture::assert_last_crate_event(RawEvent::StakeIncreased(worker_id));
- });
- }
- #[test]
- fn increase_worker_stake_succeeds_for_leader() {
- build_test_externalities().execute_with(|| {
- let worker_id = HireLeadFixture::default().with_stake(100).hire_lead();
- let increase_stake_fixture = IncreaseWorkerStakeFixture::default_for_worker_id(worker_id);
- increase_stake_fixture.call_and_assert(Ok(()));
- });
- }
- #[test]
- fn increase_worker_stake_fails_with_invalid_origin() {
- build_test_externalities().execute_with(|| {
- let worker_id = 0;
- let increase_stake_fixture = IncreaseWorkerStakeFixture::default_for_worker_id(worker_id)
- .with_origin(RawOrigin::None);
- increase_stake_fixture.call_and_assert(Err(Error::RequireSignedOrigin));
- });
- }
- #[test]
- fn increase_worker_stake_fails_with_zero_balance() {
- build_test_externalities().execute_with(|| {
- let worker_id = fill_worker_position_with_stake(100);
- let increase_stake_fixture =
- IncreaseWorkerStakeFixture::default_for_worker_id(worker_id).with_balance(0);
- increase_stake_fixture.call_and_assert(Err(Error::StakeBalanceCannotBeZero));
- });
- }
- #[test]
- fn increase_worker_stake_fails_with_invalid_worker_id() {
- build_test_externalities().execute_with(|| {
- let invalid_worker_id = 11;
- let increase_stake_fixture =
- IncreaseWorkerStakeFixture::default_for_worker_id(invalid_worker_id);
- increase_stake_fixture.call_and_assert(Err(Error::WorkerDoesNotExist));
- });
- }
- #[test]
- fn increase_worker_stake_fails_with_invalid_balance() {
- build_test_externalities().execute_with(|| {
- let worker_id = fill_worker_position_with_stake(100);
- let invalid_balance = 100000000;
- let increase_stake_fixture = IncreaseWorkerStakeFixture::default_for_worker_id(worker_id)
- .with_balance(invalid_balance);
- increase_stake_fixture
- .call_and_assert(Err(Error::StakingErrorInsufficientBalanceInSourceAccount));
- });
- }
- #[test]
- fn increase_worker_stake_fails_with_no_stake_profile() {
- build_test_externalities().execute_with(|| {
- let worker_id = fill_default_worker_position();
- let increase_stake_fixture = IncreaseWorkerStakeFixture::default_for_worker_id(worker_id);
- increase_stake_fixture.call_and_assert(Err(Error::NoWorkerStakeProfile));
- });
- }
- #[test]
- fn decrease_worker_stake_succeeds() {
- build_test_externalities().execute_with(|| {
- let worker_id = fill_worker_position_with_stake(100);
- let decrease_stake_fixture = DecreaseWorkerStakeFixture::default_for_worker_id(worker_id);
- decrease_stake_fixture.call_and_assert(Ok(()));
- EventFixture::assert_last_crate_event(RawEvent::StakeDecreased(worker_id));
- });
- }
- #[test]
- fn decrease_worker_stake_succeeds_for_leader() {
- build_test_externalities().execute_with(|| {
- let worker_id = HireLeadFixture::default().with_stake(100).hire_lead();
- let decrease_stake_fixture = DecreaseWorkerStakeFixture::default_for_worker_id(worker_id)
- .with_origin(RawOrigin::Root);
- decrease_stake_fixture.call_and_assert(Ok(()));
- });
- }
- #[test]
- fn decrease_worker_stake_fails_with_invalid_origin() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- let worker_id = 22; // random worker id
- let decrease_stake_fixture = DecreaseWorkerStakeFixture::default_for_worker_id(worker_id)
- .with_origin(RawOrigin::None);
- decrease_stake_fixture.call_and_assert(Err(Error::RequireSignedOrigin));
- });
- }
- #[test]
- fn decrease_worker_stake_fails_with_invalid_origin_for_leader() {
- build_test_externalities().execute_with(|| {
- let worker_id = HireLeadFixture::default().hire_lead();
- let decrease_stake_fixture = DecreaseWorkerStakeFixture::default_for_worker_id(worker_id)
- .with_origin(RawOrigin::None);
- decrease_stake_fixture.call_and_assert(Err(Error::RequireRootOrigin));
- });
- }
- #[test]
- fn decrease_worker_stake_fails_with_zero_balance() {
- build_test_externalities().execute_with(|| {
- let worker_id = fill_worker_position_with_stake(100);
- let decrease_stake_fixture =
- DecreaseWorkerStakeFixture::default_for_worker_id(worker_id).with_balance(0);
- decrease_stake_fixture.call_and_assert(Err(Error::StakeBalanceCannotBeZero));
- });
- }
- #[test]
- fn decrease_worker_stake_fails_with_invalid_worker_id() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- let invalid_worker_id = 11;
- let decrease_stake_fixture =
- DecreaseWorkerStakeFixture::default_for_worker_id(invalid_worker_id);
- decrease_stake_fixture.call_and_assert(Err(Error::WorkerDoesNotExist));
- });
- }
- #[test]
- fn decrease_worker_stake_fails_with_invalid_balance() {
- build_test_externalities().execute_with(|| {
- let worker_id = fill_worker_position_with_stake(100);
- let invalid_balance = 100000000;
- let decrease_stake_fixture = DecreaseWorkerStakeFixture::default_for_worker_id(worker_id)
- .with_balance(invalid_balance);
- decrease_stake_fixture.call_and_assert(Err(Error::StakingErrorInsufficientStake));
- });
- }
- #[test]
- fn decrease_worker_stake_fails_with_no_stake_profile() {
- build_test_externalities().execute_with(|| {
- let worker_id = fill_default_worker_position();
- let decrease_stake_fixture = DecreaseWorkerStakeFixture::default_for_worker_id(worker_id);
- decrease_stake_fixture.call_and_assert(Err(Error::NoWorkerStakeProfile));
- });
- }
- #[test]
- fn decrease_worker_stake_fails_with_not_set_lead() {
- build_test_externalities().execute_with(|| {
- let invalid_worker_id = 11;
- let decrease_stake_fixture =
- DecreaseWorkerStakeFixture::default_for_worker_id(invalid_worker_id);
- decrease_stake_fixture.call_and_assert(Err(Error::CurrentLeadNotSet));
- });
- }
- #[test]
- fn slash_worker_stake_succeeds() {
- build_test_externalities().execute_with(|| {
- let worker_id = fill_worker_position_with_stake(100);
- let slash_stake_fixture = SlashWorkerStakeFixture::default_for_worker_id(worker_id);
- slash_stake_fixture.call_and_assert(Ok(()));
- EventFixture::assert_last_crate_event(RawEvent::StakeSlashed(worker_id));
- });
- }
- #[test]
- fn slash_leader_stake_succeeds() {
- build_test_externalities().execute_with(|| {
- let leader_worker_id = HiringWorkflow::default()
- .with_role_stake(Some(100))
- .with_opening_type(OpeningType::Leader)
- .add_default_application()
- .execute()
- .unwrap();
- let slash_stake_fixture = SlashWorkerStakeFixture::default_for_worker_id(leader_worker_id)
- .with_origin(RawOrigin::Root);
- slash_stake_fixture.call_and_assert(Ok(()));
- EventFixture::assert_last_crate_event(RawEvent::StakeSlashed(leader_worker_id));
- });
- }
- #[test]
- fn slash_worker_stake_fails_with_invalid_origin() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- let invalid_worker_id = 22;
- let slash_stake_fixture = SlashWorkerStakeFixture::default_for_worker_id(invalid_worker_id)
- .with_origin(RawOrigin::None);
- slash_stake_fixture.call_and_assert(Err(Error::RequireSignedOrigin));
- });
- }
- #[test]
- fn slash_leader_stake_fails_with_invalid_origin() {
- build_test_externalities().execute_with(|| {
- let worker_id = HireLeadFixture::default().hire_lead();
- let slash_stake_fixture =
- SlashWorkerStakeFixture::default_for_worker_id(worker_id).with_origin(RawOrigin::None);
- slash_stake_fixture.call_and_assert(Err(Error::RequireRootOrigin));
- });
- }
- #[test]
- fn slash_worker_stake_fails_with_zero_balance() {
- build_test_externalities().execute_with(|| {
- let worker_id = fill_worker_position_with_stake(100);
- let slash_stake_fixture =
- SlashWorkerStakeFixture::default_for_worker_id(worker_id).with_balance(0);
- slash_stake_fixture.call_and_assert(Err(Error::StakeBalanceCannotBeZero));
- });
- }
- #[test]
- fn slash_worker_stake_fails_with_invalid_worker_id() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- let invalid_worker_id = 11;
- let slash_stake_fixture = SlashWorkerStakeFixture::default_for_worker_id(invalid_worker_id);
- slash_stake_fixture.call_and_assert(Err(Error::WorkerDoesNotExist));
- });
- }
- #[test]
- fn slash_worker_stake_fails_with_no_stake_profile() {
- build_test_externalities().execute_with(|| {
- let worker_id = fill_default_worker_position();
- let slash_stake_fixture = SlashWorkerStakeFixture::default_for_worker_id(worker_id);
- slash_stake_fixture.call_and_assert(Err(Error::NoWorkerStakeProfile));
- });
- }
- #[test]
- fn slash_worker_stake_fails_with_not_set_lead() {
- build_test_externalities().execute_with(|| {
- let invalid_worker_id = 11;
- let slash_stake_fixture = SlashWorkerStakeFixture::default_for_worker_id(invalid_worker_id);
- slash_stake_fixture.call_and_assert(Err(Error::CurrentLeadNotSet));
- });
- }
- #[test]
- fn get_all_worker_ids_succeeds() {
- build_test_externalities().execute_with(|| {
- let worker_ids = TestWorkingGroup::get_regular_worker_ids();
- assert_eq!(worker_ids, Vec::new());
- let leader_worker_id = HireLeadFixture::default().hire_lead();
- let worker_id1 = fill_worker_position(None, None, false, OpeningType::Worker, None);
- let worker_id2 = fill_worker_position(None, None, false, OpeningType::Worker, None);
- let mut expected_ids = vec![worker_id1, worker_id2];
- expected_ids.sort();
- let mut worker_ids = TestWorkingGroup::get_regular_worker_ids();
- worker_ids.sort();
- assert_eq!(worker_ids, expected_ids);
- assert!(!expected_ids.contains(&leader_worker_id));
- <crate::WorkerById<Test, TestWorkingGroupInstance>>::remove(worker_id1);
- let worker_ids = TestWorkingGroup::get_regular_worker_ids();
- assert_eq!(worker_ids, vec![worker_id2]);
- });
- }
- #[test]
- fn set_working_group_mint_capacity_succeeds() {
- build_test_externalities().execute_with(|| {
- let mint_id = <minting::Module<Test>>::add_mint(0, None).unwrap();
- <crate::Mint<Test, TestWorkingGroupInstance>>::put(mint_id);
- let capacity = 15000;
- let result = TestWorkingGroup::set_mint_capacity(RawOrigin::Root.into(), capacity);
- assert_eq!(result, Ok(()));
- let mint = <minting::Module<Test>>::mints(mint_id);
- assert_eq!(mint.capacity(), capacity);
- });
- }
- #[test]
- fn set_working_group_mint_capacity_fails_with_mint_not_found() {
- build_test_externalities().execute_with(|| {
- let capacity = 15000;
- <crate::Mint<Test, TestWorkingGroupInstance>>::put(5); // random mint id
- let result = TestWorkingGroup::set_mint_capacity(RawOrigin::Root.into(), capacity);
- assert_eq!(result, Err(Error::CannotFindMint));
- });
- }
- #[test]
- fn set_working_group_mint_capacity_fails_with_invalid_origin() {
- build_test_externalities().execute_with(|| {
- let capacity = 15000;
- let result = TestWorkingGroup::set_mint_capacity(RawOrigin::None.into(), capacity);
- assert_eq!(result, Err(Error::RequireRootOrigin));
- });
- }
- #[test]
- fn ensure_setting_genesis_working_group_mint_succeeds() {
- build_test_externalities().execute_with(|| {
- let mint_id = TestWorkingGroup::mint();
- assert!(minting::Mints::<Test>::exists(mint_id));
- let mint = <minting::Module<Test>>::mints(mint_id);
- assert_eq!(mint.capacity(), WORKING_GROUP_MINT_CAPACITY);
- });
- }
- #[test]
- fn ensure_setting_genesis_constraints_succeeds() {
- build_test_externalities().execute_with(|| {
- let default_constraint = common::constraints::InputValidationLengthConstraint::new(
- WORKING_GROUP_CONSTRAINT_MIN,
- WORKING_GROUP_CONSTRAINT_DIFF,
- );
- let opening_text_constraint = TestWorkingGroup::opening_human_readable_text();
- let worker_text_constraint = TestWorkingGroup::application_human_readable_text();
- let worker_exit_text_constraint = TestWorkingGroup::worker_exit_rationale_text();
- assert_eq!(opening_text_constraint, default_constraint);
- assert_eq!(worker_text_constraint, default_constraint);
- assert_eq!(worker_exit_text_constraint, default_constraint);
- });
- }
- #[test]
- fn active_worker_counter_works_successfully() {
- build_test_externalities().execute_with(|| {
- assert_eq!(TestWorkingGroup::active_worker_count(), 0);
- let leader_id = HireLeadFixture::default().hire_lead();
- assert_eq!(TestWorkingGroup::active_worker_count(), 1);
- let worker_id1 = fill_worker_position(
- None,
- None,
- false,
- OpeningType::Worker,
- Some(b"worker1".to_vec()),
- );
- assert_eq!(TestWorkingGroup::active_worker_count(), 2);
- let worker_id2 = fill_worker_position(
- None,
- None,
- false,
- OpeningType::Worker,
- Some(b"worker1".to_vec()),
- );
- assert_eq!(TestWorkingGroup::active_worker_count(), 3);
- TerminateWorkerRoleFixture::default_for_worker_id(worker_id1).call_and_assert(Ok(()));
- assert_eq!(TestWorkingGroup::active_worker_count(), 2);
- TerminateWorkerRoleFixture::default_for_worker_id(worker_id2).call_and_assert(Ok(()));
- assert_eq!(TestWorkingGroup::active_worker_count(), 1);
- TerminateWorkerRoleFixture::default_for_worker_id(leader_id)
- .with_origin(RawOrigin::Root)
- .call_and_assert(Ok(()));
- assert_eq!(TestWorkingGroup::active_worker_count(), 0);
- });
- }
- #[test]
- fn adding_too_much_workers_fails_with_single_application_out_of_limit() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- fill_worker_position(None, None, false, OpeningType::Worker, None);
- fill_worker_position(None, None, false, OpeningType::Worker, None);
- let hiring_workflow = HiringWorkflow::default()
- .disable_setup_environment()
- .add_default_application()
- .expect(Err(Error::MaxActiveWorkerNumberExceeded));
- hiring_workflow.execute()
- });
- }
- #[test]
- fn fill_opening_cannot_hire_more_workers_using_several_applicationst_han_allows_worker_limit() {
- build_test_externalities().execute_with(|| {
- HireLeadFixture::default().hire_lead();
- fill_worker_position(None, None, false, OpeningType::Worker, None);
- let hiring_workflow = HiringWorkflow::default()
- .disable_setup_environment()
- .add_application_with_origin(b"Some1".to_vec(), RawOrigin::Signed(2), 2)
- .add_application_with_origin(b"Some2".to_vec(), RawOrigin::Signed(3), 3)
- .expect(Err(Error::MaxActiveWorkerNumberExceeded));
- hiring_workflow.execute()
- });
- }
|