Skip to content

Commit

Permalink
transactions - make #_validateTxParams not async and "linting" wink w…
Browse files Browse the repository at this point in the history
…ink nudge nudge
  • Loading branch information
frankiebee committed Apr 4, 2018
1 parent 6ab9385 commit 245c01b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
19 changes: 12 additions & 7 deletions app/scripts/controllers/transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ module.exports = class TransactionController extends EventEmitter {

async addUnapprovedTransaction (txParams) {
// validate
await this._validateTxParams(txParams)
this._validateTxParams(txParams)
this._normalizeTxParams(txParams)
// construct txMeta
let txMeta = this.txStateManager.generateTxMeta({txParams})
Expand Down Expand Up @@ -317,21 +317,26 @@ module.exports = class TransactionController extends EventEmitter {
_normalizeTxParams (txParams) {
delete txParams.chainId

if ( !txParams.to ) delete txParams.to
else txParams.to = ethUtil.addHexPrefix(txParams.to)

if ( !txParams.to ) {
delete txParams.to
} else {
txParams.to = ethUtil.addHexPrefix(txParams.to)
}
txParams.from = ethUtil.addHexPrefix(txParams.from).toLowerCase()

if (!txParams.data) delete txParams.data
else txParams.data = ethUtil.addHexPrefix(txParams.data)
if (!txParams.data) {
delete txParams.data
} else {
txParams.data = ethUtil.addHexPrefix(txParams.data)
}

if (txParams.value) txParams.value = ethUtil.addHexPrefix(txParams.value)

if (txParams.gas) txParams.gas = ethUtil.addHexPrefix(txParams.gas)
if (txParams.gasPrice) txParams.gas = ethUtil.addHexPrefix(txParams.gas)
}

async _validateTxParams (txParams) {
_validateTxParams (txParams) {
this._validateFrom(txParams)
this._validateRecipient(txParams)
if ('value' in txParams) {
Expand Down
19 changes: 8 additions & 11 deletions test/unit/tx-controller-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,28 +210,25 @@ describe('Transaction Controller', function () {
})
})

describe('#validateTxParams', function () {
it('does not throw for positive values', function (done) {
describe('#_validateTxParams', function () {
it('does not throw for positive values', function () {
var sample = {
from: '0x1678a085c290ebd122dc42cba69373b5953b831d',
value: '0x01',
}
txController._validateTxParams(sample).then(() => {
done()
}).catch(done)
txController._validateTxParams(sample)
})

it('returns error for negative values', function (done) {
it('returns error for negative values', function () {
var sample = {
from: '0x1678a085c290ebd122dc42cba69373b5953b831d',
value: '-0x01',
}
txController._validateTxParams(sample)
.then(() => done('expected to thrown on negativity values but didn\'t'))
.catch((err) => {
try {
txController._validateTxParams(sample)
} catch (err) {
assert.ok(err, 'error')
done()
})
}
})
})

Expand Down

0 comments on commit 245c01b

Please sign in to comment.