feat: add instructions_used() budget probe helper and regression test for instruction budget#1679
Merged
Merged
Conversation
… for instruction budget
|
@Opulencechuks 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! 🚀 |
Contributor
|
add instructions_used() budget probe helper and regression test for instruction budget — solid — merging 👍 |
5 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.
This PR closes #1568
📝 Description
Adds a budget probing helper
instructions_used()and comprehensive instruction‑budget regression tests for theaccept_bid_and_fundentry‑point. The new helper makes it easy to assert CPU‑instruction usage directly from tests, while the added test suite guards against future regressions in instruction consumption.🎯 Type of Change
🔧 Changes Made
bench::instructions_used(&Env) -> u64to expose the number of CPU instructions used.src/bench.rswith documentation and the new helper.src/test_accept_bid_instruction_budget.rs:Files Modified
quicklendx-contracts/src/bench.rsquicklendx-contracts/src/test_accept_bid_instruction_budget.rsNew Files Added
Key Changes
pub fn instructions_used(env: &Env) -> u64returningenv.cost_estimate().resources().instructions as u64.< 10 000).🧪 Testing
Test Coverage
accept_bid_and_fundcompletes within the instruction budget when the invoice holds the maximum number of active bids (MAX_BIDS_PER_INVOICE = 50).All tests invoke
bench::instructions_used(&env)and assert the count is below10_000(well under Soroban’s instruction limit).📋 Contract‑Specific Checks
cargo build --target wasm32-unknown-unknown).Contract Testing Details
quicklendx-contractscrate targetingwasm32-unknown-unknown.mainbranch and fail (instruction count exceeds threshold) on the previous commit, confirming they act as a regression guard.📋 Review Checklist
expect).🔍 Code Quality
rustfmtstandards.///comments.🚀 Performance & Security
📚 Documentation
cargo doc) now includesinstructions_used.🔗 Related Issues
Closes #
<!-- issue number -->Fixes #
<!-- if applicable -->Related to #
<!-- if applicable -->📋 Additional Notes
instructions_usedhelper is compiled only under#[cfg(any(test, feature = "testutils"))], so it does not affect production builds.10_000instructions) is comfortably below Soroban’s default budget, providing a safety margin while still catching regressions.🧪 How to Test
cargo test -p quicklendx-contractstest_accept_bid_instruction_budget_full_capacity,test_accept_bid_instruction_budget_quarter_capacity,test_accept_bid_instruction_budget_single_bid) pass.📸 Screenshots (if applicable)
No UI changes – none required.
None. The new helper is test‑only and does not affect contract ABI or runtime behavior.
🔄 Migration Steps (if applicable)
No migration required.
📋 Reviewer Checklist
Code Review
Contract Review
Documentation Review
Testing Review