X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests.js;h=89f4ce367462fdf27dcff025ebebcec295ddc887;hb=49b21f122a232330f7efc499095d8d80f7895a20;hp=16f19630bfa3eab9622dc91619688b187b12b952;hpb=40892aba5013cd75927f63e66492f46b2d206ec9;p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FBIP39.git diff --git a/tests.js b/tests.js index 16f1963..89f4ce3 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, @@ -607,6 +607,66 @@ 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[value=13]").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 = "8f253078b73d7498302bb78c171b23ce7a8fb511987d2b2702b731638a4a15e7"; + 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(); + }); +}); +}, + // BIP39 seed is set from phrase function() { page.open(url, function(status) { @@ -2268,7 +2328,6 @@ page.open(url, function(status) { // use entropy page.evaluate(function() { $(".use-entropy").prop("checked", true).trigger("change"); - $(".mnemonic-length").val("raw"); $(".entropy").val("00000000 00000000 00000000 00000000").trigger("input"); }); // check the mnemonic is set and address is correct @@ -2804,7 +2863,6 @@ page.open(url, function(status) { // use entropy page.evaluate(function() { $(".use-entropy").prop("checked", true).trigger("change"); - $(".mnemonic-length").val("raw"); }); var nextTest = function runNextTest(i) { function getFeedbackError(expected, actual) { @@ -2886,7 +2944,6 @@ page.open(url, function(status) { // use entropy page.evaluate(function() { $(".use-entropy").prop("checked", true).trigger("change"); - $(".mnemonic-length").val("raw"); var entropy = "00000000 00000000 00000000 00000000"; entropy += "11111111 11111111 11111111 1111"; // Missing last byte $(".entropy").val(entropy).trigger("input"); @@ -2913,7 +2970,6 @@ page.open(url, function(status) { // use entropy page.evaluate(function() { $(".use-entropy").prop("checked", true).trigger("change"); - $(".mnemonic-length").val("raw"); var entropy = ""; // Generate a very long entropy string for (var i=0; i<33; i++) { @@ -2947,7 +3003,6 @@ page.open(url, function(status) { // use entropy page.evaluate(function() { $(".use-entropy").prop("checked", true).trigger("change"); - $(".mnemonic-length").val("raw"); var entropy = "543210543210543210543210543210543210543210543210543210543210543210543210543210543210543210543210543"; $(".entropy").val(entropy).trigger("input"); }); @@ -3039,7 +3094,6 @@ page.open(url, function(status) { // use entropy page.evaluate(function() { $(".use-entropy").prop("checked", true).trigger("change"); - $(".mnemonic-length").val("raw"); $(".entropy").val("7S 9H 9S QH 8C KS AS 7D 7C QD 4S 4D TC 2D 5S JS 3D 8S 8H 4C 3C AC 3S QC 9C JC 7H AD TD JD 6D KH 5C QS 2S 6S 6H JH KD 9D-6C TS TH 4H KC 5H 2H AH 2C 8D 3H 5D").trigger("input"); }); // get the mnemonic @@ -3335,6 +3389,36 @@ page.open(url, function(status) { }); }, +// Github issue 49 +// padding for binary should give length with multiple of 256 +// hashed entropy 1111 is length 252, so requires 4 leading zeros +// prior to issue 49 it would only generate 2 leading zeros, ie missing 2 +function() { +page.open(url, function(status) { + expected = "avocado valid quantum cross link predict excuse edit street able flame large galaxy ginger nuclear" + // use entropy + page.evaluate(function() { + $(".use-entropy").prop("checked", true).trigger("change"); + $(".mnemonic-length").val("15"); + $(".entropy").val("1111").trigger("input"); + }); + waitForGenerate(function() { + // get the mnemonic + var actual = page.evaluate(function() { + return $(".phrase").val(); + }); + // check the mnemonic is correct + if (actual != expected) { + console.log("Left padding error for entropy"); + 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