aboutsummaryrefslogtreecommitdiff
path: root/tests.js
diff options
context:
space:
mode:
Diffstat (limited to 'tests.js')
-rw-r--r--tests.js100
1 files changed, 41 insertions, 59 deletions
diff --git a/tests.js b/tests.js
index 102144f..420873d 100644
--- a/tests.js
+++ b/tests.js
@@ -80,7 +80,7 @@ function waitForEntropyFeedback(fn, maxTime) {
80 maxTime = testMaxTime; 80 maxTime = testMaxTime;
81 } 81 }
82 var origFeedback = page.evaluate(function() { 82 var origFeedback = page.evaluate(function() {
83 return $(".entropy-error").text(); 83 return $(".entropy-feedback").text();
84 }); 84 });
85 var start = new Date().getTime(); 85 var start = new Date().getTime();
86 var wait = function keepWaiting() { 86 var wait = function keepWaiting() {
@@ -92,11 +92,7 @@ function waitForEntropyFeedback(fn, maxTime) {
92 return; 92 return;
93 } 93 }
94 var feedback = page.evaluate(function() { 94 var feedback = page.evaluate(function() {
95 var feedback = $(".entropy-error"); 95 return $(".entropy-feedback").text();
96 if (feedback.css("display") == "none") {
97 return "";
98 }
99 return feedback.text();
100 }); 96 });
101 var hasFinished = feedback != origFeedback; 97 var hasFinished = feedback != origFeedback;
102 if (hasFinished) { 98 if (hasFinished) {
@@ -2130,30 +2126,33 @@ page.open(url, function(status) {
2130 catch (e) { 2126 catch (e) {
2131 return e.message; 2127 return e.message;
2132 } 2128 }
2133 // Leading zeros are not used for base 6 as binary string 2129 // Leading zeros for base 6 as binary string
2130 // 20 = 2 events at 2.58 bits per event = 5 bits
2131 // 20 in base 6 = 12 in base 10 = 1100 in base 2
2132 // so it needs 1 bit of padding to be the right bit length
2134 try { 2133 try {
2135 e = Entropy.fromString("2"); 2134 e = Entropy.fromString("20");
2136 if (e.binaryStr != "10") { 2135 if (e.binaryStr != "01100") {
2137 return "Base 6 as binary has leading zeros"; 2136 return "Base 6 as binary has leading zeros";
2138 } 2137 }
2139 } 2138 }
2140 catch (e) { 2139 catch (e) {
2141 return e.message; 2140 return e.message;
2142 } 2141 }
2143 // Leading zeros are not used for base 10 as binary string 2142 // Leading zeros for base 10 as binary string
2144 try { 2143 try {
2145 e = Entropy.fromString("7"); 2144 e = Entropy.fromString("17");
2146 if (e.binaryStr != "111") { 2145 if (e.binaryStr != "010001") {
2147 return "Base 10 as binary has leading zeros"; 2146 return "Base 10 as binary has leading zeros";
2148 } 2147 }
2149 } 2148 }
2150 catch (e) { 2149 catch (e) {
2151 return e.message; 2150 return e.message;
2152 } 2151 }
2153 // Leading zeros are not used for card entropy as binary string 2152 // Leading zeros for card entropy as binary string
2154 try { 2153 try {
2155 e = Entropy.fromString("2c"); 2154 e = Entropy.fromString("2c");
2156 if (e.binaryStr != "1") { 2155 if (e.binaryStr != "00001") {
2157 return "Card entropy as binary has leading zeros"; 2156 return "Card entropy as binary has leading zeros";
2158 } 2157 }
2159 } 2158 }
@@ -2187,18 +2186,18 @@ page.open(url, function(status) {
2187 var cards = [ 2186 var cards = [
2188 [ "ac", "00000" ], 2187 [ "ac", "00000" ],
2189 [ "acac", "00000000000" ], 2188 [ "acac", "00000000000" ],
2190 [ "acac2c", "000000000001" ], 2189 [ "acac2c", "00000000000000001" ],
2191 [ "acks", "00000110011" ], 2190 [ "acks", "00000110011" ],
2192 [ "acacks", "00000000000110011" ], 2191 [ "acacks", "00000000000110011" ],
2193 [ "2c", "1" ], 2192 [ "2c", "00001" ],
2194 [ "3d", "1111" ], 2193 [ "3d", "01111" ],
2195 [ "4h", "11101" ], 2194 [ "4h", "11101" ],
2196 [ "5s", "101011" ], 2195 [ "5s", "101011" ],
2197 [ "6c", "101" ], 2196 [ "6c", "00101" ],
2198 [ "7d", "10011" ], 2197 [ "7d", "10011" ],
2199 [ "8h", "100001" ], 2198 [ "8h", "100001" ],
2200 [ "9s", "101111" ], 2199 [ "9s", "101111" ],
2201 [ "tc", "1001" ], 2200 [ "tc", "01001" ],
2202 [ "jd", "10111" ], 2201 [ "jd", "10111" ],
2203 [ "qh", "100101" ], 2202 [ "qh", "100101" ],
2204 [ "ks", "110011" ], 2203 [ "ks", "110011" ],
@@ -2489,7 +2488,7 @@ page.open(url, function(status) {
2489 [ "7", "3" ], // 7 in base 10 is 111 in base 2, no leading zeros 2488 [ "7", "3" ], // 7 in base 10 is 111 in base 2, no leading zeros
2490 [ "8", "4" ], 2489 [ "8", "4" ],
2491 [ "F", "4" ], 2490 [ "F", "4" ],
2492 [ "29", "5" ], 2491 [ "29", "6" ],
2493 [ "0A", "8" ], 2492 [ "0A", "8" ],
2494 [ "1A", "8" ], // hex is always multiple of 4 bits of entropy 2493 [ "1A", "8" ], // hex is always multiple of 4 bits of entropy
2495 [ "2A", "8" ], 2494 [ "2A", "8" ],
@@ -2499,9 +2498,10 @@ page.open(url, function(status) {
2499 [ "000A", "16" ], 2498 [ "000A", "16" ],
2500 [ "5555", "11" ], 2499 [ "5555", "11" ],
2501 [ "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) 2500 [ "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)
2502 [ "2227", "12" ], 2501 [ "2227", "13" ], // Uses base 10, which is 4 lots of 3.32 bits, which is 13.3 bits (rounded down to 13)
2503 [ "222F", "16" ], 2502 [ "222F", "16" ],
2504 [ "FFFF", "16" ], 2503 [ "FFFF", "16" ],
2504 [ "0000101017", "33" ], // 10 events at 3.32 bits per event
2505 ] 2505 ]
2506 // use entropy 2506 // use entropy
2507 page.evaluate(function(e) { 2507 page.evaluate(function(e) {
@@ -2518,11 +2518,10 @@ page.open(url, function(status) {
2518 // check the number of bits of entropy is shown 2518 // check the number of bits of entropy is shown
2519 waitForEntropyFeedback(function() { 2519 waitForEntropyFeedback(function() {
2520 var entropyText = page.evaluate(function() { 2520 var entropyText = page.evaluate(function() {
2521 return $(".entropy-error").text(); 2521 return $(".entropy-feedback").text();
2522 }); 2522 });
2523 if (entropyText.indexOf("Have " + expected + " bits of entropy") == -1) { 2523 if (entropyText.replace(/\s/g,"").indexOf("Bits" + expected) == -1) {
2524 console.log("Accumulated entropy is not shown correctly for " + entropy); 2524 console.log("Accumulated entropy is not shown correctly for " + entropy);
2525 console.log(entropyText);
2526 fail(); 2525 fail();
2527 } 2526 }
2528 var isLastTest = i == tests.length - 1; 2527 var isLastTest = i == tests.length - 1;
@@ -2538,28 +2537,6 @@ page.open(url, function(status) {
2538}); 2537});
2539}, 2538},
2540 2539
2541// The number of bits of entropy to reach the next mnemonic strength is shown
2542function() {
2543page.open(url, function(status) {
2544 // use entropy
2545 page.evaluate(function() {
2546 $(".use-entropy").prop("checked", true).trigger("change");
2547 $(".entropy").val("7654321").trigger("input");
2548 });
2549 // check the amount of additional entropy required is shown
2550 waitForEntropyFeedback(function() {
2551 var entropyText = page.evaluate(function() {
2552 return $(".entropy-container").text();
2553 });
2554 if (entropyText.indexOf("3 more base 10 chars required") == -1) {
2555 console.log("Additional entropy requirement is not shown");
2556 fail();
2557 }
2558 next();
2559 });
2560});
2561},
2562
2563// The next strength above 0-word mnemonics is considered extremely weak 2540// The next strength above 0-word mnemonics is considered extremely weak
2564// The next strength above 3-word mnemonics is considered very weak 2541// The next strength above 3-word mnemonics is considered very weak
2565// The next strength above 6-word mnemonics is considered weak 2542// The next strength above 6-word mnemonics is considered weak
@@ -2572,37 +2549,42 @@ page.open(url, function(status) {
2572 { 2549 {
2573 entropy: "A", 2550 entropy: "A",
2574 words: 0, 2551 words: 0,
2575 nextStrength: "an extremely weak", 2552 strength: "extremely weak",
2576 }, 2553 },
2577 { 2554 {
2578 entropy: "AAAAAAAA", 2555 entropy: "AAAAAAAA",
2579 words: 3, 2556 words: 3,
2580 nextStrength: "a very weak", 2557 strength: "extremely weak",
2581 }, 2558 },
2582 { 2559 {
2583 entropy: "AAAAAAAA B", 2560 entropy: "AAAAAAAA B",
2584 words: 3, 2561 words: 3,
2585 nextStrength: "a very weak", 2562 strength: "extremely weak",
2586 }, 2563 },
2587 { 2564 {
2588 entropy: "AAAAAAAA BBBBBBBB", 2565 entropy: "AAAAAAAA BBBBBBBB",
2589 words: 6, 2566 words: 6,
2590 nextStrength: "a weak", 2567 strength: "very weak",
2591 }, 2568 },
2592 { 2569 {
2593 entropy: "AAAAAAAA BBBBBBBB CCCCCCCC", 2570 entropy: "AAAAAAAA BBBBBBBB CCCCCCCC",
2594 words: 9, 2571 words: 9,
2595 nextStrength: "a strong", 2572 strength: "weak",
2596 }, 2573 },
2597 { 2574 {
2598 entropy: "AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD", 2575 entropy: "AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD",
2599 words: 12, 2576 words: 12,
2600 nextStrength: "a very strong", 2577 strength: "strong",
2601 }, 2578 },
2602 { 2579 {
2603 entropy: "AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD EEEEEEEE", 2580 entropy: "AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD EEEEEEEE",
2604 words: 15, 2581 words: 15,
2605 nextStrength: "an extremely strong", 2582 strength: "very strong",
2583 },
2584 {
2585 entropy: "AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD EEEEEEEE FFFFFFFF",
2586 words: 18,
2587 strength: "extremely strong",
2606 } 2588 }
2607 ]; 2589 ];
2608 // use entropy 2590 // use entropy
@@ -2621,7 +2603,7 @@ page.open(url, function(status) {
2621 return $(".phrase").val(); 2603 return $(".phrase").val();
2622 }); 2604 });
2623 if (mnemonic.length > 0) { 2605 if (mnemonic.length > 0) {
2624 console.log("Mnemonic length for " + test.nextStrength + " strength is not " + test.words); 2606 console.log("Mnemonic length for " + test.strength + " strength is not " + test.words);
2625 console.log("Mnemonic: " + mnemonic); 2607 console.log("Mnemonic: " + mnemonic);
2626 fail(); 2608 fail();
2627 } 2609 }
@@ -2635,21 +2617,21 @@ page.open(url, function(status) {
2635 } 2617 }
2636 else { 2618 else {
2637 waitForGenerate(function() { 2619 waitForGenerate(function() {
2638 // check the strength of the current mnemonic 2620 // check the number of words in the current mnemonic
2639 var mnemonic = page.evaluate(function() { 2621 var mnemonic = page.evaluate(function() {
2640 return $(".phrase").val(); 2622 return $(".phrase").val();
2641 }); 2623 });
2642 if (mnemonic.split(" ").length != test.words) { 2624 if (mnemonic.split(" ").length != test.words) {
2643 console.log("Mnemonic length for " + test.nextStrength + " strength is not " + test.words); 2625 console.log("Mnemonic length for " + test.strength + " strength is not " + test.words);
2644 console.log("Mnemonic: " + mnemonic); 2626 console.log("Mnemonic: " + mnemonic);
2645 fail(); 2627 fail();
2646 } 2628 }
2647 // check the strength of the next mnemonic is shown 2629 // check the strength of the mnemonic is shown
2648 var entropyText = page.evaluate(function() { 2630 var entropyText = page.evaluate(function() {
2649 return $(".entropy-container").text(); 2631 return $(".entropy-container").text();
2650 }); 2632 });
2651 if (entropyText.indexOf("required to generate " + test.nextStrength + " mnemonic") == -1) { 2633 if (entropyText.indexOf(test.strength) == -1) {
2652 console.log("Strength indicator for " + test.nextStrength + " mnemonic is incorrect"); 2634 console.log("Strength indicator for " + test.strength + " mnemonic is incorrect");
2653 fail(); 2635 fail();
2654 } 2636 }
2655 var isLastTest = i == tests.length - 1; 2637 var isLastTest = i == tests.length - 1;