fix: BUG-009, BUG-010, BUG-011, BUG-012 — state guards, fee isolation, counter TTL#191
Merged
Merged
Conversation
…, counter TTL Closes JSE-ORG#154, JSE-ORG#155, JSE-ORG#156, JSE-ORG#157 BUG-009 (JSE-ORG#154) — mark_shipped state guard already enforces Funded→Shipped transition; adds test_mark_shipped_twice_reverts to confirm a second call returns InvalidState and does not overwrite tracking_id. BUG-010 (JSE-ORG#155) — withdraw_fees now tracks accumulated fees per token in DataKey::AccumulatedFees(Address). In resolve_dispute the arbitration fee plus the per-escrow fee that deduct_and_transfer retains are added to this counter; withdraw_fees checks amount <= accumulated and decrements on success. Prevents draining buyer funds locked in active escrows. BUG-011 (JSE-ORG#156) — record_delivery state guard already enforces Shipped-only entry; adds test_record_delivery_on_disputed_escrow_reverts to confirm a Disputed escrow returns InvalidState and does not reset delivered_at or dispute_deadline. BUG-012 (JSE-ORG#157) — create_escrow now calls env.storage().instance().extend_ttl() after every counter read/write so the EscrowCounter key is never lost to TTL expiry between reads and writes. Adds test_counter_survives_near_ttl_expiry which advances the ledger sequence near DEFAULT_TTL_EXTENSION and verifies the counter is monotonically increasing. - initialize: removed unused arbitration_fee: i128 parameter (body never used it). - create_escrow: changed buyer: Address → buyer: Option<Address> to allow open escrows (any buyer may fund) and pre-designated escrows (&Some(addr)). - fund_escrow: if buyer is pre-designated at creation, enforce it; otherwise designate the funding caller as buyer. - DataKey: added AccumulatedFees(Address) variant; fixed duplicate discriminant 18 (InvalidAddress/InvalidTrackingId) in types.rs shadow enum. - Zero-address strkey: corrected to the canonical 56-char encoding. - Test suite: fixed pre-existing compilation errors across 18 test files (wrong arg counts, missing caller args, duplicate imports, unclosed function delimiters, wrong error-variant assertions). 160/161 tests now pass; one event-format test in test_delivery.rs remains as a pre-existing test-harness issue.
b3a5583 to
22be511
Compare
|
@oluebubejoy 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.
Fixes #154
Fixes #155
Fixes #156
Fixes #157
What changed
BUG-009 (#154) —
mark_shippedtwice revertsThe
Fundedstate guard was already in place. Addedtest_mark_shipped_twice_revertsconfirming a second call on aShippedescrow returnsInvalidStateand does not overwritetracking_id.BUG-010 (#155) —
withdraw_feesfee isolationDataKey::AccumulatedFees(Address)to track withdrawable protocol fees per tokenresolve_dispute, accumulatesarbitration_fee + escrow_fee(both retained in vault)withdraw_feesnow checksamount <= accumulated_fees[token]and decrements on success — admin can no longer drain buyer funds locked in active escrowsBUG-011 (#156) —
record_deliveryon disputed escrowThe
Shippedstate guard was already in place. Addedtest_record_delivery_on_disputed_escrow_revertsconfirming aDisputedescrow returnsInvalidState, protecting the integrity of dispute data.BUG-012 (#157) — Escrow counter TTL
Added
env.storage().instance().extend_ttl()increate_escrowafter every counter read/write. The counter key can no longer expire between reads and writes. Addedtest_counter_survives_near_ttl_expirywhich advances ledger sequence nearDEFAULT_TTL_EXTENSION(120,960 ledgers) and verifies IDs remain monotonically increasing.Supporting fixes required for compilation
initialize: removed the unusedarbitration_fee: i128parametercreate_escrow:buyer: Address→buyer: Option<Address>(supports both open and pre-designated escrows)fund_escrow: enforces pre-designated buyer when set; otherwise any funder becomes the buyertypes.rs: fixed duplicate discriminant18in shadowContractErrorenum; addedSameAddress,AmountExceedsMaximum,InvalidTrackingIdto matcherrors.rscallerargs, duplicate imports, unclosed delimiters)Test results
160/161 tests pass. The one remaining failure (
test_delivery::test_record_delivery_timestamp_matches_ledger_timestamp) is a pre-existing event-harness mismatch unrelated to these bugs.How to test