Skip to content

test: cover the contest precheck mapping and the masternode balance read - #1489

Merged
llbartekll merged 1 commit into
developfrom
test/platform-refusal-followup-tests
Nov 24, 2026
Merged

llbartekll merged 1 commit into
developfrom
test/platform-refusal-followup-tests

Conversation

@llbartekll

@llbartekll llbartekll commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Issue being fixed or feature implemented

Follow-up to #1476. Its review deferred two test gaps:

  • UsernameMarketplaceService.contestPrecheck(label:) had no unit test. refactor: recognize Platform refusals by consensus code in one table #1476 made every query failure .unknown (which blocks "Continue" on the create-username screen), and the mapping could not be called without SwiftDashSDKHost.shared.sdk.
  • MasternodeClaimableBalanceTests fed dictionaries to resolve but never exercised the fetchBalances(ids:) path that the masternode screens' balance and Withdraw button depend on.

What was done?

Two minimal seams, no behaviour change:

  • UsernameMarketplaceService.contestPrecheck(voteState:): a pure function from the vote-state answer (or its failure) to ContestPrecheck. contestPrecheck(label:) calls it and, as before, asks the current-contests listing for the deadline only when a contest is active. The pure function reports an active contest with no deadline.
  • MasternodeClaimableBalance.fetch(identityId:fetchBalances:): the batch read is passed in. fetch(sdk:identityId:) hands it sdk.identities.fetchBalances(ids:).

Tests:

  • New UsernameContestPrecheckTests (5 tests): no contenders → .fresh; winner "LOCKED" → .locked; winner an identity id → .locked; contenders with no winner → .activeContest with their count; a failed query → .unknown, including failures whose text reads "not found" / "no contest". Payloads go through JSONSerialization, as in the SDK.
  • 3 new tests in MasternodeClaimableBalanceTests: credits, no identity (missing entry and entry with no balance), and a failed read let through as an error.

How Has This Been Tested?

  • UsernameContestPrecheckTests and MasternodeClaimableBalanceTests on a simulator, scheme dashwallet-dashpay, Debug, arm64, platform at the pinned commit: 10 tests (8 new), 0 failed.
  • scripts/ci/check_test_target_membership.py passes.
  • The full DashWalletTests suite was not run locally.

Not covered:

  • contestPrecheck(label:) still reads the SDK from the host: the missing-SDK → .unknown path, label normalization, the query itself and the deadline lookup have no test.
  • That the SDK answers a label with no contest with an empty contender list rather than an error is still confirmed only by hand (testnet, 2026-11-24).
  • An answer with no contenders key maps to .fresh (the existing ?? []). The FFI always writes that key, so this is neither pinned by a test nor changed.
  • sdk.identities.fetchBalances(ids:) itself (missing identity = no entry, failure = thrown error) needs a network.
  • fetchClaimableBalance() in MasternodesScreen and TrackedMasternodeDetailScreen, which turns the three outcomes into the balance, the message and the Withdraw button, has no test; both take the SDK from the host.

Breaking Changes

None.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation
  • ADR (ADR-0001): no significant decision
  • Nothing in this PR (files, commit messages, branch name, description, comments, attachments, linked issues) holds customer data, unfixed vulnerability detail, secrets, or step-by-step attack detail against keys, PIN or encryption; such content is left out and handled privately with the maintainers (ADR-0001, rule 2)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved masternode claimable balance results for the selected identity, including when its balance is unavailable or the balance request fails.
    • Improved username contest status handling when contest data is missing, incomplete, or unavailable. Contest deadlines may be omitted when they can’t be retrieved.

Follow-up to #1476, whose review deferred two test gaps.

The contest precheck mapped the vote-state answer inline, next to a
query that reads the SDK from the host, so nothing could call it with a
chosen answer. The mapping is now a pure function over the answer or
its failure; the caller adds the deadline for an active contest as
before.

The masternode balance read called the SDK directly. It now takes the
batch read as a parameter, so the three outcomes (credits, no identity,
failed read) can be exercised without a network.

No behavior change.

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

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The changes add a closure-based masternode balance fetch overload and separate username contest vote-state mapping from deadline lookup. Tests cover balance fetch results and contest precheck outcomes.

Changes: Masternode balance fetch

Layer / File(s) Summary
Fetch identity balance
DashWallet/Sources/Infrastructure/SwiftDashSDK/Masternodes/MasternodeClaimableBalance.swift, DashWalletTests/MasternodeClaimableBalanceTests.swift
The SDK-based fetch delegates to an overload that reads only the requested identity. Tests cover matching, missing, and nil balances, and verify that read errors propagate.

Username contest precheck

Layer / File(s) Summary
Map contest state and resolve deadline
DashWallet/Sources/Infrastructure/SwiftDashSDK/UsernameMarketplaceService.swift, DashWalletTests/UsernameContestPrecheckTests.swift, DashWallet.xcodeproj/project.pbxproj
Vote-state query results pass to a separate mapper. Active contests get an optional deadline from the current-contests listing. Tests cover fresh, locked, active-contest, and unknown results. The project registers the new test file.

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Other

Possibly related PRs

  • dashpay/dashwallet-ios#1476: This PR follows #1476 and adds tests for contest precheck mapping and masternode balance reads changed in that PR.

Suggested reviewers: quantumexplorer, romchornyi

