Skip to content

[CT-14] Implement Payment Amount Validator with tolerance support in Rust #1031

@devwums

Description

@devwums

Problem

The payment validation logic in the manage_hub contract accepts any payment amount. There is no check against the expected subscription price, allowing underpayment to silently succeed.

Proposed Solution

Create contracts/cntr/payment_validator.rs implementing pub fn validate_payment_amount(received_stroops: i128, expected_stroops: i128, tolerance_stroops: i128) -> Result<(), &'static str>. The payment is valid when received_stroops >= expected_stroops - tolerance_stroops. Also validates that expected_stroops > 0. All implementation must live inside contracts/cntr/.

Acceptance Criteria

  • File at contracts/cntr/payment_validator.rs
  • Returns Ok(()) when received is within tolerance of expected
  • Returns Err("Payment amount insufficient") when received is below the tolerance threshold
  • Returns Err("Expected amount must be positive") when expected_stroops <= 0
  • At least 6 unit tests: exact amount, within tolerance, one stroop below tolerance, overpayment, zero expected
  • Compiles with cargo test

Metadata

Metadata

Labels

Stellar WaveIssues in the Stellar wave program

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