Skip to content

add tests for workspace booking contract functionality#642

Merged
yusuftomilola merged 2 commits intoDistinctCodes:mainfrom
JoeX17:test/booking-creation-test
Mar 9, 2026
Merged

add tests for workspace booking contract functionality#642
yusuftomilola merged 2 commits intoDistinctCodes:mainfrom
JoeX17:test/booking-creation-test

Conversation

@JoeX17
Copy link
Contributor

@JoeX17 JoeX17 commented Mar 8, 2026

closes #609

Description:
This PR introduces test coverage for the core book_workspace functionality within the workspace_booking smart contract. It ensures that successful bookings calculate costs correctly and execute the required token transfers, while also verifying that the contract strictly rejects overlapping booking attempts.

Key Changes:

  • Added test_book_workspace_success:

  • Utilizes setup_token to mint 10,000 tokens to the member address.

  • Registers a Meeting Room workspace ("ws-001", capacity 10, rate 1,000/hr).

  • Creates a 2-hour booking (booking-001) and asserts that the stored booking fields match the expected data (workspace_id, member, status: Active).

  • Validates the contract's cost calculation logic (using ceiling division), ensuring amount_paid equals 2,000.

  • Instantiates the TokenClient to verify the member's token balance correctly decreased from 10,000 to 8,000 after the transaction.

  • Added test_book_workspace_conflict_fails:

  • Registers a Hot Desk workspace (capacity 1).

  • Creates an initial 1-hour booking.

  • Attempts to create a second booking that overlaps with the first timeframe.

  • Ensures the contract successfully rejects the overlapping booking by panicking with the expected BookingConflict = 7 error (Error(Contract, #7)).

Files Modified:

  • contracts/workspace_booking/src/test.rs

Acceptance Criteria Met:

  • All 7 tests (5 previous + 2 new) pass successfully using cargo test -p workspace_booking.
  • test_book_workspace_success verifies the token balance decreased by exactly the amount_paid.
  • test_book_workspace_success verifies the cost calculation logic (amount_paid == 2_000 for a 2-hour booking at 1_000/hr).
  • test_book_workspace_conflict_fails correctly catches the Error(Contract, #7) panic.

@vercel
Copy link

vercel bot commented Mar 8, 2026

@JoeX17 is attempting to deploy a commit to the naijabuz's projects Team on Vercel.

A member of the Team first needs to authorize it.

@yusuftomilola yusuftomilola merged commit 0cf11dd into DistinctCodes:main Mar 9, 2026
2 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issue #9 — Booking Creation Tests

2 participants