]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/BIP39.git/blob - tests.js
Test suite using phantomjs
[perso/Immae/Projets/Cryptomonnaies/BIP39.git] / tests.js
1 // Usage:
2 // $ phantomjs tests.js
3
4
5 var page = require('webpage').create();
6 var url = 'src/index.html';
7
8 page.onResourceError = function(e) {
9 console.log("Error loading " + e.url);
10 phantom.exit();
11 }
12
13 function fail() {
14 console.log("Failed");
15 phantom.exit();
16 }
17
18 function next() {
19 if (tests.length > 0) {
20 var testsStr = tests.length == 1 ? "test" : "tests";
21 console.log(tests.length + " " + testsStr + " remaining");
22 tests.shift()();
23 }
24 else {
25 console.log("Finished with 0 failures");
26 phantom.exit();
27 }
28 }
29
30 tests = [
31
32 // Page loads with status of 'success'
33 function() {
34 page.open(url, function(status) {
35 if (status != "success") {
36 console.log("Page did not load with status 'success'");
37 fail();
38 }
39 next();
40 });
41 },
42
43 // Page has text
44 function() {
45 page.open(url, function(status) {
46 var content = page.evaluate(function() {
47 return document.body.textContent.trim();
48 });
49 if (!content) {
50 console.log("Page does not have text");
51 fail();
52 }
53 next();
54 });
55 },
56
57 // Entering mnemonic generates addresses
58 function() {
59 page.open(url, function(status) {
60 var expected = "1Di3Vp7tBWtyQaDABLAjfWtF6V7hYKJtug";
61 // set the phrase
62 page.evaluate(function() {
63 $(".phrase").val("abandon abandon ability").trigger("input");
64 });
65 // get the address
66 setTimeout(function() {
67 var actual = page.evaluate(function() {
68 return $(".address:first").text();
69 });
70 if (actual != expected) {
71 console.log("Mnemonic did not generate address");
72 console.log("Expected: " + expected);
73 console.log("Got: " + actual);
74 fail();
75 }
76 next();
77 }, 1000);
78 });
79 },
80
81 // Random button generates random mnemonic
82 function() {
83 page.open(url, function(status) {
84 // check initial phrase is empty
85 var phrase = page.evaluate(function() {
86 return $(".phrase").text();
87 });
88 if (phrase != "") {
89 console.log("Initial phrase is not blank");
90 fail();
91 }
92 // press the 'generate' button
93 page.evaluate(function() {
94 $(".generate").click();
95 });
96 // get the new phrase
97 setTimeout(function() {
98 var phrase = page.evaluate(function() {
99 return $(".phrase").val();
100 });
101 if (phrase.length <= 0) {
102 console.log("Phrase not generated by pressing button");
103 fail();
104 }
105 next();
106 }, 1000);
107 });
108 },
109
110 // Mnemonic length can be customized
111 function() {
112 page.open(url, function(status) {
113 // set the length to 6
114 var expectedLength = 6;
115 page.evaluate(function() {
116 $(".strength").val(expectedLength);
117 });
118 // press the 'generate' button
119 page.evaluate(function() {
120 $(".generate").click();
121 });
122 // check the new phrase is six words long
123 setTimeout(function() {
124 var actualLength = page.evaluate(function() {
125 var words = $(".phrase").val().split(" ");
126 return words.length;
127 });
128 if (actualLength != expectedLength) {
129 console.log("Phrase not generated with correct length");
130 console.log("Expected: " + expectedLength);
131 console.log("Actual: " + actualLength);
132 fail();
133 }
134 }, 200);
135 next();
136 });
137 },
138
139 // TODO finish these tests
140
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
153
154 // Tabs show correct addresses when changed
155
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
163
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
168
169 // Derivation path is shown in table
170 // Derivation path for address can be hardened
171 // Derivation path visibility can be toggled
172 // Address is shown
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
177
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
181
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
185
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
191
192 // Github Issue 11: Default word length is 15
193 // https://github.com/dcpos/bip39/issues/11
194
195 // Github Issue 12: Generate more rows with private keys hidden
196 // https://github.com/dcpos/bip39/issues/12
197
198 // Github Issue 19: Mnemonic is not sensitive to whitespace
199 // https://github.com/dcpos/bip39/issues/19
200
201 // Github Issue 23: Use correct derivation path when changing tabs
202 // https://github.com/dcpos/bip39/issues/23
203
204 ];
205
206 console.log("Running tests...");
207 next();