-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathslip39_test.go
795 lines (725 loc) · 21.8 KB
/
slip39_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
package slip39
import (
"crypto/rand"
"encoding/hex"
"encoding/json"
"errors"
"math/big"
"os"
"regexp"
"sort"
"strconv"
"strings"
"testing"
"gonum.org/v1/gonum/stat/combin"
)
const (
testPassphrase = "TREZOR"
)
var (
reRange = regexp.MustCompile(`^(?:(\d+)?(-))?(\d+)$`)
// vectorErrors maps vector index to expected error
vectorErrors = map[int]error{
2: ErrInvalidChecksum,
3: ErrInvalidPadding{},
5: ErrTooFewShares{},
6: ErrInvalidCommonParameters,
7: ErrInvalidCommonParameters,
8: ErrInvalidCommonParameters,
9: ErrInvalidCommonParameters,
10: ErrBadGroupThreshold{},
11: ErrInvalidMnemonicIndices,
12: ErrTooManyShares{},
13: ErrInvalidMnemonicSharedSecretDigest,
14: ErrTooFewShares{},
15: ErrTooFewShares{},
16: ErrTooFewShares{},
21: ErrInvalidChecksum,
22: ErrInvalidPadding{},
24: ErrTooFewShares{},
25: ErrInvalidCommonParameters,
26: ErrInvalidCommonParameters,
27: ErrInvalidCommonParameters,
28: ErrInvalidCommonParameters,
29: ErrBadGroupThreshold{},
30: ErrInvalidMnemonicIndices,
31: ErrTooManyShares{},
32: ErrInvalidMnemonicSharedSecretDigest,
33: ErrTooFewShares{},
34: ErrTooFewShares{},
35: ErrTooFewShares{},
39: ErrInvalidMnemonic,
40: ErrInvalidPadding{},
}
)
type vector struct {
description string
shares []string
masterSecret string
rootPrivateKey string
}
type secret struct {
Description string
MasterSecret string `json:"master_secret"`
GroupThreshold int `json:"group_threshold"`
MemberGroupParams []MemberGroupParameters `json:"member_group_params"`
}
func mustLoadVectors(t *testing.T) []vector {
t.Helper()
data, err := os.ReadFile("testdata/vectors.json")
if err != nil {
t.Fatal(err)
}
var records [][]interface{}
err = json.Unmarshal(data, &records)
if err != nil {
t.Fatal(err)
}
vectors := make([]vector, len(records))
for i, record := range records {
v := vector{}
v.description = record[0].(string)
shares := record[1].([]interface{})
v.shares = make([]string, len(shares))
for j, s := range shares {
v.shares[j] = s.(string)
}
v.masterSecret = record[2].(string)
//v.rootPrivateKey = record[3].(string)
vectors[i] = v
}
return vectors
}
func mustLoadSecrets(t *testing.T) []secret {
t.Helper()
data, err := os.ReadFile("testdata/secrets.json")
if err != nil {
t.Fatal(err)
}
var secrets []secret
err = json.Unmarshal(data, &secrets)
if err != nil {
t.Fatal(err)
}
return secrets
}
func parseArgs(t *testing.T) (int, int) {
t.Helper()
finalArg := os.Args[len(os.Args)-1]
matches := reRange.FindStringSubmatch(finalArg)
var m1, m3 int
var m2 string
var err error
if matches != nil {
if matches[1] != "" {
m1, err = strconv.Atoi(matches[1])
if err != nil {
t.Fatal(err)
}
}
if matches[2] != "" {
m2 = matches[2]
}
if matches[3] != "" {
m3, err = strconv.Atoi(matches[3])
if err != nil {
t.Fatal(err)
}
}
}
to := m3
from := 0
if m1 > 0 {
// range with both ends defined e.g. 10-43
from = m1
} else if m2 != "" {
// range with right-end-only defined e.g. -43
from = 1
} else {
// simple number e.g. 43
from = m3
}
return from, to
}
// Text xor
func TestXor(t *testing.T) {
t.Parallel()
var tests = []struct {
a []byte
b []byte
want []byte
}{
{[]byte{0, 1, 2, 3}, []byte{0, 2, 4, 6}, []byte{0, 3, 6, 5}},
{[]byte{0, 1, 2, 3}, []byte{0, 2}, []byte{0, 3}},
}
for _, tc := range tests {
got := xor(tc.a, tc.b)
if string(got) != string(tc.want) {
t.Errorf("getSalt failed: got %v, want %v", got, tc.want)
}
}
}
// Test getSalt
func TestGetSalt(t *testing.T) {
t.Parallel()
var tests = []struct {
id int
ext bool
want string
}{
{7945, false, "shamir\x1f\t"},
{25653, false, "shamird5"},
}
for _, tc := range tests {
got := getSalt(tc.id, tc.ext)
if string(got) != tc.want {
t.Errorf("getSalt failed: got %q, want %q", string(got), tc.want)
}
}
}
// Test round-tripping ParseShare and share.Mnemonic()
func TestParseShareMnemonic(t *testing.T) {
t.Parallel()
var tests = []struct {
name string
input string
err error
}{
{"m1", "duckling enlarge academic academic agency result length solution fridge kidney coal piece deal husband erode duke ajar critical decision keyboard", nil},
// Error cases
{"mnemonic bad word", "duckling enlarge academic academic agency result length solution fridge kidney coal piece deal husband erode duke ajar critical decision bogus", ErrInvalidMnemonicWord{}},
{"mnemonic bad length", "duckling enlarge", ErrInvalidMnemonic},
}
for _, tc := range tests {
//t.Logf("input: %v", tc.input)
s, err := ParseShare(tc.input)
if err != nil {
if tc.err == nil {
t.Error(err)
} else if !errors.Is(err, tc.err) {
t.Errorf("unexpected error on %q: want %q, got %q",
tc.name, tc.err, err)
} else {
_ = err.Error()
}
continue
}
//t.Logf("shareValues: %v", s.ShareValues)
mnemonic, err := s.Mnemonic()
if err != nil {
if tc.err == nil {
t.Error(err)
}
continue
}
//t.Logf("mnemonic: %s", mnemonic)
if mnemonic != tc.input {
t.Errorf("error on %q: input %q, output %q",
tc.name, tc.input, mnemonic)
}
}
}
// Test round-tripping cipherEncrypt and cipherDecrypt
func TestCipherEncryptDecrypt(t *testing.T) {
t.Parallel()
var tests = []struct {
secret string
id int
err error
}{
{"bb54aac4b89dc868ba37d9cc21b2cece", 342, nil},
{"bb", 342, ErrInvalidMasterSecretLength},
}
for _, tc := range tests {
encrypted, err := cipherEncrypt([]byte(tc.secret), []byte(testPassphrase), 1, tc.id, true)
if err != nil {
if tc.err == nil {
t.Fatal(err)
}
if !errors.Is(err, tc.err) {
t.Errorf("got unexpected error: want %q, got %q",
tc.err.Error(), err.Error())
} else {
continue
}
}
decrypted, err := cipherDecrypt(encrypted, []byte(testPassphrase), 1, tc.id, true)
if string(decrypted) != tc.secret {
t.Errorf("want %q, got %q", tc.secret, string(decrypted))
}
}
}
func TestCombineMnemonics(t *testing.T) {
t.Parallel()
vectors := mustLoadVectors(t)
from, to := parseArgs(t)
for i, v := range vectors {
if from > 0 && i+1 < from {
continue
}
mnemonics := []string{}
for _, m := range v.shares {
mnemonics = append(mnemonics, m)
}
masterSecretBytes, err := CombineMnemonicsWithPassphrase(
mnemonics, []byte(testPassphrase),
)
if err != nil {
// If masterSecret is empty, then an error is expected
if v.masterSecret != "" {
t.Errorf("CombineMnemonics returned (unexpected) error: %s (%q)",
err.Error(), v.description)
} else if vectorErrors[i+1] != nil && !errors.Is(err, vectorErrors[i+1]) {
t.Errorf("CombineMnemonics returned (unexpected) error type: %s (%q)",
err.Error(), v.description)
} else {
_ = err.Error()
/*
t.Logf("CombineMnemonics returned (expected) error:%s (%q)",
err.Error(), v.description)
*/
}
} else if v.masterSecret == "" {
t.Errorf("CombineMnemonics unexpectedly succeeded (%q)",
v.description)
} else {
masterSecret := hex.EncodeToString(masterSecretBytes)
if v.masterSecret != masterSecret {
t.Errorf("CombineMnemonics returned bad masterSecret (got %v, want %q, for %q)",
masterSecret, v.masterSecret, v.description)
/*
} else {
t.Logf("CombineMnemonics success: %s (%q)",
v.masterSecret, v.description)
*/
}
}
if to > 0 && i+1 >= to {
break
}
}
}
func selectRandomShares(mgp MemberGroupParameters, shares []string) []string {
if len(shares) == 1 {
return []string{shares[0]}
}
list := combin.Combinations(mgp.MemberCount, mgp.MemberThreshold)
i, err := rand.Int(rand.Reader, big.NewInt(int64(len(list))))
if err != nil {
panic("rand.Int failed:" + err.Error())
}
return selectShares(list[int(i.Int64())], shares)
}
func selectShares(selection []int, shares []string) []string {
selected := make([]string, len(selection))
for i, j := range selection {
selected[i] = shares[j]
}
return selected
}
func selectAndFlattenSets(selection []int, sets [][]string) []string {
selected := []string{}
for _, j := range selection {
for _, s := range sets[j] {
selected = append(selected, s)
}
}
return selected
}
func selectionString(selection []int) string {
var s []string
for _, i := range selection {
s = append(s, strconv.Itoa(i))
}
return strings.Join(s, ",")
}
func checkSelectedMnemonics(
t *testing.T,
s secret,
passphrase string,
selectedIndices []int,
selected []string,
) {
var masterSecretBytes []byte
var err error
if passphrase != "" {
masterSecretBytes, err = CombineMnemonicsWithPassphrase(
selected, []byte(passphrase),
)
} else {
masterSecretBytes, err = CombineMnemonics(selected)
}
if err != nil {
t.Errorf("CombineMnemonics returned error: %q on mnemonics [%s] %v",
err.Error(), selectionString(selectedIndices), selected)
return
}
masterSecret := hex.EncodeToString(masterSecretBytes)
if err != nil {
t.Errorf("hex.EncodeToString returned error: %s", err.Error())
}
if masterSecret != s.MasterSecret {
t.Errorf("masterSecret mismatch: got %q, want %q",
string(masterSecret), s.MasterSecret)
/*
} else {
t.Logf("masterSecret match with mnemonics [%s]: %v",
selectionString(selectedIndices), selected)
*/
}
// Check that deleting a random share from selected gives an error
if len(selected) > 1 {
i, err := rand.Int(rand.Reader, big.NewInt(int64(len(selected))))
if err != nil {
t.Fatalf("rand.Int failed: %s", err.Error())
}
j := int(i.Int64())
selected2 := make([]string, len(selected)-1)
copy(selected2, selected[:j])
if len(selected) > j {
copy(selected2[j:], selected[j+1:])
}
_, err = CombineMnemonicsWithPassphrase(
selected2, []byte(passphrase),
)
if err == nil {
t.Errorf("CombineMnemonics unexpectedly succeeded with k-1 mnemonics (%d) %v",
len(selected2), selected2)
} else if !errors.Is(err, ErrTooFewShares{}) {
t.Errorf("CombineMnemonics failed with unexpected error with k-1 mnemonics (%d) %v: %s",
len(selected2), selected2, err.Error())
} else {
_ = err.Error()
//t.Logf("CombineMnemonics failed as expected with k-1 mnemonics (%d) %v", len(selected2), selected2)
}
}
}
// Test round-tripping GenerateMnemonics/CombineMnemonics
func TestGenerateMnemonics(t *testing.T) {
t.Parallel()
secrets := mustLoadSecrets(t)
from, to := parseArgs(t)
for _, passphrase := range []string{testPassphrase, ""} {
for i, s := range secrets {
if from > 0 && i+1 < from {
continue
}
//fmt.Fprintf(os.Stderr, "secret: %v\n", s)
masterSecretBytes, err := hex.DecodeString(s.MasterSecret)
if err != nil {
t.Errorf("hex.DecodeString returned error: %s", err.Error())
}
var shareGroups ShareGroups
if passphrase != "" {
shareGroups, err = GenerateMnemonicsWithOptions(
s.GroupThreshold, s.MemberGroupParams,
masterSecretBytes, []byte(passphrase),
true, 0, // for some reason the python cli defaults to exponent=0
)
} else {
shareGroups, err = GenerateMnemonics(
s.GroupThreshold, s.MemberGroupParams, masterSecretBytes,
)
}
if err != nil {
t.Error(err)
}
//t.Logf("shareGroups (%d group(s)): %v\n", len(shareGroups), shareGroups)
//secretBytes, combinations, err := shareGroups.ValidateMnemonicsWithPassphrase([]byte(passphrase))
secretBytes, _, err := shareGroups.ValidateMnemonicsWithPassphrase([]byte(passphrase))
if err != nil {
if err == ErrTooManyCombinations {
continue
}
t.Fatal(err)
}
secret := hex.EncodeToString(secretBytes)
if secret != s.MasterSecret {
t.Fatalf("ValidateMnemonics secret mismatch: got %q, want %q",
secret, s.MasterSecret)
}
//t.Logf("combinations: %d, secret: %s", combinations, secret)
if to > 0 && i+1 >= to {
break
}
}
}
}
// Test ShareGroups.combinations method
func TestShareGroupsCombinations(t *testing.T) {
t.Parallel()
var tests = []struct {
groupThreshold int
memberGroupParams []MemberGroupParameters
quorumLength int
}{
// Test: 1 of: 3of5
{1, []MemberGroupParameters{{3, 5}}, 3},
// Test: 2 of: 1of1 + 2of3
{2, []MemberGroupParameters{{1, 1}, {2, 3}}, 3},
// Test: 2 of: 2of3 + 3of5
{2, []MemberGroupParameters{{2, 3}, {3, 5}}, 5},
// Test: 2 of: 1of1 + 2of3 + 2of3
{2, []MemberGroupParameters{{1, 1}, {2, 3}, {2, 3}}, 0},
}
secret := "989baf9dcaad5b10ca33dfd8cc75e42477025dce88ae83e75a230086a0e00e92"
secretBytes, err := hex.DecodeString(secret)
if err != nil {
t.Errorf("hex.DecodeString returned error: %s", err.Error())
}
for _, tc := range tests {
shareGroups, err := GenerateMnemonics(
tc.groupThreshold, tc.memberGroupParams, secretBytes,
)
if err != nil {
t.Fatal(err)
}
/*
for i, sg := range shareGroups {
t.Logf("shareGroup %d:\n%s\n", i, strings.Join(sg, "\n"))
}
*/
groupCombinations, err := shareGroups.combinations()
if err != nil {
t.Fatal(err)
}
//t.Logf("groupCombinations: %d", len(groupCombinations))
// Test validity:
// - the number of shares should be as expected (quorumLength)
// - the combinations of shares should be unique (no repeats)
// - shares should all combine back to the same expected secret
cache := make(map[string]int)
for i, mnemonics := range groupCombinations {
/*
t.Logf("shareGroup %d mnemonics (%d):\n%s\n",
i, len(mnemonics), strings.Join(mnemonics, "\n"))
*/
// Check number of shares
if tc.quorumLength != 0 && len(mnemonics) != tc.quorumLength {
t.Errorf("shareGroup %d combinations (%d) != %d", i,
len(mnemonics), tc.quorumLength)
}
// Check uniqueness
sort.Strings(mnemonics)
key := strings.Join(mnemonics, "\n")
cache[key]++
if cache[key] > 1 {
t.Errorf("shareGroup %d combinations not unique (count == %d):\n%s",
i, cache[key], key)
}
// Check resultant secret
masterSecretBytes, err := CombineMnemonics(mnemonics)
if err != nil {
t.Fatal(err)
}
masterSecret := hex.EncodeToString(masterSecretBytes)
if masterSecret != secret {
t.Errorf("shareGroup %d combined to unexpected secret: got %q, want %q",
i, masterSecret, secret)
}
}
}
}
// Test ShareGroups.String() and StringLabelled() methods
func TestShareGroupsStringMethods(t *testing.T) {
t.Parallel()
secrets := mustLoadSecrets(t)
from, to := parseArgs(t)
for i, s := range secrets {
if from > 0 && i+1 < from {
continue
}
//fmt.Fprintf(os.Stderr, "secret: %v\n", s)
masterSecretBytes, err := hex.DecodeString(s.MasterSecret)
if err != nil {
t.Errorf("hex.DecodeString returned error: %s", err.Error())
}
shareGroups, err := GenerateMnemonics(
s.GroupThreshold, s.MemberGroupParams, masterSecretBytes,
)
if err != nil {
t.Error(err)
}
//t.Logf("shareGroups (%d group(s)): %v\n", len(shareGroups), shareGroups)
str := shareGroups.String()
//t.Logf("[%d] shareGroups.String(): %s", i+1, str)
lstr, err := shareGroups.StringLabelled()
if err != nil {
t.Fatal(err)
}
//t.Logf("[%d] shareGroups.StringLabelled(): %s", i+1, lstr)
// Recombine the labelled shares
sg2, err := CombineLabelledShares(lstr)
if err != nil {
t.Fatal(err)
}
str2 := sg2.String()
if str2 != str {
t.Errorf("CombineLabelledShares mismatch: want:\n%sgot:\n%s",
str, str2)
}
if to > 0 && i+1 >= to {
break
}
}
}
// Test ShareGroups.StringLabelled() failures
func TestShareGroupsStringLabelled_Failures(t *testing.T) {
t.Parallel()
var tests = []struct {
label string
input string
}{
// 3-digit SW non-consecutive wordNum
{"3-digit SW non-consecutive wordNum",
"101 duckling\n103 enlarge"},
{"3-digit SW non-consecutive wordNum",
"101 duckling\n101 enlarge"},
{"3-digit SW non-consecutive wordNum",
"102 duckling\n101 enlarge"},
{"3-digit SW non-consecutive wordNum",
"105 duckling\n101 enlarge"},
// 3-digit SW non-consecutive shareNum
{"3-digit SW non-consecutive shareNum",
"101 duckling\n301 enlarge"},
{"3-digit SW non-consecutive shareNum",
"101 duckling\n101 enlarge"},
{"3-digit SW non-consecutive shareNum",
"301 duckling\n101 enlarge"},
{"3-digit SW non-consecutive shareNum",
"501 duckling\n201 enlarge"},
// 4-digit SW non-consecutive wordNum
{"4-digit SW non-consecutive wordNum",
"0101 duckling\n0103 enlarge"},
{"4-digit SW non-consecutive wordNum",
"0101 duckling\n0101 enlarge"},
{"4-digit SW non-consecutive wordNum",
"0102 duckling\n0101 enlarge"},
{"4-digit SW non-consecutive wordNum",
"0105 duckling\n0101 enlarge"},
// 4-digit SW non-consecutive shareNum
{"4-digit SW non-consecutive shareNum",
"0101 duckling\n0301 enlarge"},
{"4-digit SW non-consecutive shareNum",
"0101 duckling\n0101 enlarge"},
{"4-digit SW non-consecutive shareNum",
"0301 duckling\n0101 enlarge"},
{"4-digit SW non-consecutive shareNum",
"0501 duckling\n0201 enlarge"},
// 5-digit GSW non-consecutive wordNum
{"5-digit GSW non-consecutive wordNum",
"10101 duckling\n10103 enlarge"},
{"5-digit GSW non-consecutive wordNum",
"10101 duckling\n10101 enlarge"},
{"5-digit GSW non-consecutive wordNum",
"10102 duckling\n10101 enlarge"},
{"5-digit GSW non-consecutive wordNum",
"10105 duckling\n10101 enlarge"},
// 5-digit GSW non-consecutive shareNum
{"5-digit GSW non-consecutive shareNum",
"10101 duckling\n10301 enlarge"},
{"5-digit GSW non-consecutive shareNum",
"10101 duckling\n10101 enlarge"},
{"5-digit GSW non-consecutive shareNum",
"10301 duckling\n10101 enlarge"},
{"5-digit GSW non-consecutive shareNum",
"10501 duckling\n10201 enlarge"},
// 5-digit GSW non-consecutive groupNum
{"5-digit GSW non-consecutive groupNum",
"10101 duckling\n10101 enlarge"},
{"5-digit GSW non-consecutive groupNum",
"20101 duckling\n10101 enlarge"},
{"5-digit GSW non-consecutive groupNum",
"30101 duckling\n10101 enlarge"},
{"5-digit GSW non-consecutive groupNum",
"10101 duckling\n30101 enlarge"},
{"5-digit GSW non-consecutive groupNum",
"10101 duckling\n90101 enlarge"},
// 5-digit GSW non-consecutive wordNum
{"5-digit GSW non-consecutive wordNum",
"01101 duckling\n01103 enlarge"},
{"5-digit GSW non-consecutive wordNum",
"01101 duckling\n01101 enlarge"},
{"5-digit GSW non-consecutive wordNum",
"01102 duckling\n01101 enlarge"},
{"5-digit GSW non-consecutive wordNum",
"01105 duckling\n01101 enlarge"},
// 5-digit GSW non-consecutive shareNum
{"5-digit GSW non-consecutive shareNum",
"01101 duckling\n01301 enlarge"},
{"5-digit GSW non-consecutive shareNum",
"01101 duckling\n01101 enlarge"},
{"5-digit GSW non-consecutive shareNum",
"01301 duckling\n01101 enlarge"},
{"5-digit GSW non-consecutive shareNum",
"01501 duckling\n01201 enlarge"},
// 5-digit GSW non-consecutive groupNum
{"5-digit GSW non-consecutive groupNum",
"01101 duckling\n01101 enlarge"},
{"5-digit GSW non-consecutive groupNum",
"02101 duckling\n01101 enlarge"},
{"5-digit GSW non-consecutive groupNum",
"03101 duckling\n01101 enlarge"},
{"5-digit GSW non-consecutive groupNum",
"01101 duckling\n03101 enlarge"},
{"5-digit GSW non-consecutive groupNum",
"01101 duckling\n09101 enlarge"},
// 6-digit GSW non-consecutive wordNum
{"6-digit GSW non-consecutive wordNum",
"010101 duckling\n010103 enlarge"},
{"6-digit GSW non-consecutive wordNum",
"010101 duckling\n010101 enlarge"},
{"6-digit GSW non-consecutive wordNum",
"010102 duckling\n010101 enlarge"},
{"6-digit GSW non-consecutive wordNum",
"010105 duckling\n010101 enlarge"},
// 6-digit GSW non-consecutive shareNum
{"6-digit GSW non-consecutive shareNum",
"010101 duckling\n010301 enlarge"},
{"6-digit GSW non-consecutive shareNum",
"010101 duckling\n010101 enlarge"},
{"6-digit GSW non-consecutive shareNum",
"010301 duckling\n010101 enlarge"},
{"6-digit GSW non-consecutive shareNum",
"010501 duckling\n010201 enlarge"},
// 6-digit GSW non-consecutive groupNum
{"6-digit GSW non-consecutive groupNum",
"010101 duckling\n010101 enlarge"},
{"6-digit GSW non-consecutive groupNum",
"020101 duckling\n010101 enlarge"},
{"6-digit GSW non-consecutive groupNum",
"030101 duckling\n010101 enlarge"},
{"6-digit GSW non-consecutive groupNum",
"010101 duckling\n030101 enlarge"},
{"6-digit GSW non-consecutive groupNum",
"010101 duckling\n090101 enlarge"},
// Mixed-style labels
{"Mixed-style labels",
"010101 duckling\n0102 enlarge"},
{"Mixed-style labels",
"0101 duckling\n10102 enlarge"},
// Bad lastWord numbers
{"Bad lastword short 1",
"101 zoo\n"},
{"Bad lastword short 2",
"101 zoo\n102 zoo\n103 zoo\n104 zoo\n105 zoo\n106 zoo\n107 zoo\n108 zoo\n109 zoo\n110 zoo\n111 zoo\n112 zoo\n113 zoo\n114 zoo\n115 zoo\n116 zoo\n117 zoo\n118 zoo\n119 zoo\n120 zoo\n201 about\n"},
{"Bad lastword on share increment 1",
"101 zoo\n102 zoo\n103 zoo\n104 zoo\n105 zoo\n106 zoo\n107 zoo\n108 zoo\n109 zoo\n110 zoo\n111 zoo\n112 zoo\n113 zoo\n114 zoo\n115 zoo\n116 zoo\n117 zoo\n118 zoo\n119 zoo\n201 about\n"},
{"Bad lastword on share increment 2",
"101 zoo\n102 zoo\n103 zoo\n104 zoo\n105 zoo\n106 zoo\n107 zoo\n108 zoo\n109 zoo\n110 zoo\n111 zoo\n112 zoo\n113 zoo\n114 zoo\n115 zoo\n116 zoo\n117 zoo\n118 zoo\n119 zoo\n120 zoo\n121 zoo\n201 anchor\n"},
{"Bad lastword on group increment 1",
"1101 zoo\n1102 zoo\n1103 zoo\n1104 zoo\n1105 zoo\n1106 zoo\n1107 zoo\n1108 zoo\n1109 zoo\n1110 zoo\n1111 zoo\n1112 zoo\n1113 zoo\n1114 zoo\n1115 zoo\n1116 zoo\n1117 zoo\n1118 zoo\n1119 zoo\n2101 about\n"},
{"Bad lastword on group increment 2",
"1101 zoo\n1102 zoo\n1103 zoo\n1104 zoo\n1105 zoo\n1106 zoo\n1107 zoo\n1108 zoo\n1109 zoo\n1110 zoo\n1111 zoo\n1112 zoo\n1113 zoo\n1114 zoo\n1115 zoo\n1116 zoo\n1117 zoo\n1118 zoo\n1119 zoo\n1120 zoo\n1121zoo\n2101 anchor\n"},
}
for _, tc := range tests {
sg, err := CombineLabelledShares(tc.input)
if err == nil {
t.Errorf("%q test unexpectedly passed:\n%s", tc.label, sg.String())
/*
} else {
t.Logf("%q test failed as expected: %s", tc.label, err.Error())
*/
}
}
}