Added wordlist generation testing.
This commit is contained in:
parent
b61643fecb
commit
7004cd0b92
@ -8,4 +8,5 @@ module.exports = {
|
|||||||
providers: require('./test-providers'),
|
providers: require('./test-providers'),
|
||||||
utils: require('./test-utils'),
|
utils: require('./test-utils'),
|
||||||
wallet: require('./test-wallet'),
|
wallet: require('./test-wallet'),
|
||||||
|
wordlists: require('./test-wordlists'),
|
||||||
}
|
}
|
||||||
|
33
tests/test-wordlists.js
Normal file
33
tests/test-wordlists.js
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var assert = require('assert');
|
||||||
|
|
||||||
|
var utils = require('./utils');
|
||||||
|
|
||||||
|
if (global.ethers) {
|
||||||
|
console.log('Using global ethers; ' + __filename);
|
||||||
|
var ethers = global.ethers;
|
||||||
|
} else {
|
||||||
|
var ethers = require('..');
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkWordlist(filename, wordlist) {
|
||||||
|
var words = utils.loadText(filename).split('\n');
|
||||||
|
it('matches wordlists for ' + wordlist.locale, function() {
|
||||||
|
for (var i = 0; i < 2048; i++) {
|
||||||
|
var actual = wordlist.getWord(i);
|
||||||
|
var expected = words[i];
|
||||||
|
assert.equal(actual, expected, 'failed to match word ' + i + ': ' + words[i] + ' !=' + wordlist.getWord(i));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('Check Wordlists', function() {
|
||||||
|
checkWordlist('./wordlist-generation/lang-en.txt', ethers.wordlists.en);
|
||||||
|
checkWordlist('./wordlist-generation/lang-it.txt', ethers.wordlists.it);
|
||||||
|
checkWordlist('./wordlist-generation/lang-ja.txt', ethers.wordlists.ja);
|
||||||
|
checkWordlist('./wordlist-generation/lang-ko.txt', ethers.wordlists.ko);
|
||||||
|
checkWordlist('./wordlist-generation/lang-zh_cn.txt', ethers.wordlists.zh);
|
||||||
|
checkWordlist('./wordlist-generation/lang-zh_cn.txt', ethers.wordlists.zh_cn);
|
||||||
|
checkWordlist('./wordlist-generation/lang-zh_tw.txt', ethers.wordlists.zh_tw);
|
||||||
|
});
|
@ -54,6 +54,10 @@
|
|||||||
|
|
||||||
<!-- Load the browser dist ethers package -->
|
<!-- Load the browser dist ethers package -->
|
||||||
<script type="text/javascript" src="../dist/ethers.min.js"></script>
|
<script type="text/javascript" src="../dist/ethers.min.js"></script>
|
||||||
|
<script type="text/javascript" src="../dist/wordlist-it.js"></script>
|
||||||
|
<script type="text/javascript" src="../dist/wordlist-ja.js"></script>
|
||||||
|
<script type="text/javascript" src="../dist/wordlist-ko.js"></script>
|
||||||
|
<script type="text/javascript" src="../dist/wordlist-zh.js"></script>
|
||||||
|
|
||||||
<!-- Our test cases; compiled by browserify -->
|
<!-- Our test cases; compiled by browserify -->
|
||||||
<script src="./dist/tests.js" type="text/javascript"></script>
|
<script src="./dist/tests.js" type="text/javascript"></script>
|
||||||
@ -61,7 +65,7 @@
|
|||||||
<!-- Run the test cases! -->
|
<!-- Run the test cases! -->
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
// Use this to focus on specific test cases
|
// Use this to focus on specific test cases
|
||||||
//mocha.grep(new RegExp('Test Transaction Signing and Parsing parses and signs transaction - random-999')).run();
|
//mocha.grep(new RegExp('wordlists')).run();
|
||||||
mocha.run();
|
mocha.run();
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
@ -103,6 +103,11 @@ function loadJson(filename) {
|
|||||||
return JSON.parse(fs.readFileSync(filename).toString());
|
return JSON.parse(fs.readFileSync(filename).toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function loadText(filename) {
|
||||||
|
var filename = path.resolve(__dirname, filename);
|
||||||
|
return fs.readFileSync(filename).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
randomBytes: randomBytes,
|
randomBytes: randomBytes,
|
||||||
@ -120,4 +125,5 @@ module.exports = {
|
|||||||
saveTests: saveTests,
|
saveTests: saveTests,
|
||||||
|
|
||||||
loadJson: loadJson,
|
loadJson: loadJson,
|
||||||
|
loadText: loadText,
|
||||||
}
|
}
|
||||||
|
2048
tests/wordlist-generation/lang-en.txt
Normal file
2048
tests/wordlist-generation/lang-en.txt
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user