mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
transactions - make #_validateTxParams not async and "linting" wink wink nudge nudge
This commit is contained in:
parent
6ab938546c
commit
245c01bc0f
@ -185,7 +185,7 @@ module.exports = class TransactionController extends EventEmitter {
|
|||||||
|
|
||||||
async addUnapprovedTransaction (txParams) {
|
async addUnapprovedTransaction (txParams) {
|
||||||
// validate
|
// validate
|
||||||
await this._validateTxParams(txParams)
|
this._validateTxParams(txParams)
|
||||||
this._normalizeTxParams(txParams)
|
this._normalizeTxParams(txParams)
|
||||||
// construct txMeta
|
// construct txMeta
|
||||||
let txMeta = this.txStateManager.generateTxMeta({txParams})
|
let txMeta = this.txStateManager.generateTxMeta({txParams})
|
||||||
@ -317,13 +317,18 @@ module.exports = class TransactionController extends EventEmitter {
|
|||||||
_normalizeTxParams (txParams) {
|
_normalizeTxParams (txParams) {
|
||||||
delete txParams.chainId
|
delete txParams.chainId
|
||||||
|
|
||||||
if ( !txParams.to ) delete txParams.to
|
if ( !txParams.to ) {
|
||||||
else txParams.to = ethUtil.addHexPrefix(txParams.to)
|
delete txParams.to
|
||||||
|
} else {
|
||||||
|
txParams.to = ethUtil.addHexPrefix(txParams.to)
|
||||||
|
}
|
||||||
txParams.from = ethUtil.addHexPrefix(txParams.from).toLowerCase()
|
txParams.from = ethUtil.addHexPrefix(txParams.from).toLowerCase()
|
||||||
|
|
||||||
if (!txParams.data) delete txParams.data
|
if (!txParams.data) {
|
||||||
else txParams.data = ethUtil.addHexPrefix(txParams.data)
|
delete txParams.data
|
||||||
|
} else {
|
||||||
|
txParams.data = ethUtil.addHexPrefix(txParams.data)
|
||||||
|
}
|
||||||
|
|
||||||
if (txParams.value) txParams.value = ethUtil.addHexPrefix(txParams.value)
|
if (txParams.value) txParams.value = ethUtil.addHexPrefix(txParams.value)
|
||||||
|
|
||||||
@ -331,7 +336,7 @@ module.exports = class TransactionController extends EventEmitter {
|
|||||||
if (txParams.gasPrice) txParams.gas = ethUtil.addHexPrefix(txParams.gas)
|
if (txParams.gasPrice) txParams.gas = ethUtil.addHexPrefix(txParams.gas)
|
||||||
}
|
}
|
||||||
|
|
||||||
async _validateTxParams (txParams) {
|
_validateTxParams (txParams) {
|
||||||
this._validateFrom(txParams)
|
this._validateFrom(txParams)
|
||||||
this._validateRecipient(txParams)
|
this._validateRecipient(txParams)
|
||||||
if ('value' in txParams) {
|
if ('value' in txParams) {
|
||||||
|
@ -210,28 +210,25 @@ describe('Transaction Controller', function () {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('#validateTxParams', function () {
|
describe('#_validateTxParams', function () {
|
||||||
it('does not throw for positive values', function (done) {
|
it('does not throw for positive values', function () {
|
||||||
var sample = {
|
var sample = {
|
||||||
from: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
from: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
||||||
value: '0x01',
|
value: '0x01',
|
||||||
}
|
}
|
||||||
txController._validateTxParams(sample).then(() => {
|
txController._validateTxParams(sample)
|
||||||
done()
|
|
||||||
}).catch(done)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns error for negative values', function (done) {
|
it('returns error for negative values', function () {
|
||||||
var sample = {
|
var sample = {
|
||||||
from: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
from: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
||||||
value: '-0x01',
|
value: '-0x01',
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
txController._validateTxParams(sample)
|
txController._validateTxParams(sample)
|
||||||
.then(() => done('expected to thrown on negativity values but didn\'t'))
|
} catch (err) {
|
||||||
.catch((err) => {
|
|
||||||
assert.ok(err, 'error')
|
assert.ok(err, 'error')
|
||||||
done()
|
}
|
||||||
})
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user