1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

add test for addTxDefaults

This commit is contained in:
frankiebee 2017-08-02 11:34:45 -04:00
parent 432f516ab0
commit 21e76484d6

View File

@ -5,12 +5,13 @@ const ObservableStore = require('obs-store')
const clone = require('clone') const clone = require('clone')
const sinon = require('sinon') const sinon = require('sinon')
const TransactionController = require('../../app/scripts/controllers/transactions') const TransactionController = require('../../app/scripts/controllers/transactions')
const TxProvideUtils = require('../../app/scripts/lib/tx-utils')
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.only('Transaction Controller', function () { describe('Transaction Controller', function () {
let txController let txController
beforeEach(function () { beforeEach(function () {
@ -26,19 +27,19 @@ describe.only('Transaction Controller', function () {
}), }),
}) })
txController.nonceTracker.getNonceLock = () => Promise.resolve({ nextNonce: 0, releaseLock: noop }) txController.nonceTracker.getNonceLock = () => Promise.resolve({ nextNonce: 0, releaseLock: noop })
const queryStubResult = {}
txController.query = new Proxy({}, { txController.query = new Proxy({}, {
get: (_, key) => { get: (queryStubResult, key) => {
if (key === 'stubResult') { if (key === 'stubResult') {
return function (method, ...args) { return function (method, ...args) {
queryStubResult[method] = args queryStubResult[method] = args
} }
} else { } else {
returnValue = queryStubResult[key] const returnValues = queryStubResult[key]
return () => Promise.resolve(...returnValue) return () => Promise.resolve(...returnValues)
} }
}, },
}) })
txController.txProviderUtils = new TxProvideUtils(txController.query)
}) })
describe('#addUnapprovedTransaction', function () { describe('#addUnapprovedTransaction', function () {
@ -60,6 +61,30 @@ describe.only('Transaction Controller', function () {
}) })
}) })
describe('#addTxDefaults', function () {
it('should add the tx defaults if their are none', function (done) {
let txMeta = {
'txParams': {
'from':'0xc684832530fcbddae4b4230a47e991ddcec2831d',
'to':'0xc684832530fcbddae4b4230a47e991ddcec2831d',
},
}
txController.query.stubResult('gasPrice', '0x4a817c800')
txController.query.stubResult('getBlockByNumber', { gasLimit: '0x47b784' })
txController.query.stubResult('estimateGas', '0x5209')
txController.addTxDefaults(txMeta)
.then((txMetaWithDefaults) => {
assert(txMetaWithDefaults.txParams.value, '0x0','should have added 0x0 as the value')
assert(txMetaWithDefaults.txParams.gasPrice, 'should have added the gas price')
assert(txMetaWithDefaults.txParams.gas, 'should have added the gas field')
done()
})
.catch(done)
})
})
describe('#validateTxParams', function () { describe('#validateTxParams', function () {
it('does not throw for positive values', function (done) { it('does not throw for positive values', function (done) {
var sample = { var sample = {