]>
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';
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 option[selected]").removeAttr("selected");
117 $(".strength option[value=6]").prop("selected", true);
119 // press the 'generate' button
120 page
.evaluate(function() {
121 $(".generate").click();
123 // check the new phrase is six words long
124 setTimeout(function() {
125 var actualLength
= page
.evaluate(function() {
126 var words
= $(".phrase").val().split(" ");
129 if (actualLength
!= expectedLength
) {
130 console
.log("Phrase not generated with correct length");
131 console
.log("Expected: " + expectedLength
);
132 console
.log("Actual: " + actualLength
);
140 // Passphrase can be set
142 page
.open(url
, function(status
) {
143 // set the phrase and passphrase
144 var expected
= "15pJzUWPGzR7avffV9nY5by4PSgSKG9rba";
145 page
.evaluate(function() {
146 $(".phrase").val("abandon abandon ability");
147 $(".passphrase").val("secure_passphrase").trigger("input");
149 // check the address is generated correctly
150 setTimeout(function() {
151 var actual
= page
.evaluate(function() {
152 return $(".address:first").text();
154 if (actual
!= expected
) {
155 console
.log("Passphrase results in wrong address");
156 console
.log("Expected: " + expected
);
157 console
.log("Actual: " + actual
);
165 // Network can be set to bitcoin testnet
167 page
.open(url
, function(status
) {
168 // set the phrase and passphrase
169 var expected
= "mucaU5iiDaJDb69BHLeDv8JFfGiyg2nJKi";
170 page
.evaluate(function() {
171 $(".phrase").val("abandon abandon ability");
172 $(".phrase").trigger("input");
173 $(".network option[selected]").removeAttr("selected");
174 $(".network option[value=1]").prop("selected", true);
175 $(".network").trigger("change");
177 // check the address is generated correctly
178 setTimeout(function() {
179 var actual
= page
.evaluate(function() {
180 return $(".address:first").text();
182 if (actual
!= expected
) {
183 console
.log("Bitcoin testnet address is incorrect");
184 console
.log("Expected: " + expected
);
185 console
.log("Actual: " + actual
);
193 // TODO finish these tests
194 // Network can be set to litecoin
195 // Network can be set to dogecoin
196 // Network can be set to shadowcash
197 // Network can be set to shadowcash testnet
198 // Network can be set to viacoin
199 // Network can be set to viacoin testnet
200 // Network can be set to jumbucks
201 // Network can be set to clam
202 // BIP39 seed is set from phrase
203 // BIP32 root key is set from phrase
205 // Tabs show correct addresses when changed
207 // BIP44 derivation path is shown
208 // BIP44 extended private key is shown
209 // BIP44 extended public key is shown
210 // BIP44 purpose field changes address list
211 // BIP44 coin field changes address list
212 // BIP44 account field changes address list
213 // BIP44 external/internal field changes address list
215 // BIP32 derivation path can be set
216 // BIP32 can use hardened derivation paths
217 // BIP32 extended private key is shown
218 // BIP32 extended public key is shown
220 // Derivation path is shown in table
221 // Derivation path for address can be hardened
222 // Derivation path visibility can be toggled
224 // Addresses are shown in order of derivation path
225 // Address visibility can be toggled
226 // Private key is shown
227 // Private key visibility can be toggled
229 // More addresses can be generated
230 // A custom number of additional addresses can be generated
231 // Additional addresses are shown in order of derivation path
233 // BIP32 root key can be set by the user
234 // Setting BIP32 root key clears the existing phrase, passphrase and seed
235 // Clearing of phrase, passphrase and seed can be cancelled by user
236 // Custom BIP32 root key is used when changing the derivation path
238 // Incorrect mnemonic shows error
239 // Incorrect word shows suggested replacement
240 // Incorrect BIP32 root key shows error
241 // Derivation path not starting with m shows error
242 // Derivation path containing invalid characters shows useful error
244 // Github Issue 11: Default word length is 15
245 // https://github.com/dcpos/bip39/issues/11
247 // Github Issue 12: Generate more rows with private keys hidden
248 // https://github.com/dcpos/bip39/issues/12
250 // Github Issue 19: Mnemonic is not sensitive to whitespace
251 // https://github.com/dcpos/bip39/issues/19
253 // Github Issue 23: Use correct derivation path when changing tabs
254 // https://github.com/dcpos/bip39/issues/23
258 console
.log("Running tests...");