X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests.js;h=d5a73f6cee83cf1939b08ddfea962184b6952e2d;hb=c554e6ff5c2c543997841c0fb0a506262843e8df;hp=12a6c5bf398de5d2d8360b9a92d10ba0d4d8097e;hpb=3f1faa4d0e0212b1bc26f2ac8e5f0c486ccc1858;p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FBIP39.git diff --git a/tests.js b/tests.js index 12a6c5b..d5a73f6 100644 --- a/tests.js +++ b/tests.js @@ -4,7 +4,12 @@ var page = require('webpage').create(); var url = 'src/index.html'; -var testMaxTime = 5000; +var testMaxTime = 10000; + +page.viewportSize = { + width: 1024, + height: 720 +}; page.onResourceError = function(e) { console.log("Error loading " + e.url); @@ -44,6 +49,67 @@ function waitForGenerate(fn, maxTime) { wait(); } +function waitForFeedback(fn, maxTime) { + if (!maxTime) { + maxTime = testMaxTime; + } + var start = new Date().getTime(); + var wait = function keepWaiting() { + var now = new Date().getTime(); + var hasTimedOut = now - start > maxTime; + if (hasTimedOut) { + console.log("Test timed out"); + fn(); + return; + } + var feedback = page.evaluate(function() { + var feedback = $(".feedback"); + if (feedback.css("display") == "none") { + return ""; + } + return feedback.text(); + }); + var hasFinished = feedback.length > 0 && feedback != "Calculating..."; + if (hasFinished) { + fn(); + } + else { + setTimeout(keepWaiting, 100); + } + } + wait(); +} + +function waitForEntropyFeedback(fn, maxTime) { + if (!maxTime) { + maxTime = testMaxTime; + } + var origFeedback = page.evaluate(function() { + return $(".entropy-container").text(); + }); + var start = new Date().getTime(); + var wait = function keepWaiting() { + var now = new Date().getTime(); + var hasTimedOut = now - start > maxTime; + if (hasTimedOut) { + console.log("Test timed out"); + fn(); + return; + } + var feedback = page.evaluate(function() { + return $(".entropy-container").text(); + }); + var hasFinished = feedback != origFeedback; + if (hasFinished) { + fn(); + } + else { + setTimeout(keepWaiting, 100); + } + } + wait(); +} + function next() { if (tests.length > 0) { var testsStr = tests.length == 1 ? "test" : "tests"; @@ -485,6 +551,62 @@ page.open(url, function(status) { }); }, +// Network can be set to namecoin +function() { +page.open(url, function(status) { + // set the phrase and coin + var expected = "Mw2vK2Bvex1yYtYF6sfbEg2YGoUc98YUD2"; + page.evaluate(function() { + $(".phrase").val("abandon abandon ability"); + $(".phrase").trigger("input"); + $(".network option[selected]").removeAttr("selected"); + $(".network option[value=11]").prop("selected", true); + $(".network").trigger("change"); + }); + // check the address is generated correctly + waitForGenerate(function() { + var actual = page.evaluate(function() { + return $(".address:first").text(); + }); + if (actual != expected) { + console.log("Namecoin address is incorrect"); + console.log("Expected: " + expected); + console.log("Actual: " + actual); + fail(); + } + next(); + }); +}); +}, + +// Network can be set to peercoin +function() { +page.open(url, function(status) { + // set the phrase and coin + var expected = "PVAiioTaK2eDHSEo3tppT9AVdBYqxRTBAm"; + page.evaluate(function() { + $(".phrase").val("abandon abandon ability"); + $(".phrase").trigger("input"); + $(".network option[selected]").removeAttr("selected"); + $(".network option[value=12]").prop("selected", true); + $(".network").trigger("change"); + }); + // check the address is generated correctly + waitForGenerate(function() { + var actual = page.evaluate(function() { + return $(".address:first").text(); + }); + if (actual != expected) { + console.log("Peercoin address is incorrect"); + console.log("Expected: " + expected); + console.log("Actual: " + actual); + fail(); + } + next(); + }); +}); +}, + // BIP39 seed is set from phrase function() { page.open(url, function(status) { @@ -978,7 +1100,6 @@ page.open(url, function(status) { $(".phrase").val("abandon abandon ability"); $(".phrase").trigger("input"); }); - // check the path is not shown waitForGenerate(function() { // toggle path visibility page.evaluate(function() { @@ -1053,39 +1174,2001 @@ page.open(url, function(status) { }); }); }, -// Address visibility can be toggled -// Private key is shown -// Private key visibility can be toggled -// More addresses can be generated -// A custom number of additional addresses can be generated -// Additional addresses are shown in order of derivation path +// Address visibility can be toggled +function() { +page.open(url, function(status) { + // set the phrase + page.evaluate(function() { + $(".phrase").val("abandon abandon ability"); + $(".phrase").trigger("input"); + }); + waitForGenerate(function() { + // toggle address visibility + page.evaluate(function() { + $(".address-toggle").click(); + }); + // check the address is not visible + var isInvisible = page.evaluate(function() { + return $(".address:first span").hasClass("invisible"); + }); + if (!isInvisible) { + console.log("Toggled address is visible"); + fail(); + } + next(); + }); +}); +}, -// BIP32 root key can be set by the user -// Setting BIP32 root key clears the existing phrase, passphrase and seed -// Clearing of phrase, passphrase and seed can be cancelled by user -// Custom BIP32 root key is used when changing the derivation path +// Public key is shown +function() { +page.open(url, function(status) { + var expected = "033f5aed5f6cfbafaf223188095b5980814897295f723815fea5d3f4b648d0d0b3"; + // set the phrase + page.evaluate(function() { + $(".phrase").val("abandon abandon ability").trigger("input"); + }); + // get the address + waitForGenerate(function() { + var actual = page.evaluate(function() { + return $(".pubkey:first").text(); + }); + if (actual != expected) { + console.log("Public key is not shown"); + console.log("Expected: " + expected); + console.log("Got: " + actual); + fail(); + } + next(); + }); +}); +}, -// Incorrect mnemonic shows error -// Incorrect word shows suggested replacement -// Incorrect BIP32 root key shows error -// Derivation path not starting with m shows error -// Derivation path containing invalid characters shows useful error +// Public key visibility can be toggled +function() { +page.open(url, function(status) { + // set the phrase + page.evaluate(function() { + $(".phrase").val("abandon abandon ability"); + $(".phrase").trigger("input"); + }); + waitForGenerate(function() { + // toggle public key visibility + page.evaluate(function() { + $(".public-key-toggle").click(); + }); + // check the public key is not visible + var isInvisible = page.evaluate(function() { + return $(".pubkey:first span").hasClass("invisible"); + }); + if (!isInvisible) { + console.log("Toggled public key is visible"); + fail(); + } + next(); + }); +}); +}, -// Github Issue 11: Default word length is 15 -// https://github.com/dcpos/bip39/issues/11 +// Private key is shown +function() { +page.open(url, function(status) { + var expected = "L26cVSpWFkJ6aQkPkKmTzLqTdLJ923e6CzrVh9cmx21QHsoUmrEE"; + // set the phrase + page.evaluate(function() { + $(".phrase").val("abandon abandon ability").trigger("input"); + }); + // get the address + waitForGenerate(function() { + var actual = page.evaluate(function() { + return $(".privkey:first").text(); + }); + if (actual != expected) { + console.log("Private key is not shown"); + console.log("Expected: " + expected); + console.log("Got: " + actual); + fail(); + } + next(); + }); +}); +}, -// Github Issue 12: Generate more rows with private keys hidden -// https://github.com/dcpos/bip39/issues/12 +// Private key visibility can be toggled +function() { +page.open(url, function(status) { + // set the phrase + page.evaluate(function() { + $(".phrase").val("abandon abandon ability"); + $(".phrase").trigger("input"); + }); + waitForGenerate(function() { + // toggle private key visibility + page.evaluate(function() { + $(".private-key-toggle").click(); + }); + // check the private key is not visible + var isInvisible = page.evaluate(function() { + return $(".privkey:first span").hasClass("invisible"); + }); + if (!isInvisible) { + console.log("Toggled private key is visible"); + fail(); + } + next(); + }); +}); +}, -// Github Issue 19: Mnemonic is not sensitive to whitespace -// https://github.com/dcpos/bip39/issues/19 +// More addresses can be generated +function() { +page.open(url, function(status) { + // set the phrase + page.evaluate(function() { + $(".phrase").val("abandon abandon ability"); + $(".phrase").trigger("input"); + }); + waitForGenerate(function() { + // generate more addresses + page.evaluate(function() { + $(".more").click(); + }); + waitForGenerate(function() { + // check there are more addresses + var addressCount = page.evaluate(function() { + return $(".address").length; + }); + if (addressCount != 40) { + console.log("More addresses cannot be generated"); + fail(); + } + next(); + }); + }); +}); +}, -// Github Issue 23: Use correct derivation path when changing tabs -// https://github.com/dcpos/bip39/issues/23 +// A custom number of additional addresses can be generated +function() { +page.open(url, function(status) { + // set the phrase + page.evaluate(function() { + $(".phrase").val("abandon abandon ability"); + $(".phrase").trigger("input"); + }); + waitForGenerate(function() { + // get the current number of addresses + var oldAddressCount = page.evaluate(function() { + return $(".address").length; + }); + // set a custom number of additional addresses + page.evaluate(function() { + $(".rows-to-add").val(1); + }); + // generate more addresses + page.evaluate(function() { + $(".more").click(); + }); + waitForGenerate(function() { + // check there are the correct number of addresses + var newAddressCount = page.evaluate(function() { + return $(".address").length; + }); + if (newAddressCount - oldAddressCount != 1) { + console.log("Number of additional addresses cannot be customized"); + console.log(newAddressCount) + console.log(oldAddressCount) + fail(); + } + next(); + }); + }); +}); +}, -// Github Issue 26: When using a Root key derrived altcoins are incorrect -// https://github.com/dcpos/bip39/issues/26 +// Additional addresses are shown in order of derivation path +function() { +page.open(url, function(status) { + // set the phrase + page.evaluate(function() { + $(".phrase").val("abandon abandon ability").trigger("input"); + }); + waitForGenerate(function() { + // generate more addresses + page.evaluate(function() { + $(".more").click(); + }); + // get the derivation paths + waitForGenerate(function() { + var paths = page.evaluate(function() { + return $(".index").map(function(i, e) { + return $(e).text(); + }); + }); + if (paths.length != 40) { + console.log("Total additional paths is less than expected: " + paths.length); + fail(); + } + for (var i=0; i