]>
git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/BIP39.git/blob - tests.js
12b779ee723dab8af30e07cb00dea968e3db80cb
2 // $ phantomjs tests.js
5 var page
= require('webpage').create();
6 var url
= 'src/index.html';
8 page
.onResourceError = function(e
) {
9 console
.log("Error loading " + e
.url
);
14 console
.log("Failed");
19 if (tests
.length
> 0) {
20 var testsStr
= tests
.length
== 1 ? "test" : "tests";
21 console
.log(tests
.length
+ " " + testsStr
+ " remaining");
25 console
.log("Finished with 0 failures");
32 // Page loads with status of 'success'
34 page
.open(url
, function(status
) {
35 if (status
!= "success") {
36 console
.log("Page did not load with status 'success'");
45 page
.open(url
, function(status
) {
46 var content
= page
.evaluate(function() {
47 return document
.body
.textContent
.trim();
50 console
.log("Page does not have text");
57 // Entering mnemonic generates addresses
59 page
.open(url
, function(status
) {
60 var expected
= "1Di3Vp7tBWtyQaDABLAjfWtF6V7hYKJtug";
62 page
.evaluate(function() {
63 $(".phrase").val("abandon abandon ability").trigger("input");
66 setTimeout(function() {
67 var actual
= page
.evaluate(function() {
68 return $(".address:first").text();
70 if (actual
!= expected
) {
71 console
.log("Mnemonic did not generate address");
72 console
.log("Expected: " + expected
);
73 console
.log("Got: " + actual
);
81 // Random button generates random mnemonic
83 page
.open(url
, function(status
) {
84 // check initial phrase is empty
85 var phrase
= page
.evaluate(function() {
86 return $(".phrase").text();
89 console
.log("Initial phrase is not blank");
92 // press the 'generate' button
93 page
.evaluate(function() {
94 $(".generate").click();
97 setTimeout(function() {
98 var phrase
= page
.evaluate(function() {
99 return $(".phrase").val();
101 if (phrase
.length
<= 0) {
102 console
.log("Phrase not generated by pressing button");
110 // Mnemonic length can be customized
112 page
.open(url
, function(status
) {
113 // set the length to 6
114 var expectedLength
= 6;
115 page
.evaluate(function() {
116 $(".strength").val(expectedLength
);
118 // press the 'generate' button
119 page
.evaluate(function() {
120 $(".generate").click();
122 // check the new phrase is six words long
123 setTimeout(function() {
124 var actualLength
= page
.evaluate(function() {
125 var words
= $(".phrase").val().split(" ");
128 if (actualLength
!= expectedLength
) {
129 console
.log("Phrase not generated with correct length");
130 console
.log("Expected: " + expectedLength
);
131 console
.log("Actual: " + actualLength
);
139 // TODO finish these tests
141 // Passphrase can be set
142 // Network can be set to bitcoin testnet
143 // Network can be set to litecoin
144 // Network can be set to dogecoin
145 // Network can be set to shadowcash
146 // Network can be set to shadowcash testnet
147 // Network can be set to viacoin
148 // Network can be set to viacoin testnet
149 // Network can be set to jumbucks
150 // Network can be set to clam
151 // BIP39 seed is set from phrase
152 // BIP32 root key is set from phrase
154 // Tabs show correct addresses when changed
156 // BIP44 derivation path is shown
157 // BIP44 extended private key is shown
158 // BIP44 extended public key is shown
159 // BIP44 purpose field changes address list
160 // BIP44 coin field changes address list
161 // BIP44 account field changes address list
162 // BIP44 external/internal field changes address list
164 // BIP32 derivation path can be set
165 // BIP32 can use hardened derivation paths
166 // BIP32 extended private key is shown
167 // BIP32 extended public key is shown
169 // Derivation path is shown in table
170 // Derivation path for address can be hardened
171 // Derivation path visibility can be toggled
173 // Addresses are shown in order of derivation path
174 // Address visibility can be toggled
175 // Private key is shown
176 // Private key visibility can be toggled
178 // More addresses can be generated
179 // A custom number of additional addresses can be generated
180 // Additional addresses are shown in order of derivation path
182 // BIP32 root key can be set by the user
183 // Setting BIP32 clears the existing phrase, passphrase and seed
184 // Custom BIP32 root key is used when changing the derivation path
186 // Incorrect mnemonic shows error
187 // Incorrect word shows suggested replacement
188 // Incorrect BIP32 root key shows error
189 // Derivation path not starting with m shows error
190 // Derivation path containing invalid characters shows useful error
192 // Github Issue 11: Default word length is 15
193 // https://github.com/dcpos/bip39/issues/11
195 // Github Issue 12: Generate more rows with private keys hidden
196 // https://github.com/dcpos/bip39/issues/12
198 // Github Issue 19: Mnemonic is not sensitive to whitespace
199 // https://github.com/dcpos/bip39/issues/19
201 // Github Issue 23: Use correct derivation path when changing tabs
202 // https://github.com/dcpos/bip39/issues/23
206 console
.log("Running tests...");