X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests.js;h=d55b8f4730379bb34a9591362939427a282266ce;hb=f88fab206fc8fb1f14948def2f882e968a76c1b2;hp=89f4ce367462fdf27dcff025ebebcec295ddc887;hpb=5de5781ad732f71ba62d8a1640eb946e853e3c8a;p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FBIP39.git diff --git a/tests.js b/tests.js index 89f4ce3..d55b8f4 100644 --- a/tests.js +++ b/tests.js @@ -280,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() == "Bitcoin Testnet"; + }).prop("selected", true); $(".network").trigger("change"); }); // check the address is generated correctly @@ -308,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() == "Litecoin"; + }).prop("selected", true); $(".network").trigger("change"); }); // check the address is generated correctly @@ -336,7 +340,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() == "Dogecoin"; + }).prop("selected", true); $(".network").trigger("change"); }); // check the address is generated correctly @@ -364,7 +370,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() == "ShadowCash"; + }).prop("selected", true); $(".network").trigger("change"); }); // check the address is generated correctly @@ -392,7 +400,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() == "ShadowCash Testnet"; + }).prop("selected", true); $(".network").trigger("change"); }); // check the address is generated correctly @@ -420,7 +430,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() == "Viacoin"; + }).prop("selected", true); $(".network").trigger("change"); }); // check the address is generated correctly @@ -448,7 +460,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() == "Viacoin Testnet"; + }).prop("selected", true); $(".network").trigger("change"); }); // check the address is generated correctly @@ -476,7 +490,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() == "Jumbucks"; + }).prop("selected", true); $(".network").trigger("change"); }); // check the address is generated correctly @@ -504,7 +520,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"; + }).prop("selected", true); $(".network").trigger("change"); }); // check the address is generated correctly @@ -532,7 +550,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"; + }).prop("selected", true); $(".network").trigger("change"); }); // check the address is generated correctly @@ -560,7 +580,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() == "Namecoin"; + }).prop("selected", true); $(".network").trigger("change"); }); // check the address is generated correctly @@ -588,7 +610,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() == "Peercoin"; + }).prop("selected", true); $(".network").trigger("change"); }); // check the address is generated correctly @@ -617,7 +641,9 @@ page.open(url, function(status) { $(".phrase").val("abandon abandon ability"); $(".phrase").trigger("input"); $(".network option[selected]").removeAttr("selected"); - $(".network option[value=13]").prop("selected", true); + $(".network option").filter(function() { + return $(this).html() == "Ethereum"; + }).prop("selected", true); $(".network").trigger("change"); }); waitForGenerate(function() { @@ -1838,7 +1864,10 @@ page.open(url, function(status) { waitForGenerate(function() { // 4) switch from bitcoin to litecoin page.evaluate(function() { - $(".network").val("2").trigger("change"); + $(".network option").filter(function() { + return $(this).html() == "Litecoin"; + }).prop("selected", true); + $(".network").trigger("change"); }); waitForGenerate(function() { // 5) Check derivation path is displayed correctly @@ -1881,7 +1910,10 @@ page.open(url, function(status) { waitForGenerate(function() { // switch from bitcoin to clam page.evaluate(function() { - $(".network").val("9").trigger("change"); + $(".network option").filter(function() { + return $(this).html() == "CLAM"; + }).prop("selected", true); + $(".network").trigger("change"); }); waitForGenerate(function() { // check derivation path is displayed correctly @@ -1912,7 +1944,10 @@ page.open(url, function(status) { waitForGenerate(function() { // 4) switch from bitcoin to viacoin page.evaluate(function() { - $(".network").val("6").trigger("change"); + $(".network option").filter(function() { + return $(this).html() == "Viacoin"; + }).prop("selected", true); + $(".network").trigger("change"); }); waitForGenerate(function() { // 5) ensure the derived address is correct @@ -3419,6 +3454,163 @@ page.open(url, function(status) { }); }, +// Github pull request 55 +// https://github.com/iancoleman/bip39/pull/55 +// Client select +function() { +page.open(url, function(status) { + // set mnemonic and select bip32 tab + page.evaluate(function() { + $("#bip32-tab a").click(); + $(".phrase").val("abandon abandon ability").trigger("input"); + }); + waitForGenerate(function() { + // BITCOIN CORE + // set bip32 client to bitcoin core + page.evaluate(function() { + var bitcoinCoreIndex = "0"; + $("#bip32-client").val(bitcoinCoreIndex).trigger("change"); + }); + waitForGenerate(function() { + // get the derivation path + var actual = page.evaluate(function() { + return $("#bip32-path").val(); + }); + // check the derivation path is correct + expected = "m/0'/0'" + if (actual != expected) { + console.log("Selecting Bitcoin Core client does not set correct derivation path"); + console.log("Expected: " + expected); + console.log("Actual: " + actual); + fail(); + } + // get hardened addresses + var usesHardenedAddresses = page.evaluate(function() { + return $(".hardened-addresses").prop("checked"); + }); + // check hardened addresses is selected + if(!usesHardenedAddresses) { + console.log("Selecting Bitcoin Core client does not use hardened addresses"); + fail(); + } + // check input is readonly + var pathIsReadonly = page.evaluate(function() { + return $("#bip32-path").prop("readonly"); + }); + if (!pathIsReadonly) { + console.log("Selecting Bitcoin Core client does not set derivation path to readonly"); + fail(); + } + // MULTIBIT + // set bip32 client to multibit + page.evaluate(function() { + var multibitIndex = "2"; + $("#bip32-client").val(multibitIndex).trigger("change"); + }); + waitForGenerate(function() { + // get the derivation path + var actual = page.evaluate(function() { + return $("#bip32-path").val(); + }); + // check the derivation path is correct + expected = "m/0'/0" + if (actual != expected) { + console.log("Selecting Multibit client does not set correct derivation path"); + console.log("Expected: " + expected); + console.log("Actual: " + actual); + fail(); + } + // get hardened addresses + var usesHardenedAddresses = page.evaluate(function() { + return $(".hardened-addresses").prop("checked"); + }); + // check hardened addresses is selected + if(usesHardenedAddresses) { + console.log("Selecting Multibit client does not uncheck hardened addresses"); + fail(); + } + // CUSTOM DERIVATION PATH + // check input is not readonly + page.evaluate(function() { + $("#bip32-client").val("custom").trigger("change"); + }); + // do not wait for generate, since there is no change to the + // derivation path there is no new generation performed + var pathIsReadonly = page.evaluate(function() { + return $("#bip32-path").prop("readonly"); + }); + if (pathIsReadonly) { + console.log("Selecting Custom Derivation Path does not allow derivation path input"); + fail(); + } + next(); + }); + }); + }); +}); +}, + +// github issue 58 +// https://github.com/iancoleman/bip39/issues/58 +// bip32 derivation is correct, does not drop leading zeros +// see also +// https://medium.com/@alexberegszaszi/why-do-my-bip32-wallets-disagree-6f3254cc5846 +function() { +page.open(url, function(status) { + // set the phrase and passphrase + var expected = "17rxURoF96VhmkcEGCj5LNQkmN9HVhWb7F"; + // Note that bitcore generates an incorrect address + // 13EuKhffWkBE2KUwcbkbELZb1MpzbimJ3Y + // see the medium.com link above for more details + page.evaluate(function() { + $(".phrase").val("fruit wave dwarf banana earth journey tattoo true farm silk olive fence"); + $(".passphrase").val("banana").trigger("input"); + }); + // check the address is generated correctly + waitForGenerate(function() { + var actual = page.evaluate(function() { + return $(".address:first").text(); + }); + if (actual != expected) { + console.log("BIP32 derivation is incorrect"); + console.log("Expected: " + expected); + console.log("Actual: " + actual); + fail(); + } + next(); + }); +}); +}, + + +// github issue 60 +// Japanese mnemonics generate incorrect bip32 seed +// BIP39 seed is set from phrase +function() { +page.open(url, function(status) { + // set the phrase + var expected = "a262d6fb6122ecf45be09c50492b31f92e9beb7d9a845987a02cefda57a15f9c467a17872029a9e92299b5cbdf306e3a0ee620245cbd508959b6cb7ca637bd55"; + page.evaluate(function() { + $(".phrase").val("あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あおぞら"); + $("#passphrase").val("メートルガバヴァぱばぐゞちぢ十人十色"); + $("#passphrase").trigger("input"); + }); + // check the seed is generated correctly + waitForGenerate(function() { + var actual = page.evaluate(function() { + return $(".seed").val(); + }); + if (actual != expected) { + console.log("BIP39 seed is incorrectly generated from Japanese mnemonic"); + console.log("Expected: " + expected); + console.log("Actual: " + actual); + fail(); + } + next(); + }); +}); +}, + // If you wish to add more tests, do so here... // Here is a blank test template