Skip to content

Smart account: policy events#616

Open
brozorec wants to merge 5 commits intomainfrom
smart-accounts-events
Open

Smart account: policy events#616
brozorec wants to merge 5 commits intomainfrom
smart-accounts-events

Conversation

@brozorec
Copy link
Collaborator

@brozorec brozorec commented Mar 12, 2026

Fixes #613

PR Checklist

  • Tests
  • Documentation

Summary by CodeRabbit

  • Documentation

    • Updated build command instructions for contract deployment
  • New Features

    • Policy lifecycle events now emitted for auditing and monitoring installation, configuration changes, and removal across all policy types
  • Improvements

    • Simplified policy addition API by removing unnecessary parameters
  • Tests

    • Added assertions to verify policy event emissions

@brozorec brozorec self-assigned this Mar 12, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 12, 2026

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2b00fafa-90f1-4bfd-9a82-49fc6861fc45

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

The PR adds contract events for policy lifecycle management (install, uninstall, and configuration changes) across three policy implementations. It removes the install_param field from the PolicyAdded event in the smart account module for consistency, and adds test assertions to verify event emissions during policy operations.

Changes

Cohort / File(s) Summary
Documentation
examples/multisig-smart-account/README.md
Updated build command from cargo build --target wasm32v1-none --release to stellar contract build.
Policy Trait Documentation
packages/accounts/src/policies/mod.rs
Added event documentation to the Policy trait's install and uninstall functions, including policy-installed and policy-uninstalled event conventions and rollback behavior notes.
Simple Threshold Policy Events
packages/accounts/src/policies/simple_threshold.rs, packages/accounts/src/policies/test/simple_threshold.rs
Introduced SimplePolicyInstalled, SimpleThresholdChanged, and SimplePolicyUninstalled event structs; added event emissions in set_threshold, install, and uninstall functions; added test assertions verifying exact event counts.
Spending Limit Policy Events
packages/accounts/src/policies/spending_limit.rs, packages/accounts/src/policies/test/spending_limit.rs
Introduced SpendingLimitInstalled, SpendingLimitChanged, and SpendingLimitUninstalled event structs; added event emissions in lifecycle functions; added test assertions for event emission verification.
Weighted Threshold Policy Events
packages/accounts/src/policies/weighted_threshold.rs, packages/accounts/src/policies/test/weighted_threshold.rs
Introduced WeightedPolicyInstalled, WeightedThresholdChanged, WeightedSignerWeightChanged, and WeightedPolicyUninstalled event structs; added event emissions in set_threshold, set_signer_weight, install, and uninstall; added test assertions for event counts.
Smart Account Event Refactoring
packages/accounts/src/smart_account/mod.rs, packages/accounts/src/smart_account/storage.rs
Removed install_param field from PolicyAdded event struct and its emission; updated add_policy and emit_policy_added function signatures to remove the install_param parameter; updated PolicyAdded struct to derive Eq and PartialEq.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~18 minutes

Possibly related PRs

  • Update to soroban-sdk v25 #559: Relates to contract event surface updates and test migrations for event emission assertions across multiple policy implementations.

Suggested reviewers

  • ozgunozerk

Poem

