aboutsummaryrefslogtreecommitdiff
path: root/tests.js
diff options
context:
space:
mode:
Diffstat (limited to 'tests.js')
-rw-r--r--tests.js585
1 files changed, 547 insertions, 38 deletions
diff --git a/tests.js b/tests.js
index f5ce6d3..9889e0b 100644
--- a/tests.js
+++ b/tests.js
@@ -4,6 +4,7 @@
4 4
5var page = require('webpage').create(); 5var page = require('webpage').create();
6var url = 'src/index.html'; 6var url = 'src/index.html';
7var testMaxTime = 5000;
7 8
8page.onResourceError = function(e) { 9page.onResourceError = function(e) {
9 console.log("Error loading " + e.url); 10 console.log("Error loading " + e.url);
@@ -15,6 +16,34 @@ function fail() {
15 phantom.exit(); 16 phantom.exit();
16} 17}
17 18
19function 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
18function next() { 47function next() {
19 if (tests.length > 0) { 48 if (tests.length > 0) {
20 var testsStr = tests.length == 1 ? "test" : "tests"; 49 var testsStr = tests.length == 1 ? "test" : "tests";
@@ -27,6 +56,21 @@ function next() {
27 } 56 }
28} 57}
29 58
59/**
60 * Randomize array element order in-place.
61 * Using Durstenfeld shuffle algorithm.
62 * See http://stackoverflow.com/a/12646864
63 */
64function 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
30tests = [ 74tests = [
31 75
32// Page loads with status of 'success' 76// Page loads with status of 'success'
@@ -57,24 +101,23 @@ page.open(url, function(status) {
57// Entering mnemonic generates addresses 101// Entering mnemonic generates addresses
58function() { 102function() {
59page.open(url, function(status) { 103page.open(url, function(status) {
60 var expected = "1Di3Vp7tBWtyQaDABLAjfWtF6V7hYKJtug";
61 // set the phrase 104 // set the phrase
62 page.evaluate(function() { 105 page.evaluate(function() {
63 $(".phrase").val("abandon abandon ability").trigger("input"); 106 $(".phrase").val("abandon abandon ability").trigger("input");
64 }); 107 });
65 // get the address 108 // get the address
66 setTimeout(function() { 109 waitForGenerate(function() {
67 var actual = page.evaluate(function() { 110 var addressCount = page.evaluate(function() {
68 return $(".address:first").text(); 111 return $(".address").length;
69 }); 112 });
70 if (actual != expected) { 113 if (addressCount != 20) {
71 console.log("Mnemonic did not generate address"); 114 console.log("Mnemonic did not generate addresses");
72 console.log("Expected: " + expected); 115 console.log("Expected: " + expected);
73 console.log("Got: " + actual); 116 console.log("Got: " + actual);
74 fail(); 117 fail();
75 } 118 }
76 next(); 119 next();
77 }, 1000); 120 });
78}); 121});
79}, 122},
80 123
@@ -94,7 +137,7 @@ page.open(url, function(status) {
94 $(".generate").click(); 137 $(".generate").click();
95 }); 138 });
96 // get the new phrase 139 // get the new phrase
97 setTimeout(function() { 140 waitForGenerate(function() {
98 var phrase = page.evaluate(function() { 141 var phrase = page.evaluate(function() {
99 return $(".phrase").val(); 142 return $(".phrase").val();
100 }); 143 });
@@ -103,7 +146,7 @@ page.open(url, function(status) {
103 fail(); 146 fail();
104 } 147 }
105 next(); 148 next();
106 }, 1000); 149 });
107}); 150});
108}, 151},
109 152
@@ -121,7 +164,7 @@ page.open(url, function(status) {
121 $(".generate").click(); 164 $(".generate").click();
122 }); 165 });
123 // check the new phrase is six words long 166 // check the new phrase is six words long
124 setTimeout(function() { 167 waitForGenerate(function() {
125 var actualLength = page.evaluate(function() { 168 var actualLength = page.evaluate(function() {
126 var words = $(".phrase").val().split(" "); 169 var words = $(".phrase").val().split(" ");
127 return words.length; 170 return words.length;
@@ -133,7 +176,7 @@ page.open(url, function(status) {
133 fail(); 176 fail();
134 } 177 }
135 next(); 178 next();
136 }, 1000); 179 });
137}); 180});
138}, 181},
139 182
@@ -147,7 +190,7 @@ page.open(url, function(status) {
147 $(".passphrase").val("secure_passphrase").trigger("input"); 190 $(".passphrase").val("secure_passphrase").trigger("input");
148 }); 191 });
149 // check the address is generated correctly 192 // check the address is generated correctly
150 setTimeout(function() { 193 waitForGenerate(function() {
151 var actual = page.evaluate(function() { 194 var actual = page.evaluate(function() {
152 return $(".address:first").text(); 195 return $(".address:first").text();
153 }); 196 });
@@ -158,7 +201,7 @@ page.open(url, function(status) {
158 fail(); 201 fail();
159 } 202 }
160 next(); 203 next();
161 }, 1000); 204 });
162}); 205});
163}, 206},
164 207
@@ -175,7 +218,7 @@ page.open(url, function(status) {
175 $(".network").trigger("change"); 218 $(".network").trigger("change");
176 }); 219 });
177 // check the address is generated correctly 220 // check the address is generated correctly
178 setTimeout(function() { 221 waitForGenerate(function() {
179 var actual = page.evaluate(function() { 222 var actual = page.evaluate(function() {
180 return $(".address:first").text(); 223 return $(".address:first").text();
181 }); 224 });
@@ -186,7 +229,7 @@ page.open(url, function(status) {
186 fail(); 229 fail();
187 } 230 }
188 next(); 231 next();
189 }, 1000); 232 });
190}); 233});
191}, 234},
192 235
@@ -203,7 +246,7 @@ page.open(url, function(status) {
203 $(".network").trigger("change"); 246 $(".network").trigger("change");
204 }); 247 });
205 // check the address is generated correctly 248 // check the address is generated correctly
206 setTimeout(function() { 249 waitForGenerate(function() {
207 var actual = page.evaluate(function() { 250 var actual = page.evaluate(function() {
208 return $(".address:first").text(); 251 return $(".address:first").text();
209 }); 252 });
@@ -214,7 +257,7 @@ page.open(url, function(status) {
214 fail(); 257 fail();
215 } 258 }
216 next(); 259 next();
217 }, 1000); 260 });
218}); 261});
219}, 262},
220 263
@@ -231,7 +274,7 @@ page.open(url, function(status) {
231 $(".network").trigger("change"); 274 $(".network").trigger("change");
232 }); 275 });
233 // check the address is generated correctly 276 // check the address is generated correctly
234 setTimeout(function() { 277 waitForGenerate(function() {
235 var actual = page.evaluate(function() { 278 var actual = page.evaluate(function() {
236 return $(".address:first").text(); 279 return $(".address:first").text();
237 }); 280 });
@@ -242,7 +285,7 @@ page.open(url, function(status) {
242 fail(); 285 fail();
243 } 286 }
244 next(); 287 next();
245 }, 1000); 288 });
246}); 289});
247}, 290},
248 291
@@ -259,7 +302,7 @@ page.open(url, function(status) {
259 $(".network").trigger("change"); 302 $(".network").trigger("change");
260 }); 303 });
261 // check the address is generated correctly 304 // check the address is generated correctly
262 setTimeout(function() { 305 waitForGenerate(function() {
263 var actual = page.evaluate(function() { 306 var actual = page.evaluate(function() {
264 return $(".address:first").text(); 307 return $(".address:first").text();
265 }); 308 });
@@ -270,7 +313,7 @@ page.open(url, function(status) {
270 fail(); 313 fail();
271 } 314 }
272 next(); 315 next();
273 }, 1000); 316 });
274}); 317});
275}, 318},
276 319
@@ -287,7 +330,7 @@ page.open(url, function(status) {
287 $(".network").trigger("change"); 330 $(".network").trigger("change");
288 }); 331 });
289 // check the address is generated correctly 332 // check the address is generated correctly
290 setTimeout(function() { 333 waitForGenerate(function() {
291 var actual = page.evaluate(function() { 334 var actual = page.evaluate(function() {
292 return $(".address:first").text(); 335 return $(".address:first").text();
293 }); 336 });
@@ -298,7 +341,7 @@ page.open(url, function(status) {
298 fail(); 341 fail();
299 } 342 }
300 next(); 343 next();
301 }, 1000); 344 });
302}); 345});
303}, 346},
304 347
@@ -315,7 +358,7 @@ page.open(url, function(status) {
315 $(".network").trigger("change"); 358 $(".network").trigger("change");
316 }); 359 });
317 // check the address is generated correctly 360 // check the address is generated correctly
318 setTimeout(function() { 361 waitForGenerate(function() {
319 var actual = page.evaluate(function() { 362 var actual = page.evaluate(function() {
320 return $(".address:first").text(); 363 return $(".address:first").text();
321 }); 364 });
@@ -326,7 +369,7 @@ page.open(url, function(status) {
326 fail(); 369 fail();
327 } 370 }
328 next(); 371 next();
329 }, 1000); 372 });
330}); 373});
331}, 374},
332 375
@@ -343,7 +386,7 @@ page.open(url, function(status) {
343 $(".network").trigger("change"); 386 $(".network").trigger("change");
344 }); 387 });
345 // check the address is generated correctly 388 // check the address is generated correctly
346 setTimeout(function() { 389 waitForGenerate(function() {
347 var actual = page.evaluate(function() { 390 var actual = page.evaluate(function() {
348 return $(".address:first").text(); 391 return $(".address:first").text();
349 }); 392 });
@@ -354,7 +397,7 @@ page.open(url, function(status) {
354 fail(); 397 fail();
355 } 398 }
356 next(); 399 next();
357 }, 1000); 400 });
358}); 401});
359}, 402},
360 403
@@ -371,7 +414,7 @@ page.open(url, function(status) {
371 $(".network").trigger("change"); 414 $(".network").trigger("change");
372 }); 415 });
373 // check the address is generated correctly 416 // check the address is generated correctly
374 setTimeout(function() { 417 waitForGenerate(function() {
375 var actual = page.evaluate(function() { 418 var actual = page.evaluate(function() {
376 return $(".address:first").text(); 419 return $(".address:first").text();
377 }); 420 });
@@ -382,7 +425,7 @@ page.open(url, function(status) {
382 fail(); 425 fail();
383 } 426 }
384 next(); 427 next();
385 }, 1000); 428 });
386}); 429});
387}, 430},
388 431
@@ -399,7 +442,7 @@ page.open(url, function(status) {
399 $(".network").trigger("change"); 442 $(".network").trigger("change");
400 }); 443 });
401 // check the address is generated correctly 444 // check the address is generated correctly
402 setTimeout(function() { 445 waitForGenerate(function() {
403 var actual = page.evaluate(function() { 446 var actual = page.evaluate(function() {
404 return $(".address:first").text(); 447 return $(".address:first").text();
405 }); 448 });
@@ -410,7 +453,7 @@ page.open(url, function(status) {
410 fail(); 453 fail();
411 } 454 }
412 next(); 455 next();
413 }, 1000); 456 });
414}); 457});
415}, 458},
416 459
@@ -424,7 +467,7 @@ page.open(url, function(status) {
424 $(".phrase").trigger("input"); 467 $(".phrase").trigger("input");
425 }); 468 });
426 // check the address is generated correctly 469 // check the address is generated correctly
427 setTimeout(function() { 470 waitForGenerate(function() {
428 var actual = page.evaluate(function() { 471 var actual = page.evaluate(function() {
429 return $(".seed").val(); 472 return $(".seed").val();
430 }); 473 });
@@ -435,7 +478,7 @@ page.open(url, function(status) {
435 fail(); 478 fail();
436 } 479 }
437 next(); 480 next();
438 }, 1000); 481 });
439}); 482});
440}, 483},
441 484
@@ -449,7 +492,7 @@ page.open(url, function(status) {
449 $(".phrase").trigger("input"); 492 $(".phrase").trigger("input");
450 }); 493 });
451 // check the address is generated correctly 494 // check the address is generated correctly
452 setTimeout(function() { 495 waitForGenerate(function() {
453 var actual = page.evaluate(function() { 496 var actual = page.evaluate(function() {
454 return $(".root-key").val(); 497 return $(".root-key").val();
455 }); 498 });
@@ -460,31 +503,496 @@ page.open(url, function(status) {
460 fail(); 503 fail();
461 } 504 }
462 next(); 505 next();
463 }, 1000); 506 });
464}); 507});
465}, 508},
466 509
467// TODO finish these tests
468
469// Tabs show correct addresses when changed 510// Tabs show correct addresses when changed
511function() {
512page.open(url, function(status) {
513 // set the phrase
514 var expected = "17uQ7s2izWPwBmEVFikTmZUjbBKWYdJchz";
515 page.evaluate(function() {
516 $(".phrase").val("abandon abandon ability");
517 $(".phrase").trigger("input");
518 });
519 // change tabs
520 waitForGenerate(function() {
521 page.evaluate(function() {
522 $("#bip32-tab a").click();
523 });
524 // check the address is generated correctly
525 waitForGenerate(function() {
526 var actual = page.evaluate(function() {
527 return $(".address:first").text();
528 });
529 if (actual != expected) {
530 console.log("Clicking tab generates incorrect address");
531 console.log("Expected: " + expected);
532 console.log("Actual: " + actual);
533 fail();
534 }
535 next();
536 });
537 });
538});
539},
470 540
471// BIP44 derivation path is shown 541// BIP44 derivation path is shown
542function() {
543page.open(url, function(status) {
544 // set the phrase
545 var expected = "m/44'/0'/0'/0";
546 page.evaluate(function() {
547 $(".phrase").val("abandon abandon ability");
548 $(".phrase").trigger("input");
549 });
550 // check the derivation path of the first address
551 waitForGenerate(function() {
552 var actual = page.evaluate(function() {
553 return $("#bip44 .path").val();
554 });
555 if (actual != expected) {
556 console.log("BIP44 derivation path is incorrect");
557 console.log("Expected: " + expected);
558 console.log("Actual: " + actual);
559 fail();
560 }
561 next();
562 });
563});
564},
565
472// BIP44 extended private key is shown 566// BIP44 extended private key is shown
567function() {
568page.open(url, function(status) {
569 // set the phrase
570 var expected = "xprvA2DxxvPZcyRvYgZMGS53nadR32mVDeCyqQYyFhrCVbJNjPoxMeVf7QT5g7mQASbTf9Kp4cryvcXnu2qurjWKcrdsr91jXymdCDNxKgLFKJG";
571 page.evaluate(function() {
572 $(".phrase").val("abandon abandon ability");
573 $(".phrase").trigger("input");
574 });
575 // check the BIP44 extended private key
576 waitForGenerate(function() {
577 var actual = page.evaluate(function() {
578 return $(".extended-priv-key").val();
579 });
580 if (actual != expected) {
581 console.log("BIP44 extended private key is incorrect");
582 console.log("Expected: " + expected);
583 console.log("Actual: " + actual);
584 fail();
585 }
586 next();
587 });
588});
589},
590
473// BIP44 extended public key is shown 591// BIP44 extended public key is shown
592function() {
593page.open(url, function(status) {
594 // set the phrase
595 var expected = "xpub6FDKNRvTTLzDmAdpNTc49ia9b4byd6vqCdUa46Fp3vqMcC96uBoufCmZXQLiN5AK3iSCJMhf9gT2sxkpyaPepRuA7W3MujV5tGmF5VfbueM";
596 page.evaluate(function() {
597 $(".phrase").val("abandon abandon ability");
598 $(".phrase").trigger("input");
599 });
600 // check the BIP44 extended public key
601 waitForGenerate(function() {
602 var actual = page.evaluate(function() {
603 return $(".extended-pub-key").val();
604 });
605 if (actual != expected) {
606 console.log("BIP44 extended public key is incorrect");
607 console.log("Expected: " + expected);
608 console.log("Actual: " + actual);
609 fail();
610 }
611 next();
612 });
613});
614},
615
474// BIP44 purpose field changes address list 616// BIP44 purpose field changes address list
617function() {
618page.open(url, function(status) {
619 // set the phrase
620 var expected = "1JbDzRJ2cDT8aat2xwKd6Pb2zzavow5MhF";
621 page.evaluate(function() {
622 $(".phrase").val("abandon abandon ability");
623 $(".phrase").trigger("input");
624 });
625 waitForGenerate(function() {
626 // change the bip44 purpose field to 45
627 page.evaluate(function() {
628 $("#bip44 .purpose").val("45");
629 $("#bip44 .purpose").trigger("input");
630 });
631 waitForGenerate(function() {
632 // check the address for the new derivation path
633 var actual = page.evaluate(function() {
634 return $(".address:first").text();
635 });
636 if (actual != expected) {
637 console.log("BIP44 purpose field generates incorrect address");
638 console.log("Expected: " + expected);
639 console.log("Actual: " + actual);
640 fail();
641 }
642 next();
643 });
644 });
645});
646},
647
475// BIP44 coin field changes address list 648// BIP44 coin field changes address list
649function() {
650page.open(url, function(status) {
651 // set the phrase
652 var expected = "1F6dB2djQYrxoyfZZmfr6D5voH8GkJTghk";
653 page.evaluate(function() {
654 $(".phrase").val("abandon abandon ability");
655 $(".phrase").trigger("input");
656 });
657 waitForGenerate(function() {
658 // change the bip44 purpose field to 45
659 page.evaluate(function() {
660 $("#bip44 .coin").val("1");
661 $("#bip44 .coin").trigger("input");
662 });
663 waitForGenerate(function() {
664 // check the address for the new derivation path
665 var actual = page.evaluate(function() {
666 return $(".address:first").text();
667 });
668 if (actual != expected) {
669 console.log("BIP44 coin field generates incorrect address");
670 console.log("Expected: " + expected);
671 console.log("Actual: " + actual);
672 fail();
673 }
674 next();
675 });
676 });
677});
678},
679
476// BIP44 account field changes address list 680// BIP44 account field changes address list
477// BIP44 external/internal field changes address list 681function() {
682page.open(url, function(status) {
683 // set the phrase
684 var expected = "1Nq2Wmu726XHCuGhctEtGmhxo3wzk5wZ1H";
685 page.evaluate(function() {
686 $(".phrase").val("abandon abandon ability");
687 $(".phrase").trigger("input");
688 });
689 waitForGenerate(function() {
690 // change the bip44 purpose field to 45
691 page.evaluate(function() {
692 $("#bip44 .account").val("1");
693 $("#bip44 .account").trigger("input");
694 });
695 waitForGenerate(function() {
696 // check the address for the new derivation path
697 var actual = page.evaluate(function() {
698 return $(".address:first").text();
699 });
700 if (actual != expected) {
701 console.log("BIP44 account field generates incorrect address");
702 console.log("Expected: " + expected);
703 console.log("Actual: " + actual);
704 fail();
705 }
706 next();
707 });
708 });
709});
710},
711
712// BIP44 change field changes address list
713function() {
714page.open(url, function(status) {
715 // set the phrase
716 var expected = "1KAGfWgqfVbSSXY56fNQ7YnhyKuoskHtYo";
717 page.evaluate(function() {
718 $(".phrase").val("abandon abandon ability");
719 $(".phrase").trigger("input");
720 });
721 waitForGenerate(function() {
722 // change the bip44 purpose field to 45
723 page.evaluate(function() {
724 $("#bip44 .change").val("1");
725 $("#bip44 .change").trigger("input");
726 });
727 waitForGenerate(function() {
728 // check the address for the new derivation path
729 var actual = page.evaluate(function() {
730 return $(".address:first").text();
731 });
732 if (actual != expected) {
733 console.log("BIP44 change field generates incorrect address");
734 console.log("Expected: " + expected);
735 console.log("Actual: " + actual);
736 fail();
737 }
738 next();
739 });
740 });
741});
742},
478 743
479// BIP32 derivation path can be set 744// BIP32 derivation path can be set
745function() {
746page.open(url, function(status) {
747 // set the phrase
748 var expected = "16pYQQdLD1hH4hwTGLXBaZ9Teboi1AGL8L";
749 page.evaluate(function() {
750 $(".phrase").val("abandon abandon ability");
751 $(".phrase").trigger("input");
752 });
753 // change tabs
754 waitForGenerate(function() {
755 page.evaluate(function() {
756 $("#bip32-tab a").click();
757 });
758 // set the derivation path to m/1
759 waitForGenerate(function() {
760 page.evaluate(function() {
761 $("#bip32 .path").val("m/1");
762 $("#bip32 .path").trigger("input");
763 });
764 // check the address is generated correctly
765 waitForGenerate(function() {
766 var actual = page.evaluate(function() {
767 return $(".address:first").text();
768 });
769 if (actual != expected) {
770 console.log("Custom BIP32 path generates incorrect address");
771 console.log("Expected: " + expected);
772 console.log("Actual: " + actual);
773 fail();
774 }
775 next();
776 });
777 });
778 });
779});
780},
781
480// BIP32 can use hardened derivation paths 782// BIP32 can use hardened derivation paths
783function() {
784page.open(url, function(status) {
785 // set the phrase
786 var expected = "14aXZeprXAE3UUKQc4ihvwBvww2LuEoHo4";
787 page.evaluate(function() {
788 $(".phrase").val("abandon abandon ability");
789 $(".phrase").trigger("input");
790 });
791 // change tabs
792 waitForGenerate(function() {
793 page.evaluate(function() {
794 $("#bip32-tab a").click();
795 });
796 // set the derivation path to m/0'
797 waitForGenerate(function() {
798 page.evaluate(function() {
799 $("#bip32 .path").val("m/0'");
800 $("#bip32 .path").trigger("input");
801 });
802 // check the address is generated correctly
803 waitForGenerate(function() {
804 var actual = page.evaluate(function() {
805 return $(".address:first").text();
806 });
807 if (actual != expected) {
808 console.log("Hardened BIP32 path generates incorrect address");
809 console.log("Expected: " + expected);
810 console.log("Actual: " + actual);
811 fail();
812 }
813 next();
814 });
815 });
816 });
817});
818},
819
481// BIP32 extended private key is shown 820// BIP32 extended private key is shown
821function() {
822page.open(url, function(status) {
823 // set the phrase
824 var expected = "xprv9va99uTVE5aLiutUVLTyfxfe8v8aaXjSQ1XxZbK6SezYVuikA9MnjQVTA8rQHpNA5LKvyQBpLiHbBQiiccKiBDs7eRmBogsvq3THFeLHYbe";
825 page.evaluate(function() {
826 $(".phrase").val("abandon abandon ability");
827 $(".phrase").trigger("input");
828 });
829 // change tabs
830 waitForGenerate(function() {
831 page.evaluate(function() {
832 $("#bip32-tab a").click();
833 });
834 // check the extended private key is generated correctly
835 waitForGenerate(function() {
836 var actual = page.evaluate(function() {
837 return $(".extended-priv-key").val();
838 });
839 if (actual != expected) {
840 console.log("BIP32 extended private key is incorrect");
841 console.log("Expected: " + expected);
842 console.log("Actual: " + actual);
843 fail();
844 }
845 next();
846 });
847 });
848});
849},
850
482// BIP32 extended public key is shown 851// BIP32 extended public key is shown
852function() {
853page.open(url, function(status) {
854 // set the phrase
855 var expected = "xpub69ZVZQzP4T8dwPxwbMzz36cNgwy4yzTHmETZMyihzzXXNi3thgg3HCow1RtY252wdw5rS8369xKnraN5Q93y3FkFfJp2XEHWUrkyXsjS93P";
856 page.evaluate(function() {
857 $(".phrase").val("abandon abandon ability");
858 $(".phrase").trigger("input");
859 });
860 // change tabs
861 waitForGenerate(function() {
862 page.evaluate(function() {
863 $("#bip32-tab a").click();
864 });
865 // check the extended public key is generated correctly
866 waitForGenerate(function() {
867 var actual = page.evaluate(function() {
868 return $(".extended-pub-key").val();
869 });
870 if (actual != expected) {
871 console.log("BIP32 extended public key is incorrect");
872 console.log("Expected: " + expected);
873 console.log("Actual: " + actual);
874 fail();
875 }
876 next();
877 });
878 });
879});
880},
483 881
484// Derivation path is shown in table 882// Derivation path is shown in table
883function() {
884page.open(url, function(status) {
885 // set the phrase
886 var expected = "m/44'/0'/0'/0/0";
887 page.evaluate(function() {
888 $(".phrase").val("abandon abandon ability");
889 $(".phrase").trigger("input");
890 });
891 // check for derivation path in table
892 waitForGenerate(function() {
893 var actual = page.evaluate(function() {
894 return $(".index:first").text();
895 });
896 if (actual != expected) {
897 console.log("Derivation path shown incorrectly in table");
898 console.log("Expected: " + expected);
899 console.log("Actual: " + actual);
900 fail();
901 }
902 next();
903 });
904});
905},
906
485// Derivation path for address can be hardened 907// Derivation path for address can be hardened
908function() {
909page.open(url, function(status) {
910 // set the phrase
911 var expected = "18exLzUv7kfpiXRzmCjFDoC9qwNLFyvwyd";
912 page.evaluate(function() {
913 $(".phrase").val("abandon abandon ability");
914 $(".phrase").trigger("input");
915 });
916 // change tabs
917 waitForGenerate(function() {
918 page.evaluate(function() {
919 $("#bip32-tab a").click();
920 });
921 waitForGenerate(function() {
922 // select the hardened addresses option
923 page.evaluate(function() {
924 $(".hardened-addresses").prop("checked", true);
925 $(".hardened-addresses").trigger("change");
926 });
927 waitForGenerate(function() {
928 // check the generated address is hardened
929 var actual = page.evaluate(function() {
930 return $(".address:first").text();
931 });
932 if (actual != expected) {
933 console.log("Hardened address is incorrect");
934 console.log("Expected: " + expected);
935 console.log("Actual: " + actual);
936 fail();
937 }
938 next();
939 });
940 });
941 });
942});
943},
944
486// Derivation path visibility can be toggled 945// Derivation path visibility can be toggled
946function() {
947page.open(url, function(status) {
948 // set the phrase
949 page.evaluate(function() {
950 $(".phrase").val("abandon abandon ability");
951 $(".phrase").trigger("input");
952 });
953 // check the path is not shown
954 waitForGenerate(function() {
955 // toggle path visibility
956 page.evaluate(function() {
957 $(".index-toggle").click();
958 });
959 // check the path is not visible
960 var isInvisible = page.evaluate(function() {
961 return $(".index:first span").hasClass("invisible");
962 });
963 if (!isInvisible) {
964 console.log("Toggled derivation path is visible");
965 fail();
966 }
967 next();
968 });
969});
970},
971
487// Address is shown 972// Address is shown
973function() {
974page.open(url, function(status) {
975 var expected = "1Di3Vp7tBWtyQaDABLAjfWtF6V7hYKJtug";
976 // set the phrase
977 page.evaluate(function() {
978 $(".phrase").val("abandon abandon ability").trigger("input");
979 });
980 // get the address
981 waitForGenerate(function() {
982 var actual = page.evaluate(function() {
983 return $(".address:first").text();
984 });
985 if (actual != expected) {
986 console.log("Address is not shown");
987 console.log("Expected: " + expected);
988 console.log("Got: " + actual);
989 fail();
990 }
991 next();
992 });
993});
994},
995
488// Addresses are shown in order of derivation path 996// Addresses are shown in order of derivation path
489// Address visibility can be toggled 997// Address visibility can be toggled
490// Private key is shown 998// Private key is shown
@@ -520,4 +1028,5 @@ page.open(url, function(status) {
520]; 1028];
521 1029
522console.log("Running tests..."); 1030console.log("Running tests...");
1031tests = shuffle(tests);
523next(); 1032next();