Skip to content

test(username): pin the DPNS contestability rule; extract the UI hints - #1563

Open
HashEngineering wants to merge 1 commit into
feat/kotlin-sdk-phase-1from
fix/consolidate-contestability
Open

HashEngineering wants to merge 1 commit into
feat/kotlin-sdk-phase-1from
fix/consolidate-contestability

Conversation

@HashEngineering

@HashEngineering HashEngineering commented Sep 10, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Investigation of the reported username contestability disagreement (MO-973 / MO-972). The reported bug is not real — no wrong funding denomination, no duplicated predicate. This PR adds the tests that would have answered the question in seconds, and removes the one piece of genuine duplication that could have grown into the reported bug.

The report's two premises are both wrong

1. checkUsername's contested is not contestability. It is contenders.map.isNotEmpty() — a network query for whether the name already has vote contenders. The MO-973 log proves it:

10:39:55  checkUsername('asd'):   exists=false contested=true  blocked=true
10:39:55  checkUsername('asdsd'): exists=false contested=false blocked=false
10:40:19  checkUsername('asda'):  exists=false contested=false blocked=false

asdsd and asda are short all-letter names — unambiguously contestable — yet the checker reports false. It reports true only for asd, the one name with real contenders (blocked=true, from a live lockVoteTally). A rule-based predicate could not produce that pattern.

2. The DPNS rule is not "short AND no digits." dashj's Names.isUsernameContestable is the DPNS contract's contestedIndex regex:

^[a-zA-Z01-]{3,19}$

0 and 1 are in the alphabet because they are homoglyphs of o and l — "he11o" vs "hello" — so DPNS keeps them in the contest. asd10augsh's only digits are 1 and 0, so it is contestable and 0.25 DASH was the correct denomination. Digits 2-9 have no letter lookalike; one of those anywhere clears the contest.

There is also only one implementation

All 21 call sites — the balance gate, SdkShieldedUsernameCreation, SdkTransparentUsernameCreation, TopUpRepository, CreateIdentityService, PlatformSyncService, IdentityRepository, RestoreIdentityWorker — call the same dashj function.

The MO-972 gate log confirms the rule working end to end: every name the gate demanded 0.25 for is [a-z0-1]-only, and asd10augda6 produced no gate-failure line at all — the 6 dropped the requirement to 0.03 against a 0.24999474 balance. That is a positive observation, not just an absence of evidence.

So: no wrong denomination, no wrong post-creation routing, and no caller changes in this PR.

What actually changed

The one genuinely duplicated thing was the request screen's two "avoid the contest" checkmarks, which hand-encoded the rule's complement privately in the ViewModel (Regex("[2-9]") and a hardcoded 20).

Those are label-only — usernameNonContestedChars / usernameNonContestedLength feed only the RequestUsernameFragment checkmark rows, and no denomination derives from them — but nothing stopped them drifting from what the wallet spends.

  • UsernameContestability.kt (new): the two hints as pure internal functions, with the homoglyph rule documented where the next reader will hit it, and an explicit "do not re-implement the rule" note.
  • RequestUserNameViewModel.kt: calls those instead of the private copies. Behaviour-identical.
  • UsernameContestabilityTest.kt (new): pins the hints as an exact decomposition of Names.isUsernameContestable itself, so a dashj bump that moves the rule breaks a test instead of quietly repricing a creation.

Tests

Seven tests pin: a short all-letters name is contestable; a 2-9 digit clears the contest; 0/1 do not; the 3..19 length window and the 20 threshold one past it; the actual field-log names from both reports; and the hint/rule equivalence over ~8k generated names.

One requested assertion was itself the bug's premise — "a name containing digits is not contestable" is false — so the tests pin the real rule instead.

Verified with teeth: substituting the report's assumed [0-9] rule fails the equivalence test. Restored, then:

  • ./gradlew ktlintFormat — no changes
  • ./gradlew :wallet:compile_testNet3DebugKotlin — clean
  • ./gradlew :wallet:test_testNet3DebugUnitTest — 1914 tests, 0 failures

Scope

Separate from the two underlying MO-973 / MO-972 failures (the FFI "Invalid identity data" DPNS rejection and the HONOR auth-gated Keystore refusal), which are handled elsewhere.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved username contestability validation on the request screen.
    • Contestability indicators now correctly reflect username length and the presence of digits 2–9.
    • Names containing 0 or 1 continue to be treated as contestable, consistent with DPNS rules.
    • Updated handling of the contested-name length range for more accurate feedback.

@coderabbitai

coderabbitai Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

Warning

Review limit reached

Next included review available in 33 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

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

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 4f0c988f-5f39-4e53-b23f-bb2b29e86dd4

📥 Commits

Reviewing files that changed from the base of the PR and between fb22657 and 6896686.

📒 Files selected for processing (3)
  • wallet/src/de/schildbach/wallet/ui/username/request/RequestUserNameViewModel.kt
  • wallet/src/de/schildbach/wallet/ui/username/request/UsernameContestability.kt
  • wallet/test/de/schildbach/wallet/ui/username/request/UsernameContestabilityTest.kt

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 58059505-0f8d-43e4-a483-6e675f4a20ba

📥 Commits

Reviewing files that changed from the base of the PR and between fb22657 and 6896686.

