Skip to content

Feat: Player Validation System Implementation #140

@manlikeHB

Description

@manlikeHB

Overview

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

Requirements

Function to Implement

is_valid() - Comprehensive Player Instance Validation

fn is_valid(self: @RoundPlayer) -> bool
  • Validate all fields of an existing RoundPlayer instance
  • Check business rule compliance and data consistency
  • Verify state transition logic and field relationships
  • Return true only if player instance is completely valid
  • Used for debugging, testing, and data integrity checks

Validation Categories

Basic Field Validation

  • Player Address: Must be non-zero valid contract address
  • Round ID: Must be > 0 (no zero round IDs allowed)
  • Card Timeout: Must be > 0 (no infinite or zero timeouts)
  • Card Index: Must be ≤ 255 (CardIndex is u8 type)

Data Consistency Validation

  • Answer Counts: correct_answers must be ≤ total_answers
  • Score Logic: total_score should be reasonable for answer count
  • Time Logic: best_time should be ≤ card_timeout (if not zero)
  • State Consistency: Various state combinations must make sense

State Transition Validation

  • Completed Round: If completed, should not have active card
  • Ready State: If not ready, should not have answered cards
  • Active Card: Card start time consistency with answering state
  • Progress Logic: Card index should align with answer progression

Business Rule Validation

  • Join Status: Joined flag consistency with other state
  • Readiness Logic: Ready state prerequisites
  • Completion Logic: Completion state consistency
  • Timing Constraints: Time-based field relationships

Acceptance Criteria

  • is_valid() method implemented with comprehensive validation
  • All basic field validations working correctly
  • Data consistency checks functioning properly
  • State transition validation accurate
  • Business rule enforcement complete
  • Type constraint validation working
  • Complete test coverage for all validation scenarios
  • All edge cases and boundary conditions tested

Note

Target Branch

  • refac/modular-architecture

File Location

  • src/models/rround/ound_player.cairo

Target Trait

  • RoundPlayerTrait

Metadata

Metadata

Assignees

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