Skip to content

[CT-10] Write comprehensive unit tests for the reputation contract #918

@mftee

Description

@mftee

Problem

The reputation contract's composite scoring formula (0-1000 scale combining rating, punctuality, and reliability) has no test coverage. An incorrect calculation would corrupt carrier rankings and shipper trust scores across the entire platform with no automated detection.

Proposed Solution

Write a test suite for the reputation contract inside contracts/package/tests/reputation/ that verifies the scoring formula with exact expected values.

Note: All work must be done inside the contracts/package/ directory. Do not modify any existing contract files outside this folder.

Acceptance Criteria

  • Tests cover add_rating: valid scores 1-5 succeed; scores 0 and 6 return InvalidScore
  • Tests cover composite score calculation with known inputs: e.g., avgRating=4, onTimePct=0.9, completionRate=0.95 → expected score calculated and asserted exactly
  • Tests cover duplicate rating: same caller rating the same shipment twice returns DuplicateRating
  • Tests cover get_reputation: returns the correct breakdown of all three score components
  • Tests cover update_stats: on-time percentage updates correctly after new data
  • All assert_eq! calls use explicit expected values, not computed values (tests verify the formula, not re-implement it)

Metadata

Metadata

Assignees

Labels

Type

No type
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