X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests.js;h=13f2c76d4271e1fc28321609b8d3e022560fffc9;hb=bbc29c80f429d7493fdb9cb7987000d633734db5;hp=37a758f4f1e8626a11bcbf9301f88ef06ca01915;hpb=3599674db4855614d9123f2f80dcf0a37c34eb79;p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FBIP39.git diff --git a/tests.js b/tests.js index 37a758f..13f2c76 100644 --- a/tests.js +++ b/tests.js @@ -4,7 +4,7 @@ var page = require('webpage').create(); var url = 'src/index.html'; -var testMaxTime = 5000; +var testMaxTime = 10000; page.onResourceError = function(e) { console.log("Error loading " + e.url); @@ -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 +2791,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 +2856,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) {