Skip to content

[BE-062] Yield API: Validation unit tests - #513

Merged
ONEONUORA merged 3 commits into
Fracverse:masterfrom
Meemlahsabi:feat/be-062-yield-api-validation-tests
Jul 27, 2026
Merged

[BE-062] Yield API: Validation unit tests#513
ONEONUORA merged 3 commits into
Fracverse:masterfrom
Meemlahsabi:feat/be-062-yield-api-validation-tests

Conversation

@Meemlahsabi

Copy link
Copy Markdown
Contributor

Summary

  • Adds API integration tests covering input validation for the /api/yield endpoints in backend/tests/yield_api_tests.rs
  • Covers non-positive amount rejection on /deposit and /withdraw
  • Covers insufficient available/earning balance rejection on /deposit and /withdraw
  • Covers malformed JSON syntax (400) vs. missing/wrong-typed fields (422) input-format checks across /deposit, /withdraw, and /toggle-auto
  • Covers /history pagination limit/offset clamping and rejection of non-numeric query params

Closes #480

Test plan

  • cargo test --test yield_api_tests against a PostgreSQL instance with the Zaps schema applied (TEST_DATABASE_URL or DATABASE_URL set)

🤖 Generated with Claude Code

Adds coverage for /api/yield input validation and format checks:
non-positive amounts, insufficient balance, malformed JSON syntax,
missing/wrong-typed fields, and pagination clamping/rejection on
/history, /deposit, /withdraw, and /toggle-auto.

Closes Fracverse#480

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@drips-wave

drips-wave Bot commented Jul 24, 2026

Copy link
Copy Markdown

@Meemlahsabi Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@ONEONUORA

Copy link
Copy Markdown
Contributor

@Meemlahsabi
Sync with master branch
Update your branch
Work on your issue description
Make sure your implementation passes CI Checks

… tests

Two real bugs found while verifying this PR against the actual codebase
(neither could have passed CI as written):

1. `let _ = AuthUser;` referenced a 3-field struct by its bare type name,
   which is not a valid Rust expression (E0533-class error) — the test
   binary did not compile. AuthUser was never actually used as a type
   anywhere in this file; removed both the import and the dead reference.

2. Every seeded test address (e.g. "GVALIDNONPOS{run}XXXX...X") was 61
   characters, but `users.address` is `VARCHAR(56)`
   (backend/migrations/0001_schema.sql:6) — every `seed_user()` call in
   every new validation test would have failed with a Postgres
   "value too long for type character varying(56)" error. Added a
   `test_address(prefix, run)` helper that always produces exactly 56
   characters and replaced all nine manual constructions with it.

Also calls `zaps_backend::db::run_migrations` in `test_pool()` so the test
binary applies the schema itself rather than requiring it pre-applied out
of band, and ran `rustfmt` on this file only (cargo fmt --check now passes
for it; unrelated pre-existing formatting drift in yield.rs, stellar.rs,
notifications.rs, and yield_calc.rs is untouched).

I could not run `cargo test`/`cargo clippy` locally (no Postgres/Redis
instance or MSVC-equivalent toolchain available in this environment) — I
verified this by reading the current backend/src/api/yield.rs handlers
line by line and confirming every status code, error string, and field
name this file asserts against still matches (Amount must be greater than
zero, Insufficient available/earning balance + available/earning fields,
Axum's default Json extractor 400-syntax/422-data split, HistoryQuery's
clamp(1,100)/max(0) logic).
@Meemlahsabi

Copy link
Copy Markdown
Contributor Author

Addressed the review feedback:

"Make sure your implementation passes CI Checks" — the test file did not actually compile. let _ = AuthUser; referenced a 3-field struct by its bare type name, which isn't a valid Rust expression — this is a hard compile error, so nothing in this file could ever have run. Fixed by removing the unused import and dead reference.

Separately (found while double-checking against the actual schema): every seeded test address in the new validation tests was 61 characters, but users.address is VARCHAR(56) (backend/migrations/0001_schema.sql:6) — every seed_user() call would have failed with a Postgres "value too long" error. Added a test_address(prefix, run) helper that always produces exactly 56 characters and switched all nine test functions to use it.

Also had test_pool() call zaps_backend::db::run_migrations directly so the test binary can apply the schema itself instead of requiring it pre-applied out of band, and ran rustfmt on this file (it's clean now; cargo fmt --all -- --check will still fail overall due to pre-existing formatting drift in yield.rs/stellar.rs/notifications.rs/yield_calc.rs that I didn't touch).

"Sync with master branch" — I couldn't fully rebase this branch onto current upstream master and push it: master is 20 commits ahead, and 2 of those touch .github/workflows/*, which GitHub blocks non-workflow-scoped tokens from pushing (even as part of an unrelated branch update). I verified line-by-line that everything this test file asserts against (Amount must be greater than zero, Insufficient available/earning balance, the HistoryQuery clamp logic, Axum's 400/422 split) is unchanged in the current backend/src/api/yield.rs, including after the #509 "Real transaction envelope generation" commit. If a real sync onto latest master is still wanted, the "Update branch" button on this PR should handle it without needing my token's scope — happy to resolve any conflicts that surfaces if you'd rather I do it by hand.

I could not run cargo test/cargo clippy/CI locally (no Postgres+Redis instance or working Rust toolchain in this environment) — flagging that clearly rather than claiming a green run I didn't actually see. Manual review against the current handlers is documented in the latest commit message.

@ONEONUORA

Copy link
Copy Markdown
Contributor

@Meemlahsabi
Pls update on this

@ONEONUORA

Copy link
Copy Markdown
Contributor

@Meemlahsabi
Update on this PR
You will be unassigned at the end of today

Resolve conflict in yield_api_tests.rs by keeping master SWEEP/REWARD
history coverage and the BE-062 validation tests, without the unused
AuthUser stub.
@Meemlahsabi

Copy link
Copy Markdown
Contributor Author

@ONEONUORA Updated — branch is synced with latest master.

What changed

  • Merged master into feat/be-062-yield-api-validation-tests
  • Resolved the conflict in backend/tests/yield_api_tests.rs by keeping:
    • master's SWEEP/REWARD friendly history coverage
    • the BE-062 validation / input-format tests from this PR
    • no unused AuthUser stub

PR is now mergeable (no conflicts). CI should re-run on the merge commit.

@ONEONUORA ONEONUORA left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job @Meemlahsabi

@ONEONUORA
ONEONUORA merged commit 115689e into Fracverse:master Jul 27, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BE-062] Yield API: Validation unit tests

3 participants