aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests.js616
1 files changed, 578 insertions, 38 deletions
diff --git a/tests.js b/tests.js
index f5ce6d3..47938a4 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,35 @@ page.open(url, function(status) {
410 fail(); 453 fail();
411 } 454 }
412 next(); 455 next();
413 }, 1000); 456 });
457});
458},
459
460// Network can be set to dash
461function() {
462page.open(url, function(status) {
463 // set the phrase and coin
464 var expected = "XdbhtMuGsPSkE6bPdNTHoFSszQKmK4S5LT";
465 page.evaluate(function() {
466 $(".phrase").val("abandon abandon ability");
467 $(".phrase").trigger("input");
468 $(".network option[selected]").removeAttr("selected");
469 $(".network option[value=10]").prop("selected", true);
470 $(".network").trigger("change");
471 });
472 // check the address is generated correctly
473 waitForGenerate(function() {
474 var actual = page.evaluate(function() {
475 return $(".address:first").text();
476 });
477 if (actual != expected) {
478 console.log("DASH address is incorrect");
479 console.log("Expected: " + expected);
480 console.log("Actual: " + actual);
481 fail();
482 }
483 next();
484 });
414}); 485});
415}, 486},
416 487
@@ -424,7 +495,7 @@ page.open(url, function(status) {
424 $(".phrase").trigger("input"); 495 $(".phrase").trigger("input");
425 }); 496 });
426 // check the address is generated correctly 497 // check the address is generated correctly
427 setTimeout(function() { 498 waitForGenerate(function() {
428 var actual = page.evaluate(function() { 499 var actual = page.evaluate(function() {
429 return $(".seed").val(); 500 return $(".seed").val();
430 }); 501 });
@@ -435,7 +506,7 @@ page.open(url, function(status) {
435 fail(); 506 fail();
436 } 507 }
437 next(); 508 next();
438 }, 1000); 509 });
439}); 510});
440}, 511},
441 512
@@ -449,7 +520,7 @@ page.open(url, function(status) {
449 $(".phrase").trigger("input"); 520 $(".phrase").trigger("input");
450 }); 521 });
451 // check the address is generated correctly 522 // check the address is generated correctly
452 setTimeout(function() { 523 waitForGenerate(function() {
453 var actual = page.evaluate(function() { 524 var actual = page.evaluate(function() {
454 return $(".root-key").val(); 525 return $(".root-key").val();
455 }); 526 });
@@ -460,31 +531,496 @@ page.open(url, function(status) {
460 fail(); 531 fail();
461 } 532 }
462 next(); 533 next();
463 }, 1000); 534 });
464}); 535});
465}, 536},
466 537
467// TODO finish these tests
468
469// Tabs show correct addresses when changed 538// Tabs show correct addresses when changed
539function() {
540page.open(url, function(status) {
541 // set the phrase
542 var expected = "17uQ7s2izWPwBmEVFikTmZUjbBKWYdJchz";
543 page.evaluate(function() {
544 $(".phrase").val("abandon abandon ability");
545 $(".phrase").trigger("input");
546 });
547 // change tabs
548 waitForGenerate(function() {
549 page.evaluate(function() {
550 $("#bip32-tab a").click();
551 });
552 // check the address is generated correctly
553 waitForGenerate(function() {
554 var actual = page.evaluate(function() {
555 return $(".address:first").text();
556 });
557 if (actual != expected) {
558 console.log("Clicking tab generates incorrect address");
559 console.log("Expected: " + expected);
560 console.log("Actual: " + actual);
561 fail();
562 }
563 next();
564 });
565 });
566});
567},
470 568
471// BIP44 derivation path is shown 569// BIP44 derivation path is shown
570function() {
571page.open(url, function(status) {
572 // set the phrase
573 var expected = "m/44'/0'/0'/0";
574 page.evaluate(function() {
575 $(".phrase").val("abandon abandon ability");
576 $(".phrase").trigger("input");
577 });
578 // check the derivation path of the first address
579 waitForGenerate(function() {
580 var actual = page.evaluate(function() {
581 return $("#bip44 .path").val();
582 });
583 if (actual != expected) {
584 console.log("BIP44 derivation path is incorrect");
585 console.log("Expected: " + expected);
586 console.log("Actual: " + actual);
587 fail();
588 }
589 next();
590 });
591});
592},
593
472// BIP44 extended private key is shown 594// BIP44 extended private key is shown
595function() {
596page.open(url, function(status) {
597 // set the phrase
598 var expected = "xprvA2DxxvPZcyRvYgZMGS53nadR32mVDeCyqQYyFhrCVbJNjPoxMeVf7QT5g7mQASbTf9Kp4cryvcXnu2qurjWKcrdsr91jXymdCDNxKgLFKJG";
599 page.evaluate(function() {
600 $(".phrase").val("abandon abandon ability");
601 $(".phrase").trigger("input");
602 });
603 // check the BIP44 extended private key
604 waitForGenerate(function() {
605 var actual = page.evaluate(function() {
606 return $(".extended-priv-key").val();
607 });
608 if (actual != expected) {
609 console.log("BIP44 extended private key is incorrect");
610 console.log("Expected: " + expected);
611 console.log("Actual: " + actual);
612 fail();
613 }
614 next();
615 });
616});
617},
618
473// BIP44 extended public key is shown 619// BIP44 extended public key is shown
620function() {
621page.open(url, function(status) {
622 // set the phrase
623 var expected = "xpub6FDKNRvTTLzDmAdpNTc49ia9b4byd6vqCdUa46Fp3vqMcC96uBoufCmZXQLiN5AK3iSCJMhf9gT2sxkpyaPepRuA7W3MujV5tGmF5VfbueM";
624 page.evaluate(function() {
625 $(".phrase").val("abandon abandon ability");
626 $(".phrase").trigger("input");
627 });
628 // check the BIP44 extended public key
629 waitForGenerate(function() {
630 var actual = page.evaluate(function() {
631 return $(".extended-pub-key").val();
632 });
633 if (actual != expected) {
634 console.log("BIP44 extended public key is incorrect");
635 console.log("Expected: " + expected);
636 console.log("Actual: " + actual);
637 fail();
638 }
639 next();
640 });
641});
642},
643
474// BIP44 purpose field changes address list 644// BIP44 purpose field changes address list
645function() {
646page.open(url, function(status) {
647 // set the phrase
648 var expected = "1JbDzRJ2cDT8aat2xwKd6Pb2zzavow5MhF";
649 page.evaluate(function() {
650 $(".phrase").val("abandon abandon ability");
651 $(".phrase").trigger("input");
652 });
653 waitForGenerate(function() {
654 // change the bip44 purpose field to 45
655 page.evaluate(function() {
656 $("#bip44 .purpose").val("45");
657 $("#bip44 .purpose").trigger("input");
658 });
659 waitForGenerate(function() {
660 // check the address for the new derivation path
661 var actual = page.evaluate(function() {
662 return $(".address:first").text();
663 });
664 if (actual != expected) {
665 console.log("BIP44 purpose field generates incorrect address");
666 console.log("Expected: " + expected);
667 console.log("Actual: " + actual);
668 fail();
669 }
670 next();
671 });
672 });
673});
674},
675
475// BIP44 coin field changes address list 676// BIP44 coin field changes address list
677function() {
678page.open(url, function(status) {
679 // set the phrase
680 var expected = "1F6dB2djQYrxoyfZZmfr6D5voH8GkJTghk";
681 page.evaluate(function() {
682 $(".phrase").val("abandon abandon ability");
683 $(".phrase").trigger("input");
684 });
685 waitForGenerate(function() {
686 // change the bip44 purpose field to 45
687 page.evaluate(function() {
688 $("#bip44 .coin").val("1");
689 $("#bip44 .coin").trigger("input");
690 });
691 waitForGenerate(function() {
692 // check the address for the new derivation path
693 var actual = page.evaluate(function() {
694 return $(".address:first").text();
695 });
696 if (actual != expected) {
697 console.log("BIP44 coin field generates incorrect address");
698 console.log("Expected: " + expected);
699 console.log("Actual: " + actual);
700 fail();
701 }
702 next();
703 });
704 });
705});
706},
707
476// BIP44 account field changes address list 708// BIP44 account field changes address list
477// BIP44 external/internal field changes address list 709function() {
710page.open(url, function(status) {
711 // set the phrase
712 var expected = "1Nq2Wmu726XHCuGhctEtGmhxo3wzk5wZ1H";
713 page.evaluate(function() {
714 $(".phrase").val("abandon abandon ability");
715 $(".phrase").trigger("input");
716 });
717 waitForGenerate(function() {
718 // change the bip44 purpose field to 45
719 page.evaluate(function() {
720 $("#bip44 .account").val("1");
721 $("#bip44 .account").trigger("input");
722 });
723 waitForGenerate(function() {
724 // check the address for the new derivation path
725 var actual = page.evaluate(function() {
726 return $(".address:first").text();
727 });
728 if (actual != expected) {
729 console.log("BIP44 account field generates incorrect address");
730 console.log("Expected: " + expected);
731 console.log("Actual: " + actual);
732 fail();
733 }
734 next();
735 });
736 });
737});
738},
739
740// BIP44 change field changes address list
741function() {
742page.open(url, function(status) {
743 // set the phrase
744 var expected = "1KAGfWgqfVbSSXY56fNQ7YnhyKuoskHtYo";
745 page.evaluate(function() {
746 $(".phrase").val("abandon abandon ability");
747 $(".phrase").trigger("input");
748 });
749 waitForGenerate(function() {
750 // change the bip44 purpose field to 45
751 page.evaluate(function() {
752 $("#bip44 .change").val("1");
753 $("#bip44 .change").trigger("input");
754 });
755 waitForGenerate(function() {
756 // check the address for the new derivation path
757 var actual = page.evaluate(function() {
758 return $(".address:first").text();
759 });
760 if (actual != expected) {
761 console.log("BIP44 change field generates incorrect address");
762 console.log("Expected: " + expected);
763 console.log("Actual: " + actual);
764 fail();
765 }
766 next();
767 });
768 });
769});
770},
478 771
479// BIP32 derivation path can be set 772// BIP32 derivation path can be set
773function() {
774page.open(url, function(status) {
775 // set the phrase
776 var expected = "16pYQQdLD1hH4hwTGLXBaZ9Teboi1AGL8L";
777 page.evaluate(function() {
778 $(".phrase").val("abandon abandon ability");
779 $(".phrase").trigger("input");
780 });
781 // change tabs
782 waitForGenerate(function() {
783 page.evaluate(function() {
784 $("#bip32-tab a").click();
785 });
786 // set the derivation path to m/1
787 waitForGenerate(function() {
788 page.evaluate(function() {
789 $("#bip32 .path").val("m/1");
790 $("#bip32 .path").trigger("input");
791 });
792 // check the address is generated correctly
793 waitForGenerate(function() {
794 var actual = page.evaluate(function() {
795 return $(".address:first").text();
796 });
797 if (actual != expected) {
798 console.log("Custom BIP32 path generates incorrect address");
799 console.log("Expected: " + expected);
800 console.log("Actual: " + actual);
801 fail();
802 }
803 next();
804 });
805 });
806 });
807});
808},
809
480// BIP32 can use hardened derivation paths 810// BIP32 can use hardened derivation paths
811function() {
812page.open(url, function(status) {
813 // set the phrase
814 var expected = "14aXZeprXAE3UUKQc4ihvwBvww2LuEoHo4";
815 page.evaluate(function() {
816 $(".phrase").val("abandon abandon ability");
817 $(".phrase").trigger("input");
818 });
819 // change tabs
820 waitForGenerate(function() {
821 page.evaluate(function() {
822 $("#bip32-tab a").click();
823 });
824 // set the derivation path to m/0'
825 waitForGenerate(function() {
826 page.evaluate(function() {
827 $("#bip32 .path").val("m/0'");
828 $("#bip32 .path").trigger("input");
829 });
830 // check the address is generated correctly
831 waitForGenerate(function() {
832 var actual = page.evaluate(function() {
833 return $(".address:first").text();
834 });
835 if (actual != expected) {
836 console.log("Hardened BIP32 path generates incorrect address");
837 console.log("Expected: " + expected);
838 console.log("Actual: " + actual);
839 fail();
840 }
841 next();
842 });
843 });
844 });
845});
846},
847
481// BIP32 extended private key is shown 848// BIP32 extended private key is shown
849function() {
850page.open(url, function(status) {
851 // set the phrase
852 var expected = "xprv9va99uTVE5aLiutUVLTyfxfe8v8aaXjSQ1XxZbK6SezYVuikA9MnjQVTA8rQHpNA5LKvyQBpLiHbBQiiccKiBDs7eRmBogsvq3THFeLHYbe";
853 page.evaluate(function() {
854 $(".phrase").val("abandon abandon ability");
855 $(".phrase").trigger("input");
856 });
857 // change tabs
858 waitForGenerate(function() {
859 page.evaluate(function() {
860 $("#bip32-tab a").click();
861 });
862 // check the extended private key is generated correctly
863 waitForGenerate(function() {
864 var actual = page.evaluate(function() {
865 return $(".extended-priv-key").val();
866 });
867 if (actual != expected) {
868 console.log("BIP32 extended private key is incorrect");
869 console.log("Expected: " + expected);
870 console.log("Actual: " + actual);
871 fail();
872 }
873 next();
874 });
875 });
876});
877},
878
482// BIP32 extended public key is shown 879// BIP32 extended public key is shown
880function() {
881page.open(url, function(status) {
882 // set the phrase
883 var expected = "xpub69ZVZQzP4T8dwPxwbMzz36cNgwy4yzTHmETZMyihzzXXNi3thgg3HCow1RtY252wdw5rS8369xKnraN5Q93y3FkFfJp2XEHWUrkyXsjS93P";
884 page.evaluate(function() {
885 $(".phrase").val("abandon abandon ability");
886 $(".phrase").trigger("input");
887 });
888 // change tabs
889 waitForGenerate(function() {
890 page.evaluate(function() {
891 $("#bip32-tab a").click();
892 });
893 // check the extended public key is generated correctly
894 waitForGenerate(function() {
895 var actual = page.evaluate(function() {
896 return $(".extended-pub-key").val();
897 });
898 if (actual != expected) {
899 console.log("BIP32 extended public key is incorrect");
900 console.log("Expected: " + expected);
901 console.log("Actual: " + actual);
902 fail();
903 }
904 next();
905 });
906 });
907});
908},
483 909
484// Derivation path is shown in table 910// Derivation path is shown in table
911function() {
912page.open(url, function(status) {
913 // set the phrase
914 var expected = "m/44'/0'/0'/0/0";
915 page.evaluate(function() {
916 $(".phrase").val("abandon abandon ability");
917 $(".phrase").trigger("input");
918 });
919 // check for derivation path in table
920 waitForGenerate(function() {
921 var actual = page.evaluate(function() {
922 return $(".index:first").text();
923 });
924 if (actual != expected) {
925 console.log("Derivation path shown incorrectly in table");
926 console.log("Expected: " + expected);
927 console.log("Actual: " + actual);
928 fail();
929 }
930 next();
931 });
932});
933},
934
485// Derivation path for address can be hardened 935// Derivation path for address can be hardened
936function() {
937page.open(url, function(status) {
938 // set the phrase
939 var expected = "18exLzUv7kfpiXRzmCjFDoC9qwNLFyvwyd";
940 page.evaluate(function() {
941 $(".phrase").val("abandon abandon ability");
942 $(".phrase").trigger("input");
943 });
944 // change tabs
945 waitForGenerate(function() {
946 page.evaluate(function() {
947 $("#bip32-tab a").click();
948 });
949 waitForGenerate(function() {
950 // select the hardened addresses option
951 page.evaluate(function() {
952 $(".hardened-addresses").prop("checked", true);
953 $(".hardened-addresses").trigger("change");
954 });
955 waitForGenerate(function() {
956 // check the generated address is hardened
957 var actual = page.evaluate(function() {
958 return $(".address:first").text();
959 });
960 if (actual != expected) {
961 console.log("Hardened address is incorrect");
962 console.log("Expected: " + expected);
963 console.log("Actual: " + actual);
964 fail();
965 }
966 next();
967 });
968 });
969 });
970});
971},
972
486// Derivation path visibility can be toggled 973// Derivation path visibility can be toggled
974function() {
975page.open(url, function(status) {
976 // set the phrase
977 page.evaluate(function() {
978 $(".phrase").val("abandon abandon ability");
979 $(".phrase").trigger("input");
980 });
981 // check the path is not shown
982 waitForGenerate(function() {
983 // toggle path visibility
984 page.evaluate(function() {
985 $(".index-toggle").click();
986 });
987 // check the path is not visible
988 var isInvisible = page.evaluate(function() {
989 return $(".index:first span").hasClass("invisible");
990 });
991 if (!isInvisible) {
992 console.log("Toggled derivation path is visible");
993 fail();
994 }
995 next();
996 });
997});
998},
999
487// Address is shown 1000// Address is shown
1001function() {
1002page.open(url, function(status) {
1003 var expected = "1Di3Vp7tBWtyQaDABLAjfWtF6V7hYKJtug";
1004 // set the phrase
1005 page.evaluate(function() {
1006 $(".phrase").val("abandon abandon ability").trigger("input");
1007 });
1008 // get the address
1009 waitForGenerate(function() {
1010 var actual = page.evaluate(function() {
1011 return $(".address:first").text();
1012 });
1013 if (actual != expected) {
1014 console.log("Address is not shown");
1015 console.log("Expected: " + expected);
1016 console.log("Got: " + actual);
1017 fail();
1018 }
1019 next();
1020 });
1021});
1022},
1023
488// Addresses are shown in order of derivation path 1024// Addresses are shown in order of derivation path
489// Address visibility can be toggled 1025// Address visibility can be toggled
490// Private key is shown 1026// Private key is shown
@@ -517,7 +1053,11 @@ page.open(url, function(status) {
517// Github Issue 23: Use correct derivation path when changing tabs 1053// Github Issue 23: Use correct derivation path when changing tabs
518// https://github.com/dcpos/bip39/issues/23 1054// https://github.com/dcpos/bip39/issues/23
519 1055
1056// Github Issue 26: When using a Root key derrived altcoins are incorrect
1057// https://github.com/dcpos/bip39/issues/26
1058
520]; 1059];
521 1060
522console.log("Running tests..."); 1061console.log("Running tests...");
1062tests = shuffle(tests);
523next(); 1063next();