Skip to content

Commit

Permalink
Add tests for failedSeedPhraseRequirements
Browse files Browse the repository at this point in the history
  • Loading branch information
rickycodes committed Sep 25, 2020
1 parent d3ab579 commit 2990f3f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
6 changes: 1 addition & 5 deletions app/components/Views/ImportFromSeed/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import TermsAndConditions from '../TermsAndConditions';
import zxcvbn from 'zxcvbn';
import Icon from 'react-native-vector-icons/FontAwesome';
import Device from '../../../util/Device';
import { failedSeedPhraseRequirements } from '../../../util/validators';
import { OutlinedTextField } from 'react-native-material-textfield';
import {
BIOMETRY_CHOICE,
Expand Down Expand Up @@ -168,11 +169,6 @@ const styles = StyleSheet.create({

const PASSCODE_NOT_SET_ERROR = 'Error: Passcode not set.';

const failedSeedPhraseRequirements = seed => {
const wordCount = seed.split(/\s/u).length;
return wordCount % 3 !== 0 || wordCount > 24 || wordCount < 12;
};

/**
* View where users can set restore their account
* using a seed phrase
Expand Down
5 changes: 5 additions & 0 deletions app/util/validators.js
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;
};
24 changes: 24 additions & 0 deletions app/util/validators.test.js
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 pass for 24 + 1 word mnemonic', () => {
const plus_one = VALID_24 + ' lol';
expect(failedSeedPhraseRequirements(plus_one)).toEqual(true);
});
});

0 comments on commit 2990f3f

Please sign in to comment.