mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 01:39:44 +01:00
Merge pull request #1441 from MetaMask/FixGasReset
Fix a test, add another
This commit is contained in:
commit
965a72486f
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
## Current Master
|
## Current Master
|
||||||
|
|
||||||
|
- Fix bug where edited gas parameters would not take effect.
|
||||||
- Trim currency list.
|
- Trim currency list.
|
||||||
- Fix event filter bug introduced by newer versions of Geth.
|
- Fix event filter bug introduced by newer versions of Geth.
|
||||||
|
|
||||||
|
@ -136,7 +136,6 @@
|
|||||||
"browserify": "^13.0.0",
|
"browserify": "^13.0.0",
|
||||||
"chai": "^3.5.0",
|
"chai": "^3.5.0",
|
||||||
"clone": "^1.0.2",
|
"clone": "^1.0.2",
|
||||||
"create-react-factory": "^0.2.1",
|
|
||||||
"deep-freeze-strict": "^1.1.1",
|
"deep-freeze-strict": "^1.1.1",
|
||||||
"del": "^2.2.0",
|
"del": "^2.2.0",
|
||||||
"envify": "^4.0.0",
|
"envify": "^4.0.0",
|
||||||
|
@ -2,15 +2,10 @@ const assert = require('assert')
|
|||||||
const additions = require('react-testutils-additions')
|
const additions = require('react-testutils-additions')
|
||||||
const h = require('react-hyperscript')
|
const h = require('react-hyperscript')
|
||||||
const PendingTx = require('../../../ui/app/components/pending-tx')
|
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 ReactTestUtils = require('react-addons-test-utils')
|
||||||
const ethUtil = require('ethereumjs-util')
|
const ethUtil = require('ethereumjs-util')
|
||||||
|
|
||||||
describe.only('PendingTx', function () {
|
describe('PendingTx', function () {
|
||||||
let pendingTxComponent
|
|
||||||
|
|
||||||
const identities = {
|
const identities = {
|
||||||
'0xfdea65c8e26263f6d9a1b5de9555d2931a33b826': {
|
'0xfdea65c8e26263f6d9a1b5de9555d2931a33b826': {
|
||||||
@ -38,7 +33,7 @@ describe.only('PendingTx', function () {
|
|||||||
|
|
||||||
it('should use updated values when edited.', function (done) {
|
it('should use updated values when edited.', function (done) {
|
||||||
|
|
||||||
const renderer = ReactTestUtils.createRenderer();
|
const renderer = ReactTestUtils.createRenderer()
|
||||||
const newGasPrice = '0x77359400'
|
const newGasPrice = '0x77359400'
|
||||||
|
|
||||||
const props = {
|
const props = {
|
||||||
@ -56,34 +51,31 @@ describe.only('PendingTx', function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const pendingTxComponent = h(PendingTx, props)
|
const pendingTxComponent = h(PendingTx, props)
|
||||||
const component = additions.renderIntoDocument(pendingTxComponent);
|
const component = additions.renderIntoDocument(pendingTxComponent)
|
||||||
renderer.render(pendingTxComponent)
|
renderer.render(pendingTxComponent)
|
||||||
const result = renderer.getRenderOutput()
|
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')
|
assert.equal(result.type, 'div', 'should create a div')
|
||||||
|
|
||||||
try{
|
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, {
|
ReactTestUtils.Simulate.change(input, {
|
||||||
target: {
|
target: {
|
||||||
value: 2,
|
value: 2,
|
||||||
checkValidity() { return true },
|
checkValidity() { return true },
|
||||||
}
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
let form = additions.find(component, 'form')[0]
|
const form = additions.find(component, 'form')[0]
|
||||||
form.checkValidity = () => true
|
form.checkValidity = () => true
|
||||||
form.getFormEl = () => { return { checkValidity() { return 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) {
|
} catch (e) {
|
||||||
console.log("WHAAAA")
|
console.log('WHAAAA')
|
||||||
console.error(e)
|
console.error(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -3,13 +3,15 @@ const EventEmitter = require('events')
|
|||||||
const ethUtil = require('ethereumjs-util')
|
const ethUtil = require('ethereumjs-util')
|
||||||
const EthTx = require('ethereumjs-tx')
|
const EthTx = require('ethereumjs-tx')
|
||||||
const ObservableStore = require('obs-store')
|
const ObservableStore = require('obs-store')
|
||||||
|
const clone = require('clone')
|
||||||
|
const sinon = require('sinon')
|
||||||
const TransactionController = require('../../app/scripts/controllers/transactions')
|
const TransactionController = require('../../app/scripts/controllers/transactions')
|
||||||
const noop = () => true
|
const noop = () => true
|
||||||
const currentNetworkId = 42
|
const currentNetworkId = 42
|
||||||
const otherNetworkId = 36
|
const otherNetworkId = 36
|
||||||
const privKey = new Buffer('8718b9618a37d1fc78c436511fc6df3c8258d3250635bba617f33003270ec03e', 'hex')
|
const privKey = new Buffer('8718b9618a37d1fc78c436511fc6df3c8258d3250635bba617f33003270ec03e', 'hex')
|
||||||
|
|
||||||
describe('Transaction Manager', function () {
|
describe('Transaction Controller', function () {
|
||||||
let txController
|
let txController
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
@ -170,6 +172,28 @@ describe('Transaction Manager', function () {
|
|||||||
var result = txController.getTx('1')
|
var result = txController.getTx('1')
|
||||||
assert.equal(result.hash, 'foo')
|
assert.equal(result.hash, 'foo')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('updates gas price', function () {
|
||||||
|
const originalGasPrice = '0x01'
|
||||||
|
const desiredGasPrice = '0x02'
|
||||||
|
|
||||||
|
const txMeta = {
|
||||||
|
id: '1',
|
||||||
|
status: 'unapproved',
|
||||||
|
metamaskNetworkId: currentNetworkId,
|
||||||
|
txParams: {
|
||||||
|
gasPrice: originalGasPrice,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
const updatedMeta = clone(txMeta)
|
||||||
|
|
||||||
|
txController.addTx(txMeta)
|
||||||
|
updatedMeta.txParams.gasPrice = desiredGasPrice
|
||||||
|
txController.updateTx(updatedMeta)
|
||||||
|
var result = txController.getTx('1')
|
||||||
|
assert.equal(result.txParams.gasPrice, desiredGasPrice, 'gas price updated')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('#getUnapprovedTxList', function () {
|
describe('#getUnapprovedTxList', function () {
|
||||||
@ -224,6 +248,66 @@ describe('Transaction Manager', 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 () {
|
describe('#sign replay-protected tx', function () {
|
||||||
it('prepares a tx with the chainId set', function () {
|
it('prepares a tx with the chainId set', function () {
|
||||||
txController.addTx({ id: '1', status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {} }, noop)
|
txController.addTx({ id: '1', status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {} }, noop)
|
||||||
@ -234,4 +318,5 @@ describe('Transaction Manager', function () {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
@ -108,7 +108,7 @@ ConfirmTxScreen.prototype.render = function () {
|
|||||||
currentCurrency,
|
currentCurrency,
|
||||||
// Actions
|
// Actions
|
||||||
buyEth: this.buyEth.bind(this, txParams.from || props.selectedAddress),
|
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),
|
cancelTransaction: this.cancelTransaction.bind(this, txData),
|
||||||
signMessage: this.signMessage.bind(this, txData),
|
signMessage: this.signMessage.bind(this, txData),
|
||||||
signPersonalMessage: this.signPersonalMessage.bind(this, txData),
|
signPersonalMessage: this.signPersonalMessage.bind(this, txData),
|
||||||
|
Loading…
Reference in New Issue
Block a user