Skip to content

test(contracts): bonding curve regression tests + stroop display helper#358

Open
Dannyswiss1 wants to merge 1 commit into
accesslayerorg:mainfrom
Dannyswiss1:Feat/test-helper-Accesslayer-contracts
Open

test(contracts): bonding curve regression tests + stroop display helper#358
Dannyswiss1 wants to merge 1 commit into
accesslayerorg:mainfrom
Dannyswiss1:Feat/test-helper-Accesslayer-contracts

Conversation

@Dannyswiss1
Copy link
Copy Markdown

This PR adds 4 regression tests and a test helper to verify bonding curve math, admin invariants, and improve test readability per audit follow-ups.

What's Changed

Buy Quote Consistency - #352

  • Added test_buy_quote_updates_after_sell in contracts/src/test.rs
  • Reads buy quote at supply S, performs sell to reduce supply to S'
  • Asserts new buy quote matches bonding_curve_price(S') helper
  • Fails if quote doesn't update after supply change
  • Confirms supply changes immediately reflect in pricing

Admin Address Invariant - #353

  • Added test_admin_unchanged_after_fee_update
  • Records get_protocol_admin() before update_fee_config()
  • Executes fee config update with new fee bps
  • Asserts admin address identical after update using read-only getter
  • Fails if admin field is overwritten by config logic

Stroop Display Helper - #354

  • Added test_helpers.rs with to_display_units(stroops: u128) -> Decimal
  • Defined const STROOP_SCALE: u128 = 10_000_000 as named constant
  • Converts stroops to XLM display units for readable assertions
  • Updated 2 existing tests: test_large_buy_amount and test_fee_calculation
  • Before: assert_eq!(amount, 15000000000u128)
  • After: assert_eq!(to_display_units(amount), dec!(1500.0))

Buy/Sell Symmetry - #355

  • Added test_buy_sell_symmetric_price_impact
  • Records buy price for N keys at supply S
  • Buys N keys, then sells N keys
  • Asserts sell_proceeds = buy_cost - fees within 1 stroop tolerance
  • Documents expected relationship: sell_quote(buy(S, N)) ≈ buy_cost * (1 - fee_bps/10000)
  • Confirms bonding curve behaves symmetrically minus protocol fees

Testing Done

  • cargo test -p accesslayer-contracts → 4 new tests pass, 0 regressions
  • cargo fmt --all -- --check → pass
  • cargo clippy --all-targets -- -D warnings → 0 new warnings
  • Verified test_buy_quote_updates_after_sell fails if quote logic commented out
  • Verified test_admin_unchanged_after_fee_update fails if admin overwritten in update path
  • Helper correctly converts: to_display_units(10_000_000) == dec!(1.0)

Notes

All tests use existing bonding_curve_price helper for expected values. No changes to contract logic, tests only. STROOP_SCALE matches Stellar asset precision.

Closes #352
Closes #353
Closes #354
Closes #355

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 30, 2026

@Dannyswiss1 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant