feat(agent-vault): emit events when assets are added/removed from the whitelist (#37) - #54
Conversation
…on-protocol#37) add_asset() and remove_asset() updated persistent storage with no on-chain event, so indexers/clients had to poll is_supported_asset() to detect whitelist changes. - Add AddAssetEvent and RemoveAssetEvent (#[contractevent], asset as #[topic], plus admin). - add_asset() emits AddAssetEvent after writing to storage. - remove_asset() emits RemoveAssetEvent only when the asset key existed (the remove is otherwise a no-op). - Tests verify both events via env.events().all() (exact topics + data reconstructed from the generated Event impl), and that removing a non-whitelisted asset emits nothing. cargo test (52 passing) and cargo clippy --all-targets -- -D warnings pass.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughTwo new Asset Whitelist Events
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
⚔️ Resolve merge conflicts
Comment |
|
LGTM. Please resolve small conflict in tests @Itodo-S |
Closes #37.
add_asset()andremove_asset()updated the asset whitelist in persistent storage with no on-chain event, forcing indexers/clients to pollis_supported_asset()per token to detect changes.Changes (
contracts/agent-vault/src/lib.rs— onlyadd_asset/remove_asset)add_asset()emitsAddAssetEventafter writing to storage.remove_asset()emitsRemoveAssetEventonly if the asset key existed (the remove is otherwise a no-op), so a no-op remove emits nothing.Tests (
contracts/agent-vault/src/tests.rs)test_add_asset_emits_event— verifiesAddAssetEventviaenv.events().all().test_remove_asset_emits_event— verifiesRemoveAssetEventviaenv.events().all().test_remove_nonexistent_asset_emits_no_event— verifies no event when the asset was never whitelisted.Events are matched exactly (contract id, topics, and data) by reconstructing the expected event through the generated
Eventimpl'stopics()/data(), so the assertions can't drift from the macro output.Acceptance criteria
AddAssetEventandRemoveAssetEventdefined with#[contractevent]add_asset()emitsAddAssetEventafter writing to storageremove_asset()emitsRemoveAssetEventafter removal (only if the key existed)env.events().all()cargo test(52 passing) andcargo clippy --all-targets -- -D warningspassSummary by CodeRabbit
New Features
Tests