Skip to content

Add automated tests for claim_token endpoint #319

@coderabbitai

Description

@coderabbitai

Context

Follow-up from PR #315 and this comment.

Description

Add comprehensive automated tests for the new claim_token endpoint and its dependent logic in src/faucet/server_api.rs.

Test Coverage Needed

Unit Tests

  • parse_and_validate_address: Test valid and invalid address parsing
    • Invalid address format → assert BAD_REQUEST (400)
    • Valid addresses for different networks

Integration/Endpoint Tests

  • Mainnet branch: Request with FaucetInfo::MainnetFIL → assert IM_A_TEAPOT (418) response
  • Rate limiting: Trigger rate limit → assert TOO_MANY_REQUESTS (429) response with proper retry-after message
  • CalibnetFIL success path: Mock Provider and test native token claim → assert success and valid transaction ID returned
  • CalibnetUSDFC success path: Mock Provider and test ERC-20 token claim → assert success and valid transaction ID returned

Implementation Notes

  • Mock or stub Provider::from_network and faucet_address for deterministic test execution
  • Consider using mockall or test-only implementations for RPC/provider behavior
  • Ensure tests assert both HTTP status codes and ServerFnError variants appropriately
  • Add focused unit tests for handle_native_claim and handle_erc20_claim

Related

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

In review

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions