2019-05-14 18:48:48 -04:00
|
|
|
'use strict';
|
2019-08-25 02:39:20 -04:00
|
|
|
import assert from 'assert';
|
|
|
|
import { ethers } from "ethers";
|
|
|
|
import { loadTests } from "@ethersproject/testcases";
|
2019-05-14 18:48:48 -04:00
|
|
|
function checkWordlist(content, wordlist) {
|
2019-08-25 02:39:20 -04:00
|
|
|
let words = content.split('\n');
|
2019-05-14 18:48:48 -04:00
|
|
|
it('matches wordlists for ' + wordlist.locale, function () {
|
2019-08-25 02:39:20 -04:00
|
|
|
for (let i = 0; i < 2048; i++) {
|
|
|
|
let actual = wordlist.getWord(i);
|
|
|
|
let expected = words[i];
|
|
|
|
assert.equal(actual, expected, 'failed to match word ' + i + ': ' + words[i] + ' !=' + wordlist.getWord(i));
|
2019-05-14 18:48:48 -04:00
|
|
|
}
|
|
|
|
});
|
2020-07-13 08:03:56 -04:00
|
|
|
it("splitting and joining are equivalent", function () {
|
|
|
|
const words = [];
|
|
|
|
for (let i = 0; i < 12; i++) {
|
|
|
|
words.push(wordlist.getWord(i));
|
|
|
|
}
|
|
|
|
const phrase = wordlist.join(words);
|
|
|
|
const words2 = wordlist.split(phrase);
|
|
|
|
const phrase2 = wordlist.join(words2);
|
|
|
|
assert.deepStrictEqual(words2, words, "split words");
|
|
|
|
assert.deepStrictEqual(phrase2, phrase, "re-joined words");
|
|
|
|
});
|
2019-05-14 18:48:48 -04:00
|
|
|
}
|
|
|
|
describe('Check Wordlists', function () {
|
2019-08-25 02:39:20 -04:00
|
|
|
let tests = loadTests("wordlists");
|
|
|
|
tests.forEach((test) => {
|
|
|
|
let wordlist = (ethers.wordlists)[test.locale];
|
2020-11-16 23:07:24 -05:00
|
|
|
if (wordlist == null) {
|
|
|
|
return;
|
|
|
|
}
|
2019-05-14 18:48:48 -04:00
|
|
|
checkWordlist(test.content, wordlist);
|
|
|
|
});
|
|
|
|
});
|
2020-07-13 08:03:56 -04:00
|
|
|
//# sourceMappingURL=test-wordlists.js.map
|