-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for failedSeedPhraseRequirements
- Loading branch information
1 parent
6103dec
commit f5b4480
Showing
3 changed files
with
30 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// eslint-disable-next-line import/prefer-default-export | ||
export const failedSeedPhraseRequirements = seed => { | ||
const wordCount = seed.split(/\s/u).length; | ||
return wordCount % 3 !== 0 || wordCount > 24 || wordCount < 12; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { failedSeedPhraseRequirements } from './validators'; | ||
|
||
const VALID_24 = | ||
'verb middle giant soon wage common wide tool gentle garlic issue nut retreat until album recall expire bronze bundle live accident expect dry cook'; | ||
const VALID_12 = VALID_24.split(' ') | ||
.splice(0, 12) | ||
.join(' '); | ||
|
||
describe('failedSeedPhraseRequirements', () => { | ||
it('Should pass for 12 word mnemonic', () => { | ||
expect(failedSeedPhraseRequirements(VALID_12)).toEqual(false); | ||
}); | ||
it('Should pass for 24 word mnemonic', () => { | ||
expect(failedSeedPhraseRequirements(VALID_24)).toEqual(false); | ||
}); | ||
it('Should fail for 12 + 1 word mnemonic', () => { | ||
const plus_one = VALID_12 + ' lol'; | ||
expect(failedSeedPhraseRequirements(plus_one)).toEqual(true); | ||
}); | ||
it('Should fail for 24 + 1 word mnemonic', () => { | ||
const plus_one = VALID_24 + ' lol'; | ||
expect(failedSeedPhraseRequirements(plus_one)).toEqual(true); | ||
}); | ||
}); |