-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtool_test.go
396 lines (357 loc) · 11.6 KB
/
tool_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
// Copyright (C) 2021 io finnet group, inc.
// SPDX-License-Identifier: AGPL-3.0-or-later
// Full license text available in LICENSE file in repository root.
package main
import (
"encoding/hex"
"math/big"
"testing"
"github.com/IoFinnet/io-vault-disaster-recovery-cli/internal/ui"
"github.com/stretchr/testify/assert"
)
// Test fixture mnemonics. Used only for this purpose.
const (
mmI = "season pole chronic surround fiber stumble remove artwork muffin apart limit vacuum horror above donkey olympic earn dizzy addict gym animal leopard before unfair"
mmL = "casual gallery jump mad claw curve portion enrich oyster calm spoon flash hat soft dizzy example exile large provide smart magnet raven nurse prison"
mmM = "decade explain repeat popular pigeon sail atom enhance toy awake breeze draw focus desert movie skull news inherit cruel case start film used unit"
mmV2 = "ridge scare utility perfect trial van inflict feel top dice present monitor always order charge door curious lobster quick guide obvious danger crisp cinnamon"
// James test case mnemonics
mmNewBvn = "domain damp hill depth label eye erode dutch impulse betray floor donate bonus hover bitter ring unfold poet identify capital combine question profit april"
mmNewX2q = "found midnight praise exhibit weather neutral inmate strong grass famous blind pet frozen shock avocado ring fringe planet opera license stand coil beauty capable"
mmNewU44 = "aerobic foam smooth immune card tragic window myth planet notice piece agree add target tortoise weather kite track spot dish dignity twice gadget spell"
// Single Signer test case mnemonics
mmNewSingle = "jacket zone rotate merry forward paper cruel forget train prevent teach bitter lumber razor uncle stairs finger chief curtain render tray tower odor garbage"
)
func TestTool_New_V2_List(t *testing.T) {
files := []ui.VaultsDataFile{
{File: "./test-files/new_bvn.json", Mnemonics: mmNewBvn},
{File: "./test-files/new_x2q.json", Mnemonics: mmNewX2q},
{File: "./test-files/new_u44.json", Mnemonics: mmNewU44},
}
// use the correct file path for tests
address, ecSK, edSK, vaultFormData, err := runTool(files, nil, nil, nil, nil, nil)
if !assert.NoError(t, err) {
return
}
if !assert.Len(t, vaultFormData, 14) {
return
}
vaultIDs := vaultIdsFromFormData(vaultFormData)
if !assert.Equal(t,
[]string{
"a70uaean4isi6aci8zzky970",
"afpuzaa5j3k7wyjfgkuvbcxz",
"bfc8uksrk5zuxihufj4m8dkt",
"d1rqfhghbr1qy819iym5dgyv",
"dfqyrx0f7vevbjx9o5yrg7gw",
"e0wspn90rz8vnngv0kdklaog",
"ejrye15wiew2201f3fahho8k",
"iesd46upmcrwnu0qojph9hst",
"liw3bn8yqykgh96uort11knz",
"nbpxb6hmupk1ygcl53jf9zg5",
"ngo46g83iug985q3fxyhsp4w",
"prd15bna3h9oxoo04dc4cn1p",
"yz5x2a7zhwwt7r0lv4gklqns",
"zbgtamgot1f6u51kt6bsn5qr",
}, vaultIDs) {
return
}
if !assert.Empty(t, address) {
return
}
if !assert.Nil(t, ecSK) || !assert.Nil(t, edSK) {
return
}
}
func TestTool_New_V2_Export_lqns(t *testing.T) {
// use the correct file path for tests
vaultID := "yz5x2a7zhwwt7r0lv4gklqns"
files := []ui.VaultsDataFile{
{File: "./test-files/new_bvn.json", Mnemonics: mmNewBvn},
{File: "./test-files/new_x2q.json", Mnemonics: mmNewX2q},
{File: "./test-files/new_u44.json", Mnemonics: mmNewU44},
}
address, ecSK, edSK, vaultsFormData, err := runTool(files, &vaultID, nil, nil, nil, nil)
if !assert.NoError(t, err) {
return
}
if !assert.Len(t, vaultsFormData, 1) {
return
}
if !assert.Equal(t, vaultID, vaultsFormData[0].VaultID) {
return
}
if !assert.Equal(t, "0x620Ac72121234f1b313BD4e8b78C81323502679A", address) {
return
}
if !assert.Equal(t, "4cc05b1d3216da8ef91729744159019b25ea1ed5932e387199f1de6ff6667ac2",
hex.EncodeToString(ecSK)) {
return
}
if !assert.Equal(t, "0e6f0e12d72483d32255000d01242fa4e179b9bbfa060de26cfb9c84e1d02d9e",
hex.EncodeToString(edSK)) {
return
}
}
func TestTool_NewSingle_V2_List(t *testing.T) {
files := []ui.VaultsDataFile{
{File: "./test-files/new_single.json", Mnemonics: mmNewSingle},
}
// use the correct file path for tests
address, _, edSK, vaultFormData, err := runTool(files, nil, nil, nil, nil, nil)
if !assert.NoError(t, err) {
return
}
if !assert.Len(t, vaultFormData, 1) {
return
}
vaultIDs := vaultIdsFromFormData(vaultFormData)
if !assert.Contains(t, vaultIDs, "phrot42ltzawmn7nrm7mqvl5", "vaults must contain expected vaultId qvl5") {
return
}
if !assert.Empty(t, address) {
return
}
if !assert.Nil(t, edSK) {
return
}
}
func TestTool_NewSingle_V2_List_BadMnemonic(t *testing.T) {
files := []ui.VaultsDataFile{
{File: "./test-files/new_single.json", Mnemonics: mmV2},
}
// use the correct file path for tests
_, _, _, _, err := runTool(files, nil, nil, nil, nil, nil)
if !assert.Error(t, err) {
return
}
}
func TestTool_NewSingle_V2_Export_qvl5(t *testing.T) {
// use the correct file path for tests
vaultID := "phrot42ltzawmn7nrm7mqvl5"
files := []ui.VaultsDataFile{
{File: "./test-files/new_single.json", Mnemonics: mmNewSingle},
}
_, ecSK, edSK, vaultsFormData, err := runTool(files, &vaultID, nil, nil, nil, nil)
if !assert.NoError(t, err) {
return
}
if !assert.Len(t, vaultsFormData, 1) {
return
}
if !assert.Equal(t, vaultID, vaultsFormData[0].VaultID) {
return
}
if !assert.Equal(t, "0a8376f6cb75d7e4197d35d2f7254f60f08827d5604589ea57843c3f754983b7",
hex.EncodeToString(ecSK)) {
return
}
if !assert.Equal(t, "04523b4b19d426517fb20b51935bc969900e016d26da0a3357f4cb1af57d8e44",
hex.EncodeToString(edSK)) {
return
}
}
func TestTool_NewSingle_V2_Export_qvl5_BadMnemonic(t *testing.T) {
// use the correct file path for tests
vaultID := "phrot42ltzawmn7nrm7mqvl5"
files := []ui.VaultsDataFile{
{File: "./test-files/new_single.json", Mnemonics: mmV2},
}
_, _, _, _, err := runTool(files, &vaultID, nil, nil, nil, nil)
if !assert.Error(t, err) {
return
}
}
func TestTool_Legacy_V2_List(t *testing.T) {
files := []ui.VaultsDataFile{
{File: "./test-files/v2.json", Mnemonics: mmV2},
}
// use the correct file path for tests
address, ecSK, edSK, vaultsFormData, err := runTool(files, nil, nil, nil, nil, nil)
if !assert.NoError(t, err) {
return
}
if !assert.Len(t, vaultsFormData, 1) {
return
}
if !assert.Equal(t, "yjanjbgmbrptwwa9i5v9c20x", vaultsFormData[0].VaultID) {
return
}
if !assert.Empty(t, address) {
return
}
if !assert.Nil(t, ecSK) || !assert.Nil(t, edSK) {
return
}
}
func TestTool_Legacy_V2_Export_c20x(t *testing.T) {
// use the correct file path for tests
vaultID := "yjanjbgmbrptwwa9i5v9c20x"
files := []ui.VaultsDataFile{
{File: "./test-files/v2.json", Mnemonics: mmV2},
}
address, ecSK, edSK, vaultsFormData, err := runTool(files, &vaultID, nil, nil, nil, nil)
if !assert.NoError(t, err) {
return
}
if !assert.Len(t, vaultsFormData, 1) {
return
}
if !assert.Equal(t, vaultID, vaultsFormData[0].VaultID) {
return
}
if !assert.Equal(t, "0x66e36b136fb8b2C98c72eEC8Ae02D531e526f454", address) {
return
}
if !assert.Equal(t, "9ca4dc783e108938e81b06d76d7b74ec4488e1acc9c569eedfaf4c949c3531d7",
hex.EncodeToString(ecSK)) {
return
}
// no EdDSA key for this vault
if !assert.Nil(t, edSK) {
return
}
}
func TestTool_Legacy_V1_IL_List(t *testing.T) {
// use the correct file path for tests
files := []ui.VaultsDataFile{
{File: "./test-files/i.json", Mnemonics: mmI},
{File: "./test-files/l.json", Mnemonics: mmL},
}
address, ecSK, edSK, vaultsFormData, err := runTool(files, nil, nil, nil, nil, nil)
if !assert.NoError(t, err) {
return
}
if !assert.Len(t, vaultsFormData, 6) {
return
}
vaultIDs := vaultIdsFromFormData(vaultsFormData)
if !assert.Equal(t, []string{
"clujhtm9d0013wc3xso1b2m0k", "clujmawnb001j173x9a2c0x47", "clujn9hhr001u173xiv9gfme6", "clujnasrf001x173xjxtcwzeq", "clul2s3f70008yf3x7mada0gb", "clur52dfl0001vc3xlbdy1d7p",
}, vaultIDs) {
return
}
if !assert.Empty(t, address) {
return
}
if !assert.Nil(t, ecSK) || !assert.Nil(t, edSK) {
return
}
}
func TestTool_Legacy_V1_IL_Export_m0k(t *testing.T) {
// use the correct file path for tests
vaultID := "clujhtm9d0013wc3xso1b2m0k"
files := []ui.VaultsDataFile{
{File: "./test-files/i.json", Mnemonics: mmI},
{File: "./test-files/l.json", Mnemonics: mmL},
}
address, ecSK, edSK, vaultFormData, err := runTool(files, &vaultID, nil, nil, nil, nil)
if !assert.NoError(t, err) {
return
}
vaultIDs := vaultIdsFromFormData(vaultFormData)
if !assert.Len(t, vaultIDs, 1) {
return
}
if !assert.Equal(t, vaultID, vaultIDs[0]) {
return
}
if !assert.Equal(t, "0x66EE83F83002b01459B750233F7B21744E679182", address) {
return
}
if !assert.Equal(t, "7d3c016f339f8cc797ee35502a5c93416d47bdd04360d22ea4fcaf85cec229b3",
hex.EncodeToString(ecSK)) {
return
}
// no EdDSA key for this vault
if !assert.Nil(t, edSK) {
return
}
}
func TestTool_Legacy_V1_ILM_List(t *testing.T) {
// use the correct file path for tests
files := []ui.VaultsDataFile{
{File: "./test-files/i.json", Mnemonics: mmI},
{File: "./test-files/m.json", Mnemonics: mmM},
{File: "./test-files/l.json", Mnemonics: mmL},
}
address, ecSK, edSK, vaultsFormData, err := runTool(files, nil, nil, nil, nil, nil)
if !assert.NoError(t, err) {
return
}
if !assert.Len(t, vaultsFormData, 6) {
return
}
vaultIDs := vaultIdsFromFormData(vaultsFormData)
if !assert.Equal(t, []string{
"clujhtm9d0013wc3xso1b2m0k", "clujmawnb001j173x9a2c0x47", "clujn9hhr001u173xiv9gfme6", "clujnasrf001x173xjxtcwzeq", "clul2s3f70008yf3x7mada0gb", "clur52dfl0001vc3xlbdy1d7p",
}, vaultIDs) {
return
}
if !assert.Empty(t, address) {
return
}
if !assert.Nil(t, ecSK) || !assert.Nil(t, edSK) {
return
}
}
func TestTool_Legacy_V1_ILM_Export_m0k(t *testing.T) {
// use the correct file path for tests
vaultID := "clujhtm9d0013wc3xso1b2m0k"
files := []ui.VaultsDataFile{
{File: "./test-files/i.json", Mnemonics: mmI},
{File: "./test-files/m.json", Mnemonics: mmM},
{File: "./test-files/l.json", Mnemonics: mmL},
}
address, ecSK, edSK, vaultsFormData, err := runTool(files, &vaultID, nil, nil, nil, nil)
if !assert.NoError(t, err) {
return
}
if !assert.Len(t, vaultsFormData, 1) {
return
}
if !assert.Equal(t, vaultID, vaultsFormData[0].VaultID) {
return
}
if !assert.Equal(t, "0x66EE83F83002b01459B750233F7B21744E679182", address) {
return
}
if !assert.Equal(t, "7d3c016f339f8cc797ee35502a5c93416d47bdd04360d22ea4fcaf85cec229b3",
hex.EncodeToString(ecSK)) {
return
}
// no EdDSA key for this vault
if !assert.Nil(t, edSK) {
return
}
}
func vaultIdsFromFormData(vaultFormData []ui.VaultPickerItem) []string {
vaultIDs := make([]string, len(vaultFormData))
for i, v := range vaultFormData {
vaultIDs[i] = v.VaultID
}
return vaultIDs
}
func TestLeftPadTo32Bytes(t *testing.T) {
bytes32Input, _ := hex.DecodeString("04523b4b19d426517fb20b51935bc969900e016d26da0a3357f4cb1af57d8e44")
bytes34Input, _ := hex.DecodeString("04523b4b19d426517fb20b51935bc969900e016d26da0a3357f4cb1af57d8e440f0f")
tests := []struct {
name string
input []byte
expected string
}{
{"Nil Input", nil, "0000000000000000000000000000000000000000000000000000000000000000"},
{"Empty Input", []byte{}, "0000000000000000000000000000000000000000000000000000000000000000"},
{"Short Input", []byte{0xab, 0xcd}, "000000000000000000000000000000000000000000000000000000000000abcd"},
{"32 Bytes Input", bytes32Input, "04523b4b19d426517fb20b51935bc969900e016d26da0a3357f4cb1af57d8e44"},
{"Long Input", bytes34Input, "04523b4b19d426517fb20b51935bc969900e016d26da0a3357f4cb1af57d8e440f0f"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := leftPadTo32Bytes(new(big.Int).SetBytes(tt.input))
if !assert.Equal(t, tt.expected, hex.EncodeToString(result)) {
return
}
})
}
}