Skip to content

Commit

Permalink
add test & fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Szegoo committed Aug 23, 2024
1 parent 9747e90 commit 5c61e9d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
14 changes: 9 additions & 5 deletions pallets/orders/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,16 @@ mod benchmarks {

// manually contribute since the order 'expired':
<<T as Config>::Currency as Currency<T::AccountId>>::transfer(
&creator.clone(),
&T::OrderToAccountId::convert(0),
<T as crate::Config>::MinimumContribution::get(),
ExistenceRequirement::KeepAlive,
&creator.clone(),
&T::OrderToAccountId::convert(0),
<T as crate::Config>::MinimumContribution::get(),
ExistenceRequirement::KeepAlive,
)?;
Contributions::<T>::insert(0, creator.clone(), <T as crate::Config>::MinimumContribution::get());
Contributions::<T>::insert(
0,
creator.clone(),
<T as crate::Config>::MinimumContribution::get(),
);

crate::Pallet::<T>::do_cancel_order(0)?;

Expand Down
34 changes: 32 additions & 2 deletions pallets/processor/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

use crate::{
mock::{
assignments, new_test_ext, Balances, Orders, Processor, Regions, RuntimeOrigin, System,
Test,
assignments, new_test_ext, Balances, Orders, Processor, Regions, RelayBlockNumber,
RuntimeOrigin, System, Test,
},
Error, Event,
};
Expand Down Expand Up @@ -108,6 +108,36 @@ fn fulfill_order_works() {
});
}

#[test]
fn cannot_fulfill_expired_order() {
new_test_ext(vec![]).execute_with(|| {
let region_owner = 1;
let order_creator = 2000;
let requirements = Requirements {
begin: 1,
end: 8,
core_occupancy: 28800, // Half of a core.
};

<Test as crate::Config>::Currency::make_free_balance_be(&order_creator, 1000u32.into());
assert_ok!(Orders::create_order(
RuntimeOrigin::signed(order_creator.clone()),
2000.into(),
requirements.clone()
));

let region_id = RegionId { begin: 0, core: 0, mask: CoreMask::complete() };
assert_ok!(Regions::mint_into(&region_id.into(), &region_owner));
assert_ok!(Regions::set_record(region_id, RegionRecord { end: 0, owner: 1, paid: None }));

RelayBlockNumber::set(10 * 80);
assert_noop!(
Processor::fulfill_order(RuntimeOrigin::signed(region_owner), 0, region_id),
Error::<Test>::OrderExpired
);
});
}

#[test]
fn assign_works() {
new_test_ext(vec![]).execute_with(|| {
Expand Down

0 comments on commit 5c61e9d

Please sign in to comment.