2 // $ phantomjs tests.js
5 var page
= require('webpage').create();
6 var url
= 'src/index.html';
7 var testMaxTime
= 20000;
14 page
.onResourceError = function(e
) {
15 console
.log("Error loading " + e
.url
);
20 console
.log("Failed");
24 function waitForGenerate(fn
, maxTime
) {
26 maxTime
= testMaxTime
;
28 var start
= new Date().getTime();
29 var prevAddressCount
= -1;
30 var wait
= function keepWaiting() {
31 var now
= new Date().getTime();
32 var hasTimedOut
= now
- start
> maxTime
;
33 var addressCount
= page
.evaluate(function() {
34 return $(".address").length
;
36 var hasFinished
= addressCount
> 0 && addressCount
== prevAddressCount
;
37 prevAddressCount
= addressCount
;
41 else if (hasTimedOut
) {
42 console
.log("Test timed out");
46 setTimeout(keepWaiting
, 100);
52 function waitForFeedback(fn
, maxTime
) {
54 maxTime
= testMaxTime
;
56 var start
= new Date().getTime();
57 var wait
= function keepWaiting() {
58 var now
= new Date().getTime();
59 var hasTimedOut
= now
- start
> maxTime
;
61 console
.log("Test timed out");
65 var feedback
= page
.evaluate(function() {
66 var feedback
= $(".feedback");
67 if (feedback
.css("display") == "none") {
70 return feedback
.text();
72 var hasFinished
= feedback
.length
> 0 && feedback
!= "Calculating...";
77 setTimeout(keepWaiting
, 100);
83 function waitForEntropyFeedback(fn
, maxTime
) {
85 maxTime
= testMaxTime
;
87 var origFeedback
= page
.evaluate(function() {
88 return $(".entropy-container").text();
90 var start
= new Date().getTime();
91 var wait
= function keepWaiting() {
92 var now
= new Date().getTime();
93 var hasTimedOut
= now
- start
> maxTime
;
95 console
.log("Test timed out");
99 var feedback
= page
.evaluate(function() {
100 return $(".entropy-container").text();
102 var hasFinished
= feedback
!= origFeedback
;
107 setTimeout(keepWaiting
, 100);
114 if (tests
.length
> 0) {
115 var testsStr
= tests
.length
== 1 ? "test" : "tests";
116 console
.log(tests
.length
+ " " + testsStr
+ " remaining");
120 console
.log("Finished with 0 failures");
126 * Randomize array element order in-place.
127 * Using Durstenfeld shuffle algorithm.
128 * See http://stackoverflow.com/a/12646864
130 function shuffle(array
) {
131 for (var i
= array
.length
- 1; i
> 0; i
--) {
132 var j
= Math
.floor(Math
.random() * (i
+ 1));
142 // Page loads with status of 'success'
144 page
.open(url
, function(status
) {
145 if (status
!= "success") {
146 console
.log("Page did not load with status 'success'");
155 page
.open(url
, function(status
) {
156 var content
= page
.evaluate(function() {
157 return document
.body
.textContent
.trim();
160 console
.log("Page does not have text");
167 // Entering mnemonic generates addresses
169 page
.open(url
, function(status
) {
171 page
.evaluate(function() {
172 $(".phrase").val("abandon abandon ability").trigger("input");
175 waitForGenerate(function() {
176 var addressCount
= page
.evaluate(function() {
177 return $(".address").length
;
179 if (addressCount
!= 20) {
180 console
.log("Mnemonic did not generate addresses");
181 console
.log("Expected: " + expected
);
182 console
.log("Got: " + actual
);
190 // Random button generates random mnemonic
192 page
.open(url
, function(status
) {
193 // check initial phrase is empty
194 var phrase
= page
.evaluate(function() {
195 return $(".phrase").text();
198 console
.log("Initial phrase is not blank");
201 // press the 'generate' button
202 page
.evaluate(function() {
203 $(".generate").click();
205 // get the new phrase
206 waitForGenerate(function() {
207 var phrase
= page
.evaluate(function() {
208 return $(".phrase").val();
210 if (phrase
.length
<= 0) {
211 console
.log("Phrase not generated by pressing button");
219 // Mnemonic length can be customized
221 page
.open(url
, function(status
) {
222 // set the length to 6
223 var expectedLength
= "6";
224 page
.evaluate(function() {
225 $(".strength option[selected]").removeAttr("selected");
226 $(".strength option[value=6]").prop("selected", true);
228 // press the 'generate' button
229 page
.evaluate(function() {
230 $(".generate").click();
232 // check the new phrase is six words long
233 waitForGenerate(function() {
234 var actualLength
= page
.evaluate(function() {
235 var words
= $(".phrase").val().split(" ");
238 if (actualLength
!= expectedLength
) {
239 console
.log("Phrase not generated with correct length");
240 console
.log("Expected: " + expectedLength
);
241 console
.log("Actual: " + actualLength
);
249 // Passphrase can be set
251 page
.open(url
, function(status
) {
252 // set the phrase and passphrase
253 var expected
= "15pJzUWPGzR7avffV9nY5by4PSgSKG9rba";
254 page
.evaluate(function() {
255 $(".phrase").val("abandon abandon ability");
256 $(".passphrase").val("secure_passphrase").trigger("input");
258 // check the address is generated correctly
259 waitForGenerate(function() {
260 var actual
= page
.evaluate(function() {
261 return $(".address:first").text();
263 if (actual
!= expected
) {
264 console
.log("Passphrase results in wrong address");
265 console
.log("Expected: " + expected
);
266 console
.log("Actual: " + actual
);
274 // Network can be set to bitcoin testnet
276 page
.open(url
, function(status
) {
277 // set the phrase and coin
278 var expected
= "mucaU5iiDaJDb69BHLeDv8JFfGiyg2nJKi";
279 page
.evaluate(function() {
280 $(".phrase").val("abandon abandon ability");
281 $(".phrase").trigger("input");
282 $(".network option[selected]").removeAttr("selected");
283 $(".network option").filter(function() {
284 return $(this).html() == "BTC - Bitcoin Testnet";
285 }).prop("selected", true);
286 $(".network").trigger("change");
288 // check the address is generated correctly
289 waitForGenerate(function() {
290 var actual
= page
.evaluate(function() {
291 return $(".address:first").text();
293 if (actual
!= expected
) {
294 console
.log("Bitcoin testnet address is incorrect");
295 console
.log("Expected: " + expected
);
296 console
.log("Actual: " + actual
);
304 // Network can be set to litecoin
306 page
.open(url
, function(status
) {
307 // set the phrase and coin
308 var expected
= "LQ4XU8RX2ULPmPq9FcUHdVmPVchP9nwXdn";
309 page
.evaluate(function() {
310 $(".phrase").val("abandon abandon ability");
311 $(".phrase").trigger("input");
312 $(".network option[selected]").removeAttr("selected");
313 $(".network option").filter(function() {
314 return $(this).html() == "LTC - Litecoin";
315 }).prop("selected", true);
316 $(".network").trigger("change");
318 // check the address is generated correctly
319 waitForGenerate(function() {
320 var actual
= page
.evaluate(function() {
321 return $(".address:first").text();
323 if (actual
!= expected
) {
324 console
.log("Litecoin address is incorrect");
325 console
.log("Expected: " + expected
);
326 console
.log("Actual: " + actual
);
334 // Network can be set to ripple
336 page
.open(url
, function(status
) {
337 // set the phrase and coin
338 var expected
= "rLTFnqbmCVPGx6VfaygdtuKWJgcN4v1zRS";
339 page
.evaluate(function() {
340 $(".phrase").val("ill clump only blind unit burden thing track silver cloth review awake useful craft whale all satisfy else trophy sunset walk vanish hope valve");
341 $(".phrase").trigger("input");
342 $(".network option[selected]").removeAttr("selected");
343 $(".network option").filter(function() {
344 return $(this).html() == "XRP - Ripple";
345 }).prop("selected", true);
346 $(".network").trigger("change");
348 // check the address is generated correctly
349 waitForGenerate(function() {
350 var actual
= page
.evaluate(function() {
351 return $(".address:first").text();
353 if (actual
!= expected
) {
354 console
.log("Ripple address is incorrect");
355 console
.log("Expected: " + expected
);
356 console
.log("Actual: " + actual
);
364 // Network can be set to dogecoin
366 page
.open(url
, function(status
) {
367 // set the phrase and coin
368 var expected
= "DPQH2AtuzkVSG6ovjKk4jbUmZ6iXLpgbJA";
369 page
.evaluate(function() {
370 $(".phrase").val("abandon abandon ability");
371 $(".phrase").trigger("input");
372 $(".network option[selected]").removeAttr("selected");
373 $(".network option").filter(function() {
374 return $(this).html() == "DOGE - Dogecoin";
375 }).prop("selected", true);
376 $(".network").trigger("change");
378 // check the address is generated correctly
379 waitForGenerate(function() {
380 var actual
= page
.evaluate(function() {
381 return $(".address:first").text();
383 if (actual
!= expected
) {
384 console
.log("Dogecoin address is incorrect");
385 console
.log("Expected: " + expected
);
386 console
.log("Actual: " + actual
);
394 // Network can be set to shadowcash
396 page
.open(url
, function(status
) {
397 // set the phrase and coin
398 var expected
= "SiSZtfYAXEFvMm3XM8hmtkGDyViRwErtCG";
399 page
.evaluate(function() {
400 $(".phrase").val("abandon abandon ability");
401 $(".phrase").trigger("input");
402 $(".network option[selected]").removeAttr("selected");
403 $(".network option").filter(function() {
404 return $(this).html() == "SDC - ShadowCash";
405 }).prop("selected", true);
406 $(".network").trigger("change");
408 // check the address is generated correctly
409 waitForGenerate(function() {
410 var actual
= page
.evaluate(function() {
411 return $(".address:first").text();
413 if (actual
!= expected
) {
414 console
.log("Shadowcash address is incorrect");
415 console
.log("Expected: " + expected
);
416 console
.log("Actual: " + actual
);
424 // Network can be set to shadowcash testnet
426 page
.open(url
, function(status
) {
427 // set the phrase and coin
428 var expected
= "tM2EDpVKaTiEg2NZg3yKg8eqjLr55BErHe";
429 page
.evaluate(function() {
430 $(".phrase").val("abandon abandon ability");
431 $(".phrase").trigger("input");
432 $(".network option[selected]").removeAttr("selected");
433 $(".network option").filter(function() {
434 return $(this).html() == "SDC - ShadowCash Testnet";
435 }).prop("selected", true);
436 $(".network").trigger("change");
438 // check the address is generated correctly
439 waitForGenerate(function() {
440 var actual
= page
.evaluate(function() {
441 return $(".address:first").text();
443 if (actual
!= expected
) {
444 console
.log("Shadowcash testnet address is incorrect");
445 console
.log("Expected: " + expected
);
446 console
.log("Actual: " + actual
);
454 // Network can be set to viacoin
456 page
.open(url
, function(status
) {
457 // set the phrase and coin
458 var expected
= "Vq9Eq4N5SQnjqZvxtxzo7hZPW5XnyJsmXT";
459 page
.evaluate(function() {
460 $(".phrase").val("abandon abandon ability");
461 $(".phrase").trigger("input");
462 $(".network option[selected]").removeAttr("selected");
463 $(".network option").filter(function() {
464 return $(this).html() == "VIA - Viacoin";
465 }).prop("selected", true);
466 $(".network").trigger("change");
468 // check the address is generated correctly
469 waitForGenerate(function() {
470 var actual
= page
.evaluate(function() {
471 return $(".address:first").text();
473 if (actual
!= expected
) {
474 console
.log("Viacoin address is incorrect");
475 console
.log("Expected: " + expected
);
476 console
.log("Actual: " + actual
);
484 // Network can be set to viacoin testnet
486 page
.open(url
, function(status
) {
487 // set the phrase and coin
488 var expected
= "tM2EDpVKaTiEg2NZg3yKg8eqjLr55BErHe";
489 page
.evaluate(function() {
490 $(".phrase").val("abandon abandon ability");
491 $(".phrase").trigger("input");
492 $(".network option[selected]").removeAttr("selected");
493 $(".network option").filter(function() {
494 return $(this).html() == "VIA - Viacoin Testnet";
495 }).prop("selected", true);
496 $(".network").trigger("change");
498 // check the address is generated correctly
499 waitForGenerate(function() {
500 var actual
= page
.evaluate(function() {
501 return $(".address:first").text();
503 if (actual
!= expected
) {
504 console
.log("Viacoin testnet address is incorrect");
505 console
.log("Expected: " + expected
);
506 console
.log("Actual: " + actual
);
514 // Network can be set to jumbucks
516 page
.open(url
, function(status
) {
517 // set the phrase and coin
518 var expected
= "JLEXccwDXADK4RxBPkRez7mqsHVoJBEUew";
519 page
.evaluate(function() {
520 $(".phrase").val("abandon abandon ability");
521 $(".phrase").trigger("input");
522 $(".network option[selected]").removeAttr("selected");
523 $(".network option").filter(function() {
524 return $(this).html() == "JBS - Jumbucks";
525 }).prop("selected", true);
526 $(".network").trigger("change");
528 // check the address is generated correctly
529 waitForGenerate(function() {
530 var actual
= page
.evaluate(function() {
531 return $(".address:first").text();
533 if (actual
!= expected
) {
534 console
.log("Jumbucks address is incorrect");
535 console
.log("Expected: " + expected
);
536 console
.log("Actual: " + actual
);
544 // Network can be set to clam
546 page
.open(url
, function(status
) {
547 // set the phrase and coin
548 var expected
= "xCp4sakjVx4pUAZ6cBCtuin8Ddb6U1sk9y";
549 page
.evaluate(function() {
550 $(".phrase").val("abandon abandon ability");
551 $(".phrase").trigger("input");
552 $(".network option[selected]").removeAttr("selected");
553 $(".network option").filter(function() {
554 return $(this).html() == "CLAM - Clams";
555 }).prop("selected", true);
556 $(".network").trigger("change");
558 // check the address is generated correctly
559 waitForGenerate(function() {
560 var actual
= page
.evaluate(function() {
561 return $(".address:first").text();
563 if (actual
!= expected
) {
564 console
.log("CLAM address is incorrect");
565 console
.log("Expected: " + expected
);
566 console
.log("Actual: " + actual
);
574 // Network can be set to crown
576 page
.open(url
, function(status
) {
577 // set the phrase and coin
578 var expected
= "18pWSwSUAQdiwMHUfFZB1fM2xue9X1FqE5";
579 page
.evaluate(function() {
580 $(".phrase").val("abandon abandon ability");
581 $(".phrase").trigger("input");
582 $(".network option[selected]").removeAttr("selected");
583 $(".network option").filter(function() {
584 return $(this).html() == "CRW - Crown";
585 }).prop("selected", true);
586 $(".network").trigger("change");
588 // check the address is generated correctly
589 waitForGenerate(function() {
590 var actual
= page
.evaluate(function() {
591 return $(".address:first").text();
593 if (actual
!= expected
) {
594 console
.log("CRW address is incorrect");
595 console
.log("Expected: " + expected
);
596 console
.log("Actual: " + actual
);
604 // Network can be set to dash
606 page
.open(url
, function(status
) {
607 // set the phrase and coin
608 var expected
= "XdbhtMuGsPSkE6bPdNTHoFSszQKmK4S5LT";
609 page
.evaluate(function() {
610 $(".phrase").val("abandon abandon ability");
611 $(".phrase").trigger("input");
612 $(".network option[selected]").removeAttr("selected");
613 $(".network option").filter(function() {
614 return $(this).html() == "DASH - Dash";
615 }).prop("selected", true);
616 $(".network").trigger("change");
618 // check the address is generated correctly
619 waitForGenerate(function() {
620 var actual
= page
.evaluate(function() {
621 return $(".address:first").text();
623 if (actual
!= expected
) {
624 console
.log("DASH address is incorrect");
625 console
.log("Expected: " + expected
);
626 console
.log("Actual: " + actual
);
635 page
.open(url
, function(status
) {
636 // set the phrase and coin
637 var expected
= "yaR52EN4oojdJfBgzWJTymC4uuCLPT29Gw";
638 page
.evaluate(function() {
639 $(".phrase").val("abandon abandon ability");
640 $(".phrase").trigger("input");
641 $(".network option[selected]").removeAttr("selected");
642 $(".network option").filter(function() {
643 return $(this).html() == "DASH - Dash Testnet";
644 }).prop("selected", true);
645 $(".network").trigger("change");
647 // check the address is generated correctly
648 waitForGenerate(function() {
649 var actual
= page
.evaluate(function() {
650 return $(".address:first").text();
652 if (actual
!= expected
) {
653 console
.log("DASH Testnet address is incorrect");
654 console
.log("Expected: " + expected
);
655 console
.log("Actual: " + actual
);
663 // Network can be set to game
665 page
.open(url
, function(status
) {
666 // set the phrase and coin
667 var expected
= "GSMY9bAp36cMR4zyT4uGVS7GFjpdXbao5Q";
668 page
.evaluate(function() {
669 $(".phrase").val("abandon abandon ability");
670 $(".phrase").trigger("input");
671 $(".network option[selected]").removeAttr("selected");
672 $(".network option").filter(function() {
673 return $(this).html() == "GAME - GameCredits";
674 }).prop("selected", true);
675 $(".network").trigger("change");
677 // check the address is generated correctly
678 waitForGenerate(function() {
679 var actual
= page
.evaluate(function() {
680 return $(".address:first").text();
682 if (actual
!= expected
) {
683 console
.log("GAME address is incorrect");
684 console
.log("Expected: " + expected
);
685 console
.log("Actual: " + actual
);
693 // Network can be set to namecoin
695 page
.open(url
, function(status
) {
696 // set the phrase and coin
697 var expected
= "Mw2vK2Bvex1yYtYF6sfbEg2YGoUc98YUD2";
698 page
.evaluate(function() {
699 $(".phrase").val("abandon abandon ability");
700 $(".phrase").trigger("input");
701 $(".network option[selected]").removeAttr("selected");
702 $(".network option").filter(function() {
703 return $(this).html() == "NMC - Namecoin";
704 }).prop("selected", true);
705 $(".network").trigger("change");
707 // check the address is generated correctly
708 waitForGenerate(function() {
709 var actual
= page
.evaluate(function() {
710 return $(".address:first").text();
712 if (actual
!= expected
) {
713 console
.log("Namecoin address is incorrect");
714 console
.log("Expected: " + expected
);
715 console
.log("Actual: " + actual
);
723 // Network can be set to peercoin
725 page
.open(url
, function(status
) {
726 // set the phrase and coin
727 var expected
= "PVAiioTaK2eDHSEo3tppT9AVdBYqxRTBAm";
728 page
.evaluate(function() {
729 $(".phrase").val("abandon abandon ability");
730 $(".phrase").trigger("input");
731 $(".network option[selected]").removeAttr("selected");
732 $(".network option").filter(function() {
733 return $(this).html() == "PPC - Peercoin";
734 }).prop("selected", true);
735 $(".network").trigger("change");
737 // check the address is generated correctly
738 waitForGenerate(function() {
739 var actual
= page
.evaluate(function() {
740 return $(".address:first").text();
742 if (actual
!= expected
) {
743 console
.log("Peercoin address is incorrect");
744 console
.log("Expected: " + expected
);
745 console
.log("Actual: " + actual
);
753 // Network can be set to ethereum
756 page
.open(url
, function(status
) {
758 // set the phrase and coin
759 page
.evaluate(function() {
760 $(".phrase").val("abandon abandon ability");
761 $(".phrase").trigger("input");
762 $(".network option[selected]").removeAttr("selected");
763 $(".network option").filter(function() {
764 return $(this).html() == "ETH - Ethereum";
765 }).prop("selected", true);
766 $(".network").trigger("change");
768 waitForGenerate(function() {
769 // check the address is generated correctly
770 // this value comes from
771 // https://www.myetherwallet.com/#view-wallet-info
772 // Unusual capitalization is due to checksum
773 var expected
= "0xe5815d5902Ad612d49283DEdEc02100Bd44C2772";
774 var actual
= page
.evaluate(function() {
775 return $(".address:first").text();
777 if (actual
!= expected
) {
778 console
.log("Ethereum address is incorrect");
779 console
.log("Expected: " + expected
);
780 console
.log("Actual: " + actual
);
783 // check the private key is correct
784 // this private key can be imported into
785 // https://www.myetherwallet.com/#view-wallet-info
786 // and it should correlate to the address above
787 var expected
= "0x8f253078b73d7498302bb78c171b23ce7a8fb511987d2b2702b731638a4a15e7";
788 var actual
= page
.evaluate(function() {
789 return $(".privkey:first").text();
791 if (actual
!= expected
) {
792 console
.log("Ethereum privkey is incorrect");
793 console
.log("Expected: " + expected
);
794 console
.log("Actual: " + actual
);
797 // check the public key is correct
799 // don't have any third-party source to generate the expected value
800 //var expected = "?";
801 //var actual = page.evaluate(function() {
802 // return $(".pubkey:first").text();
804 //if (actual != expected) {
805 // console.log("Ethereum privkey is incorrect");
806 // console.log("Expected: " + expected);
807 // console.log("Actual: " + actual);
815 // Network can be set to Slimcoin
817 page
.open(url
, function(status
) {
818 // set the phrase and coin
819 var expected
= "SNzPi1CafHFm3WWjRo43aMgiaEEj3ogjww";
820 page
.evaluate(function() {
821 $(".phrase").val("abandon abandon ability");
822 $(".phrase").trigger("input");
823 $(".network option[selected]").removeAttr("selected");
824 $(".network option").filter(function() {
825 return $(this).html() == "SLM - Slimcoin";
826 }).prop("selected", true);
827 $(".network").trigger("change");
829 // check the address is generated correctly
830 waitForGenerate(function() {
831 var actual
= page
.evaluate(function() {
832 return $(".address:first").text();
834 if (actual
!= expected
) {
835 console
.log("Slimcoin address is incorrect");
836 console
.log("Expected: " + expected
);
837 console
.log("Actual: " + actual
);
845 // Network can be set to Slimcointn
847 page
.open(url
, function(status
) {
848 // set the phrase and coin
849 var expected
= "n3nMgWufTek5QQAr6uwMhg5xbzj8xqc4Dq";
850 page
.evaluate(function() {
851 $(".phrase").val("abandon abandon ability");
852 $(".phrase").trigger("input");
853 $(".network option[selected]").removeAttr("selected");
854 $(".network option").filter(function() {
855 return $(this).html() == "SLM - Slimcoin Testnet";
856 }).prop("selected", true);
857 $(".network").trigger("change");
859 // check the address is generated correctly
860 waitForGenerate(function() {
861 var actual
= page
.evaluate(function() {
862 return $(".address:first").text();
864 if (actual
!= expected
) {
865 console
.log("Slimcoin testnet address is incorrect");
866 console
.log("Expected: " + expected
);
867 console
.log("Actual: " + actual
);
875 // BIP39 seed is set from phrase
877 page
.open(url
, function(status
) {
879 var expected
= "20da140d3dd1df8713cefcc4d54ce0e445b4151027a1ab567b832f6da5fcc5afc1c3a3f199ab78b8e0ab4652efd7f414ac2c9a3b81bceb879a70f377aa0a58f3";
880 page
.evaluate(function() {
881 $(".phrase").val("abandon abandon ability");
882 $(".phrase").trigger("input");
884 // check the address is generated correctly
885 waitForGenerate(function() {
886 var actual
= page
.evaluate(function() {
887 return $(".seed").val();
889 if (actual
!= expected
) {
890 console
.log("BIP39 seed is incorrectly generated from mnemonic");
891 console
.log("Expected: " + expected
);
892 console
.log("Actual: " + actual
);
900 // BIP32 root key is set from phrase
902 page
.open(url
, function(status
) {
904 var expected
= "xprv9s21ZrQH143K2jkGDCeTLgRewT9F2pH5JZs2zDmmjXes34geVnFiuNa8KTvY5WoYvdn4Ag6oYRoB6cXtc43NgJAEqDXf51xPm6fhiMCKwpi";
905 page
.evaluate(function() {
906 $(".phrase").val("abandon abandon ability");
907 $(".phrase").trigger("input");
909 // check the address is generated correctly
910 waitForGenerate(function() {
911 var actual
= page
.evaluate(function() {
912 return $(".root-key").val();
914 if (actual
!= expected
) {
915 console
.log("Root key is incorrectly generated from mnemonic");
916 console
.log("Expected: " + expected
);
917 console
.log("Actual: " + actual
);
925 // Tabs show correct addresses when changed
927 page
.open(url
, function(status
) {
929 var expected
= "17uQ7s2izWPwBmEVFikTmZUjbBKWYdJchz";
930 page
.evaluate(function() {
931 $(".phrase").val("abandon abandon ability");
932 $(".phrase").trigger("input");
935 waitForGenerate(function() {
936 page
.evaluate(function() {
937 $("#bip32-tab a").click();
939 // check the address is generated correctly
940 waitForGenerate(function() {
941 var actual
= page
.evaluate(function() {
942 return $(".address:first").text();
944 if (actual
!= expected
) {
945 console
.log("Clicking tab generates incorrect address");
946 console
.log("Expected: " + expected
);
947 console
.log("Actual: " + actual
);
956 // BIP44 derivation path is shown
958 page
.open(url
, function(status
) {
960 var expected
= "m/44'/0'/0'/0";
961 page
.evaluate(function() {
962 $(".phrase").val("abandon abandon ability");
963 $(".phrase").trigger("input");
965 // check the derivation path of the first address
966 waitForGenerate(function() {
967 var actual
= page
.evaluate(function() {
968 return $("#bip44 .path").val();
970 if (actual
!= expected
) {
971 console
.log("BIP44 derivation path is incorrect");
972 console
.log("Expected: " + expected
);
973 console
.log("Actual: " + actual
);
981 // BIP44 extended private key is shown
983 page
.open(url
, function(status
) {
985 var expected
= "xprvA2DxxvPZcyRvYgZMGS53nadR32mVDeCyqQYyFhrCVbJNjPoxMeVf7QT5g7mQASbTf9Kp4cryvcXnu2qurjWKcrdsr91jXymdCDNxKgLFKJG";
986 page
.evaluate(function() {
987 $(".phrase").val("abandon abandon ability");
988 $(".phrase").trigger("input");
990 // check the BIP44 extended private key
991 waitForGenerate(function() {
992 var actual
= page
.evaluate(function() {
993 return $(".extended-priv-key").val();
995 if (actual
!= expected
) {
996 console
.log("BIP44 extended private key is incorrect");
997 console
.log("Expected: " + expected
);
998 console
.log("Actual: " + actual
);
1006 // BIP44 extended public key is shown
1008 page
.open(url
, function(status
) {
1010 var expected
= "xpub6FDKNRvTTLzDmAdpNTc49ia9b4byd6vqCdUa46Fp3vqMcC96uBoufCmZXQLiN5AK3iSCJMhf9gT2sxkpyaPepRuA7W3MujV5tGmF5VfbueM";
1011 page
.evaluate(function() {
1012 $(".phrase").val("abandon abandon ability");
1013 $(".phrase").trigger("input");
1015 // check the BIP44 extended public key
1016 waitForGenerate(function() {
1017 var actual
= page
.evaluate(function() {
1018 return $(".extended-pub-key").val();
1020 if (actual
!= expected
) {
1021 console
.log("BIP44 extended public key is incorrect");
1022 console
.log("Expected: " + expected
);
1023 console
.log("Actual: " + actual
);
1031 // BIP44 account field changes address list
1033 page
.open(url
, function(status
) {
1035 var expected
= "1Nq2Wmu726XHCuGhctEtGmhxo3wzk5wZ1H";
1036 page
.evaluate(function() {
1037 $(".phrase").val("abandon abandon ability");
1038 $(".phrase").trigger("input");
1040 waitForGenerate(function() {
1041 // change the bip44 purpose field to 45
1042 page
.evaluate(function() {
1043 $("#bip44 .account").val("1");
1044 $("#bip44 .account").trigger("input");
1046 waitForGenerate(function() {
1047 // check the address for the new derivation path
1048 var actual
= page
.evaluate(function() {
1049 return $(".address:first").text();
1051 if (actual
!= expected
) {
1052 console
.log("BIP44 account field generates incorrect address");
1053 console
.log("Expected: " + expected
);
1054 console
.log("Actual: " + actual
);
1063 // BIP44 change field changes address list
1065 page
.open(url
, function(status
) {
1067 var expected
= "1KAGfWgqfVbSSXY56fNQ7YnhyKuoskHtYo";
1068 page
.evaluate(function() {
1069 $(".phrase").val("abandon abandon ability");
1070 $(".phrase").trigger("input");
1072 waitForGenerate(function() {
1073 // change the bip44 purpose field to 45
1074 page
.evaluate(function() {
1075 $("#bip44 .change").val("1");
1076 $("#bip44 .change").trigger("input");
1078 waitForGenerate(function() {
1079 // check the address for the new derivation path
1080 var actual
= page
.evaluate(function() {
1081 return $(".address:first").text();
1083 if (actual
!= expected
) {
1084 console
.log("BIP44 change field generates incorrect address");
1085 console
.log("Expected: " + expected
);
1086 console
.log("Actual: " + actual
);
1095 // BIP32 derivation path can be set
1097 page
.open(url
, function(status
) {
1099 var expected
= "16pYQQdLD1hH4hwTGLXBaZ9Teboi1AGL8L";
1100 page
.evaluate(function() {
1101 $(".phrase").val("abandon abandon ability");
1102 $(".phrase").trigger("input");
1105 waitForGenerate(function() {
1106 page
.evaluate(function() {
1107 $("#bip32-tab a").click();
1109 // set the derivation path to m/1
1110 waitForGenerate(function() {
1111 page
.evaluate(function() {
1112 $("#bip32 .path").val("m/1");
1113 $("#bip32 .path").trigger("input");
1115 // check the address is generated correctly
1116 waitForGenerate(function() {
1117 var actual
= page
.evaluate(function() {
1118 return $(".address:first").text();
1120 if (actual
!= expected
) {
1121 console
.log("Custom BIP32 path generates incorrect address");
1122 console
.log("Expected: " + expected
);
1123 console
.log("Actual: " + actual
);
1133 // BIP32 can use hardened derivation paths
1135 page
.open(url
, function(status
) {
1137 var expected
= "14aXZeprXAE3UUKQc4ihvwBvww2LuEoHo4";
1138 page
.evaluate(function() {
1139 $(".phrase").val("abandon abandon ability");
1140 $(".phrase").trigger("input");
1143 waitForGenerate(function() {
1144 page
.evaluate(function() {
1145 $("#bip32-tab a").click();
1147 // set the derivation path to m/0'
1148 waitForGenerate(function() {
1149 page
.evaluate(function() {
1150 $("#bip32 .path").val("m/0'");
1151 $("#bip32 .path").trigger("input");
1153 // check the address is generated correctly
1154 waitForGenerate(function() {
1155 var actual
= page
.evaluate(function() {
1156 return $(".address:first").text();
1158 if (actual
!= expected
) {
1159 console
.log("Hardened BIP32 path generates incorrect address");
1160 console
.log("Expected: " + expected
);
1161 console
.log("Actual: " + actual
);
1171 // BIP32 extended private key is shown
1173 page
.open(url
, function(status
) {
1175 var expected
= "xprv9va99uTVE5aLiutUVLTyfxfe8v8aaXjSQ1XxZbK6SezYVuikA9MnjQVTA8rQHpNA5LKvyQBpLiHbBQiiccKiBDs7eRmBogsvq3THFeLHYbe";
1176 page
.evaluate(function() {
1177 $(".phrase").val("abandon abandon ability");
1178 $(".phrase").trigger("input");
1181 waitForGenerate(function() {
1182 page
.evaluate(function() {
1183 $("#bip32-tab a").click();
1185 // check the extended private key is generated correctly
1186 waitForGenerate(function() {
1187 var actual
= page
.evaluate(function() {
1188 return $(".extended-priv-key").val();
1190 if (actual
!= expected
) {
1191 console
.log("BIP32 extended private key is incorrect");
1192 console
.log("Expected: " + expected
);
1193 console
.log("Actual: " + actual
);
1202 // BIP32 extended public key is shown
1204 page
.open(url
, function(status
) {
1206 var expected
= "xpub69ZVZQzP4T8dwPxwbMzz36cNgwy4yzTHmETZMyihzzXXNi3thgg3HCow1RtY252wdw5rS8369xKnraN5Q93y3FkFfJp2XEHWUrkyXsjS93P";
1207 page
.evaluate(function() {
1208 $(".phrase").val("abandon abandon ability");
1209 $(".phrase").trigger("input");
1212 waitForGenerate(function() {
1213 page
.evaluate(function() {
1214 $("#bip32-tab a").click();
1216 // check the extended public key is generated correctly
1217 waitForGenerate(function() {
1218 var actual
= page
.evaluate(function() {
1219 return $(".extended-pub-key").val();
1221 if (actual
!= expected
) {
1222 console
.log("BIP32 extended public key is incorrect");
1223 console
.log("Expected: " + expected
);
1224 console
.log("Actual: " + actual
);
1233 // Derivation path is shown in table
1235 page
.open(url
, function(status
) {
1237 var expected
= "m/44'/0'/0'/0/0";
1238 page
.evaluate(function() {
1239 $(".phrase").val("abandon abandon ability");
1240 $(".phrase").trigger("input");
1242 // check for derivation path in table
1243 waitForGenerate(function() {
1244 var actual
= page
.evaluate(function() {
1245 return $(".index:first").text();
1247 if (actual
!= expected
) {
1248 console
.log("Derivation path shown incorrectly in table");
1249 console
.log("Expected: " + expected
);
1250 console
.log("Actual: " + actual
);
1258 // Derivation path for address can be hardened
1260 page
.open(url
, function(status
) {
1262 var expected
= "18exLzUv7kfpiXRzmCjFDoC9qwNLFyvwyd";
1263 page
.evaluate(function() {
1264 $(".phrase").val("abandon abandon ability");
1265 $(".phrase").trigger("input");
1268 waitForGenerate(function() {
1269 page
.evaluate(function() {
1270 $("#bip32-tab a").click();
1272 waitForGenerate(function() {
1273 // select the hardened addresses option
1274 page
.evaluate(function() {
1275 $(".hardened-addresses").prop("checked", true);
1276 $(".hardened-addresses").trigger("change");
1278 waitForGenerate(function() {
1279 // check the generated address is hardened
1280 var actual
= page
.evaluate(function() {
1281 return $(".address:first").text();
1283 if (actual
!= expected
) {
1284 console
.log("Hardened address is incorrect");
1285 console
.log("Expected: " + expected
);
1286 console
.log("Actual: " + actual
);
1296 // Derivation path visibility can be toggled
1298 page
.open(url
, function(status
) {
1300 page
.evaluate(function() {
1301 $(".phrase").val("abandon abandon ability");
1302 $(".phrase").trigger("input");
1304 waitForGenerate(function() {
1305 // toggle path visibility
1306 page
.evaluate(function() {
1307 $(".index-toggle").click();
1309 // check the path is not visible
1310 var isInvisible
= page
.evaluate(function() {
1311 return $(".index:first span").hasClass("invisible");
1314 console
.log("Toggled derivation path is visible");
1324 page
.open(url
, function(status
) {
1325 var expected
= "1Di3Vp7tBWtyQaDABLAjfWtF6V7hYKJtug";
1327 page
.evaluate(function() {
1328 $(".phrase").val("abandon abandon ability").trigger("input");
1331 waitForGenerate(function() {
1332 var actual
= page
.evaluate(function() {
1333 return $(".address:first").text();
1335 if (actual
!= expected
) {
1336 console
.log("Address is not shown");
1337 console
.log("Expected: " + expected
);
1338 console
.log("Got: " + actual
);
1346 // Addresses are shown in order of derivation path
1348 page
.open(url
, function(status
) {
1350 page
.evaluate(function() {
1351 $(".phrase").val("abandon abandon ability").trigger("input");
1353 // get the derivation paths
1354 waitForGenerate(function() {
1355 var paths
= page
.evaluate(function() {
1356 return $(".index").map(function(i
, e
) {
1360 if (paths
.length
!= 20) {
1361 console
.log("Total paths is less than expected: " + paths
.length
);
1364 for (var i
=0; i
<paths
.length
; i
++) {
1365 var expected
= "m/44'/0'/0'/0/" + i
;
1366 var actual
= paths
[i
];
1367 if (actual
!= expected
) {
1368 console
.log("Path " + i
+ " is incorrect");
1369 console
.log("Expected: " + expected
);
1370 console
.log("Actual: " + actual
);
1379 // Address visibility can be toggled
1381 page
.open(url
, function(status
) {
1383 page
.evaluate(function() {
1384 $(".phrase").val("abandon abandon ability");
1385 $(".phrase").trigger("input");
1387 waitForGenerate(function() {
1388 // toggle address visibility
1389 page
.evaluate(function() {
1390 $(".address-toggle").click();
1392 // check the address is not visible
1393 var isInvisible
= page
.evaluate(function() {
1394 return $(".address:first span").hasClass("invisible");
1397 console
.log("Toggled address is visible");
1405 // Public key is shown
1407 page
.open(url
, function(status
) {
1408 var expected
= "033f5aed5f6cfbafaf223188095b5980814897295f723815fea5d3f4b648d0d0b3";
1410 page
.evaluate(function() {
1411 $(".phrase").val("abandon abandon ability").trigger("input");
1414 waitForGenerate(function() {
1415 var actual
= page
.evaluate(function() {
1416 return $(".pubkey:first").text();
1418 if (actual
!= expected
) {
1419 console
.log("Public key is not shown");
1420 console
.log("Expected: " + expected
);
1421 console
.log("Got: " + actual
);
1429 // Public key visibility can be toggled
1431 page
.open(url
, function(status
) {
1433 page
.evaluate(function() {
1434 $(".phrase").val("abandon abandon ability");
1435 $(".phrase").trigger("input");
1437 waitForGenerate(function() {
1438 // toggle public key visibility
1439 page
.evaluate(function() {
1440 $(".public-key-toggle").click();
1442 // check the public key is not visible
1443 var isInvisible
= page
.evaluate(function() {
1444 return $(".pubkey:first span").hasClass("invisible");
1447 console
.log("Toggled public key is visible");
1455 // Private key is shown
1457 page
.open(url
, function(status
) {
1458 var expected
= "L26cVSpWFkJ6aQkPkKmTzLqTdLJ923e6CzrVh9cmx21QHsoUmrEE";
1460 page
.evaluate(function() {
1461 $(".phrase").val("abandon abandon ability").trigger("input");
1464 waitForGenerate(function() {
1465 var actual
= page
.evaluate(function() {
1466 return $(".privkey:first").text();
1468 if (actual
!= expected
) {
1469 console
.log("Private key is not shown");
1470 console
.log("Expected: " + expected
);
1471 console
.log("Got: " + actual
);
1479 // Private key visibility can be toggled
1481 page
.open(url
, function(status
) {
1483 page
.evaluate(function() {
1484 $(".phrase").val("abandon abandon ability");
1485 $(".phrase").trigger("input");
1487 waitForGenerate(function() {
1488 // toggle private key visibility
1489 page
.evaluate(function() {
1490 $(".private-key-toggle").click();
1492 // check the private key is not visible
1493 var isInvisible
= page
.evaluate(function() {
1494 return $(".privkey:first span").hasClass("invisible");
1497 console
.log("Toggled private key is visible");
1505 // More addresses can be generated
1507 page
.open(url
, function(status
) {
1509 page
.evaluate(function() {
1510 $(".phrase").val("abandon abandon ability");
1511 $(".phrase").trigger("input");
1513 waitForGenerate(function() {
1514 // generate more addresses
1515 page
.evaluate(function() {
1518 waitForGenerate(function() {
1519 // check there are more addresses
1520 var addressCount
= page
.evaluate(function() {
1521 return $(".address").length
;
1523 if (addressCount
!= 40) {
1524 console
.log("More addresses cannot be generated");
1533 // A custom number of additional addresses can be generated
1535 page
.open(url
, function(status
) {
1537 page
.evaluate(function() {
1538 $(".phrase").val("abandon abandon ability");
1539 $(".phrase").trigger("input");
1541 waitForGenerate(function() {
1542 // get the current number of addresses
1543 var oldAddressCount
= page
.evaluate(function() {
1544 return $(".address").length
;
1546 // set a custom number of additional addresses
1547 page
.evaluate(function() {
1548 $(".rows-to-add").val(1);
1550 // generate more addresses
1551 page
.evaluate(function() {
1554 waitForGenerate(function() {
1555 // check there are the correct number of addresses
1556 var newAddressCount
= page
.evaluate(function() {
1557 return $(".address").length
;
1559 if (newAddressCount
- oldAddressCount
!= 1) {
1560 console
.log("Number of additional addresses cannot be customized");
1561 console
.log(newAddressCount
)
1562 console
.log(oldAddressCount
)
1571 // Additional addresses are shown in order of derivation path
1573 page
.open(url
, function(status
) {
1575 page
.evaluate(function() {
1576 $(".phrase").val("abandon abandon ability").trigger("input");
1578 waitForGenerate(function() {
1579 // generate more addresses
1580 page
.evaluate(function() {
1583 // get the derivation paths
1584 waitForGenerate(function() {
1585 var paths
= page
.evaluate(function() {
1586 return $(".index").map(function(i
, e
) {
1590 if (paths
.length
!= 40) {
1591 console
.log("Total additional paths is less than expected: " + paths
.length
);
1594 for (var i
=0; i
<paths
.length
; i
++) {
1595 var expected
= "m/44'/0'/0'/0/" + i
;
1596 var actual
= paths
[i
];
1597 if (actual
!= expected
) {
1598 console
.log("Path " + i
+ " is not in correct order");
1599 console
.log("Expected: " + expected
);
1600 console
.log("Actual: " + actual
);
1610 // BIP32 root key can be set by the user
1612 page
.open(url
, function(status
) {
1613 var expected
= "1Di3Vp7tBWtyQaDABLAjfWtF6V7hYKJtug";
1615 page
.evaluate(function() {
1616 $(".root-key").val("xprv9s21ZrQH143K2jkGDCeTLgRewT9F2pH5JZs2zDmmjXes34geVnFiuNa8KTvY5WoYvdn4Ag6oYRoB6cXtc43NgJAEqDXf51xPm6fhiMCKwpi").trigger("input");
1618 waitForGenerate(function() {
1619 var actual
= page
.evaluate(function() {
1620 return $(".address:first").text();
1622 if (actual
!= expected
) {
1623 console
.log("Setting BIP32 root key results in wrong address");
1624 console
.log("Expected: " + expected
);
1625 console
.log("Actual: " + actual
);
1633 // Setting BIP32 root key clears the existing phrase, passphrase and seed
1635 page
.open(url
, function(status
) {
1638 page
.evaluate(function() {
1639 $(".phrase").val("A non-blank but invalid value");
1641 // Accept any confirm dialogs
1642 page
.onConfirm = function() {
1646 page
.evaluate(function() {
1647 $(".root-key").val("xprv9s21ZrQH143K2jkGDCeTLgRewT9F2pH5JZs2zDmmjXes34geVnFiuNa8KTvY5WoYvdn4Ag6oYRoB6cXtc43NgJAEqDXf51xPm6fhiMCKwpi").trigger("input");
1649 waitForGenerate(function() {
1650 var actual
= page
.evaluate(function() {
1651 return $(".phrase").val();
1653 if (actual
!= expected
) {
1654 console
.log("Phrase not cleared when setting BIP32 root key");
1655 console
.log("Expected: " + expected
);
1656 console
.log("Actual: " + actual
);
1664 // Clearing of phrase, passphrase and seed can be cancelled by user
1666 page
.open(url
, function(status
) {
1667 var expected
= "abandon abandon ability";
1669 page
.evaluate(function() {
1670 $(".phrase").val("abandon abandon ability");
1672 // Cancel any confirm dialogs
1673 page
.onConfirm = function() {
1677 page
.evaluate(function() {
1678 $(".root-key").val("xprv9s21ZrQH143K3d3vzEDD3KpSKmxsZ3y7CqhAL1tinwtP6wqK4TKEKjpBuo6P2hUhB6ZENo7TTSRytiP857hBZVpBdk8PooFuRspE1eywwNZ").trigger("input");
1680 var actual
= page
.evaluate(function() {
1681 return $(".phrase").val();
1683 if (actual
!= expected
) {
1684 console
.log("Phrase not retained when cancelling changes to BIP32 root key");
1685 console
.log("Expected: " + expected
);
1686 console
.log("Actual: " + actual
);
1693 // Custom BIP32 root key is used when changing the derivation path
1695 page
.open(url
, function(status
) {
1696 var expected
= "1Nq2Wmu726XHCuGhctEtGmhxo3wzk5wZ1H";
1698 page
.evaluate(function() {
1699 $(".root-key").val("xprv9s21ZrQH143K2jkGDCeTLgRewT9F2pH5JZs2zDmmjXes34geVnFiuNa8KTvY5WoYvdn4Ag6oYRoB6cXtc43NgJAEqDXf51xPm6fhiMCKwpi").trigger("input");
1701 waitForGenerate(function() {
1702 // change the derivation path
1703 page
.evaluate(function() {
1704 $("#account").val("1").trigger("input");
1706 // check the bip32 root key is used for derivation, not the blank phrase
1707 waitForGenerate(function() {
1708 var actual
= page
.evaluate(function() {
1709 return $(".address:first").text();
1711 if (actual
!= expected
) {
1712 console
.log("Changing the derivation path does not use BIP32 root key");
1713 console
.log("Expected: " + expected
);
1714 console
.log("Actual: " + actual
);
1723 // Incorrect mnemonic shows error
1725 page
.open(url
, function(status
) {
1727 page
.evaluate(function() {
1728 $(".phrase").val("abandon abandon abandon").trigger("input");
1730 waitForFeedback(function() {
1731 // check there is an error shown
1732 var feedback
= page
.evaluate(function() {
1733 return $(".feedback").text();
1735 if (feedback
.length
<= 0) {
1736 console
.log("Invalid mnemonic does not show error");
1744 // Incorrect word shows suggested replacement
1746 page
.open(url
, function(status
) {
1748 page
.evaluate(function() {
1749 $(".phrase").val("abandon abandon abiliti").trigger("input");
1751 // check there is a suggestion shown
1752 waitForFeedback(function() {
1753 var feedback
= page
.evaluate(function() {
1754 return $(".feedback").text();
1756 if (feedback
.indexOf("did you mean ability?") < 0) {
1757 console
.log("Incorrect word does not show suggested replacement");
1758 console
.log("Error: " + error
);
1766 // Github pull request 48
1767 // First four letters of word shows that word, not closest
1768 // since first four letters gives unique word in BIP39 wordlist
1769 // eg ille should show illegal, not idle
1771 page
.open(url
, function(status
) {
1772 // set the incomplete word
1773 page
.evaluate(function() {
1774 $(".phrase").val("ille").trigger("input");
1776 // check there is a suggestion shown
1777 waitForFeedback(function() {
1778 var feedback
= page
.evaluate(function() {
1779 return $(".feedback").text();
1781 if (feedback
.indexOf("did you mean illegal?") < 0) {
1782 console
.log("Start of word does not show correct suggestion");
1783 console
.log("Error: " + error
);
1791 // Incorrect BIP32 root key shows error
1793 page
.open(url
, function(status
) {
1795 page
.evaluate(function() {
1796 $(".root-key").val("xprv9s21ZrQH143K2jkGDCeTLgRewT9F2pH5JZs2zDmmjXes34geVnFiuNa8KTvY5WoYvdn4Ag6oYRoB6cXtc43NgJAEqDXf51xPm6fhiMCKwpj").trigger("input");
1798 // check there is an error shown
1799 waitForFeedback(function() {
1800 var feedback
= page
.evaluate(function() {
1801 return $(".feedback").text();
1803 if (feedback
!= "Invalid root key") {
1804 console
.log("Invalid root key does not show error");
1805 console
.log("Error: " + error
);
1813 // Derivation path not starting with m shows error
1815 page
.open(url
, function(status
) {
1816 // set the mnemonic phrase
1817 page
.evaluate(function() {
1818 $(".phrase").val("abandon abandon ability").trigger("input");
1820 waitForGenerate(function() {
1821 // select the bip32 tab so custom derivation path can be set
1822 page
.evaluate(function() {
1823 $("#bip32-tab a").click();
1825 waitForGenerate(function() {
1826 // set the incorrect derivation path
1827 page
.evaluate(function() {
1828 $("#bip32 .path").val("n/0").trigger("input");
1830 waitForFeedback(function() {
1831 var feedback
= page
.evaluate(function() {
1832 return $(".feedback").text();
1834 if (feedback
!= "First character must be 'm'") {
1835 console
.log("Derivation path not starting with m should show error");
1836 console
.log("Error: " + error
);
1846 // Derivation path containing invalid characters shows useful error
1848 page
.open(url
, function(status
) {
1849 // set the mnemonic phrase
1850 page
.evaluate(function() {
1851 $(".phrase").val("abandon abandon ability").trigger("input");
1853 waitForGenerate(function() {
1854 // select the bip32 tab so custom derivation path can be set
1855 page
.evaluate(function() {
1856 $("#bip32-tab a").click();
1858 waitForGenerate(function() {
1859 // set the incorrect derivation path
1860 page
.evaluate(function() {
1861 $("#bip32 .path").val("m/1/0wrong1/1").trigger("input");
1863 waitForFeedback(function() {
1864 var feedback
= page
.evaluate(function() {
1865 return $(".feedback").text();
1867 if (feedback
!= "Invalid characters 0wrong1 found at depth 2") {
1868 console
.log("Derivation path with invalid characters should show error");
1869 console
.log("Error: " + error
);
1879 // Github Issue 11: Default word length is 15
1880 // https://github.com/iancoleman/bip39/issues/11
1882 page
.open(url
, function(status
) {
1883 // get the word length
1884 var defaultLength
= page
.evaluate(function() {
1885 return $(".strength").val();
1887 if (defaultLength
!= 15) {
1888 console
.log("Default word length is not 15");
1896 // Github Issue 12: Generate more rows with private keys hidden
1897 // https://github.com/iancoleman/bip39/issues/12
1899 page
.open(url
, function(status
) {
1901 page
.evaluate(function() {
1902 $(".phrase").val("abandon abandon ability");
1903 $(".phrase").trigger("input");
1905 waitForGenerate(function() {
1906 // toggle private keys hidden, then generate more addresses
1907 page
.evaluate(function() {
1908 $(".private-key-toggle").click();
1911 waitForGenerate(function() {
1912 // check more have been generated
1914 var numPrivKeys
= page
.evaluate(function() {
1915 return $(".privkey").length
;
1917 if (numPrivKeys
!= expected
) {
1918 console
.log("Wrong number of addresses when clicking 'more' with hidden privkeys");
1919 console
.log("Expected: " + expected
);
1920 console
.log("Actual: " + numPrivKeys
);
1923 // check no private keys are shown
1924 var numHiddenPrivKeys
= page
.evaluate(function() {
1925 return $(".privkey span[class=invisible]").length
;
1927 if (numHiddenPrivKeys
!= expected
) {
1928 console
.log("Generating more does not retain hidden state of privkeys");
1929 console
.log("Expected: " + expected
);
1930 console
.log("Actual: " + numHiddenPrivKeys
);
1939 // Github Issue 19: Mnemonic is not sensitive to whitespace
1940 // https://github.com/iancoleman/bip39/issues/19
1942 page
.open(url
, function(status
) {
1944 var expected
= "xprv9s21ZrQH143K3isaZsWbKVoTtbvd34Y1ZGRugGdMeBGbM3AgBVzTH159mj1cbbtYSJtQr65w6L5xy5L9SFC7c9VJZWHxgAzpj4mun5LhrbC";
1945 page
.evaluate(function() {
1946 var doubleSpace
= " ";
1947 $(".phrase").val("urge cat" + doubleSpace
+ "bid");
1948 $(".phrase").trigger("input");
1950 waitForGenerate(function() {
1951 // Check the bip32 root key is correct
1952 var actual
= page
.evaluate(function() {
1953 return $(".root-key").val();
1955 if (actual
!= expected
) {
1956 console
.log("Mnemonic is sensitive to whitespace");
1957 console
.log("Expected: " + expected
);
1958 console
.log("Actual: " + actual
);
1966 // Github Issue 23: Part 1: Use correct derivation path when changing tabs
1967 // https://github.com/iancoleman/bip39/issues/23
1969 page
.open(url
, function(status
) {
1970 // 1) and 2) set the phrase
1971 page
.evaluate(function() {
1972 $(".phrase").val("abandon abandon ability").trigger("input");
1974 waitForGenerate(function() {
1975 // 3) select bip32 tab
1976 page
.evaluate(function() {
1977 $("#bip32-tab a").click();
1979 waitForGenerate(function() {
1980 // 4) switch from bitcoin to litecoin
1981 page
.evaluate(function() {
1982 $(".network option").filter(function() {
1983 return $(this).html() == "LTC - Litecoin";
1984 }).prop("selected", true);
1985 $(".network").trigger("change");
1987 waitForGenerate(function() {
1988 // 5) Check derivation path is displayed correctly
1989 var expected
= "m/0/0";
1990 var actual
= page
.evaluate(function() {
1991 return $(".index:first").text();
1993 if (actual
!= expected
) {
1994 console
.log("Github Issue 23 Part 1: derivation path display error");
1995 console
.log("Expected: " + expected
);
1996 console
.log("Actual: " + actual
);
1999 // 5) Check address is displayed correctly
2000 var expected
= "LS8MP5LZ5AdzSZveRrjm3aYVoPgnfFh5T5";
2001 var actual
= page
.evaluate(function() {
2002 return $(".address:first").text();
2004 if (actual
!= expected
) {
2005 console
.log("Github Issue 23 Part 1: address display error");
2006 console
.log("Expected: " + expected
);
2007 console
.log("Actual: " + actual
);
2017 // Github Issue 23 Part 2: Coin selection in derivation path
2018 // https://github.com/iancoleman/bip39/issues/23#issuecomment-238011920
2020 page
.open(url
, function(status
) {
2022 page
.evaluate(function() {
2023 $(".phrase").val("abandon abandon ability").trigger("input");
2025 waitForGenerate(function() {
2026 // switch from bitcoin to clam
2027 page
.evaluate(function() {
2028 $(".network option").filter(function() {
2029 return $(this).html() == "CLAM - Clams";
2030 }).prop("selected", true);
2031 $(".network").trigger("change");
2033 waitForGenerate(function() {
2034 // check derivation path is displayed correctly
2035 var expected
= "m/44'/23'/0'/0/0";
2036 var actual
= page
.evaluate(function() {
2037 return $(".index:first").text();
2039 if (actual
!= expected
) {
2040 console
.log("Github Issue 23 Part 2: Coin in BIP44 derivation path is incorrect");
2041 console
.log("Expected: " + expected
);
2042 console
.log("Actual: " + actual
);
2051 // Github Issue 26: When using a Root key derrived altcoins are incorrect
2052 // https://github.com/iancoleman/bip39/issues/26
2054 page
.open(url
, function(status
) {
2055 // 1) 2) and 3) set the root key
2056 page
.evaluate(function() {
2057 $(".root-key").val("xprv9s21ZrQH143K2jkGDCeTLgRewT9F2pH5JZs2zDmmjXes34geVnFiuNa8KTvY5WoYvdn4Ag6oYRoB6cXtc43NgJAEqDXf51xPm6fhiMCKwpi").trigger("input");
2059 waitForGenerate(function() {
2060 // 4) switch from bitcoin to viacoin
2061 page
.evaluate(function() {
2062 $(".network option").filter(function() {
2063 return $(this).html() == "VIA - Viacoin";
2064 }).prop("selected", true);
2065 $(".network").trigger("change");
2067 waitForGenerate(function() {
2068 // 5) ensure the derived address is correct
2069 var expected
= "Vq9Eq4N5SQnjqZvxtxzo7hZPW5XnyJsmXT";
2070 var actual
= page
.evaluate(function() {
2071 return $(".address:first").text();
2073 if (actual
!= expected
) {
2074 console
.log("Github Issue 26: address is incorrect when changing networks and using root-key to derive");
2075 console
.log("Expected: " + expected
);
2076 console
.log("Actual: " + actual
);
2085 // Selecting a language with no existing phrase should generate a phrase in
2088 page
.open(url
, function(status
) {
2089 // Select a language
2090 // Need to manually simulate hash being set due to quirk between
2091 // 'click' event triggered by javascript vs triggered by mouse.
2092 // Perhaps look into page.sendEvent
2093 // http://phantomjs.org/api/webpage/method/send-event.html
2094 page
.evaluate(function() {
2095 window
.location
.hash
= "#japanese";
2096 $("a[href='#japanese']").trigger("click");
2098 waitForGenerate(function() {
2099 // Check the mnemonic is in Japanese
2100 var phrase
= page
.evaluate(function() {
2101 return $(".phrase").val();
2103 if (phrase
.length
<= 0) {
2104 console
.log("No Japanese phrase generated");
2107 if (phrase
.charCodeAt(0) < 128) {
2108 console
.log("First character of Japanese phrase is ascii");
2109 console
.log("Phrase: " + phrase
);
2117 // Selecting a language with existing phrase should update the phrase to use
2120 page
.open(url
, function(status
) {
2121 // Set the phrase to an English phrase.
2122 page
.evaluate(function() {
2123 $(".phrase").val("abandon abandon ability").trigger("input");
2125 waitForGenerate(function() {
2126 // Change to Italian
2127 // Need to manually simulate hash being set due to quirk between
2128 // 'click' event triggered by javascript vs triggered by mouse.
2129 // Perhaps look into page.sendEvent
2130 // http://phantomjs.org/api/webpage/method/send-event.html
2131 page
.evaluate(function() {
2132 window
.location
.hash
= "#italian";
2133 $("a[href='#italian']").trigger("click");
2135 waitForGenerate(function() {
2136 // Check only the language changes, not the phrase
2137 var expected
= "abaco abaco abbaglio";
2138 var actual
= page
.evaluate(function() {
2139 return $(".phrase").val();
2141 if (actual
!= expected
) {
2142 console
.log("Changing language with existing phrase");
2143 console
.log("Expected: " + expected
);
2144 console
.log("Actual: " + actual
);
2147 // Check the address is correct
2148 var expected
= "1Dz5TgDhdki9spa6xbPFbBqv5sjMrx3xgV";
2149 var actual
= page
.evaluate(function() {
2150 return $(".address:first").text();
2152 if (actual
!= expected
) {
2153 console
.log("Changing language generates incorrect address");
2154 console
.log("Expected: " + expected
);
2155 console
.log("Actual: " + actual
);
2164 // Suggested replacement for erroneous word in non-English language
2166 page
.open(url
, function(status
) {
2167 // Set an incorrect phrase in Italian
2168 page
.evaluate(function() {
2169 $(".phrase").val("abaco abaco zbbaglio").trigger("input");
2171 waitForFeedback(function() {
2172 // Check the suggestion is correct
2173 var feedback
= page
.evaluate(function() {
2174 return $(".feedback").text();
2176 if (feedback
.indexOf("did you mean abbaglio?") < 0) {
2177 console
.log("Incorrect Italian word does not show suggested replacement");
2178 console
.log("Error: " + error
);
2187 // Japanese word does not break across lines.
2189 // https://github.com/bitcoin/bips/blob/master/bip-0039/bip-0039-wordlists.md#japanese
2191 page
.open(url
, function(status
) {
2192 hasWordBreakCss
= page
.content
.indexOf("word-break: keep-all;") > -1;
2193 if (!hasWordBreakCss
) {
2194 console
.log("Japanese words can break across lines mid-word");
2195 console
.log("Check CSS for '.phrase { word-break: keep-all; }'");
2198 // Run the next test
2203 // Language can be specified at page load using hash value in url
2205 page
.open(url
, function(status
) {
2206 // Set the page hash as if it were on a fresh page load
2207 page
.evaluate(function() {
2208 window
.location
.hash
= "#japanese";
2210 // Generate a random phrase
2211 page
.evaluate(function() {
2212 $(".generate").trigger("click");
2214 waitForGenerate(function() {
2215 // Check the phrase is in Japanese
2216 var phrase
= page
.evaluate(function() {
2217 return $(".phrase").val();
2219 if (phrase
.length
<= 0) {
2220 console
.log("No phrase generated using url hash");
2223 if (phrase
.charCodeAt(0) < 128) {
2224 console
.log("Language not detected from url hash on page load.");
2225 console
.log("Phrase: " + phrase
);
2233 // Entropy unit tests
2235 page
.open(url
, function(status
) {
2236 var response
= page
.evaluate(function() {
2238 // binary entropy is detected
2240 e
= Entropy
.fromString("01010101");
2241 if (e
.base
.str
!= "binary") {
2242 return "Binary entropy not detected correctly";
2248 // base6 entropy is detected
2250 e
= Entropy
.fromString("012345012345");
2251 if (e
.base
.str
!= "base 6") {
2252 return "base6 entropy not detected correctly";
2258 // dice entropy is detected
2260 e
= Entropy
.fromString("123456123456");
2261 if (e
.base
.str
!= "base 6 (dice)") {
2262 return "dice entropy not detected correctly";
2268 // base10 entropy is detected
2270 e
= Entropy
.fromString("0123456789");
2271 if (e
.base
.str
!= "base 10") {
2272 return "base10 entropy not detected correctly";
2278 // hex entropy is detected
2280 e
= Entropy
.fromString("0123456789ABCDEF");
2281 if (e
.base
.str
!= "hexadecimal") {
2282 return "hexadecimal entropy not detected correctly";
2288 // card entropy is detected
2290 e
= Entropy
.fromString("AC4DTHKS");
2291 if (e
.base
.str
!= "card") {
2292 return "card entropy not detected correctly";
2298 // entropy is case insensitive
2300 e
= Entropy
.fromString("aBcDeF");
2301 if (e
.cleanStr
!= "aBcDeF") {
2302 return "Entropy should not be case sensitive";
2308 // dice entropy is converted to base6
2310 e
= Entropy
.fromString("123456");
2311 if (e
.cleanStr
!= "123450") {
2312 return "Dice entropy is not automatically converted to base6";
2318 // dice entropy is preferred to base6 if ambiguous
2320 e
= Entropy
.fromString("12345");
2321 if (e
.base
.str
!= "base 6 (dice)") {
2322 return "dice not used as default over base 6";
2328 // unused characters are ignored
2330 e
= Entropy
.fromString("fghijkl");
2331 if (e
.cleanStr
!= "f") {
2332 return "additional characters are not ignored";
2338 // the lowest base is used by default
2339 // 7 could be decimal or hexadecimal, but should be detected as decimal
2341 e
= Entropy
.fromString("7");
2342 if (e
.base
.str
!= "base 10") {
2343 return "lowest base is not used";
2349 // Leading zeros are retained
2351 e
= Entropy
.fromString("000A");
2352 if (e
.cleanStr
!= "000A") {
2353 return "Leading zeros are not retained";
2359 // Leading zeros are correctly preserved for hex in binary string
2361 e
= Entropy
.fromString("2A");
2362 if (e
.binaryStr
!= "00101010") {
2363 return "Hex leading zeros are not correct in binary";
2369 // Leading zeros for base 6 as binary string
2370 // 20 = 2 events at 2.58 bits per event = 5 bits
2371 // 20 in base 6 = 12 in base 10 = 1100 in base 2
2372 // so it needs 1 bit of padding to be the right bit length
2374 e
= Entropy
.fromString("20");
2375 if (e
.binaryStr
!= "01100") {
2376 return "Base 6 as binary has leading zeros";
2382 // Leading zeros for base 10 as binary string
2384 e
= Entropy
.fromString("17");
2385 if (e
.binaryStr
!= "010001") {
2386 return "Base 10 as binary has leading zeros";
2392 // Leading zeros for card entropy as binary string.
2393 // Card entropy is hashed so 2c does not necessarily produce leading zeros.
2395 e
= Entropy
.fromString("2c");
2396 if (e
.binaryStr
!= "0010") {
2397 return "Card entropy as binary has leading zeros";
2403 // Keyboard mashing results in weak entropy
2404 // Despite being a long string, it's less than 30 bits of entropy
2406 e
= Entropy
.fromString("aj;se ifj; ask,dfv js;ifj");
2407 if (e
.binaryStr
.length
>= 30) {
2408 return "Keyboard mashing should produce weak entropy";
2414 // Card entropy is used if every pair could be a card
2416 e
= Entropy
.fromString("4c3c2c");
2417 if (e
.base
.str
!= "card") {
2418 return "Card entropy not used if all pairs are cards";
2424 // Card entropy uses base 52
2425 // [ cards, binary ]
2429 [ "acqs", "11011100" ],
2430 [ "acks", "01011100" ],
2431 [ "2cac", "11111000" ],
2444 [ "ks2c", "01010100" ],
2445 [ "KS2C", "01010100" ],
2447 for (var i
=0; i
<cards
.length
; i
++) {
2448 var card
= cards
[i
][0];
2449 var result
= cards
[i
][1];
2450 e
= Entropy
.fromString(card
);
2451 console
.log(e
.binary
+ " " + result
);
2452 if (e
.binaryStr
!== result
) {
2453 return "card entropy " + card
+ " not parsed correctly: " + result
+ " != " + e
.binaryStr
;
2462 if (response
!= "PASS") {
2463 console
.log("Entropy unit tests");
2464 console
.log(response
);
2471 // Entropy can be entered by the user
2473 page
.open(url
, function(status
) {
2475 mnemonic: "abandon abandon ability",
2476 address: "1Di3Vp7tBWtyQaDABLAjfWtF6V7hYKJtug",
2479 page
.evaluate(function() {
2480 $(".use-entropy").prop("checked", true).trigger("change");
2481 $(".entropy").val("00000000 00000000 00000000 00000000").trigger("input");
2483 // check the mnemonic is set and address is correct
2484 waitForGenerate(function() {
2485 var actual
= page
.evaluate(function() {
2487 address: $(".address:first").text(),
2488 mnemonic: $(".phrase").val(),
2491 if (actual
.mnemonic
!= expected
.mnemonic
) {
2492 console
.log("Entropy does not generate correct mnemonic");
2493 console
.log("Expected: " + expected
.mnemonic
);
2494 console
.log("Got: " + actual
.mnemonic
);
2497 if (actual
.address
!= expected
.address
) {
2498 console
.log("Entropy does not generate correct address");
2499 console
.log("Expected: " + expected
.address
);
2500 console
.log("Got: " + actual
.address
);
2508 // A warning about entropy is shown to the user, with additional information
2510 page
.open(url
, function(status
) {
2511 // get text content from entropy sections of page
2512 var hasWarning
= page
.evaluate(function() {
2513 var entropyText
= $(".entropy-container").text();
2514 var warning
= "mnemonic may be insecure";
2515 if (entropyText
.indexOf(warning
) == -1) {
2518 var readMoreText
= $("#entropy-notes").parent().text();
2519 var goodSources
= "flipping a fair coin, rolling a fair dice, noise measurements etc";
2520 if (readMoreText
.indexOf(goodSources
) == -1) {
2525 // check the warnings and information are shown
2527 console
.log("Page does not contain warning about using own entropy");
2534 // The types of entropy available are described to the user
2536 page
.open(url
, function(status
) {
2537 // get placeholder text for entropy field
2538 var placeholder
= page
.evaluate(function() {
2539 return $(".entropy").attr("placeholder");
2549 for (var i
=0; i
<options
.length
; i
++) {
2550 var option
= options
[i
];
2551 if (placeholder
.indexOf(option
) == -1) {
2552 console
.log("Available entropy type is not shown to user: " + option
);
2560 // The actual entropy used is shown to the user
2562 page
.open(url
, function(status
) {
2564 var badEntropySource
= page
.evaluate(function() {
2565 var entropy
= "Not A Very Good Entropy Source At All";
2566 $(".use-entropy").prop("checked", true).trigger("change");
2567 $(".entropy").val(entropy
).trigger("input");
2569 // check the actual entropy being used is shown
2570 waitForEntropyFeedback(function() {
2571 var expectedText
= "AedEceAA";
2572 var entropyText
= page
.evaluate(function() {
2573 return $(".entropy-container").text();
2575 if (entropyText
.indexOf(expectedText
) == -1) {
2576 console
.log("Actual entropy used is not shown");
2584 // Binary entropy can be entered
2586 page
.open(url
, function(status
) {
2588 page
.evaluate(function() {
2589 $(".use-entropy").prop("checked", true).trigger("change");
2590 $(".entropy").val("01").trigger("input");
2592 // check the entropy is shown to be the correct type
2593 waitForEntropyFeedback(function() {
2594 var entropyText
= page
.evaluate(function() {
2595 return $(".entropy-container").text();
2597 if (entropyText
.indexOf("binary") == -1) {
2598 console
.log("Binary entropy is not detected and presented to user");
2606 // Base 6 entropy can be entered
2608 page
.open(url
, function(status
) {
2610 page
.evaluate(function() {
2611 $(".use-entropy").prop("checked", true).trigger("change");
2612 $(".entropy").val("012345").trigger("input");
2614 // check the entropy is shown to be the correct type
2615 waitForEntropyFeedback(function() {
2616 var entropyText
= page
.evaluate(function() {
2617 return $(".entropy-container").text();
2619 if (entropyText
.indexOf("base 6") == -1) {
2620 console
.log("Base 6 entropy is not detected and presented to user");
2628 // Base 6 dice entropy can be entered
2630 page
.open(url
, function(status
) {
2632 page
.evaluate(function() {
2633 $(".use-entropy").prop("checked", true).trigger("change");
2634 $(".entropy").val("123456").trigger("input");
2636 // check the entropy is shown to be the correct type
2637 waitForEntropyFeedback(function() {
2638 var entropyText
= page
.evaluate(function() {
2639 return $(".entropy-container").text();
2641 if (entropyText
.indexOf("dice") == -1) {
2642 console
.log("Dice entropy is not detected and presented to user");
2650 // Base 10 entropy can be entered
2652 page
.open(url
, function(status
) {
2654 page
.evaluate(function() {
2655 $(".use-entropy").prop("checked", true).trigger("change");
2656 $(".entropy").val("789").trigger("input");
2658 // check the entropy is shown to be the correct type
2659 waitForEntropyFeedback(function() {
2660 var entropyText
= page
.evaluate(function() {
2661 return $(".entropy-container").text();
2663 if (entropyText
.indexOf("base 10") == -1) {
2664 console
.log("Base 10 entropy is not detected and presented to user");
2672 // Hexadecimal entropy can be entered
2674 page
.open(url
, function(status
) {
2676 page
.evaluate(function() {
2677 $(".use-entropy").prop("checked", true).trigger("change");
2678 $(".entropy").val("abcdef").trigger("input");
2680 // check the entropy is shown to be the correct type
2681 waitForEntropyFeedback(function() {
2682 var entropyText
= page
.evaluate(function() {
2683 return $(".entropy-container").text();
2685 if (entropyText
.indexOf("hexadecimal") == -1) {
2686 console
.log("Hexadecimal entropy is not detected and presented to user");
2694 // Dice entropy value is shown as the converted base 6 value
2696 page
.open(url
, function(status
) {
2698 page
.evaluate(function() {
2699 $(".use-entropy").prop("checked", true).trigger("change");
2700 $(".entropy").val("123456").trigger("input");
2702 // check the entropy is shown as base 6, not as the original dice value
2703 waitForEntropyFeedback(function() {
2704 var entropyText
= page
.evaluate(function() {
2705 return $(".entropy-container").text();
2707 if (entropyText
.indexOf("123450") == -1) {
2708 console
.log("Dice entropy is not shown to user as base 6 value");
2711 if (entropyText
.indexOf("123456") > -1) {
2712 console
.log("Dice entropy value is shown instead of true base 6 value");
2720 // The number of bits of entropy accumulated is shown
2722 page
.open(url
, function(status
) {
2725 [ "0000 0000 0000 0000 0000", "20" ],
2728 [ "6", "2" ], // 6 in card is 0 in base 6, 0 in base 6 is 2.6 bits (rounded down to 2 bits)
2729 [ "7", "3" ], // 7 in base 10 is 111 in base 2, no leading zeros
2734 [ "1A", "8" ], // hex is always multiple of 4 bits of entropy
2741 [ "6666", "10" ], // uses dice, so entropy is actually 0000 in base 6, which is 4 lots of 2.58 bits, which is 10.32 bits (rounded down to 10 bits)
2742 [ "2227", "13" ], // Uses base 10, which is 4 lots of 3.32 bits, which is 13.3 bits (rounded down to 13)
2745 [ "0000101017", "33" ], // 10 events at 3.32 bits per event
2746 [ "ac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsks", "225" ], // cards are not replaced, so a full deck is not 52^52 entropy which is 296 bits, it's 52!, which is 225 bits
2749 page
.evaluate(function(e
) {
2750 $(".use-entropy").prop("checked", true).trigger("change");
2753 var nextTest
= function runNextTest(i
) {
2754 var entropy
= tests
[i
][0];
2755 var expected
= tests
[i
][1];
2757 page
.evaluate(function(e
) {
2758 $(".entropy").val(e
).trigger("input");
2760 // check the number of bits of entropy is shown
2761 waitForEntropyFeedback(function() {
2762 var entropyText
= page
.evaluate(function() {
2763 return $(".entropy-container").text();
2765 if (entropyText
.replace(/\s/g,"").indexOf("Bits" + expected
) == -1) {
2766 console
.log("Accumulated entropy is not shown correctly for " + entropy
);
2769 var isLastTest
= i
== tests
.length
- 1;
2782 // There is feedback provided about the supplied entropy
2784 page
.open(url
, function(status
) {
2789 type: "hexadecimal",
2793 strength: "less than a second",
2796 entropy: "AAAAAAAA",
2797 filtered: "AAAAAAAA",
2798 type: "hexadecimal",
2802 strength: "less than a second - Repeats like \"aaa\" are easy to guess",
2805 entropy: "AAAAAAAA B",
2806 filtered: "AAAAAAAAB",
2807 type: "hexadecimal",
2811 strength: "less than a second - Repeats like \"aaa\" are easy to guess",
2814 entropy: "AAAAAAAA BBBBBBBB",
2815 filtered: "AAAAAAAABBBBBBBB",
2816 type: "hexadecimal",
2820 strength: "less than a second - Repeats like \"aaa\" are easy to guess",
2823 entropy: "AAAAAAAA BBBBBBBB CCCCCCCC",
2824 filtered: "AAAAAAAABBBBBBBBCCCCCCCC",
2825 type: "hexadecimal",
2829 strength: "less than a second",
2832 entropy: "AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD",
2833 filtered: "AAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD",
2834 type: "hexadecimal",
2838 strength: "2 minutes",
2841 entropy: "AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDA",
2842 filtered: "AAAAAAAABBBBBBBBCCCCCCCCDDDDDDDA",
2843 type: "hexadecimal",
2850 entropy: "AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDA EEEEEEEE",
2851 filtered: "AAAAAAAABBBBBBBBCCCCCCCCDDDDDDDAEEEEEEEE",
2852 type: "hexadecimal",
2856 strength: "3 years",
2859 entropy: "AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDA EEEEEEEE FFFFFFFF",
2860 filtered: "AAAAAAAABBBBBBBBCCCCCCCCDDDDDDDAEEEEEEEEFFFFFFFF",
2861 type: "hexadecimal",
2865 strength: "centuries",
2873 strength: "less than a second",
2876 entropy: "ac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsks",
2877 type: "card (full deck)",
2881 strength: "centuries",
2884 entropy: "ac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsks3d",
2885 type: "card (full deck, 1 duplicate: 3d)",
2889 strength: "centuries",
2892 entropy: "ac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqs3d4d",
2893 type: "card (2 duplicates: 3d 4d, 1 missing: KS)",
2897 strength: "centuries",
2900 entropy: "ac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqs3d4d5d6d",
2901 type: "card (4 duplicates: 3d 4d 5d..., 1 missing: KS)",
2905 strength: "centuries",
2907 // Next test was throwing uncaught error in zxcvbn
2908 // Also tests 451 bits, ie Math.log2(52!)*2 = 225.58 * 2
2910 entropy: "ac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsksac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsks",
2911 type: "card (full deck, 52 duplicates: ac 2c 3c...)",
2915 strength: "centuries",
2917 // Case insensitivity to duplicate cards
2920 type: "card (1 duplicate: AS)",
2924 strength: "less than a second",
2928 type: "card (1 duplicate: as)",
2932 strength: "less than a second",
2934 // Missing cards are detected
2936 entropy: "ac2c3c4c5c6c7c8c tcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsks",
2937 type: "card (1 missing: 9C)",
2941 strength: "centuries",
2944 entropy: "ac2c3c4c5c6c7c8c tcjcqckcad2d3d4d 6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsks",
2945 type: "card (2 missing: 9C 5D)",
2949 strength: "centuries",
2952 entropy: "ac2c3c4c5c6c7c8c tcjcqckcad2d3d4d 6d7d8d9dtdjd kdah2h3h 5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsks",
2953 type: "card (4 missing: 9C 5D QD...)",
2957 strength: "centuries",
2959 // More than six missing cards does not show message
2961 entropy: "ac2c3c4c5c6c7c8c tcjcqckcad2d3d4d 6d 8d9d jd kdah2h3h 5h6h7h8h9hthjhqhkh 2s3s4s5s6s7s8s9stsjsqsks",
2966 strength: "centuries",
2968 // Multiple decks of cards increases bits per event
2988 entropy: "3d3d3d3d",
2994 entropy: "3d3d3d3d3d",
3000 entropy: "3d3d3d3d3d3d",
3006 entropy: "3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d",
3010 strength: 'less than a second - Repeats like "abcabcabc" are only slightly harder to guess than "abc"',
3014 page
.evaluate(function() {
3015 $(".use-entropy").prop("checked", true).trigger("change");
3017 var nextTest
= function runNextTest(i
) {
3018 function getFeedbackError(expected
, actual
) {
3019 if ("filtered" in expected
&& actual
.indexOf(expected
.filtered
) == -1) {
3020 return "Filtered value not in feedback";
3022 if ("type" in expected
&& actual
.indexOf(expected
.type
) == -1) {
3023 return "Entropy type not in feedback";
3025 if ("events" in expected
&& actual
.indexOf(expected
.events
) == -1) {
3026 return "Event count not in feedback";
3028 if ("bits" in expected
&& actual
.indexOf(expected
.bits
) == -1) {
3029 return "Bit count not in feedback";
3031 if ("strength" in expected
&& actual
.indexOf(expected
.strength
) == -1) {
3032 return "Strength not in feedback";
3034 if ("bitsPerEvent" in expected
&& actual
.indexOf(expected
.bitsPerEvent
) == -1) {
3035 return "bitsPerEvent not in feedback";
3040 page
.evaluate(function(e
) {
3041 $(".addresses").empty();
3042 $(".phrase").val("");
3043 $(".entropy").val(e
).trigger("input");
3045 waitForEntropyFeedback(function() {
3046 var mnemonic
= page
.evaluate(function() {
3047 return $(".phrase").val();
3049 // Check mnemonic length
3050 if ("words" in test
&& test
.words
== 0) {
3051 if (mnemonic
.length
> 0) {
3052 console
.log("Mnemonic length for " + test
.strength
+ " strength is not " + test
.words
);
3053 console
.log("Entropy: " + test
.entropy
);
3054 console
.log("Mnemonic: " + mnemonic
);
3058 else if ("words" in test
) {
3059 if (mnemonic
.split(" ").length
!= test
.words
) {
3060 console
.log("Mnemonic length for " + test
.strength
+ " strength is not " + test
.words
);
3061 console
.log("Entropy: " + test
.entropy
);
3062 console
.log("Mnemonic: " + mnemonic
);
3067 var feedback
= page
.evaluate(function() {
3068 return $(".entropy-container").text();
3070 var feedbackError
= getFeedbackError(test
, feedback
);
3071 if (feedbackError
) {
3072 console
.log("Entropy feedback for " + test
.entropy
+ " returned error");
3073 console
.log(feedbackError
);
3077 var isLastTest
= i
== tests
.length
- 1;
3090 // Entropy is truncated from the left
3092 page
.open(url
, function(status
) {
3093 var expected
= "avocado zoo zone";
3095 page
.evaluate(function() {
3096 $(".use-entropy").prop("checked", true).trigger("change");
3097 var entropy
= "00000000 00000000 00000000 00000000";
3098 entropy
+= "11111111 11111111 11111111 1111"; // Missing last byte
3099 $(".entropy").val(entropy
).trigger("input");
3101 // check the entropy is truncated from the right
3102 waitForGenerate(function() {
3103 var actual
= page
.evaluate(function() {
3104 return $(".phrase").val();
3106 if (actual
!= expected
) {
3107 console
.log("Entropy is not truncated from the right");
3108 console
.log("Expected: " + expected
);
3109 console
.log("Got: " + actual
);
3117 // Very large entropy results in very long mnemonics
3119 page
.open(url
, function(status
) {
3121 page
.evaluate(function() {
3122 $(".use-entropy").prop("checked", true).trigger("change");
3124 // Generate a very long entropy string
3125 for (var i
=0; i
<33; i
++) {
3126 entropy
+= "AAAAAAAA"; // 3 words * 33 iterations = 99 words
3128 $(".entropy").val(entropy
).trigger("input");
3130 // check the mnemonic is very long
3131 waitForGenerate(function() {
3132 var wordCount
= page
.evaluate(function() {
3133 return $(".phrase").val().split(" ").length
;
3135 if (wordCount
!= 99) {
3136 console
.log("Large entropy does not generate long mnemonic");
3137 console
.log("Expected 99 words, got " + wordCount
);
3145 // Is compatible with bip32jp entropy
3146 // https://bip32jp.github.io/english/index.html
3148 // Is incompatible with:
3151 page
.open(url
, function(status
) {
3152 var expected
= "train then jungle barely whip fiber purpose puppy eagle cloud clump hospital robot brave balcony utility detect estate old green desk skill multiply virus";
3154 page
.evaluate(function() {
3155 $(".use-entropy").prop("checked", true).trigger("change");
3156 var entropy
= "543210543210543210543210543210543210543210543210543210543210543210543210543210543210543210543210543";
3157 $(".entropy").val(entropy
).trigger("input");
3159 // check the mnemonic matches the expected value from bip32jp
3160 waitForGenerate(function() {
3161 var actual
= page
.evaluate(function() {
3162 return $(".phrase").val();
3164 if (actual
!= expected
) {
3165 console
.log("Mnemonic does not match bip32jp for base 6 entropy");
3166 console
.log("Expected: " + expected
);
3167 console
.log("Got: " + actual
);
3175 // Blank entropy does not generate mnemonic or addresses
3177 page
.open(url
, function(status
) {
3179 page
.evaluate(function() {
3180 $(".use-entropy").prop("checked", true).trigger("change");
3181 $(".entropy").val("").trigger("input");
3183 waitForFeedback(function() {
3184 // check there is no mnemonic
3185 var phrase
= page
.evaluate(function() {
3186 return $(".phrase").val();
3189 console
.log("Blank entropy does not result in blank mnemonic");
3190 console
.log("Got: " + phrase
);
3193 // check there are no addresses displayed
3194 var addresses
= page
.evaluate(function() {
3195 return $(".address").length
;
3197 if (addresses
!= 0) {
3198 console
.log("Blank entropy does not result in zero addresses");
3201 // Check the feedback says 'blank entropy'
3202 var feedback
= page
.evaluate(function() {
3203 return $(".feedback").text();
3205 if (feedback
!= "Blank entropy") {
3206 console
.log("Blank entropy does not show feedback message");
3214 // Mnemonic length can be selected even for weak entropy
3216 page
.open(url
, function(status
) {
3218 page
.evaluate(function() {
3219 $(".use-entropy").prop("checked", true).trigger("change");
3220 $(".entropy").val("012345");
3221 $(".mnemonic-length").val("18").trigger("change");
3223 // check the mnemonic is the correct length
3224 waitForGenerate(function() {
3225 var phrase
= page
.evaluate(function() {
3226 return $(".phrase").val();
3228 var numberOfWords
= phrase
.split(/\s/g).length
;
3229 if (numberOfWords
!= 18) {
3230 console
.log("Weak entropy cannot be overridden to give 18 word mnemonic");
3231 console
.log(phrase
);
3240 // https://github.com/iancoleman/bip39/issues/33
3241 // Final cards should contribute entropy
3243 page
.open(url
, function(status
) {
3245 page
.evaluate(function() {
3246 $(".use-entropy").prop("checked", true).trigger("change");
3247 $(".entropy").val("7S 9H 9S QH 8C KS AS 7D 7C QD 4S 4D TC 2D 5S JS 3D 8S 8H 4C 3C AC 3S QC 9C JC 7H AD TD JD 6D KH 5C QS 2S 6S 6H JH KD 9D-6C TS TH 4H KC 5H 2H AH 2C 8D 3H 5D").trigger("input");
3250 waitForGenerate(function() {
3251 var originalPhrase
= page
.evaluate(function() {
3252 return $(".phrase").val();
3254 // Set the last 12 cards to be AS
3255 page
.evaluate(function() {
3256 $(".addresses").empty();
3257 $(".entropy").val("7S 9H 9S QH 8C KS AS 7D 7C QD 4S 4D TC 2D 5S JS 3D 8S 8H 4C 3C AC 3S QC 9C JC 7H AD TD JD 6D KH 5C QS 2S 6S 6H JH KD 9D-AS AS AS AS AS AS AS AS AS AS AS AS").trigger("input");
3259 // get the new mnemonic
3260 waitForGenerate(function() {
3261 var newPhrase
= page
.evaluate(function() {
3262 return $(".phrase").val();
3264 // check the phrase has changed
3265 if (newPhrase
== originalPhrase
) {
3266 console
.log("Changing last 12 cards does not change mnemonic");
3267 console
.log("Original:");
3268 console
.log(originalPhrase
);
3269 console
.log("New:");
3270 console
.log(newPhrase
);
3280 // https://github.com/iancoleman/bip39/issues/35
3283 page
.open(url
, function(status
) {
3285 page
.evaluate(function() {
3286 $(".generate").click();
3288 waitForGenerate(function() {
3289 var p
= page
.evaluate(function() {
3290 // get position of mnemonic element
3291 return $(".phrase").offset();
3293 p
.top
= Math
.ceil(p
.top
);
3294 p
.left
= Math
.ceil(p
.left
);
3295 // check the qr code shows
3296 page
.sendEvent("mousemove", p
.left
+4, p
.top
+4);
3297 var qrShowing
= page
.evaluate(function() {
3298 return $(".qr-container").find("canvas").length
> 0;
3301 console
.log("QR Code does not show");
3304 // check the qr code hides
3305 page
.sendEvent("mousemove", p
.left
-4, p
.top
-4);
3306 var qrHidden
= page
.evaluate(function() {
3307 return $(".qr-container").find("canvas").length
== 0;
3310 console
.log("QR Code does not hide");
3318 // BIP44 account extendend private key is shown
3319 // github issue 37 - compatibility with electrum
3321 page
.open(url
, function(status
) {
3323 var expected
= "xprv9yzrnt4zWVJUr1k2VxSPy9ettKz5PpeDMgaVG7UKedhqnw1tDkxP2UyYNhuNSumk2sLE5ctwKZs9vwjsq3e1vo9egCK6CzP87H2cVYXpfwQ";
3324 page
.evaluate(function() {
3325 $(".phrase").val("abandon abandon ability");
3326 $(".phrase").trigger("input");
3328 // check the BIP44 account extended private key
3329 waitForGenerate(function() {
3330 var actual
= page
.evaluate(function() {
3331 return $("#bip44 .account-xprv").val();
3333 if (actual
!= expected
) {
3334 console
.log("BIP44 account extended private key is incorrect");
3335 console
.log("Expected: " + expected
);
3336 console
.log("Actual: " + actual
);
3344 // BIP44 account extendend public key is shown
3345 // github issue 37 - compatibility with electrum
3347 page
.open(url
, function(status
) {
3349 var expected
= "xpub6CzDCPbtLrrn4VpVbyyQLHbdSMpZoHN4iuW64VswCyEpfjM2mJGdaHJ2DyuZwtst96E16VvcERb8BBeJdHSCVmAq9RhtRQg6eAZFrTKCNqf";
3350 page
.evaluate(function() {
3351 $(".phrase").val("abandon abandon ability");
3352 $(".phrase").trigger("input");
3354 // check the BIP44 account extended public key
3355 waitForGenerate(function() {
3356 var actual
= page
.evaluate(function() {
3357 return $("#bip44 .account-xpub").val();
3359 if (actual
!= expected
) {
3360 console
.log("BIP44 account extended public key is incorrect");
3361 console
.log("Expected: " + expected
);
3362 console
.log("Actual: " + actual
);
3371 // BIP32 root key can be set as an xpub
3373 page
.open(url
, function(status
) {
3375 page
.evaluate(function() {
3376 // set xpub for account 0 of bip44 for 'abandon abandon ability'
3377 var bip44AccountXpub
= "xpub6CzDCPbtLrrn4VpVbyyQLHbdSMpZoHN4iuW64VswCyEpfjM2mJGdaHJ2DyuZwtst96E16VvcERb8BBeJdHSCVmAq9RhtRQg6eAZFrTKCNqf";
3378 $("#root-key").val(bip44AccountXpub
);
3379 $("#root-key").trigger("input");
3381 waitForFeedback(function() {
3382 page
.evaluate(function() {
3384 $("#bip32-tab a").click();
3386 waitForGenerate(function() {
3387 page
.evaluate(function() {
3388 // derive external addresses for this xpub
3389 var firstAccountDerivationPath
= "m/0";
3390 $("#bip32-path").val(firstAccountDerivationPath
);
3391 $("#bip32-path").trigger("input");
3393 waitForGenerate(function() {
3394 // check the addresses are generated
3395 var expected
= "1Di3Vp7tBWtyQaDABLAjfWtF6V7hYKJtug";
3396 var actual
= page
.evaluate(function() {
3397 return $(".address:first").text();
3399 if (actual
!= expected
) {
3400 console
.log("xpub key does not generate addresses in table");
3401 console
.log("Expected: " + expected
);
3402 console
.log("Actual: " + actual
);
3405 // check the xprv key is not set
3406 var expected
= "NA";
3407 var actual
= page
.evaluate(function() {
3408 return $(".extended-priv-key").val();
3410 if (actual
!= expected
) {
3411 console
.log("xpub key as root shows derived bip32 xprv key");
3412 console
.log("Expected: " + expected
);
3413 console
.log("Actual: " + actual
);
3416 // check the private key is not set
3417 var expected
= "NA";
3418 var actual
= page
.evaluate(function() {
3419 return $(".privkey:first").text();
3421 if (actual
!= expected
) {
3422 console
.log("xpub key generates private key in addresses table");
3423 console
.log("Expected: " + expected
);
3424 console
.log("Actual: " + actual
);
3435 // xpub for bip32 root key will not work with hardened derivation paths
3437 page
.open(url
, function(status
) {
3439 page
.evaluate(function() {
3440 // set xpub for account 0 of bip44 for 'abandon abandon ability'
3441 var bip44AccountXpub
= "xpub6CzDCPbtLrrn4VpVbyyQLHbdSMpZoHN4iuW64VswCyEpfjM2mJGdaHJ2DyuZwtst96E16VvcERb8BBeJdHSCVmAq9RhtRQg6eAZFrTKCNqf";
3442 $("#root-key").val(bip44AccountXpub
);
3443 $("#root-key").trigger("input");
3445 waitForFeedback(function() {
3446 // Check feedback is correct
3447 var expected
= "Hardened derivation path is invalid with xpub key";
3448 var actual
= page
.evaluate(function() {
3449 return $(".feedback").text();
3451 if (actual
!= expected
) {
3452 console
.log("xpub key with hardened derivation path does not show feedback");
3453 console
.log("Expected: " + expected
);
3454 console
.log("Actual: " + actual
);
3457 // Check no addresses are shown
3459 var actual
= page
.evaluate(function() {
3460 return $(".addresses tr").length
;
3462 if (actual
!= expected
) {
3463 console
.log("addresses still show after setting xpub key with hardened derivation path");
3464 console
.log("Expected: " + expected
);
3465 console
.log("Actual: " + actual
);
3474 // no root key shows feedback
3476 page
.open(url
, function(status
) {
3477 // click the bip32 tab on fresh page
3478 page
.evaluate(function() {
3479 $("#bip32-tab a").click();
3481 waitForFeedback(function() {
3482 // Check feedback is correct
3483 var expected
= "No root key";
3484 var actual
= page
.evaluate(function() {
3485 return $(".feedback").text();
3487 if (actual
!= expected
) {
3488 console
.log("Blank root key not detected");
3489 console
.log("Expected: " + expected
);
3490 console
.log("Actual: " + actual
);
3499 // display error switching tabs while addresses are generating
3501 page
.open(url
, function(status
) {
3503 page
.evaluate(function() {
3504 $(".phrase").val("abandon abandon ability").trigger("input");
3506 waitForGenerate(function() {
3507 // set to generate 500 more addresses
3508 // generate more addresses
3509 // change tabs which should cancel the previous generating
3510 page
.evaluate(function() {
3511 $(".rows-to-add").val("100");
3513 $("#bip32-tab a").click();
3515 // check the derivation paths are in order and of the right quantity
3516 waitForGenerate(function() {
3517 var paths
= page
.evaluate(function() {
3518 return $(".index").map(function(i
, e
) {
3522 for (var i
=0; i
<paths
.length
; i
++) {
3523 var expected
= "m/0/" + i
;
3524 var actual
= paths
[i
];
3525 if (actual
!= expected
) {
3526 console
.log("Path " + i
+ " is not in correct order");
3527 console
.log("Expected: " + expected
);
3528 console
.log("Actual: " + actual
);
3532 if (paths
.length
!= 20) {
3533 console
.log("Generation was not cancelled by new action");
3543 // padding for binary should give length with multiple of 256
3544 // hashed entropy 1111 is length 252, so requires 4 leading zeros
3545 // prior to issue 49 it would only generate 2 leading zeros, ie missing 2
3547 page
.open(url
, function(status
) {
3548 expected
= "avocado valid quantum cross link predict excuse edit street able flame large galaxy ginger nuclear"
3550 page
.evaluate(function() {
3551 $(".use-entropy").prop("checked", true).trigger("change");
3552 $(".mnemonic-length").val("15");
3553 $(".entropy").val("1111").trigger("input");
3555 waitForGenerate(function() {
3557 var actual
= page
.evaluate(function() {
3558 return $(".phrase").val();
3560 // check the mnemonic is correct
3561 if (actual
!= expected
) {
3562 console
.log("Left padding error for entropy");
3563 console
.log("Expected: " + expected
);
3564 console
.log("Actual: " + actual
);
3572 // Github pull request 55
3573 // https://github.com/iancoleman/bip39/pull/55
3576 page
.open(url
, function(status
) {
3577 // set mnemonic and select bip32 tab
3578 page
.evaluate(function() {
3579 $("#bip32-tab a").click();
3580 $(".phrase").val("abandon abandon ability").trigger("input");
3582 waitForGenerate(function() {
3584 // set bip32 client to bitcoin core
3585 page
.evaluate(function() {
3586 var bitcoinCoreIndex
= "0";
3587 $("#bip32-client").val(bitcoinCoreIndex
).trigger("change");
3589 waitForGenerate(function() {
3590 // get the derivation path
3591 var actual
= page
.evaluate(function() {
3592 return $("#bip32-path").val();
3594 // check the derivation path is correct
3595 expected
= "m/0'/0'"
3596 if (actual
!= expected
) {
3597 console
.log("Selecting Bitcoin Core client does not set correct derivation path");
3598 console
.log("Expected: " + expected
);
3599 console
.log("Actual: " + actual
);
3602 // get hardened addresses
3603 var usesHardenedAddresses
= page
.evaluate(function() {
3604 return $(".hardened-addresses").prop("checked");
3606 // check hardened addresses is selected
3607 if(!usesHardenedAddresses
) {
3608 console
.log("Selecting Bitcoin Core client does not use hardened addresses");
3611 // check input is readonly
3612 var pathIsReadonly
= page
.evaluate(function() {
3613 return $("#bip32-path").prop("readonly");
3615 if (!pathIsReadonly
) {
3616 console
.log("Selecting Bitcoin Core client does not set derivation path to readonly");
3620 // set bip32 client to multibit
3621 page
.evaluate(function() {
3622 var multibitIndex
= "2";
3623 $("#bip32-client").val(multibitIndex
).trigger("change");
3625 waitForGenerate(function() {
3626 // get the derivation path
3627 var actual
= page
.evaluate(function() {
3628 return $("#bip32-path").val();
3630 // check the derivation path is correct
3632 if (actual
!= expected
) {
3633 console
.log("Selecting Multibit client does not set correct derivation path");
3634 console
.log("Expected: " + expected
);
3635 console
.log("Actual: " + actual
);
3638 // get hardened addresses
3639 var usesHardenedAddresses
= page
.evaluate(function() {
3640 return $(".hardened-addresses").prop("checked");
3642 // check hardened addresses is selected
3643 if(usesHardenedAddresses
) {
3644 console
.log("Selecting Multibit client does not uncheck hardened addresses");
3647 // CUSTOM DERIVATION PATH
3648 // check input is not readonly
3649 page
.evaluate(function() {
3650 $("#bip32-client").val("custom").trigger("change");
3652 // do not wait for generate, since there is no change to the
3653 // derivation path there is no new generation performed
3654 var pathIsReadonly
= page
.evaluate(function() {
3655 return $("#bip32-path").prop("readonly");
3657 if (pathIsReadonly
) {
3658 console
.log("Selecting Custom Derivation Path does not allow derivation path input");
3669 // https://github.com/iancoleman/bip39/issues/58
3670 // bip32 derivation is correct, does not drop leading zeros
3672 // https://medium.com/@alexberegszaszi/why-do-my-bip32-wallets-disagree-6f3254cc5846
3674 page
.open(url
, function(status
) {
3675 // set the phrase and passphrase
3676 var expected
= "17rxURoF96VhmkcEGCj5LNQkmN9HVhWb7F";
3677 // Note that bitcore generates an incorrect address
3678 // 13EuKhffWkBE2KUwcbkbELZb1MpzbimJ3Y
3679 // see the medium.com link above for more details
3680 page
.evaluate(function() {
3681 $(".phrase").val("fruit wave dwarf banana earth journey tattoo true farm silk olive fence");
3682 $(".passphrase").val("banana").trigger("input");
3684 // check the address is generated correctly
3685 waitForGenerate(function() {
3686 var actual
= page
.evaluate(function() {
3687 return $(".address:first").text();
3689 if (actual
!= expected
) {
3690 console
.log("BIP32 derivation is incorrect");
3691 console
.log("Expected: " + expected
);
3692 console
.log("Actual: " + actual
);
3702 // Japanese mnemonics generate incorrect bip32 seed
3703 // BIP39 seed is set from phrase
3705 page
.open(url
, function(status
) {
3707 var expected
= "a262d6fb6122ecf45be09c50492b31f92e9beb7d9a845987a02cefda57a15f9c467a17872029a9e92299b5cbdf306e3a0ee620245cbd508959b6cb7ca637bd55";
3708 page
.evaluate(function() {
3709 $(".phrase").val("あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あおぞら");
3710 $("#passphrase").val("メートルガバヴァぱばぐゞちぢ十人十色");
3711 $("#passphrase").trigger("input");
3713 // check the seed is generated correctly
3714 waitForGenerate(function() {
3715 var actual
= page
.evaluate(function() {
3716 return $(".seed").val();
3718 if (actual
!= expected
) {
3719 console
.log("BIP39 seed is incorrectly generated from Japanese mnemonic");
3720 console
.log("Expected: " + expected
);
3721 console
.log("Actual: " + actual
);
3729 // BIP49 official test vectors
3730 // https://github.com/bitcoin/bips/blob/master/bip-0049.mediawiki#test-vectors
3732 page
.open(url
, function(status
) {
3733 // set the phrase and select bitcoin testnet
3734 var expected
= "2Mww8dCYPUpKHofjgcXcBCEGmniw9CoaiD2";
3735 page
.evaluate(function() {
3736 $("#bip49-tab a").click();
3737 $(".phrase").val("abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about");
3738 $(".network option[selected]").removeAttr("selected");
3739 $(".network option").filter(function() {
3740 return $(this).html() == "BTC - Bitcoin Testnet";
3741 }).prop("selected", true);
3742 $(".network").trigger("change");
3743 $(".phrase").trigger("input");
3745 // check the first address
3746 waitForGenerate(function() {
3747 var actual
= page
.evaluate(function() {
3748 return $(".address:first").text();
3750 if (actual
!= expected
) {
3751 console
.log("BIP49 address is incorrect");
3752 console
.log("Expected: " + expected
);
3753 console
.log("Actual: " + actual
);
3761 // BIP49 derivation path is shown
3763 page
.open(url
, function(status
) {
3765 var expected
= "m/49'/0'/0'/0";
3766 page
.evaluate(function() {
3767 $("#bip49-tab a").click();
3768 $(".phrase").val("abandon abandon ability").trigger("input");
3770 // check the derivation path of the first address
3771 waitForGenerate(function() {
3772 var actual
= page
.evaluate(function() {
3773 return $("#bip49 .path").val();
3775 if (actual
!= expected
) {
3776 console
.log("BIP49 derivation path is incorrect");
3777 console
.log("Expected: " + expected
);
3778 console
.log("Actual: " + actual
);
3786 // BIP49 extended private key is shown
3788 page
.open(url
, function(status
) {
3790 var expected
= "xprvA1hukYsW7QfX9CVsaDAKde4eryajKa4DKWb6m9YjSnqkiZHrahFwwTJfEQTwBQ5kptWT5pZMkkusT1oK8dc1efQ8VFfq4SLSPAWd7Cpt423";
3791 page
.evaluate(function() {
3792 $("#bip49-tab a").click();
3793 $(".phrase").val("abandon abandon ability").trigger("input");
3795 // check the BIP49 extended private key
3796 waitForGenerate(function() {
3797 var actual
= page
.evaluate(function() {
3798 return $(".extended-priv-key").val();
3800 if (actual
!= expected
) {
3801 console
.log("BIP49 extended private key is incorrect");
3802 console
.log("Expected: " + expected
);
3803 console
.log("Actual: " + actual
);
3811 // BIP49 extended public key is shown
3813 page
.open(url
, function(status
) {
3815 var expected
= "xpub6EhGA4QPwnDpMgaLgEhKzn1PR1RDj2n4gjWhZXxM18NjbMd18EaCVFd95gkLARJaBD2rXAYJED2gdkUbGn1KkrSzCKR554AdABUELoainnt";
3816 page
.evaluate(function() {
3817 $("#bip49-tab a").click();
3818 $(".phrase").val("abandon abandon ability").trigger("input");
3820 // check the BIP49 extended public key
3821 waitForGenerate(function() {
3822 var actual
= page
.evaluate(function() {
3823 return $(".extended-pub-key").val();
3825 if (actual
!= expected
) {
3826 console
.log("BIP49 extended public key is incorrect");
3827 console
.log("Expected: " + expected
);
3828 console
.log("Actual: " + actual
);
3836 // BIP49 account field changes address list
3838 page
.open(url
, function(status
) {
3840 var expected
= "381wg1GGN4rP88rNC9v7QWsiww63yLVPsn";
3841 page
.evaluate(function() {
3842 $("#bip49-tab a").click();
3843 $(".phrase").val("abandon abandon ability").trigger("input");
3845 waitForGenerate(function() {
3846 // change the bip49 account field to 1
3847 page
.evaluate(function() {
3848 $("#bip49 .account").val("1");
3849 $("#bip49 .account").trigger("input");
3851 waitForGenerate(function() {
3852 // check the address for the new derivation path
3853 var actual
= page
.evaluate(function() {
3854 return $(".address:first").text();
3856 if (actual
!= expected
) {
3857 console
.log("BIP49 account field generates incorrect address");
3858 console
.log("Expected: " + expected
);
3859 console
.log("Actual: " + actual
);
3868 // BIP49 change field changes address list
3870 page
.open(url
, function(status
) {
3872 var expected
= "3PEM7MiKed5konBoN66PQhK8r3hjGhy9dT";
3873 page
.evaluate(function() {
3874 $("#bip49-tab a").click();
3875 $(".phrase").val("abandon abandon ability").trigger("input");
3877 waitForGenerate(function() {
3878 // change the bip49 change field to 1
3879 page
.evaluate(function() {
3880 $("#bip49 .change").val("1");
3881 $("#bip49 .change").trigger("input");
3883 waitForGenerate(function() {
3884 // check the address for the new derivation path
3885 var actual
= page
.evaluate(function() {
3886 return $(".address:first").text();
3888 if (actual
!= expected
) {
3889 console
.log("BIP49 change field generates incorrect address");
3890 console
.log("Expected: " + expected
);
3891 console
.log("Actual: " + actual
);
3900 // BIP49 account extendend private key is shown
3902 page
.open(url
, function(status
) {
3904 var expected
= "xprv9y3uhgQbfQZbj3o98nfgLDwGGuCJjUn7GKArSAZXjKgMjSdYHjQmTyf78s22g6jsGrxXvHB6HJeFyvFSPkuYZajeTGMZVXV6aNLWw2fagCn";
3905 page
.evaluate(function() {
3906 $("#bip49-tab a").click();
3907 $(".phrase").val("abandon abandon ability");
3908 $(".phrase").trigger("input");
3910 // check the BIP49 account extended private key
3911 waitForGenerate(function() {
3912 var actual
= page
.evaluate(function() {
3913 return $("#bip49 .account-xprv").val();
3915 if (actual
!= expected
) {
3916 console
.log("BIP49 account extended private key is incorrect");
3917 console
.log("Expected: " + expected
);
3918 console
.log("Actual: " + actual
);
3926 // BIP49 account extendend public key is shown
3928 page
.open(url
, function(status
) {
3930 var expected
= "xpub6C3G7BwVVn7twXscEpCghMszpw2o8wVxdY6TEYy9HfDLcExgqGj21myazAiq6HSmW2F1cBiFqJa3D1cqcDpSh8pbZF5x4iqpd4PyJvd3gjB";
3931 page
.evaluate(function() {
3932 $("#bip49-tab a").click();
3933 $(".phrase").val("abandon abandon ability");
3934 $(".phrase").trigger("input");
3936 // check the BIP49 account extended public key
3937 waitForGenerate(function() {
3938 var actual
= page
.evaluate(function() {
3939 return $("#bip49 .account-xpub").val();
3941 if (actual
!= expected
) {
3942 console
.log("BIP49 account extended public key is incorrect");
3943 console
.log("Expected: " + expected
);
3944 console
.log("Actual: " + actual
);
3952 // Test selecting coin where bip49 is unavailable (eg CLAM)
3954 page
.open(url
, function(status
) {
3956 page
.evaluate(function() {
3957 $("#bip49-tab a").click();
3958 $(".phrase").val("abandon abandon ability");
3959 $(".phrase").trigger("input");
3961 waitForGenerate(function() {
3962 // select non-bip49 network, ie CLAM network
3963 page
.evaluate(function() {
3964 $(".network option[selected]").removeAttr("selected");
3965 $(".network option").filter(function() {
3966 return $(this).html() == "CLAM - Clams";
3967 }).prop("selected", true);
3968 $(".network").trigger("change");
3970 // check the BIP49 error is shown
3971 var bip49ErrorShown
= page
.evaluate(function() {
3972 var bip49hidden
= $("#bip49 .available").hasClass("hidden");
3973 bip49hidden
= bip49hidden
&& !($("#bip49 .unavailable").hasClass("hidden"));
3976 if (!bip49ErrorShown
) {
3977 console
.log("BIP49 error not shown for non-bip49 network");
3980 // check there are no addresses shown
3981 var addressCount
= page
.evaluate(function() {
3982 return $(".address").length
;
3984 if (addressCount
!= 0) {
3985 console
.log("BIP49 address count for non-bip49 network is " + addressCount
);
3988 // check the derived keys are blank
3989 var areBlank
= page
.evaluate(function() {
3990 var prvKeyIsBlank
= $(".extended-priv-key").val().length
== 0;
3991 var pubKeyIsBlank
= $(".extended-pub-key").val().length
== 0;
3992 return prvKeyIsBlank
&& pubKeyIsBlank
;
3995 console
.log("BIP49 extended keys for non-bip49 network are not blank ");
4003 // If you wish to add more tests, do so here...
4005 // Here is a blank test template
4009 page.open(url, function(status) {
4010 // Do something on the page
4011 page.evaluate(function() {
4012 $(".phrase").val("abandon abandon ability").trigger("input");
4014 waitForGenerate(function() {
4015 // Check the result of doing the thing
4016 var expected = "1Di3Vp7tBWtyQaDABLAjfWtF6V7hYKJtug";
4017 var actual = page.evaluate(function() {
4018 return $(".address:first").text();
4020 if (actual != expected) {
4021 console.log("A specific message about what failed");
4022 console.log("Expected: " + expected);
4023 console.log("Actual: " + actual);
4026 // Run the next test
4036 console
.log("Running tests...");
4037 tests
= shuffle(tests
);