X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests.js;h=10d13a324f5dfb6d0aab2aa3068be44f3affc361;hb=e00964ccf7a556895784ed05f0fdec954f5558d5;hp=c7d92e4ead3365d99a4955e40cb7448733226902;hpb=92e73fd952dd89069c51b47689ab39b28f99a547;p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FBIP39.git diff --git a/tests.js b/tests.js index c7d92e4..10d13a3 100644 --- a/tests.js +++ b/tests.js @@ -6,6 +6,11 @@ var page = require('webpage').create(); var url = 'src/index.html'; var testMaxTime = 10000; +page.viewportSize = { + width: 1024, + height: 720 +}; + page.onResourceError = function(e) { console.log("Error loading " + e.url); phantom.exit(); @@ -2149,10 +2154,11 @@ page.open(url, function(status) { catch (e) { return e.message; } - // Leading zeros for card entropy as binary string + // Leading zeros for card entropy as binary string. + // Card entropy is hashed so 2c does not produce leading zeros. try { - e = Entropy.fromString("2c"); - if (e.binaryStr != "00001") { + e = Entropy.fromString("4c"); + if (e.binaryStr != "0001") { return "Card entropy as binary has leading zeros"; } } @@ -2184,24 +2190,24 @@ page.open(url, function(status) { // [ cards, binary ] try { var cards = [ - [ "ac", "00000" ], - [ "acqs", "00001100011" ], - [ "acks", "00001100100" ], - [ "2cac", "00001100101" ], - [ "2c", "00001" ], - [ "3d", "01111" ], - [ "4h", "11101" ], - [ "5s", "101011" ], - [ "6c", "00101" ], - [ "7d", "10011" ], - [ "8h", "100001" ], - [ "9s", "101111" ], - [ "tc", "01001" ], - [ "jd", "10111" ], - [ "qh", "100101" ], - [ "ks", "110011" ], - [ "ks2c", "101001011100" ], - [ "KS2C", "101001011100" ], + [ "ac", "0100" ], + [ "acqs", "10111101" ], + [ "acks", "11110000" ], + [ "2cac", "11000010" ], + [ "2c", "1000" ], + [ "3d", "1111" ], + [ "4h", "0011" ], + [ "5s", "1001" ], + [ "6c", "1011" ], + [ "7d", "1101" ], + [ "8h", "1011" ], + [ "9s", "1010" ], + [ "tc", "1101" ], + [ "jd", "1101" ], + [ "qh", "1100" ], + [ "ks", "1111" ], + [ "ks2c", "10000001" ], + [ "KS2C", "10000001" ], ]; for (var i=0; i 0) { console.log("Mnemonic length for " + test.strength + " strength is not " + test.words); + console.log("Entropy: " + test.entropy); console.log("Mnemonic: " + mnemonic); fail(); } } - else { + else if ("words" in test) { if (mnemonic.split(" ").length != test.words) { console.log("Mnemonic length for " + test.strength + " strength is not " + test.words); + console.log("Entropy: " + test.entropy); console.log("Mnemonic: " + mnemonic); fail(); } @@ -3107,18 +3032,6 @@ page.open(url, function(status) { var newPhrase = page.evaluate(function() { return $(".phrase").val(); }); - // check raw entropy is in use, ie the first bits should remain the same - var startLength = 20; - var originalPhraseStart = originalPhrase.substring(0,startLength); - var newPhraseStart = newPhrase.substring(0,startLength); - if (newPhraseStart != originalPhraseStart) { - console.log("Changing last 12 cards changed first portion of mnemonic"); - console.log("Original:"); - console.log(originalPhrase); - console.log("New:"); - console.log(newPhrase); - fail(); - } // check the phrase has changed if (newPhrase == originalPhrase) { console.log("Changing last 12 cards does not change mnemonic"); @@ -3134,6 +3047,45 @@ page.open(url, function(status) { }); }, +// Github issue 35 +// https://github.com/iancoleman/bip39/issues/35 +// QR Code support +function() { +page.open(url, function(status) { + // use entropy + page.evaluate(function() { + $(".generate").click(); + }); + waitForGenerate(function() { + var p = page.evaluate(function() { + // get position of mnemonic element + return $(".phrase").offset(); + }); + p.top = Math.ceil(p.top); + p.left = Math.ceil(p.left); + // check the qr code shows + page.sendEvent("mousemove", p.left+4, p.top+4); + var qrShowing = page.evaluate(function() { + return $(".qr-container").find("canvas").length > 0; + }); + if (!qrShowing) { + console.log("QR Code does not show"); + fail(); + } + // check the qr code hides + page.sendEvent("mousemove", p.left-4, p.top-4); + var qrHidden = page.evaluate(function() { + return $(".qr-container").find("canvas").length == 0; + }); + if (!qrHidden) { + console.log("QR Code does not hide"); + fail(); + } + next(); + }); +}); +}, + // If you wish to add more tests, do so here...