X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests.js;h=b6713b040e371803fab23cd47b5b555d7750d6db;hb=6c08f364b30e711feac698546041388325a11834;hp=10d13a324f5dfb6d0aab2aa3068be44f3affc361;hpb=e00964ccf7a556895784ed05f0fdec954f5558d5;p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FBIP39.git diff --git a/tests.js b/tests.js index 10d13a3..b6713b0 100644 --- a/tests.js +++ b/tests.js @@ -4,7 +4,7 @@ var page = require('webpage').create(); var url = 'src/index.html'; -var testMaxTime = 10000; +var testMaxTime = 20000; page.viewportSize = { width: 1024, @@ -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() == "BTC - 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() == "LTC - Litecoin"; + }).prop("selected", true); $(".network").trigger("change"); }); // check the address is generated correctly @@ -327,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) { @@ -336,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 @@ -364,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 @@ -392,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 @@ -420,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 @@ -448,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 @@ -476,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 @@ -504,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 @@ -523,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) { @@ -532,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 @@ -551,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) { @@ -560,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 @@ -588,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 @@ -607,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) { @@ -763,70 +1028,6 @@ page.open(url, function(status) { }); }, -// BIP44 purpose field changes address list -function() { -page.open(url, function(status) { - // set the phrase - var expected = "1JbDzRJ2cDT8aat2xwKd6Pb2zzavow5MhF"; - page.evaluate(function() { - $(".phrase").val("abandon abandon ability"); - $(".phrase").trigger("input"); - }); - 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(); - }); - }); -}); -}, - -// BIP44 coin field changes address list -function() { -page.open(url, function(status) { - // set the phrase - var expected = "1F6dB2djQYrxoyfZZmfr6D5voH8GkJTghk"; - page.evaluate(function() { - $(".phrase").val("abandon abandon ability"); - $(".phrase").trigger("input"); - }); - 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(); - }); - }); -}); -}, - // BIP44 account field changes address list function() { page.open(url, function(status) { @@ -1562,6 +1763,31 @@ page.open(url, function(status) { }); }, +// Github pull request 48 +// First four letters of word shows that word, not closest +// since first four letters gives unique word in BIP39 wordlist +// eg ille should show illegal, not idle +function() { +page.open(url, function(status) { + // set the incomplete word + page.evaluate(function() { + $(".phrase").val("ille").trigger("input"); + }); + // check there is a suggestion shown + waitForFeedback(function() { + var feedback = page.evaluate(function() { + return $(".feedback").text(); + }); + if (feedback.indexOf("did you mean illegal?") < 0) { + console.log("Start of word does not show correct suggestion"); + console.log("Error: " + error); + fail(); + } + next(); + }); +}); +}, + // Incorrect BIP32 root key shows error function() { page.open(url, function(status) { @@ -1753,7 +1979,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() == "LTC - Litecoin"; + }).prop("selected", true); + $(".network").trigger("change"); }); waitForGenerate(function() { // 5) Check derivation path is displayed correctly @@ -1796,7 +2025,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 - Clams"; + }).prop("selected", true); + $(".network").trigger("change"); }); waitForGenerate(function() { // check derivation path is displayed correctly @@ -1827,7 +2059,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() == "VIA - Viacoin"; + }).prop("selected", true); + $(".network").trigger("change"); }); waitForGenerate(function() { // 5) ensure the derived address is correct @@ -2155,10 +2390,10 @@ page.open(url, function(status) { return e.message; } // Leading zeros for card entropy as binary string. - // Card entropy is hashed so 2c does not produce leading zeros. + // Card entropy is hashed so 2c does not necessarily produce leading zeros. try { - e = Entropy.fromString("4c"); - if (e.binaryStr != "0001") { + e = Entropy.fromString("2c"); + if (e.binaryStr != "0010") { return "Card entropy as binary has leading zeros"; } } @@ -2190,24 +2425,24 @@ page.open(url, function(status) { // [ cards, binary ] try { var cards = [ - [ "ac", "0100" ], - [ "acqs", "10111101" ], - [ "acks", "11110000" ], - [ "2cac", "11000010" ], - [ "2c", "1000" ], - [ "3d", "1111" ], - [ "4h", "0011" ], + [ "ac", "0101" ], + [ "acqs", "11011100" ], + [ "acks", "01011100" ], + [ "2cac", "11111000" ], + [ "2c", "0010" ], + [ "3d", "0001" ], + [ "4h", "1001" ], [ "5s", "1001" ], - [ "6c", "1011" ], - [ "7d", "1101" ], + [ "6c", "0000" ], + [ "7d", "0001" ], [ "8h", "1011" ], - [ "9s", "1010" ], - [ "tc", "1101" ], - [ "jd", "1101" ], - [ "qh", "1100" ], - [ "ks", "1111" ], - [ "ks2c", "10000001" ], - [ "KS2C", "10000001" ], + [ "9s", "0010" ], + [ "tc", "1001" ], + [ "jd", "1111" ], + [ "qh", "0010" ], + [ "ks", "0101" ], + [ "ks2c", "01010100" ], + [ "KS2C", "01010100" ], ]; for (var i=0; i