From a00941c8894258a7534f8373405a0f8f4d27a904 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Tue, 16 May 2017 13:21:31 -0700 Subject: [PATCH 1/8] Remove only line from test --- test/unit/components/pending-tx-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/components/pending-tx-test.js b/test/unit/components/pending-tx-test.js index fe8290003..166b471cb 100644 --- a/test/unit/components/pending-tx-test.js +++ b/test/unit/components/pending-tx-test.js @@ -9,7 +9,7 @@ const Factory = createReactFactory(PendingTx) const ReactTestUtils = require('react-addons-test-utils') const ethUtil = require('ethereumjs-util') -describe.only('PendingTx', function () { +describe('PendingTx', function () { let pendingTxComponent const identities = { From a15e753c800617879384634a7096497550588eaf Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Tue, 16 May 2017 13:22:03 -0700 Subject: [PATCH 2/8] Add gas updating test to tx controller tests --- test/unit/tx-controller-test.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/test/unit/tx-controller-test.js b/test/unit/tx-controller-test.js index d0b32ff41..51e0b9a17 100644 --- a/test/unit/tx-controller-test.js +++ b/test/unit/tx-controller-test.js @@ -9,7 +9,7 @@ const currentNetworkId = 42 const otherNetworkId = 36 const privKey = new Buffer('8718b9618a37d1fc78c436511fc6df3c8258d3250635bba617f33003270ec03e', 'hex') -describe('Transaction Manager', function () { +describe('Transaction Controller', function () { let txController beforeEach(function () { @@ -170,6 +170,25 @@ describe('Transaction Manager', function () { var result = txController.getTx('1') assert.equal(result.hash, 'foo') }) + + it('updates gas price', function () { + const originalGasPrice = '0x01' + const desiredGasPriced = '0x02' + + const txMeta = { + id: '1', + status: 'unapproved', + metamaskNetworkId: currentNetworkId, + txParams: { + gasPrice: originalGasPrice, + }, + } + + txController.addTx(txMeta) + txMeta.txParams.gasPrice = desiredGasPriced + var result = txController.getTx('1') + assert.equal(result.txParams.gasPrice, desiredGasPriced, 'gas price updated') + }) }) describe('#getUnapprovedTxList', function () { @@ -234,4 +253,5 @@ describe('Transaction Manager', function () { }) }) }) + }) From caeadc24072829deaabd0f6a33563bb84c10008a Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Tue, 16 May 2017 16:19:10 -0700 Subject: [PATCH 3/8] Linted and removed unused deps --- package.json | 1 - test/unit/components/pending-tx-test.js | 23 ++++++++--------------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index eb5ed8a32..14ddd2886 100644 --- a/package.json +++ b/package.json @@ -136,7 +136,6 @@ "browserify": "^13.0.0", "chai": "^3.5.0", "clone": "^1.0.2", - "create-react-factory": "^0.2.1", "deep-freeze-strict": "^1.1.1", "del": "^2.2.0", "envify": "^4.0.0", diff --git a/test/unit/components/pending-tx-test.js b/test/unit/components/pending-tx-test.js index 166b471cb..36339474c 100644 --- a/test/unit/components/pending-tx-test.js +++ b/test/unit/components/pending-tx-test.js @@ -2,15 +2,10 @@ const assert = require('assert') const additions = require('react-testutils-additions') const h = require('react-hyperscript') const PendingTx = require('../../../ui/app/components/pending-tx') -const createReactFactory = require('create-react-factory').createReactFactory -const React = require('react') -const shallow = require('react-test-renderer/shallow') -const Factory = createReactFactory(PendingTx) const ReactTestUtils = require('react-addons-test-utils') const ethUtil = require('ethereumjs-util') describe('PendingTx', function () { - let pendingTxComponent const identities = { '0xfdea65c8e26263f6d9a1b5de9555d2931a33b826': { @@ -38,7 +33,7 @@ describe('PendingTx', function () { it('should use updated values when edited.', function (done) { - const renderer = ReactTestUtils.createRenderer(); + const renderer = ReactTestUtils.createRenderer() const newGasPrice = '0x77359400' const props = { @@ -56,16 +51,14 @@ describe('PendingTx', function () { } const pendingTxComponent = h(PendingTx, props) - const component = additions.renderIntoDocument(pendingTxComponent); + const component = additions.renderIntoDocument(pendingTxComponent) renderer.render(pendingTxComponent) const result = renderer.getRenderOutput() const form = result.props.children - const children = form.props.children[form.props.children.length - 1] assert.equal(result.type, 'div', 'should create a div') - try{ - - const input = additions.find(component, '.cell.row input[type="number"]')[1] + try { + const input = additions.find(component, '.cell.row input[type='number']')[1] ReactTestUtils.Simulate.change(input, { target: { value: 2, @@ -76,14 +69,14 @@ describe('PendingTx', function () { let form = additions.find(component, 'form')[0] form.checkValidity = () => true form.getFormEl = () => { return { checkValidity() { return true } } } - ReactTestUtils.Simulate.submit(form, { preventDefault() {}, target: { checkValidity() {return true} } }) + ReactTestUtils.Simulate.submit(form, { preventDefault() {}, target: { checkValidity() { + return true + } } }) } catch (e) { - console.log("WHAAAA") + console.log('WHAAAA') console.error(e) } - }) - }) From cfb7bfed186a03e4e879d932501a51a9758dd3ad Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Tue, 16 May 2017 16:44:17 -0700 Subject: [PATCH 4/8] Fix quotation mark --- test/unit/components/pending-tx-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/components/pending-tx-test.js b/test/unit/components/pending-tx-test.js index 36339474c..89e6892a3 100644 --- a/test/unit/components/pending-tx-test.js +++ b/test/unit/components/pending-tx-test.js @@ -58,7 +58,7 @@ describe('PendingTx', function () { assert.equal(result.type, 'div', 'should create a div') try { - const input = additions.find(component, '.cell.row input[type='number']')[1] + const input = additions.find(component, '.cell.row input[type="number"]')[1] ReactTestUtils.Simulate.change(input, { target: { value: 2, From c1bef31d9d3b2cf091ac94c908700c3c0081318f Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Tue, 16 May 2017 16:49:59 -0700 Subject: [PATCH 5/8] Linted --- test/unit/components/pending-tx-test.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/unit/components/pending-tx-test.js b/test/unit/components/pending-tx-test.js index 89e6892a3..9ff948604 100644 --- a/test/unit/components/pending-tx-test.js +++ b/test/unit/components/pending-tx-test.js @@ -54,7 +54,6 @@ describe('PendingTx', function () { const component = additions.renderIntoDocument(pendingTxComponent) renderer.render(pendingTxComponent) const result = renderer.getRenderOutput() - const form = result.props.children assert.equal(result.type, 'div', 'should create a div') try { @@ -63,10 +62,10 @@ describe('PendingTx', function () { target: { value: 2, checkValidity() { return true }, - } + }, }) - let form = additions.find(component, 'form')[0] + const form = additions.find(component, 'form')[0] form.checkValidity = () => true form.getFormEl = () => { return { checkValidity() { return true } } } ReactTestUtils.Simulate.submit(form, { preventDefault() {}, target: { checkValidity() { From c6fd5090519af64bbe3d29346484bcf45572d3c2 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Tue, 16 May 2017 17:06:19 -0700 Subject: [PATCH 6/8] Improve test --- test/unit/tx-controller-test.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/unit/tx-controller-test.js b/test/unit/tx-controller-test.js index 51e0b9a17..e6645090e 100644 --- a/test/unit/tx-controller-test.js +++ b/test/unit/tx-controller-test.js @@ -3,6 +3,7 @@ const EventEmitter = require('events') const ethUtil = require('ethereumjs-util') const EthTx = require('ethereumjs-tx') const ObservableStore = require('obs-store') +const clone = require('clone') const TransactionController = require('../../app/scripts/controllers/transactions') const noop = () => true const currentNetworkId = 42 @@ -184,8 +185,11 @@ describe('Transaction Controller', function () { }, } + const updatedMeta = clone(txMeta) + txController.addTx(txMeta) - txMeta.txParams.gasPrice = desiredGasPriced + updatedMeta.txParams.gasPrice = desiredGasPriced + txController.updateTx(updatedMeta) var result = txController.getTx('1') assert.equal(result.txParams.gasPrice, desiredGasPriced, 'gas price updated') }) From 6491b42266b2114af72e72a46a6453dc3dd59290 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Tue, 16 May 2017 18:16:18 -0700 Subject: [PATCH 7/8] Add test around txManager#approveTransaction --- test/unit/tx-controller-test.js | 67 +++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 3 deletions(-) diff --git a/test/unit/tx-controller-test.js b/test/unit/tx-controller-test.js index e6645090e..d4e8d79f0 100644 --- a/test/unit/tx-controller-test.js +++ b/test/unit/tx-controller-test.js @@ -4,6 +4,7 @@ const ethUtil = require('ethereumjs-util') const EthTx = require('ethereumjs-tx') const ObservableStore = require('obs-store') const clone = require('clone') +const sinon = require('sinon') const TransactionController = require('../../app/scripts/controllers/transactions') const noop = () => true const currentNetworkId = 42 @@ -174,7 +175,7 @@ describe('Transaction Controller', function () { it('updates gas price', function () { const originalGasPrice = '0x01' - const desiredGasPriced = '0x02' + const desiredGasPrice = '0x02' const txMeta = { id: '1', @@ -188,10 +189,10 @@ describe('Transaction Controller', function () { const updatedMeta = clone(txMeta) txController.addTx(txMeta) - updatedMeta.txParams.gasPrice = desiredGasPriced + updatedMeta.txParams.gasPrice = desiredGasPrice txController.updateTx(updatedMeta) var result = txController.getTx('1') - assert.equal(result.txParams.gasPrice, desiredGasPriced, 'gas price updated') + assert.equal(result.txParams.gasPrice, desiredGasPrice, 'gas price updated') }) }) @@ -247,6 +248,66 @@ describe('Transaction Controller', function () { }) }) + describe('#approveTransaction', function () { + let txMeta, originalValue + + beforeEach(function () { + originalValue = '0x01' + txMeta = { + id: '1', + status: 'unapproved', + metamaskNetworkId: currentNetworkId, + txParams: { + nonce: originalValue, + gas: originalValue, + gasPrice: originalValue, + }, + } + }) + + + it('does not overwrite set values', function (done) { + const wrongValue = '0x05' + + txController.addTx(txMeta) + + const estimateStub = sinon.stub(txController.txProviderUtils.query, 'estimateGas') + .callsArgWith(1, null, wrongValue) + + const priceStub = sinon.stub(txController.txProviderUtils.query, 'gasPrice') + .callsArgWith(0, null, wrongValue) + + const nonceStub = sinon.stub(txController.txProviderUtils.query, 'getTransactionCount') + .callsArgWith(2, null, wrongValue) + + const signStub = sinon.stub(txController, 'signTransaction') + .callsArgWith(1, null, noop) + + const pubStub = sinon.stub(txController.txProviderUtils, 'publishTransaction') + .callsArgWith(1, null, originalValue) + + txController.approveTransaction(txMeta.id, (err) => { + assert.ifError(err, 'should not error') + + const result = txController.getTx(txMeta.id) + const params = result.txParams + + assert.equal(params.gas, originalValue, 'gas unmodified') + assert.equal(params.gasPrice, originalValue, 'gas price unmodified') + assert.equal(params.nonce, originalValue, 'nonce unmodified') + assert.equal(result.hash, originalValue, 'hash was set') + + estimateStub.restore() + priceStub.restore() + signStub.restore() + nonceStub.restore() + pubStub.restore() + + done() + }) + }) + }) + describe('#sign replay-protected tx', function () { it('prepares a tx with the chainId set', function () { txController.addTx({ id: '1', status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {} }, noop) From 31c7daee73fa41e356d1bd5cd92186e60b252212 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Tue, 16 May 2017 23:33:40 -0700 Subject: [PATCH 8/8] Fix bug where edited gas parameters did not take effect Fixes #1407 --- CHANGELOG.md | 1 + ui/app/conf-tx.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3653e5018..998219254 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Current Master +- Fix bug where edited gas parameters would not take effect. - Trim currency list. - Fix event filter bug introduced by newer versions of Geth. diff --git a/ui/app/conf-tx.js b/ui/app/conf-tx.js index 0d7c4c1bb..008627ce6 100644 --- a/ui/app/conf-tx.js +++ b/ui/app/conf-tx.js @@ -108,7 +108,7 @@ ConfirmTxScreen.prototype.render = function () { currentCurrency, // Actions buyEth: this.buyEth.bind(this, txParams.from || props.selectedAddress), - sendTransaction: this.sendTransaction.bind(this, txData), + sendTransaction: this.sendTransaction.bind(this), cancelTransaction: this.cancelTransaction.bind(this, txData), signMessage: this.signMessage.bind(this, txData), signPersonalMessage: this.signPersonalMessage.bind(this, txData),