Skip to content

test(drive-abci): cover name price updates at the limits of the recorded price - #5966

Closed
QuantumExplorer wants to merge 1 commit into
v5.1-devfrom
claude/serene-euler-e9f6d1
Closed

QuantumExplorer wants to merge 1 commit into
v5.1-devfrom
claude/serene-euler-e9f6d1

Conversation

@QuantumExplorer

@QuantumExplorer QuantumExplorer commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Basic explanation

What this does: Adds four tests around setting a sale price on a DPNS name. The domain type records every price in the document history system contract, and these tests cover a price update at the largest price that record holds, the next update after it, an update at zero, and a price above that largest value.

Value: The results of these cases were not covered by any test. They are now pinned at protocol versions 13, 14 and the latest, so any later change to how a price update is validated or recorded shows up as a test change instead of going unnoticed.

Risks: Low. Test code only, in one file; no consensus, storage or API change. The tests state today's results, so a later change to this behaviour has to update them.

Issue being fixed or feature implemented

Price updates on a document type that keeps pricing history had no test at the ends of the price range.

What was done?

  • Added helpers to dpns_username_transfer_tests in packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/document/dpns.rs that sign a price update for an identity's name and run it through check_tx and a block, returning what check_tx said, the execution result and what the seller was charged.
  • Added should_end_a_listing_as_an_internal_error_once_the_listed_price_sum_is_full for the latest protocol version, with _protocol_version_14 and _protocol_version_13 twins.
  • Added should_end_a_listing_above_the_signed_range_as_an_internal_error.

How Has This Been Tested?

cargo test -p drive-abci --lib should_end_a_listing

4 passed. cargo fmt --all leaves the tree unchanged.

Breaking Changes

None.

Checklist:

  • I have performed a self-review of my own code
  • My Rust, FFI, WASM, Swift or Kotlin changes follow the coding conventions
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed
  • If I added or changed GroveDB structure, I described it in the area's structure.rs, regenerated grovedb-structure.json, and checked the structure viewer link posted on this pull request
  • If I added or changed a system contract's document schemas, I checked the contract viewer link posted on this pull request

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

🤖 Generated with Claude Code

PR Hygiene · 5dd953e

  • Bots — thepastaclaw ✓
  • Self-review — post /self-reviewed
  • Build green
  • Approvals — you own every area touched; none needed

When every merge requirement is met, the PR Hygiene check passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.

…ded price

Adds four tests of a price update on a DPNS name, whose type records each
price in the document history contract: at the largest price the record
holds, after it, at zero, and above it. They pin today's results at protocol
versions 13, 14 and the latest, so a later change to them shows up in a test.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 14 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 9da740b and 5dd953e.

Files selected for processing: 1

  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/document/dpns.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions github-actions Bot added this to the v5.1.0 milestone Nov 17, 2026
@thepastaclaw

thepastaclaw commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Final review complete — no blockers (commit 5dd953e) · triage: low

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@github-actions github-actions Bot added the waiting-bots Waiting for the review bots to report on this head label Nov 17, 2026

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Final validation — Phase 1 + Phase 2

The change is a focused, deterministic test-only addition covering DPNS price-history boundaries across protocol versions, with no production or consensus implementation changes. Four minor test-quality improvements remain; no blocking defect was found, and the CI snapshot shows no failed code checks, although runner selection and review checks are still pending.

🟡 3 suggestion(s)

Approved: nothing here blocks the merge. The non-blocking findings are optional: fix them forward, in this PR or a follow-up, without waiting for another review round.

Review provenance

Source: reviewer 1: glm-5.3-flash (agent: phase1-reviewer, role: general); reviewer 2: glm-5.3-flash (agent: phase1-reviewer, role: rust-quality); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 4: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 5: gpt-6.1-sol (agent: phase2-reviewer, role: platform-versioning); reviewer 6: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: low by gpt-6.1-sol (effort low) — This is a contained Rust test-only addition in one file with no production behavior, consensus, storage, or API changes, and its correctness is straightforward to verify from the test coverage.
  • Phase 1 reviewers: glm-5.3-flash — general (completed, effort high); agent phase1-reviewer, glm-5.3-flash — rust-quality (completed, effort high); agent phase1-reviewer
  • Phase 1 model: glm-5.3-flash — zai quota: 5h 99% left, weekly 98% left; passed over gemini-3.8-flash-high (antigravity quota lookup failed)
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort medium); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort medium); agent phase2-reviewer, gpt-6.1-sol — platform-versioning (completed, effort medium); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort medium); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.

In `packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/document/dpns.rs`:
- [SUGGESTION] packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/document/dpns.rs:3484-3493: Use the dedicated sum helper for listed_price_sum
  `listed_price_sum` is documented and used as a sum accessor, but it calls the average helper and discards the count with `.1`. The module already provides `history_aggregate_price_sum` for this exact query, so using it avoids an unnecessary count aggregation and makes the assertion's intent explicit.
