-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: validate mnemonic phrase against BIP39 wordlist (#739)
Co-authored-by: Zachary Johnson <[email protected]> Co-authored-by: theborakompanioni <[email protected]>
- Loading branch information
1 parent
24a9026
commit 69e8fa7
Showing
4 changed files
with
2,099 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,37 @@ | ||
import { render, screen } from '../testUtils' | ||
import { Bip39MnemonicWordInput, MnemonicWordInputProps } from './MnemonicWordInput' | ||
|
||
const NOOP = () => {} | ||
|
||
describe('<Bip39MnemonicWordInput />', () => { | ||
const validBip39MnemonicWord = 'abandon' | ||
const invalidBip39MnemonicWord = 'not a bip39 word!' | ||
|
||
const setup = (props: MnemonicWordInputProps) => { | ||
render(<Bip39MnemonicWordInput {...props} />) | ||
} | ||
|
||
it('should render without errors', async () => { | ||
setup({ index: 0, value: '', setValue: NOOP }) | ||
|
||
expect(await screen.findByTestId('mnemonic-word-input')).toBeVisible() | ||
}) | ||
|
||
it('should report if input is NOT included in the BIP-39 wordlist', async () => { | ||
setup({ index: 0, value: invalidBip39MnemonicWord, setValue: NOOP }) | ||
|
||
const input = await screen.findByTestId('mnemonic-word-input') | ||
expect(input).toBeVisible() | ||
expect(input).toHaveClass('is-invalid') | ||
expect(input).not.toHaveClass('is-valid') | ||
}) | ||
|
||
it('should report if input IS INCLUDED in the BIP-39 wordlist', async () => { | ||
setup({ index: 0, value: validBip39MnemonicWord, setValue: NOOP }) | ||
|
||
const input = await screen.findByTestId('mnemonic-word-input') | ||
expect(input).toBeVisible() | ||
expect(input).toHaveClass('is-valid') | ||
expect(input).not.toHaveClass('is-invalid') | ||
}) | ||
}) |
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
Oops, something went wrong.