This repository has been archived by the owner on Apr 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Create transaction register second passhrase - Closes #249 #303
Merged
willclarktech
merged 14 commits into
0.3.0
from
249-create_transaction_register_second_passhrase
Oct 26, 2017
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
3bfad7a
:seedling: Add lisk transaction module
10cfe77
:seedling: Add alias to vorpal command creator
0092ac5
:seedling: Add second passphrase to options
5866541
:recycle: Change data to passphrase in encrypt and decrypt tests
b81b4e2
:seedling: :white_check_mark: Add tests to createTransactionRegisterS…
d9a550a
:recycle: Remove getSecondPassphrase function to reuse getPassphrase
a4ee9f2
:seedling: Add display prefix configuration to getPassphrase
52262c1
:recycle: Postreview changes for create transaction register second p…
d8a8432
:recycle: Postreview changes to create transaction register second pa…
900020e
:white_check_mark: transaction register second passphrase test
bd1f373
:house: merge 0.3.0
a1a293d
:recycle: Postreview optimizing tests for create transaction register…
fa26768
:recycle: Refactor tranasction tests, add test to transaction registe…
280f077
:recycle: Rename type utils function and throw error on unsupported t…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* LiskHQ/lisky | ||
* Copyright © 2017 Lisk Foundation | ||
* | ||
* See the LICENSE file at the top-level directory of this distribution | ||
* for licensing information. | ||
* | ||
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation, | ||
* no part of this software, including this file, may be copied, modified, | ||
* propagated, or distributed except according to the terms contained in the | ||
* LICENSE file. | ||
* | ||
* Removal or modification of this copyright notice is prohibited. | ||
* | ||
*/ | ||
import { | ||
getStdIn, | ||
getPassphrase, | ||
getFirstLineFromString, | ||
} from '../utils/input'; | ||
import { createCommand } from '../utils/helpers'; | ||
import commonOptions from '../utils/options'; | ||
import transactions from '../utils/transactions'; | ||
|
||
const description = `Creates a transaction which will register a second passphrase for an existing account if broadcast to the network. | ||
|
||
Examples: | ||
- create transaction register second passphrase | ||
- create transaction 1 | ||
`; | ||
|
||
export const createSignature = ( | ||
[passphrase, secondPassphrase], | ||
) => transactions.createSignature(passphrase, secondPassphrase); | ||
|
||
export const actionCreator = vorpal => async ({ options }) => { | ||
const { | ||
passphrase: passphraseSource, | ||
'second-passphrase': secondPassphraseSource, | ||
} = options; | ||
|
||
return getStdIn({ | ||
passphraseIsRequired: passphraseSource === 'stdin', | ||
dataIsRequired: secondPassphraseSource === 'stdin', | ||
}) | ||
.then(stdIn => getPassphrase(vorpal, passphraseSource, stdIn.passphrase, { shouldRepeat: true }) | ||
.then(passphrase => getPassphrase( | ||
vorpal, | ||
secondPassphraseSource, | ||
getFirstLineFromString(stdIn.data), | ||
{ shouldRepeat: true, displayName: 'your second secret passphrase' }, | ||
) | ||
.then(secondPassphrase => [passphrase, secondPassphrase]), | ||
), | ||
) | ||
.then(createSignature); | ||
}; | ||
|
||
const createTransactionRegisterSecondPassphrase = createCommand({ | ||
command: 'create transaction register second passphrase', | ||
alias: 'create transaction 1', | ||
description, | ||
actionCreator, | ||
options: [ | ||
commonOptions.passphrase, | ||
commonOptions.secondPassphrase, | ||
], | ||
errorPrefix: 'Could not create register second passphrase transaction', | ||
}); | ||
|
||
export default createTransactionRegisterSecondPassphrase; |
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
File renamed without changes.
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
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,24 @@ | ||
/* | ||
* LiskHQ/lisky | ||
* Copyright © 2017 Lisk Foundation | ||
* | ||
* See the LICENSE file at the top-level directory of this distribution | ||
* for licensing information. | ||
* | ||
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation, | ||
* no part of this software, including this file, may be copied, modified, | ||
* propagated, or distributed except according to the terms contained in the | ||
* LICENSE file. | ||
* | ||
* Removal or modification of this copyright notice is prohibited. | ||
* | ||
*/ | ||
import lisk from 'lisk-js'; | ||
|
||
export default Object.assign({}, | ||
lisk.transaction, | ||
lisk.multisignature, | ||
lisk.signature, | ||
lisk.delegate, | ||
lisk.vote, | ||
); |
135 changes: 135 additions & 0 deletions
135
test/specs/commands/createTransactionRegisterSecondPassphrase.js
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,135 @@ | ||
/* | ||
* LiskHQ/lisky | ||
* Copyright © 2017 Lisk Foundation | ||
* | ||
* See the LICENSE file at the top-level directory of this distribution | ||
* for licensing information. | ||
* | ||
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation, | ||
* no part of this software, including this file, may be copied, modified, | ||
* propagated, or distributed except according to the terms contained in the | ||
* LICENSE file. | ||
* | ||
* Removal or modification of this copyright notice is prohibited. | ||
* | ||
*/ | ||
import { setUpInputStubs } from '../../steps/utils'; | ||
import * as given from '../../steps/1_given'; | ||
import * as when from '../../steps/2_when'; | ||
import * as then from '../../steps/3_then'; | ||
|
||
describe('create transaction register second passphrase command', () => { | ||
beforeEach(() => { | ||
setUpInputStubs(); | ||
}); | ||
describe('Given a Vorpal instance with a UI and an active command that can prompt', () => { | ||
beforeEach(given.aVorpalInstanceWithAUIAndAnActiveCommandThatCanPrompt); | ||
describe('Given an action "create transaction register second passphrase"', () => { | ||
beforeEach(given.anAction); | ||
describe('Given a passphrase "minute omit local rare sword knee banner pair rib museum shadow juice"', () => { | ||
beforeEach(given.aPassphrase); | ||
describe('Given a second passphrase "fame spoil quiz garbage mirror envelope island rapid lend year bike adapt"', () => { | ||
beforeEach(given.aSecondPassphrase); | ||
describe('Given a Lisk object that can create transactions', () => { | ||
beforeEach(given.aLiskObjectThatCanCreateTransactions); | ||
describe('Given an options object with passphrase set to unknown source "xxx"', () => { | ||
beforeEach(given.anOptionsObjectWithPassphraseSetToUnknownSource); | ||
describe('When the action is called with the options', () => { | ||
beforeEach(when.theActionIsCalledWithTheOptions); | ||
it('Then it should reject with message "Unknown passphrase source type. Must be one of `file`, or `stdin`."', then.itShouldRejectWithMessage); | ||
}); | ||
}); | ||
describe('Given an options object with second passphrase set to unknown source "xxx"', () => { | ||
beforeEach(given.anOptionsObjectWithSecondPassphraseSetToUnknownSource); | ||
describe('When the action is called with the options', () => { | ||
beforeEach(when.theActionIsCalledWithTheOptions); | ||
it('Then it should reject with message "Unknown second passphrase source type. Must be one of `file`, or `stdin`."', then.itShouldRejectWithMessage); | ||
}); | ||
}); | ||
describe('Given an empty options object', () => { | ||
beforeEach(given.anEmptyOptionsObject); | ||
describe('Given the passphrase and the second passphrase are provided via the prompt', () => { | ||
beforeEach(given.thePassphraseAndTheSecondPassphraseAreProvidedViaThePrompt); | ||
describe('When the action is called with the options', () => { | ||
beforeEach(when.theActionIsCalledWithTheOptions); | ||
it('Then it should not get the passphrase from stdin', then.itShouldNotGetThePassphraseFromStdIn); | ||
it('Then it should get the passphrase using the vorpal instance', then.itShouldGetThePassphraseUsingTheVorpalInstance); | ||
it('Then it should get the passphrase with a repeated prompt', then.itShouldGetThePassphraseWithARepeatedPrompt); | ||
it('Then it should not get the second passphrase from stdin', then.itShouldNotGetTheSecondPassphraseFromStdIn); | ||
it('Then it should get the second passphrase using the vorpal instance', then.itShouldGetTheSecondPassphraseUsingTheVorpalInstance); | ||
it('Then it should get the second passphrase with a repeated prompt', then.itShouldGetTheSecondPassphraseWithARepeatedPrompt); | ||
it('Then it should create a register second passphrase transaction using the passphrase and the second passphrase', then.itShouldCreateARegisterSecondPassphraseTransactionUsingThePassphraseAndTheSecondPassphrase); | ||
it('Then it should resolve to the created transaction', then.itShouldResolveToTheCreatedTransaction); | ||
}); | ||
}); | ||
}); | ||
describe('Given an options object with passphrase set to "stdin"', () => { | ||
beforeEach(given.anOptionsObjectWithPassphraseSetTo); | ||
describe('Given the passphrase is provided via stdin', () => { | ||
beforeEach(given.thePassphraseIsProvidedViaStdIn); | ||
describe('Given the second passphrase is provided via the prompt', () => { | ||
beforeEach(given.theSecondPassphraseIsProvidedViaThePrompt); | ||
describe('When the action is called with the options', () => { | ||
beforeEach(when.theActionIsCalledWithTheOptions); | ||
it('Then it should get the passphrase from stdin', then.itShouldGetThePassphraseFromStdIn); | ||
it('Then it should get the passphrase using the passphrase from stdin', then.itShouldGetThePassphraseUsingThePassphraseFromStdIn); | ||
it('Then it should not get the second passphrase from stdin', then.itShouldNotGetTheSecondPassphraseFromStdIn); | ||
it('Then it should get the second passphrase using the vorpal instance', then.itShouldGetTheSecondPassphraseUsingTheVorpalInstance); | ||
it('Then it should get the second passphrase with a repeated prompt', then.itShouldGetTheSecondPassphraseWithARepeatedPrompt); | ||
it('Then it should create a register second passphrase transaction using the passphrase and the second passphrase', then.itShouldCreateARegisterSecondPassphraseTransactionUsingThePassphraseAndTheSecondPassphrase); | ||
it('Then it should resolve to the created transaction', then.itShouldResolveToTheCreatedTransaction); | ||
}); | ||
}); | ||
}); | ||
}); | ||
describe('Given an options object with passphrase set to "stdin" and second passphrase set to "stdin"', () => { | ||
beforeEach(given.anOptionsObjectWithPassphraseSetToAndSecondPassphraseSetTo); | ||
describe('Given the passphrase and the second passphrase are provided via stdin', () => { | ||
beforeEach(given.thePassphraseAndTheSecondPassphraseAreProvidedViaStdIn); | ||
describe('When the action is called with the options', () => { | ||
beforeEach(when.theActionIsCalledWithTheOptions); | ||
it('Then it should get the passphrase from stdin', then.itShouldGetThePassphraseFromStdIn); | ||
it('Then it should get the passphrase using the passphrase from stdin', then.itShouldGetThePassphraseUsingThePassphraseFromStdIn); | ||
it('Then it should get the second passphrase from stdin', then.itShouldGetTheSecondPassphraseFromStdIn); | ||
it('Then it should get the second passphrase using the second passphrase from stdin', then.itShouldGetTheSecondPassphraseUsingTheSecondPassphraseFromStdIn); | ||
it('Then it should create a register second passphrase transaction using the passphrase and the second passphrase', then.itShouldCreateARegisterSecondPassphraseTransactionUsingThePassphraseAndTheSecondPassphrase); | ||
it('Then it should resolve to the created transaction', then.itShouldResolveToTheCreatedTransaction); | ||
}); | ||
}); | ||
}); | ||
describe('Given an options object with passphrase set to "stdin" and second passphrase set to "file:/path/to/my/password.txt"', () => { | ||
beforeEach(given.anOptionsObjectWithPassphraseSetToAndSecondPassphraseSetTo); | ||
describe('Given the passphrase is provided via stdin', () => { | ||
beforeEach(given.thePassphraseIsProvidedViaStdIn); | ||
describe('When the action is called with the options', () => { | ||
beforeEach(when.theActionIsCalledWithTheOptions); | ||
it('Then it should get the passphrase from stdin', then.itShouldGetThePassphraseFromStdIn); | ||
it('Then it should get the passphrase using the passphrase from stdin', then.itShouldGetThePassphraseUsingThePassphraseFromStdIn); | ||
it('Then it should not get the second passphrase from stdin', then.itShouldNotGetTheSecondPassphraseFromStdIn); | ||
it('Then it should get the second passphrase using the second passphrase source', then.itShouldGetTheSecondPassphraseUsingTheSecondPassphraseSource); | ||
it('Then it should create a register second passphrase transaction using the passphrase and the second passphrase', then.itShouldCreateARegisterSecondPassphraseTransactionUsingThePassphraseAndTheSecondPassphrase); | ||
it('Then it should resolve to the created transaction', then.itShouldResolveToTheCreatedTransaction); | ||
}); | ||
}); | ||
}); | ||
describe('Given an options object with passphrase set to "file:/path/to/my/password.txt" and second passphrase set to "stdin"', () => { | ||
beforeEach(given.anOptionsObjectWithPassphraseSetToAndSecondPassphraseSetTo); | ||
describe('Given the second passphrase is provided via stdin', () => { | ||
beforeEach(given.theSecondPassphraseIsProvidedViaStdIn); | ||
describe('When the action is called with the options', () => { | ||
beforeEach(when.theActionIsCalledWithTheOptions); | ||
it('Then it should not get the passphrase from stdin', then.itShouldNotGetThePassphraseFromStdIn); | ||
it('Then it should get the passphrase from the passphrase source', then.itShouldGetThePassphraseUsingThePassphraseSource); | ||
it('Then it should get the second passphrase from stdin', then.itShouldGetTheSecondPassphraseFromStdIn); | ||
it('Then it should get the second passphrase using the second passphrase from stdin', then.itShouldGetTheSecondPassphraseUsingTheSecondPassphraseFromStdIn); | ||
it('Then it should create a register second passphrase transaction using the passphrase and the second passphrase', then.itShouldCreateARegisterSecondPassphraseTransactionUsingThePassphraseAndTheSecondPassphrase); | ||
it('Then it should resolve to the created transaction', then.itShouldResolveToTheCreatedTransaction); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
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
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think this is a helpful alias?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes :)