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 // Network can be set to bitcoin cash
877 page
.open(url
, function(status
) {
878 // set the phrase and coin
879 var expected
= "1JKvb6wKtsjNoCRxpZ4DGrbniML7z5U16A";
880 page
.evaluate(function() {
881 $(".phrase").val("abandon abandon ability");
882 $(".phrase").trigger("input");
883 $(".network option[selected]").removeAttr("selected");
884 $(".network option").filter(function() {
885 return $(this).html() == "BCH - Bitcoin Cash";
886 }).prop("selected", true);
887 $(".network").trigger("change");
889 // check the address is generated correctly
890 waitForGenerate(function() {
891 var actual
= page
.evaluate(function() {
892 return $(".address:first").text();
894 if (actual
!= expected
) {
895 console
.log("Bitcoin Cash address is incorrect");
896 console
.log("Expected: " + expected
);
897 console
.log("Actual: " + actual
);
905 // Network can be set to myriadcoin
907 page
.open(url
, function(status
) {
908 // set the phrase and coin
909 var expected
= "MJEswvRR46wh9BoiVj9DzKYMBkCramhoBV";
910 page
.evaluate(function() {
911 $(".phrase").val("abandon abandon ability");
912 $(".phrase").trigger("input");
913 $(".network option[selected]").removeAttr("selected");
914 $(".network option").filter(function() {
915 return $(this).html() == "XMY - Myriadcoin";
916 }).prop("selected", true);
917 $(".network").trigger("change");
919 // check the address is generated correctly
920 waitForGenerate(function() {
921 var actual
= page
.evaluate(function() {
922 return $(".address:first").text();
924 if (actual
!= expected
) {
925 console
.log("Myriadcoin address is incorrect");
926 console
.log("Expected: " + expected
);
927 console
.log("Actual: " + actual
);
935 // Network can be set to pivx
937 page
.open(url
, function(status
) {
938 // set the phrase and coin
939 var expected
= "DBxgT7faCuno7jmtKuu6KWCiwqsVPqh1tS";
940 page
.evaluate(function() {
941 $(".phrase").val("abandon abandon ability");
942 $(".phrase").trigger("input");
943 $(".network option[selected]").removeAttr("selected");
944 $(".network option").filter(function() {
945 return $(this).html() == "PIVX - PIVX";
946 }).prop("selected", true);
947 $(".network").trigger("change");
949 // check the address is generated correctly
950 waitForGenerate(function() {
951 var actual
= page
.evaluate(function() {
952 return $(".address:first").text();
954 if (actual
!= expected
) {
955 console
.log("PIVX address is incorrect");
956 console
.log("Expected: " + expected
);
957 console
.log("Actual: " + actual
);
965 // Network can be set to pivx testnet
967 page
.open(url
, function(status
) {
968 // set the phrase and coin
969 var expected
= "yB5U384n6dGkVE3by5y9VdvHHPwPg68fQj";
970 page
.evaluate(function() {
971 $(".phrase").val("abandon abandon ability");
972 $(".phrase").trigger("input");
973 $(".network option[selected]").removeAttr("selected");
974 $(".network option").filter(function() {
975 return $(this).html() == "PIVX - PIVX Testnet";
976 }).prop("selected", true);
977 $(".network").trigger("change");
979 // check the address is generated correctly
980 waitForGenerate(function() {
981 var actual
= page
.evaluate(function() {
982 return $(".address:first").text();
984 if (actual
!= expected
) {
985 console
.log("PIVX Testnet address is incorrect");
986 console
.log("Expected: " + expected
);
987 console
.log("Actual: " + actual
);
995 // Network can be set to maza
997 page
.open(url
, function(status
) {
998 // set the phrase and coin
999 var expected
= "MGW4Bmi2NEm4PxSjgeFwhP9vg18JHoRnfw";
1000 page
.evaluate(function() {
1001 $(".phrase").val("abandon abandon ability");
1002 $(".phrase").trigger("input");
1003 $(".network option[selected]").removeAttr("selected");
1004 $(".network option").filter(function() {
1005 return $(this).html() == "MAZA - Maza";
1006 }).prop("selected", true);
1007 $(".network").trigger("change");
1009 // check the address is generated correctly
1010 waitForGenerate(function() {
1011 var actual
= page
.evaluate(function() {
1012 return $(".address:first").text();
1014 if (actual
!= expected
) {
1015 console
.log("Maza address is incorrect");
1016 console
.log("Expected: " + expected
);
1017 console
.log("Actual: " + actual
);
1025 // BIP39 seed is set from phrase
1027 page
.open(url
, function(status
) {
1029 var expected
= "20da140d3dd1df8713cefcc4d54ce0e445b4151027a1ab567b832f6da5fcc5afc1c3a3f199ab78b8e0ab4652efd7f414ac2c9a3b81bceb879a70f377aa0a58f3";
1030 page
.evaluate(function() {
1031 $(".phrase").val("abandon abandon ability");
1032 $(".phrase").trigger("input");
1034 // check the address is generated correctly
1035 waitForGenerate(function() {
1036 var actual
= page
.evaluate(function() {
1037 return $(".seed").val();
1039 if (actual
!= expected
) {
1040 console
.log("BIP39 seed is incorrectly generated from mnemonic");
1041 console
.log("Expected: " + expected
);
1042 console
.log("Actual: " + actual
);
1050 // BIP32 root key is set from phrase
1052 page
.open(url
, function(status
) {
1054 var expected
= "xprv9s21ZrQH143K2jkGDCeTLgRewT9F2pH5JZs2zDmmjXes34geVnFiuNa8KTvY5WoYvdn4Ag6oYRoB6cXtc43NgJAEqDXf51xPm6fhiMCKwpi";
1055 page
.evaluate(function() {
1056 $(".phrase").val("abandon abandon ability");
1057 $(".phrase").trigger("input");
1059 // check the address is generated correctly
1060 waitForGenerate(function() {
1061 var actual
= page
.evaluate(function() {
1062 return $(".root-key").val();
1064 if (actual
!= expected
) {
1065 console
.log("Root key is incorrectly generated from mnemonic");
1066 console
.log("Expected: " + expected
);
1067 console
.log("Actual: " + actual
);
1075 // Tabs show correct addresses when changed
1077 page
.open(url
, function(status
) {
1079 var expected
= "17uQ7s2izWPwBmEVFikTmZUjbBKWYdJchz";
1080 page
.evaluate(function() {
1081 $(".phrase").val("abandon abandon ability");
1082 $(".phrase").trigger("input");
1085 waitForGenerate(function() {
1086 page
.evaluate(function() {
1087 $("#bip32-tab a").click();
1089 // check the address is generated correctly
1090 waitForGenerate(function() {
1091 var actual
= page
.evaluate(function() {
1092 return $(".address:first").text();
1094 if (actual
!= expected
) {
1095 console
.log("Clicking tab generates incorrect address");
1096 console
.log("Expected: " + expected
);
1097 console
.log("Actual: " + actual
);
1106 // BIP44 derivation path is shown
1108 page
.open(url
, function(status
) {
1110 var expected
= "m/44'/0'/0'/0";
1111 page
.evaluate(function() {
1112 $(".phrase").val("abandon abandon ability");
1113 $(".phrase").trigger("input");
1115 // check the derivation path of the first address
1116 waitForGenerate(function() {
1117 var actual
= page
.evaluate(function() {
1118 return $("#bip44 .path").val();
1120 if (actual
!= expected
) {
1121 console
.log("BIP44 derivation path is incorrect");
1122 console
.log("Expected: " + expected
);
1123 console
.log("Actual: " + actual
);
1131 // BIP44 extended private key is shown
1133 page
.open(url
, function(status
) {
1135 var expected
= "xprvA2DxxvPZcyRvYgZMGS53nadR32mVDeCyqQYyFhrCVbJNjPoxMeVf7QT5g7mQASbTf9Kp4cryvcXnu2qurjWKcrdsr91jXymdCDNxKgLFKJG";
1136 page
.evaluate(function() {
1137 $(".phrase").val("abandon abandon ability");
1138 $(".phrase").trigger("input");
1140 // check the BIP44 extended private key
1141 waitForGenerate(function() {
1142 var actual
= page
.evaluate(function() {
1143 return $(".extended-priv-key").val();
1145 if (actual
!= expected
) {
1146 console
.log("BIP44 extended private key is incorrect");
1147 console
.log("Expected: " + expected
);
1148 console
.log("Actual: " + actual
);
1156 // BIP44 extended public key is shown
1158 page
.open(url
, function(status
) {
1160 var expected
= "xpub6FDKNRvTTLzDmAdpNTc49ia9b4byd6vqCdUa46Fp3vqMcC96uBoufCmZXQLiN5AK3iSCJMhf9gT2sxkpyaPepRuA7W3MujV5tGmF5VfbueM";
1161 page
.evaluate(function() {
1162 $(".phrase").val("abandon abandon ability");
1163 $(".phrase").trigger("input");
1165 // check the BIP44 extended public key
1166 waitForGenerate(function() {
1167 var actual
= page
.evaluate(function() {
1168 return $(".extended-pub-key").val();
1170 if (actual
!= expected
) {
1171 console
.log("BIP44 extended public key is incorrect");
1172 console
.log("Expected: " + expected
);
1173 console
.log("Actual: " + actual
);
1181 // BIP44 account field changes address list
1183 page
.open(url
, function(status
) {
1185 var expected
= "1Nq2Wmu726XHCuGhctEtGmhxo3wzk5wZ1H";
1186 page
.evaluate(function() {
1187 $(".phrase").val("abandon abandon ability");
1188 $(".phrase").trigger("input");
1190 waitForGenerate(function() {
1191 // change the bip44 purpose field to 45
1192 page
.evaluate(function() {
1193 $("#bip44 .account").val("1");
1194 $("#bip44 .account").trigger("input");
1196 waitForGenerate(function() {
1197 // check the address for the new derivation path
1198 var actual
= page
.evaluate(function() {
1199 return $(".address:first").text();
1201 if (actual
!= expected
) {
1202 console
.log("BIP44 account field generates incorrect address");
1203 console
.log("Expected: " + expected
);
1204 console
.log("Actual: " + actual
);
1213 // BIP44 change field changes address list
1215 page
.open(url
, function(status
) {
1217 var expected
= "1KAGfWgqfVbSSXY56fNQ7YnhyKuoskHtYo";
1218 page
.evaluate(function() {
1219 $(".phrase").val("abandon abandon ability");
1220 $(".phrase").trigger("input");
1222 waitForGenerate(function() {
1223 // change the bip44 purpose field to 45
1224 page
.evaluate(function() {
1225 $("#bip44 .change").val("1");
1226 $("#bip44 .change").trigger("input");
1228 waitForGenerate(function() {
1229 // check the address for the new derivation path
1230 var actual
= page
.evaluate(function() {
1231 return $(".address:first").text();
1233 if (actual
!= expected
) {
1234 console
.log("BIP44 change field generates incorrect address");
1235 console
.log("Expected: " + expected
);
1236 console
.log("Actual: " + actual
);
1245 // BIP32 derivation path can be set
1247 page
.open(url
, function(status
) {
1249 var expected
= "16pYQQdLD1hH4hwTGLXBaZ9Teboi1AGL8L";
1250 page
.evaluate(function() {
1251 $(".phrase").val("abandon abandon ability");
1252 $(".phrase").trigger("input");
1255 waitForGenerate(function() {
1256 page
.evaluate(function() {
1257 $("#bip32-tab a").click();
1259 // set the derivation path to m/1
1260 waitForGenerate(function() {
1261 page
.evaluate(function() {
1262 $("#bip32 .path").val("m/1");
1263 $("#bip32 .path").trigger("input");
1265 // check the address is generated correctly
1266 waitForGenerate(function() {
1267 var actual
= page
.evaluate(function() {
1268 return $(".address:first").text();
1270 if (actual
!= expected
) {
1271 console
.log("Custom BIP32 path generates incorrect address");
1272 console
.log("Expected: " + expected
);
1273 console
.log("Actual: " + actual
);
1283 // BIP32 can use hardened derivation paths
1285 page
.open(url
, function(status
) {
1287 var expected
= "14aXZeprXAE3UUKQc4ihvwBvww2LuEoHo4";
1288 page
.evaluate(function() {
1289 $(".phrase").val("abandon abandon ability");
1290 $(".phrase").trigger("input");
1293 waitForGenerate(function() {
1294 page
.evaluate(function() {
1295 $("#bip32-tab a").click();
1297 // set the derivation path to m/0'
1298 waitForGenerate(function() {
1299 page
.evaluate(function() {
1300 $("#bip32 .path").val("m/0'");
1301 $("#bip32 .path").trigger("input");
1303 // check the address is generated correctly
1304 waitForGenerate(function() {
1305 var actual
= page
.evaluate(function() {
1306 return $(".address:first").text();
1308 if (actual
!= expected
) {
1309 console
.log("Hardened BIP32 path generates incorrect address");
1310 console
.log("Expected: " + expected
);
1311 console
.log("Actual: " + actual
);
1321 // BIP32 extended private key is shown
1323 page
.open(url
, function(status
) {
1325 var expected
= "xprv9va99uTVE5aLiutUVLTyfxfe8v8aaXjSQ1XxZbK6SezYVuikA9MnjQVTA8rQHpNA5LKvyQBpLiHbBQiiccKiBDs7eRmBogsvq3THFeLHYbe";
1326 page
.evaluate(function() {
1327 $(".phrase").val("abandon abandon ability");
1328 $(".phrase").trigger("input");
1331 waitForGenerate(function() {
1332 page
.evaluate(function() {
1333 $("#bip32-tab a").click();
1335 // check the extended private key is generated correctly
1336 waitForGenerate(function() {
1337 var actual
= page
.evaluate(function() {
1338 return $(".extended-priv-key").val();
1340 if (actual
!= expected
) {
1341 console
.log("BIP32 extended private key is incorrect");
1342 console
.log("Expected: " + expected
);
1343 console
.log("Actual: " + actual
);
1352 // BIP32 extended public key is shown
1354 page
.open(url
, function(status
) {
1356 var expected
= "xpub69ZVZQzP4T8dwPxwbMzz36cNgwy4yzTHmETZMyihzzXXNi3thgg3HCow1RtY252wdw5rS8369xKnraN5Q93y3FkFfJp2XEHWUrkyXsjS93P";
1357 page
.evaluate(function() {
1358 $(".phrase").val("abandon abandon ability");
1359 $(".phrase").trigger("input");
1362 waitForGenerate(function() {
1363 page
.evaluate(function() {
1364 $("#bip32-tab a").click();
1366 // check the extended public key is generated correctly
1367 waitForGenerate(function() {
1368 var actual
= page
.evaluate(function() {
1369 return $(".extended-pub-key").val();
1371 if (actual
!= expected
) {
1372 console
.log("BIP32 extended public key is incorrect");
1373 console
.log("Expected: " + expected
);
1374 console
.log("Actual: " + actual
);
1383 // Derivation path is shown in table
1385 page
.open(url
, function(status
) {
1387 var expected
= "m/44'/0'/0'/0/0";
1388 page
.evaluate(function() {
1389 $(".phrase").val("abandon abandon ability");
1390 $(".phrase").trigger("input");
1392 // check for derivation path in table
1393 waitForGenerate(function() {
1394 var actual
= page
.evaluate(function() {
1395 return $(".index:first").text();
1397 if (actual
!= expected
) {
1398 console
.log("Derivation path shown incorrectly in table");
1399 console
.log("Expected: " + expected
);
1400 console
.log("Actual: " + actual
);
1408 // Derivation path for address can be hardened
1410 page
.open(url
, function(status
) {
1412 var expected
= "18exLzUv7kfpiXRzmCjFDoC9qwNLFyvwyd";
1413 page
.evaluate(function() {
1414 $(".phrase").val("abandon abandon ability");
1415 $(".phrase").trigger("input");
1418 waitForGenerate(function() {
1419 page
.evaluate(function() {
1420 $("#bip32-tab a").click();
1422 waitForGenerate(function() {
1423 // select the hardened addresses option
1424 page
.evaluate(function() {
1425 $(".hardened-addresses").prop("checked", true);
1426 $(".hardened-addresses").trigger("change");
1428 waitForGenerate(function() {
1429 // check the generated address is hardened
1430 var actual
= page
.evaluate(function() {
1431 return $(".address:first").text();
1433 if (actual
!= expected
) {
1434 console
.log("Hardened address is incorrect");
1435 console
.log("Expected: " + expected
);
1436 console
.log("Actual: " + actual
);
1446 // Derivation path visibility can be toggled
1448 page
.open(url
, function(status
) {
1450 page
.evaluate(function() {
1451 $(".phrase").val("abandon abandon ability");
1452 $(".phrase").trigger("input");
1454 waitForGenerate(function() {
1455 // toggle path visibility
1456 page
.evaluate(function() {
1457 $(".index-toggle").click();
1459 // check the path is not visible
1460 var isInvisible
= page
.evaluate(function() {
1461 return $(".index:first span").hasClass("invisible");
1464 console
.log("Toggled derivation path is visible");
1474 page
.open(url
, function(status
) {
1475 var expected
= "1Di3Vp7tBWtyQaDABLAjfWtF6V7hYKJtug";
1477 page
.evaluate(function() {
1478 $(".phrase").val("abandon abandon ability").trigger("input");
1481 waitForGenerate(function() {
1482 var actual
= page
.evaluate(function() {
1483 return $(".address:first").text();
1485 if (actual
!= expected
) {
1486 console
.log("Address is not shown");
1487 console
.log("Expected: " + expected
);
1488 console
.log("Got: " + actual
);
1496 // Addresses are shown in order of derivation path
1498 page
.open(url
, function(status
) {
1500 page
.evaluate(function() {
1501 $(".phrase").val("abandon abandon ability").trigger("input");
1503 // get the derivation paths
1504 waitForGenerate(function() {
1505 var paths
= page
.evaluate(function() {
1506 return $(".index").map(function(i
, e
) {
1510 if (paths
.length
!= 20) {
1511 console
.log("Total paths is less than expected: " + paths
.length
);
1514 for (var i
=0; i
<paths
.length
; i
++) {
1515 var expected
= "m/44'/0'/0'/0/" + i
;
1516 var actual
= paths
[i
];
1517 if (actual
!= expected
) {
1518 console
.log("Path " + i
+ " is incorrect");
1519 console
.log("Expected: " + expected
);
1520 console
.log("Actual: " + actual
);
1529 // Address visibility can be toggled
1531 page
.open(url
, function(status
) {
1533 page
.evaluate(function() {
1534 $(".phrase").val("abandon abandon ability");
1535 $(".phrase").trigger("input");
1537 waitForGenerate(function() {
1538 // toggle address visibility
1539 page
.evaluate(function() {
1540 $(".address-toggle").click();
1542 // check the address is not visible
1543 var isInvisible
= page
.evaluate(function() {
1544 return $(".address:first span").hasClass("invisible");
1547 console
.log("Toggled address is visible");
1555 // Public key is shown
1557 page
.open(url
, function(status
) {
1558 var expected
= "033f5aed5f6cfbafaf223188095b5980814897295f723815fea5d3f4b648d0d0b3";
1560 page
.evaluate(function() {
1561 $(".phrase").val("abandon abandon ability").trigger("input");
1564 waitForGenerate(function() {
1565 var actual
= page
.evaluate(function() {
1566 return $(".pubkey:first").text();
1568 if (actual
!= expected
) {
1569 console
.log("Public key is not shown");
1570 console
.log("Expected: " + expected
);
1571 console
.log("Got: " + actual
);
1579 // Public key visibility can be toggled
1581 page
.open(url
, function(status
) {
1583 page
.evaluate(function() {
1584 $(".phrase").val("abandon abandon ability");
1585 $(".phrase").trigger("input");
1587 waitForGenerate(function() {
1588 // toggle public key visibility
1589 page
.evaluate(function() {
1590 $(".public-key-toggle").click();
1592 // check the public key is not visible
1593 var isInvisible
= page
.evaluate(function() {
1594 return $(".pubkey:first span").hasClass("invisible");
1597 console
.log("Toggled public key is visible");
1605 // Private key is shown
1607 page
.open(url
, function(status
) {
1608 var expected
= "L26cVSpWFkJ6aQkPkKmTzLqTdLJ923e6CzrVh9cmx21QHsoUmrEE";
1610 page
.evaluate(function() {
1611 $(".phrase").val("abandon abandon ability").trigger("input");
1614 waitForGenerate(function() {
1615 var actual
= page
.evaluate(function() {
1616 return $(".privkey:first").text();
1618 if (actual
!= expected
) {
1619 console
.log("Private key is not shown");
1620 console
.log("Expected: " + expected
);
1621 console
.log("Got: " + actual
);
1629 // Private key visibility can be toggled
1631 page
.open(url
, function(status
) {
1633 page
.evaluate(function() {
1634 $(".phrase").val("abandon abandon ability");
1635 $(".phrase").trigger("input");
1637 waitForGenerate(function() {
1638 // toggle private key visibility
1639 page
.evaluate(function() {
1640 $(".private-key-toggle").click();
1642 // check the private key is not visible
1643 var isInvisible
= page
.evaluate(function() {
1644 return $(".privkey:first span").hasClass("invisible");
1647 console
.log("Toggled private key is visible");
1655 // More addresses can be generated
1657 page
.open(url
, function(status
) {
1659 page
.evaluate(function() {
1660 $(".phrase").val("abandon abandon ability");
1661 $(".phrase").trigger("input");
1663 waitForGenerate(function() {
1664 // generate more addresses
1665 page
.evaluate(function() {
1668 waitForGenerate(function() {
1669 // check there are more addresses
1670 var addressCount
= page
.evaluate(function() {
1671 return $(".address").length
;
1673 if (addressCount
!= 40) {
1674 console
.log("More addresses cannot be generated");
1683 // A custom number of additional addresses can be generated
1685 page
.open(url
, function(status
) {
1687 page
.evaluate(function() {
1688 $(".phrase").val("abandon abandon ability");
1689 $(".phrase").trigger("input");
1691 waitForGenerate(function() {
1692 // get the current number of addresses
1693 var oldAddressCount
= page
.evaluate(function() {
1694 return $(".address").length
;
1696 // set a custom number of additional addresses
1697 page
.evaluate(function() {
1698 $(".rows-to-add").val(1);
1700 // generate more addresses
1701 page
.evaluate(function() {
1704 waitForGenerate(function() {
1705 // check there are the correct number of addresses
1706 var newAddressCount
= page
.evaluate(function() {
1707 return $(".address").length
;
1709 if (newAddressCount
- oldAddressCount
!= 1) {
1710 console
.log("Number of additional addresses cannot be customized");
1711 console
.log(newAddressCount
)
1712 console
.log(oldAddressCount
)
1721 // Additional addresses are shown in order of derivation path
1723 page
.open(url
, function(status
) {
1725 page
.evaluate(function() {
1726 $(".phrase").val("abandon abandon ability").trigger("input");
1728 waitForGenerate(function() {
1729 // generate more addresses
1730 page
.evaluate(function() {
1733 // get the derivation paths
1734 waitForGenerate(function() {
1735 var paths
= page
.evaluate(function() {
1736 return $(".index").map(function(i
, e
) {
1740 if (paths
.length
!= 40) {
1741 console
.log("Total additional paths is less than expected: " + paths
.length
);
1744 for (var i
=0; i
<paths
.length
; i
++) {
1745 var expected
= "m/44'/0'/0'/0/" + i
;
1746 var actual
= paths
[i
];
1747 if (actual
!= expected
) {
1748 console
.log("Path " + i
+ " is not in correct order");
1749 console
.log("Expected: " + expected
);
1750 console
.log("Actual: " + actual
);
1760 // BIP32 root key can be set by the user
1762 page
.open(url
, function(status
) {
1763 var expected
= "1Di3Vp7tBWtyQaDABLAjfWtF6V7hYKJtug";
1765 page
.evaluate(function() {
1766 $(".root-key").val("xprv9s21ZrQH143K2jkGDCeTLgRewT9F2pH5JZs2zDmmjXes34geVnFiuNa8KTvY5WoYvdn4Ag6oYRoB6cXtc43NgJAEqDXf51xPm6fhiMCKwpi").trigger("input");
1768 waitForGenerate(function() {
1769 var actual
= page
.evaluate(function() {
1770 return $(".address:first").text();
1772 if (actual
!= expected
) {
1773 console
.log("Setting BIP32 root key results in wrong address");
1774 console
.log("Expected: " + expected
);
1775 console
.log("Actual: " + actual
);
1783 // Setting BIP32 root key clears the existing phrase, passphrase and seed
1785 page
.open(url
, function(status
) {
1788 page
.evaluate(function() {
1789 $(".phrase").val("A non-blank but invalid value");
1791 // Accept any confirm dialogs
1792 page
.onConfirm = function() {
1796 page
.evaluate(function() {
1797 $(".root-key").val("xprv9s21ZrQH143K2jkGDCeTLgRewT9F2pH5JZs2zDmmjXes34geVnFiuNa8KTvY5WoYvdn4Ag6oYRoB6cXtc43NgJAEqDXf51xPm6fhiMCKwpi").trigger("input");
1799 waitForGenerate(function() {
1800 var actual
= page
.evaluate(function() {
1801 return $(".phrase").val();
1803 if (actual
!= expected
) {
1804 console
.log("Phrase not cleared when setting BIP32 root key");
1805 console
.log("Expected: " + expected
);
1806 console
.log("Actual: " + actual
);
1814 // Clearing of phrase, passphrase and seed can be cancelled by user
1816 page
.open(url
, function(status
) {
1817 var expected
= "abandon abandon ability";
1819 page
.evaluate(function() {
1820 $(".phrase").val("abandon abandon ability");
1822 // Cancel any confirm dialogs
1823 page
.onConfirm = function() {
1827 page
.evaluate(function() {
1828 $(".root-key").val("xprv9s21ZrQH143K3d3vzEDD3KpSKmxsZ3y7CqhAL1tinwtP6wqK4TKEKjpBuo6P2hUhB6ZENo7TTSRytiP857hBZVpBdk8PooFuRspE1eywwNZ").trigger("input");
1830 var actual
= page
.evaluate(function() {
1831 return $(".phrase").val();
1833 if (actual
!= expected
) {
1834 console
.log("Phrase not retained when cancelling changes to BIP32 root key");
1835 console
.log("Expected: " + expected
);
1836 console
.log("Actual: " + actual
);
1843 // Custom BIP32 root key is used when changing the derivation path
1845 page
.open(url
, function(status
) {
1846 var expected
= "1Nq2Wmu726XHCuGhctEtGmhxo3wzk5wZ1H";
1848 page
.evaluate(function() {
1849 $(".root-key").val("xprv9s21ZrQH143K2jkGDCeTLgRewT9F2pH5JZs2zDmmjXes34geVnFiuNa8KTvY5WoYvdn4Ag6oYRoB6cXtc43NgJAEqDXf51xPm6fhiMCKwpi").trigger("input");
1851 waitForGenerate(function() {
1852 // change the derivation path
1853 page
.evaluate(function() {
1854 $("#account").val("1").trigger("input");
1856 // check the bip32 root key is used for derivation, not the blank phrase
1857 waitForGenerate(function() {
1858 var actual
= page
.evaluate(function() {
1859 return $(".address:first").text();
1861 if (actual
!= expected
) {
1862 console
.log("Changing the derivation path does not use BIP32 root key");
1863 console
.log("Expected: " + expected
);
1864 console
.log("Actual: " + actual
);
1873 // Incorrect mnemonic shows error
1875 page
.open(url
, function(status
) {
1877 page
.evaluate(function() {
1878 $(".phrase").val("abandon abandon abandon").trigger("input");
1880 waitForFeedback(function() {
1881 // check there is an error shown
1882 var feedback
= page
.evaluate(function() {
1883 return $(".feedback").text();
1885 if (feedback
.length
<= 0) {
1886 console
.log("Invalid mnemonic does not show error");
1894 // Incorrect word shows suggested replacement
1896 page
.open(url
, function(status
) {
1898 page
.evaluate(function() {
1899 $(".phrase").val("abandon abandon abiliti").trigger("input");
1901 // check there is a suggestion shown
1902 waitForFeedback(function() {
1903 var feedback
= page
.evaluate(function() {
1904 return $(".feedback").text();
1906 if (feedback
.indexOf("did you mean ability?") < 0) {
1907 console
.log("Incorrect word does not show suggested replacement");
1908 console
.log("Error: " + error
);
1916 // Github pull request 48
1917 // First four letters of word shows that word, not closest
1918 // since first four letters gives unique word in BIP39 wordlist
1919 // eg ille should show illegal, not idle
1921 page
.open(url
, function(status
) {
1922 // set the incomplete word
1923 page
.evaluate(function() {
1924 $(".phrase").val("ille").trigger("input");
1926 // check there is a suggestion shown
1927 waitForFeedback(function() {
1928 var feedback
= page
.evaluate(function() {
1929 return $(".feedback").text();
1931 if (feedback
.indexOf("did you mean illegal?") < 0) {
1932 console
.log("Start of word does not show correct suggestion");
1933 console
.log("Error: " + error
);
1941 // Incorrect BIP32 root key shows error
1943 page
.open(url
, function(status
) {
1945 page
.evaluate(function() {
1946 $(".root-key").val("xprv9s21ZrQH143K2jkGDCeTLgRewT9F2pH5JZs2zDmmjXes34geVnFiuNa8KTvY5WoYvdn4Ag6oYRoB6cXtc43NgJAEqDXf51xPm6fhiMCKwpj").trigger("input");
1948 // check there is an error shown
1949 waitForFeedback(function() {
1950 var feedback
= page
.evaluate(function() {
1951 return $(".feedback").text();
1953 if (feedback
!= "Invalid root key") {
1954 console
.log("Invalid root key does not show error");
1955 console
.log("Error: " + error
);
1963 // Derivation path not starting with m shows error
1965 page
.open(url
, function(status
) {
1966 // set the mnemonic phrase
1967 page
.evaluate(function() {
1968 $(".phrase").val("abandon abandon ability").trigger("input");
1970 waitForGenerate(function() {
1971 // select the bip32 tab so custom derivation path can be set
1972 page
.evaluate(function() {
1973 $("#bip32-tab a").click();
1975 waitForGenerate(function() {
1976 // set the incorrect derivation path
1977 page
.evaluate(function() {
1978 $("#bip32 .path").val("n/0").trigger("input");
1980 waitForFeedback(function() {
1981 var feedback
= page
.evaluate(function() {
1982 return $(".feedback").text();
1984 if (feedback
!= "First character must be 'm'") {
1985 console
.log("Derivation path not starting with m should show error");
1986 console
.log("Error: " + error
);
1996 // Derivation path containing invalid characters shows useful error
1998 page
.open(url
, function(status
) {
1999 // set the mnemonic phrase
2000 page
.evaluate(function() {
2001 $(".phrase").val("abandon abandon ability").trigger("input");
2003 waitForGenerate(function() {
2004 // select the bip32 tab so custom derivation path can be set
2005 page
.evaluate(function() {
2006 $("#bip32-tab a").click();
2008 waitForGenerate(function() {
2009 // set the incorrect derivation path
2010 page
.evaluate(function() {
2011 $("#bip32 .path").val("m/1/0wrong1/1").trigger("input");
2013 waitForFeedback(function() {
2014 var feedback
= page
.evaluate(function() {
2015 return $(".feedback").text();
2017 if (feedback
!= "Invalid characters 0wrong1 found at depth 2") {
2018 console
.log("Derivation path with invalid characters should show error");
2019 console
.log("Error: " + error
);
2029 // Github Issue 11: Default word length is 15
2030 // https://github.com/iancoleman/bip39/issues/11
2032 page
.open(url
, function(status
) {
2033 // get the word length
2034 var defaultLength
= page
.evaluate(function() {
2035 return $(".strength").val();
2037 if (defaultLength
!= 15) {
2038 console
.log("Default word length is not 15");
2046 // Github Issue 12: Generate more rows with private keys hidden
2047 // https://github.com/iancoleman/bip39/issues/12
2049 page
.open(url
, function(status
) {
2051 page
.evaluate(function() {
2052 $(".phrase").val("abandon abandon ability");
2053 $(".phrase").trigger("input");
2055 waitForGenerate(function() {
2056 // toggle private keys hidden, then generate more addresses
2057 page
.evaluate(function() {
2058 $(".private-key-toggle").click();
2061 waitForGenerate(function() {
2062 // check more have been generated
2064 var numPrivKeys
= page
.evaluate(function() {
2065 return $(".privkey").length
;
2067 if (numPrivKeys
!= expected
) {
2068 console
.log("Wrong number of addresses when clicking 'more' with hidden privkeys");
2069 console
.log("Expected: " + expected
);
2070 console
.log("Actual: " + numPrivKeys
);
2073 // check no private keys are shown
2074 var numHiddenPrivKeys
= page
.evaluate(function() {
2075 return $(".privkey span[class=invisible]").length
;
2077 if (numHiddenPrivKeys
!= expected
) {
2078 console
.log("Generating more does not retain hidden state of privkeys");
2079 console
.log("Expected: " + expected
);
2080 console
.log("Actual: " + numHiddenPrivKeys
);
2089 // Github Issue 19: Mnemonic is not sensitive to whitespace
2090 // https://github.com/iancoleman/bip39/issues/19
2092 page
.open(url
, function(status
) {
2094 var expected
= "xprv9s21ZrQH143K3isaZsWbKVoTtbvd34Y1ZGRugGdMeBGbM3AgBVzTH159mj1cbbtYSJtQr65w6L5xy5L9SFC7c9VJZWHxgAzpj4mun5LhrbC";
2095 page
.evaluate(function() {
2096 var doubleSpace
= " ";
2097 $(".phrase").val("urge cat" + doubleSpace
+ "bid");
2098 $(".phrase").trigger("input");
2100 waitForGenerate(function() {
2101 // Check the bip32 root key is correct
2102 var actual
= page
.evaluate(function() {
2103 return $(".root-key").val();
2105 if (actual
!= expected
) {
2106 console
.log("Mnemonic is sensitive to whitespace");
2107 console
.log("Expected: " + expected
);
2108 console
.log("Actual: " + actual
);
2116 // Github Issue 23: Part 1: Use correct derivation path when changing tabs
2117 // https://github.com/iancoleman/bip39/issues/23
2119 page
.open(url
, function(status
) {
2120 // 1) and 2) set the phrase
2121 page
.evaluate(function() {
2122 $(".phrase").val("abandon abandon ability").trigger("input");
2124 waitForGenerate(function() {
2125 // 3) select bip32 tab
2126 page
.evaluate(function() {
2127 $("#bip32-tab a").click();
2129 waitForGenerate(function() {
2130 // 4) switch from bitcoin to litecoin
2131 page
.evaluate(function() {
2132 $(".network option").filter(function() {
2133 return $(this).html() == "LTC - Litecoin";
2134 }).prop("selected", true);
2135 $(".network").trigger("change");
2137 waitForGenerate(function() {
2138 // 5) Check derivation path is displayed correctly
2139 var expected
= "m/0/0";
2140 var actual
= page
.evaluate(function() {
2141 return $(".index:first").text();
2143 if (actual
!= expected
) {
2144 console
.log("Github Issue 23 Part 1: derivation path display error");
2145 console
.log("Expected: " + expected
);
2146 console
.log("Actual: " + actual
);
2149 // 5) Check address is displayed correctly
2150 var expected
= "LS8MP5LZ5AdzSZveRrjm3aYVoPgnfFh5T5";
2151 var actual
= page
.evaluate(function() {
2152 return $(".address:first").text();
2154 if (actual
!= expected
) {
2155 console
.log("Github Issue 23 Part 1: address display error");
2156 console
.log("Expected: " + expected
);
2157 console
.log("Actual: " + actual
);
2167 // Github Issue 23 Part 2: Coin selection in derivation path
2168 // https://github.com/iancoleman/bip39/issues/23#issuecomment-238011920
2170 page
.open(url
, function(status
) {
2172 page
.evaluate(function() {
2173 $(".phrase").val("abandon abandon ability").trigger("input");
2175 waitForGenerate(function() {
2176 // switch from bitcoin to clam
2177 page
.evaluate(function() {
2178 $(".network option").filter(function() {
2179 return $(this).html() == "CLAM - Clams";
2180 }).prop("selected", true);
2181 $(".network").trigger("change");
2183 waitForGenerate(function() {
2184 // check derivation path is displayed correctly
2185 var expected
= "m/44'/23'/0'/0/0";
2186 var actual
= page
.evaluate(function() {
2187 return $(".index:first").text();
2189 if (actual
!= expected
) {
2190 console
.log("Github Issue 23 Part 2: Coin in BIP44 derivation path is incorrect");
2191 console
.log("Expected: " + expected
);
2192 console
.log("Actual: " + actual
);
2201 // Github Issue 26: When using a Root key derrived altcoins are incorrect
2202 // https://github.com/iancoleman/bip39/issues/26
2204 page
.open(url
, function(status
) {
2205 // 1) 2) and 3) set the root key
2206 page
.evaluate(function() {
2207 $(".root-key").val("xprv9s21ZrQH143K2jkGDCeTLgRewT9F2pH5JZs2zDmmjXes34geVnFiuNa8KTvY5WoYvdn4Ag6oYRoB6cXtc43NgJAEqDXf51xPm6fhiMCKwpi").trigger("input");
2209 waitForGenerate(function() {
2210 // 4) switch from bitcoin to viacoin
2211 page
.evaluate(function() {
2212 $(".network option").filter(function() {
2213 return $(this).html() == "VIA - Viacoin";
2214 }).prop("selected", true);
2215 $(".network").trigger("change");
2217 waitForGenerate(function() {
2218 // 5) ensure the derived address is correct
2219 var expected
= "Vq9Eq4N5SQnjqZvxtxzo7hZPW5XnyJsmXT";
2220 var actual
= page
.evaluate(function() {
2221 return $(".address:first").text();
2223 if (actual
!= expected
) {
2224 console
.log("Github Issue 26: address is incorrect when changing networks and using root-key to derive");
2225 console
.log("Expected: " + expected
);
2226 console
.log("Actual: " + actual
);
2235 // Selecting a language with no existing phrase should generate a phrase in
2238 page
.open(url
, function(status
) {
2239 // Select a language
2240 // Need to manually simulate hash being set due to quirk between
2241 // 'click' event triggered by javascript vs triggered by mouse.
2242 // Perhaps look into page.sendEvent
2243 // http://phantomjs.org/api/webpage/method/send-event.html
2244 page
.evaluate(function() {
2245 window
.location
.hash
= "#japanese";
2246 $("a[href='#japanese']").trigger("click");
2248 waitForGenerate(function() {
2249 // Check the mnemonic is in Japanese
2250 var phrase
= page
.evaluate(function() {
2251 return $(".phrase").val();
2253 if (phrase
.length
<= 0) {
2254 console
.log("No Japanese phrase generated");
2257 if (phrase
.charCodeAt(0) < 128) {
2258 console
.log("First character of Japanese phrase is ascii");
2259 console
.log("Phrase: " + phrase
);
2267 // Selecting a language with existing phrase should update the phrase to use
2270 page
.open(url
, function(status
) {
2271 // Set the phrase to an English phrase.
2272 page
.evaluate(function() {
2273 $(".phrase").val("abandon abandon ability").trigger("input");
2275 waitForGenerate(function() {
2276 // Change to Italian
2277 // Need to manually simulate hash being set due to quirk between
2278 // 'click' event triggered by javascript vs triggered by mouse.
2279 // Perhaps look into page.sendEvent
2280 // http://phantomjs.org/api/webpage/method/send-event.html
2281 page
.evaluate(function() {
2282 window
.location
.hash
= "#italian";
2283 $("a[href='#italian']").trigger("click");
2285 waitForGenerate(function() {
2286 // Check only the language changes, not the phrase
2287 var expected
= "abaco abaco abbaglio";
2288 var actual
= page
.evaluate(function() {
2289 return $(".phrase").val();
2291 if (actual
!= expected
) {
2292 console
.log("Changing language with existing phrase");
2293 console
.log("Expected: " + expected
);
2294 console
.log("Actual: " + actual
);
2297 // Check the address is correct
2298 var expected
= "1Dz5TgDhdki9spa6xbPFbBqv5sjMrx3xgV";
2299 var actual
= page
.evaluate(function() {
2300 return $(".address:first").text();
2302 if (actual
!= expected
) {
2303 console
.log("Changing language generates incorrect address");
2304 console
.log("Expected: " + expected
);
2305 console
.log("Actual: " + actual
);
2314 // Suggested replacement for erroneous word in non-English language
2316 page
.open(url
, function(status
) {
2317 // Set an incorrect phrase in Italian
2318 page
.evaluate(function() {
2319 $(".phrase").val("abaco abaco zbbaglio").trigger("input");
2321 waitForFeedback(function() {
2322 // Check the suggestion is correct
2323 var feedback
= page
.evaluate(function() {
2324 return $(".feedback").text();
2326 if (feedback
.indexOf("did you mean abbaglio?") < 0) {
2327 console
.log("Incorrect Italian word does not show suggested replacement");
2328 console
.log("Error: " + error
);
2337 // Japanese word does not break across lines.
2339 // https://github.com/bitcoin/bips/blob/master/bip-0039/bip-0039-wordlists.md#japanese
2341 page
.open(url
, function(status
) {
2342 hasWordBreakCss
= page
.content
.indexOf("word-break: keep-all;") > -1;
2343 if (!hasWordBreakCss
) {
2344 console
.log("Japanese words can break across lines mid-word");
2345 console
.log("Check CSS for '.phrase { word-break: keep-all; }'");
2348 // Run the next test
2353 // Language can be specified at page load using hash value in url
2355 page
.open(url
, function(status
) {
2356 // Set the page hash as if it were on a fresh page load
2357 page
.evaluate(function() {
2358 window
.location
.hash
= "#japanese";
2360 // Generate a random phrase
2361 page
.evaluate(function() {
2362 $(".generate").trigger("click");
2364 waitForGenerate(function() {
2365 // Check the phrase is in Japanese
2366 var phrase
= page
.evaluate(function() {
2367 return $(".phrase").val();
2369 if (phrase
.length
<= 0) {
2370 console
.log("No phrase generated using url hash");
2373 if (phrase
.charCodeAt(0) < 128) {
2374 console
.log("Language not detected from url hash on page load.");
2375 console
.log("Phrase: " + phrase
);
2383 // Entropy unit tests
2385 page
.open(url
, function(status
) {
2386 var response
= page
.evaluate(function() {
2388 // binary entropy is detected
2390 e
= Entropy
.fromString("01010101");
2391 if (e
.base
.str
!= "binary") {
2392 return "Binary entropy not detected correctly";
2398 // base6 entropy is detected
2400 e
= Entropy
.fromString("012345012345");
2401 if (e
.base
.str
!= "base 6") {
2402 return "base6 entropy not detected correctly";
2408 // dice entropy is detected
2410 e
= Entropy
.fromString("123456123456");
2411 if (e
.base
.str
!= "base 6 (dice)") {
2412 return "dice entropy not detected correctly";
2418 // base10 entropy is detected
2420 e
= Entropy
.fromString("0123456789");
2421 if (e
.base
.str
!= "base 10") {
2422 return "base10 entropy not detected correctly";
2428 // hex entropy is detected
2430 e
= Entropy
.fromString("0123456789ABCDEF");
2431 if (e
.base
.str
!= "hexadecimal") {
2432 return "hexadecimal entropy not detected correctly";
2438 // card entropy is detected
2440 e
= Entropy
.fromString("AC4DTHKS");
2441 if (e
.base
.str
!= "card") {
2442 return "card entropy not detected correctly";
2448 // entropy is case insensitive
2450 e
= Entropy
.fromString("aBcDeF");
2451 if (e
.cleanStr
!= "aBcDeF") {
2452 return "Entropy should not be case sensitive";
2458 // dice entropy is converted to base6
2460 e
= Entropy
.fromString("123456");
2461 if (e
.cleanStr
!= "123450") {
2462 return "Dice entropy is not automatically converted to base6";
2468 // dice entropy is preferred to base6 if ambiguous
2470 e
= Entropy
.fromString("12345");
2471 if (e
.base
.str
!= "base 6 (dice)") {
2472 return "dice not used as default over base 6";
2478 // unused characters are ignored
2480 e
= Entropy
.fromString("fghijkl");
2481 if (e
.cleanStr
!= "f") {
2482 return "additional characters are not ignored";
2488 // the lowest base is used by default
2489 // 7 could be decimal or hexadecimal, but should be detected as decimal
2491 e
= Entropy
.fromString("7");
2492 if (e
.base
.str
!= "base 10") {
2493 return "lowest base is not used";
2499 // Leading zeros are retained
2501 e
= Entropy
.fromString("000A");
2502 if (e
.cleanStr
!= "000A") {
2503 return "Leading zeros are not retained";
2509 // Leading zeros are correctly preserved for hex in binary string
2511 e
= Entropy
.fromString("2A");
2512 if (e
.binaryStr
!= "00101010") {
2513 return "Hex leading zeros are not correct in binary";
2519 // Leading zeros for base 6 as binary string
2520 // 20 = 2 events at 2.58 bits per event = 5 bits
2521 // 20 in base 6 = 12 in base 10 = 1100 in base 2
2522 // so it needs 1 bit of padding to be the right bit length
2524 e
= Entropy
.fromString("20");
2525 if (e
.binaryStr
!= "01100") {
2526 return "Base 6 as binary has leading zeros";
2532 // Leading zeros for base 10 as binary string
2534 e
= Entropy
.fromString("17");
2535 if (e
.binaryStr
!= "010001") {
2536 return "Base 10 as binary has leading zeros";
2542 // Leading zeros for card entropy as binary string.
2543 // Card entropy is hashed so 2c does not necessarily produce leading zeros.
2545 e
= Entropy
.fromString("2c");
2546 if (e
.binaryStr
!= "0010") {
2547 return "Card entropy as binary has leading zeros";
2553 // Keyboard mashing results in weak entropy
2554 // Despite being a long string, it's less than 30 bits of entropy
2556 e
= Entropy
.fromString("aj;se ifj; ask,dfv js;ifj");
2557 if (e
.binaryStr
.length
>= 30) {
2558 return "Keyboard mashing should produce weak entropy";
2564 // Card entropy is used if every pair could be a card
2566 e
= Entropy
.fromString("4c3c2c");
2567 if (e
.base
.str
!= "card") {
2568 return "Card entropy not used if all pairs are cards";
2574 // Card entropy uses base 52
2575 // [ cards, binary ]
2579 [ "acqs", "11011100" ],
2580 [ "acks", "01011100" ],
2581 [ "2cac", "11111000" ],
2594 [ "ks2c", "01010100" ],
2595 [ "KS2C", "01010100" ],
2597 for (var i
=0; i
<cards
.length
; i
++) {
2598 var card
= cards
[i
][0];
2599 var result
= cards
[i
][1];
2600 e
= Entropy
.fromString(card
);
2601 console
.log(e
.binary
+ " " + result
);
2602 if (e
.binaryStr
!== result
) {
2603 return "card entropy " + card
+ " not parsed correctly: " + result
+ " != " + e
.binaryStr
;
2612 if (response
!= "PASS") {
2613 console
.log("Entropy unit tests");
2614 console
.log(response
);
2621 // Entropy can be entered by the user
2623 page
.open(url
, function(status
) {
2625 mnemonic: "abandon abandon ability",
2626 address: "1Di3Vp7tBWtyQaDABLAjfWtF6V7hYKJtug",
2629 page
.evaluate(function() {
2630 $(".use-entropy").prop("checked", true).trigger("change");
2631 $(".entropy").val("00000000 00000000 00000000 00000000").trigger("input");
2633 // check the mnemonic is set and address is correct
2634 waitForGenerate(function() {
2635 var actual
= page
.evaluate(function() {
2637 address: $(".address:first").text(),
2638 mnemonic: $(".phrase").val(),
2641 if (actual
.mnemonic
!= expected
.mnemonic
) {
2642 console
.log("Entropy does not generate correct mnemonic");
2643 console
.log("Expected: " + expected
.mnemonic
);
2644 console
.log("Got: " + actual
.mnemonic
);
2647 if (actual
.address
!= expected
.address
) {
2648 console
.log("Entropy does not generate correct address");
2649 console
.log("Expected: " + expected
.address
);
2650 console
.log("Got: " + actual
.address
);
2658 // A warning about entropy is shown to the user, with additional information
2660 page
.open(url
, function(status
) {
2661 // get text content from entropy sections of page
2662 var hasWarning
= page
.evaluate(function() {
2663 var entropyText
= $(".entropy-container").text();
2664 var warning
= "mnemonic may be insecure";
2665 if (entropyText
.indexOf(warning
) == -1) {
2668 var readMoreText
= $("#entropy-notes").parent().text();
2669 var goodSources
= "flipping a fair coin, rolling a fair dice, noise measurements etc";
2670 if (readMoreText
.indexOf(goodSources
) == -1) {
2675 // check the warnings and information are shown
2677 console
.log("Page does not contain warning about using own entropy");
2684 // The types of entropy available are described to the user
2686 page
.open(url
, function(status
) {
2687 // get placeholder text for entropy field
2688 var placeholder
= page
.evaluate(function() {
2689 return $(".entropy").attr("placeholder");
2699 for (var i
=0; i
<options
.length
; i
++) {
2700 var option
= options
[i
];
2701 if (placeholder
.indexOf(option
) == -1) {
2702 console
.log("Available entropy type is not shown to user: " + option
);
2710 // The actual entropy used is shown to the user
2712 page
.open(url
, function(status
) {
2714 var badEntropySource
= page
.evaluate(function() {
2715 var entropy
= "Not A Very Good Entropy Source At All";
2716 $(".use-entropy").prop("checked", true).trigger("change");
2717 $(".entropy").val(entropy
).trigger("input");
2719 // check the actual entropy being used is shown
2720 waitForEntropyFeedback(function() {
2721 var expectedText
= "AedEceAA";
2722 var entropyText
= page
.evaluate(function() {
2723 return $(".entropy-container").text();
2725 if (entropyText
.indexOf(expectedText
) == -1) {
2726 console
.log("Actual entropy used is not shown");
2734 // Binary entropy can be entered
2736 page
.open(url
, function(status
) {
2738 page
.evaluate(function() {
2739 $(".use-entropy").prop("checked", true).trigger("change");
2740 $(".entropy").val("01").trigger("input");
2742 // check the entropy is shown to be the correct type
2743 waitForEntropyFeedback(function() {
2744 var entropyText
= page
.evaluate(function() {
2745 return $(".entropy-container").text();
2747 if (entropyText
.indexOf("binary") == -1) {
2748 console
.log("Binary entropy is not detected and presented to user");
2756 // Base 6 entropy can be entered
2758 page
.open(url
, function(status
) {
2760 page
.evaluate(function() {
2761 $(".use-entropy").prop("checked", true).trigger("change");
2762 $(".entropy").val("012345").trigger("input");
2764 // check the entropy is shown to be the correct type
2765 waitForEntropyFeedback(function() {
2766 var entropyText
= page
.evaluate(function() {
2767 return $(".entropy-container").text();
2769 if (entropyText
.indexOf("base 6") == -1) {
2770 console
.log("Base 6 entropy is not detected and presented to user");
2778 // Base 6 dice entropy can be entered
2780 page
.open(url
, function(status
) {
2782 page
.evaluate(function() {
2783 $(".use-entropy").prop("checked", true).trigger("change");
2784 $(".entropy").val("123456").trigger("input");
2786 // check the entropy is shown to be the correct type
2787 waitForEntropyFeedback(function() {
2788 var entropyText
= page
.evaluate(function() {
2789 return $(".entropy-container").text();
2791 if (entropyText
.indexOf("dice") == -1) {
2792 console
.log("Dice entropy is not detected and presented to user");
2800 // Base 10 entropy can be entered
2802 page
.open(url
, function(status
) {
2804 page
.evaluate(function() {
2805 $(".use-entropy").prop("checked", true).trigger("change");
2806 $(".entropy").val("789").trigger("input");
2808 // check the entropy is shown to be the correct type
2809 waitForEntropyFeedback(function() {
2810 var entropyText
= page
.evaluate(function() {
2811 return $(".entropy-container").text();
2813 if (entropyText
.indexOf("base 10") == -1) {
2814 console
.log("Base 10 entropy is not detected and presented to user");
2822 // Hexadecimal entropy can be entered
2824 page
.open(url
, function(status
) {
2826 page
.evaluate(function() {
2827 $(".use-entropy").prop("checked", true).trigger("change");
2828 $(".entropy").val("abcdef").trigger("input");
2830 // check the entropy is shown to be the correct type
2831 waitForEntropyFeedback(function() {
2832 var entropyText
= page
.evaluate(function() {
2833 return $(".entropy-container").text();
2835 if (entropyText
.indexOf("hexadecimal") == -1) {
2836 console
.log("Hexadecimal entropy is not detected and presented to user");
2844 // Dice entropy value is shown as the converted base 6 value
2846 page
.open(url
, function(status
) {
2848 page
.evaluate(function() {
2849 $(".use-entropy").prop("checked", true).trigger("change");
2850 $(".entropy").val("123456").trigger("input");
2852 // check the entropy is shown as base 6, not as the original dice value
2853 waitForEntropyFeedback(function() {
2854 var entropyText
= page
.evaluate(function() {
2855 return $(".entropy-container").text();
2857 if (entropyText
.indexOf("123450") == -1) {
2858 console
.log("Dice entropy is not shown to user as base 6 value");
2861 if (entropyText
.indexOf("123456") > -1) {
2862 console
.log("Dice entropy value is shown instead of true base 6 value");
2870 // The number of bits of entropy accumulated is shown
2872 page
.open(url
, function(status
) {
2875 [ "0000 0000 0000 0000 0000", "20" ],
2878 [ "6", "2" ], // 6 in card is 0 in base 6, 0 in base 6 is 2.6 bits (rounded down to 2 bits)
2879 [ "7", "3" ], // 7 in base 10 is 111 in base 2, no leading zeros
2884 [ "1A", "8" ], // hex is always multiple of 4 bits of entropy
2891 [ "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)
2892 [ "2227", "13" ], // Uses base 10, which is 4 lots of 3.32 bits, which is 13.3 bits (rounded down to 13)
2895 [ "0000101017", "33" ], // 10 events at 3.32 bits per event
2896 [ "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
2899 page
.evaluate(function(e
) {
2900 $(".use-entropy").prop("checked", true).trigger("change");
2903 var nextTest
= function runNextTest(i
) {
2904 var entropy
= tests
[i
][0];
2905 var expected
= tests
[i
][1];
2907 page
.evaluate(function(e
) {
2908 $(".entropy").val(e
).trigger("input");
2910 // check the number of bits of entropy is shown
2911 waitForEntropyFeedback(function() {
2912 var entropyText
= page
.evaluate(function() {
2913 return $(".entropy-container").text();
2915 if (entropyText
.replace(/\s/g,"").indexOf("Bits" + expected
) == -1) {
2916 console
.log("Accumulated entropy is not shown correctly for " + entropy
);
2919 var isLastTest
= i
== tests
.length
- 1;
2932 // There is feedback provided about the supplied entropy
2934 page
.open(url
, function(status
) {
2939 type: "hexadecimal",
2943 strength: "less than a second",
2946 entropy: "AAAAAAAA",
2947 filtered: "AAAAAAAA",
2948 type: "hexadecimal",
2952 strength: "less than a second - Repeats like \"aaa\" are easy to guess",
2955 entropy: "AAAAAAAA B",
2956 filtered: "AAAAAAAAB",
2957 type: "hexadecimal",
2961 strength: "less than a second - Repeats like \"aaa\" are easy to guess",
2964 entropy: "AAAAAAAA BBBBBBBB",
2965 filtered: "AAAAAAAABBBBBBBB",
2966 type: "hexadecimal",
2970 strength: "less than a second - Repeats like \"aaa\" are easy to guess",
2973 entropy: "AAAAAAAA BBBBBBBB CCCCCCCC",
2974 filtered: "AAAAAAAABBBBBBBBCCCCCCCC",
2975 type: "hexadecimal",
2979 strength: "less than a second",
2982 entropy: "AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD",
2983 filtered: "AAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD",
2984 type: "hexadecimal",
2988 strength: "2 minutes",
2991 entropy: "AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDA",
2992 filtered: "AAAAAAAABBBBBBBBCCCCCCCCDDDDDDDA",
2993 type: "hexadecimal",
3000 entropy: "AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDA EEEEEEEE",
3001 filtered: "AAAAAAAABBBBBBBBCCCCCCCCDDDDDDDAEEEEEEEE",
3002 type: "hexadecimal",
3006 strength: "3 years",
3009 entropy: "AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDA EEEEEEEE FFFFFFFF",
3010 filtered: "AAAAAAAABBBBBBBBCCCCCCCCDDDDDDDAEEEEEEEEFFFFFFFF",
3011 type: "hexadecimal",
3015 strength: "centuries",
3023 strength: "less than a second",
3026 entropy: "ac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsks",
3027 type: "card (full deck)",
3031 strength: "centuries",
3034 entropy: "ac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsks3d",
3035 type: "card (full deck, 1 duplicate: 3d)",
3039 strength: "centuries",
3042 entropy: "ac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqs3d4d",
3043 type: "card (2 duplicates: 3d 4d, 1 missing: KS)",
3047 strength: "centuries",
3050 entropy: "ac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqs3d4d5d6d",
3051 type: "card (4 duplicates: 3d 4d 5d..., 1 missing: KS)",
3055 strength: "centuries",
3057 // Next test was throwing uncaught error in zxcvbn
3058 // Also tests 451 bits, ie Math.log2(52!)*2 = 225.58 * 2
3060 entropy: "ac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsksac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsks",
3061 type: "card (full deck, 52 duplicates: ac 2c 3c...)",
3065 strength: "centuries",
3067 // Case insensitivity to duplicate cards
3070 type: "card (1 duplicate: AS)",
3074 strength: "less than a second",
3078 type: "card (1 duplicate: as)",
3082 strength: "less than a second",
3084 // Missing cards are detected
3086 entropy: "ac2c3c4c5c6c7c8c tcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsks",
3087 type: "card (1 missing: 9C)",
3091 strength: "centuries",
3094 entropy: "ac2c3c4c5c6c7c8c tcjcqckcad2d3d4d 6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsks",
3095 type: "card (2 missing: 9C 5D)",
3099 strength: "centuries",
3102 entropy: "ac2c3c4c5c6c7c8c tcjcqckcad2d3d4d 6d7d8d9dtdjd kdah2h3h 5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsks",
3103 type: "card (4 missing: 9C 5D QD...)",
3107 strength: "centuries",
3109 // More than six missing cards does not show message
3111 entropy: "ac2c3c4c5c6c7c8c tcjcqckcad2d3d4d 6d 8d9d jd kdah2h3h 5h6h7h8h9hthjhqhkh 2s3s4s5s6s7s8s9stsjsqsks",
3116 strength: "centuries",
3118 // Multiple decks of cards increases bits per event
3138 entropy: "3d3d3d3d",
3144 entropy: "3d3d3d3d3d",
3150 entropy: "3d3d3d3d3d3d",
3156 entropy: "3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d",
3160 strength: 'less than a second - Repeats like "abcabcabc" are only slightly harder to guess than "abc"',
3164 page
.evaluate(function() {
3165 $(".use-entropy").prop("checked", true).trigger("change");
3167 var nextTest
= function runNextTest(i
) {
3168 function getFeedbackError(expected
, actual
) {
3169 if ("filtered" in expected
&& actual
.indexOf(expected
.filtered
) == -1) {
3170 return "Filtered value not in feedback";
3172 if ("type" in expected
&& actual
.indexOf(expected
.type
) == -1) {
3173 return "Entropy type not in feedback";
3175 if ("events" in expected
&& actual
.indexOf(expected
.events
) == -1) {
3176 return "Event count not in feedback";
3178 if ("bits" in expected
&& actual
.indexOf(expected
.bits
) == -1) {
3179 return "Bit count not in feedback";
3181 if ("strength" in expected
&& actual
.indexOf(expected
.strength
) == -1) {
3182 return "Strength not in feedback";
3184 if ("bitsPerEvent" in expected
&& actual
.indexOf(expected
.bitsPerEvent
) == -1) {
3185 return "bitsPerEvent not in feedback";
3190 page
.evaluate(function(e
) {
3191 $(".addresses").empty();
3192 $(".phrase").val("");
3193 $(".entropy").val(e
).trigger("input");
3195 waitForEntropyFeedback(function() {
3196 var mnemonic
= page
.evaluate(function() {
3197 return $(".phrase").val();
3199 // Check mnemonic length
3200 if ("words" in test
&& test
.words
== 0) {
3201 if (mnemonic
.length
> 0) {
3202 console
.log("Mnemonic length for " + test
.strength
+ " strength is not " + test
.words
);
3203 console
.log("Entropy: " + test
.entropy
);
3204 console
.log("Mnemonic: " + mnemonic
);
3208 else if ("words" in test
) {
3209 if (mnemonic
.split(" ").length
!= test
.words
) {
3210 console
.log("Mnemonic length for " + test
.strength
+ " strength is not " + test
.words
);
3211 console
.log("Entropy: " + test
.entropy
);
3212 console
.log("Mnemonic: " + mnemonic
);
3217 var feedback
= page
.evaluate(function() {
3218 return $(".entropy-container").text();
3220 var feedbackError
= getFeedbackError(test
, feedback
);
3221 if (feedbackError
) {
3222 console
.log("Entropy feedback for " + test
.entropy
+ " returned error");
3223 console
.log(feedbackError
);
3227 var isLastTest
= i
== tests
.length
- 1;
3240 // Entropy is truncated from the left
3242 page
.open(url
, function(status
) {
3243 var expected
= "avocado zoo zone";
3245 page
.evaluate(function() {
3246 $(".use-entropy").prop("checked", true).trigger("change");
3247 var entropy
= "00000000 00000000 00000000 00000000";
3248 entropy
+= "11111111 11111111 11111111 1111"; // Missing last byte
3249 $(".entropy").val(entropy
).trigger("input");
3251 // check the entropy is truncated from the right
3252 waitForGenerate(function() {
3253 var actual
= page
.evaluate(function() {
3254 return $(".phrase").val();
3256 if (actual
!= expected
) {
3257 console
.log("Entropy is not truncated from the right");
3258 console
.log("Expected: " + expected
);
3259 console
.log("Got: " + actual
);
3267 // Very large entropy results in very long mnemonics
3269 page
.open(url
, function(status
) {
3271 page
.evaluate(function() {
3272 $(".use-entropy").prop("checked", true).trigger("change");
3274 // Generate a very long entropy string
3275 for (var i
=0; i
<33; i
++) {
3276 entropy
+= "AAAAAAAA"; // 3 words * 33 iterations = 99 words
3278 $(".entropy").val(entropy
).trigger("input");
3280 // check the mnemonic is very long
3281 waitForGenerate(function() {
3282 var wordCount
= page
.evaluate(function() {
3283 return $(".phrase").val().split(" ").length
;
3285 if (wordCount
!= 99) {
3286 console
.log("Large entropy does not generate long mnemonic");
3287 console
.log("Expected 99 words, got " + wordCount
);
3295 // Is compatible with bip32jp entropy
3296 // https://bip32jp.github.io/english/index.html
3298 // Is incompatible with:
3301 page
.open(url
, function(status
) {
3302 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";
3304 page
.evaluate(function() {
3305 $(".use-entropy").prop("checked", true).trigger("change");
3306 var entropy
= "543210543210543210543210543210543210543210543210543210543210543210543210543210543210543210543210543";
3307 $(".entropy").val(entropy
).trigger("input");
3309 // check the mnemonic matches the expected value from bip32jp
3310 waitForGenerate(function() {
3311 var actual
= page
.evaluate(function() {
3312 return $(".phrase").val();
3314 if (actual
!= expected
) {
3315 console
.log("Mnemonic does not match bip32jp for base 6 entropy");
3316 console
.log("Expected: " + expected
);
3317 console
.log("Got: " + actual
);
3325 // Blank entropy does not generate mnemonic or addresses
3327 page
.open(url
, function(status
) {
3329 page
.evaluate(function() {
3330 $(".use-entropy").prop("checked", true).trigger("change");
3331 $(".entropy").val("").trigger("input");
3333 waitForFeedback(function() {
3334 // check there is no mnemonic
3335 var phrase
= page
.evaluate(function() {
3336 return $(".phrase").val();
3339 console
.log("Blank entropy does not result in blank mnemonic");
3340 console
.log("Got: " + phrase
);
3343 // check there are no addresses displayed
3344 var addresses
= page
.evaluate(function() {
3345 return $(".address").length
;
3347 if (addresses
!= 0) {
3348 console
.log("Blank entropy does not result in zero addresses");
3351 // Check the feedback says 'blank entropy'
3352 var feedback
= page
.evaluate(function() {
3353 return $(".feedback").text();
3355 if (feedback
!= "Blank entropy") {
3356 console
.log("Blank entropy does not show feedback message");
3364 // Mnemonic length can be selected even for weak entropy
3366 page
.open(url
, function(status
) {
3368 page
.evaluate(function() {
3369 $(".use-entropy").prop("checked", true).trigger("change");
3370 $(".entropy").val("012345");
3371 $(".mnemonic-length").val("18").trigger("change");
3373 // check the mnemonic is the correct length
3374 waitForGenerate(function() {
3375 var phrase
= page
.evaluate(function() {
3376 return $(".phrase").val();
3378 var numberOfWords
= phrase
.split(/\s/g).length
;
3379 if (numberOfWords
!= 18) {
3380 console
.log("Weak entropy cannot be overridden to give 18 word mnemonic");
3381 console
.log(phrase
);
3390 // https://github.com/iancoleman/bip39/issues/33
3391 // Final cards should contribute entropy
3393 page
.open(url
, function(status
) {
3395 page
.evaluate(function() {
3396 $(".use-entropy").prop("checked", true).trigger("change");
3397 $(".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");
3400 waitForGenerate(function() {
3401 var originalPhrase
= page
.evaluate(function() {
3402 return $(".phrase").val();
3404 // Set the last 12 cards to be AS
3405 page
.evaluate(function() {
3406 $(".addresses").empty();
3407 $(".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");
3409 // get the new mnemonic
3410 waitForGenerate(function() {
3411 var newPhrase
= page
.evaluate(function() {
3412 return $(".phrase").val();
3414 // check the phrase has changed
3415 if (newPhrase
== originalPhrase
) {
3416 console
.log("Changing last 12 cards does not change mnemonic");
3417 console
.log("Original:");
3418 console
.log(originalPhrase
);
3419 console
.log("New:");
3420 console
.log(newPhrase
);
3430 // https://github.com/iancoleman/bip39/issues/35
3433 page
.open(url
, function(status
) {
3435 page
.evaluate(function() {
3436 $(".generate").click();
3438 waitForGenerate(function() {
3439 var p
= page
.evaluate(function() {
3440 // get position of mnemonic element
3441 return $(".phrase").offset();
3443 p
.top
= Math
.ceil(p
.top
);
3444 p
.left
= Math
.ceil(p
.left
);
3445 // check the qr code shows
3446 page
.sendEvent("mousemove", p
.left
+4, p
.top
+4);
3447 var qrShowing
= page
.evaluate(function() {
3448 return $(".qr-container").find("canvas").length
> 0;
3451 console
.log("QR Code does not show");
3454 // check the qr code hides
3455 page
.sendEvent("mousemove", p
.left
-4, p
.top
-4);
3456 var qrHidden
= page
.evaluate(function() {
3457 return $(".qr-container").find("canvas").length
== 0;
3460 console
.log("QR Code does not hide");
3468 // BIP44 account extendend private key is shown
3469 // github issue 37 - compatibility with electrum
3471 page
.open(url
, function(status
) {
3473 var expected
= "xprv9yzrnt4zWVJUr1k2VxSPy9ettKz5PpeDMgaVG7UKedhqnw1tDkxP2UyYNhuNSumk2sLE5ctwKZs9vwjsq3e1vo9egCK6CzP87H2cVYXpfwQ";
3474 page
.evaluate(function() {
3475 $(".phrase").val("abandon abandon ability");
3476 $(".phrase").trigger("input");
3478 // check the BIP44 account extended private key
3479 waitForGenerate(function() {
3480 var actual
= page
.evaluate(function() {
3481 return $("#bip44 .account-xprv").val();
3483 if (actual
!= expected
) {
3484 console
.log("BIP44 account extended private key is incorrect");
3485 console
.log("Expected: " + expected
);
3486 console
.log("Actual: " + actual
);
3494 // BIP44 account extendend public key is shown
3495 // github issue 37 - compatibility with electrum
3497 page
.open(url
, function(status
) {
3499 var expected
= "xpub6CzDCPbtLrrn4VpVbyyQLHbdSMpZoHN4iuW64VswCyEpfjM2mJGdaHJ2DyuZwtst96E16VvcERb8BBeJdHSCVmAq9RhtRQg6eAZFrTKCNqf";
3500 page
.evaluate(function() {
3501 $(".phrase").val("abandon abandon ability");
3502 $(".phrase").trigger("input");
3504 // check the BIP44 account extended public key
3505 waitForGenerate(function() {
3506 var actual
= page
.evaluate(function() {
3507 return $("#bip44 .account-xpub").val();
3509 if (actual
!= expected
) {
3510 console
.log("BIP44 account extended public key is incorrect");
3511 console
.log("Expected: " + expected
);
3512 console
.log("Actual: " + actual
);
3521 // BIP32 root key can be set as an xpub
3523 page
.open(url
, function(status
) {
3525 page
.evaluate(function() {
3526 // set xpub for account 0 of bip44 for 'abandon abandon ability'
3527 var bip44AccountXpub
= "xpub6CzDCPbtLrrn4VpVbyyQLHbdSMpZoHN4iuW64VswCyEpfjM2mJGdaHJ2DyuZwtst96E16VvcERb8BBeJdHSCVmAq9RhtRQg6eAZFrTKCNqf";
3528 $("#root-key").val(bip44AccountXpub
);
3529 $("#root-key").trigger("input");
3531 waitForFeedback(function() {
3532 page
.evaluate(function() {
3534 $("#bip32-tab a").click();
3536 waitForGenerate(function() {
3537 page
.evaluate(function() {
3538 // derive external addresses for this xpub
3539 var firstAccountDerivationPath
= "m/0";
3540 $("#bip32-path").val(firstAccountDerivationPath
);
3541 $("#bip32-path").trigger("input");
3543 waitForGenerate(function() {
3544 // check the addresses are generated
3545 var expected
= "1Di3Vp7tBWtyQaDABLAjfWtF6V7hYKJtug";
3546 var actual
= page
.evaluate(function() {
3547 return $(".address:first").text();
3549 if (actual
!= expected
) {
3550 console
.log("xpub key does not generate addresses in table");
3551 console
.log("Expected: " + expected
);
3552 console
.log("Actual: " + actual
);
3555 // check the xprv key is not set
3556 var expected
= "NA";
3557 var actual
= page
.evaluate(function() {
3558 return $(".extended-priv-key").val();
3560 if (actual
!= expected
) {
3561 console
.log("xpub key as root shows derived bip32 xprv key");
3562 console
.log("Expected: " + expected
);
3563 console
.log("Actual: " + actual
);
3566 // check the private key is not set
3567 var expected
= "NA";
3568 var actual
= page
.evaluate(function() {
3569 return $(".privkey:first").text();
3571 if (actual
!= expected
) {
3572 console
.log("xpub key generates private key in addresses table");
3573 console
.log("Expected: " + expected
);
3574 console
.log("Actual: " + actual
);
3585 // xpub for bip32 root key will not work with hardened derivation paths
3587 page
.open(url
, function(status
) {
3589 page
.evaluate(function() {
3590 // set xpub for account 0 of bip44 for 'abandon abandon ability'
3591 var bip44AccountXpub
= "xpub6CzDCPbtLrrn4VpVbyyQLHbdSMpZoHN4iuW64VswCyEpfjM2mJGdaHJ2DyuZwtst96E16VvcERb8BBeJdHSCVmAq9RhtRQg6eAZFrTKCNqf";
3592 $("#root-key").val(bip44AccountXpub
);
3593 $("#root-key").trigger("input");
3595 waitForFeedback(function() {
3596 // Check feedback is correct
3597 var expected
= "Hardened derivation path is invalid with xpub key";
3598 var actual
= page
.evaluate(function() {
3599 return $(".feedback").text();
3601 if (actual
!= expected
) {
3602 console
.log("xpub key with hardened derivation path does not show feedback");
3603 console
.log("Expected: " + expected
);
3604 console
.log("Actual: " + actual
);
3607 // Check no addresses are shown
3609 var actual
= page
.evaluate(function() {
3610 return $(".addresses tr").length
;
3612 if (actual
!= expected
) {
3613 console
.log("addresses still show after setting xpub key with hardened derivation path");
3614 console
.log("Expected: " + expected
);
3615 console
.log("Actual: " + actual
);
3624 // no root key shows feedback
3626 page
.open(url
, function(status
) {
3627 // click the bip32 tab on fresh page
3628 page
.evaluate(function() {
3629 $("#bip32-tab a").click();
3631 waitForFeedback(function() {
3632 // Check feedback is correct
3633 var expected
= "No root key";
3634 var actual
= page
.evaluate(function() {
3635 return $(".feedback").text();
3637 if (actual
!= expected
) {
3638 console
.log("Blank root key not detected");
3639 console
.log("Expected: " + expected
);
3640 console
.log("Actual: " + actual
);
3649 // display error switching tabs while addresses are generating
3651 page
.open(url
, function(status
) {
3653 page
.evaluate(function() {
3654 $(".phrase").val("abandon abandon ability").trigger("input");
3656 waitForGenerate(function() {
3657 // set to generate 500 more addresses
3658 // generate more addresses
3659 // change tabs which should cancel the previous generating
3660 page
.evaluate(function() {
3661 $(".rows-to-add").val("100");
3663 $("#bip32-tab a").click();
3665 // check the derivation paths are in order and of the right quantity
3666 waitForGenerate(function() {
3667 var paths
= page
.evaluate(function() {
3668 return $(".index").map(function(i
, e
) {
3672 for (var i
=0; i
<paths
.length
; i
++) {
3673 var expected
= "m/0/" + i
;
3674 var actual
= paths
[i
];
3675 if (actual
!= expected
) {
3676 console
.log("Path " + i
+ " is not in correct order");
3677 console
.log("Expected: " + expected
);
3678 console
.log("Actual: " + actual
);
3682 if (paths
.length
!= 20) {
3683 console
.log("Generation was not cancelled by new action");
3693 // padding for binary should give length with multiple of 256
3694 // hashed entropy 1111 is length 252, so requires 4 leading zeros
3695 // prior to issue 49 it would only generate 2 leading zeros, ie missing 2
3697 page
.open(url
, function(status
) {
3698 expected
= "avocado valid quantum cross link predict excuse edit street able flame large galaxy ginger nuclear"
3700 page
.evaluate(function() {
3701 $(".use-entropy").prop("checked", true).trigger("change");
3702 $(".mnemonic-length").val("15");
3703 $(".entropy").val("1111").trigger("input");
3705 waitForGenerate(function() {
3707 var actual
= page
.evaluate(function() {
3708 return $(".phrase").val();
3710 // check the mnemonic is correct
3711 if (actual
!= expected
) {
3712 console
.log("Left padding error for entropy");
3713 console
.log("Expected: " + expected
);
3714 console
.log("Actual: " + actual
);
3722 // Github pull request 55
3723 // https://github.com/iancoleman/bip39/pull/55
3726 page
.open(url
, function(status
) {
3727 // set mnemonic and select bip32 tab
3728 page
.evaluate(function() {
3729 $("#bip32-tab a").click();
3730 $(".phrase").val("abandon abandon ability").trigger("input");
3732 waitForGenerate(function() {
3734 // set bip32 client to bitcoin core
3735 page
.evaluate(function() {
3736 var bitcoinCoreIndex
= "0";
3737 $("#bip32-client").val(bitcoinCoreIndex
).trigger("change");
3739 waitForGenerate(function() {
3740 // get the derivation path
3741 var actual
= page
.evaluate(function() {
3742 return $("#bip32-path").val();
3744 // check the derivation path is correct
3745 expected
= "m/0'/0'"
3746 if (actual
!= expected
) {
3747 console
.log("Selecting Bitcoin Core client does not set correct derivation path");
3748 console
.log("Expected: " + expected
);
3749 console
.log("Actual: " + actual
);
3752 // get hardened addresses
3753 var usesHardenedAddresses
= page
.evaluate(function() {
3754 return $(".hardened-addresses").prop("checked");
3756 // check hardened addresses is selected
3757 if(!usesHardenedAddresses
) {
3758 console
.log("Selecting Bitcoin Core client does not use hardened addresses");
3761 // check input is readonly
3762 var pathIsReadonly
= page
.evaluate(function() {
3763 return $("#bip32-path").prop("readonly");
3765 if (!pathIsReadonly
) {
3766 console
.log("Selecting Bitcoin Core client does not set derivation path to readonly");
3770 // set bip32 client to multibit
3771 page
.evaluate(function() {
3772 var multibitIndex
= "2";
3773 $("#bip32-client").val(multibitIndex
).trigger("change");
3775 waitForGenerate(function() {
3776 // get the derivation path
3777 var actual
= page
.evaluate(function() {
3778 return $("#bip32-path").val();
3780 // check the derivation path is correct
3782 if (actual
!= expected
) {
3783 console
.log("Selecting Multibit client does not set correct derivation path");
3784 console
.log("Expected: " + expected
);
3785 console
.log("Actual: " + actual
);
3788 // get hardened addresses
3789 var usesHardenedAddresses
= page
.evaluate(function() {
3790 return $(".hardened-addresses").prop("checked");
3792 // check hardened addresses is selected
3793 if(usesHardenedAddresses
) {
3794 console
.log("Selecting Multibit client does not uncheck hardened addresses");
3797 // CUSTOM DERIVATION PATH
3798 // check input is not readonly
3799 page
.evaluate(function() {
3800 $("#bip32-client").val("custom").trigger("change");
3802 // do not wait for generate, since there is no change to the
3803 // derivation path there is no new generation performed
3804 var pathIsReadonly
= page
.evaluate(function() {
3805 return $("#bip32-path").prop("readonly");
3807 if (pathIsReadonly
) {
3808 console
.log("Selecting Custom Derivation Path does not allow derivation path input");
3819 // https://github.com/iancoleman/bip39/issues/58
3820 // bip32 derivation is correct, does not drop leading zeros
3822 // https://medium.com/@alexberegszaszi/why-do-my-bip32-wallets-disagree-6f3254cc5846
3824 page
.open(url
, function(status
) {
3825 // set the phrase and passphrase
3826 var expected
= "17rxURoF96VhmkcEGCj5LNQkmN9HVhWb7F";
3827 // Note that bitcore generates an incorrect address
3828 // 13EuKhffWkBE2KUwcbkbELZb1MpzbimJ3Y
3829 // see the medium.com link above for more details
3830 page
.evaluate(function() {
3831 $(".phrase").val("fruit wave dwarf banana earth journey tattoo true farm silk olive fence");
3832 $(".passphrase").val("banana").trigger("input");
3834 // check the address is generated correctly
3835 waitForGenerate(function() {
3836 var actual
= page
.evaluate(function() {
3837 return $(".address:first").text();
3839 if (actual
!= expected
) {
3840 console
.log("BIP32 derivation is incorrect");
3841 console
.log("Expected: " + expected
);
3842 console
.log("Actual: " + actual
);
3852 // Japanese mnemonics generate incorrect bip32 seed
3853 // BIP39 seed is set from phrase
3855 page
.open(url
, function(status
) {
3857 var expected
= "a262d6fb6122ecf45be09c50492b31f92e9beb7d9a845987a02cefda57a15f9c467a17872029a9e92299b5cbdf306e3a0ee620245cbd508959b6cb7ca637bd55";
3858 page
.evaluate(function() {
3859 $(".phrase").val("あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あおぞら");
3860 $("#passphrase").val("メートルガバヴァぱばぐゞちぢ十人十色");
3861 $("#passphrase").trigger("input");
3863 // check the seed is generated correctly
3864 waitForGenerate(function() {
3865 var actual
= page
.evaluate(function() {
3866 return $(".seed").val();
3868 if (actual
!= expected
) {
3869 console
.log("BIP39 seed is incorrectly generated from Japanese mnemonic");
3870 console
.log("Expected: " + expected
);
3871 console
.log("Actual: " + actual
);
3879 // BIP49 official test vectors
3880 // https://github.com/bitcoin/bips/blob/master/bip-0049.mediawiki#test-vectors
3882 page
.open(url
, function(status
) {
3883 // set the phrase and select bitcoin testnet
3884 var expected
= "2Mww8dCYPUpKHofjgcXcBCEGmniw9CoaiD2";
3885 page
.evaluate(function() {
3886 $("#bip49-tab a").click();
3887 $(".phrase").val("abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about");
3888 $(".network option[selected]").removeAttr("selected");
3889 $(".network option").filter(function() {
3890 return $(this).html() == "BTC - Bitcoin Testnet";
3891 }).prop("selected", true);
3892 $(".network").trigger("change");
3893 $(".phrase").trigger("input");
3895 // check the first address
3896 waitForGenerate(function() {
3897 var actual
= page
.evaluate(function() {
3898 return $(".address:first").text();
3900 if (actual
!= expected
) {
3901 console
.log("BIP49 address is incorrect");
3902 console
.log("Expected: " + expected
);
3903 console
.log("Actual: " + actual
);
3911 // BIP49 derivation path is shown
3913 page
.open(url
, function(status
) {
3915 var expected
= "m/49'/0'/0'/0";
3916 page
.evaluate(function() {
3917 $("#bip49-tab a").click();
3918 $(".phrase").val("abandon abandon ability").trigger("input");
3920 // check the derivation path of the first address
3921 waitForGenerate(function() {
3922 var actual
= page
.evaluate(function() {
3923 return $("#bip49 .path").val();
3925 if (actual
!= expected
) {
3926 console
.log("BIP49 derivation path is incorrect");
3927 console
.log("Expected: " + expected
);
3928 console
.log("Actual: " + actual
);
3936 // BIP49 extended private key is shown
3938 page
.open(url
, function(status
) {
3940 var expected
= "xprvA1hukYsW7QfX9CVsaDAKde4eryajKa4DKWb6m9YjSnqkiZHrahFwwTJfEQTwBQ5kptWT5pZMkkusT1oK8dc1efQ8VFfq4SLSPAWd7Cpt423";
3941 page
.evaluate(function() {
3942 $("#bip49-tab a").click();
3943 $(".phrase").val("abandon abandon ability").trigger("input");
3945 // check the BIP49 extended private key
3946 waitForGenerate(function() {
3947 var actual
= page
.evaluate(function() {
3948 return $(".extended-priv-key").val();
3950 if (actual
!= expected
) {
3951 console
.log("BIP49 extended private key is incorrect");
3952 console
.log("Expected: " + expected
);
3953 console
.log("Actual: " + actual
);
3961 // BIP49 extended public key is shown
3963 page
.open(url
, function(status
) {
3965 var expected
= "xpub6EhGA4QPwnDpMgaLgEhKzn1PR1RDj2n4gjWhZXxM18NjbMd18EaCVFd95gkLARJaBD2rXAYJED2gdkUbGn1KkrSzCKR554AdABUELoainnt";
3966 page
.evaluate(function() {
3967 $("#bip49-tab a").click();
3968 $(".phrase").val("abandon abandon ability").trigger("input");
3970 // check the BIP49 extended public key
3971 waitForGenerate(function() {
3972 var actual
= page
.evaluate(function() {
3973 return $(".extended-pub-key").val();
3975 if (actual
!= expected
) {
3976 console
.log("BIP49 extended public key is incorrect");
3977 console
.log("Expected: " + expected
);
3978 console
.log("Actual: " + actual
);
3986 // BIP49 account field changes address list
3988 page
.open(url
, function(status
) {
3990 var expected
= "381wg1GGN4rP88rNC9v7QWsiww63yLVPsn";
3991 page
.evaluate(function() {
3992 $("#bip49-tab a").click();
3993 $(".phrase").val("abandon abandon ability").trigger("input");
3995 waitForGenerate(function() {
3996 // change the bip49 account field to 1
3997 page
.evaluate(function() {
3998 $("#bip49 .account").val("1");
3999 $("#bip49 .account").trigger("input");
4001 waitForGenerate(function() {
4002 // check the address for the new derivation path
4003 var actual
= page
.evaluate(function() {
4004 return $(".address:first").text();
4006 if (actual
!= expected
) {
4007 console
.log("BIP49 account field generates incorrect address");
4008 console
.log("Expected: " + expected
);
4009 console
.log("Actual: " + actual
);
4018 // BIP49 change field changes address list
4020 page
.open(url
, function(status
) {
4022 var expected
= "3PEM7MiKed5konBoN66PQhK8r3hjGhy9dT";
4023 page
.evaluate(function() {
4024 $("#bip49-tab a").click();
4025 $(".phrase").val("abandon abandon ability").trigger("input");
4027 waitForGenerate(function() {
4028 // change the bip49 change field to 1
4029 page
.evaluate(function() {
4030 $("#bip49 .change").val("1");
4031 $("#bip49 .change").trigger("input");
4033 waitForGenerate(function() {
4034 // check the address for the new derivation path
4035 var actual
= page
.evaluate(function() {
4036 return $(".address:first").text();
4038 if (actual
!= expected
) {
4039 console
.log("BIP49 change field generates incorrect address");
4040 console
.log("Expected: " + expected
);
4041 console
.log("Actual: " + actual
);
4050 // BIP49 account extendend private key is shown
4052 page
.open(url
, function(status
) {
4054 var expected
= "xprv9y3uhgQbfQZbj3o98nfgLDwGGuCJjUn7GKArSAZXjKgMjSdYHjQmTyf78s22g6jsGrxXvHB6HJeFyvFSPkuYZajeTGMZVXV6aNLWw2fagCn";
4055 page
.evaluate(function() {
4056 $("#bip49-tab a").click();
4057 $(".phrase").val("abandon abandon ability");
4058 $(".phrase").trigger("input");
4060 // check the BIP49 account extended private key
4061 waitForGenerate(function() {
4062 var actual
= page
.evaluate(function() {
4063 return $("#bip49 .account-xprv").val();
4065 if (actual
!= expected
) {
4066 console
.log("BIP49 account extended private key is incorrect");
4067 console
.log("Expected: " + expected
);
4068 console
.log("Actual: " + actual
);
4076 // BIP49 account extendend public key is shown
4078 page
.open(url
, function(status
) {
4080 var expected
= "xpub6C3G7BwVVn7twXscEpCghMszpw2o8wVxdY6TEYy9HfDLcExgqGj21myazAiq6HSmW2F1cBiFqJa3D1cqcDpSh8pbZF5x4iqpd4PyJvd3gjB";
4081 page
.evaluate(function() {
4082 $("#bip49-tab a").click();
4083 $(".phrase").val("abandon abandon ability");
4084 $(".phrase").trigger("input");
4086 // check the BIP49 account extended public key
4087 waitForGenerate(function() {
4088 var actual
= page
.evaluate(function() {
4089 return $("#bip49 .account-xpub").val();
4091 if (actual
!= expected
) {
4092 console
.log("BIP49 account extended public key is incorrect");
4093 console
.log("Expected: " + expected
);
4094 console
.log("Actual: " + actual
);
4102 // Test selecting coin where bip49 is unavailable (eg CLAM)
4104 page
.open(url
, function(status
) {
4106 page
.evaluate(function() {
4107 $("#bip49-tab a").click();
4108 $(".phrase").val("abandon abandon ability");
4109 $(".phrase").trigger("input");
4111 waitForGenerate(function() {
4112 // select non-bip49 network, ie CLAM network
4113 page
.evaluate(function() {
4114 $(".network option[selected]").removeAttr("selected");
4115 $(".network option").filter(function() {
4116 return $(this).html() == "CLAM - Clams";
4117 }).prop("selected", true);
4118 $(".network").trigger("change");
4120 // check the BIP49 error is shown
4121 var bip49ErrorShown
= page
.evaluate(function() {
4122 var bip49hidden
= $("#bip49 .available").hasClass("hidden");
4123 bip49hidden
= bip49hidden
&& !($("#bip49 .unavailable").hasClass("hidden"));
4126 if (!bip49ErrorShown
) {
4127 console
.log("BIP49 error not shown for non-bip49 network");
4130 // check there are no addresses shown
4131 var addressCount
= page
.evaluate(function() {
4132 return $(".address").length
;
4134 if (addressCount
!= 0) {
4135 console
.log("BIP49 address count for non-bip49 network is " + addressCount
);
4138 // check the derived keys are blank
4139 var areBlank
= page
.evaluate(function() {
4140 var prvKeyIsBlank
= $(".extended-priv-key").val().length
== 0;
4141 var pubKeyIsBlank
= $(".extended-pub-key").val().length
== 0;
4142 return prvKeyIsBlank
&& pubKeyIsBlank
;
4145 console
.log("BIP49 extended keys for non-bip49 network are not blank ");
4154 // Cleared mnemonic and root key still allows addresses to be generated
4155 // https://github.com/iancoleman/bip39/issues/43
4157 page
.open(url
, function(status
) {
4159 page
.evaluate(function() {
4160 $("#bip49-tab a").click();
4161 $(".phrase").val("abandon abandon ability");
4162 $(".phrase").trigger("input");
4164 waitForGenerate(function() {
4165 // clear the mnemonic and root key
4166 page
.evaluate(function() {
4167 $(".phrase").val("");
4168 $(".phrase").trigger("input");
4169 $(".root-key").val("");
4170 $(".root-key").trigger("input");
4173 waitForFeedback(function() {
4174 // check there are no addresses shown
4175 var addressCount
= page
.evaluate(function() {
4176 return $(".address").length
;
4178 if (addressCount
!= 0) {
4179 console
.log("Clearing mnemonic should not allow addresses to be generated");
4188 // If you wish to add more tests, do so here...
4190 // Here is a blank test template
4194 page.open(url, function(status) {
4195 // Do something on the page
4196 page.evaluate(function() {
4197 $(".phrase").val("abandon abandon ability").trigger("input");
4199 waitForGenerate(function() {
4200 // Check the result of doing the thing
4201 var expected = "1Di3Vp7tBWtyQaDABLAjfWtF6V7hYKJtug";
4202 var actual = page.evaluate(function() {
4203 return $(".address:first").text();
4205 if (actual != expected) {
4206 console.log("A specific message about what failed");
4207 console.log("Expected: " + expected);
4208 console.log("Actual: " + actual);
4211 // Run the next test
4221 console
.log("Running tests...");
4222 tests
= shuffle(tests
);