forked from input-output-hk/daedalus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request input-output-hk#1379 from input-output-hk/chore/dd…
…w-614-add-unit-tests-for-mnemonics [DDW-614] Add unit tests for mnemonics
- Loading branch information
Showing
5 changed files
with
67 additions
and
0 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
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,13 @@ | ||
Feature: Mnemonics generation and validation | ||
|
||
As a developer I want to be sure our mnemonic | ||
(12-word recovery phrase) is correctly generated/validated | ||
|
||
@unit @slow | ||
Scenario: All generated wallet recovery mnemonics are valid | ||
Given I generate 10000 wallet recovery mnemonics | ||
Then all generated wallet recovery mnemonics should be valid | ||
|
||
@unbound @mnemonics | ||
Scenario: Unbound manual test run gives no invalid mnemeonics | ||
Given I generate and validate an unbound number of wallet recovery mnemonics |
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,42 @@ | ||
import { Given, When, Then } from 'cucumber'; | ||
import { expect } from 'chai'; | ||
import { range } from 'lodash'; | ||
import { generateAccountMnemonics } from '../../../../source/renderer/app/api/utils/mnemonics'; | ||
import { isValidMnemonic } from '../../../../source/common/crypto/decrypt'; | ||
import { WALLET_RECOVERY_PHRASE_WORD_COUNT } from '../../../../source/renderer/app/config/cryptoConfig'; | ||
|
||
const isValidWalletRecoveryPhrase = mnemonic => | ||
isValidMnemonic(mnemonic, WALLET_RECOVERY_PHRASE_WORD_COUNT); | ||
|
||
Given('I generate {int} wallet recovery mnemonics', function( | ||
numberOfMnemonics | ||
) { | ||
this.context.mnemonics = range(numberOfMnemonics).map(() => | ||
generateAccountMnemonics().join(' ') | ||
); | ||
}); | ||
|
||
Then('all generated wallet recovery mnemonics should be valid', function() { | ||
for (const mnemonic of this.context.mnemonics) { | ||
if (!isValidWalletRecoveryPhrase(mnemonic)) { | ||
throw new Error(`"${mnemonic}" is not valid`); | ||
} | ||
} | ||
}); | ||
|
||
Given( | ||
'I generate and validate an unbound number of wallet recovery mnemonics', | ||
function() { | ||
let numberOfTestsExecuted = 0; | ||
while (true) { | ||
const mnemonic = generateAccountMnemonics().join(' '); | ||
if (!isValidWalletRecoveryPhrase(mnemonic)) { | ||
throw new Error(`"${mnemonic}" is not valid`); | ||
} | ||
numberOfTestsExecuted++; | ||
process.stdout.clearLine(); | ||
process.stdout.cursorTo(0); | ||
process.stdout.write(numberOfTestsExecuted + ' mnemonics validated.'); | ||
} | ||
} | ||
); |
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