Skip to content

test: boundary invariants, max amounts, error docs, storage notes#187

Merged
Chucks1093 merged 4 commits into
accesslayerorg:mainfrom
williamedvard:test/boundary-errors-benchmark-159-171-172-173
Apr 25, 2026
Merged

test: boundary invariants, max amounts, error docs, storage notes#187
Chucks1093 merged 4 commits into
accesslayerorg:mainfrom
williamedvard:test/boundary-errors-benchmark-159-171-172-173

Conversation

@williamedvard

Copy link
Copy Markdown
Contributor

Summary

Comprehensive test coverage and documentation for fee rounding behavior, maximum amount inputs, error codes, and storage performance characteristics. This batch adds boundary-value testing for invariants, documentation for error handling, and performance notes for contributors.

Changes

  • Add fee rounding invariant tests (20 tests) covering boundary values, balance conservation, rounding direction, and overflow prevention
  • Add max-value amount input test coverage (8 tests) for large amounts approaching i128 limits in buy/sell/quote paths
  • Document all contract error codes with meanings, causes, and caller behavior guidance
  • Document storage read patterns and performance optimization candidates for hot paths

Testing

All cargo CI checks pass:

  • cargo fmt --all -- --check: ✓
  • cargo clippy --workspace --all-targets -- -D warnings: ✓
  • cargo test --workspace: ✓ (152 tests passed, including 28 new tests)

Closes #159
Closes #171
Closes #172
Closes #173

Add comprehensive test suite verifying fee split invariants at boundary values:
- Balance conservation: creator_amount + protocol_amount == total
- Rounding direction: remainder from division goes to creator
- Boundary handling: zero, negative, dust amounts, and i128 limits
- Overflow prevention in checked variant

Tests cover:
- All typical amounts (1, 10, 99, 100, 999, 1000, 10000, 100000, 1M)
- All valid fee configurations (protocol_bps from 0 to 10000)
- Edge cases: equal splits, remainder favoring creator
- Safe and unsafe amounts for multiplication

Refs #159
Add tests for near-maximum amount input values in buy and sell paths:
- Large safe amounts (1 trillion, max safe i128/10000)
- Quote operations with maximum safe amounts
- Buy/sell transactions with large amounts
- Fee configurations with maximum amounts (50/50 split)

Tests verify overflow-safe behavior and error-free operation when
amounts approach i128 limits. Coverage includes both buy and sell paths
with various fee configurations.

Refs #173
Document all ContractError enum values with:
- Numeric error codes (1-9)
- Meaning and context for each error
- Likely causes and error conditions
- Expected caller behavior and remediation
- Integration notes for authorization, pricing, overflow
- Event emission and version stability guidance

Maps errors to their discriminant values and provides guidance for
clients on handling each error type appropriately.

Refs #171
Document storage access patterns and performance considerations:
- Query paths: 1-4 storage reads per call (get_buy_quote, get_sell_quote)
- State-modifying paths: read counts for buy_key, sell_key, register
- Optimization candidates for short/medium-term improvements
- Reproducible profiling methodology for contributors
- Storage layout summary and testing guidance

Identify hot paths (get_buy_quote: 3 reads, get_sell_quote: 4 reads)
and potential optimizations including client-side caching, separate
holder count storage, and quote batching API extensions.

Refs #172
@drips-wave

drips-wave Bot commented Apr 25, 2026

Copy link
Copy Markdown

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

@Chucks1093
Chucks1093 merged commit d97c7a3 into accesslayerorg:main Apr 25, 2026
1 check 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

2 participants