Skip to content

Feat: Round Instance Validation Implementation #128

@manlikeHB

Description

@manlikeHB

Overview

Implement comprehensive validation for Round instances. This issue covers the is_valid() method that ensures round instances maintain data integrity and business rule compliance.

Requirements

Function to Implement

is_valid() - Comprehensive Round Instance Validation

fn is_valid(self: @Round) -> bool
  • Validate all fields of an existing Round instance
  • Check business rule compliance
  • Verify data consistency and integrity
  • Validate state transition logic
  • Return true only if round is completely valid

Validation Categories

Basic Field Validation

  • Round ID: Must be > 0 (no zero IDs allowed)
  • Creator Address: Must be non-zero valid address
  • Player Counts: players_count must be > 0 and ≤ max_players
  • Ready Count: ready_players_count must be ≤ players_count
  • Configuration: cards_per_round and card_timeout must be > 0

Enum Integrity Validation

  • Mode Conversion: Validate mode felt252 converts to valid Mode enum
  • State Conversion: Validate state felt252 converts to valid RoundState enum
  • Challenge Type: Validate challenge_type felt252 converts to valid enum
  • Non-Zero Validation: Converted enums must not be zero values

State Transition Validation

  • Started State: If Started, start_time must be > 0
  • Completed State: If Completed, both start_time and end_time must be > 0
  • Time Logic: If Completed, end_time must be > start_time
  • Pending State: No additional time constraints

Validation Strategy

  • Fail Fast: Return false immediately on first invalid condition
  • Comprehensive: Check all aspects of round integrity
  • Safe: Handle all edge cases gracefully

Acceptance Criteria

  • is_valid() method implemented with comprehensive validation
  • All basic field validations working correctly
  • Enum integrity validation complete
  • State transition validation accurate
  • Complete test coverage for all validation scenarios
  • All edge cases and boundary conditions tested

Dependencies

  • Use existing Round struct and helper methods (get_mode(), get_state(), get_challenge_type())
  • Use Zero trait for enum zero-value detection
  • No dependencies on other implementation issues

Note

Target Branch

  • refac/modular-architecture

File Location

  • src/models/round.cairo

Target Trait

  • RoundTrait

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions