2019-05-14 18:25:46 -04:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import assert from 'assert';
|
|
|
|
|
2019-05-14 18:42:45 -04:00
|
|
|
import { ethers } from "ethers";
|
2019-05-14 18:25:46 -04:00
|
|
|
import { loadTests, TestCase } from "@ethersproject/testcases";
|
|
|
|
|
|
|
|
|
|
|
|
function checkWordlist(content: string, wordlist: ethers.Wordlist): void {
|
|
|
|
let words = content.split('\n');
|
|
|
|
it('matches wordlists for ' + wordlist.locale, function() {
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
});
|
2020-07-13 07:30:49 -04:00
|
|
|
|
|
|
|
it ("splitting and joining are equivalent", function() {
|
|
|
|
const words: Array<string> = [ ];
|
|
|
|
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:25:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
describe('Check Wordlists', function() {
|
|
|
|
let tests: Array<TestCase.Wordlist> = loadTests("wordlists");
|
|
|
|
tests.forEach((test) => {
|
|
|
|
let wordlist = (<{ [ locale: string ]: ethers.Wordlist }>(ethers.wordlists))[test.locale];
|
2020-11-14 17:42:36 -05:00
|
|
|
if (wordlist == null) { return; }
|
2019-05-14 18:25:46 -04:00
|
|
|
checkWordlist(test.content, wordlist);
|
|
|
|
});
|
|
|
|
});
|