Skip to content

Commit

Permalink
[DDW-614] add unbound mnemonics test case
Browse files Browse the repository at this point in the history
  • Loading branch information
DominikGuzei committed Apr 8, 2019
1 parent 681394e commit 13b5ebd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
6 changes: 5 additions & 1 deletion features/mnemonics-generation-and-validation.feature
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
@unit @slow
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
22 changes: 21 additions & 1 deletion features/tests/unit/steps/mnemonics-steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { generateAccountMnemonics } from '../../../../source/renderer/app/api/ut
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
) {
Expand All @@ -15,8 +18,25 @@ Given('I generate {int} wallet recovery mnemonics', function(

Then('all generated wallet recovery mnemonics should be valid', function() {
for (const mnemonic of this.context.mnemonics) {
if (!isValidMnemonic(mnemonic, WALLET_RECOVERY_PHRASE_WORD_COUNT)) {
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.');
}
}
);
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"test": "NODE_ENV=test yarn build && yarn test:unit && yarn test:ui",
"test:unit": "yarn cucumber --require 'features/tests/unit/**/*.js' --tags '@unit and not @skip'",
"test:unit:watch": "nodemon --watch source --watch features --exec \"yarn test:unit --tags '@unit and @watch'\"",
"test:unit:unbound": "yarn cucumber --require 'features/tests/unit/**/*.js' --tags '@unbound and not @skip'",
"test:ui": "yarn cucumber --require 'features/tests/ui/**/*.js' --tags '@ui and not @skip'",
"test:ui:watch": "gulp test:ui:watch",
"cucumber": "cross-env NODE_ENV=test cucumber-js --require-module @babel/register -f node_modules/cucumber-pretty --format-options '{\"snippetInterface\": \"async-await\"}'",
Expand Down

0 comments on commit 13b5ebd

Please sign in to comment.