🐰 Events now bloom in each policy's life,
Install, uninstall, through ledger's night,
Each threshold and limit now sings its song,
Smart accounts listen all along! 🌟
No install\_params cluttering the way,
Just ids and events, pure and clear today.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Smart account: policy events' clearly and concisely summarizes the main change: adding event functionality to smart account policies.
Description check ✅ Passed The description adequately references the linked issue (#613) and marks both Tests and Documentation as complete via the checklist, meeting template requirements.
Linked Issues check ✅ Passed The PR fully implements all coding requirements from issue #613: adds install/uninstall events to all policy implementations, removes install_param from smart account events, and adds Policy trait docstrings.
Out of Scope Changes check ✅ Passed All changes directly support the linked issue objectives; the build command update in README.md is a minor documentation fix incidental to the main scope.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch smart-accounts-events
📝 Coding Plan for PR comments
  • Generate coding plan

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link

codecov bot commented Mar 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.41%. Comparing base (263d86b) to head (11f2075).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #616      +/-   ##
==========================================
+ Coverage   96.37%   96.41%   +0.03%     
==========================================
  Files          58       58              
  Lines        5960     6021      +61     
==========================================
+ Hits         5744     5805      +61     
  Misses        216      216              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🧹 Nitpick comments (1)
packages/accounts/src/policies/test/weighted_threshold.rs (1)

64-65: Assert the installed event payload, not just the total count.

len() == 1 only proves that some event was emitted in this test path. It will not catch a wrong topic or wrong payload, which is the contract this PR is changing. Snapshot the count before install, then assert the appended event matches WeightedPolicyInstalled.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/accounts/src/policies/test/weighted_threshold.rs` around lines 64 -
65, Before calling install in the test, capture the current event count from
e.events().all().events().len(), then call the install path and assert that
exactly one new event was appended; retrieve the newly appended event from
e.events().all().events()[old_len] and assert its topic/variant and payload
equal the expected WeightedPolicyInstalled (check the event's discriminant and
the contained payload fields); update the assertion in weighted_threshold.rs to
validate the specific event type and payload rather than only checking len() ==
1.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/accounts/src/policies/test/simple_threshold.rs`:
- Around line 60-61: The assertions currently assume a fresh event list but Env
event storage is cumulative (e.events().all().events()), so save the pre-call
count (e.g., let before = e.events().all().events().len()) before calling
install/uninstall and assert against before + 1 (or appropriate delta), or
alternatively inspect the tail event directly via
e.events().all().events().last().unwrap() and match its type; also update the
enforce_success check (the code referencing enforce_success) to use the same
saved pre-call count logic so it asserts the delta rather than assuming a
single-event-only Env.

In `@packages/accounts/src/policies/test/spending_limit.rs`:
- Around line 80-81: The test is asserting the global event count via
e.events().all().events().len(), which is cumulative across the Env and makes
the assert in uninstall_success brittle; instead record the event count before
the action (let before = e.events().all().events().len()), perform the
uninstall/install action, then assert the delta
(assert_eq!(e.events().all().events().len() - before, 1)) so you verify
per-action events; apply the same change to the other similar assertion(s)
around lines 446-447 that use e.events().all().events().len().

In `@packages/accounts/src/policies/test/weighted_threshold.rs`:
- Around line 446-447: The test asserts a fixed total event count
(assert_eq!(e.events().all().events().len(), 1)) which is brittle because the
policy was installed earlier; instead, record the event count before calling
uninstall (let before = e.events().all().events().len()), perform the uninstall,
then get the new count and assert new_count == before + 1, and finally assert
that the newly appended event (e.events().all().events().last().unwrap()) is the
WeightedPolicyUninstalled variant to verify the correct event was emitted.

In `@packages/accounts/src/policies/weighted_threshold.rs`:
- Around line 531-538: Check whether the policy state exists before removing and
only publish WeightedPolicyUninstalled when an actual stored entry was removed:
look up the storage key constructed with
WeightedThresholdStorageKey::AccountContext(smart_account.clone(),
context_rule.id), call e.storage().persistent().get/remove in a way that detects
existence (e.g., remove returns Option or check get first), and only invoke
WeightedPolicyUninstalled { smart_account: smart_account.clone(),
context_rule_id: context_rule.id }.publish(e) if the stored entry was present;
do not publish when nothing was removed.

---

Nitpick comments:
In `@packages/accounts/src/policies/test/weighted_threshold.rs`:
- Around line 64-65: Before calling install in the test, capture the current
event count from e.events().all().events().len(), then call the install path and
assert that exactly one new event was appended; retrieve the newly appended
event from e.events().all().events()[old_len] and assert its topic/variant and
payload equal the expected WeightedPolicyInstalled (check the event's
discriminant and the contained payload fields); update the assertion in
weighted_threshold.rs to validate the specific event type and payload rather
than only checking len() == 1.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d3ec2a12-5812-4454-8f8a-bc9ecdc3f4bf

📥 Commits

Reviewing files that changed from the base of the PR and between 263d86b and a7b7ff1.

📒 Files selected for processing (10)
  • examples/multisig-smart-account/README.md
  • packages/accounts/src/policies/mod.rs
  • packages/accounts/src/policies/simple_threshold.rs
  • packages/accounts/src/policies/spending_limit.rs
  • packages/accounts/src/policies/test/simple_threshold.rs
  • packages/accounts/src/policies/test/spending_limit.rs
  • packages/accounts/src/policies/test/weighted_threshold.rs
  • packages/accounts/src/policies/weighted_threshold.rs
  • packages/accounts/src/smart_account/mod.rs
  • packages/accounts/src/smart_account/storage.rs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Smart Accounts: events consistency on install/uninstall policies

1 participant