aboutsummaryrefslogtreecommitdiff
path: root/tests.js
diff options
context:
space:
mode:
authorIan Coleman <coleman.ian@gmail.com>2016-11-10 20:44:50 +1100
committerIan Coleman <coleman.ian@gmail.com>2016-11-10 20:44:50 +1100
commitfb353f9d4dd7c2ae6167fa2ee3d8772dd23595bc (patch)
tree4ad246bdf05ee3e9fa9b42a1507d87a9d5f4c99d /tests.js
parent3599674db4855614d9123f2f80dcf0a37c34eb79 (diff)
downloadBIP39-fb353f9d4dd7c2ae6167fa2ee3d8772dd23595bc.tar.gz
BIP39-fb353f9d4dd7c2ae6167fa2ee3d8772dd23595bc.tar.zst
BIP39-fb353f9d4dd7c2ae6167fa2ee3d8772dd23595bc.zip
Entropy feedback tests all fields
Diffstat (limited to 'tests.js')
-rw-r--r--tests.js118
1 files changed, 78 insertions, 40 deletions
diff --git a/tests.js b/tests.js
index 37a758f..fed6278 100644
--- a/tests.js
+++ b/tests.js
@@ -2537,76 +2537,142 @@ page.open(url, function(status) {
2537}); 2537});
2538}, 2538},
2539 2539
2540// The next strength above 0-word mnemonics is considered extremely weak 2540// There is feedback provided about the supplied entropy
2541// The next strength above 3-word mnemonics is considered very weak
2542// The next strength above 6-word mnemonics is considered weak
2543// The next strength above 9-word mnemonics is considered strong
2544// The next strength above 12-word mnemonics is considered very strong
2545// The next strength above 15-word mnemonics is considered extremely strong
2546function() { 2541function() {
2547page.open(url, function(status) { 2542page.open(url, function(status) {
2548 var tests = [ 2543 var tests = [
2549 { 2544 {
2550 entropy: "A", 2545 entropy: "A",
2546 filtered: "A",
2547 type: "hexadecimal",
2548 events: 1,
2549 bits: 4,
2551 words: 0, 2550 words: 0,
2552 strength: "extremely weak", 2551 strength: "extremely weak",
2553 }, 2552 },
2554 { 2553 {
2555 entropy: "AAAAAAAA", 2554 entropy: "AAAAAAAA",
2555 filtered: "AAAAAAAA",
2556 type: "hexadecimal",
2557 events: 8,
2558 bits: 32,
2556 words: 3, 2559 words: 3,
2557 strength: "extremely weak", 2560 strength: "extremely weak",
2558 }, 2561 },
2559 { 2562 {
2560 entropy: "AAAAAAAA B", 2563 entropy: "AAAAAAAA B",
2564 filtered: "AAAAAAAAB",
2565 type: "hexadecimal",
2566 events: 9,
2567 bits: 36,
2561 words: 3, 2568 words: 3,
2562 strength: "extremely weak", 2569 strength: "extremely weak",
2563 }, 2570 },
2564 { 2571 {
2565 entropy: "AAAAAAAA BBBBBBBB", 2572 entropy: "AAAAAAAA BBBBBBBB",
2573 filtered: "AAAAAAAABBBBBBBB",
2574 type: "hexadecimal",
2575 events: 16,
2576 bits: 64,
2566 words: 6, 2577 words: 6,
2567 strength: "very weak", 2578 strength: "very weak",
2568 }, 2579 },
2569 { 2580 {
2570 entropy: "AAAAAAAA BBBBBBBB CCCCCCCC", 2581 entropy: "AAAAAAAA BBBBBBBB CCCCCCCC",
2582 filtered: "AAAAAAAABBBBBBBBCCCCCCCC",
2583 type: "hexadecimal",
2584 events: 24,
2585 bits: 96,
2571 words: 9, 2586 words: 9,
2572 strength: "weak", 2587 strength: "weak",
2573 }, 2588 },
2574 { 2589 {
2575 entropy: "AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD", 2590 entropy: "AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD",
2591 filtered: "AAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD",
2592 type: "hexadecimal",
2593 events: 32,
2594 bits: 128,
2576 words: 12, 2595 words: 12,
2577 strength: "strong", 2596 strength: "strong",
2578 }, 2597 },
2579 { 2598 {
2580 entropy: "AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD EEEEEEEE", 2599 entropy: "AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD EEEEEEEE",
2600 filtered: "AAAAAAAABBBBBBBBCCCCCCCCDDDDDDDDEEEEEEEE",
2601 type: "hexadecimal",
2602 events: 40,
2603 bits: 160,
2581 words: 15, 2604 words: 15,
2582 strength: "very strong", 2605 strength: "very strong",
2583 }, 2606 },
2584 { 2607 {
2585 entropy: "AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD EEEEEEEE FFFFFFFF", 2608 entropy: "AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD EEEEEEEE FFFFFFFF",
2609 filtered: "AAAAAAAABBBBBBBBCCCCCCCCDDDDDDDDEEEEEEEEFFFFFFFF",
2610 type: "hexadecimal",
2611 events: 48,
2612 bits: 192,
2586 words: 18, 2613 words: 18,
2587 strength: "extremely strong", 2614 strength: "extremely strong",
2588 } 2615 },
2589 ]; 2616 ];
2590 // use entropy 2617 // use entropy
2591 page.evaluate(function() { 2618 page.evaluate(function() {
2592 $(".use-entropy").prop("checked", true).trigger("change"); 2619 $(".use-entropy").prop("checked", true).trigger("change");
2593 }); 2620 });
2594 var nextTest = function runNextTest(i) { 2621 var nextTest = function runNextTest(i) {
2622 function getFeedbackError(expected, actual) {
2623 if (actual.indexOf(expected.filtered) == -1) {
2624 return "Filtered value not in feedback";
2625 }
2626 if (actual.indexOf(expected.type) == -1) {
2627 return "Entropy type not in feedback";
2628 }
2629 if (actual.indexOf(expected.events) == -1) {
2630 return "Event count not in feedback";
2631 }
2632 if (actual.indexOf(expected.bits) == -1) {
2633 return "Bit count not in feedback";
2634 }
2635 if (actual.indexOf(expected.strength) == -1) {
2636 return "Strength not in feedback";
2637 }
2638 return false;
2639 }
2595 test = tests[i]; 2640 test = tests[i];
2596 page.evaluate(function(e) { 2641 page.evaluate(function(e) {
2597 $(".addresses").empty(); 2642 $(".addresses").empty();
2598 $(".phrase").val(""); 2643 $(".phrase").val("");
2599 $(".entropy").val(e).trigger("input"); 2644 $(".entropy").val(e).trigger("input");
2600 }, test.entropy); 2645 }, test.entropy);
2601 if (test.words == 0) { 2646 waitForEntropyFeedback(function() {
2602 var mnemonic = page.evaluate(function() { 2647 var mnemonic = page.evaluate(function() {
2603 return $(".phrase").val(); 2648 return $(".phrase").val();
2604 }); 2649 });
2605 if (mnemonic.length > 0) { 2650 // Check mnemonic length
2606 console.log("Mnemonic length for " + test.strength + " strength is not " + test.words); 2651 if (test.words == 0) {
2607 console.log("Mnemonic: " + mnemonic); 2652 if (mnemonic.length > 0) {
2653 console.log("Mnemonic length for " + test.strength + " strength is not " + test.words);
2654 console.log("Mnemonic: " + mnemonic);
2655 fail();
2656 }
2657 }
2658 else {
2659 if (mnemonic.split(" ").length != test.words) {
2660 console.log("Mnemonic length for " + test.strength + " strength is not " + test.words);
2661 console.log("Mnemonic: " + mnemonic);
2662 fail();
2663 }
2664 }
2665 // check feedback
2666 var feedback = page.evaluate(function() {
2667 return $(".entropy-feedback").text();
2668 });
2669 var feedbackError = getFeedbackError(test, feedback);
2670 if (feedbackError) {
2671 console.log("Entropy feedback for " + test.entropy + " returned error");
2672 console.log(feedbackError);
2608 fail(); 2673 fail();
2609 } 2674 }
2675 // Run next test
2610 var isLastTest = i == tests.length - 1; 2676 var isLastTest = i == tests.length - 1;
2611 if (isLastTest) { 2677 if (isLastTest) {
2612 next(); 2678 next();
@@ -2614,35 +2680,7 @@ page.open(url, function(status) {
2614 else { 2680 else {
2615 runNextTest(i+1); 2681 runNextTest(i+1);
2616 } 2682 }
2617 } 2683 });
2618 else {
2619 waitForGenerate(function() {
2620 // check the number of words in the current mnemonic
2621 var mnemonic = page.evaluate(function() {
2622 return $(".phrase").val();
2623 });
2624 if (mnemonic.split(" ").length != test.words) {
2625 console.log("Mnemonic length for " + test.strength + " strength is not " + test.words);
2626 console.log("Mnemonic: " + mnemonic);
2627 fail();
2628 }
2629 // check the strength of the mnemonic is shown
2630 var entropyText = page.evaluate(function() {
2631 return $(".entropy-container").text();
2632 });
2633 if (entropyText.indexOf(test.strength) == -1) {
2634 console.log("Strength indicator for " + test.strength + " mnemonic is incorrect");
2635 fail();
2636 }
2637 var isLastTest = i == tests.length - 1;
2638 if (isLastTest) {
2639 next();
2640 }
2641 else {
2642 runNextTest(i+1);
2643 }
2644 });
2645 }
2646 } 2684 }
2647 nextTest(0); 2685 nextTest(0);
2648}); 2686});