@@ -23,34 +23,37 @@ func TestPromptCommissionRate_ValidInput(t *testing.T) {
2323}
2424
2525func TestPromptCommissionRate_InvalidInput (t * testing.T ) {
26- p := & mockPrompter {responses : []string {"abc" }}
26+ // Invalid input, then empty → falls back to default
27+ p := & mockPrompter {responses : []string {"abc" , "" }, interactive : true }
2728 rate := promptCommissionRate (p , "0.10" )
2829 if rate != "0.10" {
2930 t .Errorf ("expected default 0.10, got %s" , rate )
3031 }
3132}
3233
3334func TestPromptCommissionRate_TooHigh (t * testing.T ) {
34- p := & mockPrompter {responses : []string {"150" }}
35+ // Too high, then empty → falls back to default
36+ p := & mockPrompter {responses : []string {"150" , "" }, interactive : true }
3537 rate := promptCommissionRate (p , "0.10" )
3638 if rate != "0.10" {
3739 t .Errorf ("expected default 0.10 for >100, got %s" , rate )
3840 }
3941}
4042
4143func TestPromptCommissionRate_TooLow (t * testing.T ) {
42- p := & mockPrompter {responses : []string {"0" }}
44+ // Too low, then empty → falls back to default
45+ p := & mockPrompter {responses : []string {"4" , "" }, interactive : true }
4346 rate := promptCommissionRate (p , "0.10" )
4447 if rate != "0.10" {
45- t .Errorf ("expected default 0.10 for <1 , got %s" , rate )
48+ t .Errorf ("expected default 0.10 for <5 , got %s" , rate )
4649 }
4750}
4851
4952func TestPromptCommissionRate_BoundaryValues (t * testing.T ) {
50- p := & mockPrompter {responses : []string {"1 " }}
53+ p := & mockPrompter {responses : []string {"5 " }}
5154 rate := promptCommissionRate (p , "0.10" )
52- if rate != "0.01 " {
53- t .Errorf ("expected 0.01 for 1 %%, got %s" , rate )
55+ if rate != "0.05 " {
56+ t .Errorf ("expected 0.05 for 5 %%, got %s" , rate )
5457 }
5558
5659 p = & mockPrompter {responses : []string {"100" }}
@@ -234,12 +237,11 @@ func TestCollectRegistrationInputs_DefaultValues(t *testing.T) {
234237 CommissionRate : "0.10" ,
235238 }
236239
240+ // Response 0: wallet choice → "" (default = create new)
241+ // Response 1: key name prompt → "" (use default)
237242 // Moniker prompt is skipped (not "" or "push-validator")
238- // Response 0: key name prompt → "" (use default)
239- // Response 1: wallet choice → "" (default = create new)
240- // Response 2: commission rate → "" (use default 0.10)
241243 d .Prompter = & mockPrompter {
242- responses : []string {"" , "" , "" },
244+ responses : []string {"" , "" },
243245 interactive : true ,
244246 }
245247
@@ -253,9 +255,6 @@ func TestCollectRegistrationInputs_DefaultValues(t *testing.T) {
253255 if result .KeyName != "my-key" {
254256 t .Errorf ("expected keyName my-key, got %s" , result .KeyName )
255257 }
256- if result .CommissionRate != "0.10" {
257- t .Errorf ("expected rate 0.10, got %s" , result .CommissionRate )
258- }
259258}
260259
261260func TestCollectRegistrationInputs_CustomValues (t * testing.T ) {
@@ -275,13 +274,12 @@ func TestCollectRegistrationInputs_CustomValues(t *testing.T) {
275274 CommissionRate : "0.10" ,
276275 }
277276
278- // Moniker IS "push-validator" so moniker prompt fires
279- // Response 0: moniker → "custom-moniker"
277+ // Response 0: wallet choice → "" (default = create new)
280278 // Response 1: key name → "custom-key"
281- // Response 2: wallet choice → "" (default = create new)
282- // Response 3: commission rate → "20 "
279+ // Moniker IS "push-validator" so moniker prompt fires
280+ // Response 2: moniker → "custom-moniker "
283281 d .Prompter = & mockPrompter {
284- responses : []string {"custom-moniker " , "custom-key" , "" , "20 " },
282+ responses : []string {"" , "custom-key" , "custom-moniker " },
285283 interactive : true ,
286284 }
287285
@@ -295,9 +293,6 @@ func TestCollectRegistrationInputs_CustomValues(t *testing.T) {
295293 if result .KeyName != "custom-key" {
296294 t .Errorf ("expected custom-key, got %s" , result .KeyName )
297295 }
298- if result .CommissionRate != "0.20" {
299- t .Errorf ("expected 0.20, got %s" , result .CommissionRate )
300- }
301296}
302297
303298func TestCollectRegistrationInputs_KeyExists_UseExisting (t * testing.T ) {
@@ -324,9 +319,9 @@ func TestCollectRegistrationInputs_KeyExists_UseExisting(t *testing.T) {
324319 runner .outputs [binPath + " keys show my-key -a --keyring-backend " + cfg .KeyringBackend + " --home " + cfg .HomeDir ] = []byte ("push1existing\n " )
325320 d .Runner = runner
326321
327- // Response 0: key name → "" (use default "my-key" which exists )
328- // Key exists branch: Response 1: enter different name → "" (use existing )
329- // Response 2: commission rate → ""
322+ // Response 0: wallet choice → "" (create new )
323+ // Response 1: key name → "" (use default "my-key" which exists )
324+ // Key exists branch: Response 2: enter different name → "" (use existing)
330325 d .Prompter = & mockPrompter {
331326 responses : []string {"" , "" , "" },
332327 interactive : true ,
@@ -370,13 +365,11 @@ func TestCollectRegistrationInputs_KeyExists_EnterNewName(t *testing.T) {
370365 runner .errors [binPath + " keys show new-key -a --keyring-backend " + cfg .KeyringBackend + " --home " + cfg .HomeDir ] = errMock
371366 d .Runner = runner
372367
373- // Response 0: key name → "" (use default "existing-key" which exists)
374- // Key exists: Response 1: enter different name → "new-key"
375- // new-key doesn't exist, so wallet choice fires
376- // Response 2: wallet choice → "" (create new)
377- // Response 3: commission rate → "15"
368+ // Response 0: wallet choice → "" (create new)
369+ // Response 1: key name → "" (use default "existing-key" which exists)
370+ // Key exists: Response 2: enter different name → "new-key"
378371 d .Prompter = & mockPrompter {
379- responses : []string {"" , "new-key " , "" , "15 " },
372+ responses : []string {"" , "" , "new-key " },
380373 interactive : true ,
381374 }
382375
@@ -387,9 +380,6 @@ func TestCollectRegistrationInputs_KeyExists_EnterNewName(t *testing.T) {
387380 if result .KeyName != "new-key" {
388381 t .Errorf ("expected new-key, got %s" , result .KeyName )
389382 }
390- if result .CommissionRate != "0.15" {
391- t .Errorf ("expected 0.15, got %s" , result .CommissionRate )
392- }
393383}
394384
395385func TestCollectRegistrationInputs_KeyExists_NewNameAlsoExists (t * testing.T ) {
@@ -417,12 +407,11 @@ func TestCollectRegistrationInputs_KeyExists_NewNameAlsoExists(t *testing.T) {
417407 runner .outputs [binPath + " keys show also-exists -a --keyring-backend " + cfg .KeyringBackend + " --home " + cfg .HomeDir ] = []byte ("push1b\n " )
418408 d .Runner = runner
419409
420- // Response 0: key name → "" (use default which exists)
421- // Key exists: Response 1: enter different name → "also-exists" (also exists)
422- // Since new key also exists, wallet choice NOT called
423- // Response 2: commission rate → ""
410+ // Response 0: wallet choice → "" (create new)
411+ // Response 1: key name → "" (use default which exists)
412+ // Key exists: Response 2: enter different name → "also-exists" (also exists)
424413 d .Prompter = & mockPrompter {
425- responses : []string {"" , "also-exists " , "" },
414+ responses : []string {"" , "" , "also-exists " },
426415 interactive : true ,
427416 }
428417
0 commit comments