]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/BIP39.git/blobdiff - tests.js
Test github issue 23: derivation path on bip32 tab
[perso/Immae/Projets/Cryptomonnaies/BIP39.git] / tests.js
index f76baf85adec70f5fdaf4f2a045aab96a81f7934..557eaa7f353a2912415e2a83ce32788ae7ba3ce8 100644 (file)
--- a/tests.js
+++ b/tests.js
@@ -1456,21 +1456,252 @@ page.open(url, function(status) {
 },
 
 // Incorrect word shows suggested replacement
+function() {
+page.open(url, function(status) {
+    // set the root key
+    page.evaluate(function() {
+        $(".phrase").val("abandon abandon abiliti").trigger("input");
+    });
+    // check there is a suggestion shown
+    waitForFeedback(function() {
+        var feedback = page.evaluate(function() {
+            return $(".feedback").text();
+        });
+        if (feedback.indexOf("did you mean ability?") < 0) {
+            console.log("Incorrect word does not show suggested replacement");
+            console.log("Error: " + error);
+            fail();
+        }
+        next();
+    });
+});
+},
+
 // Incorrect BIP32 root key shows error
+function() {
+page.open(url, function(status) {
+    // set the root key
+    page.evaluate(function() {
+        $(".root-key").val("xprv9s21ZrQH143K2jkGDCeTLgRewT9F2pH5JZs2zDmmjXes34geVnFiuNa8KTvY5WoYvdn4Ag6oYRoB6cXtc43NgJAEqDXf51xPm6fhiMCKwpj").trigger("input");
+    });
+    // check there is an error shown
+    waitForFeedback(function() {
+        var feedback = page.evaluate(function() {
+            return $(".feedback").text();
+        });
+        if (feedback != "Invalid root key") {
+            console.log("Invalid root key does not show error");
+            console.log("Error: " + error);
+            fail();
+        }
+        next();
+    });
+});
+},
+
 // Derivation path not starting with m shows error
+function() {
+page.open(url, function(status) {
+    // set the mnemonic phrase
+    page.evaluate(function() {
+        $(".phrase").val("abandon abandon ability").trigger("input");
+    });
+    waitForGenerate(function() {
+        // select the bip32 tab so custom derivation path can be set
+        page.evaluate(function() {
+            $("#bip32-tab a").click();
+        });
+        waitForGenerate(function() {
+            // set the incorrect derivation path
+            page.evaluate(function() {
+                $("#bip32 .path").val("n/0").trigger("input");
+            });
+            waitForFeedback(function() {
+                var feedback = page.evaluate(function() {
+                    return $(".feedback").text();
+                });
+                if (feedback != "First character must be 'm'") {
+                    console.log("Derivation path not starting with m should show error");
+                    console.log("Error: " + error);
+                    fail();
+                }
+                next();
+            });
+        });
+    });
+});
+},
+
 // Derivation path containing invalid characters shows useful error
+function() {
+page.open(url, function(status) {
+    // set the mnemonic phrase
+    page.evaluate(function() {
+        $(".phrase").val("abandon abandon ability").trigger("input");
+    });
+    waitForGenerate(function() {
+        // select the bip32 tab so custom derivation path can be set
+        page.evaluate(function() {
+            $("#bip32-tab a").click();
+        });
+        waitForGenerate(function() {
+            // set the incorrect derivation path
+            page.evaluate(function() {
+                $("#bip32 .path").val("m/1/0wrong1/1").trigger("input");
+            });
+            waitForFeedback(function() {
+                var feedback = page.evaluate(function() {
+                    return $(".feedback").text();
+                });
+                if (feedback != "Invalid characters 0wrong1 found at depth 2") {
+                    console.log("Derivation path with invalid characters should show error");
+                    console.log("Error: " + error);
+                    fail();
+                }
+                next();
+            });
+        });
+    });
+});
+},
 
 // Github Issue 11: Default word length is 15
 // https://github.com/dcpos/bip39/issues/11
+function() {
+page.open(url, function(status) {
+    // get the word length
+    var defaultLength = page.evaluate(function() {
+        return $(".strength").val();
+    });
+    if (defaultLength != 15) {
+        console.log("Default word length is not 15");
+        fail();
+    }
+    next();
+});
+},
+
 
 // Github Issue 12: Generate more rows with private keys hidden
 // https://github.com/dcpos/bip39/issues/12
+function() {
+page.open(url, function(status) {
+    // set the phrase
+    page.evaluate(function() {
+        $(".phrase").val("abandon abandon ability");
+        $(".phrase").trigger("input");
+    });
+    waitForGenerate(function() {
+        // toggle private keys hidden, then generate more addresses
+        page.evaluate(function() {
+            $(".private-key-toggle").click();
+            $(".more").click();
+        });
+        waitForGenerate(function() {
+            // check more have been generated
+            var expected = 40;
+            var numPrivKeys = page.evaluate(function() {
+                return $(".privkey").length;
+            });
+            if (numPrivKeys != expected) {
+                console.log("Wrong number of addresses when clicking 'more' with hidden privkeys");
+                console.log("Expected: " + expected);
+                console.log("Actual: " + numPrivKeys);
+                fail();
+            }
+            // check no private keys are shown
+            var numHiddenPrivKeys = page.evaluate(function() {
+                return $(".privkey span[class=invisible]").length;
+            });
+            if (numHiddenPrivKeys != expected) {
+                console.log("Generating more does not retain hidden state of privkeys");
+                console.log("Expected: " + expected);
+                console.log("Actual: " + numHiddenPrivKeys);
+                fail();
+            }
+            next();
+        });
+    });
+});
+},
 
 // Github Issue 19: Mnemonic is not sensitive to whitespace
 // https://github.com/dcpos/bip39/issues/19
+function() {
+page.open(url, function(status) {
+    // set the phrase
+    var expected = "xprv9s21ZrQH143K3isaZsWbKVoTtbvd34Y1ZGRugGdMeBGbM3AgBVzTH159mj1cbbtYSJtQr65w6L5xy5L9SFC7c9VJZWHxgAzpj4mun5LhrbC";
+    page.evaluate(function() {
+        var doubleSpace = "  ";
+        $(".phrase").val("urge cat" + doubleSpace + "bid");
+        $(".phrase").trigger("input");
+    });
+    waitForGenerate(function() {
+        // Check the bip32 root key is correct
+        var actual = page.evaluate(function() {
+            return $(".root-key").val();
+        });
+        if (actual != expected) {
+            console.log("Mnemonic is sensitive to whitespace");
+            console.log("Expected: " + expected);
+            console.log("Actual: " + actual);
+            fail();
+        }
+        next();
+    });
+});
+},
 
-// Github Issue 23: Use correct derivation path when changing tabs
+// Github Issue 23: Part 1: Use correct derivation path when changing tabs
 // https://github.com/dcpos/bip39/issues/23
+function() {
+page.open(url, function(status) {
+    // 1) and 2) set the phrase
+    page.evaluate(function() {
+        $(".phrase").val("abandon abandon ability").trigger("input");
+    });
+    waitForGenerate(function() {
+        // 3) select bip32 tab
+        page.evaluate(function() {
+            $("#bip32-tab a").click();
+        });
+        waitForGenerate(function() {
+            // 4) switch from bitcoin to litecoin
+            page.evaluate(function() {
+                $(".network").val("2").trigger("change");
+            });
+            waitForGenerate(function() {
+                // 5) Check derivation path is displayed correctly
+                var expected = "m/0/0";
+                var actual = page.evaluate(function() {
+                    return $(".index:first").text();
+                });
+                if (actual != expected) {
+                    console.log("Github Issue 23 Part 1: derivation path display error");
+                    console.log("Expected: " + expected);
+                    console.log("Actual: " + actual);
+                    fail();
+                }
+                // 5) Check address is displayed correctly
+                var expected = "LS8MP5LZ5AdzSZveRrjm3aYVoPgnfFh5T5";
+                var actual = page.evaluate(function() {
+                    return $(".address:first").text();
+                });
+                if (actual != expected) {
+                    console.log("Github Issue 23 Part 1: address display error");
+                    console.log("Expected: " + expected);
+                    console.log("Actual: " + actual);
+                    fail();
+                }
+                next();
+            });
+        });
+    });
+});
+},
+
+// Github Issue 23 Part 2: Coin selection in derivation path
+// https://github.com/dcpos/bip39/issues/23#issuecomment-238011920
 
 // Github Issue 26: When using a Root key derrived altcoins are incorrect
 // https://github.com/dcpos/bip39/issues/26