Skip to content

Commit 00f7df7

Browse files
lklimekclaude
andcommitted
docs(contested-names): slim comments and restyle unit tests as given/when/then
Address review feedback on #835: the `dpns_vote_poll_index_values` doc comment and the pre-flight check inline comment were over-explanatory; trimmed each to 2-3 lines with concrete examples. The two unit tests now use inline Given/When/Then comments instead of a free-form doc comment — easier to scan and matches project test-style preference. No logic changes; assertions unchanged. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 801cf07 commit 00f7df7

1 file changed

Lines changed: 20 additions & 21 deletions

File tree

src/backend_task/contested_names/vote_on_dpns_name.rs

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,10 @@ use dash_sdk::platform::transition::vote::PutVote;
2121
use dash_sdk::query_types::ContestedResource;
2222
use std::sync::Arc;
2323

24-
/// Build the DPNS contested-index values for a vote poll.
24+
/// Build `[Value::from("dash"), Value::Text(normalized_label)]` for a DPNS vote poll.
2525
///
26-
/// Platform stores the vote poll under the homograph-safe **normalized** label,
27-
/// not the raw user input (e.g. `"alice"` → `"a11ce"`, with `i`→`1`, `l`→`1`,
28-
/// `o`→`0`, and `to_lowercase`). Any caller that constructs a vote poll with
29-
/// the raw label hits `VotePollNotFoundError` at `PrepareProposal`, which
30-
/// surfaces as an opaque ~70 s timeout.
31-
///
32-
/// Pure helper — no `AppContext`/`Sdk` dependency, trivially unit-testable.
33-
/// Returns `[Value::from("dash"), Value::Text(normalized_label)]`.
26+
/// Label is normalized via `convert_to_homograph_safe_chars` (`alice` → `a11ce`);
27+
/// Platform indexes polls under the normalized form.
3428
fn dpns_vote_poll_index_values(name: &str) -> Vec<Value> {
3529
vec![
3630
Value::from("dash"),
@@ -73,11 +67,8 @@ impl AppContext {
7367
contract_id: data_contract.id(),
7468
};
7569

76-
// Pre-flight existence check. Confirm Platform actually has an open
77-
// vote poll for `(dash, normalized_label)` before broadcasting any
78-
// signed vote state transitions. This short-circuits the ~70 s
79-
// retry chain triggered by `VotePollNotFoundError` at
80-
// `PrepareProposal` when the poll is missing or already resolved.
70+
// Pre-flight: confirm Platform has an open poll for this label before
71+
// broadcasting — avoids the ~70 s retry chain on a missing poll.
8172
let existence_query = VotePollsByDocumentTypeQuery {
8273
contract_id: data_contract.id(),
8374
document_type_name: document_type.name().to_string(),
@@ -142,22 +133,30 @@ impl AppContext {
142133
mod tests {
143134
use super::*;
144135

145-
/// Homograph substitutions must apply — Platform indexes the poll under
146-
/// the normalized label, so a raw label produces a `VotePollNotFound`
147-
/// mismatch at `PrepareProposal` time.
148136
#[test]
149137
fn index_values_normalizes_homograph_chars() {
150-
let values = dpns_vote_poll_index_values("alice");
138+
// Given: a label containing i/l/o homograph characters.
139+
let label = "alice";
140+
141+
// When: constructing the vote poll index values.
142+
let values = dpns_vote_poll_index_values(label);
143+
144+
// Then: first element is always the `"dash"` parent, second is the
145+
// normalized label (i/l → 1, o → 0).
151146
assert_eq!(values.len(), 2);
152147
assert_eq!(values[0], Value::from("dash"));
153148
assert_eq!(values[1], Value::Text("a11ce".to_owned()));
154149
}
155150

156-
/// Labels that contain no homograph characters must round-trip unchanged —
157-
/// except for `to_lowercase`, which is part of the normalization pipeline.
158151
#[test]
159152
fn index_values_preserve_non_homograph_label() {
160-
let values = dpns_vote_poll_index_values("bar22");
153+
// Given: a label with no homograph characters (e.g. `bar22`).
154+
let label = "bar22";
155+
156+
// When: constructing the vote poll index values.
157+
let values = dpns_vote_poll_index_values(label);
158+
159+
// Then: normalization leaves it unchanged.
161160
assert_eq!(values[1], Value::Text("bar22".to_owned()));
162161
}
163162
}

0 commit comments

Comments
 (0)