Skip to content

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

Description

@Leothosine

Problem

contracts/order/src/lib.rs:125-135 - place_order() accepts any restaurant_id: u64 without cross-contract validation:

pub fn place_order(env: Env, customer: Address, restaurant_id: u64, items: Vec<OrderItem>, ...) -> u64 {
    customer.require_auth();
    // No call to RestaurantRegistry to verify restaurant_id exists or is active
}

Orders can be placed against ghost restaurant IDs. The payment escrow will fund a wallet address that may not exist, permanently locking customer funds.

Proposed Solution

  1. Add restaurant_registry_address: Address to the Order contract's initialize() and store in persistent storage
  2. In place_order(), make a cross-contract call:
let registry_client = RestaurantRegistryClient::new(&env, &registry_addr);
let restaurant = registry_client.get_restaurant(&restaurant_id);
if !restaurant.is_active { panic!("restaurant is not active"); }

Acceptance Criteria

  • place_order() with a non-existent restaurant_id panics with "restaurant not found"
  • place_order() for an inactive restaurant panics with "restaurant is not active"
  • Happy-path test with a valid active restaurant passes
  • Cross-contract call is mocked via MockRestaurantRegistry in unit tests
  • initialize() stores the registry address and all existing tests are updated

Metadata

Metadata

Labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions