test(creator-earnings): review gas usage for hot paths#1277
Merged
Conversation
|
@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! 🚀 |
44fd29c to
abdaa48
Compare
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
abdaa48 to
54bb747
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add seven correctness tests that exercise the three hot execution paths of the
creator-earningscontract (deposit,withdraw,balanceread), 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:
depositwithdrawbalanceTest plan
hot_path_deposit_single_correctness— sender and contract token balances change by the expected deltahot_path_deposit_repeated_accumulates— three successive deposits sum correctlyhot_path_withdraw_correctness— creator and contract balances updated correctlyhot_path_full_withdraw_leaves_zero— full withdrawal empties internal balancehot_path_balance_read_consistent_with_token_client— internal balance matches token client viewhot_path_invalid_amount_rejected_before_transfer— zero amounts rejected before auth/transferhot_path_overdraft_rejected— over-withdrawal rejected, balance unchangedCloses #946