Skip to content

tests: add Soroban budget profiling to SmartAccount tests#81

Open
alberto-crossmint wants to merge 1 commit intomainfrom
devin/1756171985-budget-profiling-tests
Open

tests: add Soroban budget profiling to SmartAccount tests#81
alberto-crossmint wants to merge 1 commit intomainfrom
devin/1756171985-budget-profiling-tests

Conversation

@alberto-crossmint
Copy link
Contributor

@alberto-crossmint alberto-crossmint commented Aug 26, 2025

tests: add Soroban budget profiling to SmartAccount tests

Summary

Integrates budget profiling into unit tests that invoke SmartAccount contract functions to track CPU instructions and memory bytes consumed during contract execution. Adds budget snapshot utilities and instruments key contract operations across auth, plugin, policy, and signer management tests.

Changes:

  • Added BudgetSnapshot struct and helper functions (budget_snapshot, print_budget_delta) in test_utils.rs
  • Instrumented __check_auth calls in auth_test.rs to measure authorization overhead
  • Added profiling around plugin operations (install_plugin, uninstall_plugin) in plugin_test.rs
  • Instrumented signer management operations (add_signer, revoke_signer, update_signer) in signer_management_test.rs
  • Added budget tracking for policy-related operations in policy_test.rs

Example budget output:

[Budget] check_auth cpu_insns=333000 mem_bytes=0
[Budget] install_plugin cpu_insns=28128 mem_bytes=5510
[Budget] uninstall_plugin cpu_insns=55619 mem_bytes=7980
[Budget] add_signer:admin3 cpu_insns=1092 mem_bytes=704

Review & Testing Checklist for Human

  • Verify Soroban SDK budget API usage: Confirm env.cost_estimate().budget(), cpu_instruction_cost(), and memory_bytes_cost() are correct for soroban-sdk v22 (API was debugged during implementation but should be double-checked)
  • Run tests locally: Execute cargo test -- --nocapture and verify budget output lines appear and show reasonable CPU/memory numbers
  • Spot check budget measurements: Review a few "[Budget]" output lines to ensure values make sense relative to operation complexity

Notes

… around contract calls

Co-Authored-By: Alberto García <alberto@paella.dev>
@devin-ai-integration
Copy link
Contributor

Original prompt from Alberto
The task is to integrate budget profiling into unit tests that call contract functions. This will allow for granular profiling of CPU and memory consumption using the Soroban Rust SDK's budget utilities.

- For unit tests that invoke contract functions, add code to query or print the budget.
- Utilize `env.cost_estimate().budget()` or `env.budget()` (for older versions) to access the budget tracker.
- The goal is to record and display CPU instructions and bytes of memory used by contract calls.

To submit the work, ensure the changes are applied to the relevant unit test files within the stellar-smart-account repository in the smart account contract. Provide a report detailing the files modified and an example of the budget output.

You only need to look in the following repo: Crossmint/stellar-smart-account

@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

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.

1 participant