]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/BIP39.git/commitdiff
Tests for passphrase and coin selection
authorIan Coleman <coleman.ian@gmail.com>
Tue, 23 Aug 2016 06:16:41 +0000 (16:16 +1000)
committerIan Coleman <coleman.ian@gmail.com>
Tue, 23 Aug 2016 06:17:17 +0000 (16:17 +1000)
bip39-standalone.html
src/index.html
src/js/index.js
tests.js

index 523000328ec3ade464dd15a97fdeef55b31d0b1c..5f9cf7cca095f2e3020ac255a9d3bea044bce6a2 100644 (file)
                             <div class="col-sm-10">
                                 <div class="input-group">
                                     <select id="strength" class="strength form-control">
-                                        <option val="3">3</option>
-                                        <option val="6">6</option>
-                                        <option val="9">9</option>
-                                        <option val="12">12</option>
-                                        <option val="15" selected>15</option>
-                                        <option val="18">18</option>
-                                        <option val="21">21</option>
-                                        <option val="24">24</option>
+                                        <option value="3">3</option>
+                                        <option value="6">6</option>
+                                        <option value="9">9</option>
+                                        <option value="12">12</option>
+                                        <option value="15" selected>15</option>
+                                        <option value="18">18</option>
+                                        <option value="21">21</option>
+                                        <option value="24">24</option>
                                     </select>
                                     <span class="input-group-btn">
                                         <button class="btn generate">Generate Random Mnemonic</button>
@@ -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() {
index 15fb063fcda91ed8366e41337c131faba6fa41c1..ea7096cd9ba4146e4ed78f2f5d20cb6cfc8b9db6 100644 (file)
                             <div class="col-sm-10">
                                 <div class="input-group">
                                     <select id="strength" class="strength form-control">
-                                        <option val="3">3</option>
-                                        <option val="6">6</option>
-                                        <option val="9">9</option>
-                                        <option val="12">12</option>
-                                        <option val="15" selected>15</option>
-                                        <option val="18">18</option>
-                                        <option val="21">21</option>
-                                        <option val="24">24</option>
+                                        <option value="3">3</option>
+                                        <option value="6">6</option>
+                                        <option value="9">9</option>
+                                        <option value="12">12</option>
+                                        <option value="15" selected>15</option>
+                                        <option value="18">18</option>
+                                        <option value="21">21</option>
+                                        <option value="24">24</option>
                                     </select>
                                     <span class="input-group-btn">
                                         <button class="btn generate">Generate Random Mnemonic</button>
index 68f1cdaa17e0b6213d057db7184aa263e8fa3f29..8f7d658dad75b1564a5b41f55c37c18d2a65245e 100644 (file)
     // 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() {
index 12b779ee723dab8af30e07cb00dea968e3db80cb..7a3a84223ee0a5e89ee64b6d4936a28516869d17 100644 (file)
--- 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