Skip to content

Commit

Permalink
test unlist_region
Browse files Browse the repository at this point in the history
  • Loading branch information
cuteolaf committed May 23, 2024
1 parent 44aefb1 commit d5f648c
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions pallets/market/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,42 @@ fn list_region_works() {
);
});
}

#[test]
fn unlist_region_works() {
new_test_ext().execute_with(|| {
let region_id = RegionId { begin: 0, core: 0, mask: CoreMask::complete() };
let seller = 2;
let signer = RuntimeOrigin::signed(seller);

assert_ok!(Regions::mint_into(&region_id.into(), &seller));

let record: RegionRecord<u64, u64> = RegionRecord { end: 8, owner: 1, paid: None };
let timeslice: u64 = <Test as crate::Config>::TimeslicePeriod::get();
let price = 1_000_000;
let recipient = 1;

assert_ok!(Regions::set_record(region_id, record.clone()));

// Failure: NotListed
assert_err!(Market::unlist_region(signer.clone(), region_id), Error::<Test>::NotListed);

assert_ok!(Market::list_region(signer.clone(), region_id, price, Some(recipient)));

// Failure: NotAllowed
RelayBlockNumber::set(1 * timeslice);
assert_err!(
Market::unlist_region(RuntimeOrigin::signed(3), region_id),
Error::<Test>::NotAllowed
);

// Should be working now.
assert_ok!(Market::unlist_region(signer, region_id));

// Check storage items
assert!(Market::listings(region_id).is_none());

// Check events
System::assert_last_event(Event::Unlisted { region_id }.into())
});
}

0 comments on commit d5f648c

Please sign in to comment.