diff --git a/pallets/orders/src/benchmarking.rs b/pallets/orders/src/benchmarking.rs index 87e59ea1..33d1fef9 100644 --- a/pallets/orders/src/benchmarking.rs +++ b/pallets/orders/src/benchmarking.rs @@ -146,12 +146,16 @@ mod benchmarks { // manually contribute since the order 'expired': <::Currency as Currency>::transfer( - &creator.clone(), - &T::OrderToAccountId::convert(0), - ::MinimumContribution::get(), - ExistenceRequirement::KeepAlive, + &creator.clone(), + &T::OrderToAccountId::convert(0), + ::MinimumContribution::get(), + ExistenceRequirement::KeepAlive, )?; - Contributions::::insert(0, creator.clone(), ::MinimumContribution::get()); + Contributions::::insert( + 0, + creator.clone(), + ::MinimumContribution::get(), + ); crate::Pallet::::do_cancel_order(0)?; diff --git a/pallets/processor/src/tests.rs b/pallets/processor/src/tests.rs index ff4e20c8..8fb472cf 100644 --- a/pallets/processor/src/tests.rs +++ b/pallets/processor/src/tests.rs @@ -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, }; @@ -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. + }; + + ::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(®ion_id.into(), ®ion_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::::OrderExpired + ); + }); +} + #[test] fn assign_works() { new_test_ext(vec![]).execute_with(|| {