Skip to content
This repository has been archived by the owner on Feb 22, 2024. It is now read-only.

Commit

Permalink
test create_project
Browse files Browse the repository at this point in the history
  • Loading branch information
amiyatulu committed Nov 14, 2023
1 parent 46f3221 commit 4cba178
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 14 deletions.
6 changes: 3 additions & 3 deletions pallets/project-tips/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
/// Edit this file to define custom logic or remove it if it is not needed.
/// Learn more about FRAME and the core library of Substrate FRAME pallets:
/// <https://docs.substrate.io/reference/frame-pallets/>


pub use pallet::*;

#[cfg(test)]
Expand Down Expand Up @@ -156,9 +158,7 @@ pub mod pallet {
ProjectCreatorDontMatch,
}

// Dispatchable functions allows users to interact with the pallet and invoke state changes.
// These functions materialize as "extrinsics", which are often compared to transactions.
// Dispatchable functions must be annotated with a weight and must return a DispatchResult.
// Check deparment exists, it will done using loose coupling
#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::call_index(0)]
Expand Down
2 changes: 1 addition & 1 deletion pallets/project-tips/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ frame_support::construct_runtime!(
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system,
TemplateModule: pallet_template,
ProjectTips: pallet_template,
Balances: pallet_balances,
Timestamp: pallet_timestamp,
SharedStorage:shared_storage,
Expand Down
41 changes: 31 additions & 10 deletions pallets/project-tips/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,41 @@
use crate::types::TippingName;
use crate::{mock::*, Error, Event};
use frame_support::{assert_noop, assert_ok};

#[test]
fn it_works_for_default_value() {
fn check_create_project_function() {
new_test_ext().execute_with(|| {
// Go past genesis block so events get deposited
System::set_block_number(1);
// Dispatch a signed extrinsic.

});
}
let tipping_name = TippingName::SmallTipper;
let tipping_value = ProjectTips::value_of_tipping_name(tipping_name);
let max_tipping_value = tipping_value.max_tipping_value;
let stake_required = tipping_value.stake_required;
let funding_needed = max_tipping_value - 100;
let balance = Balances::free_balance(1);
assert_ok!(ProjectTips::create_project(
RuntimeOrigin::signed(1),
2,
tipping_name,
funding_needed
));

#[test]
fn correct_error_for_none_value() {
new_test_ext().execute_with(|| {
// Ensure the expected error is thrown when no value is present.

let after_balance = Balances::free_balance(1);

assert_eq!(after_balance, balance - stake_required);

System::assert_last_event(Event::ProjectCreated { account: 1, project_id: 1 }.into());

let next_project_id = ProjectTips::next_project_id();

assert_eq!(2, next_project_id);

let funding_needed = max_tipping_value + 100;

assert_noop!(
ProjectTips::create_project(RuntimeOrigin::signed(1), 2, tipping_name, funding_needed),
Error::<Test>::FundingMoreThanTippingValue
);
});
}

0 comments on commit 4cba178

Please sign in to comment.