123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236 |
- mod mock;
- use crate::constraints::InputValidationLengthConstraint;
- use crate::types::{
- Lead, OpeningPolicyCommitment, RewardPolicy, Worker, WorkerApplication, WorkerOpening,
- WorkerRoleStage,
- };
- use crate::{Instance1, RawEvent};
- use mock::{build_test_externalities, Balances, Bureaucracy1, Membership, System, TestEvent};
- use srml_support::StorageValue;
- use std::collections::{BTreeMap, BTreeSet};
- use system::{EventRecord, Phase, RawOrigin};
- struct FillWorkerOpeningFixture {
- origin: RawOrigin<u64>,
- opening_id: u64,
- successful_worker_application_ids: BTreeSet<u64>,
- role_account: u64,
- reward_policy: Option<RewardPolicy<u64, u64>>,
- }
- impl FillWorkerOpeningFixture {
- pub fn default_for_ids(opening_id: u64, application_ids: Vec<u64>) -> Self {
- let application_ids: BTreeSet<u64> = application_ids.iter().map(|x| *x).collect();
- FillWorkerOpeningFixture {
- origin: RawOrigin::Signed(1),
- opening_id,
- successful_worker_application_ids: application_ids,
- role_account: 1,
- reward_policy: None,
- }
- }
- fn with_origin(self, origin: RawOrigin<u64>) -> Self {
- FillWorkerOpeningFixture { origin, ..self }
- }
- pub fn call_and_assert(&self, expected_result: Result<(), &str>) {
- let saved_worker_next_id = Bureaucracy1::next_worker_id();
- let actual_result = Bureaucracy1::fill_worker_opening(
- self.origin.clone().into(),
- self.opening_id,
- self.successful_worker_application_ids.clone(),
- self.reward_policy.clone(),
- );
- assert_eq!(actual_result.clone(), expected_result);
- if actual_result.is_ok() {
- assert_eq!(Bureaucracy1::next_worker_id(), saved_worker_next_id + 1);
- let worker_id = saved_worker_next_id;
- let actual_worker = Bureaucracy1::worker_by_id(worker_id);
- let expected_worker = Worker {
- role_account: self.role_account,
- reward_relationship: None,
- role_stake_profile: None,
- stage: WorkerRoleStage::Active,
- };
- assert_eq!(actual_worker, expected_worker);
- }
- }
- }
- struct BeginReviewWorkerApplicationsFixture {
- origin: RawOrigin<u64>,
- opening_id: u64,
- }
- impl BeginReviewWorkerApplicationsFixture {
- pub fn default_for_opening_id(opening_id: u64) -> Self {
- BeginReviewWorkerApplicationsFixture {
- origin: RawOrigin::Signed(1),
- opening_id,
- }
- }
- fn with_origin(self, origin: RawOrigin<u64>) -> Self {
- BeginReviewWorkerApplicationsFixture { origin, ..self }
- }
- pub fn call_and_assert(&self, expected_result: Result<(), &str>) {
- let actual_result = Bureaucracy1::begin_worker_applicant_review(
- self.origin.clone().into(),
- self.opening_id,
- );
- assert_eq!(actual_result, expected_result);
- }
- }
- struct TerminateApplicationFixture {
- origin: RawOrigin<u64>,
- worker_application_id: u64,
- }
- impl TerminateApplicationFixture {
- fn with_signer(self, account_id: u64) -> Self {
- TerminateApplicationFixture {
- origin: RawOrigin::Signed(account_id),
- ..self
- }
- }
- fn with_origin(self, origin: RawOrigin<u64>) -> Self {
- TerminateApplicationFixture { origin, ..self }
- }
- pub fn default_for_application_id(application_id: u64) -> Self {
- TerminateApplicationFixture {
- origin: RawOrigin::Signed(1),
- worker_application_id: application_id,
- }
- }
- pub fn call_and_assert(&self, expected_result: Result<(), &str>) {
- let actual_result = Bureaucracy1::terminate_worker_application(
- self.origin.clone().into(),
- self.worker_application_id,
- );
- assert_eq!(actual_result.clone(), expected_result);
- }
- }
- struct WithdrawApplicationFixture {
- origin: RawOrigin<u64>,
- worker_application_id: u64,
- }
- impl WithdrawApplicationFixture {
- fn with_signer(self, account_id: u64) -> Self {
- WithdrawApplicationFixture {
- origin: RawOrigin::Signed(account_id),
- ..self
- }
- }
- fn with_origin(self, origin: RawOrigin<u64>) -> Self {
- WithdrawApplicationFixture { origin, ..self }
- }
- pub fn default_for_application_id(application_id: u64) -> Self {
- WithdrawApplicationFixture {
- origin: RawOrigin::Signed(1),
- worker_application_id: application_id,
- }
- }
- pub fn call_and_assert(&self, expected_result: Result<(), &str>) {
- let actual_result = Bureaucracy1::withdraw_worker_application(
- self.origin.clone().into(),
- self.worker_application_id,
- );
- assert_eq!(actual_result.clone(), expected_result);
- }
- }
- pub(crate) fn increase_total_balance_issuance_using_account_id(account_id: u64, balance: u64) {
- let _ =
- <Balances as srml_support::traits::Currency<u64>>::deposit_creating(&account_id, balance);
- }
- fn setup_members(count: u8) {
- let authority_account_id = 1;
- Membership::set_screening_authority(RawOrigin::Root.into(), authority_account_id).unwrap();
- for i in 0..count {
- let account_id: u64 = i as u64;
- let handle: [u8; 20] = [i; 20];
- Membership::add_screened_member(
- RawOrigin::Signed(authority_account_id).into(),
- account_id,
- membership::members::UserInfo {
- handle: Some(handle.to_vec()),
- avatar_uri: None,
- about: None,
- },
- )
- .unwrap();
- }
- }
- struct ApplyOnWorkerOpeningFixture {
- origin: RawOrigin<u64>,
- member_id: u64,
- worker_opening_id: u64,
- role_account: u64,
- opt_role_stake_balance: Option<u64>,
- opt_application_stake_balance: Option<u64>,
- human_readable_text: Vec<u8>,
- }
- impl ApplyOnWorkerOpeningFixture {
- fn with_text(self, text: Vec<u8>) -> Self {
- ApplyOnWorkerOpeningFixture {
- human_readable_text: text,
- ..self
- }
- }
- fn with_role_stake(self, stake: u64) -> Self {
- ApplyOnWorkerOpeningFixture {
- opt_role_stake_balance: Some(stake),
- ..self
- }
- }
- fn with_application_stake(self, stake: u64) -> Self {
- ApplyOnWorkerOpeningFixture {
- opt_application_stake_balance: Some(stake),
- ..self
- }
- }
- pub fn default_for_opening_id(opening_id: u64) -> Self {
- ApplyOnWorkerOpeningFixture {
- origin: RawOrigin::Signed(1),
- member_id: 1,
- worker_opening_id: opening_id,
- role_account: 1,
- opt_role_stake_balance: None,
- opt_application_stake_balance: None,
- human_readable_text: Vec::new(),
- }
- }
- pub fn call_and_assert(&self, expected_result: Result<(), &str>) {
- let saved_application_next_id = Bureaucracy1::next_worker_application_id();
- let actual_result = Bureaucracy1::apply_on_worker_opening(
- self.origin.clone().into(),
- self.member_id,
- self.worker_opening_id,
- self.role_account,
- self.opt_role_stake_balance,
- self.opt_application_stake_balance,
- self.human_readable_text.clone(),
- );
- assert_eq!(actual_result.clone(), expected_result);
- if actual_result.is_ok() {
- assert_eq!(
- Bureaucracy1::next_worker_application_id(),
- saved_application_next_id + 1
- );
- let application_id = saved_application_next_id;
- let actual_application = Bureaucracy1::worker_application_by_id(application_id);
- let expected_application = WorkerApplication {
- role_account: self.role_account,
- worker_opening_id: self.worker_opening_id,
- member_id: self.member_id,
- application_id,
- };
- assert_eq!(actual_application, expected_application);
- let current_opening = Bureaucracy1::worker_opening_by_id(self.worker_opening_id);
- assert!(current_opening
- .worker_applications
- .contains(&application_id));
- }
- }
- }
- struct AcceptWorkerApplicationsFixture {
- origin: RawOrigin<u64>,
- opening_id: u64,
- }
- impl AcceptWorkerApplicationsFixture {
- pub fn default_for_opening_id(opening_id: u64) -> Self {
- AcceptWorkerApplicationsFixture {
- origin: RawOrigin::Signed(1),
- opening_id,
- }
- }
- pub fn call_and_assert(&self, expected_result: Result<(), &str>) {
- let actual_result =
- Bureaucracy1::accept_worker_applications(self.origin.clone().into(), self.opening_id);
- assert_eq!(actual_result, expected_result);
- }
- }
- struct SetLeadFixture;
- impl SetLeadFixture {
- fn set_lead(lead_account_id: u64) {
- assert_eq!(
- Bureaucracy1::set_lead(RawOrigin::Root.into(), 1, lead_account_id),
- Ok(())
- );
- }
- }
- struct AddWorkerOpeningFixture {
- origin: RawOrigin<u64>,
- activate_at: hiring::ActivateOpeningAt<u64>,
- commitment: OpeningPolicyCommitment<u64, u64>,
- human_readable_text: Vec<u8>,
- }
- impl Default for AddWorkerOpeningFixture {
- fn default() -> Self {
- AddWorkerOpeningFixture {
- origin: RawOrigin::Signed(1),
- activate_at: hiring::ActivateOpeningAt::CurrentBlock,
- commitment: <OpeningPolicyCommitment<u64, u64>>::default(),
- human_readable_text: Vec::new(),
- }
- }
- }
- impl AddWorkerOpeningFixture {
- pub fn call_and_assert(&self, expected_result: Result<(), &str>) {
- let saved_opening_next_id = Bureaucracy1::next_worker_opening_id();
- let actual_result = Bureaucracy1::add_worker_opening(
- self.origin.clone().into(),
- self.activate_at.clone(),
- self.commitment.clone(),
- self.human_readable_text.clone(),
- );
- assert_eq!(actual_result.clone(), expected_result);
- if actual_result.is_ok() {
- assert_eq!(
- Bureaucracy1::next_worker_opening_id(),
- saved_opening_next_id + 1
- );
- let opening_id = saved_opening_next_id;
- let actual_opening = Bureaucracy1::worker_opening_by_id(opening_id);
- let expected_opening = WorkerOpening::<u64, u64, u64, u64> {
- opening_id,
- worker_applications: BTreeSet::new(),
- policy_commitment: OpeningPolicyCommitment::default(),
- };
- assert_eq!(actual_opening, expected_opening);
- }
- }
- fn with_text(self, text: Vec<u8>) -> Self {
- AddWorkerOpeningFixture {
- human_readable_text: text,
- ..self
- }
- }
- fn with_activate_at(self, activate_at: hiring::ActivateOpeningAt<u64>) -> Self {
- AddWorkerOpeningFixture {
- activate_at,
- ..self
- }
- }
- }
- struct EventFixture;
- impl EventFixture {
- fn assert_crate_events(
- expected_raw_events: Vec<
- RawEvent<u64, u64, u64, u64, std::collections::BTreeMap<u64, u64>, crate::Instance1>,
- >,
- ) {
- let converted_events = expected_raw_events
- .iter()
- .map(|ev| TestEvent::bureaucracy_Instance1(ev.clone()))
- .collect::<Vec<TestEvent>>();
- Self::assert_global_events(converted_events)
- }
- fn assert_global_events(expected_raw_events: Vec<TestEvent>) {
- let expected_events = expected_raw_events
- .iter()
- .map(|ev| EventRecord {
- phase: Phase::ApplyExtrinsic(0),
- event: ev.clone(),
- topics: vec![],
- })
- .collect::<Vec<EventRecord<_, _>>>();
- assert_eq!(System::events(), expected_events);
- }
- }
- #[test]
- fn set_forum_sudo_set() {
- build_test_externalities().execute_with(|| {
-
- assert_eq!(Bureaucracy1::current_lead(), None);
- let lead_account_id = 1;
- let lead_member_id = 1;
-
- assert_eq!(
- Bureaucracy1::set_lead(RawOrigin::Root.into(), lead_member_id, lead_account_id),
- Ok(())
- );
- let lead = Lead {
- member_id: lead_member_id,
- role_account_id: lead_account_id,
- };
- assert_eq!(Bureaucracy1::current_lead(), Some(lead));
- EventFixture::assert_crate_events(vec![RawEvent::LeaderSet(
- lead_member_id,
- lead_account_id,
- )]);
- });
- }
- #[test]
- fn add_worker_opening_succeeds() {
- build_test_externalities().execute_with(|| {
- let lead_account_id = 1;
- SetLeadFixture::set_lead(lead_account_id);
- let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
- add_worker_opening_fixture.call_and_assert(Ok(()));
- EventFixture::assert_crate_events(vec![
- RawEvent::LeaderSet(1, lead_account_id),
- RawEvent::WorkerOpeningAdded(0),
- ]);
- });
- }
- #[test]
- fn add_worker_opening_fails_with_lead_is_not_set() {
- build_test_externalities().execute_with(|| {
- let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
- add_worker_opening_fixture.call_and_assert(Err(crate::MSG_CURRENT_LEAD_NOT_SET));
- });
- }
- #[test]
- fn add_worker_opening_fails_with_invalid_human_readable_text() {
- build_test_externalities().execute_with(|| {
- SetLeadFixture::set_lead(1);
- <crate::OpeningHumanReadableText<Instance1>>::put(InputValidationLengthConstraint {
- min: 1,
- max_min_diff: 5,
- });
- let add_worker_opening_fixture = AddWorkerOpeningFixture::default().with_text(Vec::new());
- add_worker_opening_fixture.call_and_assert(Err(crate::MSG_OPENING_TEXT_TOO_SHORT));
- let add_worker_opening_fixture =
- AddWorkerOpeningFixture::default().with_text(b"Long text".to_vec());
- add_worker_opening_fixture.call_and_assert(Err(crate::MSG_OPENING_TEXT_TOO_LONG));
- });
- }
- #[test]
- fn add_worker_opening_fails_with_hiring_error() {
- build_test_externalities().execute_with(|| {
- SetLeadFixture::set_lead(1);
- let add_worker_opening_fixture = AddWorkerOpeningFixture::default()
- .with_activate_at(hiring::ActivateOpeningAt::ExactBlock(0));
- add_worker_opening_fixture.call_and_assert(Err(
- crate::errors::MSG_ADD_WORKER_OPENING_ACTIVATES_IN_THE_PAST,
- ));
- });
- }
- #[test]
- fn accept_worker_applications_succeeds() {
- build_test_externalities().execute_with(|| {
- let lead_account_id = 1;
- SetLeadFixture::set_lead(lead_account_id);
- let add_worker_opening_fixture = AddWorkerOpeningFixture::default()
- .with_activate_at(hiring::ActivateOpeningAt::ExactBlock(5));
- add_worker_opening_fixture.call_and_assert(Ok(()));
- let opening_id = 0;
- let accept_worker_applications_fixture =
- AcceptWorkerApplicationsFixture::default_for_opening_id(opening_id);
- accept_worker_applications_fixture.call_and_assert(Ok(()));
- EventFixture::assert_crate_events(vec![
- RawEvent::LeaderSet(1, lead_account_id),
- RawEvent::WorkerOpeningAdded(opening_id),
- RawEvent::AcceptedWorkerApplications(opening_id),
- ]);
- });
- }
- #[test]
- fn accept_worker_applications_fails_with_hiring_error() {
- build_test_externalities().execute_with(|| {
- SetLeadFixture::set_lead(1);
- let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
- add_worker_opening_fixture.call_and_assert(Ok(()));
- let opening_id = 0;
- let accept_worker_applications_fixture =
- AcceptWorkerApplicationsFixture::default_for_opening_id(opening_id);
- accept_worker_applications_fixture.call_and_assert(Err(
- crate::errors::MSG_ACCEPT_WORKER_APPLICATIONS_OPENING_IS_NOT_WAITING_TO_BEGIN,
- ));
- });
- }
- #[test]
- fn accept_worker_applications_fails_with_not_lead() {
- build_test_externalities().execute_with(|| {
- SetLeadFixture::set_lead(1);
- let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
- add_worker_opening_fixture.call_and_assert(Ok(()));
- SetLeadFixture::set_lead(2);
- let opening_id = 0;
- let accept_worker_applications_fixture =
- AcceptWorkerApplicationsFixture::default_for_opening_id(opening_id);
- accept_worker_applications_fixture.call_and_assert(Err(crate::MSG_IS_NOT_LEAD_ACCOUNT));
- });
- }
- #[test]
- fn accept_worker_applications_fails_with_no_opening() {
- build_test_externalities().execute_with(|| {
- SetLeadFixture::set_lead(1);
- let opening_id = 0;
- let accept_worker_applications_fixture =
- AcceptWorkerApplicationsFixture::default_for_opening_id(opening_id);
- accept_worker_applications_fixture
- .call_and_assert(Err(crate::MSG_WORKER_OPENING_DOES_NOT_EXIST));
- });
- }
- #[test]
- fn apply_on_worker_opening_succeeds() {
- build_test_externalities().execute_with(|| {
- let lead_account_id = 1;
- SetLeadFixture::set_lead(lead_account_id);
- setup_members(2);
- let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
- add_worker_opening_fixture.call_and_assert(Ok(()));
- let opening_id = 0;
- let appy_on_worker_opening_fixture =
- ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
- appy_on_worker_opening_fixture.call_and_assert(Ok(()));
- EventFixture::assert_global_events(vec![
- TestEvent::bureaucracy_Instance1(RawEvent::LeaderSet(1, lead_account_id)),
- TestEvent::membership_mod(membership::members::RawEvent::MemberRegistered(0, 0)),
- TestEvent::membership_mod(membership::members::RawEvent::MemberRegistered(1, 1)),
- TestEvent::bureaucracy_Instance1(RawEvent::WorkerOpeningAdded(opening_id)),
- TestEvent::bureaucracy_Instance1(RawEvent::AppliedOnWorkerOpening(opening_id, 0)),
- ]);
- });
- }
- #[test]
- fn apply_on_worker_opening_fails_with_no_opening() {
- build_test_externalities().execute_with(|| {
- let lead_account_id = 1;
- SetLeadFixture::set_lead(lead_account_id);
- setup_members(2);
- let opening_id = 0;
- let appy_on_worker_opening_fixture =
- ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
- appy_on_worker_opening_fixture
- .call_and_assert(Err(crate::MSG_WORKER_OPENING_DOES_NOT_EXIST));
- });
- }
- #[test]
- fn apply_on_worker_opening_fails_with_not_set_members() {
- build_test_externalities().execute_with(|| {
- let lead_account_id = 1;
- SetLeadFixture::set_lead(lead_account_id);
- let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
- add_worker_opening_fixture.call_and_assert(Ok(()));
- let opening_id = 0;
- let appy_on_worker_opening_fixture =
- ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
- appy_on_worker_opening_fixture
- .call_and_assert(Err(crate::MSG_ORIGIN_IS_NEITHER_MEMBER_CONTROLLER_OR_ROOT));
- });
- }
- #[test]
- fn apply_on_worker_opening_fails_with_hiring_error() {
- build_test_externalities().execute_with(|| {
- increase_total_balance_issuance_using_account_id(1, 500000);
- let lead_account_id = 1;
- SetLeadFixture::set_lead(lead_account_id);
- setup_members(2);
- let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
- add_worker_opening_fixture.call_and_assert(Ok(()));
- let opening_id = 0;
- let appy_on_worker_opening_fixture =
- ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id)
- .with_application_stake(100);
- appy_on_worker_opening_fixture.call_and_assert(Err(
- crate::errors::MSG_ADD_WORKER_OPENING_STAKE_PROVIDED_WHEN_REDUNDANT,
- ));
- });
- }
- #[test]
- fn apply_on_worker_opening_fails_with_invalid_application_stake() {
- build_test_externalities().execute_with(|| {
- let lead_account_id = 1;
- SetLeadFixture::set_lead(lead_account_id);
- setup_members(2);
- let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
- add_worker_opening_fixture.call_and_assert(Ok(()));
- let opening_id = 0;
- let appy_on_worker_opening_fixture =
- ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id)
- .with_application_stake(100);
- appy_on_worker_opening_fixture
- .call_and_assert(Err(crate::MSG_INSUFFICIENT_BALANCE_TO_APPLY));
- });
- }
- #[test]
- fn apply_on_worker_opening_fails_with_invalid_role_stake() {
- build_test_externalities().execute_with(|| {
- let lead_account_id = 1;
- SetLeadFixture::set_lead(lead_account_id);
- setup_members(2);
- let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
- add_worker_opening_fixture.call_and_assert(Ok(()));
- let opening_id = 0;
- let appy_on_worker_opening_fixture =
- ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id).with_role_stake(100);
- appy_on_worker_opening_fixture
- .call_and_assert(Err(crate::MSG_INSUFFICIENT_BALANCE_TO_APPLY));
- });
- }
- #[test]
- fn apply_on_worker_opening_fails_with_invalid_text() {
- build_test_externalities().execute_with(|| {
- let lead_account_id = 1;
- SetLeadFixture::set_lead(lead_account_id);
- setup_members(2);
- let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
- add_worker_opening_fixture.call_and_assert(Ok(()));
- let opening_id = 0;
- <crate::WorkerApplicationHumanReadableText<Instance1>>::put(
- InputValidationLengthConstraint {
- min: 1,
- max_min_diff: 5,
- },
- );
- let appy_on_worker_opening_fixture =
- ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id).with_text(Vec::new());
- appy_on_worker_opening_fixture
- .call_and_assert(Err(crate::MSG_WORKER_APPLICATION_TEXT_TOO_SHORT));
- let appy_on_worker_opening_fixture =
- ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id)
- .with_text(b"Long text".to_vec());
- appy_on_worker_opening_fixture
- .call_and_assert(Err(crate::MSG_WORKER_APPLICATION_TEXT_TOO_LONG));
- });
- }
- #[test]
- fn apply_on_worker_opening_fails_with_already_active_application() {
- build_test_externalities().execute_with(|| {
- let lead_account_id = 1;
- SetLeadFixture::set_lead(lead_account_id);
- setup_members(2);
- let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
- add_worker_opening_fixture.call_and_assert(Ok(()));
- let opening_id = 0;
- let appy_on_worker_opening_fixture =
- ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
- appy_on_worker_opening_fixture.call_and_assert(Ok(()));
- appy_on_worker_opening_fixture
- .call_and_assert(Err(crate::MSG_MEMBER_HAS_ACTIVE_APPLICATION_ON_OPENING));
- });
- }
- #[test]
- fn withdraw_worker_application_succeeds() {
- build_test_externalities().execute_with(|| {
- let lead_account_id = 1;
- SetLeadFixture::set_lead(lead_account_id);
- setup_members(2);
- let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
- add_worker_opening_fixture.call_and_assert(Ok(()));
- let opening_id = 0;
- let appy_on_worker_opening_fixture =
- ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
- appy_on_worker_opening_fixture.call_and_assert(Ok(()));
- let application_id = 0;
- let withdraw_application_fixture =
- WithdrawApplicationFixture::default_for_application_id(application_id);
- withdraw_application_fixture.call_and_assert(Ok(()));
- EventFixture::assert_global_events(vec![
- TestEvent::bureaucracy_Instance1(RawEvent::LeaderSet(1, lead_account_id)),
- TestEvent::membership_mod(membership::members::RawEvent::MemberRegistered(0, 0)),
- TestEvent::membership_mod(membership::members::RawEvent::MemberRegistered(1, 1)),
- TestEvent::bureaucracy_Instance1(RawEvent::WorkerOpeningAdded(opening_id)),
- TestEvent::bureaucracy_Instance1(RawEvent::AppliedOnWorkerOpening(
- opening_id,
- application_id,
- )),
- TestEvent::bureaucracy_Instance1(RawEvent::WorkerApplicationWithdrawn(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(crate::MSG_WORKER_APPLICATION_DOES_NOT_EXIST));
- });
- }
- #[test]
- fn withdraw_worker_application_fails_invalid_origin() {
- build_test_externalities().execute_with(|| {
- let lead_account_id = 1;
- SetLeadFixture::set_lead(lead_account_id);
- setup_members(2);
- let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
- add_worker_opening_fixture.call_and_assert(Ok(()));
- let opening_id = 0;
- let appy_on_worker_opening_fixture =
- ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
- appy_on_worker_opening_fixture.call_and_assert(Ok(()));
- let application_id = 0;
- let withdraw_application_fixture =
- WithdrawApplicationFixture::default_for_application_id(application_id)
- .with_origin(RawOrigin::None);
- withdraw_application_fixture.call_and_assert(Err("RequireSignedOrigin"));
- });
- }
- #[test]
- fn withdraw_worker_application_fails_with_invalid_application_author() {
- build_test_externalities().execute_with(|| {
- let lead_account_id = 1;
- SetLeadFixture::set_lead(lead_account_id);
- setup_members(2);
- let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
- add_worker_opening_fixture.call_and_assert(Ok(()));
- let opening_id = 0;
- let appy_on_worker_opening_fixture =
- ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
- appy_on_worker_opening_fixture.call_and_assert(Ok(()));
- let application_id = 0;
- 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(crate::MSG_ORIGIN_IS_NOT_APPLICANT));
- });
- }
- #[test]
- fn withdraw_worker_application_fails_with_hiring_error() {
- build_test_externalities().execute_with(|| {
- let lead_account_id = 1;
- SetLeadFixture::set_lead(lead_account_id);
- setup_members(2);
- let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
- add_worker_opening_fixture.call_and_assert(Ok(()));
- let opening_id = 0;
- let appy_on_worker_opening_fixture =
- ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
- appy_on_worker_opening_fixture.call_and_assert(Ok(()));
- let application_id = 0;
- 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(
- crate::errors::MSG_WITHDRAW_WORKER_APPLICATION_APPLICATION_NOT_ACTIVE,
- ));
- });
- }
- #[test]
- fn terminate_worker_application_succeeds() {
- build_test_externalities().execute_with(|| {
- let lead_account_id = 1;
- SetLeadFixture::set_lead(lead_account_id);
- setup_members(2);
- let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
- add_worker_opening_fixture.call_and_assert(Ok(()));
- let opening_id = 0;
- let appy_on_worker_opening_fixture =
- ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
- appy_on_worker_opening_fixture.call_and_assert(Ok(()));
- let application_id = 0;
- let terminate_application_fixture =
- TerminateApplicationFixture::default_for_application_id(application_id);
- terminate_application_fixture.call_and_assert(Ok(()));
- EventFixture::assert_global_events(vec![
- TestEvent::bureaucracy_Instance1(RawEvent::LeaderSet(1, lead_account_id)),
- TestEvent::membership_mod(membership::members::RawEvent::MemberRegistered(0, 0)),
- TestEvent::membership_mod(membership::members::RawEvent::MemberRegistered(1, 1)),
- TestEvent::bureaucracy_Instance1(RawEvent::WorkerOpeningAdded(opening_id)),
- TestEvent::bureaucracy_Instance1(RawEvent::AppliedOnWorkerOpening(
- opening_id,
- application_id,
- )),
- TestEvent::bureaucracy_Instance1(RawEvent::WorkerApplicationTerminated(application_id)),
- ]);
- });
- }
- #[test]
- fn terminate_worker_application_fails_with_invalid_application_author() {
- build_test_externalities().execute_with(|| {
- let lead_account_id = 1;
- SetLeadFixture::set_lead(lead_account_id);
- setup_members(2);
- let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
- add_worker_opening_fixture.call_and_assert(Ok(()));
- let opening_id = 0;
- let appy_on_worker_opening_fixture =
- ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
- appy_on_worker_opening_fixture.call_and_assert(Ok(()));
- let application_id = 0;
- 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(crate::MSG_IS_NOT_LEAD_ACCOUNT));
- });
- }
- #[test]
- fn terminate_worker_application_fails_invalid_origin() {
- build_test_externalities().execute_with(|| {
- let lead_account_id = 1;
- SetLeadFixture::set_lead(lead_account_id);
- setup_members(2);
- let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
- add_worker_opening_fixture.call_and_assert(Ok(()));
- let opening_id = 0;
- let appy_on_worker_opening_fixture =
- ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
- appy_on_worker_opening_fixture.call_and_assert(Ok(()));
- let application_id = 0;
- let terminate_application_fixture =
- TerminateApplicationFixture::default_for_application_id(application_id)
- .with_origin(RawOrigin::None);
- terminate_application_fixture.call_and_assert(Err("RequireSignedOrigin"));
- });
- }
- #[test]
- fn terminate_worker_application_fails_invalid_application_id() {
- build_test_externalities().execute_with(|| {
- let lead_account_id = 1;
- SetLeadFixture::set_lead(lead_account_id);
- let invalid_application_id = 6;
- let terminate_application_fixture =
- TerminateApplicationFixture::default_for_application_id(invalid_application_id);
- terminate_application_fixture
- .call_and_assert(Err(crate::MSG_WORKER_APPLICATION_DOES_NOT_EXIST));
- });
- }
- #[test]
- fn terminate_worker_application_fails_with_hiring_error() {
- build_test_externalities().execute_with(|| {
- let lead_account_id = 1;
- SetLeadFixture::set_lead(lead_account_id);
- setup_members(2);
- let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
- add_worker_opening_fixture.call_and_assert(Ok(()));
- let opening_id = 0;
- let appy_on_worker_opening_fixture =
- ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
- appy_on_worker_opening_fixture.call_and_assert(Ok(()));
- let application_id = 0;
- 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(
- crate::errors::MSG_WITHDRAW_WORKER_APPLICATION_APPLICATION_NOT_ACTIVE,
- ));
- });
- }
- #[test]
- fn begin_review_worker_applications_succeeds() {
- build_test_externalities().execute_with(|| {
- let lead_account_id = 1;
- SetLeadFixture::set_lead(lead_account_id);
- let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
- add_worker_opening_fixture.call_and_assert(Ok(()));
- let opening_id = 0;
- let begin_review_worker_applications_fixture =
- BeginReviewWorkerApplicationsFixture::default_for_opening_id(opening_id);
- begin_review_worker_applications_fixture.call_and_assert(Ok(()));
- EventFixture::assert_crate_events(vec![
- RawEvent::LeaderSet(1, lead_account_id),
- RawEvent::WorkerOpeningAdded(opening_id),
- RawEvent::BeganWorkerApplicationReview(opening_id),
- ]);
- });
- }
- #[test]
- fn begin_review_worker_applications_fails_with_not_a_lead() {
- build_test_externalities().execute_with(|| {
- let lead_account_id = 1;
- SetLeadFixture::set_lead(lead_account_id);
- let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
- add_worker_opening_fixture.call_and_assert(Ok(()));
- let new_lead_account_id = 33;
- SetLeadFixture::set_lead(new_lead_account_id);
- let opening_id = 0;
- let begin_review_worker_applications_fixture =
- BeginReviewWorkerApplicationsFixture::default_for_opening_id(opening_id);
- begin_review_worker_applications_fixture
- .call_and_assert(Err(crate::MSG_IS_NOT_LEAD_ACCOUNT));
- });
- }
- #[test]
- fn begin_review_worker_applications_fails_with_invalid_opening() {
- build_test_externalities().execute_with(|| {
- let lead_account_id = 1;
- SetLeadFixture::set_lead(lead_account_id);
- 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(crate::MSG_WORKER_OPENING_DOES_NOT_EXIST));
- });
- }
- #[test]
- fn begin_review_worker_applications_with_hiring_error() {
- build_test_externalities().execute_with(|| {
- let lead_account_id = 1;
- SetLeadFixture::set_lead(lead_account_id);
- let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
- add_worker_opening_fixture.call_and_assert(Ok(()));
- let opening_id = 0;
- 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(
- crate::errors::MSG_BEGIN_WORKER_APPLICANT_REVIEW_OPENING_OPENING_IS_NOT_WAITING_TO_BEGIN,
- ));
- });
- }
- #[test]
- fn begin_review_worker_applications_fails_with_invalid_origin() {
- build_test_externalities().execute_with(|| {
- let lead_account_id = 1;
- SetLeadFixture::set_lead(lead_account_id);
- let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
- add_worker_opening_fixture.call_and_assert(Ok(()));
- let opening_id = 0;
- 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("RequireSignedOrigin"));
- });
- }
- #[test]
- fn fill_worker_opening_succeeds() {
- build_test_externalities().execute_with(|| {
- let lead_account_id = 1;
- SetLeadFixture::set_lead(lead_account_id);
- setup_members(2);
- let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
- add_worker_opening_fixture.call_and_assert(Ok(()));
- let opening_id = 0;
- let appy_on_worker_opening_fixture =
- ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
- appy_on_worker_opening_fixture.call_and_assert(Ok(()));
- let application_id = 0;
- let begin_review_worker_applications_fixture =
- BeginReviewWorkerApplicationsFixture::default_for_opening_id(opening_id);
- begin_review_worker_applications_fixture.call_and_assert(Ok(()));
- let fill_worker_opening_fixture =
- FillWorkerOpeningFixture::default_for_ids(opening_id, vec![application_id]);
- fill_worker_opening_fixture.call_and_assert(Ok(()));
- let worker_id = 0;
- let mut worker_application_dictionary = BTreeMap::new();
- worker_application_dictionary.insert(application_id, worker_id);
- EventFixture::assert_global_events(vec![
- TestEvent::bureaucracy_Instance1(RawEvent::LeaderSet(1, lead_account_id)),
- TestEvent::membership_mod(membership::members::RawEvent::MemberRegistered(0, 0)),
- TestEvent::membership_mod(membership::members::RawEvent::MemberRegistered(1, 1)),
- TestEvent::bureaucracy_Instance1(RawEvent::WorkerOpeningAdded(opening_id)),
- TestEvent::bureaucracy_Instance1(RawEvent::AppliedOnWorkerOpening(
- opening_id,
- application_id,
- )),
- TestEvent::bureaucracy_Instance1(RawEvent::BeganWorkerApplicationReview(opening_id)),
- TestEvent::bureaucracy_Instance1(RawEvent::WorkerOpeningFilled(
- opening_id,
- worker_application_dictionary,
- )),
- ]);
- });
- }
- #[test]
- fn fill_worker_opening_fails_with_invalid_origin() {
- build_test_externalities().execute_with(|| {
- let lead_account_id = 1;
- SetLeadFixture::set_lead(lead_account_id);
- let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
- add_worker_opening_fixture.call_and_assert(Ok(()));
- let opening_id = 0;
- let fill_worker_opening_fixture =
- FillWorkerOpeningFixture::default_for_ids(opening_id, Vec::new())
- .with_origin(RawOrigin::None);
- fill_worker_opening_fixture.call_and_assert(Err("RequireSignedOrigin"));
- });
- }
- #[test]
- fn fill_worker_opening_fails_with_not_a_lead() {
- build_test_externalities().execute_with(|| {
- let lead_account_id = 1;
- SetLeadFixture::set_lead(lead_account_id);
- let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
- add_worker_opening_fixture.call_and_assert(Ok(()));
- let new_lead_account_id = 33;
- SetLeadFixture::set_lead(new_lead_account_id);
- let opening_id = 0;
- let fill_worker_opening_fixture =
- FillWorkerOpeningFixture::default_for_ids(opening_id, Vec::new());
- fill_worker_opening_fixture.call_and_assert(Err(crate::MSG_IS_NOT_LEAD_ACCOUNT));
- });
- }
- #[test]
- fn fill_worker_opening_fails_with_invalid_opening() {
- build_test_externalities().execute_with(|| {
- let lead_account_id = 1;
- SetLeadFixture::set_lead(lead_account_id);
- let invalid_opening_id = 6;
- let fill_worker_opening_fixture =
- FillWorkerOpeningFixture::default_for_ids(invalid_opening_id, Vec::new());
- fill_worker_opening_fixture.call_and_assert(Err(crate::MSG_WORKER_OPENING_DOES_NOT_EXIST));
- });
- }
- #[test]
- fn fill_worker_opening_fails_with_invalid_application_list() {
- build_test_externalities().execute_with(|| {
- let lead_account_id = 1;
- SetLeadFixture::set_lead(lead_account_id);
- setup_members(2);
- let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
- add_worker_opening_fixture.call_and_assert(Ok(()));
- let opening_id = 0;
- let appy_on_worker_opening_fixture =
- ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
- appy_on_worker_opening_fixture.call_and_assert(Ok(()));
- let application_id = 0;
- 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_worker_opening_fixture = FillWorkerOpeningFixture::default_for_ids(
- opening_id,
- vec![application_id, invalid_application_id],
- );
- fill_worker_opening_fixture
- .call_and_assert(Err(crate::MSG_SUCCESSFUL_WORKER_APPLICATION_DOES_NOT_EXIST));
- });
- }
- #[test]
- fn fill_worker_opening_fails_with_invalid_application_with_hiring_error() {
- build_test_externalities().execute_with(|| {
- let lead_account_id = 1;
- SetLeadFixture::set_lead(lead_account_id);
- setup_members(2);
- let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
- add_worker_opening_fixture.call_and_assert(Ok(()));
- let opening_id = 0;
- let fill_worker_opening_fixture =
- FillWorkerOpeningFixture::default_for_ids(opening_id, Vec::new());
- fill_worker_opening_fixture.call_and_assert(Err(
- crate::errors::MSG_FULL_WORKER_OPENING_OPENING_NOT_IN_REVIEW_PERIOD_STAGE,
- ));
- });
- }
|