Added wordlist generation testing.

This commit is contained in:
Richard Moore 2018-07-16 00:19:50 -04:00
parent b61643fecb
commit 7004cd0b92
No known key found for this signature in database
GPG Key ID: 525F70A6FCABC295
5 changed files with 2093 additions and 1 deletions

@ -8,4 +8,5 @@ module.exports = {
providers: require('./test-providers'),
utils: require('./test-utils'),
wallet: require('./test-wallet'),
wordlists: require('./test-wordlists'),
}

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 -->
<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 -->
<script src="./dist/tests.js" type="text/javascript"></script>
@ -61,7 +65,7 @@
<!-- Run the test cases! -->
<script type="text/javascript">
// 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();
</script>
</body>

@ -103,6 +103,11 @@ function loadJson(filename) {
return JSON.parse(fs.readFileSync(filename).toString());
}
function loadText(filename) {
var filename = path.resolve(__dirname, filename);
return fs.readFileSync(filename).toString();
}
module.exports = {
randomBytes: randomBytes,
@ -120,4 +125,5 @@ module.exports = {
saveTests: saveTests,
loadJson: loadJson,
loadText: loadText,
}

File diff suppressed because it is too large Load Diff