]>
git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/BIP39.git/blob - tests.js
2 // $ phantomjs tests.js
5 var page
= require('webpage').create();
6 var url
= 'src/index.html';
7 var testMaxTime
= 5000;
9 page
.onResourceError = function(e
) {
10 console
.log("Error loading " + e
.url
);
15 console
.log("Failed");
19 function waitForGenerate(fn
, maxTime
) {
21 maxTime
= testMaxTime
;
23 var start
= new Date().getTime();
24 var prevAddressCount
= -1;
25 var wait
= function keepWaiting() {
26 var now
= new Date().getTime();
27 var hasTimedOut
= now
- start
> maxTime
;
28 var addressCount
= page
.evaluate(function() {
29 return $(".address").length
;
31 var hasFinished
= addressCount
> 0 && addressCount
== prevAddressCount
;
32 prevAddressCount
= addressCount
;
36 else if (hasTimedOut
) {
37 console
.log("Test timed out");
41 setTimeout(keepWaiting
, 100);
48 if (tests
.length
> 0) {
49 var testsStr
= tests
.length
== 1 ? "test" : "tests";
50 console
.log(tests
.length
+ " " + testsStr
+ " remaining");
54 console
.log("Finished with 0 failures");
61 // Page loads with status of 'success'
63 page
.open(url
, function(status
) {
64 if (status
!= "success") {
65 console
.log("Page did not load with status 'success'");
74 page
.open(url
, function(status
) {
75 var content
= page
.evaluate(function() {
76 return document
.body
.textContent
.trim();
79 console
.log("Page does not have text");
86 // Entering mnemonic generates addresses
88 page
.open(url
, function(status
) {
89 var expected
= "1Di3Vp7tBWtyQaDABLAjfWtF6V7hYKJtug";
91 page
.evaluate(function() {
92 $(".phrase").val("abandon abandon ability").trigger("input");
95 waitForGenerate(function() {
96 var actual
= page
.evaluate(function() {
97 return $(".address:first").text();
99 if (actual
!= expected
) {
100 console
.log("Mnemonic did not generate address");
101 console
.log("Expected: " + expected
);
102 console
.log("Got: " + actual
);
110 // Random button generates random mnemonic
112 page
.open(url
, function(status
) {
113 // check initial phrase is empty
114 var phrase
= page
.evaluate(function() {
115 return $(".phrase").text();
118 console
.log("Initial phrase is not blank");
121 // press the 'generate' button
122 page
.evaluate(function() {
123 $(".generate").click();
125 // get the new phrase
126 waitForGenerate(function() {
127 var phrase
= page
.evaluate(function() {
128 return $(".phrase").val();
130 if (phrase
.length
<= 0) {
131 console
.log("Phrase not generated by pressing button");
139 // Mnemonic length can be customized
141 page
.open(url
, function(status
) {
142 // set the length to 6
143 var expectedLength
= "6";
144 page
.evaluate(function() {
145 $(".strength option[selected]").removeAttr("selected");
146 $(".strength option[value=6]").prop("selected", true);
148 // press the 'generate' button
149 page
.evaluate(function() {
150 $(".generate").click();
152 // check the new phrase is six words long
153 waitForGenerate(function() {
154 var actualLength
= page
.evaluate(function() {
155 var words
= $(".phrase").val().split(" ");
158 if (actualLength
!= expectedLength
) {
159 console
.log("Phrase not generated with correct length");
160 console
.log("Expected: " + expectedLength
);
161 console
.log("Actual: " + actualLength
);
169 // Passphrase can be set
171 page
.open(url
, function(status
) {
172 // set the phrase and passphrase
173 var expected
= "15pJzUWPGzR7avffV9nY5by4PSgSKG9rba";
174 page
.evaluate(function() {
175 $(".phrase").val("abandon abandon ability");
176 $(".passphrase").val("secure_passphrase").trigger("input");
178 // check the address is generated correctly
179 waitForGenerate(function() {
180 var actual
= page
.evaluate(function() {
181 return $(".address:first").text();
183 if (actual
!= expected
) {
184 console
.log("Passphrase results in wrong address");
185 console
.log("Expected: " + expected
);
186 console
.log("Actual: " + actual
);
194 // Network can be set to bitcoin testnet
196 page
.open(url
, function(status
) {
197 // set the phrase and coin
198 var expected
= "mucaU5iiDaJDb69BHLeDv8JFfGiyg2nJKi";
199 page
.evaluate(function() {
200 $(".phrase").val("abandon abandon ability");
201 $(".phrase").trigger("input");
202 $(".network option[selected]").removeAttr("selected");
203 $(".network option[value=1]").prop("selected", true);
204 $(".network").trigger("change");
206 // check the address is generated correctly
207 waitForGenerate(function() {
208 var actual
= page
.evaluate(function() {
209 return $(".address:first").text();
211 if (actual
!= expected
) {
212 console
.log("Bitcoin testnet address is incorrect");
213 console
.log("Expected: " + expected
);
214 console
.log("Actual: " + actual
);
222 // Network can be set to litecoin
224 page
.open(url
, function(status
) {
225 // set the phrase and coin
226 var expected
= "LQ4XU8RX2ULPmPq9FcUHdVmPVchP9nwXdn";
227 page
.evaluate(function() {
228 $(".phrase").val("abandon abandon ability");
229 $(".phrase").trigger("input");
230 $(".network option[selected]").removeAttr("selected");
231 $(".network option[value=2]").prop("selected", true);
232 $(".network").trigger("change");
234 // check the address is generated correctly
235 waitForGenerate(function() {
236 var actual
= page
.evaluate(function() {
237 return $(".address:first").text();
239 if (actual
!= expected
) {
240 console
.log("Litecoin address is incorrect");
241 console
.log("Expected: " + expected
);
242 console
.log("Actual: " + actual
);
250 // Network can be set to dogecoin
252 page
.open(url
, function(status
) {
253 // set the phrase and coin
254 var expected
= "DPQH2AtuzkVSG6ovjKk4jbUmZ6iXLpgbJA";
255 page
.evaluate(function() {
256 $(".phrase").val("abandon abandon ability");
257 $(".phrase").trigger("input");
258 $(".network option[selected]").removeAttr("selected");
259 $(".network option[value=3]").prop("selected", true);
260 $(".network").trigger("change");
262 // check the address is generated correctly
263 waitForGenerate(function() {
264 var actual
= page
.evaluate(function() {
265 return $(".address:first").text();
267 if (actual
!= expected
) {
268 console
.log("Dogecoin address is incorrect");
269 console
.log("Expected: " + expected
);
270 console
.log("Actual: " + actual
);
278 // Network can be set to shadowcash
280 page
.open(url
, function(status
) {
281 // set the phrase and coin
282 var expected
= "SiSZtfYAXEFvMm3XM8hmtkGDyViRwErtCG";
283 page
.evaluate(function() {
284 $(".phrase").val("abandon abandon ability");
285 $(".phrase").trigger("input");
286 $(".network option[selected]").removeAttr("selected");
287 $(".network option[value=4]").prop("selected", true);
288 $(".network").trigger("change");
290 // check the address is generated correctly
291 waitForGenerate(function() {
292 var actual
= page
.evaluate(function() {
293 return $(".address:first").text();
295 if (actual
!= expected
) {
296 console
.log("Shadowcash address is incorrect");
297 console
.log("Expected: " + expected
);
298 console
.log("Actual: " + actual
);
306 // Network can be set to shadowcash testnet
308 page
.open(url
, function(status
) {
309 // set the phrase and coin
310 var expected
= "tM2EDpVKaTiEg2NZg3yKg8eqjLr55BErHe";
311 page
.evaluate(function() {
312 $(".phrase").val("abandon abandon ability");
313 $(".phrase").trigger("input");
314 $(".network option[selected]").removeAttr("selected");
315 $(".network option[value=5]").prop("selected", true);
316 $(".network").trigger("change");
318 // check the address is generated correctly
319 waitForGenerate(function() {
320 var actual
= page
.evaluate(function() {
321 return $(".address:first").text();
323 if (actual
!= expected
) {
324 console
.log("Shadowcash testnet address is incorrect");
325 console
.log("Expected: " + expected
);
326 console
.log("Actual: " + actual
);
334 // Network can be set to viacoin
336 page
.open(url
, function(status
) {
337 // set the phrase and coin
338 var expected
= "Vq9Eq4N5SQnjqZvxtxzo7hZPW5XnyJsmXT";
339 page
.evaluate(function() {
340 $(".phrase").val("abandon abandon ability");
341 $(".phrase").trigger("input");
342 $(".network option[selected]").removeAttr("selected");
343 $(".network option[value=6]").prop("selected", true);
344 $(".network").trigger("change");
346 // check the address is generated correctly
347 waitForGenerate(function() {
348 var actual
= page
.evaluate(function() {
349 return $(".address:first").text();
351 if (actual
!= expected
) {
352 console
.log("Viacoin address is incorrect");
353 console
.log("Expected: " + expected
);
354 console
.log("Actual: " + actual
);
362 // Network can be set to viacoin testnet
364 page
.open(url
, function(status
) {
365 // set the phrase and coin
366 var expected
= "tM2EDpVKaTiEg2NZg3yKg8eqjLr55BErHe";
367 page
.evaluate(function() {
368 $(".phrase").val("abandon abandon ability");
369 $(".phrase").trigger("input");
370 $(".network option[selected]").removeAttr("selected");
371 $(".network option[value=7]").prop("selected", true);
372 $(".network").trigger("change");
374 // check the address is generated correctly
375 waitForGenerate(function() {
376 var actual
= page
.evaluate(function() {
377 return $(".address:first").text();
379 if (actual
!= expected
) {
380 console
.log("Viacoin testnet address is incorrect");
381 console
.log("Expected: " + expected
);
382 console
.log("Actual: " + actual
);
390 // Network can be set to jumbucks
392 page
.open(url
, function(status
) {
393 // set the phrase and coin
394 var expected
= "JLEXccwDXADK4RxBPkRez7mqsHVoJBEUew";
395 page
.evaluate(function() {
396 $(".phrase").val("abandon abandon ability");
397 $(".phrase").trigger("input");
398 $(".network option[selected]").removeAttr("selected");
399 $(".network option[value=8]").prop("selected", true);
400 $(".network").trigger("change");
402 // check the address is generated correctly
403 waitForGenerate(function() {
404 var actual
= page
.evaluate(function() {
405 return $(".address:first").text();
407 if (actual
!= expected
) {
408 console
.log("Jumbucks address is incorrect");
409 console
.log("Expected: " + expected
);
410 console
.log("Actual: " + actual
);
418 // Network can be set to clam
420 page
.open(url
, function(status
) {
421 // set the phrase and coin
422 var expected
= "xCp4sakjVx4pUAZ6cBCtuin8Ddb6U1sk9y";
423 page
.evaluate(function() {
424 $(".phrase").val("abandon abandon ability");
425 $(".phrase").trigger("input");
426 $(".network option[selected]").removeAttr("selected");
427 $(".network option[value=9]").prop("selected", true);
428 $(".network").trigger("change");
430 // check the address is generated correctly
431 waitForGenerate(function() {
432 var actual
= page
.evaluate(function() {
433 return $(".address:first").text();
435 if (actual
!= expected
) {
436 console
.log("CLAM address is incorrect");
437 console
.log("Expected: " + expected
);
438 console
.log("Actual: " + actual
);
446 // BIP39 seed is set from phrase
448 page
.open(url
, function(status
) {
450 var expected
= "20da140d3dd1df8713cefcc4d54ce0e445b4151027a1ab567b832f6da5fcc5afc1c3a3f199ab78b8e0ab4652efd7f414ac2c9a3b81bceb879a70f377aa0a58f3";
451 page
.evaluate(function() {
452 $(".phrase").val("abandon abandon ability");
453 $(".phrase").trigger("input");
455 // check the address is generated correctly
456 waitForGenerate(function() {
457 var actual
= page
.evaluate(function() {
458 return $(".seed").val();
460 if (actual
!= expected
) {
461 console
.log("BIP39 seed is incorrectly generated from mnemonic");
462 console
.log("Expected: " + expected
);
463 console
.log("Actual: " + actual
);
471 // BIP32 root key is set from phrase
473 page
.open(url
, function(status
) {
475 var expected
= "xprv9s21ZrQH143K2jkGDCeTLgRewT9F2pH5JZs2zDmmjXes34geVnFiuNa8KTvY5WoYvdn4Ag6oYRoB6cXtc43NgJAEqDXf51xPm6fhiMCKwpi";
476 page
.evaluate(function() {
477 $(".phrase").val("abandon abandon ability");
478 $(".phrase").trigger("input");
480 // check the address is generated correctly
481 waitForGenerate(function() {
482 var actual
= page
.evaluate(function() {
483 return $(".root-key").val();
485 if (actual
!= expected
) {
486 console
.log("Root key is incorrectly generated from mnemonic");
487 console
.log("Expected: " + expected
);
488 console
.log("Actual: " + actual
);
496 // TODO finish these tests
498 // Tabs show correct addresses when changed
500 // BIP44 derivation path is shown
501 // BIP44 extended private key is shown
502 // BIP44 extended public key is shown
503 // BIP44 purpose field changes address list
504 // BIP44 coin field changes address list
505 // BIP44 account field changes address list
506 // BIP44 external/internal field changes address list
508 // BIP32 derivation path can be set
509 // BIP32 can use hardened derivation paths
510 // BIP32 extended private key is shown
511 // BIP32 extended public key is shown
513 // Derivation path is shown in table
514 // Derivation path for address can be hardened
515 // Derivation path visibility can be toggled
517 // Addresses are shown in order of derivation path
518 // Address visibility can be toggled
519 // Private key is shown
520 // Private key visibility can be toggled
522 // More addresses can be generated
523 // A custom number of additional addresses can be generated
524 // Additional addresses are shown in order of derivation path
526 // BIP32 root key can be set by the user
527 // Setting BIP32 root key clears the existing phrase, passphrase and seed
528 // Clearing of phrase, passphrase and seed can be cancelled by user
529 // Custom BIP32 root key is used when changing the derivation path
531 // Incorrect mnemonic shows error
532 // Incorrect word shows suggested replacement
533 // Incorrect BIP32 root key shows error
534 // Derivation path not starting with m shows error
535 // Derivation path containing invalid characters shows useful error
537 // Github Issue 11: Default word length is 15
538 // https://github.com/dcpos/bip39/issues/11
540 // Github Issue 12: Generate more rows with private keys hidden
541 // https://github.com/dcpos/bip39/issues/12
543 // Github Issue 19: Mnemonic is not sensitive to whitespace
544 // https://github.com/dcpos/bip39/issues/19
546 // Github Issue 23: Use correct derivation path when changing tabs
547 // https://github.com/dcpos/bip39/issues/23
551 console
.log("Running tests...");