From 54563907c721a90f8fc9861a62fe7c214b5c5041 Mon Sep 17 00:00:00 2001 From: Ian Coleman Date: Tue, 23 Aug 2016 16:16:41 +1000 Subject: Tests for passphrase and coin selection --- bip39-standalone.html | 27 ++++++++++++--------- src/index.html | 16 ++++++------- src/js/index.js | 11 ++++++--- tests.js | 66 +++++++++++++++++++++++++++++++++++++++++++++------ 4 files changed, 91 insertions(+), 29 deletions(-) diff --git a/bip39-standalone.html b/bip39-standalone.html index 5230003..5f9cf7c 100644 --- a/bip39-standalone.html +++ b/bip39-standalone.html @@ -71,14 +71,14 @@
@@ -14906,9 +14906,14 @@ var Mnemonic = function(language) { // Event handlers function networkChanged(e) { - var network = e.target.value; - networks[network].onSelect(); - displayBip32Info(); + var networkIndex = e.target.value; + networks[networkIndex].onSelect(); + if (seed != null) { + phraseChanged(); + } + else { + rootKeyChanged(); + } } function delayedPhraseChanged() { diff --git a/src/index.html b/src/index.html index 15fb063..ea7096c 100644 --- a/src/index.html +++ b/src/index.html @@ -67,14 +67,14 @@
diff --git a/src/js/index.js b/src/js/index.js index 68f1cda..8f7d658 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -72,9 +72,14 @@ // Event handlers function networkChanged(e) { - var network = e.target.value; - networks[network].onSelect(); - displayBip32Info(); + var networkIndex = e.target.value; + networks[networkIndex].onSelect(); + if (seed != null) { + phraseChanged(); + } + else { + rootKeyChanged(); + } } function delayedPhraseChanged() { diff --git a/tests.js b/tests.js index 12b779e..7a3a842 100644 --- a/tests.js +++ b/tests.js @@ -111,9 +111,10 @@ page.open(url, function(status) { function() { page.open(url, function(status) { // set the length to 6 - var expectedLength = 6; + var expectedLength = "6"; page.evaluate(function() { - $(".strength").val(expectedLength); + $(".strength option[selected]").removeAttr("selected"); + $(".strength option[value=6]").prop("selected", true); }); // press the 'generate' button page.evaluate(function() { @@ -131,15 +132,65 @@ page.open(url, function(status) { console.log("Actual: " + actualLength); fail(); } - }, 200); - next(); + next(); + }, 1000); }); }, -// TODO finish these tests - // Passphrase can be set +function() { +page.open(url, function(status) { + // set the phrase and passphrase + var expected = "15pJzUWPGzR7avffV9nY5by4PSgSKG9rba"; + page.evaluate(function() { + $(".phrase").val("abandon abandon ability"); + $(".passphrase").val("secure_passphrase").trigger("input"); + }); + // check the address is generated correctly + setTimeout(function() { + var actual = page.evaluate(function() { + return $(".address:first").text(); + }); + if (actual != expected) { + console.log("Passphrase results in wrong address"); + console.log("Expected: " + expected); + console.log("Actual: " + actual); + fail(); + } + next(); + }, 1000); +}); +}, + // Network can be set to bitcoin testnet +function() { +page.open(url, function(status) { + // set the phrase and passphrase + var expected = "mucaU5iiDaJDb69BHLeDv8JFfGiyg2nJKi"; + page.evaluate(function() { + $(".phrase").val("abandon abandon ability"); + $(".phrase").trigger("input"); + $(".network option[selected]").removeAttr("selected"); + $(".network option[value=1]").prop("selected", true); + $(".network").trigger("change"); + }); + // check the address is generated correctly + setTimeout(function() { + var actual = page.evaluate(function() { + return $(".address:first").text(); + }); + if (actual != expected) { + console.log("Bitcoin testnet address is incorrect"); + console.log("Expected: " + expected); + console.log("Actual: " + actual); + fail(); + } + next(); + }, 1000); +}); +}, + +// TODO finish these tests // Network can be set to litecoin // Network can be set to dogecoin // Network can be set to shadowcash @@ -180,7 +231,8 @@ page.open(url, function(status) { // Additional addresses are shown in order of derivation path // BIP32 root key can be set by the user -// Setting BIP32 clears the existing phrase, passphrase and seed +// 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 -- cgit v1.2.3