- [SUGGESTION] packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/document/dpns.rs:3433: Do not let saturating_sub hide an unexpected balance increase
  The helper uses `saturating_sub` to calculate the charge. If a regression credited the seller instead of charging them, the result would also be zero and the refused-listing assertion would pass. A checked subtraction makes an unexpected balance increase fail immediately instead of masking it.
- [SUGGESTION] packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/document/dpns.rs:3571-3575: Assert the zero-price listing's check_tx result and aggregate effect
  The zero-price case is described as both successfully recorded and as adding nothing to the history sum, but it currently asserts only block success and a positive charge. It also ignores the `check_tx` result returned by the helper. Asserting both values would pin the complete behavior claimed by the test and catch a future check_tx/execution divergence.
Out-of-scope follow-up suggestions (1)

These are valid observations, but they are outside this PR's scope and should be handled in separate issues or author/maintainer-requested PRs rather than blocking this review.

  • Price-history sums can permanently reject later positive listings — Once the document-history priceUpdate aggregate reaches i64::MAX, a later positive price update can pass check_tx but fail during operation conversion as an internal error, without charging the seller or advancing the nonce. Because the history aggregate is retained, the contract remains unable to record later positive prices. The tests correctly document this existing behavior but do not introduce it.
    • Follow-up: Add a protocol-versioned state-validation guard or equivalent user-facing handling for document price updates that would overflow the history sum, and audit the token-history set-price path for the same condition.

Comment on lines +3484 to +3493
history_aggregate_price_average(
platform,
"priceUpdate",
vec![
history_where_by_contract(dpns_contract.id()),
history_where_created_between(0, 9_999_999_999_999),
],
platform_version,
)
.1

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🟡 Suggestion: Use the dedicated sum helper for listed_price_sum

listed_price_sum is documented and used as a sum accessor, but it calls the average helper and discards the count with .1. The module already provides history_aggregate_price_sum for this exact query, so using it avoids an unnecessary count aggregation and makes the assertion's intent explicit.

Suggested change
history_aggregate_price_average(
platform,
"priceUpdate",
vec![
history_where_by_contract(dpns_contract.id()),
history_where_created_between(0, 9_999_999_999_999),
],
platform_version,
)
.1
history_aggregate_price_sum(
platform,
"priceUpdate",
vec![
history_where_by_contract(dpns_contract.id()),
history_where_created_between(0, 9_999_999_999_999),
],
platform_version,
)

source: glm-5.3-flash (phase1-reviewer: general, rust-quality)

ListingOutcome {
check_tx_valid,
result: processing_result.into_execution_results().remove(0),
charged: balance_before.saturating_sub(balance(platform)),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🟡 Suggestion: Do not let saturating_sub hide an unexpected balance increase

The helper uses saturating_sub to calculate the charge. If a regression credited the seller instead of charging them, the result would also be zero and the refused-listing assertion would pass. A checked subtraction makes an unexpected balance increase fail immediately instead of masking it.

Suggested change
charged: balance_before.saturating_sub(balance(platform)),
charged: balance_before
.checked_sub(balance(platform))
.expect("the seller's balance must never grow from a price update"),

source: glm-5.3-flash (phase1-reviewer: general, rust-quality)

Comment on lines +3571 to +3575
assert_matches!(
free.result,
StateTransitionExecutionResult::SuccessfulExecution { .. }
);
assert!(free.charged > 0);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🟡 Suggestion: Assert the zero-price listing's check_tx result and aggregate effect

The zero-price case is described as both successfully recorded and as adding nothing to the history sum, but it currently asserts only block success and a positive charge. It also ignores the check_tx result returned by the helper. Asserting both values would pin the complete behavior claimed by the test and catch a future check_tx/execution divergence.

Suggested change
assert_matches!(
free.result,
StateTransitionExecutionResult::SuccessfulExecution { .. }
);
assert!(free.charged > 0);
assert_eq!(free.check_tx_valid, Ok(true));
assert_matches!(
free.result,
StateTransitionExecutionResult::SuccessfulExecution { .. }
);
assert!(free.charged > 0);
assert_eq!(
listed_price_sum(&platform, &dpns_contract, platform_version),
i64::MAX,
"the zero listing added nothing to the recorded sum"
);

source: glm-5.3-flash (phase1-reviewer: general, rust-quality)

@github-actions

Copy link
Copy Markdown
Contributor

Bots are done — your move: post /self-reviewed.
Full checklist in the description.

@github-actions github-actions Bot added waiting-self-review Waiting for the author to post /self-reviewed and removed waiting-bots Waiting for the review bots to report on this head labels Nov 17, 2026
@QuantumExplorer

Copy link
Copy Markdown
Member Author

Superseded by #5987, which carries these tests and extends them.

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

Labels

waiting-self-review Waiting for the author to post /self-reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants