Skip to content

test(creator-earnings): review gas usage for hot paths#1277

Merged
aji70 merged 2 commits into
MyFanss:mainfrom
Xaxxoo:feat/946-creator-earnings-gas-review
May 31, 2026
Merged

test(creator-earnings): review gas usage for hot paths#1277
aji70 merged 2 commits into
MyFanss:mainfrom
Xaxxoo:feat/946-creator-earnings-gas-review

Conversation

@Xaxxoo

@Xaxxoo Xaxxoo commented May 31, 2026

Copy link
Copy Markdown
Contributor

Summary

Add seven correctness tests that exercise the three hot execution paths of the creator-earnings contract (deposit, withdraw, balance read), following the pattern established by the treasury contract's gas benchmark module.

Soroban metering tracks CPU instructions and memory bytes per invocation. Correct balance accounting is the observable proxy for gas efficiency: wrong balances indicate a bad write path, which is also where gas is spent.

Hot-path analysis:

Function Dominant cost Storage tier
deposit token cross-contract transfer instance
withdraw auth check + balance read + transfer instance
balance storage read instance

Test plan

  • hot_path_deposit_single_correctness — sender and contract token balances change by the expected delta
  • hot_path_deposit_repeated_accumulates — three successive deposits sum correctly
  • hot_path_withdraw_correctness — creator and contract balances updated correctly
  • hot_path_full_withdraw_leaves_zero — full withdrawal empties internal balance
  • hot_path_balance_read_consistent_with_token_client — internal balance matches token client view
  • hot_path_invalid_amount_rejected_before_transfer — zero amounts rejected before auth/transfer
  • hot_path_overdraft_rejected — over-withdrawal rejected, balance unchanged
  • All existing tests continue to pass (no regressions)

Closes #946

@drips-wave

drips-wave Bot commented May 31, 2026

Copy link
Copy Markdown

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

@Xaxxoo Xaxxoo force-pushed the feat/946-creator-earnings-gas-review branch from 44fd29c to abdaa48 Compare May 31, 2026 17:09
Add seven correctness tests that exercise the three hot execution paths
of the creator-earnings contract (deposit, withdraw, balance read),
following the pattern established by the treasury gas benchmark module.

Soroban metering tracks CPU instructions and memory bytes per invocation.
Correct balance accounting is the observable proxy for gas efficiency:
wrong balances indicate a bad write path, which is also where gas is spent.

Hot-path analysis:
| Function | Dominant cost                         | Storage tier |
|----------|---------------------------------------|--------------|
| deposit  | token cross-contract transfer         | instance     |
| withdraw | auth check + balance read + transfer  | instance     |
| balance  | storage read                          | instance     |

Tests added:
- hot_path_deposit_single_correctness
- hot_path_deposit_repeated_accumulates
- hot_path_withdraw_correctness
- hot_path_full_withdraw_leaves_zero
- hot_path_balance_read_consistent_with_token_client
- hot_path_invalid_amount_rejected_before_transfer
- hot_path_overdraft_rejected

Also fixes a pre-existing compile error in content-likes: missing
`contracttype` import and invalid `panic_with_error!` string literal
(replaced with `Error::AlreadyInitialized`).

Applies cargo fmt to pre-existing formatting violations across
content-access, content-likes, subscription, test-consumer, and treasury.

Closes MyFanss#946
@Xaxxoo Xaxxoo force-pushed the feat/946-creator-earnings-gas-review branch from abdaa48 to 54bb747 Compare May 31, 2026 17:24
@aji70 aji70 merged commit 03fce34 into MyFanss:main May 31, 2026
4 of 16 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.

Contract creator-earnings: Review gas usage for hot paths

2 participants