Skip to content

Commit 40a5209

Browse files
committed
Add tests for failedSeedPhraseRequirements
1 parent d3ab579 commit 40a5209

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

app/components/Views/ImportFromSeed/index.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import TermsAndConditions from '../TermsAndConditions';
3030
import zxcvbn from 'zxcvbn';
3131
import Icon from 'react-native-vector-icons/FontAwesome';
3232
import Device from '../../../util/Device';
33+
import { failedSeedPhraseRequirements } from '../../../util/validators';
3334
import { OutlinedTextField } from 'react-native-material-textfield';
3435
import {
3536
BIOMETRY_CHOICE,
@@ -168,11 +169,6 @@ const styles = StyleSheet.create({
168169

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

171-
const failedSeedPhraseRequirements = seed => {
172-
const wordCount = seed.split(/\s/u).length;
173-
return wordCount % 3 !== 0 || wordCount > 24 || wordCount < 12;
174-
};
175-
176172
/**
177173
* View where users can set restore their account
178174
* using a seed phrase

app/util/validators.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// eslint-disable-next-line import/prefer-default-export
2+
export const failedSeedPhraseRequirements = seed => {
3+
const wordCount = seed.split(/\s/u).length;
4+
return wordCount % 3 !== 0 || wordCount > 24 || wordCount < 12;
5+
};

app/util/validators.test.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { failedSeedPhraseRequirements } from './validators';
2+
3+
const VALID_24 =
4+
'verb middle giant soon wage common wide tool gentle garlic issue nut retreat until album recall expire bronze bundle live accident expect dry cook';
5+
const VALID_12 = VALID_24.split(' ')
6+
.splice(0, 12)
7+
.join(' ');
8+
9+
describe('failedSeedPhraseRequirements', () => {
10+
it('Should pass for 12 word mnemonic', () => {
11+
expect(failedSeedPhraseRequirements(VALID_12)).toEqual(false);
12+
});
13+
it('Should pass for 24 word mnemonic', () => {
14+
expect(failedSeedPhraseRequirements(VALID_24)).toEqual(false);
15+
});
16+
it('Should fail for 12 + 1 word mnemonic', () => {
17+
const plus_one = VALID_12 + ' lol';
18+
expect(failedSeedPhraseRequirements(plus_one)).toEqual(true);
19+
});
20+
it('Should fail for 24 + 1 word mnemonic', () => {
21+
const plus_one = VALID_24 + ' lol';
22+
expect(failedSeedPhraseRequirements(plus_one)).toEqual(true);
23+
});
24+
});

0 commit comments

Comments
 (0)