Skip to content
This repository has been archived by the owner on Aug 19, 2022. It is now read-only.

Commit

Permalink
refactor specification
Browse files Browse the repository at this point in the history
  • Loading branch information
stojanov-igor committed Feb 28, 2022
1 parent dcf743e commit edf5d77
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
14 changes: 7 additions & 7 deletions task/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
//!
//! When Tasks are created, there is some associated metadata that shall be defined.
//! This includes the following:
//! - Task Description (Defining the Task description)
//! - Task Specification (Defining the Task specification)
//! - Task Budget (The cost of completion for the Task)
//! - Task Deadline (The specified time until which the task should be completed)
//!
Expand Down Expand Up @@ -97,7 +97,7 @@ pub mod pallet {
#[scale_info(skip_type_params(T))]
pub struct Task<T: Config> {
pub title: Vec<u8>,
pub description: Vec<u8>,
pub specification: Vec<u8>,
pub initiator: AccountOf<T>,
pub volunteer: AccountOf<T>,
pub current_owner: AccountOf<T>,
Expand Down Expand Up @@ -191,15 +191,15 @@ pub mod pallet {
// Dispatchable functions must be annotated with a weight and must return a DispatchResult.
#[pallet::call]
impl<T: Config> Pallet<T> {
/// Function call that creates tasks. [ origin, description, budget, deadline]
/// Function call that creates tasks. [ origin, specification, budget, deadline]
#[pallet::weight(10_000 + T::DbWeight::get().writes(1))]
pub fn create_task(origin: OriginFor<T>, title: Vec<u8>, description: Vec<u8>, budget: BalanceOf<T>, deadline: u32) -> DispatchResultWithPostInfo {
pub fn create_task(origin: OriginFor<T>, title: Vec<u8>, specification: Vec<u8>, budget: BalanceOf<T>, deadline: u32) -> DispatchResultWithPostInfo {

// Check that the extrinsic was signed and get the signer.
let signer = ensure_signed(origin)?;

// Update storage.
let task_id = Self::new_task(&signer, &title, &description, &budget, &deadline)?;
let task_id = Self::new_task(&signer, &title, &specification, &budget, &deadline)?;

// TODO: Check if user has balance to create task
// T::Currency::reserve(&signer, budget).map_err(|_| "locker can't afford to lock the amount requested")?;
Expand Down Expand Up @@ -263,15 +263,15 @@ pub mod pallet {
// *** Helper functions *** //
impl<T:Config> Pallet<T> {

pub fn new_task(from_initiator: &T::AccountId, title: &[u8], description: &[u8], budget: &BalanceOf<T>, deadline: &u32) -> Result<T::Hash, Error<T>> {
pub fn new_task(from_initiator: &T::AccountId, title: &[u8], specification: &[u8], budget: &BalanceOf<T>, deadline: &u32) -> Result<T::Hash, Error<T>> {

// Ensure user has a profile before creating a task
ensure!(pallet_profile::Pallet::<T>::has_profile(from_initiator).unwrap(), <Error<T>>::NoProfile);

// Init Task Object
let task = Task::<T> {
title: title.to_owned(),
description: description.to_owned(),
specification: specification.to_owned(),
initiator: from_initiator.clone(),
volunteer: from_initiator.clone(),
status: Created,
Expand Down
26 changes: 13 additions & 13 deletions task/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn create_new_task(){
let mut vec = Vec::new();
vec.push(2);

// Ensure new task can be created with [signer, description vector, budget, deadline]
// Ensure new task can be created with [signer, specification, budget, deadline]
assert_ok!(Task::create_task(Origin::signed(1), TITLE.to_vec(), vec, 7, DEADLINE));
});
}
Expand All @@ -30,7 +30,7 @@ fn increase_task_count_when_creating_task(){
let mut vec = Vec::new();
vec.push(2);

// Ensure new task can be created with [signer, description vector, budget, deadline]
// Ensure new task can be created with [signer, specification, budget, deadline]
assert_ok!(Task::create_task(Origin::signed(1), TITLE.to_vec(), vec, 7, DEADLINE));

// Assert that count is incremented by 1 after task creation
Expand All @@ -51,7 +51,7 @@ fn increase_task_count_when_creating_two_tasks(){
let mut vec2 = Vec::new();
vec2.push(7);

// Ensure new task can be created with [signer, description vector, budget, deadline]
// Ensure new task can be created with [signer, specification, budget, deadline]
assert_ok!(Task::create_task(Origin::signed(1), TITLE.to_vec(), vec1, 7, DEADLINE));
assert_ok!(Task::create_task(Origin::signed(1), TITLE.to_vec(), vec2, 99, DEADLINE));

Expand All @@ -75,7 +75,7 @@ fn cant_own_more_tax_than_max_tasks(){
let mut vec1 = Vec::new();
vec1.push(n);

// Ensure new task can be created with [signer, description vector, budget, deadline]
// Ensure new task can be created with [signer, specification, budget, deadline]
assert_ok!(Task::create_task(Origin::signed(1), TITLE.to_vec(), vec1, 7, DEADLINE));
}

Expand Down Expand Up @@ -146,7 +146,7 @@ fn start_tasks_assigns_new_current_owner(){
let mut vec1 = Vec::new();
vec1.push(2);

// Ensure new task can be created with [signer, description vector, budget]
// Ensure new task can be created with [signer, specification, budget]
assert_ok!(Task::create_task(Origin::signed(1), TITLE.to_vec(), vec1, 7, DEADLINE));

// Ensure new task is assigned to new current_owner (user 1)
Expand Down Expand Up @@ -175,7 +175,7 @@ fn start_tasks_assigns_task_to_volunteer(){
let mut vec1 = Vec::new();
vec1.push(2);

// Ensure new task can be created with [signer, description vector, budget]
// Ensure new task can be created with [signer, specification, budget]
assert_ok!(Task::create_task(Origin::signed(1), TITLE.to_vec(), vec1, 7, DEADLINE));

// Ensure new task is assigned to new current_owner (user 1)
Expand Down Expand Up @@ -204,7 +204,7 @@ fn completing_tasks_assigns_new_current_owner(){
let mut vec1 = Vec::new();
vec1.push(2);

// Ensure new task can be created with [signer, description vector, budget, deadline]
// Ensure new task can be created with [signer, specification, budget, deadline]
assert_ok!(Task::create_task(Origin::signed(1), TITLE.to_vec(), vec1, 7, DEADLINE));

// Ensure new task is assigned to new current_owner (user 1)
Expand Down Expand Up @@ -241,7 +241,7 @@ fn only_creator_deletes_task(){
let mut vec1 = Vec::new();
vec1.push(2);

// Ensure new task can be created with [signer, description vector, budget]
// Ensure new task can be created with [signer, specification, budget]
assert_ok!(Task::create_task(Origin::signed(1), TITLE.to_vec(), vec1, 7, DEADLINE));

// Ensure new task is assigned to new current_owner (user 1)
Expand Down Expand Up @@ -281,7 +281,7 @@ fn only_started_task_can_be_completed(){
let mut vec1 = Vec::new();
vec1.push(2);

// Ensure new task can be created with [signer, description vector, budget, deadline]
// Ensure new task can be created with [signer, specification, budget, deadline]
assert_ok!(Task::create_task(Origin::signed(1), TITLE.to_vec(), vec1, 7, DEADLINE));

// Ensure new task is assigned to new current_owner (user 1)
Expand Down Expand Up @@ -311,7 +311,7 @@ fn when_task_is_removed_ownership_is_cleared(){
let mut vec1 = Vec::new();
vec1.push(2);

// Ensure new task can be created with [signer, description vector, budget]
// Ensure new task can be created with [signer, specification, budget]
assert_ok!(Task::create_task(Origin::signed(1), TITLE.to_vec(), vec1, 7, DEADLINE));

// Ensure new task is assigned to new current_owner (user 1)
Expand Down Expand Up @@ -354,7 +354,7 @@ fn decrease_task_count_when_removing_task(){
let mut vec = Vec::new();
vec.push(2);

// Ensure new task can be created with [signer, description vector, budget]
// Ensure new task can be created with [signer, specification, budget]
assert_ok!(Task::create_task(Origin::signed(1), TITLE.to_vec(), vec, 8, DEADLINE));

// Get hash of task owned
Expand Down Expand Up @@ -391,7 +391,7 @@ fn increase_profile_reputation_when_task_completed(){
let mut vec1 = Vec::new();
vec1.push(2);

// Ensure new task can be created with [signer, description vector, budget]
// Ensure new task can be created with [signer, specification, budget]
assert_ok!(Task::create_task(Origin::signed(1), TITLE.to_vec(), vec1, 7, DEADLINE));

// Ensure new task is assigned to new current_owner (user 1)
Expand Down Expand Up @@ -428,7 +428,7 @@ fn only_add_reputation_when_task_has_been_completed(){
let mut vec = Vec::new();
vec.push(2);

// Ensure new task can be created with [signer, description vector, budget]
// Ensure new task can be created with [signer, specification, budget]
assert_ok!(Task::create_task(Origin::signed(1), TITLE.to_vec(), vec, 8, DEADLINE));

// Get hash of task owned
Expand Down

0 comments on commit edf5d77

Please sign in to comment.