Skip to content

feat: validate restaurant_id against RestaurantRegistry in place_order#293

Merged
Leothosine merged 2 commits into
tosirano:mainfrom
AbdulmujibOladayo:feat/validate-restaurant-id
Jun 25, 2026
Merged

feat: validate restaurant_id against RestaurantRegistry in place_order#293
Leothosine merged 2 commits into
tosirano:mainfrom
AbdulmujibOladayo:feat/validate-restaurant-id

Conversation

@AbdulmujibOladayo

Copy link
Copy Markdown
Contributor

Summary

Validates restaurant_id against the RestaurantRegistry contract inside place_order() to prevent orders being placed against ghost or inactive restaurants.

Changes

  • DataKey: Added RestaurantRegistry variant to store the registry contract address
  • initialize(): Now accepts restaurant_registry_address: Address and stores it in instance storage
  • place_order(): Before saving the order, makes a cross-contract call to RestaurantRegistry::get_restaurant(restaurant_id):
    • Panics with "restaurant not found" if the registry has no record (propagated from registry)
    • Panics with "restaurant is not active" if is_active is false
  • Tests: All existing tests updated to pass registry_id to initialize(). Added MockRestaurantRegistry for unit tests with:
    • ID 1: active restaurant (happy path)
    • ID 2: inactive restaurant
    • Any other ID: panics with "restaurant not found"
    • New tests: valid active restaurant passes, inactive restaurant panics, nonexistent restaurant panics

Closes #282

@Leothosine Leothosine merged commit 3f5a639 into tosirano:main Jun 25, 2026
2 of 3 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.

[CO-04] Validate restaurant_id against RestaurantRegistry in place_order()

2 participants