]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/BIP39.git/blob - tests.js
Test address table shows derivation path
[perso/Immae/Projets/Cryptomonnaies/BIP39.git] / tests.js
1 // Usage:
2 // $ phantomjs tests.js
3
4
5 var page = require('webpage').create();
6 var url = 'src/index.html';
7 var testMaxTime = 5000;
8
9 page.onResourceError = function(e) {
10 console.log("Error loading " + e.url);
11 phantom.exit();
12 }
13
14 function fail() {
15 console.log("Failed");
16 phantom.exit();
17 }
18
19 function waitForGenerate(fn, maxTime) {
20 if (!maxTime) {
21 maxTime = testMaxTime;
22 }
23 var start = new Date().getTime();
24 var prevAddressCount = -1;
25 var wait = function keepWaiting() {
26 var now = new Date().getTime();
27 var hasTimedOut = now - start > maxTime;
28 var addressCount = page.evaluate(function() {
29 return $(".address").length;
30 });
31 var hasFinished = addressCount > 0 && addressCount == prevAddressCount;
32 prevAddressCount = addressCount;
33 if (hasFinished) {
34 fn();
35 }
36 else if (hasTimedOut) {
37 console.log("Test timed out");
38 fn();
39 }
40 else {
41 setTimeout(keepWaiting, 100);
42 }
43 }
44 wait();
45 }
46
47 function next() {
48 if (tests.length > 0) {
49 var testsStr = tests.length == 1 ? "test" : "tests";
50 console.log(tests.length + " " + testsStr + " remaining");
51 tests.shift()();
52 }
53 else {
54 console.log("Finished with 0 failures");
55 phantom.exit();
56 }
57 }
58
59 /**
60 * Randomize array element order in-place.
61 * Using Durstenfeld shuffle algorithm.
62 * See http://stackoverflow.com/a/12646864
63 */
64 function shuffle(array) {
65 for (var i = array.length - 1; i > 0; i--) {
66 var j = Math.floor(Math.random() * (i + 1));
67 var temp = array[i];
68 array[i] = array[j];
69 array[j] = temp;
70 }
71 return array;
72 }
73
74 tests = [
75
76 // Page loads with status of 'success'
77 function() {
78 page.open(url, function(status) {
79 if (status != "success") {
80 console.log("Page did not load with status 'success'");
81 fail();
82 }
83 next();
84 });
85 },
86
87 // Page has text
88 function() {
89 page.open(url, function(status) {
90 var content = page.evaluate(function() {
91 return document.body.textContent.trim();
92 });
93 if (!content) {
94 console.log("Page does not have text");
95 fail();
96 }
97 next();
98 });
99 },
100
101 // Entering mnemonic generates addresses
102 function() {
103 page.open(url, function(status) {
104 var expected = "1Di3Vp7tBWtyQaDABLAjfWtF6V7hYKJtug";
105 // set the phrase
106 page.evaluate(function() {
107 $(".phrase").val("abandon abandon ability").trigger("input");
108 });
109 // get the address
110 waitForGenerate(function() {
111 var actual = page.evaluate(function() {
112 return $(".address:first").text();
113 });
114 if (actual != expected) {
115 console.log("Mnemonic did not generate address");
116 console.log("Expected: " + expected);
117 console.log("Got: " + actual);
118 fail();
119 }
120 next();
121 });
122 });
123 },
124
125 // Random button generates random mnemonic
126 function() {
127 page.open(url, function(status) {
128 // check initial phrase is empty
129 var phrase = page.evaluate(function() {
130 return $(".phrase").text();
131 });
132 if (phrase != "") {
133 console.log("Initial phrase is not blank");
134 fail();
135 }
136 // press the 'generate' button
137 page.evaluate(function() {
138 $(".generate").click();
139 });
140 // get the new phrase
141 waitForGenerate(function() {
142 var phrase = page.evaluate(function() {
143 return $(".phrase").val();
144 });
145 if (phrase.length <= 0) {
146 console.log("Phrase not generated by pressing button");
147 fail();
148 }
149 next();
150 });
151 });
152 },
153
154 // Mnemonic length can be customized
155 function() {
156 page.open(url, function(status) {
157 // set the length to 6
158 var expectedLength = "6";
159 page.evaluate(function() {
160 $(".strength option[selected]").removeAttr("selected");
161 $(".strength option[value=6]").prop("selected", true);
162 });
163 // press the 'generate' button
164 page.evaluate(function() {
165 $(".generate").click();
166 });
167 // check the new phrase is six words long
168 waitForGenerate(function() {
169 var actualLength = page.evaluate(function() {
170 var words = $(".phrase").val().split(" ");
171 return words.length;
172 });
173 if (actualLength != expectedLength) {
174 console.log("Phrase not generated with correct length");
175 console.log("Expected: " + expectedLength);
176 console.log("Actual: " + actualLength);
177 fail();
178 }
179 next();
180 });
181 });
182 },
183
184 // Passphrase can be set
185 function() {
186 page.open(url, function(status) {
187 // set the phrase and passphrase
188 var expected = "15pJzUWPGzR7avffV9nY5by4PSgSKG9rba";
189 page.evaluate(function() {
190 $(".phrase").val("abandon abandon ability");
191 $(".passphrase").val("secure_passphrase").trigger("input");
192 });
193 // check the address is generated correctly
194 waitForGenerate(function() {
195 var actual = page.evaluate(function() {
196 return $(".address:first").text();
197 });
198 if (actual != expected) {
199 console.log("Passphrase results in wrong address");
200 console.log("Expected: " + expected);
201 console.log("Actual: " + actual);
202 fail();
203 }
204 next();
205 });
206 });
207 },
208
209 // Network can be set to bitcoin testnet
210 function() {
211 page.open(url, function(status) {
212 // set the phrase and coin
213 var expected = "mucaU5iiDaJDb69BHLeDv8JFfGiyg2nJKi";
214 page.evaluate(function() {
215 $(".phrase").val("abandon abandon ability");
216 $(".phrase").trigger("input");
217 $(".network option[selected]").removeAttr("selected");
218 $(".network option[value=1]").prop("selected", true);
219 $(".network").trigger("change");
220 });
221 // check the address is generated correctly
222 waitForGenerate(function() {
223 var actual = page.evaluate(function() {
224 return $(".address:first").text();
225 });
226 if (actual != expected) {
227 console.log("Bitcoin testnet address is incorrect");
228 console.log("Expected: " + expected);
229 console.log("Actual: " + actual);
230 fail();
231 }
232 next();
233 });
234 });
235 },
236
237 // Network can be set to litecoin
238 function() {
239 page.open(url, function(status) {
240 // set the phrase and coin
241 var expected = "LQ4XU8RX2ULPmPq9FcUHdVmPVchP9nwXdn";
242 page.evaluate(function() {
243 $(".phrase").val("abandon abandon ability");
244 $(".phrase").trigger("input");
245 $(".network option[selected]").removeAttr("selected");
246 $(".network option[value=2]").prop("selected", true);
247 $(".network").trigger("change");
248 });
249 // check the address is generated correctly
250 waitForGenerate(function() {
251 var actual = page.evaluate(function() {
252 return $(".address:first").text();
253 });
254 if (actual != expected) {
255 console.log("Litecoin address is incorrect");
256 console.log("Expected: " + expected);
257 console.log("Actual: " + actual);
258 fail();
259 }
260 next();
261 });
262 });
263 },
264
265 // Network can be set to dogecoin
266 function() {
267 page.open(url, function(status) {
268 // set the phrase and coin
269 var expected = "DPQH2AtuzkVSG6ovjKk4jbUmZ6iXLpgbJA";
270 page.evaluate(function() {
271 $(".phrase").val("abandon abandon ability");
272 $(".phrase").trigger("input");
273 $(".network option[selected]").removeAttr("selected");
274 $(".network option[value=3]").prop("selected", true);
275 $(".network").trigger("change");
276 });
277 // check the address is generated correctly
278 waitForGenerate(function() {
279 var actual = page.evaluate(function() {
280 return $(".address:first").text();
281 });
282 if (actual != expected) {
283 console.log("Dogecoin address is incorrect");
284 console.log("Expected: " + expected);
285 console.log("Actual: " + actual);
286 fail();
287 }
288 next();
289 });
290 });
291 },
292
293 // Network can be set to shadowcash
294 function() {
295 page.open(url, function(status) {
296 // set the phrase and coin
297 var expected = "SiSZtfYAXEFvMm3XM8hmtkGDyViRwErtCG";
298 page.evaluate(function() {
299 $(".phrase").val("abandon abandon ability");
300 $(".phrase").trigger("input");
301 $(".network option[selected]").removeAttr("selected");
302 $(".network option[value=4]").prop("selected", true);
303 $(".network").trigger("change");
304 });
305 // check the address is generated correctly
306 waitForGenerate(function() {
307 var actual = page.evaluate(function() {
308 return $(".address:first").text();
309 });
310 if (actual != expected) {
311 console.log("Shadowcash address is incorrect");
312 console.log("Expected: " + expected);
313 console.log("Actual: " + actual);
314 fail();
315 }
316 next();
317 });
318 });
319 },
320
321 // Network can be set to shadowcash testnet
322 function() {
323 page.open(url, function(status) {
324 // set the phrase and coin
325 var expected = "tM2EDpVKaTiEg2NZg3yKg8eqjLr55BErHe";
326 page.evaluate(function() {
327 $(".phrase").val("abandon abandon ability");
328 $(".phrase").trigger("input");
329 $(".network option[selected]").removeAttr("selected");
330 $(".network option[value=5]").prop("selected", true);
331 $(".network").trigger("change");
332 });
333 // check the address is generated correctly
334 waitForGenerate(function() {
335 var actual = page.evaluate(function() {
336 return $(".address:first").text();
337 });
338 if (actual != expected) {
339 console.log("Shadowcash testnet address is incorrect");
340 console.log("Expected: " + expected);
341 console.log("Actual: " + actual);
342 fail();
343 }
344 next();
345 });
346 });
347 },
348
349 // Network can be set to viacoin
350 function() {
351 page.open(url, function(status) {
352 // set the phrase and coin
353 var expected = "Vq9Eq4N5SQnjqZvxtxzo7hZPW5XnyJsmXT";
354 page.evaluate(function() {
355 $(".phrase").val("abandon abandon ability");
356 $(".phrase").trigger("input");
357 $(".network option[selected]").removeAttr("selected");
358 $(".network option[value=6]").prop("selected", true);
359 $(".network").trigger("change");
360 });
361 // check the address is generated correctly
362 waitForGenerate(function() {
363 var actual = page.evaluate(function() {
364 return $(".address:first").text();
365 });
366 if (actual != expected) {
367 console.log("Viacoin address is incorrect");
368 console.log("Expected: " + expected);
369 console.log("Actual: " + actual);
370 fail();
371 }
372 next();
373 });
374 });
375 },
376
377 // Network can be set to viacoin testnet
378 function() {
379 page.open(url, function(status) {
380 // set the phrase and coin
381 var expected = "tM2EDpVKaTiEg2NZg3yKg8eqjLr55BErHe";
382 page.evaluate(function() {
383 $(".phrase").val("abandon abandon ability");
384 $(".phrase").trigger("input");
385 $(".network option[selected]").removeAttr("selected");
386 $(".network option[value=7]").prop("selected", true);
387 $(".network").trigger("change");
388 });
389 // check the address is generated correctly
390 waitForGenerate(function() {
391 var actual = page.evaluate(function() {
392 return $(".address:first").text();
393 });
394 if (actual != expected) {
395 console.log("Viacoin testnet address is incorrect");
396 console.log("Expected: " + expected);
397 console.log("Actual: " + actual);
398 fail();
399 }
400 next();
401 });
402 });
403 },
404
405 // Network can be set to jumbucks
406 function() {
407 page.open(url, function(status) {
408 // set the phrase and coin
409 var expected = "JLEXccwDXADK4RxBPkRez7mqsHVoJBEUew";
410 page.evaluate(function() {
411 $(".phrase").val("abandon abandon ability");
412 $(".phrase").trigger("input");
413 $(".network option[selected]").removeAttr("selected");
414 $(".network option[value=8]").prop("selected", true);
415 $(".network").trigger("change");
416 });
417 // check the address is generated correctly
418 waitForGenerate(function() {
419 var actual = page.evaluate(function() {
420 return $(".address:first").text();
421 });
422 if (actual != expected) {
423 console.log("Jumbucks address is incorrect");
424 console.log("Expected: " + expected);
425 console.log("Actual: " + actual);
426 fail();
427 }
428 next();
429 });
430 });
431 },
432
433 // Network can be set to clam
434 function() {
435 page.open(url, function(status) {
436 // set the phrase and coin
437 var expected = "xCp4sakjVx4pUAZ6cBCtuin8Ddb6U1sk9y";
438 page.evaluate(function() {
439 $(".phrase").val("abandon abandon ability");
440 $(".phrase").trigger("input");
441 $(".network option[selected]").removeAttr("selected");
442 $(".network option[value=9]").prop("selected", true);
443 $(".network").trigger("change");
444 });
445 // check the address is generated correctly
446 waitForGenerate(function() {
447 var actual = page.evaluate(function() {
448 return $(".address:first").text();
449 });
450 if (actual != expected) {
451 console.log("CLAM address is incorrect");
452 console.log("Expected: " + expected);
453 console.log("Actual: " + actual);
454 fail();
455 }
456 next();
457 });
458 });
459 },
460
461 // BIP39 seed is set from phrase
462 function() {
463 page.open(url, function(status) {
464 // set the phrase
465 var expected = "20da140d3dd1df8713cefcc4d54ce0e445b4151027a1ab567b832f6da5fcc5afc1c3a3f199ab78b8e0ab4652efd7f414ac2c9a3b81bceb879a70f377aa0a58f3";
466 page.evaluate(function() {
467 $(".phrase").val("abandon abandon ability");
468 $(".phrase").trigger("input");
469 });
470 // check the address is generated correctly
471 waitForGenerate(function() {
472 var actual = page.evaluate(function() {
473 return $(".seed").val();
474 });
475 if (actual != expected) {
476 console.log("BIP39 seed is incorrectly generated from mnemonic");
477 console.log("Expected: " + expected);
478 console.log("Actual: " + actual);
479 fail();
480 }
481 next();
482 });
483 });
484 },
485
486 // BIP32 root key is set from phrase
487 function() {
488 page.open(url, function(status) {
489 // set the phrase
490 var expected = "xprv9s21ZrQH143K2jkGDCeTLgRewT9F2pH5JZs2zDmmjXes34geVnFiuNa8KTvY5WoYvdn4Ag6oYRoB6cXtc43NgJAEqDXf51xPm6fhiMCKwpi";
491 page.evaluate(function() {
492 $(".phrase").val("abandon abandon ability");
493 $(".phrase").trigger("input");
494 });
495 // check the address is generated correctly
496 waitForGenerate(function() {
497 var actual = page.evaluate(function() {
498 return $(".root-key").val();
499 });
500 if (actual != expected) {
501 console.log("Root key is incorrectly generated from mnemonic");
502 console.log("Expected: " + expected);
503 console.log("Actual: " + actual);
504 fail();
505 }
506 next();
507 });
508 });
509 },
510
511 // Tabs show correct addresses when changed
512 function() {
513 page.open(url, function(status) {
514 // set the phrase
515 var expected = "17uQ7s2izWPwBmEVFikTmZUjbBKWYdJchz";
516 page.evaluate(function() {
517 $(".phrase").val("abandon abandon ability");
518 $(".phrase").trigger("input");
519 });
520 // change tabs
521 waitForGenerate(function() {
522 page.evaluate(function() {
523 $("#bip32-tab a").click();
524 });
525 // check the address is generated correctly
526 waitForGenerate(function() {
527 var actual = page.evaluate(function() {
528 return $(".address:first").text();
529 });
530 if (actual != expected) {
531 console.log("Clicking tab generates incorrect address");
532 console.log("Expected: " + expected);
533 console.log("Actual: " + actual);
534 fail();
535 }
536 next();
537 });
538 });
539 });
540 },
541
542 // BIP44 derivation path is shown
543 function() {
544 page.open(url, function(status) {
545 // set the phrase
546 var expected = "m/44'/0'/0'/0";
547 page.evaluate(function() {
548 $(".phrase").val("abandon abandon ability");
549 $(".phrase").trigger("input");
550 });
551 // check the derivation path of the first address
552 waitForGenerate(function() {
553 var actual = page.evaluate(function() {
554 return $("#bip44 .path").val();
555 });
556 if (actual != expected) {
557 console.log("BIP44 derivation path is incorrect");
558 console.log("Expected: " + expected);
559 console.log("Actual: " + actual);
560 fail();
561 }
562 next();
563 });
564 });
565 },
566
567 // BIP44 extended private key is shown
568 function() {
569 page.open(url, function(status) {
570 // set the phrase
571 var expected = "xprvA2DxxvPZcyRvYgZMGS53nadR32mVDeCyqQYyFhrCVbJNjPoxMeVf7QT5g7mQASbTf9Kp4cryvcXnu2qurjWKcrdsr91jXymdCDNxKgLFKJG";
572 page.evaluate(function() {
573 $(".phrase").val("abandon abandon ability");
574 $(".phrase").trigger("input");
575 });
576 // check the BIP44 extended private key
577 waitForGenerate(function() {
578 var actual = page.evaluate(function() {
579 return $(".extended-priv-key").val();
580 });
581 if (actual != expected) {
582 console.log("BIP44 extended private key is incorrect");
583 console.log("Expected: " + expected);
584 console.log("Actual: " + actual);
585 fail();
586 }
587 next();
588 });
589 });
590 },
591
592 // BIP44 extended public key is shown
593 function() {
594 page.open(url, function(status) {
595 // set the phrase
596 var expected = "xpub6FDKNRvTTLzDmAdpNTc49ia9b4byd6vqCdUa46Fp3vqMcC96uBoufCmZXQLiN5AK3iSCJMhf9gT2sxkpyaPepRuA7W3MujV5tGmF5VfbueM";
597 page.evaluate(function() {
598 $(".phrase").val("abandon abandon ability");
599 $(".phrase").trigger("input");
600 });
601 // check the BIP44 extended public key
602 waitForGenerate(function() {
603 var actual = page.evaluate(function() {
604 return $(".extended-pub-key").val();
605 });
606 if (actual != expected) {
607 console.log("BIP44 extended public key is incorrect");
608 console.log("Expected: " + expected);
609 console.log("Actual: " + actual);
610 fail();
611 }
612 next();
613 });
614 });
615 },
616
617 // BIP44 purpose field changes address list
618 function() {
619 page.open(url, function(status) {
620 // set the phrase
621 var expected = "1JbDzRJ2cDT8aat2xwKd6Pb2zzavow5MhF";
622 page.evaluate(function() {
623 $(".phrase").val("abandon abandon ability");
624 $(".phrase").trigger("input");
625 });
626 waitForGenerate(function() {
627 // change the bip44 purpose field to 45
628 page.evaluate(function() {
629 $("#bip44 .purpose").val("45");
630 $("#bip44 .purpose").trigger("input");
631 });
632 waitForGenerate(function() {
633 // check the address for the new derivation path
634 var actual = page.evaluate(function() {
635 return $(".address:first").text();
636 });
637 if (actual != expected) {
638 console.log("BIP44 purpose field generates incorrect address");
639 console.log("Expected: " + expected);
640 console.log("Actual: " + actual);
641 fail();
642 }
643 next();
644 });
645 });
646 });
647 },
648
649 // BIP44 coin field changes address list
650 function() {
651 page.open(url, function(status) {
652 // set the phrase
653 var expected = "1F6dB2djQYrxoyfZZmfr6D5voH8GkJTghk";
654 page.evaluate(function() {
655 $(".phrase").val("abandon abandon ability");
656 $(".phrase").trigger("input");
657 });
658 waitForGenerate(function() {
659 // change the bip44 purpose field to 45
660 page.evaluate(function() {
661 $("#bip44 .coin").val("1");
662 $("#bip44 .coin").trigger("input");
663 });
664 waitForGenerate(function() {
665 // check the address for the new derivation path
666 var actual = page.evaluate(function() {
667 return $(".address:first").text();
668 });
669 if (actual != expected) {
670 console.log("BIP44 coin field generates incorrect address");
671 console.log("Expected: " + expected);
672 console.log("Actual: " + actual);
673 fail();
674 }
675 next();
676 });
677 });
678 });
679 },
680
681 // BIP44 account field changes address list
682 function() {
683 page.open(url, function(status) {
684 // set the phrase
685 var expected = "1Nq2Wmu726XHCuGhctEtGmhxo3wzk5wZ1H";
686 page.evaluate(function() {
687 $(".phrase").val("abandon abandon ability");
688 $(".phrase").trigger("input");
689 });
690 waitForGenerate(function() {
691 // change the bip44 purpose field to 45
692 page.evaluate(function() {
693 $("#bip44 .account").val("1");
694 $("#bip44 .account").trigger("input");
695 });
696 waitForGenerate(function() {
697 // check the address for the new derivation path
698 var actual = page.evaluate(function() {
699 return $(".address:first").text();
700 });
701 if (actual != expected) {
702 console.log("BIP44 account field generates incorrect address");
703 console.log("Expected: " + expected);
704 console.log("Actual: " + actual);
705 fail();
706 }
707 next();
708 });
709 });
710 });
711 },
712
713 // BIP44 change field changes address list
714 function() {
715 page.open(url, function(status) {
716 // set the phrase
717 var expected = "1KAGfWgqfVbSSXY56fNQ7YnhyKuoskHtYo";
718 page.evaluate(function() {
719 $(".phrase").val("abandon abandon ability");
720 $(".phrase").trigger("input");
721 });
722 waitForGenerate(function() {
723 // change the bip44 purpose field to 45
724 page.evaluate(function() {
725 $("#bip44 .change").val("1");
726 $("#bip44 .change").trigger("input");
727 });
728 waitForGenerate(function() {
729 // check the address for the new derivation path
730 var actual = page.evaluate(function() {
731 return $(".address:first").text();
732 });
733 if (actual != expected) {
734 console.log("BIP44 change field generates incorrect address");
735 console.log("Expected: " + expected);
736 console.log("Actual: " + actual);
737 fail();
738 }
739 next();
740 });
741 });
742 });
743 },
744
745 // BIP32 derivation path can be set
746 function() {
747 page.open(url, function(status) {
748 // set the phrase
749 var expected = "16pYQQdLD1hH4hwTGLXBaZ9Teboi1AGL8L";
750 page.evaluate(function() {
751 $(".phrase").val("abandon abandon ability");
752 $(".phrase").trigger("input");
753 });
754 // change tabs
755 waitForGenerate(function() {
756 page.evaluate(function() {
757 $("#bip32-tab a").click();
758 });
759 // set the derivation path to m/1
760 waitForGenerate(function() {
761 page.evaluate(function() {
762 $("#bip32 .path").val("m/1");
763 $("#bip32 .path").trigger("input");
764 });
765 // check the address is generated correctly
766 waitForGenerate(function() {
767 var actual = page.evaluate(function() {
768 return $(".address:first").text();
769 });
770 if (actual != expected) {
771 console.log("Custom BIP32 path generates incorrect address");
772 console.log("Expected: " + expected);
773 console.log("Actual: " + actual);
774 fail();
775 }
776 next();
777 });
778 });
779 });
780 });
781 },
782
783 // BIP32 can use hardened derivation paths
784 function() {
785 page.open(url, function(status) {
786 // set the phrase
787 var expected = "14aXZeprXAE3UUKQc4ihvwBvww2LuEoHo4";
788 page.evaluate(function() {
789 $(".phrase").val("abandon abandon ability");
790 $(".phrase").trigger("input");
791 });
792 // change tabs
793 waitForGenerate(function() {
794 page.evaluate(function() {
795 $("#bip32-tab a").click();
796 });
797 // set the derivation path to m/0'
798 waitForGenerate(function() {
799 page.evaluate(function() {
800 $("#bip32 .path").val("m/0'");
801 $("#bip32 .path").trigger("input");
802 });
803 // check the address is generated correctly
804 waitForGenerate(function() {
805 var actual = page.evaluate(function() {
806 return $(".address:first").text();
807 });
808 if (actual != expected) {
809 console.log("Hardened BIP32 path generates incorrect address");
810 console.log("Expected: " + expected);
811 console.log("Actual: " + actual);
812 fail();
813 }
814 next();
815 });
816 });
817 });
818 });
819 },
820
821 // BIP32 extended private key is shown
822 function() {
823 page.open(url, function(status) {
824 // set the phrase
825 var expected = "xprv9va99uTVE5aLiutUVLTyfxfe8v8aaXjSQ1XxZbK6SezYVuikA9MnjQVTA8rQHpNA5LKvyQBpLiHbBQiiccKiBDs7eRmBogsvq3THFeLHYbe";
826 page.evaluate(function() {
827 $(".phrase").val("abandon abandon ability");
828 $(".phrase").trigger("input");
829 });
830 // change tabs
831 waitForGenerate(function() {
832 page.evaluate(function() {
833 $("#bip32-tab a").click();
834 });
835 // check the extended private key is generated correctly
836 waitForGenerate(function() {
837 var actual = page.evaluate(function() {
838 return $(".extended-priv-key").val();
839 });
840 if (actual != expected) {
841 console.log("BIP32 extended private key is incorrect");
842 console.log("Expected: " + expected);
843 console.log("Actual: " + actual);
844 fail();
845 }
846 next();
847 });
848 });
849 });
850 },
851
852 // BIP32 extended public key is shown
853 function() {
854 page.open(url, function(status) {
855 // set the phrase
856 var expected = "xpub69ZVZQzP4T8dwPxwbMzz36cNgwy4yzTHmETZMyihzzXXNi3thgg3HCow1RtY252wdw5rS8369xKnraN5Q93y3FkFfJp2XEHWUrkyXsjS93P";
857 page.evaluate(function() {
858 $(".phrase").val("abandon abandon ability");
859 $(".phrase").trigger("input");
860 });
861 // change tabs
862 waitForGenerate(function() {
863 page.evaluate(function() {
864 $("#bip32-tab a").click();
865 });
866 // check the extended public key is generated correctly
867 waitForGenerate(function() {
868 var actual = page.evaluate(function() {
869 return $(".extended-pub-key").val();
870 });
871 if (actual != expected) {
872 console.log("BIP32 extended public key is incorrect");
873 console.log("Expected: " + expected);
874 console.log("Actual: " + actual);
875 fail();
876 }
877 next();
878 });
879 });
880 });
881 },
882
883 // Derivation path is shown in table
884 function() {
885 page.open(url, function(status) {
886 // set the phrase
887 var expected = "m/44'/0'/0'/0/0";
888 page.evaluate(function() {
889 $(".phrase").val("abandon abandon ability");
890 $(".phrase").trigger("input");
891 });
892 // check for derivation path in table
893 waitForGenerate(function() {
894 var actual = page.evaluate(function() {
895 return $(".index:first").text();
896 });
897 if (actual != expected) {
898 console.log("Derivation path shown incorrectly in table");
899 console.log("Expected: " + expected);
900 console.log("Actual: " + actual);
901 fail();
902 }
903 next();
904 });
905 });
906 },
907
908 // Derivation path for address can be hardened
909 // Derivation path visibility can be toggled
910 // Address is shown
911 // Addresses are shown in order of derivation path
912 // Address visibility can be toggled
913 // Private key is shown
914 // Private key visibility can be toggled
915
916 // More addresses can be generated
917 // A custom number of additional addresses can be generated
918 // Additional addresses are shown in order of derivation path
919
920 // BIP32 root key can be set by the user
921 // Setting BIP32 root key clears the existing phrase, passphrase and seed
922 // Clearing of phrase, passphrase and seed can be cancelled by user
923 // Custom BIP32 root key is used when changing the derivation path
924
925 // Incorrect mnemonic shows error
926 // Incorrect word shows suggested replacement
927 // Incorrect BIP32 root key shows error
928 // Derivation path not starting with m shows error
929 // Derivation path containing invalid characters shows useful error
930
931 // Github Issue 11: Default word length is 15
932 // https://github.com/dcpos/bip39/issues/11
933
934 // Github Issue 12: Generate more rows with private keys hidden
935 // https://github.com/dcpos/bip39/issues/12
936
937 // Github Issue 19: Mnemonic is not sensitive to whitespace
938 // https://github.com/dcpos/bip39/issues/19
939
940 // Github Issue 23: Use correct derivation path when changing tabs
941 // https://github.com/dcpos/bip39/issues/23
942
943 ];
944
945 console.log("Running tests...");
946 tests = shuffle(tests);
947 next();