Merge Risk: Minimal · up to e945e

This change adds test seams for two code paths and is described as having no behavior change. The tests it adds target the new seams. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "test: cover the contest precheck mapping and the masternode balance read" matches the changeset. The PR adds UsernameContestPrecheckTests and fetch tests for MasternodeClaimableBalance. It …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "test: cover the contest precheck mapping and the masternode balance read" matches the changeset. The PR adds UsernameContestPrecheckTests and fetch tests for MasternodeClaimableBalance. It also adds the test seams (contestPrecheck(voteState:) and the fetchBalances parameter) that make those tests possible. The title names the two main areas of change and uses the conventional test: prefix. It omits the small refactor, but the PR objectives describe that refactor as behavior-neutral test seams, so this is an acceptable level of detail.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • 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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 349ac8e0-f99b-4a88-a1a3-b89bcca08e69
Commits

Reviewing files that changed from the base of the PR and between 10ca3ce and e945eec.

Files selected for processing: 5

  • DashWallet.xcodeproj/project.pbxproj
  • DashWallet/Sources/Infrastructure/SwiftDashSDK/Masternodes/MasternodeClaimableBalance.swift
  • DashWallet/Sources/Infrastructure/SwiftDashSDK/UsernameMarketplaceService.swift
  • DashWalletTests/MasternodeClaimableBalanceTests.swift
  • DashWalletTests/UsernameContestPrecheckTests.swift

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@thepastaclaw

thepastaclaw commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

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

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Contributor

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

This follow-up adds eight unit tests for username contest status mapping and masternode balance reads, using two test seams without changing production behavior. At the reviewed head, the simulator suite, test-target membership check, workflow lint, and accessibility audit passed; the automated review check was still pending.

🟡 1 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: gpt-6.2-sol (agent: phase2-reviewer, role: general); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)

  • Triage: low by gpt-6.2-sol (effort low) — The diff adds two small test seams and focused unit coverage without changing the existing contest or balance-read behavior.
  • Phase 1 reviewers: glm-5.3-flash — general (completed, effort high); agent phase1-reviewer
  • Phase 1 model: glm-5.3-flash — zai quota: 5h 82% left, weekly 59% left; passed over gemini-3.8-flash-high (lane failed)
  • Fresh verifier: gpt-6.2-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.2-sol — general (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 `DashWallet/Sources/Infrastructure/SwiftDashSDK/UsernameMarketplaceService.swift`:
- [SUGGESTION] DashWallet/Sources/Infrastructure/SwiftDashSDK/UsernameMarketplaceService.swift:499-507: Precheck tests still pass if an active contest loses its known deadline
  Impact: If the precheck drops a known deadline, users who otherwise qualify to request the name can still see Continue after the contest's join window has closed.
  Losing a known deadline would let users proceed with a request Platform will refuse: Create Username blocks joining after the cutoff only when it has the contest's end time. The new tests exercise only `contestPrecheck(voteState:)` and expect `endsAt: nil` for active contests, so they stay green even if the refactored production branch stops attaching the deadline. Add a focused test that exercises that branch with a stubbed contest listing: verify that a millisecond timestamp under the normalized label becomes the returned `Date`, and that a missing entry or failed lookup keeps the contest active with no deadline.

Comment on lines +499 to +507
let precheck = Self.contestPrecheck(voteState: voteState)
guard case .activeContest(let contenders, _) = precheck else { return precheck }
// The vote-state payload carries no deadline, so ask the
// current-contests listing (normalized name → TimestampMillis)
// for it. Best-effort: a failed or incomplete listing just
// leaves the deadline unknown.
let endsAt = (try? await sdk.dpnsGetCurrentContests())?[normalized]
.map { Date(timeIntervalSince1970: Double($0) / 1000) }
return .activeContest(contenders: contenders, endsAt: endsAt)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Suggestion: Precheck tests still pass if an active contest loses its known deadline
Impact: If the precheck drops a known deadline, users who otherwise qualify to request the name can still see Continue after the contest's join window has closed.

Losing a known deadline would let users proceed with a request Platform will refuse: Create Username blocks joining after the cutoff only when it has the contest's end time. The new tests exercise only contestPrecheck(voteState:) and expect endsAt: nil for active contests, so they stay green even if the refactored production branch stops attaching the deadline. Add a focused test that exercises that branch with a stubbed contest listing: verify that a millisecond timestamp under the normalized label becomes the returned Date, and that a missing entry or failed lookup keeps the contest active with no deadline.

source: gpt-6.2-sol (phase2-reviewer: general)

@llbartekll
llbartekll merged commit f6e507b into develop Nov 24, 2026
8 checks passed
romchornyi added a commit that referenced this pull request Nov 25, 2026
…ail, drop diary tags

Merge develop (#1489, #1487): the contest precheck failure line stays in
the catch and writes only the error summary.

Asset-lock retry failures keep the wallet error's detail on the retry
line and in summary.txt (#1276), as a stated exception in ADR-0061: a
recipient mismatch writes its fixed sentence, a consensus rejection its
code and kind only, any other error no text.

Test comments drop review-diary tags (guardrail 6); a source check keeps
them out. The feature README says where a failed network switch's
Platform address sync reason is in the export (the SDK session log).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
SDD-Published-From: e994f3ccb9e6e4f9d89819d15f406e20182fe8e0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants