X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests.js;h=1b1d44577a91b01e8addb301c54b707c594610c8;hb=9bc39377aa0317ffbfed3b6e29814bb26681cfd5;hp=420873dc11bd2a126df003b5f15d62a08f6734aa;hpb=1cf1bbaff575e647ef38b091a00edfa2e1ce024d;p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FBIP39.git diff --git a/tests.js b/tests.js index 420873d..1b1d445 100644 --- a/tests.js +++ b/tests.js @@ -80,7 +80,7 @@ function waitForEntropyFeedback(fn, maxTime) { maxTime = testMaxTime; } var origFeedback = page.evaluate(function() { - return $(".entropy-feedback").text(); + return $(".entropy-container").text(); }); var start = new Date().getTime(); var wait = function keepWaiting() { @@ -92,7 +92,7 @@ function waitForEntropyFeedback(fn, maxTime) { return; } var feedback = page.evaluate(function() { - return $(".entropy-feedback").text(); + return $(".entropy-container").text(); }); var hasFinished = feedback != origFeedback; if (hasFinished) { @@ -2304,6 +2304,7 @@ page.open(url, function(status) { "dice", "base 10", "hexadecimal", + "cards", ]; for (var i=0; i 0) { - console.log("Mnemonic length for " + test.strength + " strength is not " + test.words); - console.log("Mnemonic: " + mnemonic); + // Check mnemonic length + if (test.words == 0) { + if (mnemonic.length > 0) { + console.log("Mnemonic length for " + test.strength + " strength is not " + test.words); + console.log("Mnemonic: " + mnemonic); + fail(); + } + } + else { + if (mnemonic.split(" ").length != test.words) { + console.log("Mnemonic length for " + test.strength + " strength is not " + test.words); + console.log("Mnemonic: " + mnemonic); + fail(); + } + } + // check feedback + var feedback = page.evaluate(function() { + return $(".entropy-container").text(); + }); + var feedbackError = getFeedbackError(test, feedback); + if (feedbackError) { + console.log("Entropy feedback for " + test.entropy + " returned error"); + console.log(feedbackError); fail(); } + // Run next test var isLastTest = i == tests.length - 1; if (isLastTest) { next(); @@ -2614,49 +2740,21 @@ page.open(url, function(status) { else { runNextTest(i+1); } - } - else { - waitForGenerate(function() { - // check the number of words in the current mnemonic - var mnemonic = page.evaluate(function() { - return $(".phrase").val(); - }); - if (mnemonic.split(" ").length != test.words) { - console.log("Mnemonic length for " + test.strength + " strength is not " + test.words); - console.log("Mnemonic: " + mnemonic); - fail(); - } - // check the strength of the mnemonic is shown - var entropyText = page.evaluate(function() { - return $(".entropy-container").text(); - }); - if (entropyText.indexOf(test.strength) == -1) { - console.log("Strength indicator for " + test.strength + " mnemonic is incorrect"); - fail(); - } - var isLastTest = i == tests.length - 1; - if (isLastTest) { - next(); - } - else { - runNextTest(i+1); - } - }); - } + }); } nextTest(0); }); }, -// Entropy is truncated from the right +// Entropy is truncated from the left function() { page.open(url, function(status) { - var expected = "abandon abandon ability"; + var expected = "avocado zoo zone"; // use entropy page.evaluate(function() { $(".use-entropy").prop("checked", true).trigger("change"); var entropy = "00000000 00000000 00000000 00000000"; - entropy += "11111111 11111111 11111111 1111"; // Missing last byte, only first 8 bytes are used + entropy += "11111111 11111111 11111111 1111"; // Missing last byte $(".entropy").val(entropy).trigger("input"); }); // check the entropy is truncated from the right @@ -2707,8 +2805,6 @@ page.open(url, function(status) { // https://bip32jp.github.io/english/index.html // NOTES: // Is incompatible with: -// base 6 with leading zeros -// base 6 wth 12 words / 53 chars // base 20 function() { page.open(url, function(status) { @@ -2774,6 +2870,31 @@ page.open(url, function(status) { }); }, +// Mnemonic length can be selected even for weak entropy +function() { +page.open(url, function(status) { + // use entropy + page.evaluate(function() { + $(".use-entropy").prop("checked", true).trigger("change"); + $(".entropy").val("012345"); + $(".mnemonic-length").val("18").trigger("change"); + }); + // check the mnemonic is the correct length + waitForGenerate(function() { + var phrase = page.evaluate(function() { + return $(".phrase").val(); + }); + var numberOfWords = phrase.split(/\s/g).length; + if (numberOfWords != 18) { + console.log("Weak entropy cannot be overridden to give 18 word mnemonic"); + console.log(phrase); + fail(); + } + next(); + }); +}); +}, + // If you wish to add more tests, do so here... // Here is a blank test template