From 7b1f97e5b0eb2b37b0c2b3d6eb89e9e9ae5eb0af Mon Sep 17 00:00:00 2001 From: Vit Stanislav Date: Fri, 17 Nov 2017 09:18:58 +0100 Subject: [PATCH 1/3] Update message signature with passphrase input value ... before displaying it --- src/components/signMessage/signMessage.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/signMessage/signMessage.js b/src/components/signMessage/signMessage.js index 579e688de..342c63542 100644 --- a/src/components/signMessage/signMessage.js +++ b/src/components/signMessage/signMessage.js @@ -44,6 +44,7 @@ class SignMessageComponent extends React.Component { showResult(event) { event.preventDefault(); + this.sign(this.state.message); const copied = this.props.copyToClipboard(this.state.result, { message: this.props.t('Press #{key} to copy'), }); From a99af88013393d81bd699a855552e00ca5100a80 Mon Sep 17 00:00:00 2001 From: Vit Stanislav Date: Fri, 17 Nov 2017 10:34:29 +0100 Subject: [PATCH 2/3] Add unit tests for sign message with locked account --- .../signMessage/signMessage.test.js | 55 ++++++++++++++++--- 1 file changed, 46 insertions(+), 9 deletions(-) diff --git a/src/components/signMessage/signMessage.test.js b/src/components/signMessage/signMessage.test.js index 7e41cd5fc..d1c52d51a 100644 --- a/src/components/signMessage/signMessage.test.js +++ b/src/components/signMessage/signMessage.test.js @@ -1,11 +1,10 @@ import React from 'react'; import { expect } from 'chai'; import { mount } from 'enzyme'; +import configureMockStore from 'redux-mock-store'; import sinon from 'sinon'; -import { Provider } from 'react-redux'; -import { I18nextProvider } from 'react-i18next'; +import PropTypes from 'prop-types'; import i18n from '../../i18n'; -import store from '../../store'; import SignMessage from './signMessage'; @@ -13,6 +12,9 @@ describe('SignMessage', () => { let wrapper; let successToastSpy; let copyMock; + let props; + let store; + let options; const publicKey = 'c094ebee7ec0c50ebee32918655e089f6e1a604b83bcaa760293c61e0f18ab6f'; const signature = '079331d868678fd5f272f09d6dc8792fb21335aec42af7f11caadbfbc17d4707e7' + 'd7f343854b0c619b647b81ba3f29b23edb4eaf382a47c534746bad4529560b48656c6c6f20776f726c64'; @@ -33,18 +35,24 @@ ${signature} beforeEach(() => { successToastSpy = sinon.spy(); copyMock = sinon.mock(); - const props = { + props = { account, successToast: successToastSpy, copyToClipboard: copyMock, t: key => key, }; + store = configureMockStore([])({ + account, + }); + options = { + context: { store, i18n }, + childContextTypes: { + store: PropTypes.object.isRequired, + i18n: PropTypes.object.isRequired, + }, + }; - wrapper = mount( - - - - ); + wrapper = mount(, options); }); it('allows to sign a message, copies sign message result to clipboard and shows success toast', () => { @@ -55,6 +63,35 @@ ${signature} expect(successToastSpy).to.have.been.calledWith({ label: 'Result copied to clipboard' }); }); + it('allows to sign a message with a locked account', () => { + copyMock.returns(true); + + store = configureMockStore([])({ + account: { + ...account, + passphrase: undefined, + }, + }); + + wrapper = mount(, { + ...options, + context: { store, i18n }, + }); + + wrapper.setProps({ + ...props, + account: { + ...account, + passphrase: undefined, + }, + }); + + wrapper.find('.message textarea').simulate('change', { target: { value: message } }); + wrapper.find('.passphrase input').simulate('change', { target: { value: account.passphrase } }); + wrapper.find('#signMessageForm').simulate('submit'); + expect(wrapper.find('.result Input').text()).to.equal(result); + }); + it('does not show success toast if copy-to-clipboard failed', () => { copyMock.returns(false); wrapper.find('.message textarea').simulate('change', { target: { value: message } }); From 700e87a950f0f29e78bbf2f5818daa42339e37ec Mon Sep 17 00:00:00 2001 From: Vit Stanislav Date: Fri, 17 Nov 2017 12:19:56 +0100 Subject: [PATCH 3/3] Change signMessage to sign message only on button click ... not on input change --- src/components/signMessage/signMessage.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/components/signMessage/signMessage.js b/src/components/signMessage/signMessage.js index 342c63542..0220f9866 100644 --- a/src/components/signMessage/signMessage.js +++ b/src/components/signMessage/signMessage.js @@ -13,7 +13,7 @@ class SignMessageComponent extends React.Component { constructor() { super(); this.state = { - message: '', + message: { value: '' }, result: '', ...authStatePrefill(), }; @@ -39,12 +39,12 @@ class SignMessageComponent extends React.Component { this.state.passphrase.value); const result = Lisk.crypto.printSignedMessage( message, signedMessage, this.props.account.publicKey); - this.setState({ result, resultIsShown: false, message }); + this.setState({ result, resultIsShown: false }); } showResult(event) { event.preventDefault(); - this.sign(this.state.message); + this.sign(this.state.message.value); const copied = this.props.copyToClipboard(this.state.result, { message: this.props.t('Press #{key} to copy'), }); @@ -66,8 +66,8 @@ class SignMessageComponent extends React.Component {
+ value={this.state.message.value} + onChange={this.handleChange.bind(this, 'message')} />