From 3be428e30e4556e094a72d37844301b4fd72248d Mon Sep 17 00:00:00 2001 From: Sergej Date: Wed, 24 Jul 2024 15:00:29 +0200 Subject: [PATCH] ensure_matching_requirements_works --- pallets/processor/src/tests.rs | 48 ++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/pallets/processor/src/tests.rs b/pallets/processor/src/tests.rs index d38b6411..eb2b3afc 100644 --- a/pallets/processor/src/tests.rs +++ b/pallets/processor/src/tests.rs @@ -96,3 +96,51 @@ fn fulfill_order_works() { assert_eq!(assignments(), vec![(region_id, 2000.into())]); }); } + +#[test] +fn ensure_matching_requirements_works() { + new_test_ext(vec![]).execute_with(|| { + let requirements = Requirements { + begin: 0, + end: 8, + core_occupancy: 28800, // Half of a core. + }; + + // Region starts too late: + assert_noop!( + Processor::ensure_matching_requirements( + RegionId { begin: 2, core: 0, mask: CoreMask::complete() }, + RegionRecord { end: 10, owner: 1, paid: None }, + requirements.clone() + ), + Error::::RegionStartsTooLate + ); + + // Region ends too soon: + assert_noop!( + Processor::ensure_matching_requirements( + RegionId { begin: 0, core: 0, mask: CoreMask::complete() }, + RegionRecord { end: 4, owner: 1, paid: None }, + requirements.clone() + ), + Error::::RegionEndsTooSoon + ); + + // Region core occupancy insufficient: + assert_noop!( + Processor::ensure_matching_requirements( + RegionId { begin: 0, core: 0, mask: CoreMask::from_chunk(0, 39) }, + RegionRecord { end: 8, owner: 1, paid: None }, + requirements.clone() + ), + Error::::RegionCoreOccupancyInsufficient + ); + + // Works when all requirements are met: + assert_ok!(Processor::ensure_matching_requirements( + RegionId { begin: 0, core: 0, mask: CoreMask::from_chunk(0, 40) }, + RegionRecord { end: 8, owner: 1, paid: None }, + requirements.clone() + ),); + }) +}