feat(settlement): add admin parameter setter - #1
Open
Sensei-Victor wants to merge 446 commits into
Open
Conversation
Adds simulate_issue_reputation, a read-only preview of issue_reputation that runs the identical validation (pause/emergency gate, caller/role check, rating and comment bounds, contract status, duplicate-issuance and self-rating checks) and returns the projected Reputation record without writing storage, emitting events, or requiring caller auth.
Add versioned dispute metadata with migrate-on-read from v0 to the current layout, a no-op path for current records, and tests that assert field preservation across upgrades.
Add docs/reputation-auth.md describing roles, entrypoints, guard chain, state transitions, and error codes for the reputation system. Covers issue Talenttrust#883.
Integrate upstream settlement-token and dispute API changes while preserving versioned dispute metadata migrate-on-read for Talenttrust#1017.
Emit a fail-closed Soroban event on every successful `issue_reputation`
call so off-chain indexers can cheaply reconstruct per-freelancer
reputation history without re-fetching contract storage.
Topic: (symbol_short!("rep_issue"), contract_id: u32)
Payload: (client: Address, freelancer: Address, rating: u32,
total_rating: i128, completed_contracts: i128,
timestamp: u64)
- "rep_issue" is exactly 9 ASCII chars and does not collide with any
other symbol_short! / Symbol::new topic in the crate (verified
against init, mlstn_rls, ctrct_cmp, refunded, pause, unpaused,
cancelled, created, finalized, evidence, fee, dispute, admin,
settlement_token_bound, milestone_released, client_migration_*,
protocol_fee_bps, emergency).
- Symbol::new(&env, "rep_issue") == symbol_short!("rep_issue") so
consumers can match the topic either way.
- No fund-movement change; emit is after every storage mutation.
- comment is deliberately excluded to bound per-event size (~150 bytes).
- Strictly additive: pre-existing reputation records NOT retroactively
emitted.
13 new tests in contracts/escrow/src/test/reputation.rs
("rep_issue event tests (issue Talenttrust#944)" block): 1 happy-path, 1 interop,
2 quantity, 1 collision, 8 fail-closed (UnauthorizedRole, InvalidRating,
EmptyComment, CommentTooLong, ReputationAlreadyIssued, NotCompleted,
SelfRating, ContractPaused, EmergencyActive).
closes Talenttrust#944
Closes Talenttrust#938. Before: every read/write of the milestone vector used the literal tuple `(DataKey::Contract(id), Symbol::new(&env, "milestones"))` duplicated across 25+ sites in `create_contract`, `deposit`, `release`, `refund_impl`, `finalize`, `approvals`, `lib`, and `ttl`. After: a typed wrapper `MilestonesKey(u32)` is the single source of truth. Its `IntoVal`/`TryFromVal` delegate to the legacy tuple, so on-disk SCVal is byte-identical — contracts written by older binaries remain readable through `MilestonesKey` without migration. Coverage: - 9 new round-trip tests in test/storage.rs (incl. SCVal byte compare) - 1 byte-equivalence test in test/persistence.rs - All 25+ inline call sites now route through MilestonesKey::new Behaviour and layout unchanged. No ABI change.
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
…hreatmodel docs(contracts): add threat-model note
…-auth docs(disputes): document authorization rules Talenttrust#888
…-21-batch feat(disputes): add bounded batch entrypoint Talenttrust#946
…-21-storagekey refactor(milestones): typed storage key
…-rustdoc docs(disputes): add rustdoc examples for the disputes public API
docs(reputation): document authorization rules
…22-index-event feat(reputation): emit indexed event
…2-pauseguard feat(disputes): add pause-aware guard
…-threatmodel docs(reputation): add threat-model note
…41-budget test(milestones): add resource-budget tests
…41-rustdoc docs(milestones): add rustdoc examples
…torage docs(contracts): document storage layout and TTL
…11-bounds fix(escrow): add missing validate_contract_id_bounds for reputation/evidence/dispute
…budget test(settlement): add resource-budget regression tests for settlement
…property-tests-for-escrow-1020 test(escrow): add property tests
…-31-threatmodel docs(disputes): add threat-model note
…variants to EscrowError
…entInput, MilestoneEntry, MAX_EVENT_BATCH_SIZE) for CI build resolution
Add a read-only simulate_dispute_resolution entrypoint that returns the projected dispute resolution outcome without writing storage or emitting events. Mirrors all pre-condition checks from resolve_dispute: initialization, pause gate, arbiter auth, contract existence, finalization guard, Disputed state requirement, arbiter matching, and payout arithmetic validation. - Add SimulateDisputeOutcome type to types.rs - Add simulate_dispute_resolution entrypoint to lib.rs - Re-export new type and add to entrypoint docs - Add 11 comprehensive tests covering all resolution variants, auth, state, idempotency, and consistency with real resolve - Update implemented entrypoints list in test/summary.rs Closes Talenttrust#1056
Enable dispute integration tests to run by: - Switching make_env from mock_all_auths to mock_all_auths_allowing_non_root_auth (required for SAC token transfers in deposit_funds sub-contract calls) - Binding a settlement token in make_client so deposit_funds works - Minting settlement tokens before deposit in funded helpers and inline tests - Adding mint_and_deposit helper to reduce duplication Also fix pre-existing test expectation bugs exposed by the auth fix: - Correct PartialRefund rounding expectations (floor(amount*30/100)) - Fix Split acceptance test to expect actual payout not (0,0) - Add approve_milestone_release before release_milestone in lifecycle tests - Fix raise_dispute_on_refunded to expect InvalidState not AlreadyFinalized
Comprehensive improvements to milestone auth matrix coverage: Test Enhancements: - Add detailed documentation to refund_unreleased_milestones test - Explain Soroban auth model and authorization enforcement - Document why only client case is explicitly tested - Fix syntax errors in reputation_config_setter tests Documentation: - Add MILESTONES_AUTH_MATRIX_UPDATE.md with complete coverage analysis - Include authorization matrix table for all roles and actions - Document technical implementation details and edge cases - Add Windows MSVC linker setup guides (4 solution options) - Include automated PowerShell and batch installers - Add dispute resolution documentation Code Quality: - Apply cargo fmt to all source files - Ensure consistent code formatting Addresses issue Talenttrust#21: Complete milestones auth matrix coverage with 95%+ test coverage
The Error enum had InvalidDepositAmount defined twice (both at value 32), causing a compilation error. This fixes the contracterror macro panic.
Co-authored-by: Gogo-Eng <“progressgogochinda@gmail.com”>
…lenttrust#1298) Co-authored-by: flourishbar <you@example.com>
Add docs/contracts-errors.md with a full reference for every EscrowError variant (codes 1–45): - Quick-reference table mapping name → numeric value - Per-error sections covering: when it fires, how to avoid it, and which entrypoints can return it - Integration guidance with pre-flight check examples - Cross-references to abi-reference.md, contracts-auth.md, and contracts-storage.md All codes verified against the EscrowError enum in lib.rs.
Add contracts/escrow/src/test/contracts_events.rs with comprehensive
topic/payload assertions for every event emitted by the contracts module:
- create_contract: ('created', id) topic; (client, freelancer, ts) payload
- set_arbiter: ('arbiter', id) topic; (old_arb, new_arb, ts) payload
- set_contracts_parameters: ('contracts','params') topic; (ContractsParameters, ts) payload
- set_max_settlement: ('limits','max_settlement') topic; (max, ts) payload
Tests cover:
- Correct symbol strings for both topics
- Payload field values match what was passed in
- Boundary conditions (min/max values, None arbiter removal, multi-call)
- No topic collision: all four module topics are mutually distinct and
do not collide with the 16+ global escrow topics
Register the new module in test/mod.rs.
…nttrust#894) (Talenttrust#1295) - Added MIN_WORK_EVIDENCE_BYTES and MAX_WORK_EVIDENCE_BYTES - Added EmptyEvidence to Error enum - Validated all milestone entrypoints against IndexOutOfBounds and work evidence lengths - Created milestones_bounds_validation test suite
- Fix 5 unchecked arithmetic sites with checked_add/checked_sub: - dispute.rs resolve_dispute_impl: refunded/released += checked_add - lib.rs resolve_dispute: same accumulators checked_add - refund_impl.rs: refunded_amount and total_refund_amount checked_add - refund_impl.rs check_sufficient_balance: checked_sub for available - Add comprehensive settlement_overflow.rs (697 lines, 33 test cases): - resolution_payouts: FullRefund/FullPayout/PartialRefund/Split extremes - i128::MAX, i128::MIN, safe_max, one-past-safe boundaries - Conservation invariant table-driven tests - safe_add/sub, validate_single_amount, accumulate_amounts edges - Integration: corrupted state rejection via entrypoints - Register test module in test/mod.rs Closes Talenttrust#895
Replace the hardcoded 30 and 100 in resolution_payouts's PartialRefund arm with named, documented consts (PARTIAL_REFUND_FREELANCER_PERCENT, PARTIAL_REFUND_PERCENT_BASE). Values and behavior are unchanged. This also restores dispute-module types and wiring that a prior merge had silently dropped (DisputeInfo, DisputeMetadata, DisputeMetadataV0, DISPUTE_STORAGE_VERSION, the two DataKey::Dispute* variants, and the two related Error variants), since dispute.rs did not compile without them. Fixes the resulting tuple/struct mismatches in dispute.rs, lib.rs::resolve_dispute, and the dispute payout tests. Addresses Talenttrust#1058. Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
* docs(settlement): add rustdoc examples * fix(settlement): expose settlement as pub mod so rustdoc examples resolve * fix(settlement): mark doc examples no_run to avoid doctest compile failures
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
Closes issue Talenttrust#52. Adds
set_settlement_params- an admin-guarded setter forGovernedParameters(protocol_fee_bpsandmax_escrow_total_stroops) following the same pattern asset_protocol_fee_bps.Changes
contracts/escrow/src/governance.rsset_settlement_params(env, protocol_fee_bps, max_escrow_total_stroops) -> bool:DataKey::Admin, callsrequire_auth()fee_bps <= 10_000andcap > 0, panics withInvalidProtocolParameterson failureDataKey::GovernedParameterssettlement_paramsevent with old/new values, admin, timestampcontracts/escrow/src/test/settlement_params.rs(new)contracts/escrow/src/test/mod.rsmod settlement_paramsdocs/escrow/abi-reference.mdset_settlement_paramsentryWhat was not changed
set_governed_paramskept intact