X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests.js;h=b6713b040e371803fab23cd47b5b555d7750d6db;hb=6c08f364b30e711feac698546041388325a11834;hp=124b6ce685b5cbed506133c6bcce285c7f99eef8;hpb=8a89b9da97e437f9ce9476951896e51a9764800c;p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FBIP39.git diff --git a/tests.js b/tests.js index 124b6ce..b6713b0 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 = 20000; + +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"; @@ -214,7 +280,9 @@ page.open(url, function(status) { $(".phrase").val("abandon abandon ability"); $(".phrase").trigger("input"); $(".network option[selected]").removeAttr("selected"); - $(".network option[value=1]").prop("selected", true); + $(".network option").filter(function() { + return $(this).html() == "BTC - Bitcoin Testnet"; + }).prop("selected", true); $(".network").trigger("change"); }); // check the address is generated correctly @@ -242,7 +310,9 @@ page.open(url, function(status) { $(".phrase").val("abandon abandon ability"); $(".phrase").trigger("input"); $(".network option[selected]").removeAttr("selected"); - $(".network option[value=2]").prop("selected", true); + $(".network option").filter(function() { + return $(this).html() == "LTC - Litecoin"; + }).prop("selected", true); $(".network").trigger("change"); }); // check the address is generated correctly @@ -261,6 +331,36 @@ page.open(url, function(status) { }); }, +// Network can be set to ripple +function() { +page.open(url, function(status) { + // set the phrase and coin + var expected = "rLTFnqbmCVPGx6VfaygdtuKWJgcN4v1zRS"; + page.evaluate(function() { + $(".phrase").val("ill clump only blind unit burden thing track silver cloth review awake useful craft whale all satisfy else trophy sunset walk vanish hope valve"); + $(".phrase").trigger("input"); + $(".network option[selected]").removeAttr("selected"); + $(".network option").filter(function() { + return $(this).html() == "XRP - Ripple"; + }).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("Ripple address is incorrect"); + console.log("Expected: " + expected); + console.log("Actual: " + actual); + fail(); + } + next(); + }); +}); +}, + // Network can be set to dogecoin function() { page.open(url, function(status) { @@ -270,7 +370,9 @@ page.open(url, function(status) { $(".phrase").val("abandon abandon ability"); $(".phrase").trigger("input"); $(".network option[selected]").removeAttr("selected"); - $(".network option[value=3]").prop("selected", true); + $(".network option").filter(function() { + return $(this).html() == "DOGE - Dogecoin"; + }).prop("selected", true); $(".network").trigger("change"); }); // check the address is generated correctly @@ -298,7 +400,9 @@ page.open(url, function(status) { $(".phrase").val("abandon abandon ability"); $(".phrase").trigger("input"); $(".network option[selected]").removeAttr("selected"); - $(".network option[value=4]").prop("selected", true); + $(".network option").filter(function() { + return $(this).html() == "SDC - ShadowCash"; + }).prop("selected", true); $(".network").trigger("change"); }); // check the address is generated correctly @@ -326,7 +430,9 @@ page.open(url, function(status) { $(".phrase").val("abandon abandon ability"); $(".phrase").trigger("input"); $(".network option[selected]").removeAttr("selected"); - $(".network option[value=5]").prop("selected", true); + $(".network option").filter(function() { + return $(this).html() == "SDC - ShadowCash Testnet"; + }).prop("selected", true); $(".network").trigger("change"); }); // check the address is generated correctly @@ -354,7 +460,9 @@ page.open(url, function(status) { $(".phrase").val("abandon abandon ability"); $(".phrase").trigger("input"); $(".network option[selected]").removeAttr("selected"); - $(".network option[value=6]").prop("selected", true); + $(".network option").filter(function() { + return $(this).html() == "VIA - Viacoin"; + }).prop("selected", true); $(".network").trigger("change"); }); // check the address is generated correctly @@ -382,7 +490,9 @@ page.open(url, function(status) { $(".phrase").val("abandon abandon ability"); $(".phrase").trigger("input"); $(".network option[selected]").removeAttr("selected"); - $(".network option[value=7]").prop("selected", true); + $(".network option").filter(function() { + return $(this).html() == "VIA - Viacoin Testnet"; + }).prop("selected", true); $(".network").trigger("change"); }); // check the address is generated correctly @@ -410,7 +520,9 @@ page.open(url, function(status) { $(".phrase").val("abandon abandon ability"); $(".phrase").trigger("input"); $(".network option[selected]").removeAttr("selected"); - $(".network option[value=8]").prop("selected", true); + $(".network option").filter(function() { + return $(this).html() == "JBS - Jumbucks"; + }).prop("selected", true); $(".network").trigger("change"); }); // check the address is generated correctly @@ -438,7 +550,9 @@ page.open(url, function(status) { $(".phrase").val("abandon abandon ability"); $(".phrase").trigger("input"); $(".network option[selected]").removeAttr("selected"); - $(".network option[value=9]").prop("selected", true); + $(".network option").filter(function() { + return $(this).html() == "CLAM - Clams"; + }).prop("selected", true); $(".network").trigger("change"); }); // check the address is generated correctly @@ -457,6 +571,36 @@ page.open(url, function(status) { }); }, +// Network can be set to crown +function() { +page.open(url, function(status) { + // set the phrase and coin + var expected = "18pWSwSUAQdiwMHUfFZB1fM2xue9X1FqE5"; + page.evaluate(function() { + $(".phrase").val("abandon abandon ability"); + $(".phrase").trigger("input"); + $(".network option[selected]").removeAttr("selected"); + $(".network option").filter(function() { + return $(this).html() == "CRW - Crown"; + }).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("CRW address is incorrect"); + console.log("Expected: " + expected); + console.log("Actual: " + actual); + fail(); + } + next(); + }); +}); +}, + // Network can be set to dash function() { page.open(url, function(status) { @@ -466,7 +610,9 @@ page.open(url, function(status) { $(".phrase").val("abandon abandon ability"); $(".phrase").trigger("input"); $(".network option[selected]").removeAttr("selected"); - $(".network option[value=10]").prop("selected", true); + $(".network option").filter(function() { + return $(this).html() == "DASH - Dash"; + }).prop("selected", true); $(".network").trigger("change"); }); // check the address is generated correctly @@ -485,6 +631,65 @@ page.open(url, function(status) { }); }, +function() { +page.open(url, function(status) { + // set the phrase and coin + var expected = "yaR52EN4oojdJfBgzWJTymC4uuCLPT29Gw"; + page.evaluate(function() { + $(".phrase").val("abandon abandon ability"); + $(".phrase").trigger("input"); + $(".network option[selected]").removeAttr("selected"); + $(".network option").filter(function() { + return $(this).html() == "DASH - Dash Testnet"; + }).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("DASH Testnet address is incorrect"); + console.log("Expected: " + expected); + console.log("Actual: " + actual); + fail(); + } + next(); + }); +}); +}, + +// Network can be set to game +function() { +page.open(url, function(status) { + // set the phrase and coin + var expected = "GSMY9bAp36cMR4zyT4uGVS7GFjpdXbao5Q"; + page.evaluate(function() { + $(".phrase").val("abandon abandon ability"); + $(".phrase").trigger("input"); + $(".network option[selected]").removeAttr("selected"); + $(".network option").filter(function() { + return $(this).html() == "GAME - GameCredits"; + }).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("GAME address is incorrect"); + console.log("Expected: " + expected); + console.log("Actual: " + actual); + fail(); + } + next(); + }); +}); +}, + // Network can be set to namecoin function() { page.open(url, function(status) { @@ -494,7 +699,9 @@ page.open(url, function(status) { $(".phrase").val("abandon abandon ability"); $(".phrase").trigger("input"); $(".network option[selected]").removeAttr("selected"); - $(".network option[value=11]").prop("selected", true); + $(".network option").filter(function() { + return $(this).html() == "NMC - Namecoin"; + }).prop("selected", true); $(".network").trigger("change"); }); // check the address is generated correctly @@ -522,7 +729,9 @@ page.open(url, function(status) { $(".phrase").val("abandon abandon ability"); $(".phrase").trigger("input"); $(".network option[selected]").removeAttr("selected"); - $(".network option[value=12]").prop("selected", true); + $(".network option").filter(function() { + return $(this).html() == "PPC - Peercoin"; + }).prop("selected", true); $(".network").trigger("change"); }); // check the address is generated correctly @@ -541,6 +750,128 @@ page.open(url, function(status) { }); }, +// Network can be set to ethereum +function() { + +page.open(url, function(status) { + + // set the phrase and coin + page.evaluate(function() { + $(".phrase").val("abandon abandon ability"); + $(".phrase").trigger("input"); + $(".network option[selected]").removeAttr("selected"); + $(".network option").filter(function() { + return $(this).html() == "ETH - Ethereum"; + }).prop("selected", true); + $(".network").trigger("change"); + }); + waitForGenerate(function() { + // check the address is generated correctly + // this value comes from + // https://www.myetherwallet.com/#view-wallet-info + // Unusual capitalization is due to checksum + var expected = "0xe5815d5902Ad612d49283DEdEc02100Bd44C2772"; + var actual = page.evaluate(function() { + return $(".address:first").text(); + }); + if (actual != expected) { + console.log("Ethereum address is incorrect"); + console.log("Expected: " + expected); + console.log("Actual: " + actual); + fail(); + } + // check the private key is correct + // this private key can be imported into + // https://www.myetherwallet.com/#view-wallet-info + // and it should correlate to the address above + var expected = "0x8f253078b73d7498302bb78c171b23ce7a8fb511987d2b2702b731638a4a15e7"; + var actual = page.evaluate(function() { + return $(".privkey:first").text(); + }); + if (actual != expected) { + console.log("Ethereum privkey is incorrect"); + console.log("Expected: " + expected); + console.log("Actual: " + actual); + fail(); + } + // check the public key is correct + // TODO + // don't have any third-party source to generate the expected value + //var expected = "?"; + //var actual = page.evaluate(function() { + // return $(".pubkey:first").text(); + //}); + //if (actual != expected) { + // console.log("Ethereum privkey is incorrect"); + // console.log("Expected: " + expected); + // console.log("Actual: " + actual); + // fail(); + //} + next(); + }); +}); +}, + +// Network can be set to Slimcoin +function() { +page.open(url, function(status) { + // set the phrase and coin + var expected = "SNzPi1CafHFm3WWjRo43aMgiaEEj3ogjww"; + page.evaluate(function() { + $(".phrase").val("abandon abandon ability"); + $(".phrase").trigger("input"); + $(".network option[selected]").removeAttr("selected"); + $(".network option").filter(function() { + return $(this).html() == "SLM - Slimcoin"; + }).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("Slimcoin address is incorrect"); + console.log("Expected: " + expected); + console.log("Actual: " + actual); + fail(); + } + next(); + }); +}); +}, + +// Network can be set to Slimcointn +function() { +page.open(url, function(status) { + // set the phrase and coin + var expected = "n3nMgWufTek5QQAr6uwMhg5xbzj8xqc4Dq"; + page.evaluate(function() { + $(".phrase").val("abandon abandon ability"); + $(".phrase").trigger("input"); + $(".network option[selected]").removeAttr("selected"); + $(".network option").filter(function() { + return $(this).html() == "SLM - Slimcoin Testnet"; + }).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("Slimcoin testnet 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) { @@ -697,11 +1028,11 @@ page.open(url, function(status) { }); }, -// BIP44 purpose field changes address list +// BIP44 account field changes address list function() { page.open(url, function(status) { // set the phrase - var expected = "1JbDzRJ2cDT8aat2xwKd6Pb2zzavow5MhF"; + var expected = "1Nq2Wmu726XHCuGhctEtGmhxo3wzk5wZ1H"; page.evaluate(function() { $(".phrase").val("abandon abandon ability"); $(".phrase").trigger("input"); @@ -709,8 +1040,8 @@ page.open(url, function(status) { waitForGenerate(function() { // change the bip44 purpose field to 45 page.evaluate(function() { - $("#bip44 .purpose").val("45"); - $("#bip44 .purpose").trigger("input"); + $("#bip44 .account").val("1"); + $("#bip44 .account").trigger("input"); }); waitForGenerate(function() { // check the address for the new derivation path @@ -718,7 +1049,7 @@ page.open(url, function(status) { return $(".address:first").text(); }); if (actual != expected) { - console.log("BIP44 purpose field generates incorrect address"); + console.log("BIP44 account field generates incorrect address"); console.log("Expected: " + expected); console.log("Actual: " + actual); fail(); @@ -729,11 +1060,11 @@ page.open(url, function(status) { }); }, -// BIP44 coin field changes address list +// BIP44 change field changes address list function() { page.open(url, function(status) { // set the phrase - var expected = "1F6dB2djQYrxoyfZZmfr6D5voH8GkJTghk"; + var expected = "1KAGfWgqfVbSSXY56fNQ7YnhyKuoskHtYo"; page.evaluate(function() { $(".phrase").val("abandon abandon ability"); $(".phrase").trigger("input"); @@ -741,8 +1072,8 @@ page.open(url, function(status) { waitForGenerate(function() { // change the bip44 purpose field to 45 page.evaluate(function() { - $("#bip44 .coin").val("1"); - $("#bip44 .coin").trigger("input"); + $("#bip44 .change").val("1"); + $("#bip44 .change").trigger("input"); }); waitForGenerate(function() { // check the address for the new derivation path @@ -750,7 +1081,7 @@ page.open(url, function(status) { return $(".address:first").text(); }); if (actual != expected) { - console.log("BIP44 coin field generates incorrect address"); + console.log("BIP44 change field generates incorrect address"); console.log("Expected: " + expected); console.log("Actual: " + actual); fail(); @@ -761,89 +1092,25 @@ page.open(url, function(status) { }); }, -// BIP44 account field changes address list +// BIP32 derivation path can be set function() { page.open(url, function(status) { // set the phrase - var expected = "1Nq2Wmu726XHCuGhctEtGmhxo3wzk5wZ1H"; + var expected = "16pYQQdLD1hH4hwTGLXBaZ9Teboi1AGL8L"; page.evaluate(function() { $(".phrase").val("abandon abandon ability"); $(".phrase").trigger("input"); }); + // change tabs waitForGenerate(function() { - // change the bip44 purpose field to 45 page.evaluate(function() { - $("#bip44 .account").val("1"); - $("#bip44 .account").trigger("input"); + $("#bip32-tab a").click(); }); + // set the derivation path to m/1 waitForGenerate(function() { - // check the address for the new derivation path - var actual = page.evaluate(function() { - return $(".address:first").text(); - }); - if (actual != expected) { - console.log("BIP44 account field generates incorrect address"); - console.log("Expected: " + expected); - console.log("Actual: " + actual); - fail(); - } - next(); - }); - }); -}); -}, - -// BIP44 change field changes address list -function() { -page.open(url, function(status) { - // set the phrase - var expected = "1KAGfWgqfVbSSXY56fNQ7YnhyKuoskHtYo"; - page.evaluate(function() { - $(".phrase").val("abandon abandon ability"); - $(".phrase").trigger("input"); - }); - waitForGenerate(function() { - // change the bip44 purpose field to 45 - page.evaluate(function() { - $("#bip44 .change").val("1"); - $("#bip44 .change").trigger("input"); - }); - waitForGenerate(function() { - // check the address for the new derivation path - var actual = page.evaluate(function() { - return $(".address:first").text(); - }); - if (actual != expected) { - console.log("BIP44 change field generates incorrect address"); - console.log("Expected: " + expected); - console.log("Actual: " + actual); - fail(); - } - next(); - }); - }); -}); -}, - -// BIP32 derivation path can be set -function() { -page.open(url, function(status) { - // set the phrase - var expected = "16pYQQdLD1hH4hwTGLXBaZ9Teboi1AGL8L"; - page.evaluate(function() { - $(".phrase").val("abandon abandon ability"); - $(".phrase").trigger("input"); - }); - // change tabs - waitForGenerate(function() { - page.evaluate(function() { - $("#bip32-tab a").click(); - }); - // set the derivation path to m/1 - waitForGenerate(function() { - page.evaluate(function() { - $("#bip32 .path").val("m/1"); - $("#bip32 .path").trigger("input"); + page.evaluate(function() { + $("#bip32 .path").val("m/1"); + $("#bip32 .path").trigger("input"); }); // check the address is generated correctly waitForGenerate(function() { @@ -1135,6 +1402,56 @@ page.open(url, function(status) { }); }, +// 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(); + }); +}); +}, + +// 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(); + }); +}); +}, + // Private key is shown function() { page.open(url, function(status) { @@ -1252,32 +1569,2467 @@ page.open(url, function(status) { }, // 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