X-Git-Url: https://git.immae.eu/?p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FBIP39.git;a=blobdiff_plain;f=tests.js;h=8965f80a8d3935ad0da5bfb333dc77eec6c2327e;hp=0c28ec8a68ff34a08f22233fb33a691b9b335739;hb=d933c3f731ba0f854e07dda73f60c39c70b11526;hpb=3563165943956529b9f35caa005db9f91a3d6c59 diff --git a/tests.js b/tests.js index 0c28ec8..8965f80 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,16 +631,17 @@ 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"; + var expected = "yaR52EN4oojdJfBgzWJTymC4uuCLPT29Gw"; page.evaluate(function() { $(".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() == "DASH - Dash Testnet"; + }).prop("selected", true); $(".network").trigger("change"); }); // check the address is generated correctly @@ -503,7 +650,7 @@ page.open(url, function(status) { return $(".address:first").text(); }); if (actual != expected) { - console.log("Namecoin address is incorrect"); + console.log("DASH Testnet address is incorrect"); console.log("Expected: " + expected); console.log("Actual: " + actual); fail(); @@ -513,16 +660,18 @@ page.open(url, function(status) { }); }, -// Network can be set to peercoin +// Network can be set to game function() { page.open(url, function(status) { // set the phrase and coin - var expected = "PVAiioTaK2eDHSEo3tppT9AVdBYqxRTBAm"; + var expected = "GSMY9bAp36cMR4zyT4uGVS7GFjpdXbao5Q"; page.evaluate(function() { $(".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() == "GAME - GameCredits"; + }).prop("selected", true); $(".network").trigger("change"); }); // check the address is generated correctly @@ -531,7 +680,7 @@ page.open(url, function(status) { return $(".address:first").text(); }); if (actual != expected) { - console.log("Peercoin address is incorrect"); + console.log("GAME address is incorrect"); console.log("Expected: " + expected); console.log("Actual: " + actual); fail(); @@ -541,22 +690,27 @@ page.open(url, function(status) { }); }, -// BIP39 seed is set from phrase +// Network can be set to namecoin function() { page.open(url, function(status) { - // set the phrase - var expected = "20da140d3dd1df8713cefcc4d54ce0e445b4151027a1ab567b832f6da5fcc5afc1c3a3f199ab78b8e0ab4652efd7f414ac2c9a3b81bceb879a70f377aa0a58f3"; + // 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").filter(function() { + return $(this).html() == "NMC - Namecoin"; + }).prop("selected", true); + $(".network").trigger("change"); }); // check the address is generated correctly waitForGenerate(function() { var actual = page.evaluate(function() { - return $(".seed").val(); + return $(".address:first").text(); }); if (actual != expected) { - console.log("BIP39 seed is incorrectly generated from mnemonic"); + console.log("Namecoin address is incorrect"); console.log("Expected: " + expected); console.log("Actual: " + actual); fail(); @@ -566,22 +720,27 @@ page.open(url, function(status) { }); }, -// BIP32 root key is set from phrase +// Network can be set to peercoin function() { page.open(url, function(status) { - // set the phrase - var expected = "xprv9s21ZrQH143K2jkGDCeTLgRewT9F2pH5JZs2zDmmjXes34geVnFiuNa8KTvY5WoYvdn4Ag6oYRoB6cXtc43NgJAEqDXf51xPm6fhiMCKwpi"; + // 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").filter(function() { + return $(this).html() == "PPC - Peercoin"; + }).prop("selected", true); + $(".network").trigger("change"); }); // check the address is generated correctly waitForGenerate(function() { var actual = page.evaluate(function() { - return $(".root-key").val(); + return $(".address:first").text(); }); if (actual != expected) { - console.log("Root key is incorrectly generated from mnemonic"); + console.log("Peercoin address is incorrect"); console.log("Expected: " + expected); console.log("Actual: " + actual); fail(); @@ -591,53 +750,89 @@ page.open(url, function(status) { }); }, -// Tabs show correct addresses when changed +// Network can be set to ethereum function() { + page.open(url, function(status) { - // set the phrase - var expected = "17uQ7s2izWPwBmEVFikTmZUjbBKWYdJchz"; + + // 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"); }); - // change tabs waitForGenerate(function() { - page.evaluate(function() { - $("#bip32-tab a").click(); - }); // check the address is generated correctly - waitForGenerate(function() { - var actual = page.evaluate(function() { - return $(".address:first").text(); - }); - if (actual != expected) { - console.log("Clicking tab generates incorrect address"); - console.log("Expected: " + expected); - console.log("Actual: " + actual); - fail(); - } - next(); + // 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(); }); }); }, -// BIP44 derivation path is shown +// Network can be set to Slimcoin function() { page.open(url, function(status) { - // set the phrase - var expected = "m/44'/0'/0'/0"; + // 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 derivation path of the first address + // check the address is generated correctly waitForGenerate(function() { var actual = page.evaluate(function() { - return $("#bip44 .path").val(); + return $(".address:first").text(); }); if (actual != expected) { - console.log("BIP44 derivation path is incorrect"); + console.log("Slimcoin address is incorrect"); console.log("Expected: " + expected); console.log("Actual: " + actual); fail(); @@ -647,22 +842,27 @@ page.open(url, function(status) { }); }, -// BIP44 extended private key is shown +// Network can be set to Slimcointn function() { page.open(url, function(status) { - // set the phrase - var expected = "xprvA2DxxvPZcyRvYgZMGS53nadR32mVDeCyqQYyFhrCVbJNjPoxMeVf7QT5g7mQASbTf9Kp4cryvcXnu2qurjWKcrdsr91jXymdCDNxKgLFKJG"; + // 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 BIP44 extended private key + // check the address is generated correctly waitForGenerate(function() { var actual = page.evaluate(function() { - return $(".extended-priv-key").val(); + return $(".address:first").text(); }); if (actual != expected) { - console.log("BIP44 extended private key is incorrect"); + console.log("Slimcoin testnet address is incorrect"); console.log("Expected: " + expected); console.log("Actual: " + actual); fail(); @@ -672,22 +872,27 @@ page.open(url, function(status) { }); }, -// BIP44 extended public key is shown +// Network can be set to bitcoin cash function() { page.open(url, function(status) { - // set the phrase - var expected = "xpub6FDKNRvTTLzDmAdpNTc49ia9b4byd6vqCdUa46Fp3vqMcC96uBoufCmZXQLiN5AK3iSCJMhf9gT2sxkpyaPepRuA7W3MujV5tGmF5VfbueM"; + // set the phrase and coin + var expected = "1JKvb6wKtsjNoCRxpZ4DGrbniML7z5U16A"; page.evaluate(function() { $(".phrase").val("abandon abandon ability"); $(".phrase").trigger("input"); + $(".network option[selected]").removeAttr("selected"); + $(".network option").filter(function() { + return $(this).html() == "BCH - Bitcoin Cash"; + }).prop("selected", true); + $(".network").trigger("change"); }); - // check the BIP44 extended public key + // check the address is generated correctly waitForGenerate(function() { var actual = page.evaluate(function() { - return $(".extended-pub-key").val(); + return $(".address:first").text(); }); if (actual != expected) { - console.log("BIP44 extended public key is incorrect"); + console.log("Bitcoin Cash address is incorrect"); console.log("Expected: " + expected); console.log("Actual: " + actual); fail(); @@ -697,81 +902,293 @@ page.open(url, function(status) { }); }, -// BIP44 purpose field changes address list +// Network can be set to myriadcoin function() { page.open(url, function(status) { - // set the phrase - var expected = "1JbDzRJ2cDT8aat2xwKd6Pb2zzavow5MhF"; + // set the phrase and coin + var expected = "MJEswvRR46wh9BoiVj9DzKYMBkCramhoBV"; page.evaluate(function() { $(".phrase").val("abandon abandon ability"); $(".phrase").trigger("input"); + $(".network option[selected]").removeAttr("selected"); + $(".network option").filter(function() { + return $(this).html() == "XMY - Myriadcoin"; + }).prop("selected", true); + $(".network").trigger("change"); }); + // check the address is generated correctly waitForGenerate(function() { - // change the bip44 purpose field to 45 - page.evaluate(function() { - $("#bip44 .purpose").val("45"); - $("#bip44 .purpose").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 purpose field generates incorrect address"); - console.log("Expected: " + expected); - console.log("Actual: " + actual); - fail(); - } - next(); + var actual = page.evaluate(function() { + return $(".address:first").text(); }); + if (actual != expected) { + console.log("Myriadcoin address is incorrect"); + console.log("Expected: " + expected); + console.log("Actual: " + actual); + fail(); + } + next(); }); }); }, -// BIP44 coin field changes address list +// Network can be set to pivx function() { page.open(url, function(status) { - // set the phrase - var expected = "1F6dB2djQYrxoyfZZmfr6D5voH8GkJTghk"; + // set the phrase and coin + var expected = "DBxgT7faCuno7jmtKuu6KWCiwqsVPqh1tS"; page.evaluate(function() { $(".phrase").val("abandon abandon ability"); $(".phrase").trigger("input"); + $(".network option[selected]").removeAttr("selected"); + $(".network option").filter(function() { + return $(this).html() == "PIVX - PIVX"; + }).prop("selected", true); + $(".network").trigger("change"); }); + // check the address is generated correctly waitForGenerate(function() { - // change the bip44 purpose field to 45 - page.evaluate(function() { - $("#bip44 .coin").val("1"); - $("#bip44 .coin").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 coin field generates incorrect address"); - console.log("Expected: " + expected); - console.log("Actual: " + actual); - fail(); - } - next(); + var actual = page.evaluate(function() { + return $(".address:first").text(); }); + if (actual != expected) { + console.log("PIVX address is incorrect"); + console.log("Expected: " + expected); + console.log("Actual: " + actual); + fail(); + } + next(); }); }); }, -// BIP44 account field changes address list +// Network can be set to pivx testnet function() { page.open(url, function(status) { - // set the phrase - var expected = "1Nq2Wmu726XHCuGhctEtGmhxo3wzk5wZ1H"; + // set the phrase and coin + var expected = "yB5U384n6dGkVE3by5y9VdvHHPwPg68fQj"; page.evaluate(function() { $(".phrase").val("abandon abandon ability"); $(".phrase").trigger("input"); + $(".network option[selected]").removeAttr("selected"); + $(".network option").filter(function() { + return $(this).html() == "PIVX - PIVX Testnet"; + }).prop("selected", true); + $(".network").trigger("change"); }); + // check the address is generated correctly waitForGenerate(function() { - // change the bip44 purpose field to 45 + var actual = page.evaluate(function() { + return $(".address:first").text(); + }); + if (actual != expected) { + console.log("PIVX Testnet address is incorrect"); + console.log("Expected: " + expected); + console.log("Actual: " + actual); + fail(); + } + next(); + }); +}); +}, + +// Network can be set to maza +function() { +page.open(url, function(status) { + // set the phrase and coin + var expected = "MGW4Bmi2NEm4PxSjgeFwhP9vg18JHoRnfw"; + page.evaluate(function() { + $(".phrase").val("abandon abandon ability"); + $(".phrase").trigger("input"); + $(".network option[selected]").removeAttr("selected"); + $(".network option").filter(function() { + return $(this).html() == "MAZA - Maza"; + }).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("Maza 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) { + // set the phrase + var expected = "20da140d3dd1df8713cefcc4d54ce0e445b4151027a1ab567b832f6da5fcc5afc1c3a3f199ab78b8e0ab4652efd7f414ac2c9a3b81bceb879a70f377aa0a58f3"; + page.evaluate(function() { + $(".phrase").val("abandon abandon ability"); + $(".phrase").trigger("input"); + }); + // check the address is generated correctly + waitForGenerate(function() { + var actual = page.evaluate(function() { + return $(".seed").val(); + }); + if (actual != expected) { + console.log("BIP39 seed is incorrectly generated from mnemonic"); + console.log("Expected: " + expected); + console.log("Actual: " + actual); + fail(); + } + next(); + }); +}); +}, + +// BIP32 root key is set from phrase +function() { +page.open(url, function(status) { + // set the phrase + var expected = "xprv9s21ZrQH143K2jkGDCeTLgRewT9F2pH5JZs2zDmmjXes34geVnFiuNa8KTvY5WoYvdn4Ag6oYRoB6cXtc43NgJAEqDXf51xPm6fhiMCKwpi"; + page.evaluate(function() { + $(".phrase").val("abandon abandon ability"); + $(".phrase").trigger("input"); + }); + // check the address is generated correctly + waitForGenerate(function() { + var actual = page.evaluate(function() { + return $(".root-key").val(); + }); + if (actual != expected) { + console.log("Root key is incorrectly generated from mnemonic"); + console.log("Expected: " + expected); + console.log("Actual: " + actual); + fail(); + } + next(); + }); +}); +}, + +// Tabs show correct addresses when changed +function() { +page.open(url, function(status) { + // set the phrase + var expected = "17uQ7s2izWPwBmEVFikTmZUjbBKWYdJchz"; + page.evaluate(function() { + $(".phrase").val("abandon abandon ability"); + $(".phrase").trigger("input"); + }); + // change tabs + waitForGenerate(function() { + page.evaluate(function() { + $("#bip32-tab a").click(); + }); + // check the address is generated correctly + waitForGenerate(function() { + var actual = page.evaluate(function() { + return $(".address:first").text(); + }); + if (actual != expected) { + console.log("Clicking tab generates incorrect address"); + console.log("Expected: " + expected); + console.log("Actual: " + actual); + fail(); + } + next(); + }); + }); +}); +}, + +// BIP44 derivation path is shown +function() { +page.open(url, function(status) { + // set the phrase + var expected = "m/44'/0'/0'/0"; + page.evaluate(function() { + $(".phrase").val("abandon abandon ability"); + $(".phrase").trigger("input"); + }); + // check the derivation path of the first address + waitForGenerate(function() { + var actual = page.evaluate(function() { + return $("#bip44 .path").val(); + }); + if (actual != expected) { + console.log("BIP44 derivation path is incorrect"); + console.log("Expected: " + expected); + console.log("Actual: " + actual); + fail(); + } + next(); + }); +}); +}, + +// BIP44 extended private key is shown +function() { +page.open(url, function(status) { + // set the phrase + var expected = "xprvA2DxxvPZcyRvYgZMGS53nadR32mVDeCyqQYyFhrCVbJNjPoxMeVf7QT5g7mQASbTf9Kp4cryvcXnu2qurjWKcrdsr91jXymdCDNxKgLFKJG"; + page.evaluate(function() { + $(".phrase").val("abandon abandon ability"); + $(".phrase").trigger("input"); + }); + // check the BIP44 extended private key + waitForGenerate(function() { + var actual = page.evaluate(function() { + return $(".extended-priv-key").val(); + }); + if (actual != expected) { + console.log("BIP44 extended private key is incorrect"); + console.log("Expected: " + expected); + console.log("Actual: " + actual); + fail(); + } + next(); + }); +}); +}, + +// BIP44 extended public key is shown +function() { +page.open(url, function(status) { + // set the phrase + var expected = "xpub6FDKNRvTTLzDmAdpNTc49ia9b4byd6vqCdUa46Fp3vqMcC96uBoufCmZXQLiN5AK3iSCJMhf9gT2sxkpyaPepRuA7W3MujV5tGmF5VfbueM"; + page.evaluate(function() { + $(".phrase").val("abandon abandon ability"); + $(".phrase").trigger("input"); + }); + // check the BIP44 extended public key + waitForGenerate(function() { + var actual = page.evaluate(function() { + return $(".extended-pub-key").val(); + }); + if (actual != expected) { + console.log("BIP44 extended public key is incorrect"); + console.log("Expected: " + expected); + console.log("Actual: " + actual); + fail(); + } + next(); + }); +}); +}, + +// BIP44 account field changes address list +function() { +page.open(url, function(status) { + // set the phrase + var expected = "1Nq2Wmu726XHCuGhctEtGmhxo3wzk5wZ1H"; + page.evaluate(function() { + $(".phrase").val("abandon abandon ability"); + $(".phrase").trigger("input"); + }); + waitForGenerate(function() { + // change the bip44 purpose field to 45 page.evaluate(function() { $("#bip44 .account").val("1"); $("#bip44 .account").trigger("input"); @@ -1135,6 +1552,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) { @@ -1214,33 +1681,2661 @@ page.open(url, function(status) { }, // A custom number of additional addresses can be generated -// Additional addresses are shown in order of derivation path - -// 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 - -// 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 +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(); + }); + }); +}); +}, + +// 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