test: enforce strict soroban compute budget assertions - #88
Merged
Conversation
Add explicit CPU instruction and memory ceilings for every state-changing entry point (create_escrow, lock_funds, release_funds, refund, resolve_dispute) using env.cost_estimate().budget(). Each test prints the metered cost via budget().print() and fails if usage regresses past a calibrated threshold, well before the transaction-level Mainnet limits would be hit. Includes a dummy contract with a deliberately heavy loop to prove the assertion mechanism actually fails when resource usage exceeds the ceiling. Closes Padi-Pay#72
3 tasks
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.
Description
Adds explicit Soroban compute budget assertions so the test suite fails aggressively if any contract entry point's CPU instructions or memory usage regresses past a safe, calibrated threshold — long before it could hit Mainnet's transaction resource limits.
Every state-changing entry point (
create_escrow,lock_funds,release_funds,refund,resolve_dispute) is measured withenv.cost_estimate().budget(), prints its metered cost viabudget().print()so usage is visible in CI logs/PR reviews, and asserts it stays under a ceiling calibrated with ~2-2.5x headroom over measured usage (still far below Mainnet's 600M instruction / ~42MB memory limits).A standalone dummy contract with a deliberately heavy hashing loop is included to prove the assertion mechanism actually fails when usage exceeds the ceiling, rather than trivially passing.
Type of Change
Testing
cargo test— all 65 existing tests + 6 new budget tests passcargo fmt --all -- --checkandcargo clippy --all-targets --all-features -- -D warnings— cleancargo build --target wasm32v1-none --release— builds successfullycargo test --test budgetin isolation confirmstest_budget_assertion_catches_heavy_loop(#[should_panic]) proves the ceiling assertion actually fires on a resource-heavy workloadCloses #72
Checklist
cargo fmtrun)cargo testpasses