Skip to content

Commit

Permalink
updated tests, removed template tests, removed benchmarks (#161)
Browse files Browse the repository at this point in the history
* updated tests, removed template tests, removed benchmarks

* removed unused code
  • Loading branch information
letodunc authored Sep 23, 2022
1 parent 703c22a commit ec009b7
Show file tree
Hide file tree
Showing 5 changed files with 425 additions and 69 deletions.
12 changes: 0 additions & 12 deletions pallets/bidding/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,3 @@ use super::*;
use crate::Pallet as Bidding;
use frame_benchmarking::{benchmarks, whitelisted_caller};
use frame_system::RawOrigin;

benchmarks! {
do_something {
let s in 0 .. 100;
let caller: T::AccountId = whitelisted_caller();
}: _(RawOrigin::Signed(caller), s)
verify {
assert_eq!(Something::<T>::get(), Some(s));
}

impl_benchmark_test_suite!(Bidding, crate::mock::new_test_ext(), crate::mock::Test);
}
50 changes: 4 additions & 46 deletions pallets/bidding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ pub mod pallet {
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
/// Event documentation should end with an array that provides descriptive names for event
/// parameters. [something, who]
SomethingStored(u32, T::AccountId),
// The house is already being processed
HouseAlreadyInBiddingProcess(T::NftCollectionId, T::NftItemId, Housing_Fund::BalanceOf<T>, BlockNumberOf<T>),
// No enough fund for the house
Expand All @@ -91,52 +88,14 @@ pub mod pallet {
// Errors inform users that something went wrong.
#[pallet::error]
pub enum Error<T> {
/// Error names should be descriptive.
NoneValue,
/// Errors should have helpful documentation associated with them.
StorageOverflow,
/// No new onboarded houses found
NoNewHousesFound,
}

#[pallet::call]
impl<T: Config> Pallet<T> {
/// An example dispatchable that takes a singles value as a parameter, writes the value to
/// storage and emits an event. This function must be dispatched by a signed extrinsic.
//#[pallet::weight(10_000 + T::DbWeight::get().writes(1))]
#[pallet::weight(<T as pallet::Config>::WeightInfo::do_something(100))]
pub fn do_something(origin: OriginFor<T>, something: u32) -> DispatchResult {
// Check that the extrinsic was signed and get the signer.
// This function will return an error if the extrinsic is not signed.
let who = ensure_signed(origin)?;

// Update storage.
<Something<T>>::put(something);

// Emit an event.
Self::deposit_event(Event::SomethingStored(something, who));
// Return a successful DispatchResultWithPostInfo
Ok(())
}

/// An example dispatchable that may throw a custom error.
#[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]
pub fn cause_error(origin: OriginFor<T>) -> DispatchResult {
let _who = ensure_signed(origin)?;

// Read a value from storage.
match <Something<T>>::get() {
// Return an error if the value has not been set.
None => return Err(Error::<T>::NoneValue.into()),
Some(old) => {
// Increment the value read from storage; will error in the event of overflow.
let new = old.checked_add(1).ok_or(Error::<T>::StorageOverflow)?;
// Update the value in storage with the incremented result.
<Something<T>>::put(new);
Ok(())
},
}
}


}
}

Expand Down Expand Up @@ -176,8 +135,7 @@ impl<T: Config> Pallet<T> {

// Checki that the investor list creation was successful
if investors_shares.len() == 0 {
let block = <frame_system::Pallet<T>>
::block_number();
let block = <frame_system::Pallet<T>>::block_number();
Self::deposit_event(Event::FailedToAssembleInvestor(
item.0.clone(), item.1.clone(), amount.clone(), block,
));
Expand Down Expand Up @@ -209,7 +167,7 @@ impl<T: Config> Pallet<T> {
}

/// Create the list of investor and their contribution for a given asset's price
/// I follows the rules:
/// It follows the rules:
/// - the oldest contribution comes first
/// - no more than T::MaximumSharePerInvestor share per investor
/// - no less than T::MinimumSharePerInvestor share per investor
Expand Down
5 changes: 5 additions & 0 deletions pallets/bidding/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Block = frame_system::mocking::MockBlock<Test>;
pub(crate) type Balance = u128;
pub type CollectionId = u32;
pub type ItemId = u32;
pub type NftCollection = pallet_nft::PossibleCollections;
type AccountId = u64;
pub type MaxProposals = u32;
pub type BlockNumber = u64;
Expand Down Expand Up @@ -309,6 +310,8 @@ pub const BOB: u64 = 2;
pub const CHARLIE: u64 = 3;
pub const DAVE: u64 = 4;
pub const EVE: u64 = 5;
pub const AMANI: u64 = 6;
pub const KEZIA: u64 = 7;

// Build genesis storage according to the mock runtime.
pub fn new_test_ext() -> sp_io::TestExternalities {
Expand All @@ -321,6 +324,8 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
(CHARLIE, 200_000_000),
(DAVE, 150_000),
(EVE, 150_000),
(AMANI, 150_000),
(KEZIA, 150_000),
],
}
.assimilate_storage(&mut storage)
Expand Down
Loading

0 comments on commit ec009b7

Please sign in to comment.