mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-26 12:29:06 +01:00
Merge branch 'master' into build-lock-gulp
This commit is contained in:
commit
e561740133
@ -57,6 +57,14 @@ module.exports = class TransactionController extends EventEmitter {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
this.txStateManager.getFilteredTxList({
|
||||||
|
status: 'approved',
|
||||||
|
}).forEach((txMeta) => {
|
||||||
|
const txSignError = new Error('Transaction found as "approved" during boot - possibly stuck during signing')
|
||||||
|
this.txStateManager.setTxStatusFailed(txMeta.id, txSignError)
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
this.store = this.txStateManager.store
|
this.store = this.txStateManager.store
|
||||||
this.txStateManager.on('tx:status-update', this.emit.bind(this, 'tx:status-update'))
|
this.txStateManager.on('tx:status-update', this.emit.bind(this, 'tx:status-update'))
|
||||||
this.nonceTracker = new NonceTracker({
|
this.nonceTracker = new NonceTracker({
|
||||||
|
@ -12,7 +12,8 @@ its passed ethquery
|
|||||||
and used to do things like calculate gas of a tx.
|
and used to do things like calculate gas of a tx.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = class txProvideUtil {
|
module.exports = class TxGasUtil {
|
||||||
|
|
||||||
constructor (provider) {
|
constructor (provider) {
|
||||||
this.query = new EthQuery(provider)
|
this.query = new EthQuery(provider)
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@
|
|||||||
"ensnare": "^1.0.0",
|
"ensnare": "^1.0.0",
|
||||||
"eslint-plugin-react": "^7.4.0",
|
"eslint-plugin-react": "^7.4.0",
|
||||||
"eth-bin-to-ops": "^1.0.1",
|
"eth-bin-to-ops": "^1.0.1",
|
||||||
"eth-block-tracker": "^2.2.0",
|
"eth-block-tracker": "^2.3.0",
|
||||||
"eth-contract-metadata": "^1.1.4",
|
"eth-contract-metadata": "^1.1.4",
|
||||||
"eth-json-rpc-filters": "^1.2.5",
|
"eth-json-rpc-filters": "^1.2.5",
|
||||||
"eth-json-rpc-infura": "^2.0.5",
|
"eth-json-rpc-infura": "^2.0.5",
|
||||||
@ -99,7 +99,7 @@
|
|||||||
"iframe-stream": "^3.0.0",
|
"iframe-stream": "^3.0.0",
|
||||||
"inject-css": "^0.1.1",
|
"inject-css": "^0.1.1",
|
||||||
"jazzicon": "^1.2.0",
|
"jazzicon": "^1.2.0",
|
||||||
"json-rpc-engine": "3.2.0",
|
"json-rpc-engine": "^3.5.0",
|
||||||
"json-rpc-middleware-stream": "^1.0.1",
|
"json-rpc-middleware-stream": "^1.0.1",
|
||||||
"lodash.debounce": "^4.0.8",
|
"lodash.debounce": "^4.0.8",
|
||||||
"lodash.memoize": "^4.1.2",
|
"lodash.memoize": "^4.1.2",
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
const JsonRpcEngine = require('json-rpc-engine')
|
const JsonRpcEngine = require('json-rpc-engine')
|
||||||
const scaffoldMiddleware = require('eth-json-rpc-middleware/scaffold')
|
const scaffoldMiddleware = require('eth-json-rpc-middleware/scaffold')
|
||||||
|
const TestBlockchain = require('eth-block-tracker/test/util/testBlockMiddleware')
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
createEngineForTestData,
|
createEngineForTestData,
|
||||||
providerFromEngine,
|
providerFromEngine,
|
||||||
scaffoldMiddleware,
|
scaffoldMiddleware,
|
||||||
createEthJsQueryStub,
|
createTestProviderTools,
|
||||||
createStubedProvider,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -19,20 +19,13 @@ function providerFromEngine (engine) {
|
|||||||
return provider
|
return provider
|
||||||
}
|
}
|
||||||
|
|
||||||
function createEthJsQueryStub (stubProvider) {
|
function createTestProviderTools (opts = {}) {
|
||||||
return new Proxy({}, {
|
|
||||||
get: (obj, method) => {
|
|
||||||
return (...params) => {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
stubProvider.sendAsync({ method: `eth_${method}`, params }, (err, res) => err ? reject(err) : resolve(res.result))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function createStubedProvider (resultStub) {
|
|
||||||
const engine = createEngineForTestData()
|
const engine = createEngineForTestData()
|
||||||
engine.push(scaffoldMiddleware(resultStub))
|
const testBlockchain = new TestBlockchain()
|
||||||
return providerFromEngine(engine)
|
// handle provided hooks
|
||||||
|
engine.push(scaffoldMiddleware(opts.scaffold || {}))
|
||||||
|
// handle block tracker methods
|
||||||
|
engine.push(testBlockchain.createMiddleware())
|
||||||
|
const provider = providerFromEngine(engine)
|
||||||
|
return { provider, engine, testBlockchain }
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ 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 clone = require('clone')
|
||||||
const { createStubedProvider } = require('../stub/provider')
|
const { createTestProviderTools } = require('../stub/provider')
|
||||||
const PendingTransactionTracker = require('../../app/scripts/lib/pending-tx-tracker')
|
const PendingTransactionTracker = require('../../app/scripts/lib/pending-tx-tracker')
|
||||||
const MockTxGen = require('../lib/mock-tx-gen')
|
const MockTxGen = require('../lib/mock-tx-gen')
|
||||||
const sinon = require('sinon')
|
const sinon = require('sinon')
|
||||||
@ -39,7 +39,7 @@ describe('PendingTransactionTracker', function () {
|
|||||||
txParams: { from: '0x1678a085c290ebd122dc42cba69373b5953b831d'},
|
txParams: { from: '0x1678a085c290ebd122dc42cba69373b5953b831d'},
|
||||||
}
|
}
|
||||||
providerResultStub = {}
|
providerResultStub = {}
|
||||||
provider = createStubedProvider(providerResultStub)
|
provider = createTestProviderTools({ scaffold: providerResultStub }).provider
|
||||||
|
|
||||||
pendingTxTracker = new PendingTransactionTracker({
|
pendingTxTracker = new PendingTransactionTracker({
|
||||||
provider,
|
provider,
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
const assert = require('assert')
|
const assert = require('assert')
|
||||||
const ethUtil = require('ethereumjs-util')
|
const ethUtil = require('ethereumjs-util')
|
||||||
const EthTx = require('ethereumjs-tx')
|
const EthTx = require('ethereumjs-tx')
|
||||||
|
const EthjsQuery = require('ethjs-query')
|
||||||
const ObservableStore = require('obs-store')
|
const ObservableStore = require('obs-store')
|
||||||
const sinon = require('sinon')
|
const sinon = require('sinon')
|
||||||
const TransactionController = require('../../app/scripts/controllers/transactions')
|
const TransactionController = require('../../app/scripts/controllers/transactions')
|
||||||
const TxGasUtils = require('../../app/scripts/lib/tx-gas-utils')
|
const TxGasUtils = require('../../app/scripts/lib/tx-gas-utils')
|
||||||
const { createStubedProvider, createEthJsQueryStub } = require('../stub/provider')
|
const { createTestProviderTools } = require('../stub/provider')
|
||||||
|
|
||||||
const noop = () => true
|
const noop = () => true
|
||||||
const currentNetworkId = 42
|
const currentNetworkId = 42
|
||||||
@ -14,11 +15,18 @@ const privKey = new Buffer('8718b9618a37d1fc78c436511fc6df3c8258d3250635bba617f3
|
|||||||
|
|
||||||
|
|
||||||
describe('Transaction Controller', function () {
|
describe('Transaction Controller', function () {
|
||||||
let txController, provider, providerResultStub
|
let txController, provider, providerResultStub, testBlockchain
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
providerResultStub = {}
|
providerResultStub = {
|
||||||
provider = createStubedProvider(providerResultStub)
|
// 1 gwei
|
||||||
|
eth_gasPrice: '0x0de0b6b3a7640000',
|
||||||
|
// by default, all accounts are external accounts (not contracts)
|
||||||
|
eth_getCode: '0x',
|
||||||
|
}
|
||||||
|
const providerTools = createTestProviderTools({ scaffold: providerResultStub })
|
||||||
|
provider = providerTools.provider
|
||||||
|
testBlockchain = providerTools.testBlockchain
|
||||||
|
|
||||||
txController = new TransactionController({
|
txController = new TransactionController({
|
||||||
provider,
|
provider,
|
||||||
@ -30,10 +38,7 @@ describe('Transaction Controller', function () {
|
|||||||
resolve()
|
resolve()
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
txController.query = createEthJsQueryStub(provider)
|
|
||||||
txController.txGasUtil.query = createEthJsQueryStub(provider)
|
|
||||||
txController.nonceTracker.getNonceLock = () => Promise.resolve({ nextNonce: 0, releaseLock: noop })
|
txController.nonceTracker.getNonceLock = () => Promise.resolve({ nextNonce: 0, releaseLock: noop })
|
||||||
txController.txProviderUtils = new TxGasUtils(txController.provider)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('#getState', function () {
|
describe('#getState', function () {
|
||||||
@ -155,15 +160,6 @@ describe('Transaction Controller', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe('#addUnapprovedTransaction', function () {
|
describe('#addUnapprovedTransaction', function () {
|
||||||
let addTxDefaults
|
|
||||||
beforeEach(() => {
|
|
||||||
addTxDefaults = txController.addTxDefaults
|
|
||||||
txController.addTxDefaults = function addTxDefaultsStub () { return Promise.resolve() }
|
|
||||||
|
|
||||||
})
|
|
||||||
afterEach(() => {
|
|
||||||
txController.addTxDefaults = addTxDefaults
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should add an unapproved transaction and return a valid txMeta', function (done) {
|
it('should add an unapproved transaction and return a valid txMeta', function (done) {
|
||||||
txController.addUnapprovedTransaction({})
|
txController.addUnapprovedTransaction({})
|
||||||
@ -219,7 +215,7 @@ describe('Transaction Controller', function () {
|
|||||||
var sample = {
|
var sample = {
|
||||||
value: '0x01',
|
value: '0x01',
|
||||||
}
|
}
|
||||||
txController.txProviderUtils.validateTxParams(sample).then(() => {
|
txController.txGasUtil.validateTxParams(sample).then(() => {
|
||||||
done()
|
done()
|
||||||
}).catch(done)
|
}).catch(done)
|
||||||
})
|
})
|
||||||
@ -228,7 +224,7 @@ describe('Transaction Controller', function () {
|
|||||||
var sample = {
|
var sample = {
|
||||||
value: '-0x01',
|
value: '-0x01',
|
||||||
}
|
}
|
||||||
txController.txProviderUtils.validateTxParams(sample)
|
txController.txGasUtil.validateTxParams(sample)
|
||||||
.then(() => done('expected to thrown on negativity values but didn\'t'))
|
.then(() => done('expected to thrown on negativity values but didn\'t'))
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
assert.ok(err, 'error')
|
assert.ok(err, 'error')
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
const assert = require('assert')
|
const assert = require('assert')
|
||||||
const TxGasUtils = require('../../app/scripts/lib/tx-gas-utils')
|
const TxGasUtils = require('../../app/scripts/lib/tx-gas-utils')
|
||||||
const { createStubedProvider } = require('../stub/provider')
|
const { createTestProviderTools } = require('../stub/provider')
|
||||||
|
|
||||||
describe('Tx Gas Util', function () {
|
describe('Tx Gas Util', function () {
|
||||||
let txGasUtil, provider, providerResultStub
|
let txGasUtil, provider, providerResultStub
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
providerResultStub = {}
|
providerResultStub = {}
|
||||||
provider = createStubedProvider(providerResultStub)
|
provider = createTestProviderTools({ scaffold: providerResultStub }).provider
|
||||||
txGasUtil = new TxGasUtils({
|
txGasUtil = new TxGasUtils({
|
||||||
provider,
|
provider,
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user