Merge pull request #796 from MetaMask/IncreaseGasBuffer

Increase gas buffer
feature/default_network_editable
Dan Finlay 8 years ago committed by GitHub
commit 2160eb35aa
  1. 3
      CHANGELOG.md
  2. 3
      app/scripts/lib/idStore.js
  3. 10
      test/unit/idStore-test.js

@ -2,7 +2,8 @@
## Current Master ## Current Master
- Fix gas estimation bug. - Fix bug where gas estimate would sometimes be very high.
- Increased our gas estimate from 100k gas to 20% of estimate.
- Fix github link on info page to point at current repository. - Fix github link on info page to point at current repository.
## 2.13.6 2016-10-26 ## 2.13.6 2016-10-26

@ -287,9 +287,10 @@ IdentityStore.prototype.checkForDelegateCall = function (codeHex) {
} }
} }
const gasBuffer = new BN('100000', 10)
IdentityStore.prototype.addGasBuffer = function (gas) { IdentityStore.prototype.addGasBuffer = function (gas) {
const bnGas = new BN(ethUtil.stripHexPrefix(gas), 16) const bnGas = new BN(ethUtil.stripHexPrefix(gas), 16)
const five = new BN('5', 10)
const gasBuffer = bnGas.div(five)
const correct = bnGas.add(gasBuffer) const correct = bnGas.add(gasBuffer)
return ethUtil.addHexPrefix(correct.toString(16)) return ethUtil.addHexPrefix(correct.toString(16))
} }

@ -159,7 +159,7 @@ describe('IdentityStore', function() {
assert.equal(result.indexOf('0x'), 0, 'include hex prefix') assert.equal(result.indexOf('0x'), 0, 'include hex prefix')
}) })
it('buffers reasonably', function() { it('buffers 20%', function() {
const idStore = new IdentityStore({ const idStore = new IdentityStore({
configManager: configManagerGen(), configManager: configManagerGen(),
ethStore: { ethStore: {
@ -168,20 +168,18 @@ describe('IdentityStore', function() {
}) })
const gas = '0x04ee59' // Actual estimated gas example const gas = '0x04ee59' // Actual estimated gas example
const tooBigOutput = '0x80674f9' // Actual bad output
const bnGas = new BN(ethUtil.stripHexPrefix(gas), 16) const bnGas = new BN(ethUtil.stripHexPrefix(gas), 16)
const correctBuffer = new BN('100000', 10) const five = new BN('5', 10)
const correctBuffer = bnGas.div(five)
const correct = bnGas.add(correctBuffer) const correct = bnGas.add(correctBuffer)
const tooBig = new BN(tooBigOutput, 16)
const result = idStore.addGasBuffer(gas) const result = idStore.addGasBuffer(gas)
const bnResult = new BN(ethUtil.stripHexPrefix(result), 16) const bnResult = new BN(ethUtil.stripHexPrefix(result), 16)
assert.equal(result.indexOf('0x'), 0, 'included hex prefix') assert.equal(result.indexOf('0x'), 0, 'included hex prefix')
assert(bnResult.gt(bnGas), 'Estimate increased in value.') assert(bnResult.gt(bnGas), 'Estimate increased in value.')
assert.equal(bnResult.sub(bnGas).toString(10), '100000', 'added 100k gas') assert.equal(bnResult.sub(bnGas).toString(10), correctBuffer.toString(10), 'added 20% gas')
assert.equal(result, '0x' + correct.toString(16), 'Added the right amount') assert.equal(result, '0x' + correct.toString(16), 'Added the right amount')
assert.notEqual(result, tooBigOutput, 'not that bad estimate')
}) })
}) })

Loading…
Cancel
Save