📒 Files selected for processing (3)
  • wallet/src/de/schildbach/wallet/ui/username/request/RequestUserNameViewModel.kt
  • wallet/src/de/schildbach/wallet/ui/username/request/UsernameContestability.kt
  • wallet/test/de/schildbach/wallet/ui/username/request/UsernameContestabilityTest.kt

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

The change centralizes DPNS username contestability checks, updates request validation to use the shared helpers, and adds boundary, field-log, and randomized property tests.

Changes

Username contestability

Layer / File(s) Summary
Contestability rule and request validation
wallet/src/de/schildbach/wallet/ui/username/request/UsernameContestability.kt, wallet/src/de/schildbach/wallet/ui/username/request/RequestUserNameViewModel.kt
Defines length and digit-based contestability helpers. Request validation now uses these helpers instead of duplicated private functions.
Contestability test coverage
wallet/test/de/schildbach/wallet/ui/username/request/UsernameContestabilityTest.kt
Tests contestable length boundaries, homoglyph digits, non-homoglyph digits, field-log examples, and equivalence between contestability and request-screen hints.

Priority: ⬇️ Low

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

Change: Other

Merge Risk: ⚪ Minimal · up to 68966

The shared contestability hints and request-screen wiring are covered by boundary and equivalence tests, with no current merge-blocking risk identified.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 15.38% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main changes: pinning the DPNS contestability rule and extracting request-screen UI hints.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/consolidate-contestability

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

Comment @coderabbitai help to get the list of available commands.

MO-973 read `checkUsername('asd10augsh'): contested=false` against
`SdkShieldedUsernameCreation ... 0.25 denomination, contested=true` as two
contestability implementations disagreeing, with the creation path
overcharging. Neither half of that holds:

- `checkUsername`'s `contested` is not contestability. It is
  `contenders.map.isNotEmpty()` — a network query for whether the name
  already has vote contenders. The same log has contested=false for
  'asdsd', 'asda', 'asds', 'asdsg', all short all-letter names that ARE
  contestable, and contested=true only for 'asd', the one name with real
  contenders (blocked=true, from a live lockVoteTally).

- The DPNS rule is not "short AND no digits". The contract's
  contestedIndex regex is ^[a-zA-Z01-]{3,19}$: `0` and `1` are homoglyphs
  of `o` and `l`, so they stay in the contest. 'asd10augsh' is
  contestable, and 0.25 DASH was the correct denomination.

There is also only ONE predicate. All 21 call sites — the balance gate,
both SDK creation paths, TopUpRepository, CreateIdentityService,
PlatformSyncService, IdentityRepository, RestoreIdentityWorker — call
dashj `Names.isUsernameContestable`. The MO-972 gate log confirms it
end to end: every name it required 0.25 for is [a-z0-1]-only, and
'asd10augda6' produced no gate failure at all, i.e. the `6` dropped the
requirement to 0.03.

No funding bug, so no caller changes. What was genuinely duplicated is
the request screen's two "avoid the contest" checkmarks, which
hand-encoded the rule's complement privately in the ViewModel
(`[2-9]` and a hardcoded 20). Those are label-only — no denomination
derives from them — but they could drift away from what the wallet
spends. Extracted to pure internal functions in UsernameContestability.kt
and pinned in UsernameContestabilityTest against
`Names.isUsernameContestable` itself, so a dashj bump that moves the rule
breaks a test instead of quietly repricing a creation.

Tests pin: short all-letters contestable; a 2-9 digit clears the contest;
0/1 do not; the 3..19 length window and the 20 threshold one past it; the
field-log names; and the hints as an exact decomposition of the rule over
~8k generated names. Verified with teeth — encoding the report's assumed
"any digit" rule fails the equivalence test.

Co-Authored-By: Claude Opus 5 <[email protected]>
@HashEngineering
HashEngineering force-pushed the fix/consolidate-contestability branch from e301691 to 6896686 Compare September 11, 2026 06:03
@HashEngineering
HashEngineering changed the base branch from chore/start-v12.0.0 to feat/kotlin-sdk-phase-1 September 11, 2026 06:03
@HashEngineering

Copy link
Copy Markdown
Collaborator Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Review rate limited.


Your included review limit is currently reached under our Fair Usage Limits Policy. This review may still proceed through usage-based billing if eligible. Your next included review will be available in 33 minutes.

@thepastaclaw

thepastaclaw commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

✅ Final review complete — no blockers (commit 6896686) · triage: low · Phase 2 only (queue backlog)

@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 2 only (queue backlog)

The changes correctly extract the request-screen contestability hints without altering funding or username-creation decisions. The new tests directly pin the UI hint decomposition against dashj’s contestability predicate, including the DPNS treatment of digits 0/1 and the 3–19 character contested-name range; no in-scope defects were found.

Review provenance

Source: reviewer 1: gpt-6-astra (agent: phase2-reviewer, role: general); final verifier: gpt-6-astra (agent: astra-verifier, role: final-verifier)

  • Triage: low by gpt-6-astra (effort low) — The diff is a small, well-contained UI-hint extraction with comprehensive tests and no changes to username contestability, funding, routing, or other critical wallet surfaces.
  • Phase 1 reviewers: not run (skipped for throughput: 18 PRs queued, above the 10 limit)
  • Fresh verifier: gpt-6-astra — final-verifier; agent astra-verifier
  • Phase 2 reviewers: gpt-6-astra — general (completed, effort medium); agent phase2-reviewer

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