Add structured events for rate limiting triggers and multi-sig contract upgrade tests#374
Open
EmeditWeb wants to merge 3 commits into
Open
Conversation
- Add emit_global_rate_limit_exceeded event (rl_gexcd) when global limit hit - Add emit_address_rate_limit_exceeded event (rl_aexcd) when address limit hit - Add emit_global_rate_limit_set event (rl_gset) when global limit configured - Add emit_address_rate_limit_set event (rl_aset) when address limit configured - Emit events from internal_check_rate_limit, internal_set_global_rate_limit, internal_set_address_rate_limit - Add 6 unit tests covering all event types, edge cases, and window reset Closes BCPathway#326
- Add set_admin_pool, get_admin_pool, get_threshold for multi-sig admin pool management - Add propose_upgrade(caller, desc, hash) for creating upgrade proposals - Add approve_upgrade(caller, proposal_id) for pool members to approve upgrades - Add execute_upgrade(proposal_id) to execute approved proposals - Add upgrade(hash) for direct admin upgrade (bypasses multi-sig) - Fix admin module proposal TTL extension (instance vs persistent storage mismatch) - Add 20 unit tests covering happy paths, edge cases, and expected failures - Guard update_current_contract_wasm with cfg!(not(test)) to avoid test env crash
|
@EmeditWeb 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! 🚀 |
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.
Summary
This PR adds two features: rate-limit structured events and multi-sig contract upgrade tests for the bc-forge token contract.
Closes #325
Rate-Limit Events
New Event Types
emit_global_rate_limit_exceededrl_gexcdemit_address_rate_limit_exceededrl_aexcdemit_global_rate_limit_setrl_gsetemit_address_rate_limit_setrl_asetEvent Data Schemas
(admin, leader, requested, current_window, current_volume, limit)(admin, target, leader, requested, current_window, current_volume, limit)(admin, limit, window)(admin, target, limit, window)Rate-limit exceeded events are split into global (
rl_gexcd) and address-specific (rl_aexcd) variants to avoidOption<Address>in event data.Tests
Multi-Sig Contract Upgrades
New Token Contract Functions
set_admin_pool(pool, threshold)get_admin_pool() -> Vec<Address>[admin])get_threshold() -> u32propose_upgrade(caller, description, new_wasm_hash) -> u64approve_upgrade(caller, proposal_id)execute_upgrade(proposal_id)upgrade(new_wasm_hash)Governance Flow
set_admin_poolpropose_upgrade(creator is auto-approved)approve_upgradeto add approvalsexecute_upgradeto update the contract WASMBug Fix: Admin Module Proposal TTL
Removed invalid
extend_storage_ttl_for_keycalls in the admin module'screate_proposal,approve_proposal,is_proposal_ready, andmark_executedfunctions. These were callingpersistent().extend_ttl()for keys stored in instance storage, causingError(Storage, MissingValue)at runtime.Tests (20 total)
Proposal lifecycle:
test_propose_upgrade_happy_path— basic proposal creation returns ID 0test_propose_upgrade_non_admin_fails— non-pool-member cannot proposetest_approve_upgrade_happy_path— pool member can approvetest_approve_upgrade_double_approval_fails— duplicate approval rejectedtest_approve_upgrade_non_pool_member_fails— random address cannot approvetest_execute_upgrade_full_multi_sig_flow— propose, approve, execute (2-of-3 threshold)test_execute_upgrade_single_admin_pool— single-pool-member upgradetest_execute_upgrade_insufficient_approvals_fails— threshold not mettest_execute_upgrade_double_execution_fails— cannot execute twicetest_approve_after_execute_fails— cannot approve after executiontest_execute_upgrade_nonexistent_proposal_fails— invalid proposal IDEdge cases:
test_multiple_proposals_independent— independent proposal IDs and hash storagetest_propose_approve_execute_different_admins— different pool members propose, approve, executetest_admin_pool_can_include_multiple_members— pool with 6 members, threshold 3test_get_admin_pool_before_set— falls back to[admin]test_get_threshold_before_set— defaults to 1test_set_admin_pool_zero_threshold_fails— threshold 0 rejectedtest_set_admin_pool_threshold_exceeds_pool_fails— threshold > pool size rejectedDirect upgrade:
test_upgrade_direct_single_admin— single admin direct upgradetest_upgrade_before_init_fails— upgrade on uninitialized contract failstest_direct_upgrade_after_multi_sig_setup— direct upgrade still works after multi-sig setuptest_upgrade_hash_stored_per_proposal— each proposal stores its own WASM hashTest Workaround
update_current_contract_wasmcrashes the Soroban SDK test environment duringEnvcleanup (panic-in-destructor). Theperform_wasm_updatehelper guards the call withcfg!(not(test)), making it a no-op in unit tests so governance logic can be fully tested.Files Changed
contracts/rate-limit/src/lib.rscontracts/token/src/lib.rscontracts/token/src/test.rscontracts/admin/src/lib.rsVerification
cargo test -p bc-forge-token -p bc-forge-rate-limit— 32 tests pass (6 rate-limit + 26 token)cargo clippy— no new warningscargo fmt --check— clean