forked from openethereum/wordlist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.spec.js
70 lines (56 loc) · 2.05 KB
/
index.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
/* global describe,it */
const dictionary = require('./res/wordlist.json')
const { expect } = require('chai')
const {
randomNumber,
randomWord,
randomPhrase,
verifyPhrase
} = require('./')
describe('wordlist', () => {
describe('randomNumber', () => {
it('generates numbers in range', () => {
for (let i = 0; i < 100; i++) {
const number = randomNumber(7777)
expect(number).to.be.at.least(0)
expect(number).to.be.below(7777)
expect(number % 1).to.be.equal(0)
}
})
})
describe('randomWord', () => {
it('generates a random word from the dictionary', () => {
const word = randomWord()
expect(dictionary.includes(word)).to.be.equal(true)
})
})
describe('randomPhrase', () => {
it('generates a random phrase from the dictionary', () => {
const phrase = randomPhrase(7).split(' ')
expect(phrase.length).to.be.equal(7)
phrase.forEach((word) => {
expect(dictionary.includes(word)).to.be.equal(true)
})
})
})
describe('verifyPhrase', () => {
it('verifies too short phrase', () => {
const phrase = randomPhrase(7)
expect(verifyPhrase(phrase, 7)).to.be.equal(true)
expect(() => verifyPhrase(phrase, 12)).to.throw(Error, 'too short')
expect(() => verifyPhrase('xxx', 0)).to.throw(Error, 'not in the dictionary')
})
})
})