]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/BIP39.git/blobdiff - tests.js
Test setting BIP32 root key clears phrase
[perso/Immae/Projets/Cryptomonnaies/BIP39.git] / tests.js
index 12a6c5bf398de5d2d8360b9a92d10ba0d4d8097e..97cb646b4780633d771ea767e36f7ae29c6986d5 100644 (file)
--- a/tests.js
+++ b/tests.js
@@ -485,6 +485,62 @@ page.open(url, function(status) {
 });
 },
 
+// Network can be set to namecoin
+function() {
+page.open(url, function(status) {
+    // set the phrase and coin
+    var expected = "Mw2vK2Bvex1yYtYF6sfbEg2YGoUc98YUD2";
+    page.evaluate(function() {
+        $(".phrase").val("abandon abandon ability");
+        $(".phrase").trigger("input");
+        $(".network option[selected]").removeAttr("selected");
+        $(".network option[value=11]").prop("selected", true);
+        $(".network").trigger("change");
+    });
+    // check the address is generated correctly
+    waitForGenerate(function() {
+        var actual = page.evaluate(function() {
+            return $(".address:first").text();
+        });
+        if (actual != expected) {
+            console.log("Namecoin address is incorrect");
+            console.log("Expected: " + expected);
+            console.log("Actual: " + actual);
+            fail();
+        }
+        next();
+    });
+});
+},
+
+// Network can be set to peercoin
+function() {
+page.open(url, function(status) {
+    // set the phrase and coin
+    var expected = "PVAiioTaK2eDHSEo3tppT9AVdBYqxRTBAm";
+    page.evaluate(function() {
+        $(".phrase").val("abandon abandon ability");
+        $(".phrase").trigger("input");
+        $(".network option[selected]").removeAttr("selected");
+        $(".network option[value=12]").prop("selected", true);
+        $(".network").trigger("change");
+    });
+    // check the address is generated correctly
+    waitForGenerate(function() {
+        var actual = page.evaluate(function() {
+            return $(".address:first").text();
+        });
+        if (actual != expected) {
+            console.log("Peercoin address is incorrect");
+            console.log("Expected: " + expected);
+            console.log("Actual: " + actual);
+            fail();
+        }
+        next();
+    });
+});
+},
+
 // BIP39 seed is set from phrase
 function() {
 page.open(url, function(status) {
@@ -978,7 +1034,6 @@ page.open(url, function(status) {
         $(".phrase").val("abandon abandon ability");
         $(".phrase").trigger("input");
     });
-    // check the path is not shown
     waitForGenerate(function() {
         // toggle path visibility
         page.evaluate(function() {
@@ -1053,16 +1108,242 @@ page.open(url, function(status) {
     });
 });
 },
+
 // Address visibility can be toggled
+function() {
+page.open(url, function(status) {
+    // set the phrase
+    page.evaluate(function() {
+        $(".phrase").val("abandon abandon ability");
+        $(".phrase").trigger("input");
+    });
+    waitForGenerate(function() {
+        // toggle address visibility
+        page.evaluate(function() {
+            $(".address-toggle").click();
+        });
+        // check the address is not visible
+        var isInvisible = page.evaluate(function() {
+            return $(".address:first span").hasClass("invisible");
+        });
+        if (!isInvisible) {
+            console.log("Toggled address is visible");
+            fail();
+        }
+        next();
+    });
+});
+},
+
 // Private key is shown
+function() {
+page.open(url, function(status) {
+    var expected = "L26cVSpWFkJ6aQkPkKmTzLqTdLJ923e6CzrVh9cmx21QHsoUmrEE";
+    // set the phrase
+    page.evaluate(function() {
+        $(".phrase").val("abandon abandon ability").trigger("input");
+    });
+    // get the address
+    waitForGenerate(function() {
+        var actual = page.evaluate(function() {
+            return $(".privkey:first").text();
+        });
+        if (actual != expected) {
+            console.log("Private key is not shown");
+            console.log("Expected: " + expected);
+            console.log("Got: " + actual);
+            fail();
+        }
+        next();
+    });
+});
+},
+
 // Private key visibility can be toggled
+function() {
+page.open(url, function(status) {
+    // set the phrase
+    page.evaluate(function() {
+        $(".phrase").val("abandon abandon ability");
+        $(".phrase").trigger("input");
+    });
+    waitForGenerate(function() {
+        // toggle private key visibility
+        page.evaluate(function() {
+            $(".private-key-toggle").click();
+        });
+        // check the private key is not visible
+        var isInvisible = page.evaluate(function() {
+            return $(".privkey:first span").hasClass("invisible");
+        });
+        if (!isInvisible) {
+            console.log("Toggled private key is visible");
+            fail();
+        }
+        next();
+    });
+});
+},
 
 // More addresses can be generated
+function() {
+page.open(url, function(status) {
+    // set the phrase
+    page.evaluate(function() {
+        $(".phrase").val("abandon abandon ability");
+        $(".phrase").trigger("input");
+    });
+    waitForGenerate(function() {
+        // generate more addresses
+        page.evaluate(function() {
+            $(".more").click();
+        });
+        waitForGenerate(function() {
+            // check there are more addresses
+            var addressCount = page.evaluate(function() {
+                return $(".address").length;
+            });
+            if (addressCount != 40) {
+                console.log("More addresses cannot be generated");
+                fail();
+            }
+            next();
+        });
+    });
+});
+},
+
 // A custom number of additional addresses can be generated
+function() {
+page.open(url, function(status) {
+    // set the phrase
+    page.evaluate(function() {
+        $(".phrase").val("abandon abandon ability");
+        $(".phrase").trigger("input");
+    });
+    waitForGenerate(function() {
+        // get the current number of addresses
+        var oldAddressCount = page.evaluate(function() {
+            return $(".address").length;
+        });
+        // set a custom number of additional addresses
+        page.evaluate(function() {
+            $(".rows-to-add").val(1);
+        });
+        // generate more addresses
+        page.evaluate(function() {
+            $(".more").click();
+        });
+        waitForGenerate(function() {
+            // check there are the correct number of addresses
+            var newAddressCount = page.evaluate(function() {
+                return $(".address").length;
+            });
+            if (newAddressCount - oldAddressCount != 1) {
+                console.log("Number of additional addresses cannot be customized");
+                console.log(newAddressCount)
+                console.log(oldAddressCount)
+                fail();
+            }
+            next();
+        });
+    });
+});
+},
+
 // Additional addresses are shown in order of derivation path
+function() {
+page.open(url, function(status) {
+    // set the phrase
+    page.evaluate(function() {
+        $(".phrase").val("abandon abandon ability").trigger("input");
+    });
+    waitForGenerate(function() {
+        // generate more addresses
+        page.evaluate(function() {
+            $(".more").click();
+        });
+        // get the derivation paths
+        waitForGenerate(function() {
+            var paths = page.evaluate(function() {
+                return $(".index").map(function(i, e) {
+                    return $(e).text();
+                });
+            });
+            if (paths.length != 40) {
+                console.log("Total additional paths is less than expected: " + paths.length);
+                fail();
+            }
+            for (var i=0; i<paths.length; i++) {
+                var expected = "m/44'/0'/0'/0/" + i;
+                var actual = paths[i];
+                if (actual != expected) {
+                    console.log("Path " + i + " is not in correct order");
+                    console.log("Expected: " + expected);
+                    console.log("Actual: " + actual);
+                    fail();
+                }
+            }
+            next();
+        });
+    });
+});
+},
 
 // BIP32 root key can be set by the user
+function() {
+page.open(url, function(status) {
+    var expected = "1Di3Vp7tBWtyQaDABLAjfWtF6V7hYKJtug";
+    // set the root key
+    page.evaluate(function() {
+        $(".root-key").val("xprv9s21ZrQH143K2jkGDCeTLgRewT9F2pH5JZs2zDmmjXes34geVnFiuNa8KTvY5WoYvdn4Ag6oYRoB6cXtc43NgJAEqDXf51xPm6fhiMCKwpi").trigger("input");
+    });
+    waitForGenerate(function() {
+        var actual = page.evaluate(function() {
+            return $(".address:first").text();
+        });
+        if (actual != expected) {
+            console.log("Setting BIP32 root key results in wrong address");
+            console.log("Expected: " + expected);
+            console.log("Actual: " + actual);
+            fail();
+        }
+        next();
+    });
+});
+},
+
 // Setting BIP32 root key clears the existing phrase, passphrase and seed
+function() {
+page.open(url, function(status) {
+    var expected = "";
+    // set a mnemonic
+    page.evaluate(function() {
+        $(".phrase").val("A non-blank but invalid value");
+    });
+    // Accept any confirm dialogs
+    page.onConfirm = function() {
+        return true;
+    };
+    // set the root key
+    page.evaluate(function() {
+        $(".root-key").val("xprv9s21ZrQH143K2jkGDCeTLgRewT9F2pH5JZs2zDmmjXes34geVnFiuNa8KTvY5WoYvdn4Ag6oYRoB6cXtc43NgJAEqDXf51xPm6fhiMCKwpi").trigger("input");
+    });
+    waitForGenerate(function() {
+        var actual = page.evaluate(function() {
+            return $(".phrase").val();
+        });
+        if (actual != expected) {
+            console.log("Phrase not cleared when setting BIP32 root key");
+            console.log("Expected: " + expected);
+            console.log("Actual: " + actual);
+            fail();
+        }
+        next();
+    });
+});
+},
+
 // Clearing of phrase, passphrase and seed can be cancelled by user
 // Custom BIP32 root key is used when changing the derivation path