Skip to content

test(fee): add unit and integration tests for protocol fee calculation at edge supply values (#557)#593

Open
TheDEV111 wants to merge 1 commit into
accesslayerorg:mainfrom
TheDEV111:issue-557
Open

test(fee): add unit and integration tests for protocol fee calculation at edge supply values (#557)#593
TheDEV111 wants to merge 1 commit into
accesslayerorg:mainfrom
TheDEV111:issue-557

Conversation

@TheDEV111

Copy link
Copy Markdown

Summary

Fixes #557

This PR adds unit and integration test coverage to verify that the protocol fee is calculated correctly across key supply edge cases — specifically at supply 0 (first key), supply 1, and supply 1000. It also enforces that fee calculations dynamically use the configured fee basis points from the test environment rather than hardcoded percentages, and verifies floor rounding (truncation towards zero) when protocol fee calculations produce non-integer stroop amounts.

Changes Included

  • Added dedicated test suite creator-keys/tests/protocol_fee_supply_edge_cases.rs:
    • test_protocol_fee_at_supply_0: Asserts protocol fee calculation when total key supply is 0 (first key buy quote & fee split).
    • test_protocol_fee_at_supply_1: Asserts protocol fee calculation when key supply is 1.
    • test_protocol_fee_at_supply_1000: Asserts protocol fee calculation at large supply (1000 keys).
    • test_protocol_fee_rounding_is_floor_not_ceiling: Verifies floor rounding behavior when the calculated fee contains a fractional stroop amount (e.g. 999 stroops @ 10% fee -> 99 stroops, 1 stroop @ 10% fee -> 0 stroops, 1001 stroops @ 10% fee -> 100 stroops).
    • test_apply_percentage_fee_uses_configured_bps_and_floors: Directly unit tests fee::apply_percentage_fee across multiple fee configurations (500 bps, 1000 bps, 2500 bps).

Acceptance Criteria Verification

  • Fee correct at supply 0, 1, and 1000
  • Rounding behavior is floor, not ceiling
  • Tests use the configured fee bps, not a hardcoded percentage

CI / Testing

  • cargo fmt --all -- --check passed
  • cargo clippy --workspace --all-targets -- -D warnings passed cleanly
  • cargo test --workspace passed (all workspace tests passing)
  • cargo check --workspace passed

@TheDEV111

Copy link
Copy Markdown
Author

@Chucks1093 kindly review

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.

Add unit test for protocol fee calculation at boundary supply values

1 participant