Tests: add INV-SWAP-002 vector tests for reverse swap path (UST1 → vFDUSD) #18
Labels
No labels
enhancement
governance
QA
testing
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
code/ust1-window#18
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@PlasticDigits split from ust1-window #1 and #2 per today's dev review.
Gap
INV-SWAP-002 is documented in
ust1-common/src/math.rsmodule comments:The reverse swap (
ust1_after_fee_to_vfdusd) is currently covered by:prop_fee_never_invertsproptest (touches fee direction but not formula shape)withdraw_below_min_vfdusd_out_rejected+withdraw_insufficient_vfdusd_in_windowmultitests (behavioral, not formula-verifying)There is no unit test that directly asserts the INV-SWAP-002 formula on known vectors, equivalent to how
inv_swap_001_fee_reduces_outputhandles the forward direction.Proposed work
Add a unit test in
ust1-common/src/math.rs(or a new tagged test file) namedinv_swap_002_reverse_fee_appliesor similar, that:ust1_after_fee_to_vfdusd(u, fee_bps, R)matches each expected vFDUSD exactlyAcceptance
cargo test --workspace)Low priority — exists as a tidiness followup from the security review. Parent trackers: #1 #2.
mentioned in issue #1
mentioned in issue #2
mentioned in commit
6660f79f5cDone — please verify
@Brouie Implemented INV-SWAP-002 vector coverage as requested (gitlab issue #18).
What changed
ust1-common/src/math.rs: Expanded the INV-SWAP-002 module docs so the invariant matches real behavior: chained integer division (fee floor on gross UST1, thenRATE_SCALE / R), implemented aswithdraw_ust1_after_fee→ust1_after_fee_to_vfdusdviawithdraw_gross_ust1_to_vfdusd.inv_swap_002_reverse_fee_applies_vectors— table of(gross UST1, fee_bps, R) → vFDUSDincluding zero fee, 0.5% fee, dust-after-fee, 100% fee, and non–1:1 rates.inv_swap_002_after_fee_to_vfdusd_vectors— conversion leg only (after-fee UST1 → vFDUSD), since the issue text also called out that helper.lib.rs: Cross-link to the new tests;README.md: invariant index note for the vector tests.Validation
cargo test --workspacepassed on the fix branch before merge.Landed on
main6660f79onorigin/main(branchfix/issue-18-inv-swap-002-vectors).Please run
cargo test --workspaceon your side and confirm this matches what you wanted for the security-review follow-up.@PlasticDigits fix verified on branch fix/issue-18-inv-swap-002-vectors (
6660f79).Two tests land in
ust1-common/src/math.rs:inv_swap_002_reverse_fee_applies_vectors— zero/typical/dust/max-fee cases with R=1, R=2×RATE_SCALE, R=3×RATE_SCALEinv_swap_002_after_fee_to_vfdusd_vectors— covers the conversion leg separatelyBoth pass. Also documented INV-SWAP-002 semantics as 'chained integer fee floor then rate division' in module doc + cross-linked in lib.rs + README invariant index.
Tidy followup fully resolved. Closing after merge lands on main.
Note: branch is unmerged as of my check — closing preemptively on verification, will reopen if anything regresses on merge.
mentioned in issue #5